
function dispatcher(validationFunc)
{	
	this.doValidate=validationFunc
}

function validate(frame,form,field,method)
{
	gFrame=frame
	gField=eval("window" + ".document." + form.name +"." + field.name)
	var args =validate.arguments
	for (i=3;i < args.length; i++)
		{
				if (!dispatchLookup[args[i]].doValidate())
					{
							return false
					}
		}
		return true
}


function isEmpty(inputStr)
{
	var inputStr = gField.value 
	if (inputStr == null || inputStr == "")
	{
		return (true);
	}
return (false);
}
function isNotEmpty(inputStr)
{	
	var inputStr = gField.value 
		if (inputStr == null || inputStr == "")
	{

		return (false);
	}
return (true);
}

// date field validation (called by other validation functions that specify minYear/maxYear) 
function isDate(minYear,maxYear,minDays,maxDays)
 { if (isEmpty(gField.value))
		{ 
		return(true)
		}
	var inputStr = gField.value 
// convert hyphen delimiters to slashes 
	while (inputStr.indexOf("-") != -1) 
			{ 
				inputStr = inputStr.replace("-","/") 
			}
	while (inputStr.indexOf(".") != -1) 
			{ 
				inputStr = inputStr.replace(".","/") 
			}
	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: mmddyyyy, mmddyy, mm.dd.yyyy, mm/dd/yyyy, or mm-dd-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(0,delim1),10)
		 var dd = parseInt(inputStr.substring(delim1 + 1,delim2),10)
		 var yyyy = parseInt(inputStr.substring(delim2 + 1, inputStr.length),10) 
		  
	  } else 
	  { 
	  // there are no delimiters; extract component values
	   var mm = parseInt(inputStr.substring(0,2),10) 
	   var dd = parseInt(inputStr.substring(2,4),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: mmddyyyy, mmddyy, mm.dd.yyyy, mm/dd/yyyy, or mm-dd-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 dateStr = new String(mm + "/" +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 
		gField.value=  "" + mm + "/" + 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 cfcheckdate(inputstr) 
{
	inputstr=trim(inputstr)
	
	if (isdate(inputstr)== false)  
		{
			cfcheckdate=false
		}
	else
		{
			cfcheckdate=true
		}
}	


var dispatchLookup=new Array()
dispatchLookup["isNotEmpty"]= new dispatcher(isNotEmpty)
dispatchLookup["isEmpty"]=new dispatcher(isEmpty)
dispatchLookup["isDate"]= new dispatcher(isDate)


