function setOptionOfSelect( theSelect, optionToSelect ) {
	for ( var i = 0; i < theSelect.options.length; i++ ) {
		if ( optionToSelect == Math.round( theSelect.options[i].value ) ) {
			theSelect.options[i].selected = true;
			return true;
		}
	}
}

function initFlightSearchForm() {
	var searchForm			= document.forms['QuickFlightSearch'];
	var nowDate				= new Date();
	var nowDay				= nowDate.getDate();
	var nowMonth			= nowDate.getMonth();
	
	setOptionOfSelect( searchForm.DeptMonth, nowMonth + 1 );
	setOptionOfSelect( searchForm.DeptDay, nowDay + 7 );
	setOptionOfSelect( searchForm.ArriveMonth, nowMonth + 1 );
	setOptionOfSelect( searchForm.ArriveDay, nowDay + 14 );
}

function validateFlightSearchForm() {
	var DAY					= 24 * 60 * 60 * 1000;		//	enough of the 8.64e7 crap
	var MONTHNAME			= new Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
	var nowDate				= new Date();
	var nowDay				= nowDate.getDate();
	var nowYear				= ( nowDate.getYear() > 1900 ) ? nowDate.getYear() : nowDate.getYear() + 1900;
	
	var searchForm			= document.forms['QuickFlightSearch'];
	var selectDepartMonth	= searchForm.DeptMonth.options[searchForm.DeptMonth.selectedIndex].value;		//	May == 5
	var selectDepartDay		= searchForm.DeptDay.options[searchForm.DeptDay.selectedIndex].value;
	var selectArriveMonth	= searchForm.ArriveMonth.options[searchForm.ArriveMonth.selectedIndex].value;	//	May == 5
	var selectArriveDay		= searchForm.ArriveDay.options[searchForm.ArriveDay.selectedIndex].value;
	
	var departYear			= nowYear;
	var departDate			= new Date( departYear, selectDepartMonth - 1, selectDepartDay );	//	month is zero-based (May == 4, != 5)
	if ( departDate < nowDate - DAY ) {			//	if they depart before today, then they must be doing it next year
		departDate = new Date( ++departYear, selectDepartMonth - 1, selectDepartDay );	//	month is zero-based (May == 4, != 5)
	}
		
	var arriveYear			= departYear;
	var arriveDate			= new Date( arriveYear, selectArriveMonth - 1, selectArriveDay );	//	month is zero-based (May == 4, != 5)
	if ( arriveDate < departDate ) {		//	if they arrive before they depart, then they do it in different years
		arriveDate = new Date( ++arriveYear, selectArriveMonth - 1, selectArriveDay );	//	month is zero-based (May == 4, != 5)
	}
	
	if ( searchForm.DeptAirport.value == "City/Town" || searchForm.DeptAirport.value == "" ) {
		alert( "Please enter a Departure Airport." );
		searchForm.DeptAirport.focus();
		return false;
	}
	
	if ( searchForm.ArriveAirport.value == "City/Town" || searchForm.ArriveAirport.value == "" ) {
		alert( "Please enter an Arrival Airport." );
		searchForm.ArriveAirport.focus();
		return false;
	}
	
	if ( searchForm.DeptAirport.value == searchForm.ArriveAirport.value ) {
		alert( "Destination and Arrival Airport cannot be the same." );
		searchForm.ArriveAirport.focus();
		return false;
	}
	
	if ( Math.ceil( ( departDate - nowDate ) / DAY ) < 3 ) {
		alert( "You must book at least 3 days in advance." );
		searchForm.DeptDay.focus();
		return false;
	}
	
	if ( ( departDate - nowDate ) / DAY > 300 ) {
		alert( "You cannot book more than 300 days ahead." +
				"\\n(Departure Date = " + MONTHNAME[selectDepartMonth-1] + " " + selectDepartDay + ", " + departYear + "?)" );
		searchForm.DeptDay.focus();
		return false;
	}
	
	if ( ( arriveDate - nowDate ) / DAY > 300 ) {
		alert( "You cannot book more than 300 days ahead." +
				"\\n(Return Date = " + MONTHNAME[selectArriveMonth-1] + " " + selectArriveDay + ", " + arriveYear + "?)" );
		searchForm.ArriveDay.focus();
		return false;
	}
	
	return true;
}
