/**
 * Calendar Utility Functions
 * @author Gourav Budhia
 * @version $Header: @(#) /ccviews/genesis_ua_fd/genesis_ua/Source/Docroot/js/calendar_utils.js@@/main/1  2004-05-20 12:43:56 GMT  BudhiaG $
 * @created 05/20/2004
 */

function openCalendarCheckIn(sURL, theForm, brand, region, locale, secure)
{
	var cDate = theForm.checkInDate[theForm.checkInDate.selectedIndex].value;
	var cMonthYear = theForm.checkInMonthYear[theForm.checkInMonthYear.selectedIndex].value;
	var url = sURL + '&openerForm=' + theForm.name + '&monthYear=' + cMonthYear + '&date=' + cDate + '&checkOut=false';
	if(navigator.userAgent.indexOf("AOL 6.0") != -1 || navigator.userAgent.indexOf("AOL 5.0") != -1) {
		newWin = window.open(url,'HI','DEPENDANT=YES,WIDTH=225,HEIGHT=230,TITLEBAR=YES,MENUBAR=NO,SCROLLBARS=NO,TOP=0,LEFT=0');
	} else {
		var topPos = (screen.availHeight/2)-115;
		var leftPos = (screen.availWidth/2)-105;
		newWin = window.open(url,'cal','top=' + topPos + ',left=' + leftPos + ',dependent=yes,width=200,height=158,screenX=' + leftPos + ',screenY=' + topPos + ',titlebar=yes');
	}
	newWin.focus();
	return false;
}


function openCalendarCheckOut(sURL, theForm, brand, region, locale, secure)
{
	var cDate = theForm.checkOutDate[theForm.checkOutDate.selectedIndex].value;
	var cMonthYear = theForm.checkOutMonthYear[theForm.checkOutMonthYear.selectedIndex].value;
	var url = sURL + '&openerForm=' + theForm.name + '&monthYear=' + cMonthYear + '&date=' + cDate + '&checkOut=true';
	if(navigator.userAgent.indexOf("AOL 6.0") != -1 || navigator.userAgent.indexOf("AOL 5.0") != -1) {
		newWin = window.open(url,'HI','DEPENDANT=YES,WIDTH=225,HEIGHT=230,TITLEBAR=YES,MENUBAR=NO,SCROLLBARS=NO,TOP=0,LEFT=0');
	} else {
		var topPos = (screen.availHeight/2)-115;
		var leftPos = (screen.availWidth/2)-105;
		newWin = window.open(url,'cal','top=' + topPos + ',left=' + leftPos + ',dependent=yes,width=200,height=158,screenX=' + leftPos + ',screenY=' + topPos + ',titlebar=yes');
	}
	newWin.focus();
	return false;
}


function populateCheckOut(theForm)
{
	if(theForm.checkInDate.selectedIndex != 0 && theForm.checkInMonthYear.selectedIndex != 0) {
		if ((theForm.checkOutDate.selectedIndex == 0) ||
			(theForm.checkOutMonthYear.selectedIndex == 0) ||
			(theForm.checkOutMonthYear.selectedIndex < theForm.checkInMonthYear.selectedIndex) ||
			((theForm.checkOutMonthYear.selectedIndex == theForm.checkInMonthYear.selectedIndex) &&
			 (theForm.checkOutDate.selectedIndex <= theForm.checkInDate.selectedIndex))) {
			var monthYear= theForm.checkInMonthYear.value;
			var month = monthYear.substring(0,monthYear.length-4);
			var year = monthYear.substring(monthYear.length-4);
			var date = theForm.checkInDate.selectedIndex;
			var outDateObj = new Date(year, month, date+1);
			theForm.checkOutMonthYear.value = "" + outDateObj.getMonth() + outDateObj.getYear();
			//We have set the checkOutMonthYear, now see how to set the date field
			if((theForm.checkOutMonthYear.selectedIndex != theForm.checkInMonthYear.selectedIndex) ||
				(outDateObj.getDate() > theForm.checkOutDate.selectedIndex)) {
				theForm.checkOutDate.selectedIndex = outDateObj.getDate();
			}
		}
	}
}
