

function validate() {
	if ( document.thisform.departCity.selectedIndex < 1 || document.thisform.returnCity.selectedIndex < 1 ) { 
		alert('You must select a departure and arrival.');
		return false;
	}
	return true;
}

function adjustDaysInMonth(objName,setdate) {
	if ( objName == 'DEPDATE' ) {
		fday = 'depDay';
		fmonth = 'depMonth';
		fyear = 'depYear';
	} else {
		fday = 'retDay';
		fmonth = 'retMonth';
		fyear = 'retYear';
	}

	this.today        	= new Date();
	this.date           = this.today.getDate();
	this.month          = this.today.getMonth()+1;
	this.year           = this.today.getFullYear();
	MonthText = document.thisform[fmonth].options[document.thisform[fmonth].selectedIndex].value;
	
	if ( MonthText == 'JAN') { Month = 1; }
	if ( MonthText == 'FEB') { Month = 2; }
	if ( MonthText == 'MAR') { Month = 3; }
	if ( MonthText == 'APR') { Month = 4; }
	if ( MonthText == 'MAY') { Month = 5; }
	if ( MonthText == 'JUN') { Month = 6; }
	if ( MonthText == 'JUL') { Month = 7; }
	if ( MonthText == 'AUG') { Month = 8; }
	if ( MonthText == 'SEP') { Month = 9; }
	if ( MonthText == 'OCT') { Month = 10; }
	if ( MonthText == 'NOV') { Month = 11; }
	if ( MonthText == 'DEC') { Month = 12; }
	
	if ( Month < this.month ) {
		Year = this.year+1;
	} else {
		Year = this.year;
	}
	DaysForThisSelection = getDaysInMonth(Month, Year);
	PrevDaysInSelection = document.thisform[fday].length;

	if (PrevDaysInSelection > DaysForThisSelection) {
		for (i=0; i<(PrevDaysInSelection-DaysForThisSelection); i++) {
			document.thisform[fday].options[document.thisform[fday].options.length - 1] = null;
		}
	}
	
	if (DaysForThisSelection > PrevDaysInSelection) {
		var prevLastDay = document.thisform[fday].options.length;
		for( i = prevLastDay+1; i <= DaysForThisSelection; i++ ) {
			var newOption = new Option( i, i );
			var optionsColl = document.thisform[fday].options;
			optionsColl[optionsColl.length] = newOption;
		}
	}
	if (document.thisform[fday].selectedIndex < 0) {
		document.thisform[fday].selectedIndex == 0;
	}
	Day = document.thisform[fday].selectedIndex + 1;
	if ( setdate < 1 ) {
		adjustDateField(objName,Year,Month,Day);
	}
}

function adjustDaysTextField(objName) {
	if ( objName == 'DEPDATE' ) {
		fdate = 'DEPDATE';
		fday = 'depDay';
		fmonth = 'depMonth';
		fyear = 'depYear';
	} else {
		fdate = 'RETDATE';
		fday = 'retDay';
		fmonth = 'retMonth';
		fyear = 'retYear';
	}
	this.today        	= new Date();
	this.date           = this.today.getDate();
	this.month          = this.today.getMonth()+1;
	this.year           = this.today.getFullYear();
	MonthText = document.thisform[fmonth].options[document.thisform[fmonth].selectedIndex].value;
	//alert( MonthText );
	
	if ( MonthText == 'JAN') { Month = 1; }
	if ( MonthText == 'FEB') { Month = 2; }
	if ( MonthText == 'MAR') { Month = 3; }
	if ( MonthText == 'APR') { Month = 4; }
	if ( MonthText == 'MAY') { Month = 5; }
	if ( MonthText == 'JUN') { Month = 6; }
	if ( MonthText == 'JUL') { Month = 7; }
	if ( MonthText == 'AUG') { Month = 8; }
	if ( MonthText == 'SEP') { Month = 9; }
	if ( MonthText == 'OCT') { Month = 10; }
	if ( MonthText == 'NOV') { Month = 11; }
	if ( MonthText == 'DEC') { Month = 12; }
	
	if ( Month < this.month ) {
		Year = this.year+1;
	} else {
		Year = this.year;
	}
	Day = document.thisform[fday].selectedIndex + 1;
	adjustDateField(objName,Year,Month,Day);
}

function adjustDateField(objName,Year,Month,Day) {
	if ( objName == 'DEPDATE' ) {
		fdate = 'DEPDATE';
		fday = 'depDay';
		fmonth = 'depMonth';
		fyear = 'depYear';
	} else {
		fdate = 'RETDATE';
		fday = 'retDay';
		fmonth = 'retMonth';
		fyear = 'retYear';
	}
	if ( Month < 10 ) { Month = "0"+Month; }
	if ( Day < 10 ) { Day = "0"+Day; }
	document.thisform[fdate].value = Year+"-"+Month+"-"+Day;	
}

function adjustHiddenDate(target,str_datetime) {
	if ( target == 'DEPDATE' ) {
		fday = 'depDay';
		fmonth = 'depMonth';
		fyear = 'depYear';
	} else {
		fday = 'retDay';
		fmonth = 'retMonth';
		fyear = 'retYear';
	}
	datearray = str_datetime.split("-");
	strg = datearray[0]+"-"+datearray[1]+"-"+datearray[2]
	
	document.thisform[target].value = strg;
	Month = datearray[1];
	//first set the month, 
	if ( Month == 1  || Month == '01' ) { MonthText = 'JAN'; }
	if ( Month == 2  || Month == '02' ) { MonthText = 'FEB'; }
	if ( Month == 3  || Month == '03' ) { MonthText = 'MAR'; }
	if ( Month == 4  || Month == '04' ) { MonthText = 'APR'; }
	if ( Month == 5  || Month == '05' ) { MonthText = 'MAY'; }
	if ( Month == 6  || Month == '06' ) { MonthText = 'JUN'; }
	if ( Month == 7  || Month == '07' ) { MonthText = 'JUL'; }
	if ( Month == 8  || Month == '00' ) { MonthText = 'AUG'; }
	if ( Month == 9  || Month == '09' ) { MonthText = 'SEP'; }
	if ( Month == 11 || Month == '10' ) { MonthText = 'OCT'; }
	if ( Month == 11 || Month == '11' ) { MonthText = 'NOV'; }
	if ( Month == 12 || Month == '12' ) { MonthText = 'DEC'; }
	
	m2 = document.thisform[fmonth];
	m2len = document.thisform[fmonth].length;
	for ( i=0; i<m2len ; i++){
		if ( m2.options[i].value == MonthText ) {
			m2.options[i].selected = true;
		} else {
			m2.options[i].selected = false;
		}
	}
	Day = datearray[2];
	adjustDaysInMonth(target,Day);
	Day = datearray[2];
	m2 = document.thisform[fday];
	m2len = document.thisform[fday].length;
	for ( i=0; i<m2len ; i++){
		if ( m2.options[i].value == Day ) {
			m2.options[i].selected = true;
		} else {
			m2.options[i].selected = false;
		}
	}
}

function getDaysInMonth( m, y ) {
	var monthdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	if (m != 2) {
		return monthdays[m];
	} else {
		return ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0 ? 29 : 28);
	}
}

function MM_openBrWindow(theURL,winName,features) { 
	window.open(theURL,winName,features);
}

