var localForm; 
function initForm(theForm) 
{ 
   localForm = theForm;
}
function MonthName(strMonth)
{
	if (strMonth==0)
	{
		return ("January");
	}
	if (strMonth==1)
	{
		return("February");
	}
	if (strMonth==2)
	{
		return("March");
	}
	if (strMonth==3)
	{
		return("April");
	}
	if (strMonth==4)
	{
		return("May");
	}
	if (strMonth==5)
	{
		return("June");
	}
	if (strMonth==6)
	{
		return("July");
	}
	if (strMonth==7)
	{
		return("August");
	}
	if (strMonth==8)
	{
		return("September");
	}
	if (strMonth==9)
	{
		return("October");
	}
	if (strMonth==10)
	{
		return("November");
	}
	if (strMonth==11)
	{
		return("December");
	}
}
// Checks if browser is Netscape 2.0x since the options array properties don't work with Netscape 2.0x
function isBrowserSupp() {

    // Get the version of the browser
    version =  parseFloat( navigator.appVersion );

    if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
        return false;
    }
    else {
	return true;
    }
}


function isLeapYear(yrStr)
{
var leapYear=false;
var year = parseInt(yrStr, 10);
// every fourth year is a leap year
if (year%4 == 0)
	{
	leapYear=true;
	// unless it's a multiple of 100
	if (year%100 == 0)
		{
		leapYear=false;
		// unless it's a multiple of 400
		if (year%400 == 0)
			{
			leapYear=true;
			}
		}
	}
return leapYear;
}


function getDaysInMonth(mthIdx, YrStr)
{
// all the rest have 31
var maxDays=31
// expect Feb. (of course)
if (mthIdx==1) 
	{
	if (isLeapYear(YrStr))
		{
		maxDays=29;
		}
	else 
		{
		maxDays=28;
		}
	}
// thirty days hath...
if (mthIdx==3 || mthIdx==5 || mthIdx==8 || mthIdx==10)
	{
	maxDays=30;
	}
return maxDays;
}


//the function which does some magic to the date fields
// return non-zero if it is the last day of the month
function adjustDate(mthIdx, Dt, Yr) 
{
var value=0; 		
var numDays=getDaysInMonth(mthIdx, Yr.options[Yr.options.selectedIndex].text);

if (mthIdx==1) 
	{
	if (Dt.options.selectedIndex + 1 < numDays)
		{
		return 0;
		}
	else 
		{
		Dt.options.selectedIndex=numDays - 1;
		//check for leap year
		if (numDays==29)
			{
			return 99;
			}
		else 
			{
			return 1;
			}
		}
	}
if (Dt.options.selectedIndex + 1 < numDays)
	{
	value=0;
	}
else 
	{
	if (Dt.options.selectedIndex + 1 > numDays)
		{
		Dt.options.selectedIndex--;
		value=3;
		}
	else 
		{
		//index is 31 or 30
		value=2;
		}
	}
return value;
}

// Get the index of the corresponding option in the field's list
function getIndex (val, field) {
	var i;
	for (i = 0; i < field.length; i++) {
		if (val == field.options[i].text) {
			return i;
		}
	}
	return -1;
}


//changes departure month when arrival month is changed
function inMonthChange( inM, outM, inD, outD, inY, outY ) {

	if ( !isBrowserSupp() ) {

		return;
	}

	var res = adjustDate(inM.options.selectedIndex, inD,inY);

	if ( res != 0 ) {
		outD.options.selectedIndex=0;
		outM.options.selectedIndex = inM.options.selectedIndex + 1;
	} else {
		outM.options.selectedIndex = inM.options.selectedIndex;
		outD.options.selectedIndex = inD.options.selectedIndex + 2;
	}

	// Set the out year to the same as the in year
	outY.options.selectedIndex = inY.options.selectedIndex;

	var currentMonth = ( new Date() ).getMonth();
    
	// If the in date is 12/31/?? set the out date to 01/01/??
	if ( ( inM.options.selectedIndex == 11 ) && ( inD.options.selectedIndex == 30 ) ) {
		outM.options.selectedIndex=0;
		outY.options.selectedIndex++;
	}

	// If the selected month is before the current month, increment the in year.
	if ( ( inM.options.selectedIndex < currentMonth ) && (inY.options.selectedIndex == 0 ) ) {

		// First make sure it is a valid selection
		if ( inY.selectedIndex < ( inY.options.length - 1 ) )
			inY.options.selectedIndex++;

		// Now set the out year to the same as the in year
		outY.options.selectedIndex = inY.options.selectedIndex;		
	}

	return;
}
	

//changes departure day when arrival day is changed
function inDayChange(inD, outD, inM, outM, inY, outY) 
{
if (!isBrowserSupp())
	{
 	return;
	}			
var Inmth = inM.options.selectedIndex;

var res =adjustDate(Inmth, inD, inY)
if (res != 0)
	{
	outD.options.selectedIndex=0;
	outM.options.selectedIndex=inM.options.selectedIndex + 1;
	}
else
	{
	outM.options.selectedIndex = inM.options.selectedIndex;
	outD.options.selectedIndex = inD.options.selectedIndex+2;
	}
outY.options.selectedIndex = inY.options.selectedIndex;
if ((inM.options.selectedIndex == 11) && (inD.options.selectedIndex == 30))
	{
	outM.options.selectedIndex=0;
	outY.options.selectedIndex++;
	}
return;
}
	

//changes departure year when arrival year is changed
function inYearChange(inY, outY, inM, outM, inD, outD) 
{
if (!isBrowserSupp()) 
	{
	return;			
	}

outY.options.selectedIndex = inY.options.selectedIndex;
adjustDate(inM.options.selectedIndex, inD,inY);
return;
}	

function closeCalendar(io)
{
if (io=='CheckIn')
{
var arrMonthField = document.frmRoomInventory.elements["CheckIn-month"];
var arrDayField   = document.frmRoomInventory.elements["CheckIn-day"];
var arrYearField  = document.frmRoomInventory.elements["CheckIn-year"];
var depMonthField = document.frmRoomInventory.elements["CheckOut-month"];
var depDayField   = document.frmRoomInventory.elements["CheckOut-day"];
var depYearField  = document.frmRoomInventory.elements["CheckOut-year"];

var res = adjustDate(arrMonthField, arrDayField, arrYearField); 
if (res != 0)
	{
	depDayField.options.selectedIndex=0;
	depMonthField.options.selectedIndex = arrMonthField.options.selectedIndex+1;
	}
else 
	{
	depMonthField.options.selectedIndex = arrMonthField.options.selectedIndex;
	depDayField.options.selectedIndex = arrDayField.options.selectedIndex+1;
	}
depYearField.options.selectedIndex = arrYearField.options.selectedIndex;
if ((arrMonthField.options.selectedIndex == 11) && (arrDayField.options.selectedIndex == 30))
	{
	depMonthField.options.selectedIndex=0;
	depYearField.options.selectedIndex++;
	}
}
return;
}
function getSMSdates(inday,outday,inmonth,outmonth,inyear,outyear,RtReq,resGroup,resSource)
{
	document.forms[0].inday.value = inday;
	document.forms[0].outday.value = outday;
	document.forms[0].inmonth.value = inmonth;
	document.forms[0].outmonth.value = outmonth;
	document.forms[0].inyear.value = inyear;
	document.forms[0].resGroup.value = resGroup;
	document.forms[0].RtReq.value = RtReq;
	document.forms[0].resSource.value = resSource;
	document.forms[0].outyear.value = outyear;
//alert(inday + "," + outday + "," + inmonth + "," + outmonth + "," + inyear + "," + outyear + "," + RtReq + "," + resSource);
	//document.forms[0].submit();
}
function getSMSdates1(inday,outday,inmonth,outmonth,inyear,outyear,resGroup,resSource)
{
	document.forms[0].inday.value = inday;
	document.forms[0].outday.value = outday;
	document.forms[0].inmonth.value = inmonth;
	document.forms[0].outmonth.value = outmonth;
	document.forms[0].inyear.value = inyear;
	document.forms[0].resGroup.value = resGroup;
	document.forms[0].resSource.value = resSource;
	document.forms[0].outyear.value = outyear;
//alert(inday + "," + outday + "," + inmonth + "," + outmonth + "," + inyear + "," + outyear + "," + RtReq + "," + resSource);
	//document.forms[0].submit();
}
