// JavaScript Document
<!--
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

//form validation functions below//////////////////////////////////////////////////////////////
function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

function Form1_Validator(theform)
{
  if (theform.Company_Name.value == "")
  {
	alert("Please enter your \"Company Name\"");
	theform.Company_Name.focus();
	return (false);
  }

  if (theform.Name.value == "")
  {
	alert("Please enter your \"First & Last Name\"");
	theform.Name.focus();
	return (false);
  }

  if (theform.Address_1.value == "")
  {
	alert("Please enter your \"Address\"");
	theform.Address_1.focus();
	return (false);
  }

  if (theform.City.value == "")
  {
	alert("Please enter your \"City\"");
	theform.City.focus();
	return (false);
  }

  if (theform.State_Province.value == "")
  {
	alert("Please enter your \"State / Province\"");
	theform.State_Province.focus();
	return (false);
  }

  if (theform.State_Province.value == "")
  {
	alert("Please enter your \"State / Province\"");
	theform.State_Province.focus();
	return (false);
  }

  if (theform.Zip_Postal_Code.value == "")
  {
	alert("Please enter your \"Zip / Postal Code\"");
	theform.Zip_Postal_Code.focus();
	return (false);
  }

  if (theform.Phone_Number.value == "")
  {
	alert("Please enter your \"Phone Number\"");
	theform.Phone_Number.focus();
	return (false);
  }

  var num = theform.Phone_Number.value;
  if (!(num.length == 12) || !(num.charAt(3) == "-") || !(num.charAt(7) == "-"))
	{
	alert("Please enter Phone Number in xxx-xxx-xxxx format.");
	theform.Phone_Number.focus();
	return(false);
	}  
  //num = replaceSubstring(num,"(","");
  //num = replaceSubstring(num,")","");
  //num = replaceSubstring(num," ","");
  num = replaceSubstring(num,"-","");
  
  if (!(IsNumeric(num)))
	{
	alert("Please enter Phone Number in xxx-xxx-xxxx format.");
	theform.Phone_Number.focus();
	return (false);
	}
	
  if (!(num.length == 10))
	{
	alert("Please enter phone Number in xxx-xxx-xxxx format.");
	theform.Phone_Number.focus();
	return (false);
	}

var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
  var regex = new RegExp(emailReg);
		if (theform.email.value.length == 0)
	{
			alert("Please enter a valid \"eMail Address\" ");
			theform.email.focus();
		return (false);
	}

  if (theform.email.value.length > 0)
	{
		if (!(regex.test(theform.email.value)))
		{
			alert("Please enter a valid \"eMail Address\" ");
			theform.email.focus();
			return (false);
		}
	}

  if (theform.email.value.length > 75)
  {
	alert("Please limit your \"eMail Address\" field to 75 characters ");
	theform.email.focus();
	return (false);
  } 

	if (document.theform.information.options[document.theform.information.selectedIndex].value == "Select Information")
	{
	alert("Please select the \"Information Needed\" ");
	theform.information.focus();
	return (false);
	}

return (true);
}
//-->
