<!--

function MatchValues(field1, field2, msg) {
	if(field1.value == field2.value) {
		return (true);
	} else {
		alert(msg);
		return (false);
	}
}

function IsCurrency(theField, msg) {

	decimals = 2;  // how many decimals are allowed?
	var isValid = false;

	if (!isNaN(theField.value))
	{
		timeshundred = parseFloat(theField.value * Math.pow(10, decimals));
		integervalue = parseInt(parseFloat(theField.value) * Math.pow(10, decimals));
		if ((timeshundred == integervalue) && (timeshundred > 0)) {
			isValid = true;
		}
	}

	if (isValid) {
		return (true);
	} else {
		alert (msg);
		theField.select();
		theField.focus();
		return(false);
	}
}

function IsDate(theField) {
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables
	
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	
	// To require a 4 digit year entry, use this line instead:
	// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	
	var matchArray = theField.value.match(datePat); // is the format ok?
	if (matchArray == null) {
		//alert("Date is not in a valid format.")
		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.");
		return false;
	}

	if (day < 1 || day > 31) {
		//alert("Day must be between 1 and 31.");
	return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		//alert("Month "+month+" doesn't have 31 days!")
		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!");
			return false;
	   }
	}
	return true;  // date is valid
}

function IsDateRequireFourDigitYear(theField, msg) {
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables
	
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	
	var matchArray = theField.value.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert(msg);
		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.");
		return false;
	}

	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
	return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		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!");
			return false;
	   }
	}
	return true;  // date is valid
}


function IsNumber(theField) {

	var valid = "0123456789"
	var ok = "yes";
	var temp;

	for (var i=0; i<theField.value.length; i++) {
		temp = "" + theField.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}

	if (ok == "no") {
		return(false);		
	}
	else
	{	return(true);

	}
}

function IsDecimalNumber(theField) {

	var valid = "0123456789."
	var ok = "yes";
	var temp;
	
	var nDecimals = 0;

	for (var i=0; i<theField.value.length; i++)
	{
		temp = "" + theField.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
		{
			ok = "no";
		}
		
		if(temp == ".")
		{
			nDecimals++;
		}
	}
	
	if(nDecimals > 1)
	{
		ok = "no";
	}

	if (ok == "no") {
		return(false);		
	}
	else
	{	return(true);

	}
}

function IsLetter(theField) {

	var valid = "abcdefghijklmnopqrstuvwxyz"
	var ok = "yes";
	var temp;
	
	for (var i=0; i<theField.value.length; i++) {
		temp = "" + theField.value.substring(i, i+1);
		temp = temp.toLowerCase()
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") {
		return(false);
   }
   else
   {
   		return(true);
   }
}

function IsEmail(theField) {
	var sAlert;
	var sField1;
	var sMessageIndex;
	var sMessage;
	var myRe;
	
	sMessage = "The Email address entered is invalid.  Please re-enter.";
		
	// constructs Regular Expression Object and sets pattern
	// to the value between the "/" characters.	
	myRe = new RegExp("^([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-])*)+@{1}([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-])*)+\.{1}[a-zA-Z]{2,3}$","ig");

	// calls the test method of the Regular Expression Object
	// with string value parameter and returns boolean result.
	if (!myRe.test(theField.value))
	{
		sAlert = sMessage;
		alert(sAlert);
		return(false);
	}
	return(true);
}

function IsEmail_NSOK(theField)
	{	
	//--This function takes the Email field to be tested as input.
	//--It tests for the presence of "@" and ".".
	//--If neither of these characters is present, the user gets an error message.	
	var sMessage;
	var sTest;	
	sMessage = "The Email address entered is invalid.  Please re-enter.";	
	sTest = new String(theField.value)
	if((sTest.search(/@/gi) == -1) || (sTest.search(/\./gi) == -1))
		{
		alert(sMessage);
		return(false);
		}
	return(true);
	}
	
function IsValidSelection(objSelBox, intIndex, msg) {
		
	var index = objSelBox.selectedIndex

	if (index > intIndex) {
		return true;
	} else {
		alert(msg);
		return false;
	}
}
	
function RequireField(fld, msg)
{
	//--This function is called to ensure entries are made for required fields.
	if(fld.value.length == 0)
	{
		fld.focus();
		fld.select();
		alert(msg);
		return false;
	}
	return true; 
}

function RequireDateField(fld, msg, blnAllowNull)
{
	if(blnAllowNull && fld.value.length == 0)
	{
		return true;
	}

	if(fld.value.length == 0)
	{
		fld.focus();
		fld.select();
		alert(msg);
		return false;
	}
	if(!IsDateRequireFourDigitYear(fld,msg))
	{
		fld.focus();
		fld.select();
		return false;
	}
	return true; 
}

function RequireIntegerField(fld, msg, blnAllowNull)
{
	if(blnAllowNull && fld.value.length == 0)
	{
		return true;
	}
	
	if(fld.value.length == 0 || !IsNumber(fld))
	{
		fld.focus();
		fld.select();
		alert(msg);
		return false;
	}
	return true; 
}

function RequireCurrencyField(fld, msg, blnAllowNull) {

	//parse out any $ signs
	fld.value= fld.value.replace(/[\\$]*/g, "");
	return RequireNumericField(fld, msg, blnAllowNull);
}

function RequireNumericField(fld, msg, blnAllowNull) {

	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 

	if(blnAllowNull && fld.value.length == 0) {
		return true;
	}

	if(fld.value.length == 0 || !objRegExp.test(fld.value)) {
		fld.focus();
		fld.select();
		alert(msg);
		return false;
	}
	return true; 
}

function RequireEmailField(fld, msg, blnAllowNull)
{
	if(blnAllowNull && fld.value.length == 0)
	{
		return true;
	}
	
	if(fld.value.length == 0 || !IsEmailNoMsg(fld))
	{
		fld.focus();
		fld.select();
		alert(msg);
		return false;
	}
	return true; 
}

function RequireRadioButton(objRadio, msg) {
	
	var numButtons = objRadio.length;
	
	for (i=0; i<numButtons; i++) {
		if(objRadio[i].checked) {
			//If any one radio button is checked, field is valid
			return true;
		}
	}
	//Otherwise, no radio button was selected
	alert(msg);
	return false;
}		

function RequireCheckBox (objCheckBox, msg) {
	
	var numBoxes = objCheckBox.length;
	
	for (i=0; i<numBoxes; i++) {
		if(objCheckBox[i].checked) {
			//If any one radio button is checked, field is valid
			return true;
		}
	}
	//Otherwise, no radio button was selected
	alert(msg);
	return false;
}	

// Trim all whitespace from form text elements
function TrimFormElements(frm)
{
	for(var i = 0; i < frm.length; i++)
	{
		if(frm.elements[i].type == "text")
		{
			frm.elements[i].value = Trim(frm.elements[i].value);
		}
	}	
}

function LTrim(str)
{
	return str.replace(/^\s+/g, "");
}

function RTrim(str)
{
	return str.replace(/\s+$/g, "");

}

function Trim(str)
{
	return str.replace(/^\s+/g, "").replace(/\s+$/g, "");
}

function IsZipCode(fld, msg, blnAllowNull)
{
	if(blnAllowNull && fld.value.length == 0)
	{
		return true;
	}

	if(fld.value.length == 0)
	{
		fld.focus();
		fld.select();
		alert(msg);
		return false;
	}

	var objRegExp = new RegExp("(^[0-9]{5}$)|(^[0-9]{5}-[0-9]{4}$)");
	
	if(objRegExp.test(fld.value)) {
		return true;
	} else {
		alert(msg);
		return false;
	}
}

function URLencode (theString) {
	var re = / /g;
	return (theString.replace(re, "%20"));
}

function IsEmailNoMsg(theField)
{
	// constructs Regular Expression Object and sets pattern
	// to the value between the "/" characters.	
	var regexp = new RegExp("^([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-])*)+@{1}([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-])*)+\.{1}[a-zA-Z]{2,3}$","ig");
	
	return regexp.test(theField.value);
}
/*
--Alternate method, from: http://tech.irt.org/articles/js049/index.htm
in case we ever have any trouble with the given method (no trouble so far...)

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

*/

//-->
