function formCheck(formName, checkString, submitButton, displayText) {
	
	//disable the submit button
	submitButton.disabled = true;
	
	
	
  /*---------------------------------------------------------------------------------------
        Name:  formCheck()
     Purpose:  Return Errors if form check tests do not pass
       Usage:  -Ensure all HTML names and values have quotes around them.  Eg. name="city"
  			 -To use form check use: onSubmit="JavaScript: return formCheck('nameOfForm','homePhone=true=phone=error text&email=true=Email Address&mMonth!mDay!mYear=true=date=Date&webURL=true=url=WebURL')"
  			 -Pass a string to the formCheck function containing the
  	 	      ordered arguments: nameOfField=checkType=true=ErrorDisplayMessage
               -Seperate ordered arguments with an ampersand (&)
  			 -If a field is optional then  don't include =true
  			 -Example:
  				Validate optional email field:
  					email=email (will flag user only if an incorrect email entered)
  				Validate a manditory email field:
  					email=email=true (will flag if incorrect email or no value entered)
  				Validate that a value has been typed into the fname field:
  					fname=true
   Check Type:    Description:
   1. true		Make sure a field has a value other than spaces
   2. false       Make sure a field is left blank with no spaces
   3. email		Validate proper email
   4. credit		Validate proper American Express, Visa, Master Card number
   5. code		Validate proper Postal Code or American Zip Code & reformat.
   6. image		Make sure a field contains a .jpg or .gif extention.
   7. phone		make sure an areacode + number is submitted and reformat.
   8. noIllegalChars makes sure a field does not contain illegal characters
   9. singleValueCheckbox Make sure a checkbox passes only a single value
   10. groupCheckbox make sure that in a list of checkboxes, at least n are checked.  
  				--> n is the number passed into the javascript of checkboxes that need to be checked
  				--> format field|field|field|field=groupCheckbox|3=field name|field name|field name 
  
   11. url
   12. Date
   13. Phone no with three different fields Areacode+3digits+4Digits
   14. number - Validate optional numeric field with optional range check
  				- Example to validate number within range
					myField=number1:1000
				- Example to validate number
					myfield=number
   Other Functions:
      
  ---------------------------------------------------------------------------------------*/
  
  
  //---------------------------------------------------------------------------------------
  //Error codes to be displayed to the end user:
  //---------------------------------------------------------------------------------------
  var errorText = new Array();
  var errorTextCode;
  var errorExists = false;  
  
  //Field not filled in that should be filled in.
  	errorText[0] = "Check the following entries for omissions and errors:\n\n";
  //Email not the correct format.
  	errorText[1] = "  - Please enter a valid email address.\n";
  //Credit Card format not correct.
    errorText[2] = "  - Enter a valid credit card number.\n";
  //Uploaded file is not an image file:
    errorText[3] = "  - Ensure that the file you are uploading\n  is an image file with a .gif or .jpg extention.\n";
  //Postal/Zip Code format not correct.
    errorText[4] = "  - Enter a valid Postal/ZIP code.\n";
  //Phone number and area code not valid.
    errorText[5] = "  - Enter Area Code and Phone Number (xxx-xxx-xxxx).\n";
  //Field contains illegal characters.
    errorText[6] = "  - This field contains one of the following illegal characters:\n<  > { } [ ] ( ) * & ^ $ # @ ! ~ \\ / = + ' ` ? : ; | % .";
  //Checkbox contains more than one value
  	errorText[7] = "  - This field should only have a single value checked.\n";
  //List of checkboxes need to have at least n checked
  	errorText[8] = "  - At least ";
	errorText[9] = " of the following checkbox(es) need to be selected.\n";
  //Website URL need to be in a proper form.
	errorText[10] = "Invalid Website URL (eg. http://www.xyz.com) and also prefix http:// if not entered";
  //Date checking for proper days in a month including February month and leap year
	errorText[11] = "  - This month does not contain 31 date.";
	errorText[12] = "  - Invalid date in February month.";
  //Phone checking for proper format of 999 999 9999 and extension 99999
	errorText[13] = "  - Area code required/incorrect.";
	errorText[14] = "  - First three digits required/incorrect.";
	errorText[15] = "  - Last four digits required/incorrect.";
	errorText[16] = "  - Invalid extension";		
  //---------------------------------------------------------------------------------------
  
  //Generate array or ordered commands
  var checkArray = checkString.split("&");
  var checkArrayLen = checkArray.length;
  
  //Declare variables
  var subCheckArray;
  var subCheckArrayLen;
  var groupCheckboxNumber;
  var groupCheckboxArray;
  var fieldTrue;
  var fieldFalse;
  var listOfErrorFields= "";
  listOfErrorFields = listOfErrorFields + errorText[0];
  
  //If no array passed then return true;
  if (checkArray[0] != "no") {
	//loop through array:
	for (i = 0; i < checkArrayLen; i++){

   	    //alert("There Are: " + checkArrayLen + " elements in the checkArray");		
		//Create a new array for the ordered arguments within each CheckArrey element.
		
		subCheckArray = checkArray[i].split("=");
		subCheckArrayLen = subCheckArray.length;

		//----------------------------------------------
		//  STEP 1. Check for true or false argument   -
		//----------------------------------------------
		
		//set whether field is true or false to false to start off with
		var fieldTrue = false;
		var fieldFalse = false;
		var checkFormatting = false;
		var formatVarified = false;
		var formatLocation;
		var formatType = "";
		var testString = "";
		var textReturn = false;
		
  //---------------------------------------------------------------------------------------
		//Loop through subArray and check if field required, and if formatting is needed.
		//Fields that are not set to true but require formatting will only be checked
		//if a value has been entered.
  //---------------------------------------------------------------------------------------
		
		//used to override the set value, since with groupCheckbox the value is NULL
		var doNotSetValue = 0;

		for (y = 0; y < subCheckArrayLen; y++) {
		  if (subCheckArray[y] == "true") {
		    fieldTrue = true;
		  } else if (subCheckArray[y] == "false") {
		    fieldFalse = true;
		  } else if (subCheckArray[y].indexOf("groupCheckbox") > -1) {
		  	checkFormatting = true;
  			groupCheckboxArray = subCheckArray[y].split("|");
			for (w = 0; w < groupCheckboxArray.length; w++) {
				if (w == 0) {
					formatType = groupCheckboxArray[w];
				} else {
					groupCheckboxNumber = groupCheckboxArray[w];
				}
			}
			fieldValue = "hithere";
			doNotSetValue = 1;
		  } else  if (subCheckArray[y] == "email" || subCheckArray[y] == "credit" || subCheckArray[y] == "code" || subCheckArray[y] == "date" || subCheckArray[y] == "image" || subCheckArray[y] == "phone" || subCheckArray[y] == "noIllegalChars" || subCheckArray[y] == "singleValueCheckbox" || subCheckArray[y] == "url" || subCheckArray[y] == "phoneFax") {
		  	checkFormatting = true;
			formatType = subCheckArray[y];
			
			//alert("Format Type: " + formatType);
		  } else if(Left(subCheckArray[y],4) == "file") {
		  	checkFormatting = true;
			formatType = subCheckArray[y];
		  } else if(Left(subCheckArray[y],6) == "number") {
		  	checkFormatting = true;
			formatType = subCheckArray[y];
		  } else {
		  	errorDisplayMsg = subCheckArray[y];
		  	textReturn = true;
		  }
		 }
		
  //---------------------------------------------------------------------------------------

  //---------------------------------------------------------------------------------------
  //  Get the value of the field being checked:
  //---------------------------------------------------------------------------------------
  		if (doNotSetValue == 0) {
		   var fieldValue = getFormFieldValue(formName, subCheckArray[0]);
		}
		//alert("Form Name: " + formName + "\n Field Name: " + subCheckArray[0] + "\nValue of Field: " + fieldValue + "\nFormat Type: " + formatType);
		  
		//Determin if the form field meets true condition
		
		if (fieldTrue && (fieldValue == "null" || fieldValue=="$$$" || fieldValue=="$$$$")) {

		   if (errorDisplayMsg == "") {
		  		listOfErrorFields = listOfErrorFields + "  - " + subCheckArray[0] + "\n";
			} else {
				listOfErrorFields = listOfErrorFields + "  - " + errorDisplayMsg + "\n";
			}
		   errorExists = true;
		}

		if (fieldValue != "null" && subCheckArray[0].indexOf("!") == -1  && subCheckArray[0].indexOf("$") == -1 && textReturn) { 
			fieldValue = replaceString(fieldValue,"<script>","")
			fieldValue = replaceString(fieldValue,"<script","")
			fieldValue = replaceString(fieldValue,"</script>","")
			fieldValue = trim(fieldValue)
			eval("document." + formName + "." + subCheckArray[0] + ".value = fieldValue")
		}		
		
		if (fieldValue != "null" && fieldValue != "$$$" && fieldValue != "$$$$"  && checkFormatting) { 
			//-----------------------------------------------------------------------------
			//Check for various types of formatting:
			//-----------------------------------------------------------------------------
			//alert(formatType)

			if (formatType == "email") {
				formatVarified = varifyEmail(fieldValue);
				if (!formatVarified) {
					listOfErrorFields = listOfErrorFields + errorText[1] + "\n";
					errorExists = true;
				}
			}
			if (formatType == "credit") {
				cardType = validateCard(fieldValue);
				if (cardType == "unknownCard") {
					listOfErrorFields = listOfErrorFields + errorText[2] + "\n";
					errorExists = true;
				}
			}
			if (formatType == "code") {
				codeType = validateCode(fieldValue);
				if (codeType == "unknownCode") {
					listOfErrorFields = listOfErrorFields + errorText[4] + "\n";
					errorExists = true;
				}
				else {
				//Set the field value to the new improved formatted code
				eval("document." + formName + "." + subCheckArray[0] + ".value = codeType");
				}
			}
			if (formatType == "image") {
				if (fieldValue.indexOf(".gif") < 0 && fieldValue.indexOf(".jpg") < 0) {
					listOfErrorFields = listOfErrorFields + errorText[3] + "\n";
					errorExists = true;
				}
			}
			if (Left(formatType,4) == "file") {
				var fileExt = fieldValue.substr(fieldValue.lastIndexOf("."),fieldValue.length)
				var extensions = formatType.substr(4,formatType.length)
			    var exts = extensions.split(".")
				var allowExt = "(";
				for (var w = 1; w < exts.length; w++) {
					allowExt = allowExt + "  ." + exts[w] 
				}
				allowExt = allowExt + " )"
				if (allowExt.indexOf(fileExt) == -1) {
					listOfErrorFields = listOfErrorFields + "  - Allowed file extensions are " + allowExt + "\n";
					errorExists = true;
				}
			}
			if (Left(formatType,6) == "number") {
				//var checkOK = "0123456789.-";
				//var fileRange = fieldValue.substr(fieldValue.indexOf(":"),fieldValue.length);
				var ranges = formatType.substr(6,formatType.length);
				if (ranges.indexOf(":") < 0) {
					var rngs = new Array();
					rngs[1] = -1000000000;
					rngs[2] = 1000000000;
				} else {
					var rngs = ranges.split(":");
					rngs[1] = parseFloat(rngs[1]);
					rngs[2] = parseFloat(rngs[2]);
				}
				fileRange = parseFloat(fieldValue);
				//if (checkOK.indexOf(fileRange) < 0) {
				if (isNaN(fileRange)) {
					listOfErrorFields = listOfErrorFields + "  - "+ subCheckArray[2] +" must be numeric \n";
					errorExists = true;
				}	
				if (fileRange < rngs[1] || fileRange > rngs[2]) {
					listOfErrorFields = listOfErrorFields + "  - "+ subCheckArray[2] +" should be between " + rngs[1]+" and "+ rngs[2] + "\n";
					errorExists = true;
				}
			}
			if (formatType == "phone") {
				//validate phone number
				phoneNumber = validatePhone(fieldValue);
				//alert("The phone number returned is: " + phoneNumber);
				if (phoneNumber == "unknownNumber") {
					listOfErrorFields = listOfErrorFields + errorText[5] + "\n";
					errorExists = true;
				}
				else {
					eval("document." + formName + "." + subCheckArray[0] + ".value = phoneNumber");
				}
			}
			
			if (formatType == "phoneFax") {
				//validate phone number
				phoneFaxNumber = isValidPhoneFax(fieldValue);
				//alert("The phone number returned is: " + phoneFaxNumber);
				
				if (phoneFaxNumber == "InvalidAreaCode") 
				{
					listOfErrorFields = listOfErrorFields + errorText[13] + "\n";
					errorExists = true;
				}
				else if (phoneFaxNumber == "InvalidFirstThree") 
				{
					listOfErrorFields = listOfErrorFields + errorText[14] + "\n";
					errorExists = true;
				}
				else if (phoneFaxNumber == "InvalidLastFour") 
				{
					listOfErrorFields = listOfErrorFields + errorText[15] + "\n";
					errorExists = true;
				}
				else if (phoneFaxNumber == "InvalidExt") 
				{
					listOfErrorFields = listOfErrorFields + errorText[16] + "\n";
					errorExists = true;
				}
			}

			if (formatType == "date") {
				codeType = isValidDate(fieldValue);
				if (codeType == "invalidDay") {
					listOfErrorFields = listOfErrorFields + errorText[11] + "\n";
					errorExists = true;
				}
				if (codeType == "invalidFebruary") {
					listOfErrorFields = listOfErrorFields + errorText[12] + "\n";
					errorExists = true;
				}
			}		
		
			if (formatType == "url") {
				//validate url
				var urlValue = ishttp(fieldValue);
				if (!urlValue) {
					listOfErrorFields = listOfErrorFields + errorText[10] + "\n";
					errorExists = true;
				}
				else {
					eval("document." + formName + "." + subCheckArray[0] + ".value = urlValue");
				}	
			}

			if (formatType == "noIllegalChars") {
				//validate illegal chars
				illegalCharList = "<>{}[]()*&^$#@!~\\/=+\'`?)(:;|%,.";
				for (validateStr = 0; validateStr < illegalCharList.length; validateStr++) {
					//alert(illegalCharList.charAt(validateStr));
					if (fieldValue.indexOf(illegalCharList.charAt(validateStr)) > 0) {
						 if (errorDisplayMsg == "") {
					  		listOfErrorFields = listOfErrorFields + subCheckArray[0] + "\n\n";
						} else {
							listOfErrorFields = listOfErrorFields + errorDisplayMsg + "\n\n";
						}
						listOfErrorFields = listOfErrorFields + errorText[6] + "\n";
						errorExists = true;
					}
				}
			}
			
			if (formatType == "singleValueCheckbox") {
				//ensure checkbox only has one value
				var checkCount = 0;
				var checkboxLength = eval("document." + formName + "." + subCheckArray[0] + ".length");
				//alert("checkboxLength: " + checkboxLength);
				for (cb = 0; cb < checkboxLength; cb++) {
					if (eval("document." + formName + "." + subCheckArray[0] + "[" + cb + "]" + ".checked") == true) {
						checkCount = checkCount + 1;
						//alert("checkCount :" + checkCount);
					}
				}
				if (checkCount > 1) {
					 if (errorDisplayMsg == "") {
				  		listOfErrorFields = listOfErrorFields + subCheckArray[0] + "\n\n";
					} else {
						listOfErrorFields = listOfErrorFields + errorDisplayMsg + "\n\n";
					}
					listOfErrorFields = listOfErrorFields + errorText[7] + "\n";
					errorExists = true;
				}
			}
			
			if (formatType == "groupCheckbox") {
				//ensure at least n of the listed checkboxes are checked
				var groupCheckCount = 0;
				var checkBoxArray = subCheckArray[0].split("|");
				var groupCheckBoxLength = 0;
				var errDispWithLB = "";
				//alert("checkboxLength: " + checkboxLength);
				for (chb = 0; chb < checkBoxArray.length; chb++) {
					if (eval("document." + formName + "." + checkBoxArray[chb] + ".checked") == true) {
							groupCheckCount = groupCheckCount + 1;
					}
				}
				if (groupCheckCount < groupCheckboxNumber) {
					listOfErrorFields = listOfErrorFields  + "\n\n" + errorText[8] + groupCheckboxNumber + errorText[9] + "\n\n";
					if (errorDisplayMsg == "") {			
						listOfErrorFields = listOfErrorFields + "hello";	 
				  		listOfErrorFields = listOfErrorFields + subCheckArray[0] + "\n\n";
					} else {
						var checkBoxNamesArray = errorDisplayMsg.split("|");
						
						for(chbn = 0; chbn < checkBoxNamesArray.length; chbn++) {
							//alert(checkBoxNamesArray[chbn]);
							errDispWithLB = errDispWithLB + checkBoxNamesArray[chbn] + "\n";
						}
						listOfErrorFields = listOfErrorFields + errDispWithLB + "\n\n";
					}
					errorExists = true;
				}
			}
			//-----------------------------------------------------------------------------
		}
	}
	//End loop through Array
  }
  //---------------------------------------------------------------------------------------  
  //Check to see if an error was detected, and display errors.
  //---------------------------------------------------------------------------------------
  if (errorExists) {
  	//enable the submit button if error found
	submitButton.disabled = false;
  	alert(listOfErrorFields);
	return false;
  }	
  //Change the value of submit button
  submitButton.value= displayText
  return true
  //---------------------------------------------------------------------------------------
}


function validatePhone(number) {
	//Step 1 remove all non-numerical characters
	var validChr = "0123456789";
	var tempNumber = "";
	for (cn = 0; cn < number.length; cn++) {
		if (validChr.indexOf(number.charAt(cn)) > -1) {
			tempNumber = tempNumber + number.charAt(cn);
		}
	}
	number = tempNumber;
	
	//check to see if 10 digits long
	if (number.length != 10) {
		return "unknownNumber";
	}
	else {
	  number = "(" + number.substr(0,3) + ")" + " " + number.substr(3,3) + "-" + number.substr(6);
	}
	return number;	

}

function validateCode(code) {
	//Validate postal code for M9B 3V3 or 90210-2030 or 90210 format:
	//if Valid returns formatted code
	//if Not Valid returns Null
	
	codeType = "unknownCode"
	//alert("code: " + code);
	//Remove all spaces and - ( ) characters added to the number field
	var newCode = "";
	for (cp = 0; cp < code.length; cp++) {
		if (code.charAt(cp) != " " && code.charAt(cp) != "-" && code.charAt(cp) != "(" && code.charAt(cp) != ")" ) {
			newCode = newCode + code.charAt(cp);
		}
	}
	code = newCode.toUpperCase();
	//alert("code: " + code);
	
	var validChrCan = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var validChrUS = "01234567890";
	
	//  Validate the Canadian Postal Code
	if (validChrCan.indexOf(code.charAt(0)) >= 0) {
		codeType = "can";
		//alert("Valid Can Character! " + code);
		
		//Check to see if has 6 characters:
		if (code.length != 6) {
			return "unknownCode";
		}
		var position = 0;
		for (cc = 0; cc < code.length; cc = cc + 2) {
			if (validChrCan.indexOf(code.charAt(cc)) < 0 || validChrUS.indexOf(code.charAt(cc+1)) < 0) {
				 return "unknownCode";
				 //alert("position: " + position + "," + cc + "  Current Character: " + code.charAt(0));
			}
		}
		codeType = code.substring(0,3) + " " + code.substr(3);
	
	}
	
	//  Validate the American Zip Code
	if (validChrUS.indexOf(code.charAt(0)) >= 0) {
		codeType = "us";
		//alert("Valid US Character! " + code );
		
		//step one check all values are numbers
		for (cc = 0; cc < code.length; cc++) {
			if (validChrUS.indexOf(code.charAt(cc)) < 0) {
			  return "unknownCode";
			}
		}
		//step 2, check the length is either 5 or 9 characters
		if (code.length != 5 && code.length != 9) {
			return "unknownCode";
		}
		
		//format code properly
		if (code.length == 9) {
			codeType = code.substring(0,5) + "-" + code.substring(5);
		}
		else {
			codeType = code;
		}
		
		
	}
	return codeType;
}

function validateCard(cardNumber) {
	//Validate only for Master Card, Visa, and American Express
	//This function will determin the type of credit card and return the name of the card if it is validated
	//Otherwise "unknownCard" will be returned.
	
	var cardType = "unknownCard";
	var checkType = "";
	
	//Remove all spaces added to the number field
	var newCardNumber = "";
	for (cp = 0; cp < cardNumber.length; cp++) {
		if (cardNumber.charAt(cp) != " ") {
			newCardNumber = newCardNumber + cardNumber.charAt(cp)
		}
	}
	cardNumber = newCardNumber;
	
	
	if (cardNumber.charAt(0) == "5") {
		//Proceed with validation of a Master Card Number
		cardType = "MasterCard";

		if (cardNumber.length != 16) {
			alert (cardNumber.length + "  Card Number: " + cardNumber);
			return "unknownCard";
		}
		
		//Check for valid Master Card Prefix
		prefix = cardNumber.substring(0,2);
		if (prefix != 51 && prefix != 52 && prefix != 53 && prefix != 54 && prefix != 55) {
			alert("Card Prefix: " + prefix);
			return "unknownCard";
		} 

		//Check for MOD 10 Alogorhythm: (returns true or false)
		mod10 = checkMod10(cardNumber);
		if (!mod10) {
			return "unknownCard";
		}
	}


	if (cardNumber.charAt(0) == "4") {
		//Proceed with validation of a Visa Card Number
		cardType = "Visa";
		if (cardNumber.length != 16 && cardNumber.length != 13) {
			return "unknownCard";
		}
		
		//Check for Mod 10 Alogorhythm: (regurns true of false);
		mod10 = checkMod10(cardNumber);
		if (!mod10) {
			return "unknownCard";
		}
	}

	if (cardNumber.charAt(0) == "3") {
		//Proceed with validation of an American Express Card Number
		cardType = "AmericanExpress";
		
		prefix = cardNumber.substring(0,2);
		if (prefix != 34 && prefix != 37) {
			alert("Card Prefix: " + prefix);
			return "unknownCard";
		} 
		
		//Check length is 15;
		if (cardNumber.length != 15) {
			return "unknownCard";
		}
		
		//Check for Mod 10 Alogorhythm: (regurns true of false);
		mod10 = checkMod10(cardNumber);
		if (!mod10) {
			return "unknownCard";
		}

	}
	
	//If no errors nave caused a prior RETURN then return the cardType.
	return cardType;

}


function checkMod10(cardNumber) {
	var tempString = "";
	var position = 0;
	for (cm = cardNumber.length - 1; cm > -1; cm = cm - 1) {
		if (position == 0) {
			newValue = cardNumber.charAt(cm);
			position = 1;
		}
		else {
			newValue = 2 * cardNumber.charAt(cm);
			position = 0;
		}		
  		tempString = tempString + newValue;
	}
	//alert("Double Value String: " + tempString);
	//Tally all characters in the string:
	var tally = 0;
	for (cm = 0; cm < tempString.length; cm++) {
	 tally = tally + eval(tempString.charAt(cm));
	}
	
	//Check to see if the last digit in the tally is a "0" so that Mod10 will be true;
	testString = "" + tally;
	zeroPosition = testString.length - 1;
	testCharacter = testString.charAt(zeroPosition);
	
	if (testCharacter == "0") {
		return true;
	}
	return false;
}

function varifyEmail(email) {
//email must be at least 6 characters
//@ must be in the second or greater position
//a . must be eight 2 or 3 positions from the string end.
// The following characters must not be present:  / > ! # ?

	emailOk = true;
	domain1 = email.length - 3;
	domain2 = email.length - 4;
	domain3 = email.length - 5;
	if (email.length < 6) {
		emailOk = false;
	}
	if (email.indexOf("@") < 1) {
		emailOk = false;
	}
	if (email.charAt(domain1) != "." && email.charAt(domain2) != "." && email.charAt(domain3) != ".") {
		emailOk = false;
	}
	if (email.indexOf("/") >= 0) {
		emailOk = false;
	}
	if (email.indexOf("!") >= 0) {
		emailOk = false;
	}
	if (email.indexOf("?") >= 0) {
		emailOk = false;
	}
	if (email.indexOf(">") >= 0) {
		emailOk = false;
	}
	if (emailOk) {
		return true;
	}
	else {
	 	return false;
	}
}

function getFormFieldValue(formName, fieldName) {
 //set formValue variable to either true, false, or some string value
 var formValue = "null";
 var formElementType = getElementType(formName, fieldName);

 if(fieldName.indexOf("!") >= 0){
    var fieldArray = fieldName.split("!");
	formValue=Right(100+eval("document." + formName + "."+ fieldArray[0] +".value"),2)
	formValue+=Right(100+eval("document." + formName + "."+ fieldArray[1] +".value"),2)
	formValue+=eval("document." + formName + "."+ fieldArray[2] +".value")		
	return formValue;
 } 
 
 if(fieldName.indexOf("~") >= 0)
 {
    var fieldArray = fieldName.split("~");
	formValue=eval("document." + formName + "."+ fieldArray[0] +".value")
	for (w = 1; w < fieldArray.length; w++) 
	{
		formValue=formValue+"$"+eval("document." + formName + "."+ fieldArray[w] +".value")
	}
	return formValue;
 }
 //Get the number of elements in the form
 var numOfElements = eval("document." + formName + ".elements.length");
 //alert("Elements in Form: " + numOfElements)

 //Depending on element type check to see what the value is.
 if (formElementType == "text" || formElementType == "password" || formElementType == "file" || formElementType =="textarea" || formElementType == "hidden") {
   formValue = eval("document." + formName + "." + fieldName + ".value");
   
   //alert("Form Name: " + formName + "\nField Name: " + fieldName + "\nForm Value: " + formValue);
   //determin if 0 length string
   //determin if longer string is only 'space characters'
   if (formValue.length == 0) {
     formValue = "null";
    }
	if (formValue.length >= 1) {
	 isBlankEntry = isBlankSpace(formValue);
	 if (isBlankEntry) {
	   formValue = "null";
	 }
	}
 }
 
 if (formElementType.indexOf("select") >= 0) {
 	isSelected = eval("document." + formName + "." + fieldName + ".selectedIndex");
      if (isSelected <= 0) {
	  formValue = "null";
	}
	else {
    	  formValue = eval("document." + formName + "." + fieldName + ".options[" + isSelected + "].value")
	}
	//If an element has been selected then loop through the form elements and get the value


 }
 if (formElementType == "radio") {
	//alert(fieldName + " Is a Radio Button " + numOfElements);
      //loop through form elements where name = formName and see if any are checked.
      for (a=0; a < numOfElements; a++) {
	  var elementName = eval("document." + formName + ".elements[" + a + "].name");
	  if (elementName == fieldName) {
	    //alert("Element Name: " + elementName);
	    if (eval("document." + formName + ".elements[" + a + "].checked")) {
		formValue = eval("document." + formName + ".elements[" + a + "].value")
	    }
        }
	}
 }
 if (formElementType == "checkbox") {
	//alert(fieldName + " Is a CheckBox " + numOfElements);
	//Loop through elements and if none checked return "null"
	//Otherwise return a comma delineated list of elements checked.
	formValue = "";
	var numChecked = 0;

      for (a=0; a < numOfElements; a++) {
	  var elementName = eval("document." + formName + ".elements[" + a + "].name");
	  if (elementName == fieldName) {
	    //alert("Element Name: " + elementName);
	    if (eval("document." + formName + ".elements[" + a + "].checked")) {
		formValue = formValue + eval("document." + formName + ".elements[" + a + "].value") + ","
		numChecked++;
	    }
        }
	}
	if (numChecked == 0) {
	  formValue = "null";
	}
	else {
	  var formValueChopAt = formValue.length - 1;
	  formValue = formValue.substring(0,formValueChopAt);
	}
 }

//Complete if there is a reason for testing the value of the submit button 
if (formElementType == "submit") {
 }
  return formValue
}

function getElementType(formName, fieldName) {
 //alert("Getting Element Type for: " + fieldName)
 //loop through elements and get the number of the element with thie formName
 var formElementLen = eval("document." + formName + ".elements.length");
 var z = 0;

 for (u = 0; u < formElementLen; u++) {
   elementName = eval("document." + formName + ".elements[" + u + "].name");
   if (elementName == fieldName) {
     z = u
   }
 }
 elementType = eval("document." + formName + ".elements[" + z + "].type");
 
 return elementType
}

function isBlankSpace(formValue) {
	for (a=0; a < formValue.length; a++) {
	  var c = formValue.charAt(a);
	  //alert("Character(" + a + ") >" + c + "<");
	  if ((c != ' ') && (c != '\n') && (c != '/t')) return false;
	}
	return true;
}

function areYouSure(message)
{
	return confirm(message);
}

function ishttp (thisURL) {
	var exp = /^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,10}(\:[0-9]+)*$/;
    var regex = new RegExp(exp);
    var result;
    if (thisURL.length > 0)
     {
          result = regex.test(thisURL);
          if (result == false)
          {
               return false;
          }
		 else
          {
			if (thisURL.length >  7) {
			  if(thisURL.substring(0,7) !=  "http://") {
			     if (thisURL.substring(0,8) != "https://") {
				 	thisURL = "http://" + thisURL; 
						}
					 }
			 	}
	          return thisURL;
          }
     }
}
function isValidPhoneFax(mPhoneFax) 
{
    var fieldArray = mPhoneFax.split("$");
    var threeDigits = /^\d{3}$/
    var fourDigits = /^\d{4}$/   
    var extDigits = /^\d{0,5}$/   
	
    if (!threeDigits.test(fieldArray[0]))
	{
		return "InvalidAreaCode";	
	}	
    else if (!threeDigits.test(fieldArray[1]))
	{
		return "InvalidFirstThree";	
	}	
    else if (!fourDigits.test(fieldArray[2]))
	{
		return "InvalidLastFour";	
	}	
	else if(fieldArray.length == 4)
	{
	    if (!extDigits.test(fieldArray[3]))
		{
			return "InvalidExt";	
		}	
	}
	
	return true;  // Phone is valid
}
function isValidDate(cDate) 
{
	var month = parseInt(Left(cDate,2),10)
	var day = parseInt(Mid(cDate,2,2),10)
	var year = parseInt(Right(cDate,4),10)
	//check for 30 or 31 days in a month
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		return "invalidDay"
	}
	// check for february 29th
	if (month == 2) { 
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			return "invalidFebruary"
	   }
	}
	return true;  // date is valid
}
function Right(str, n)
{
     if (n <= 0)     
        return "";
     else if (n > String(str).length)   
        return str;                    
     else { 
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
     }
}
function Left(str, n)
{
     if (n <= 0)
        return "";
     else if (n > String(str).length)   
        return str;                
     else
         return String(str).substring(0,n);
}
function Mid(str, start, len)
{
      if (start < 0 || len < 0) return "";
      var iEnd, iLen = String(str).length;
      if (start + len > iLen)
          iEnd = iLen;
      else
          iEnd = start + len;

      return String(str).substring(start,iEnd);
}
function replaceString (input, search, replace) 
{
	var output = ""
	var i=0
	var f = input.indexOf(search,i)
	if (f == -1) {
		return input
	}
	while (i < input.length) {
		output = output + input.substring(i,f)
		if (f < input.length) {
			output = output + replace
		} else {
			break
		}
		i = f + search.length
		f = input.indexOf(search, i)
		if (f == -1) {
			f = input.length
		}
	}
	return output
}
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function setNextDate(theForm,daysAhead)
{
	var dd = parseInt(theForm.fDate.value.substring(0,2))
	var mm = parseInt(theForm.fDate.value.substring(3,5))-1
	var yy = parseInt(theForm.fDate.value.substring(6,10))
	var newDate = new Date(yy, mm, dd+daysAhead)
	dd = Right("10"+newDate.getDate().toString(),2)
	mm = Right("10"+(newDate.getMonth()+1).toString(),2)
	yy = newDate.getYear().toString()
	theForm.sDate.value= dd+"/"+mm+"/"+yy
}