// ** BEGIN GENERAL FUNCTIONS **function isEmpty(inputStr) {	if (inputStr == "" || inputStr == null) {		return true		}	return false}function inRange(inputStr, lo, hi) {	var num = parseInt(inputStr, 10)	if (num < lo || num > hi) {		return false		}	return true}// extract front part of string prior to searchStringfunction getFront(mainStr,searchStr) {	foundOffset = mainStr.indexOf(searchStr)	if (foundOffset == -1) {		return null		}	return mainStr.substring(0,foundOffset)}// extract back end of string after searchStringfunction getEnd(mainStr,searchStr) {	foundOffset = mainStr.indexOf(searchStr)	if (foundOffset == -1) {		return null	}	return mainStr.substring(foundOffset+searchStr.length,mainStr.length)}// replace searchString with replaceStringfunction replaceString(mainStr,searchStr,replaceStr) {	var front = getFront(mainStr,searchStr)	var end = getEnd(mainStr,searchStr)	if (front != null && end != null) {		return front + replaceStr + end	}	return null} function select(field) { 	field.focus() 	field.select() } // ** END GENERAL FUNCTIONS **// ** BEGIN DATE VALIDATION **function checkDate(field) {	var inputStr = field.value	if (!isEmpty(inputStr)) {		// convert hypen delimiters to slashes		while (inputStr.indexOf("-") != -1) {			inputStr = replaceString(inputStr,"-","/")		}		var delim1 = inputStr.indexOf("/")		var delim2 = inputStr.lastIndexOf("/")		if (delim1 != -1 && delim1 == delim2) {			//there is only one delimiter in the string			alert("The date entered is not in an acceptable format.\n\nPlease use the following format:\nm/d/y, or m-d-y.")			select(field)			return false		}		if (delim1 != -1) {			var mm = parseInt(inputStr.substring(0,delim1),10)			var dd = parseInt(inputStr.substring(delim1 + 1,delim2),10)			var yyyy = parseInt(inputStr.substring(delim2 + 1, inputStr.length),10)		}		if (isNaN(mm) || isNaN(dd) || isNaN(yyyy)) {			// there is a non-numeric character in one of the component values			alert("The date entered is not in an acceptable format.\n\nYou can enter dates in the following formats:\nm/d/y, or m-d-y.")			select(field)			return false		}		if (!inRange(mm,1,12)){			// month value is not 1 through 12			alert("Months must be entered between the range of 01 (January) and 12 (December).")			select(field)			return false		}		if (dd < 1 || dd > 31) {			// date value is not 1 through 31			alert("Days must be entered between the range of 01 and a maximum of 31.")			select(field)			return false		}		if (yyyy <=10) {			// entered value is two digits, which we allow for 2000-2010			yyyy += 2000		}		if (!checkMonthLength(mm,dd)) {			select(field)			return false		}		if (mm == 2 && (!checkLeapMonth(mm,dd,yyyy))) {			select(field)			return true		}		// return date as string to field		field.value = monthDayFormat(mm) + "/" + monthDayFormat(dd) + "/" + yyyy		return true	}}// check the entered month for too high a valuefunction checkMonthLength(mm,dd) {	var months = new Array("","January", "February","March","April","May","June","July","August","September","October","November","December")	if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30) {		alert(months[mm] + " has only 30 days.")		return false	} else  if (dd > 31) {		alert(months[mm] + "has only 31 days.")		return false	}	return true}// check the entered February date for too high a valuefunction checkLeapMonth(mm,dd,yyyy) {	if (yyyy % 4 > 0 && dd > 28) {		alert("February of " + yyyy + " has only 28 days.")		return false		} else if (dd > 29) {		alert("February of " + yyyy + " has only 29 days.")		return false	}	return true}// convert month or day number to string,// padding with leading zero if neededfunction monthDayFormat(val) {          if (isNaN(val) || val == 0) {             alert("Month or date value is not a number.")             return false          } else if (val < 10) {             return "0" + val          }          return "" + val}// ** END DATE VALIDATION **
