/**
 * 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(theForm, brand, region, locale, secure)
{
	var cDate = theForm.checkInDate[theForm.checkInDate.selectedIndex].value;
	if(cDate == null || cDate == ""){
	    cDate = "-1";
	}
	var cMonthYear = theForm.checkInMonthYear[theForm.checkInMonthYear.selectedIndex].value;
	var url = '/h/d/' + brand + '/' + region + '/' + locale + '/calendar?cmJourney=true&test=grb&openerForm=' + theForm.name + '&monthYear=' + cMonthYear + '&date=' + cDate + '&checkOut=false&secure=' + secure;
	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=225,height=230,screenX=' + leftPos + ',screenY=' + topPos + ',titlebar=yes');
	}
	newWin.focus();
	return false;
}


function openCalendarCheckOut(theForm, brand, region, locale, secure)
{
	var cDate = theForm.checkOutDate[theForm.checkOutDate.selectedIndex].value;
	if(cDate == null || cDate == ""){
	    cDate = "-1";
	}
	var cMonthYear = theForm.checkOutMonthYear[theForm.checkOutMonthYear.selectedIndex].value;
	var url = '/h/d/' + brand + '/' + region + '/' + locale + '/calendar?cmJourney=true&test=grb&openerForm=' + theForm.name + '&monthYear=' + cMonthYear + '&date=' + cDate + '&checkOut=true&secure=' + secure;
	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=225,height=230,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);


			var year = outDateObj.getYear();
			if(year.toString().length == 3)
				year = 2000 + (outDateObj.getYear() % 100);
			theForm.checkOutMonthYear.value = "" + outDateObj.getMonth() + year;

			//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();
			}
		}
	}
}
