

function ValidateFlightDate(fnum,fld)
{
var errMsg = "Date must be entered in DD/MM/YYYY format.\n\nFor example, you would enter 25 January 2003 as 25/01/2003."
var ValidDate = 1
var ValidDateM = 1
var ValidDateD = 1
var GivenDate = document.Form1[fld].value
if (GivenDate != ""){
var DOM
var MOY
var YOC
var c1Array = "0123"
var cGenArray = "1234567890"
var c4Array = "01"
var c7Array = "234"
MaxDays = new Array(12)
MaxDays[1] = 31;
MaxDays[2] = 29;
MaxDays[3] = 31;
MaxDays[4] = 30;
MaxDays[5] = 31;
MaxDays[6] = 30;
MaxDays[7] = 31;
MaxDays[8] = 31;
MaxDays[9] = 30;
MaxDays[10] = 31;
MaxDays[11] = 30;
MaxDays[12] = 31;
// if it's not ten characters long it's not valid
if (GivenDate.length != 10){ValidDate = 0}
// check each character against possible valid values
if (c1Array.indexOf(GivenDate.charAt(0)) == -1){ValidDate = 0}
if (cGenArray.indexOf(GivenDate.charAt(1)) == -1){ValidDate = 0}
if (GivenDate.charAt(2) != "/"){ValidDateD = 0}
if (c4Array.indexOf(GivenDate.charAt(3)) == -1){ValidDate = 0}
if (cGenArray.indexOf(GivenDate.charAt(4)) == -1){ValidDate = 0}
if (GivenDate.charAt(5) != "/"){ValidDateM = 0}
if (c7Array.indexOf(GivenDate.charAt(6)) == -1){ValidDate = 0}
if (cGenArray.indexOf(GivenDate.charAt(7)) == -1){ValidDate = 0}
if (cGenArray.indexOf(GivenDate.charAt(8)) == -1){ValidDate = 0}
if (cGenArray.indexOf(GivenDate.charAt(9)) == -1){ValidDate = 0}
if (ValidDateD != 0 && ValidDateM != 0){
validDate = 0
}
if (ValidDate != 0){
Parts = GivenDate.split("/")
DOM = Parts[0]
if (DOM.charAt(0) == "0"){DOM = DOM.charAt(1)}
MOY = Parts[1]
if (MOY.charAt(0) == "0"){MOY = MOY.charAt(1)}
YOC = Parts[2]
DOMInt = parseInt(DOM)
MOYInt = parseInt(MOY)
YOCInt = parseInt(YOC)
MaxInMonth = MaxDays[MOYInt]
// check for valid day of the month
if (DOMInt > MaxInMonth)
	{
	ValidDate = 0
	errMsg = GivenDate + " can not be interpreted as a valid date.\n\n" + errMsg
	}
// check for valid month of the year
if (MOYInt > 12)
	{
	ValidDate = 0
	errMsg = GivenDate + " can not be interpreted as a valid date.\n\n" + errMsg
	}
// check that the year is 2002 or later
if (YOCInt < 2002)
	{
	ValidDate = 0
	errMsg = "The date you enter must be on or after the year 2002.\n\n" + errMsg
	}
}
// Let them get away with no date at all
if(GivenDate == "")(ValidDate = 1)
// thow up a message and send them back to the field if false (ValidDate = 0)
	with (document.Form1) { 
		if (fnum == 1){
			flightdetails = dnr_flightselect1.options[dnr_flightselect1.selectedIndex].value
			fd2index = dnr_flightselect1.selectedIndex
		}else{
			flightdetails = dnr_flightselect2.options[dnr_flightselect2.selectedIndex].value
			fd2index = dnr_flightselect2.selectedIndex
		
		}
	   // main inbound flight
			if (fd2index > 0){
				fillflights(fnum)
			}else{
				if (ValidDate == 0){
					alert (errMsg)
					document.Form1[fld].focus()
					return false
				}
			}
	}
}
	
//function fullproductinfo(theURL,winName,features) {
//var features = 'scrollbars=yes,resizable=yes,width=10,height=10'
//if(document.theForm.ArrivalDateH.value != "" && document.theForm.DepartureDateH.value != ""){
//var theURL =  "../scripts/calcday.cfm?arrivaldate=" + document.theForm.ArrivalDateH.value + "&departuredate=" + document.theForm.DepartureDateH.value
//fullproductinfo('more_product_info.cfm?itemid=#stockid#','productpage','scrollbars=yes,resizable=yes,width=650,height=305')"
//remote = window.open(theURL,"remotewin",features);
 //remote.location.href = "more_product_info.htm";
 //remote.focus()	
 //}
}





