

function ValidatePPDate(fld)
{

var errMsg = "Date must be entered in DD/MM/YYYY format.\n\nFor example, you would enter 6 January 2003 as 06/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 < 2006)
	{
	ValidDate = 0
	errMsg = "The date you enter must be on or after the year 2006.\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)
if (ValidDate == 0){
	alert (errMsg)
	document.Form1[fld].focus()
	return false
	}
	}
	
}




