function IsLength(String,Len) {
   // return false if String has fewer than "Len" non-blank characters
  if (String.length == 0) return false;
  var count = 0;
  for (var i=0; i<String.length; i++) {
       var ch = String.charAt(i);
       if ((ch != " ") && (ch != "\t")) count++; }
  if (count >= Len) return true;
  return false; }

function IsEmailFmt(strEmail) {
  // The following pattern is used to check if the entered e-mail address
  // fits the user@domain format.  It also is used to separate the username
  // from the domain.
  var emailPat = /^(.+)@(.+)$/;

  // The following string represents the pattern for matching all special
  // characters.  We don't want to allow special characters in the address. 
  // These characters include ( ) < > @ , ; : \ " . [ ]
  var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";

  // The following string represents the range of characters allowed in a 
  // username or domainname.  It really states which chars aren't allowed.
  var validChars = "\[^\\s" + specialChars + "\]";

  // The following pattern applies if the "user" is a quoted string (in
  // which case, there are no rules about which characters are allowed
  // and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
  // is a legal e-mail address.
  var quotedUser = "(\"[^\"]*\")";

  // The following pattern applies for domains that are IP addresses,
  // rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
  // e-mail address. NOTE: The square brackets are required.
  var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

  // The following string represents an atom (basically a series of
  // non-special characters.)
  var atom = validChars + '+';

  // The following string represents one word in the typical username.
  // For example, in john.doe@somewhere.com, john and doe are words.
  // Basically, a word is either an atom or quoted string.
  var word = "(" + atom + "|" + quotedUser + ")";

  // The following pattern describes the structure of the user
  var userPat = new RegExp("^" + word + "(\\." + word + ")*$");

  // The following pattern describes the structure of a normal symbolic
  // domain, as opposed to ipDomainPat, shown above.
  var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");

  // Begin with the coarse pattern to simply break up user@domain into
  // different pieces that are easy to analyze.
  var matchArray = strEmail.match(emailPat);
  if (matchArray == null) return "Email address seems incorrect (check @ and .'s)";

  // See if "user" is valid 
  var user=matchArray[1];
  var domain=matchArray[2];
  if (user.match(userPat) == null) return "The username doesn't seem to be valid.";

  // if the e-mail address is at an IP address (as opposed to a symbolic
  // host name) make sure the IP address is valid.
  var IPArray = domain.match(ipDomainPat);
  if (IPArray != null) {
    // this is an IP address
    for (var i=1;i<=4;i++) {
      if (IPArray[i]>255) return "Destination IP address is invalid (e.g. 255.255.255.255)!"; } }

  // Domain is symbolic name
  var domainArray=domain.match(domainPat);
  if (domainArray==null) return "The email address domain name doesn't seem to be valid.";

  // domain name seems valid, but now make sure that it ends in a
  // three or four-letter TLD (like com, edu, gov, info) or a two-letter TLD,
  // representing country (uk, nl), and that there's a hostname preceding 
  // the domain or country.

  // Now we need to break up the domain to get a count of how many atoms
  // it consists of.
  var atomPat = new RegExp(atom,"g");
  var domArr = domain.match(atomPat);
  var len = domArr.length;
  if (domArr[domArr.length-1].length < 2 || domArr[domArr.length-1].length > 4) {
    return "The email address must end in a two, three, or four-letter top-level \n domain (e.g. CA, UK, TV, COM, NET, ORG, INFO, etc.)."; }

  // Make sure there's a subdomain preceding the TLD.
  if (len < 2) return "The email domain is incomplete!";

  // Subdomain minimum length check
  if (domArr[domArr.length-2].length < 2) {
    return "The email address must contain at least a two-letter domain (e.g. GE.com, MSN.com, etc.)."; }

  return ""; }


function ValidateLinkForm() {
  var doSubmit = true;
  var strError = '';

  // check for value in Customer_Name field
  if (document.form1.Customer_Name.value == '') {
    alert('Please enter your name.');
    document.form1.Customer_Name.focus();
    doSubmit = false; }

  // check for value in Company field
  if ((doSubmit) && (document.form1.Company.value == '')) {
    alert('Please enter your company name.');
    document.form1.Company.focus();
    doSubmit = false; }

  // check for value in Phone field
  if ((doSubmit) && (!IsLength(document.form1.Phone.value,7))) {
    alert('Please enter at your phone number, including area code.');
    document.form1.Phone.focus();
    doSubmit = false; }

  // check for valid email address
  strError = IsEmailFmt(document.form1.Email_Address.value);
  if ((doSubmit) && (strError != '')) {
    alert(strError + '\n\nPlease enter a valid email address.');
    document.form1.Email_Address.focus();
    doSubmit = false; }

  // check for value in Street Address field
  if ((doSubmit) && (document.form1.Street_Address1.value == '')) {
    alert('Please enter your street address.');
    document.form1.Street_Address1.focus();
    doSubmit = false; }

  // check for value in City field
  if ((doSubmit) && (!IsLength(document.form1.City.value,3))) {
    alert('Please enter at least 3 characters for your city.');
    document.form1.City.focus();
    doSubmit = false; }

  // check for value in State field
  if ((doSubmit) && (!IsLength(document.form1.State.value,2))) {
    alert('Please enter at least 2 characters for your state.');
    document.form1.State.focus();
    doSubmit = false; }

  // check for value in Zip field
  if ((doSubmit) && (!IsLength(document.form1.Zip.value,5))) {
    alert('Please enter at least 5 characters for your zipcode.');
    document.form1.Zip.focus();
    doSubmit = false; }

  // check for value in Web_Address field
  if ((doSubmit) && (document.form1.Web_Address.value == '')) {
    alert('Please enter your website address.');
    document.form1.Web_Address.focus();
    doSubmit = false; }

  // if no errors then submit the form
  if (doSubmit == true) { document.form1.submit(); } }


function ValidateFeedbackForm() {
  var doSubmit = true;
  var strError = '';

  // check for value in Customer_Name field
  if (document.form1.Customer_Name.value == '') {
    alert('Please enter your name.');
    document.form1.Customer_Name.focus();
    doSubmit = false; }

  // check for value in Phone field
  if ((doSubmit) && (!IsLength(document.form1.Phone.value,7))) {
    alert('Please enter at least 7 characters for your phone number.');
    document.form1.Phone.focus();
    doSubmit = false; }

  // check for valid email address
  strError = IsEmailFmt(document.form1.Email_Address.value);
  if ((doSubmit) && (strError != '')) {
    alert(strError + '\n\nPlease enter a valid email address.');
    document.form1.Email_Address.focus();
    doSubmit = false; }

  // check for value in Street Address field
  if ((doSubmit) && (document.form1.Street_Address1.value == '')) {
    alert('Please enter your street address.');
    document.form1.Street_Address1.focus();
    doSubmit = false; }

  // check for value in City field
  if ((doSubmit) && (!IsLength(document.form1.City.value,3))) {
    alert('Please enter at least 3 characters for your city.');
    document.form1.City.focus();
    doSubmit = false; }

  // check for value in State field
  if ((doSubmit) && (!IsLength(document.form1.State.value,2))) {
    alert('Please enter at least 2 characters for your state.');
    document.form1.State.focus();
    doSubmit = false; }

  // check for value in Zip field
  if ((doSubmit) && (!IsLength(document.form1.Zip.value,5))) {
    alert('Please enter at least 5 characters for your zipcode.');
    document.form1.Zip.focus();
    doSubmit = false; }

  // check for value in Web_Address field
  if ((doSubmit) && (!IsLength(document.form1.Web_Address.value,5))) {
    alert('Please enter your website address.');
    document.form1.Web_Address.focus();
    doSubmit = false; }

  // check for selected value in Quality_Of_Service field
  if ((doSubmit) && (document.form1.Quality_Of_Service.selectedIndex == 10)) {
    alert('Please rate us on the quality of our service.');
    document.form1.Quality_Of_Service.focus();
    doSubmit = false; }

  // check for selected value in Quality_Of_Web_Page field
  if ((doSubmit) && (document.form1.Quality_Of_Web_Page.selectedIndex == 10)) {
    alert('Please rate us on the quality of our website.');
    document.form1.Quality_Of_Web_Page.focus();
    doSubmit = false; }

  // if no errors then submit the form
  if (doSubmit == true) { document.form1.submit(); } }


function ValidateQuoteForm() {
  var doSubmit = true;
  var strError = '';

  // check for value in Customer_Name field
  if (document.form1.Name.value == '') {
    alert('Please enter your name.');
    document.form1.Name.focus();
    doSubmit = false; }

  // check for value in Phone field
  if ((doSubmit) && (!IsLength(document.form1.Phone.value,7))) {
    alert('Please enter at least 7 characters for your phone number.');
    document.form1.Phone.focus();
    doSubmit = false; }

  // check for valid email address
  strError = IsEmailFmt(document.form1.Email.value);
  if ((doSubmit) && (strError != '')) {
    alert(strError + '\n\nPlease enter a valid email address.');
    document.form1.Email.focus();
    doSubmit = false; }

  // check for selected value in MARKETING field
  if ((doSubmit) && (document.form1.MARKETING.selectedIndex == 0)) {
    alert('Please tell us how you heard about us.');
    document.form1.MARKETING.focus();
    doSubmit = false; }

  // if no errors then submit the form
  if (doSubmit == true) { document.form1.submit(); } }


