<!-- ;

/*
   Begin validation dispatching mechanism
*/
function dispatcher(validationFunc) {
   this.doValidate = validationFunc
}
var dispatchLookup = new Array()
dispatchLookup["isM10_P20Date"] = new dispatcher(isM10_P20Date)
dispatchLookup["isM90_M20Date"] = new dispatcher(isM90_M20Date)
dispatchLookup["isM70_0Date"] = new dispatcher(isM70_0Date)
dispatchLookup["isM5_P10Date"] = new dispatcher(isM5_P10Date)
dispatchLookup["isMandatory"] = new dispatcher(isMandatory)
dispatchLookup["isPosDecimal"] = new dispatcher(isPosDecimal)
dispatchLookup["isPosInteger"] = new dispatcher(isPosInteger)
dispatchLookup["isInteger"] = new dispatcher(isInteger)
dispatchLookup["isDecimal"] = new dispatcher(isDecimal)
dispatchLookup["isRightLength"] = new dispatcher(isRightLength)

// main validation function called by form event handlers
function validate(field, method) {
	gField =  field
	if (!dispatchLookup[method].doValidate()) {
		return false
	}
	return true
}

// Date Minus 90/Minus 20
function isM10_P20Date() {
	if (gField.value.length == 0) return true
	var thisYear = getTheYear()
	return isDate((thisYear - 10),(thisYear + 20))
}

// Date Minus 90/Minus 20
function isM90_M20Date() {
	if (gField.value.length == 0) return true
	var thisYear = getTheYear()
	return isDate((thisYear - 90),(thisYear - 20))
}

// Date Minus 70/Minus 0
function isM70_0Date() {
	if (gField.value.length == 0) return true
	var thisYear = getTheYear()
	return isDate((thisYear - 70),(thisYear))
}

// Date Minus 5/Plus 10
function isM5_P10Date() {
	if (gField.value.length == 0) return true
	var thisYear = getTheYear()
	return isDate((thisYear - 5),(thisYear + 10))
}

function getTheYear() {
	var thisYear = (new Date()).getYear()
	thisYear = (thisYear < 100)? thisYear + 1900: thisYear
	return thisYear
}

// date field validation (called by other validation functions that specify minYear/maxYear)
function isDate(minYear,maxYear,minDays,maxDays) {
	var inputStr = gField.value
	// convert hyphen 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 entry is not in an acceptable format.\n\nYou can enter dates in the following formats: ddmmyyyy, dd/mm/yyyy, or dd-mm-yyyy.  (If the month or date data is not available, enter \'01\' in the appropriate location.)")
		gField.focus()
		gField.select()
		return false
	}
	if (delim1 != -1) {
		// there are delimiters; extract component values
		var mm = parseInt(inputStr.substring(delim1 + 1,delim2),10)
		var dd = parseInt(inputStr.substring(0,delim1),10)
		var yyyy = parseInt(inputStr.substring(delim2 + 1, inputStr.length),10)
	} else {
		// there are no delimiters; extract component values
		var mm = parseInt(inputStr.substring(2,4),10)
		var dd = parseInt(inputStr.substring(0,2),10)
		var yyyy = parseInt(inputStr.substring(4,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 entry is not in an acceptable format.\n\nYou can enter dates in the following formats: ddmmyyyy, dd/mm/yyyy, or dd-mm-yyyy.")
		gField.focus()
		gField.select()
		return false
	}
	if (mm < 1 || mm > 12) {
		// month value is not 1 thru 12
		alert("Months must be entered between the range of 01 (January) and 12 (December).")
		gField.focus()
		gField.select()
		return false
	}
	if (dd < 1 || dd > 31) {
		// date value is not 1 thru 31
		alert("Days must be entered between the range of 01 and a maximum of 31 (depending on the month and year).")
		gField.focus()
		gField.select()
		return false
	}

	// validate year, allowing for checks between year ranges
	// passed as parameters from other validation functions
	if (yyyy < 100) {
		// entered value is two digits, which we allow for 1930-2029
		if (yyyy >= 30) {
			yyyy += 1900
		} else {
			yyyy += 2000
		}
	}

	var today = new Date()
	if (!minYear) {
		// function called with specific day range parameters
		var dateStr = new String(monthDayFormat(mm) + "/" + monthDayFormat(dd) + "/" + yyyy)
		var testDate = new Date(dateStr)
		if (testDate.getTime() < (today.getTime() + (minDays * 24 * 60 * 60 * 1000))) {
			alert("The most likely range for this entry begins " + minDays + " days from today.")
		}
		if (testDate.getTime() > today.getTime() + (maxDays * 24 * 60 * 60 * 1000)) {
			alert("The most likely range for this entry ends " + maxDays + " days from today.")
		}
	} else if (minYear && maxYear) {
		// function called with specific year range parameters
		if (yyyy < minYear || yyyy > maxYear) {
			// entered year is outside of range passed from calling function
			alert("The most likely range for this entry is between the years " + minYear + " and " + maxYear + ".  If your source data indicates a date outside this range, then enter that date.")
		}
	} else {
		// default year range (now set to (this year - 100) and (this year + 25)
		var thisYear = today.getYear()
		if (thisYear < 100) {
			thisYear += 1900
		}
		if (yyyy < minYear || yyyy > maxYear) {
			alert("It is unusual for a date entry to be before " + minYear + " or after " + maxYear + ". Please verify this entry.")
		}
	}
	if (!checkMonthLength(mm,dd)) {
		gField.focus()
		gField.select()
		return false
	}
	if (mm == 2) {
		if (!checkLeapMonth(mm,dd,yyyy)) {
			gField.focus()
			gField.select()
			return false
		}
	}
	// put the Informix-friendly format back into the field
//	gField.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
}


function isMandatory(){
	var space
	var inputStr = gField.value
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.substring(i, i + 1)
		if(oneChar != "" || oneChar != " "){
			break
		}
		if(oneChar == " ") {
			space = true
		}else{
			space = false
		}
	}
	if (space == true || inputStr == ""){
		window.alert("Field is mandatory.")
		gField.focus()
		gField.select()
		return false
	}
        return true
}

function isPosDecimal(){
	
	var decimalPoint = false
	var inputStr = gField.value
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.substring(i, i + 1)
		if(oneChar != "."){
			if(oneChar < "0" || oneChar > "9") {
				window.alert("Field must be a positive decimal number.")
				gField.focus()
				gField.select()
				return false
			}
		}else{
			if (decimalPoint == true){
				window.alert("Field contains to many decimal points.")
				gField.focus()
				gField.select()
				return false
			}else{
				decimalPoint = true
			}
		}
	}
	return true	
}

function isDecimal(){
	
	var decimalPoint = false
	var inputStr = gField.value
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.substring(i, i + 1)
		if(oneChar != "."){
                        if ( i == 0 && oneChar == "-") {
                                continue
                        }
			if (oneChar < "0" || oneChar > "9") {
				window.alert("Field must be a decimal number.")
				gField.focus()
				gField.select()
				return false
			}
		}else{
			if (decimalPoint == true){
				window.alert("Field contains to many decimal points.")
				gField.focus()
				gField.select()
				return false
			}else{
				decimalPoint = true
			}
		}
	}
	return true	
}

// general purpose function to see if a suspected numeric input
// is a positive integer
function isPosInteger() {
	var inputStr = gField.value
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if (oneChar < "0" || oneChar > "9") {
                        window.alert("Field should be a positive whole number.")
                        gField.focus()
                        gField.select()
			return false
		}
	}
	return true
}

// general purpose function to see if a suspected numeric input
// is a positive or negative integer
function isInteger() {
	var inputStr = gField.value
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if (i == 0 && oneChar == "-") {
			continue
		}
		if (oneChar < "0" || oneChar > "9") {
                        window.alert("Field is not a whole number.")
                        gField.focus()
                        gField.select()
			return false
		}
	}
	return true
}

// general purpose function to see if a field exceeds min length
function isRightLength(intMinLength){
	var inputStr = gField.value
	if (trim(inputStr).length >= intMinLength){
		return true
	}else{
		window.alert("String Length Too Short")
                gField.focus()
                gField.select()		
		return false
	}
}

//general purpose trim routine
function trim(inString){
	
	var Char = false
	while (inString.substr(0,1) == " "){
		inString = inString.substr(1,inString.length)
	}
	Char = true
	if (Char == true){
		Char = false
		while (inString.substr(inString.length - 1,inString.length) == " "){
			inString = inString.substr(0,inString.length - 1)
		}
		Char = true
		return inString
	}
}