var formArray = new Array("airForm","hotForm","carForm");

function formFocus(formName) {
	for(var i=0; i<formArray.length; i++) {
	document.getElementById(formArray[i]).style.display = "none";
	}
	document.getElementById(formName).style.display = "block";
}

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;
	}
	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 ) {
	var value = 0;

	var today = new Date()
	var theYear = parseInt( today.getYear(), 10 )

	if( mthIdx < today.getMonth() ) {
		theYear = ( parseInt( today.getYear(), 10 ) + 1 )
	}
	if( theYear < 100 ) {
		theYear = "19" + theYear
	} else {
		if( ( theYear - 100 ) < 10 ) {
			theYear = "0" + ( theYear - 100 )
		} else {
			theYear = ( theYear - 100 ) + ""
		}
			theYear = "20" + theYear
	}
	
	var numDays = getDaysInMonth( mthIdx, theYear );

	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;
}

//changes departure month when arrival month is changed
function amadChange( inM, inD, outM, outD ) {
	if ( !isBrowserSupp() ) {
		return;
	}

	var res = adjustDate( inM.options.selectedIndex, inD );
	if( res != 0 ) {
		outD.options.selectedIndex = 0;
		if ( outM.options.selectedIndex == 11 ) {
			outM.options.selectedIndex = 0
		} else {
			outM.options.selectedIndex=inM.options.selectedIndex + 1;
			outD.options.selectedIndex = 1;
		}
	} else {
		outM.options.selectedIndex = inM.options.selectedIndex;
		if (outD.options.selectedIndex <= inD.options.selectedIndex) {
			outD.options.selectedIndex = inD.options.selectedIndex + 2;
		}
	}
	return;
}


	function dmddChange( outM, outD ) {
	if ( !isBrowserSupp() ) {
		return;
	}

	adjustDate( outM.options.selectedIndex, outD );
	return;
	}



 function OpenWindow(file, name, width, height) {
	OpenWindow(file, name, width, height, false);
	}

	function OpenWindow(file, name, width, height, showLeftTopScrollbar) {
	var attr = "";
	if(showLeftTopScrollbar) {
		attr += "top=50,left=50,scrollbars=1,";
	}
	attr += "width=" + width + ",height=" + height + ",resizeable=1";
	window.open(file, name, attr);
	}

	function openWin(fileName) {
	   thor = window.open(fileName,'thor','top=200,left=220,width=275,height=450,resizable=1,scrollbars=yes');
	}

	function openWindow(fileName)
	{
	   thor = window.open(fileName,'thor','top=200,left=220,width=275,height=450,resizable=1,scrollbars=yes');
	}

   function loadAirDates() {
	var airArrival = new Date();
	var airDeparture = new Date();

	var airAdvanceArrival = 14;
	var airAdvanceDeparture = 15;

	airArrival.setDate( airArrival.getDate() + airAdvanceArrival );
	airDeparture.setDate( airDeparture.getDate() + airAdvanceDeparture );

	document.getElementById('airForm').departureMonth.value = airArrival.getMonth();
	document.getElementById('airForm').returnMonth.value = airDeparture.getMonth();
	document.getElementById('airForm').departureDay.value = airArrival.getDate();
	document.getElementById('airForm').returnDay.value = airDeparture.getDate();
	}

   function loadCarDates() {
	var carArrival = new Date();
	var carDeparture = new Date();

	var carAdvanceArrival = 7;
	var carAdvanceDeparture = 8;

	carArrival.setDate( carArrival.getDate() + carAdvanceArrival );
	carDeparture.setDate( carDeparture.getDate() + carAdvanceDeparture );

	document.getElementById('carForm').pickUpMonth.value = carArrival.getMonth();
	document.getElementById('carForm').dropOffMonth.value = carDeparture.getMonth();
	document.getElementById('carForm').pickUpDay.value = carArrival.getDate();
	document.getElementById('carForm').dropOffDay.value = carDeparture.getDate();
	}

   function loadHotelDates() {
	var hotelArrival = new Date();
	var hotelDeparture = new Date();

	var hotelAdvanceArrival = 21;
	var hotelAdvanceDeparture = 23;

	hotelArrival.setDate( hotelArrival.getDate() + hotelAdvanceArrival );
	hotelDeparture.setDate( hotelDeparture.getDate() + hotelAdvanceDeparture );

	document.getElementById('hotForm').arrivalMonth.value = hotelArrival.getMonth();
	document.getElementById('hotForm').departureMonth.value = hotelDeparture.getMonth();
	document.getElementById('hotForm').arrivalDay.value = hotelArrival.getDate();
	document.getElementById('hotForm').departureDay.value = hotelDeparture.getDate();
	}

   function loadDefaultDates() {
	var airArrival = new Date();
	var airDeparture = new Date();
	var carArrival = new Date();
	var carDeparture = new Date();
	var hotelArrival = new Date();
	var hotelDeparture = new Date();

	var hotelAdvanceArrival = 21;
	var hotelAdvanceDeparture = 23;
	var carAdvanceArrival = 7;
	var carAdvanceDeparture = 8;
	var airAdvanceArrival = 14;
	var airAdvanceDeparture = 15;

	airArrival.setDate( airArrival.getDate() + airAdvanceArrival );
	airDeparture.setDate( airDeparture.getDate() + airAdvanceDeparture );
	carArrival.setDate( carArrival.getDate() + carAdvanceArrival );
	carDeparture.setDate( carDeparture.getDate() + carAdvanceDeparture );
	hotelArrival.setDate( hotelArrival.getDate() + hotelAdvanceArrival );
	hotelDeparture.setDate( hotelDeparture.getDate() + hotelAdvanceDeparture );

	document.getElementById('airForm').departureMonth.value = airArrival.getMonth();
	document.getElementById('airForm').returnMonth.value = airDeparture.getMonth();
	document.getElementById('airForm').departureDay.value = airArrival.getDate();
	document.getElementById('airForm').returnDay.value = airDeparture.getDate();

	document.getElementById('carForm').pickUpMonth.value = carArrival.getMonth();
	document.getElementById('carForm').dropOffMonth.value = carDeparture.getMonth();
	document.getElementById('carForm').pickUpDay.value = carArrival.getDate();
	document.getElementById('carForm').dropOffDay.value = carDeparture.getDate();

	document.getElementById('hotForm').arrivalMonth.value = hotelArrival.getMonth();
	document.getElementById('hotForm').departureMonth.value = hotelDeparture.getMonth();
	document.getElementById('hotForm').arrivalDay.value = hotelArrival.getDate();
	document.getElementById('hotForm').departureDay.value = hotelDeparture.getDate();

	}

	function loadDates()
	{
	var calendar = new Date();
	var calendar2 = new Date();
	var cal
	var cal2
	var date;
	var month;
	var year;
	var date2;
	var month2;
	var year2;

	//Here is the variable to change for to advance the arrival Date
	 var advanceArrival = 14;

	//Here is the variable to change for to advance the departure Date
	 var advanceDeparture = 16;


	//Set the arrival Days
	calendar.setDate(calendar.getDate()+ advanceArrival);
	date = calendar.getDate();
	month = calendar.getMonth();

	//Set the Departure Days
	calendar2.setDate(calendar2.getDate()+advanceDeparture);
	date2 = calendar2.getDate();
	month2 = calendar2.getMonth();

	document.forms['myform'].arrivalMonth.value=month;
	document.forms['myform'].arrivalDay.value=date;
	document.forms['myform'].departureMonth.value=month2;
	document.forms['myform'].departureDay.value=date2;
	}

	function validateDepWindow(formName) {
	if (document.forms[formName].tempDepTime[document.forms[formName].tempDepTime.selectedIndex].value==('M')) {
		window.document.forms[formName].tripWindow.value='5';
		window.document.forms[formName].departureTime.value='7AM';
	} else if (document.forms[formName].tempDepTime[document.forms[formName].tempDepTime.selectedIndex].value==('A')) {
		window.document.forms[formName].tripWindow.value='5';
		window.document.forms[formName].departureTime.value='3PM';
	} else if (document.forms[formName].tempDepTime[document.forms[formName].tempDepTime.selectedIndex].value==('E')) {
		window.document.forms[formName].tripWindow.value='5';
		window.document.forms[formName].departureTime.value='8PM';
	} else if(document.forms[formName].tempDepTime[document.forms[formName].tempDepTime.selectedIndex].value==('ANT')) {
		window.document.forms[formName].tripWindow.value='9';
		window.document.forms[formName].departureTime.value='12PM';
	} else {
		window.document.forms[formName].tripWindow.value='5';
		window.document.forms[formName].departureTime.value=document.forms[formName].tempDepTime.value;
	}
	}

	function validateRetWindow(formName) {
	if (document.forms[formName].tempRetTime[document.forms[formName].tempRetTime.selectedIndex].value==('M')) {
		window.document.forms[formName].returnTime.value='7AM';
	} else if (document.forms[formName].tempRetTime[document.forms[formName].tempRetTime.selectedIndex].value==('A')) {
		window.document.forms[formName].returnTime.value='3PM';
	} else if (document.forms[formName].tempRetTime[document.forms[formName].tempRetTime.selectedIndex].value==('E')) {
		window.document.forms[formName].returnTime.value='8PM';
	} else if(document.forms[formName].tempRetTime[document.forms[formName].tempRetTime.selectedIndex].value==('ANT')) {
		window.document.forms[formName].returnTime.value='12PM';
	} else {
		window.document.forms[formName].returnTime.value=window.document.forms[formName].tempRetTime.value;
	}
	   }