<!-- ***************************************** -->
function CheckStandardField(FormElement, Message, setCase, StripString)
	{
		
	var cField;
	cField = "";
	cField = FormElement.value;	
	if (setCase == "Ucase")
		{
		cField = UpperTrim(cField);
		}
	else
		{
		cField = rtrim(cField);
		}
		
	cField = stripCharString(cField, StripString);
	FormElement.value = cField;
	var ret = test(FormElement, cField, Message);
	if (ret == "Empty")
		{
		return(0);
		}
	else
		{
		return(1);
		}
	}

<!-- ****************************************** -->

function CheckEMail(FormElement, Message)
	{
	var cEmail;
	cEmail = FormElement.value;
		
	ret = CheckStandardField(FormElement, Message, "", "'!#$;:%^&*()-=+");
	if (ret == 0)
		{
		return(0);
		}	
		
	if(FormElement.value.indexOf("@") == -1)
		{
		alert(Message);
		FormElement.focus();
		return(0);
		}
	else
		{
		if (FormElement.value.indexOf(".") == -1)
			{
			alert(Message);
			FormElement.focus();
			return(0);
			}
		}
	
	if (FormElement.length < 6)
		{
		alert(Message);
		FormElement.focus();
		return(0);
		}	
		
	ret = 1;
	return(1);
	}
<!--*****************************************************-->

function test(FormElement, ElementValue, Message)
	{
	var ret;
	if (ElementValue.length == 0)
		{
		alert(Message)
		FormElement.focus();
		ret = "Empty";		
		}
	else
		{
		ret = "";
		}
	return(ret);
	}

<!-- ************************************************ -->
function UpperTrim(cElement)
	{
	cElement = cElement.toUpperCase();
	cElement = rtrim(cElement);
	return(cElement)
	}

<!-- ************************************************ -->
function rtrim(Element)
	{
	var iLenth;
	iLength = Element.length;
	while (Element.charAt(iLength - 1) == " ")
		{		
		Element = Element.substring(0, iLength - 1);
		iLength = Element.length;
		}
	return(Element)
	}

	
<!-- ************************************************************** -->
function CheckPhoneNumber(FormElement)
	{
	var cMessage;
	var ret;
	
	ElementValue = FormElement.value;
	ElementValue = stripCharString(ElementValue, "()-.+# ");
	FormElement.value = ElementValue;
		
	cMessage = "\You do not appear to have a properly formatted PHONE NUMBER Please Include the Area Code"
	cReturn = 0;
	if (ElementValue.length > 0)
		{		
		var Ret = isNumberString(ElementValue);
		if (Ret == 0)
			{
			alert(cMessage)
			FormElement.focus();
			return(cReturn);	
			}
		if (ElementValue.length < 10)
			{
			alert(cMessage)
			FormElement.focus();
			return(cReturn);	
			}
		}
	else
		{
		alert(cMessage);
		FormElement.focus();
		return(cReturn);
		}	
	}

<!--************************************************************-->

function CheckFaxNumber(FormElement)
	{
	var cMessage;
	var ret;
	
	ElementValue = FormElement.value;
	ElementValue = stripCharString(ElementValue, "()-.+# ");
	FormElement.value = ElementValue;
		
	cMessage = "\You do not appear to have a properly formatted FAX NUMBER Please Include the Area Code"
	cReturn = 0;
	if (ElementValue.length > 0)
		{		
		var Ret = isNumberString(ElementValue);
		if (Ret == 0)
			{
			alert(cMessage)
			FormElement.focus();
			return(cReturn);	
			}
		if (ElementValue.length < 10)
			{
			alert(cMessage)
			FormElement.focus();
			return(cReturn);	
			}
		}
	else
		{
		alert(cMessage);
		FormElement.focus();
		return(cReturn);
		}	
	}

<!--************************************************************-->

function CheckCountry1(fPcode, fCountry, fProv)
	{
	
	if (fCountry.value == "CA" || fCountry.value == "CANADA" )
		{
		var cIsOkay = checkPostalCode(fPcode.value);
		if (cIsOkay == "T")
			{
			}
		else
			{
			alert("\You do not appear to have a properly formatted POSTAL CODE")
			fPcode.focus();
			return (0);
			}
		
		var cProv_State;
		cProv_State = fProv.value;
		cProv_State = checkProv(cProv_State);		
		fProv.value = cProv_State;
		if (cProv_State.length > 2)
			{
			alert("\You do not have a properly formatted 2 character province");
			fProv.focus();
			return (0);
			}
		}

	if (fCountry.value == "USA" || fCountry.value == "US" )
		{
			var Ret = isUSZip(fPcode.value);
			//alert (Ret)
			if (Ret == 0)
			{
			alert("\You do not appear to have a properly formatted ZIP CODE")
			fPcode.focus();
			return(0);	
			}
			else
			{
				return (1)
			}			
		}
	}

<!-- ************************************************************** -->

function stripChar (InString, StripThis)  
	{
	OutString="";
	for (Count=0; Count < InString.length; Count++)  
		{
		TempChar=InString.substring (Count, Count+1);
		if (TempChar!=StripThis)
			OutString=OutString+TempChar;
		}
	return (OutString);
	}

<!-- ************************************************************** -->

function allowInString (InString, RefString)  
	{
	if(InString.length==0) return (false);
	for (Count=0; Count < InString.length; Count++)  
		{
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return (false);
		}
	return (true);
	}

<!-- *************************************************************** -->

function stripCharString (InString, CharString)  
	{
	OutString="";
	for (Count=0; Count < InString.length; Count++) 
		{
		TempChar=InString.substring (Count, Count+1);
		Strip = false;
		for (Countx = 0; Countx < CharString.length; Countx++) 
			{
			StripThis = CharString.substring(Countx, Countx+1)
				if (TempChar == StripThis) 
				{
					Strip = true;
					break;
				}
			}
		if (!Strip)
			
			OutString=OutString+TempChar;
		}
	return (OutString);
	}

<!-- *********************************************************** -->

function allowNotInString (InString, RefString)  
	{
	if(InString.length==0) return (false);
	for (Count=0; Count < InString.length; Count++)  
		{
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)!=-1)  
			return (false);
		}
	return (true);
	}

<!-- *********************************************************** -->

function mask (InString, Mask)  
	{
	LenStr = InString.length;
	LenMsk = Mask.length;
	if ((LenStr==0) || (LenMsk==0))
		return(0);
	if (LenStr!=LenMsk)
		return(0);
	TempString=""
	for (Count=0; Count<=InString.length; Count++)  
		{
		StrChar = InString.substring(Count, Count+1);
		MskChar = Mask.substring(Count, Count+1);
		if (MskChar=='#') 
			{
			if(!isNumberChar(StrChar))
				return(0);
			}
		else if (MskChar=='?') 
			{
			if(!isAlphabeticChar(StrChar))
				return(0);
			}
		else if (MskChar=='!') 
			{
			if(!isNumOrChar(StrChar))
				return(0);
			}
		else if (MskChar=='*') 
			{
			}
		else 
			{
			if (MskChar!=StrChar) 
				return(0);
			}
		}
	return (1);
}

<!-- ********************************************** -->
function isAlphabeticChar (InString)  
	{
	if(InString.length!=1) 
		return (false);
	InString=InString.toLowerCase();
	RefString="abcdefghijklmnopqrstuvwxyz";
	if (RefString.indexOf (InString.toLowerCase(), 0)==-1) 
		return (false);
	return (true);
	}

<!-- ********************************************* -->

function isNumberChar (InString)  
	{
	if(InString.length!=1) 
		return (false);
	RefString="1234567890";
	if (RefString.indexOf (InString, 0)==-1) 
		return (false);
	return (true);
	}

<!-- ********************************************* -->

function isNumberString (InString)  
	{
	if(InString.length==0) 
		return (false);
	RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)  
		{
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return (false);
		}
	return (true);
	}

<!-- *************************************** -->

function isNumOrChar (InString)  
	{
	if(InString.length!=1) 
		return (false);
	InString=InString.toLowerCase();
	RefString="1234567890abcdefghijklmnopqrstuvwxyz";
	if (RefString.indexOf (InString, 0)==-1)  
		return (false);
	return (true);
	}	

<!-- *************************************** -->

function isUSZip (InString)  
	{
	//alert(InString)
	if (InString.length==0) 
		return (0);
	if ((InString.length!=5) && (InString.length!=10))
		return (0);
	RefString="1234567890-";
	for (Count=0; Count < InString.length; Count++)  
		{
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1) 
			return (0);
		}
	return (1);
	}

<!-- ************************************** -->

function ifExists (CheckVar) 
	{
	CheckVar = "" + CheckVar; 
	if (CheckVar == "<undefined>")
		return (false);
	else
		return (true);
	}

<!-- ****************************************** -->

function checkCountry(cCountry)
	{
	if (cCountry == "CANADA")
		{
		cCountry = "CA";		
		}	

	if (cCountry == "CAN")
		{
		cCountry = "CA"		
		}
	
	if (cCountry == "US")
		{
		cCountry = "USA";		
		}
	if (cCountry == "UNITED STATES OF AMERICA")
		{
		cCountry = "USA";
		}
	if (cCountry == "UNITED STATES")
		{
		cCountry = "USA";		
		}
	
	return (cCountry);
	}

<!-- ********************************************** -->

function checkProv(cProv)
	{

	
	if (cProv == "ONT")
		{
		cProv = "ON";			
		}		
	if (cProv == "ONTARIO")
		{
		cProv = "ON";			
		}
		
	if(cProv == "NEW FOUNDLAND")
		{
		cProv = "NF";			
		}
	if (cProv == "NFLD")
		{
		cProv = "NF";
		}
	
	if (cProv == "PRINCE EDWARD ISLAND")	
		{
		cProv = "PE";
		}
		
	if (cProv == "PRINCE EDWARD ISLE")
		{
		cProv = "PE";
		}
	
	if (cProv == "PEI")
		{
		cProv = "PE";
		}		
	
	if (cProv == "NOVA SCOTIA")
		{
		cProv = "NS";
		}

	if (cProv == "NEW BRUNSWICK")
		{
		cProv = "NB";
		}
	if (cProv == "NEWBRUNSWICK")
		{
		cProv = "NB";
		}

	if (cProv == "QUEBEC")
		{
		cProv = "QC";
		}		
	if (cProv == "PQ")
		{
		cProv = "QC";
			}
	if (cProv == "PROVINCE QUEBEC")
		{
		cProv = "QC";
		}
	if (cProv == "PROVINCE DE QUEBEC")
		{
		cProv = "QC";
		}

	if (cProv == "MANITOBA")
		{
		cProv = "MB";
		}
	
	if (cProv == "MAN")
		{
		cProv = "MB";
		}

	if (cProv == "ALBERTA")
		{
		cProv = "AB";
		}

	if (cProv == "ALTA")
		{
		cProv = "AB";
		}

	if (cProv == "BRITISH COLUMBIA")
		{
		cProv = "BC";
		}
	
	if (cProv == "YUKON TERRITORIES")
		{
		cProv = "YK";
		}
	
	if (cProv == "YUKON TERR")
		{
		cProv = "YK";
		}

	if (cProv == "YKN")
		{
		cProv = "YK";
		}

	if (cProv == "YKT")
		{
		cProv = "YK";
		}
		
	if (cProv == "NORTH WEST TERRITORIES")
		{
		cProv = "NT";
		}
		
	if (cProv == "NORTHWEST TERRITORIES")
		{
		cProv = "NT";
		}

	if (cProv == "NWT")
		{
		cProv = "NT";
		}
	
	return (cProv);
	}

<!-- ****************************************** -->

function checkPostalCode(cPcode)
	{
	var cIsOkay;
	cIsOkay = "T";
	if (cPcode.length < 6)
		{
		cIsOkay = "F";
		}

	if (cPcode.length > 7)
		{
		cIsOkay = "F";
		}
		
	if (cPcode.length == 6)
		{
		var Ret = mask(cPcode, "?#?#?#");
		if (Ret == 0)
			{
			cIsOkay = "F";
			}
		}

	if (cPcode.length == 7)
		{
		var Ret = mask(cPcode, "?#? #?#");
		if (Ret == 0)
			{
			cIsOkay = "F";
			}
		}
	return (cIsOkay);
	}

