function Validate(oForm) {
	var VALString;
	var VALArray;
	var VALField;
	var VALErrMessage;
	var ReturnValue = true;



	/////////////////////////////////////
	//Validate Matching Text Fields
	/////////////////////////////////////

	//First Check for an array of values
	if (oForm.VALMatchFields) {
	
		if(oForm.VALMatchFields.length) {
			var idx;
			for (var idx=0;idx < oForm.VALMatchFields.length ;idx++) {
				VALString = oForm.VALMatchFields[idx].value;
				VALArray = VALString.split(",");
				VALField1 = VALArray[0];
				VALField2 = VALArray[1];
				VALErrMessage = VALArray[2];
				if (!ValidateMatchingFields(oForm, VALField1, VALField2, VALErrMessage)) {
					ReturnValue = false;
					break;
				}
			}
		}
		else {
			
			VALString = oForm.VALMatchFields.value;
			VALArray = VALString.split(",");
			VALField1 = VALArray[0];
			VALField2 = VALArray[1];
			VALErrMessage = VALArray[2];
			if (!ValidateMatchingFields(oForm, VALField1, VALField2, VALErrMessage)) {
				ReturnValue = false;
			}
		}
	}
	
	if(!ReturnValue) {
		return ReturnValue;
	}
	
	
	/////////////////////////////////////
	//Validate Required Text Fields
	/////////////////////////////////////

	//First Check for an array of values
	if (oForm.VALTextRequired) {
		if(oForm.VALTextRequired.length) {
			var idx;
			for (var idx=0;idx < oForm.VALTextRequired.length ;idx++) {
				VALString = oForm.VALTextRequired[idx].value;
				VALArray = VALString.split(",");
				VALField = VALArray[0];
				VALErrMessage = VALArray[1];
				if (!ValidateRequiredText(oForm, VALField,VALErrMessage)) {
					ReturnValue = false;
					break;
				}
			}
		}
		else {
			
			VALString = oForm.VALTextRequired.value;
			VALArray = VALString.split(",");
			VALField = VALArray[0];
			VALErrMessage = VALArray[1];
			if (!ValidateRequiredText(oForm, VALField,VALErrMessage)) {
				ReturnValue = false;
			}
		}
	}
	
	if(!ReturnValue) {
		return ReturnValue;
	}
	/////////////////////////////////////
	// Validate Required Select Fields
	/////////////////////////////////////

	//First Check for an array of values
	if(oForm.VALSelectRequired) {
		if(oForm.VALSelectRequired.length) {
			var idx;
			for (var idx=0;idx < oForm.VALSelectRequired.length ;idx++) {
				VALString = oForm.VALSelectRequired[idx].value;
				VALArray = VALString.split(",");
				VALField = VALArray[0];
				VALErrMessage = VALArray[1];
				if (!ValidateRequiredSelect(oForm, VALField,VALErrMessage)) {
					ReturnValue = false;
					break;
				}
			}
		}
		else {
			VALString = oForm.VALSelectRequired.value;
			VALArray = VALString.split(",");
			VALField = VALArray[0];
			VALErrMessage = VALArray[1];
			if (!ValidateRequiredSelect(oForm, VALField,VALErrMessage)) {
				ReturnValue = false;
			}
		}
	}

	if(!ReturnValue) {
		return ReturnValue;
	}

	/////////////////////////////////////
	// Validate Required CheckBox Fields
	/////////////////////////////////////

	//First Check for an array of values
	if(oForm.VALCheckboxRequired) {
		if(oForm.VALCheckboxRequired.length) {
			var idx;
			for (var idx=0;idx < oForm.VALCheckboxRequired.length ;idx++) {
				VALString = oForm.VALCheckboxRequired[idx].value;
				VALArray = VALString.split(",");
				VALField = VALArray[0];
				VALErrMessage = VALArray[1];
				if (!ValidateRequiredCheckbox(oForm, VALField,VALErrMessage)) {
					ReturnValue = false;
					break;
				}
			}
		}
		else {
			VALString = oForm.VALCheckboxRequired.value;
			VALArray = VALString.split(",");
			VALField = VALArray[0];
			VALErrMessage = VALArray[1];
			if (!ValidateRequiredCheckbox(oForm, VALField,VALErrMessage)) {
				ReturnValue = false;
			}
		}
	}

	if(!ReturnValue) {
		return ReturnValue;
	}

	/////////////////////////////////////
	//Validate Valid Email Fields
	/////////////////////////////////////
	
	//First Check for an array of values
	if(oForm.VALValidEmail) {
		if(oForm.VALValidEmail.length) {
			var idx;
			for (var idx=0;idx < oForm.VALValidEmail.length ;idx++) {
				VALString = oForm.VALValidEmail[idx].value;
				VALArray = VALString.split(",");
				VALField = VALArray[0];
				VALErrMessage = VALArray[1];
				if (!ValidateValidEmail(oForm, VALField,VALErrMessage)) {
					ReturnValue = false;
					break;
				}
			}
		}
		else {
			VALString = oForm.VALValidEmail.value;
			VALArray = VALString.split(",");
			VALField = VALArray[0];
			VALErrMessage = VALArray[1];
			if (!ValidateValidEmail(oForm, VALField,VALErrMessage)) {
				ReturnValue = false;
			}
		}
	}


	if(!ReturnValue) {
		return ReturnValue;
	}

	
	/////////////////////////////////////
	//Validate Valid Date Fields
	/////////////////////////////////////
	
	//First Check for an array of values
	if(oForm.VALValidDate) {
		if(oForm.VALValidDate.length) {
			var idx;
			for (var idx=0;idx < oForm.VALValidDate.length ;idx++) {
				VALString = oForm.VALValidDate[idx].value;
				VALArray = VALString.split(",");
				VALField = VALArray[0];
				VALErrMessage = VALArray[1];
				if (!ValidateValidDate(oForm, VALField,VALErrMessage)) {
					ReturnValue = false;
					break;
				}
			}
		}
		else {
			VALString = oForm.VALValidDate.value;
			VALArray = VALString.split(",");
			VALField = VALArray[0];
			VALErrMessage = VALArray[1];
			if (!ValidateValidDate(oForm, VALField,VALErrMessage)) {
				ReturnValue = false;
			}
		}
	}


	if(!ReturnValue) {
		return ReturnValue;
	}

	/////////////////////////////////////
	//Validate Numeric Fields
	/////////////////////////////////////
	
	//First Check for an array of values
	if(oForm.VALValidNumber) {
		if(oForm.VALValidNumber.length) {
			var idx;
			for (var idx=0;idx < oForm.VALValidNumber.length ;idx++) {
				VALString = oForm.VALValidNumber[idx].value;
				VALArray = VALString.split(",");
				VALField = VALArray[0];
				VALErrMessage = VALArray[1];
				if (!ValidateNumeric(oForm, VALField,VALErrMessage)) {
					ReturnValue = false;
					break;
				}
			}
		}
		else {
			VALString = oForm.VALValidNumber.value;
			VALArray = VALString.split(",");
			VALField = VALArray[0];
			VALErrMessage = VALArray[1];
			if (!ValidateNumeric(oForm, VALField,VALErrMessage)) {
				ReturnValue = false;
			}
		}
	}

	if(!ReturnValue) {
		return ReturnValue;
	}

	/////////////////////////////////////
	//Validate Postitive Numeric Fields
	/////////////////////////////////////
	
	//First Check for an array of values
	if(oForm.VALPositiveNumber) {
		if(oForm.VALValidNumber.length) {
			var idx;
			for (var idx=0;idx < oForm.VALPositiveNumber.length ;idx++) {
				VALString = oForm.VALPositiveNumber[idx].value;
				VALArray = VALString.split(",");
				VALField = VALArray[0];
				VALErrMessage = VALArray[1];
				if (!ValidateNumericPositive(oForm, VALField,VALErrMessage)) {
					ReturnValue = false;
					break;
				}
			}
		}
		else {
			VALString = oForm.VALPositiveNumber.value;
			VALArray = VALString.split(",");
			VALField = VALArray[0];
			VALErrMessage = VALArray[1];
			if (!ValidateNumericPositive(oForm, VALField,VALErrMessage)) {
				ReturnValue = false;
			}
		}
	}

	/////////////////////////////////////
	//Validate MinMax Field Length
	/////////////////////////////////////
	var iMin;
	var iMax;
	//First Check for an array of values

	if (oForm.VALMinMax) {
		if(oForm.VALMinMax.length) {
			var idx;
			for (var idx=0;idx < oForm.VALMinMax.length ;idx++) {
				VALString = oForm.VALMinMax[idx].value;
				VALArray = VALString.split(",");
				VALField = VALArray[0];
				iMin = VALArray[1];
				iMax = VALArray[2];
				
				VALErrMessage = VALArray[3];
				if (!ValidateMinMax(oForm, VALField, iMin, iMax ,VALErrMessage)) {
					ReturnValue = false;
					break;
				}
			}
		}
		else {
			VALString = oForm.VALMinMax.value;
			VALArray = VALString.split(",");
			VALField = VALArray[0];
			iMin = VALArray[1];
			iMax = VALArray[2];
			VALErrMessage = VALArray[3];
			if (!ValidateMinMax(oForm, VALField, iMin, iMax ,VALErrMessage)) {
				ReturnValue = false;
			}
		}
	}
	if(!ReturnValue) {
		return ReturnValue;
	}

	return ReturnValue;

}

function ValidateMinMax(oForm, VALField, iMin, iMax ,VALErrMessage) {
	var iFieldLength;
	iFieldLength = eval("oForm." + VALField + ".value.length");
	if(iFieldLength < iMin || iFieldLength > iMax) {
		alert(VALErrMessage + '  You entered ' + iFieldLength + ' characters in this field.');
		eval("oForm." + VALField + ".focus()");
		return false;
	}
	return true;	
}				


function ValidateRequiredText(oForm, VALField, VALErrMessage) {
	if(eval("oForm." + VALField + ".value.length") == 0) {
		alert(VALErrMessage);
		eval("oForm." + VALField + ".focus()");
		
		return false;
	}
	return true;
}

function ValidateRequiredSelect(oForm, VALField, VALErrMessage) {
	if(eval("oForm." + VALField + ".selectedIndex") == 0) {
		alert(VALErrMessage);
		eval("oForm." + VALField + ".focus()");
		
		return false;
	}
	return true;
}

function ValidateRequiredCheckbox(oForm, VALField, VALErrMessage) {
	var oField = eval("oForm." + VALField);
	var bChecked = false;
	if(oField[0]){
		for(var i=0;i< oField.length; i++) {
			if(oField[i].checked) {
				bChecked = true;
			}
		}
		if(!bChecked)  {
			alert(VALErrMessage);
			eval("oForm." + VALField + "[0].focus()");
			return false;
		}
	}
	else {
		if (!oField.checked){
			alert(VALErrMessage);
			eval("oForm." + VALField + ".focus()");
			return false;
		}
	}
	return true;
}


function ValidateValidDate(oForm, VALField, VALErrMessage) {
	if (eval("oForm." + VALField + ".value.length") > 0) {
		if (eval("isValidDate(oForm." + VALField +")")==false) {
			alert(VALErrMessage);
			eval("oForm." + VALField + ".focus()");
			
			return false;
		}
	}
	return true;
}

function ValidateNumeric(oForm, VALField, VALErrMessage) {
	
	if (eval("oForm." + VALField + ".value.length") > 0) {
		if (eval("isNaN(oForm." + VALField +".value)")) {
			alert(VALErrMessage);
			eval("oForm." + VALField + ".focus()");
			return false;
		}
	}
	return true;
}

function isValidDate(datField) {
	var dateStr;
	dateStr = datField.value
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		//alert("Date is not in a valid format.")
		datField.value = '';
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		//alert("Month must be between 1 and 12.");
		datField.value = '';
		return false;
	}
	if (day < 1 || day > 31) {
		//alert("Day must be between 1 and 31.");
		datField.value = '';
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		//alert("Month "+ month +" doesn't have 31 days!")
		datField.value = '';
		return false
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			//alert("February " + year + " doesn't have " + day + " days!");
			datField.value = '';
			return false;
		}
	}
	return true;  // date is valid
}
function ValidateNumericPositive(VALField, VALErrMessage) {
	if (eval("document.forms[0]." + VALField + ".value.length") > 0) {
		if (eval("isNaN(document.forms[0]." + VALField +".value)")) {
			alert(VALErrMessage);
			eval("document.forms[0]." + VALField + ".focus()");
			return false;
		}
	
		if (eval("document.forms[0]." + VALField + ".value") <= 0) {
			alert(VALErrMessage);
			eval("document.forms[0]." + VALField + ".focus()");
			return false;
		}
		
	}
	return true;
}

function ValidateValidEmail(oForm, VALField, VALErrMessage) {
	if (eval("oForm." + VALField + ".value.length") > 0) {
		if (eval("isValidEmail(oForm." + VALField +".value)")==false) {
			alert(VALErrMessage);
			eval("oForm." + VALField + ".focus()");

			return false;
		}
	}
	return true;
}


function ValidateMatchingFields(oForm, VALField1, VALField2, VALErrMessage) {
		if (eval("oForm." + VALField1 + ".value") == eval("oForm." + VALField2 + ".value")) {
			return true;
		} 
		else {
			alert(VALErrMessage);
			//eval("oForm." + VALField1 + ".value=''");
			//eval("oForm." + VALField2 + ".value=''");
			eval("oForm." + VALField1 + ".focus()");
			return false;
		}

}


function isValidEmail(emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)

	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]


	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.")
		return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
			for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!")
			return false
			}
		}
		return true
	}


	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid.")
		return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
		alert("The address must end in a three-letter domain, or two letter country.")
		return false
	}

	if (len<2) {
		var errStr="This address is missing a hostname!"
		alert(errStr)
		return false
	}

	return true;
}


function CheckRadio (oFrm, fieldName,idx) {
	var obj;
	if(idx==-1){
		obj = eval('document.forms[0].' + fieldName );
	}
	else {
		obj = eval('document.forms[0].' + fieldName + '[' + idx + ']');
	}
	obj.checked = true;
}	
	
function CheckBox (oFrm, fieldName,idx) {
		var obj;
		if(eval('document.forms[0].' + fieldName + '[' + idx + ']')) {
			obj = eval('document.forms[0].' + fieldName + '[' + idx + ']');
		}
		else {
			obj = eval('document.forms[0].' + fieldName );		
		}
		obj.checked = !obj.checked;
}