// JavaScript Document
//Checking if the field is empty.
//Optional parameters are:
//text --text that will show in an alertbox if content is illegal.
function emptyvalidation(entered, alertbox)
{
	//alert("Validating required field ");
	with (entered)
	{
	if (value==null || value=="")
	{if (alertbox!="") {alert(alertbox);} return false;}
	else {return true;}
	}
} 
//Checking if the content has the general syntax of an email.
//Optional parameters are: 
//text--text that will show in an alertbox if content is illegal.
function emailvalidation(entered, alertbox)
{
	with (entered)
	{
	apos=value.indexOf("@"); 
	dotpos=value.lastIndexOf(".");
	lastpos=value.length-1;
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
	{if (alertbox) {alert(alertbox);} return false;}
	else {return true;}
	}
}
// This will validate US or Canadian Postal Codes
// Canadian Postal Code consists of two 3-character parts separated by space: 
//     [letter][digit][letter][optional space][digit][letter][digit]
// or "[a-zA-Z][0-9][a-zA-Z][ ]?[0-9][a-zA-Z][0-9]", for example: "R2G 1T9".

function zipvalidation(entered, alertbox) {
	with (entered)
	{
 	if (value.match(/^[0-9]{5}(-[0-9]{4})?$/)) {
	return true;
	}
	value=value.toUpperCase();
	if (value.match(/^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/)) {
	return true;
	}
	if (value.match(/^[A-Z][0-9][A-Z][ ]?[0-9][A-Z][0-9]$/)) {
	return true;
	}
	{if (alertbox) {alert(alertbox);} return false;}
	}
}
//Matches 18008793262 | 800-879-3262 | 0-800.879.3262 
function phonevalidation(entered, alertbox) {
	with (entered)
	{
	 if (value.match(/^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}$/)) {
	 return true;
	 }
	{if (alertbox) {alert(alertbox);} return false;}
	}
}
//Checking if the content is a number in a limited area.
//Optional parameters are:
//min --minimum value allowed in the field.
//max --maximum value allowed in the field.
//text --text that will show in an alertbox if content is illegal.
//type --enter "I" if only integers are allowed.
//if (digitvalidation(Digits,3,4,"You MUST enter 3 or 4 integer digits","I")==false) {Digits.focus(); return false;};
function digitvalidation(entered, min, max, alertbox, datatype)
{
with (entered)
	{
	checkvalue=parseFloat(value);
	if (datatype)
	{smalldatatype=datatype.toLowerCase();
	if (smalldatatype.charAt(0)=="i") 
	{checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
	}
	if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
	{if (alertbox!="") {alert(alertbox);} return false;}
	else {return true;}
	}
}
//Checking if the content is a number in a limited area.
//Optional parameters are:
//min --minimum value allowed in the field.
//max --maximum value allowed in the field.
//text --text that will show in an alertbox if content is illegal.
//type --enter "I" if only integers are allowed.
//if (valuevalidation(Value,0,5,"Value MUST be in the range 0-5")==false) {Value.focus(); return false;};
function valuevalidation(entered, min, max, alertbox, datatype)
{
with (entered)
	{
	checkvalue=parseFloat(value);
	if (datatype)
	{smalldatatype=datatype.toLowerCase();
	if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
	}
	if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
	{if (alertbox!="") {alert(alertbox);} return false;}
	else {return true;}
	}
}
