/*
-------------------------------------------------------------------------------------------
				 WATSON DATE ERROR CHECKING FUNCTIONS
-------------------------------------------------------------------------------------------
*/
function okCheckDates() {
	if (f.ciDate.value != 'MM/DD/YYYY'){
		var checkIn = new validDate(f.ciDate);
		if (!checkIn.valid ) {
			// check-in date not valid
			setErrCode(19);
		}
	}
	
	if (f.coDate.value != 'MM/DD/YYYY'){
		var checkOut = new validDate(f.coDate);	
		if (!checkOut.valid) {
			// check-out date not valid
			setErrCode(20);
		}
	}	
		
	if (f.ciDate.value != 'MM/DD/YYYY' && f.coDate.value != 'MM/DD/YYYY'){
		if ( (checkIn.valid) & (checkOut.valid) ) {
			// check for other date validation
			//alert("datesCheck(" + checkIn.d + ", " + checkOut.d);
			datesCheck(checkIn, checkOut);
		}
	}
}

// this function takes Dates, not validDates()
function datesCheck(checkIn, checkOut) {
	checkIn.setField();
	var datesDelta = checkOut.d.getTime() - checkIn.d.getTime();
	var nowDelta = checkIn.diffDate(new Date());
	var datesEqual = (checkIn.d.getTime() == checkOut.d.getTime());
	
	// begin 550 day check
		var today = new Date();
		today.setHours(0);
		today.setMinutes(0);
		today.setSeconds(0);
		today.setMilliseconds(0);
		var limit = new Date(550 * 24 * 60 * 60 * 1000);
		/*have to add the 1 hr in millis because of the possibility of daylight savings time removing an hour.*/
		var isTooLong = (checkOut.d.getTime() - today.getTime() >= (limit.getTime() - (60*60*1000))) ? true : false;
	// end 550 day check
	
	if (nowDelta < 0 ) {
		// Error : checkin date before today
		setErrCode(9);
	} else if (datesEqual) {
		// Error : checkin date = checkout date
		setErrCode(11);
	} else if (isTooLong) {
		// Error : too far out in the future (> 550 days or 18 months)
		setErrCode(13);
	} else if (datesDelta < 0) {
		// Error : checkin date after checkout date
		setErrCode(10);
	} else if (datesDelta > 1000*60*60*24*30) {
		// Error : stay too long (> 30 days or 1 month)
		setErrCode(12);
	}
}