function CS_IsValidDateBox(source, arguments){

	var txtDateBox = document.getElementById(source.datebox);
	arguments.IsValid = CS_IsValidDate(txtDateBox.value);
}

function CS_IsValidDate(strDate){

	// we consider a blank string valid to allow for times when date is not required.
	// if blank is logically not valid, you should use a required field validator or check
	// for blank in the calling script.
	if (strDate == '') return true;
	
	var dateBits = DateComponents(strDate);

	if (dateBits == null) return false;

	var month = dateBits[0];
	var day = dateBits[1];
	var year = dateBits[2];

	if ((month < 1 || month > 12) || (day < 1 || day > 31)) { // check month range 
		return false;
	} 
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		return false;
	}

	if (month == 2) {
		// check for february 29th 
		var isLeapYear = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); 

		if (day>29 || (day==29 && !isLeapYear)) {
			return false;
		}
	} 

	return true;
}

function DateComponents(strDate) {
	var results = new Array();
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = strDate.match(datePat);

	if (matchArray == null) return null; 
	
	// parse date into variables
	results[0] = matchArray[1];
	results[1] = matchArray[3]; 
	results[2] = matchArray[4];

	return results;
} 
