function Validate(oForm) {
	var VALString;
	var VALArray;
	var VALField;
	var VALErrMessage;
	var ReturnValue = true;

	/////////////////////////////////////
	//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 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;
			}
		}
	}


	return ReturnValue;
}
				
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 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;
}

function OpenWin(sUrl,iWidth,iHeight) {
	var oWin = window.open(sUrl,'winName','width='+iWidth+',height='+iHeight+',resizable=yes');	
}