<!-- Hide script contents from old browsers

function trim(str)
{
	if (str != "" && str != null)
	{
		//Trim leading spaces from the string.
		while (str.length > 0 && (str.substring(0, 1) == " " || str.substring(0, 1) == "	"))
		{
			//Remove the leading character (space or tab).
			str = str.substring(1, str.length);
		}
		
		//Trim trailing spaces from the string.
		while (str.length > 0 && (str.substring(str.length - 1, str.length) == " " || str.substring(str.length - 1, str.length) == "	"))
		{
			//Remove the trailing character (space or tab).
			str = str.substring(0, str.length - 1);
		}
	}
	return str;
}


function checkForText(fld)
{
	var txtRetVal = true;

	//See if an extra argument exists.  This would be the message text to display.
	if (arguments.length > 1)
	{
		msg = arguments[1];
	}
	else
	{
		//See if the field has label text.
		if (fld.alt)
		{
			msg = "An entry is required in the \"" + fld.alt + "\" field."
		}
		else
		{
			//Use the default message.
			msg = "An entry is required for this field.";
		}
	}
	
	if (fld)
	{
		if (trim(fld.value) == "")
		{
			//No text.
			alert(msg);
			fld.focus();
			fld.className = 'fieldFocus';
			txtRetVal = false;
		}
	}

	return txtRetVal;
}

function checkAlphaNum(fld)
{
	//This is customized for the code field.
	//Must be alpha numeric and start with a letter.
	
	//See if an extra argument exists.  This would be the message text to display.
	if (arguments.length > 1)
	{
		msg = arguments[1];
	}
	else
	{
		//See if the field has label text.
		if (fld.label)
		{
			msg = "An entry is required in the \"" + fld.label + "\" field."
		}
		else
		{
			//Use the default message.
			msg = "An entry is required for this field.";
		}
	}
	
	//See if the field exists, else just return true.
	if (fld)
	{
		//If empty, skip the check and just return true.
		//If this is a required field, check seperately using checkText.
		if (fld.value != "")
		{
			re = /\W/;
			if (re.test(fld.value))
			{
				alert ("You must enter only letters or numbers in this input field.");
				fld.focus();
				fld.className = 'fieldFocus';
				return false; 
			}
			else
			{
				re = /^[A-Za-z]/;
				if (!re.test(fld.value))
				{
					alert ("This field must begin with a letter.");
					fld.focus();
					fld.className = 'fieldFocus';
					return false; 
				}
			}
		}
	}
	return true;
}

function validatePhoneNumber(txt)
{
	//Make sure that the text has at least ten digits.
	digitCount = 0;
	for (i = 1; i <= txt.length; i++)
	{
		if (! isNaN(txt.substr(i-1, 1)))
		{
			digitCount = digitCount + 1;
		}
	}
	if (digitCount < 10)
	{
		return false;
	}
	return true;
}

function validateZipCode(txt)
{
	//Make sure that the text has at least 5 digits.
	digitCount = 0;
	for (i = 1; i <= txt.length; i++)
	{
		if (! isNaN(txt.substr(i-1, 1)))
		{
			digitCount = digitCount + 1;
		}
	}
	if (digitCount < 5)
	{
		return false;
	}
	return true;
}


function checkemail(fld)
{
	//This is customized for an email entry.
	//Must be of format "something@something.something".
	
	//See if the field exists, else just return true.
	if (fld)
	{
		//If empty, skip the check and just return true.
		//If this is a required field, check seperately using checkText.
		if (fld.value != "")
		{
			//Set up regular expression to look for email format.
			re = /.*\@.*\..*/;
			if (!re.test(fld.value))
			{
				alert ("You must enter a valid email address.");
				fld.focus();
				fld.className = 'fieldFocus';
				return false; 
			}
		}
	}
	return true;    
}

function checknumber(fld, minVal, maxVal)
{
	//This is customized for a number entry.
	//Must only contain a number and be between min and max values.
	
	//See if the field exists, else just return true.
	if (fld)
	{
		//If empty, skip the check and just return true.
		//If this is a required field, check seperately using checkText.
		if (fld.value != "")
		{
			//Set up regular expression to look for non-number.
			re = /\D+/;
			if (re.test(fld.value))
			{
				//Non-number found.
				alert ("You must enter a valid number.");
				fld.focus();
				fld.className = 'fieldFocus';
				return false; 
			}
			else
			{
				//Get the number value and see if it is within the range.
				numVal = parseInt(fld.value, 10);
				if (numVal < minVal || numVal > maxVal)
				{
					alert ("You must enter a number between " + minVal + " and " + maxVal + ".");
					fld.focus();
					fld.className = 'fieldFocus';
					return false; 
				}
			}
		}
	}
	return true;    
}

//Month names used in date conversion.
monthNames = new Array(12);
monthNames[1] = "January";
monthNames[2] = "February";
monthNames[3] = "March";
monthNames[4] = "April";
monthNames[5] = "May";
monthNames[6] = "June";
monthNames[7] = "July";
monthNames[8] = "August";
monthNames[9] = "September";
monthNames[10] = "October";
monthNames[11] = "November";
monthNames[12] = "December";

function checkdate(fld)
{
	//This is customized for a date entry.
	//Must only contain a number and be between min and max values.
	
	//See if the field exists, else just return true.
	if (fld)
	{
		//If empty, skip the check and just return true.
		//If this is a required field, check seperately using checkText.
		if (fld.value != "")
		{
			//Set up regular expression to look for date format m/d/yyyy.
			re = /\b(1[0-2]|0?[1-9])[\/](0?[1-9]|[12][0-9]|3[01])[\/]((19|20)\d{2})\b/;
			if (!re.test(fld.value))
			{
				alert ("You must enter a valid date with the format mm/dd/yyyy.  \nUse four digits for the year.");
				fld.focus();
				fld.className = 'fieldFocus';
				return false; 
			}
			else
			{
				//To get here, the format must be valid.
				//Now see if it is an actual date.
				//Split the string into its date componants.
				dateInput = fld.value ;
				dateVals = dateInput.split("/");
				mo = monthNames[parseInt(dateVals[0], 10)];
				day = parseInt(dateVals[1], 10);
				year = parseInt(dateVals[2], 10);
				
				//Convert the string to a javascript date.
				strDate = mo + " " + day + ", " + year;
				chkDate = new Date(strDate);
				//See if the months match.
				if (monthNames[chkDate.getMonth()+1] != mo)
				{
					//Bad date, ie. 11/31/2001, converts to 12/1/2001 in javascript, months don't match.
					alert ("You must enter a valid date with the format mm/dd/yyyy.");
					fld.focus();
					fld.className = 'fieldFocus';
					return false; 
				}
			}
		}
	}
	return true;    
}

function checkPhoneNumber(fld)
{
	//This is customized for a number entry.
	//Must only contain a number and be between min and max values.
	
	//See if the field exists, else just return true.
	if (fld)
	{
		//If empty, skip the check and just return true.
		//If this is a required field, check seperately using checkText.
		if (fld.value != "")
		{
			//set up regular expression to look for phone number format.
			re = /\(?\d{3}\)?[- \.]*\d{3}[- \.]*\d{4}/;
			if (!re.test(fld.value))
			{
				alert ("You must enter a valid telephone number (format xxx-xxx-xxxx).");
				fld.focus();
				fld.className = 'fieldFocus';
				return false; 
			}
		}
	}
	return true;    
}

function removeNonNumeric(str)
{
	//Removes all non-numeric characters from a string.
	//Step through each character and only add if it is a digit.
	newStr = "";
	
	for (i = 0; i < str.length; i++)
	{
		if (! isNaN(str.substr(i, 1)))
		{
			newStr += str.substr(i, 1);
		}
	}
	
	return newStr;
}


// end hiding contents from old browsers  -->
