<!--
function formValidator(strFormName)
{
	/* ****************************************
	*	NAME: formValidator
	*	
	*	CREATED: 20/02/2004
	*	CREATED BY:  Walter.
	*	MODIFIED: 
	*			-02/10/2006 By: Walter - Added none required field validation ( n| parameter).
	*	
	*	DESCRIPTION:
	*	
	*		This Validator cycles through every element in the form and looks in the ID attribute for "r|" for
	*		required fields.  Then takes the id tag and parses through the second set of parameters after the "|"
	*		looking for the types of validation the field requires.
	*
	*		Example.
	*				<input type="text" id="r|0,3,2" value="">   : For a required field
	*					or
	*				<input type="text" id="n|0,3,2" value="">	: For checking a none required field
	*
	*				ID Tag:
	*						| = Delimiter
	*						r = required validation
	*						n = not required but if filled in check
	*						0,3,2 = The Types of Validation Required (See Below)
	*					
	*	INPUTS: 
	*		- strFormName : A Sting variable that passes the validating forms name 
	*						to the function from the OnSubmit Action.
	*		
	*		- Element ID Tag : The JS reads the element ID tag from the following format
	*
	*	OUTPUTS:
	*		Returns a JavaScript Popup to the User.
	*	
	*	OTHER:
	*		Types of FormValidation Currently Avaiable:
	*		0 : Not Null x
	*		1 : Numeric Only  x
	*		2 : Alphabetic Only x
	*		3 : Zip / Postal Code x
	*		4 : Email
	*		5 : Check Pull Down For A Selected Item
	*		6 : Alphabetical and Special Characters ". -" 
	*
	*		10: Grouping (Used to have at least 1 of a group of checkboxes with a value)
	*	
	*	
	*		* To include this script in a form validating page use:
	*		<script SRC="path/formValidator.js"> </script>
	*	
	****************************************** */

	var intElementCount = document.forms[strFormName].elements.length;
	var intCounter = 0;
	var strElementIDTag = "";
	var strTypeOfValidation = "";
	var arrayValidationTypes = new Array();

	var blnIsChecked = false;		//Variable used with the G directive to allow for a group of checkboxes to have 1 check or false on 0 checks
	
	//Cycle Through Form Elements in the submitted form
	for (intCounter = 0; intCounter < intElementCount; intCounter++)
   	{
		//Sets The Current Elements ID (for checking) and its value.
		strElementIDTag = document.forms[strFormName].elements[intCounter].id;
		strElementValue = document.forms[strFormName].elements[intCounter].value;		
		blnRequiredValidation = false		

		//Check For A Validator ID Tag
		//alert(document.forms[strFormName].elements[intCounter].name +" = "+ strElementValue +" = "+ strElementIDTag.substring(0,2));
		if (strElementIDTag.substring(0,2) == "r|" || strElementIDTag.substring(0,2) == "n|" || strElementIDTag.substring(0,2) == "g|")
		{
			//Checks to see if the none-required field has had anything entered into it
			if (strElementIDTag.substring(0,2) == "n|" && strElementValue == "")
			{
				blnRequiredValidation = false;			//Empty None required field do not validate
			}
			else
			{
				blnRequiredValidation = true;			//Otherwise Validate
			}
					
			if (blnRequiredValidation == true)
			{
				
				strTypeOfValidation = strElementIDTag.substring(2, strElementIDTag.length);

				arrayCheckBoxInfo = strTypeOfValidation.split(":");			
				strGroupingMsg = arrayCheckBoxInfo[1];
				arrayValidationTypes = arrayCheckBoxInfo[0].split(",");				
					
				for (var intArrayCounter = 0; intArrayCounter < arrayValidationTypes.length; intArrayCounter++)
				{				
	//				alert("Doing Test = " + intArrayCounter + " Array Validation Type = " + arrayValidationTypes[intArrayCounter]);
										  
	//				switch (arrayValidationTypes[intArrayCounter])
					//alert(arrayValidationTypes[intArrayCounter]);
					switch (arrayValidationTypes[intArrayCounter])
					{
						
						case "0":
							//Checks for blank fields
							if (elementEmpty(strElementValue, strFormName, intCounter) == false)
							{
								return false;
							}
							else
							{
								if (strElementIDTag.substring(0,2) == "g|")
								{
									blnGroupingReturnedAResult = true;	
								}
							}
	
							break;
							
						case "1":
							//Checks for Numeric Only fields
	//						alert("Enter Case 1");
							if (elementNumericOnly(strElementValue, strFormName, intCounter) == false)
							{
								return false;
							}
	
							break;
							
						case "2":
							//Checks for Alphabetic Only fields
							if (elementAlphaOnly(strElementValue, strFormName, intCounter) == false)
							{
								return false;
							}
	
							break;
						
						case "3":
							//Checks for Postal / Zip Code 
							if (isPostCodeZipCode(strElementValue, strFormName, intCounter) == false)
							{
								return false;
							}
							
							break;
	
						case "4":
							//Checks for Valid Email Address
							if (isEmail(strElementValue, strFormName, intCounter) == false)
							{
								return false;
							}
						
						break;	
						
						case "5":
							//Checks for Selected Select Box
							if (isSelectBoxSelected(strElementValue, strFormName, intCounter) == false)
							{
								return false;
							}
							
							break;
							
						default:
							//alert("Validation Check #" + arrayValidationTypes[intArrayCounter] + " does not exist"); 
							break;
	
						case "6":
							//Checks for Alphabetic and Special Chars "- ." Only fields
							if (elementAlphaSpecChar1(strElementValue, strFormName, intCounter) == false)
							{
								return false;
							}
	
							break;

						case "10":
							//Checks for Alphabetic and Special Chars "- ." Only fields
							
							blnGroupingOn = true;
							
							if (elementCheckBoxStatus(strElementValue, strFormName, intCounter) == true)
							{
								blnIsChecked = true;
							}
						
							break;
					}
				}
				
				//Clears Array Test
				arrayValidationTypes[intArrayCounter] = "";
				
			}
		}
   	}
	
//	alert("*** " + blnGroupingOn + " -> " + blnIsChecked);
	
	if (blnGroupingOn == true && blnIsChecked != true)
	{
		alert(strGroupingMsg);
		return false;
	}
	
	//All of the Checks Passed and Form Will Be Allowed To Submit
	return true;
}

function changeBG(object){
	
	object.style.backgroundColor="#EBA313";
	
}

//Checks for A value of Nothing in a Required Field.
function elementEmpty (strValue, strForm, strElementNum)
{					
	//Checks that the Field is Not Blank, Or Undefined.
	if (strValue == "")
	{
		alert("Please complete all required fields.");
		document.forms[strForm].elements[strElementNum].focus();
		changeBG(document.forms[strForm].elements[strElementNum]);
		return false;
	}
}

function elementCheckBoxStatus(strValue, strForm, strElementNum)
{
	if (document.forms[strForm].elements[strElementNum].checked == true)
	{
		return true;
	}
	else
	{
		return false;	
	}
}

//Checks if Field is Numeric.
function elementNumericOnly (strValue, strForm, strElementNum)
{						
	alert("Enter Numeric Only Function");
	//Checks that the Field is Not Blank, Or Undefined.
	if (isNaN(strValue))
	{
		alert("Field Must Be Numeric");
		document.forms[strForm].elements[strElementNum].focus();
		changeBG(document.forms[strForm].elements[strElementNum]);
		return false;
	}
}

//Checks if Field is Alphabetic Only.
function elementAlphaOnly (strValue, strForm, strElementNum)
{						
	var len = strValue.length;
	var currentPos=0;
	var character= "";

	while (currentPos < len)
	{
		character = strValue.charAt(currentPos);
		if (  ('A' <= character && character <= 'Z') || 
			  ('a' <= character && character <= 'z') || 
			  (character == " ") )
		{
			currentPos++;
		}
		else
		{
			alert("Field Must Be Alphabetic");
			document.forms[strForm].elements[strElementNum].focus();
			changeBG(document.forms[strForm].elements[strElementNum]);
			return false;
		}
	}
}

// Special Characters + Alhpha
function elementAlphaSpecChar1 (strValue, strForm, strElementNum)
{						
	var len = strValue.length;
	var currentPos=0;
	var character= "";

	while (currentPos < len)
	{
		character = strValue.charAt(currentPos);
		if (  ('A' <= character && character <= 'Z') || 
			  ('a' <= character && character <= 'z') || 
			  (character == " ")  ||
			  (character == '-') ||
			  (character == '.') )
		{
			currentPos++;
		}
		else
		{
			alert("Field Must Be Alphabetic");
			document.forms[strForm].elements[strElementNum].focus();
			changeBG(document.forms[strForm].elements[strElementNum]);
			return false;
		}
	}
}


function elementEmailCheck (strValue, strForm, strElementNum) 
{
	
}

function isPostCodeZipCode (strValue, strForm, strElementNum) 
{ 
	strlen = strValue.length; 

	if (strlen == 6) 
	{
		strValue = strValue.toUpperCase();        // in case of lowercase characters
	
		// Check for legal characters in string - note index starts at zero
		if ( ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(strValue.charAt(0)) < 0) ||
			 ('0123456789'.indexOf(strValue.charAt(1)) < 0)	||
			 ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(strValue.charAt(2)) < 0) ||
			 ('0123456789'.indexOf(strValue.charAt(3)) < 0) ||
			 ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(strValue.charAt(4)) < 0) ||
			 ('0123456789'.indexOf(strValue.charAt(5)) < 0) )
		{
			alert("Invalid Zip / Postal Code");
			document.forms[strForm].elements[strElementNum].focus();
			changeBG(document.forms[strForm].elements[strElementNum]);
			return false;
		}
	}
	else if (strlen == 5)
	{
		if (isNaN(strValue))
		{
			alert("Invalid Zip / Postal Code");
			document.forms[strForm].elements[strElementNum].focus();
			changeBG(document.forms[strForm].elements[strElementNum]);
			return false;
		}
	}
	else
	{
		alert("Invalid Zip / Postal Code");
		document.forms[strForm].elements[strElementNum].focus();
		changeBG(document.forms[strForm].elements[strElementNum]);
		return false;		
	}
}

function isSelectBoxSelected (strValue, strForm, strElementNum)
{
		if (strValue == "") 
		{
			alert("Please complete all required fields");
			document.forms[strForm].elements[strElementNum].focus();
			changeBG(document.forms[strForm].elements[strElementNum]);
			return false;	
		}
	
}

function isEmail (strValue, strForm, strElementNum)
{
	
	var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
	
	if ( !emailRe.test(strValue) ){
		
		alert("Invalid Email");
		document.forms[strForm].elements[strElementNum].focus();
		changeBG(document.forms[strForm].elements[strElementNum]);
		return false;	
		
	}
	
	/*if (strValue.length >= 6)	// x@x.ca -> 6 chars
	{
		var indexOfAt = strValue.indexOf("@");
		var indexOfPeriod = strValue.indexOf(".");
	  
		if (indexOfAt > 0)
		{		
			if ((indexOfPeriod > indexOfAt+1) && (strValue.length > indexOfPeriod+1))
			{
				//DO NOTHING			
			}
			else
			{
				alert("Invalid Email");
				document.forms[strForm].elements[strElementNum].focus();
				changeBG(document.forms[strForm].elements[strElementNum]);
				return false;	
			}
		}
		else
		{
			alert("Invalid Email");
			document.forms[strForm].elements[strElementNum].focus();
			changeBG(document.forms[strForm].elements[strElementNum]);
			return false;	
		}
	}
	else
	{
		alert("Invalid Email");
		document.forms[strForm].elements[strElementNum].focus();
		changeBG(document.forms[strForm].elements[strElementNum]);
		return false;	
	}*/
}

-->