// JavaScript Document

function Form_Validator(theForm)
{

  if (theForm.firstName.value == "")
  {
    alert("Please enter a value for the \"FirstName\" field.");
    theForm.firstName.focus();
    return (false);
  }

  if (theForm.firstName.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"FirstName\" field.");
    theForm.firstName.focus();
    return (false);
  }

  if (theForm.firstName.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"FirstName\" field.");
    theForm.firstName.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f";
  var checkStr = theForm.firstName.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and whitespace characters in the \"FirstName\" field.");
    theForm.firstName.focus();
    return (false);
  }

  if (theForm.lastName.value == "")
  {
    alert("Please enter a value for the \"lastName\" field.");
    theForm.lastName.focus();
    return (false);
  }

  if (theForm.lastName.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"lastName\" field.");
    theForm.lastName.focus();
    return (false);
  }

  if (theForm.lastName.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"lastName\" field.");
    theForm.lastName.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f";
  var checkStr = theForm.lastName.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and whitespace characters in the \"lastName\" field.");
    theForm.lastName.focus();
    return (false);
  }

  if (theForm.city.value == "")
  {
    alert("Please enter a value for the \"city\" field.");
    theForm.city.focus();
    return (false);
  }

  if (theForm.city.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"city\" field.");
    theForm.city.focus();
    return (false);
  }

  if (theForm.city.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"city\" field.");
    theForm.city.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f";
  var checkStr = theForm.city.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and whitespace characters in the \"city\" field.");
    theForm.city.focus();
    return (false);
  }

  if (theForm.county.value == "")
  {
    alert("Please enter a value for the \"county\" field.");
    theForm.county.focus();
    return (false);
  }

  if (theForm.county.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"county\" field.");
    theForm.county.focus();
    return (false);
  }

  if (theForm.county.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"county\" field.");
    theForm.county.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f";
  var checkStr = theForm.county.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and whitespace characters in the \"county\" field.");
    theForm.county.focus();
    return (false);
  }

  if (theForm.state.selectedIndex < 0)
  {
    alert("Please select one of the \"state\" options.");
    theForm.state.focus();
    return (false);
  }

  if (theForm.state.selectedIndex == 0)
  {
    alert("The first \"state\" option is not a valid selection.  Please choose one of the other options.");
    theForm.state.focus();
    return (false);
  }

  if (theForm.postCode.value == "")
  {
    alert("Please enter a value for the \"postCode\" field.");
    theForm.postCode.focus();
    return (false);
  }

  if (theForm.postCode.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"postCode\" field.");
    theForm.postCode.focus();
    return (false);
  }

  if (theForm.postCode.value.length > 5)
  {
    alert("Please enter at most 5 characters in the \"postCode\" field.");
    theForm.postCode.focus();
    return (false);
  }

  var checkOK = "0123456789-";
  var checkStr = theForm.postCode.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"postCode\" field.");
    theForm.postCode.focus();
    return (false);
  }

  if (theForm.email.value == "")
  {
    alert("Please enter a value for the \"email\" field.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.email.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"email\" field.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.email.value.length > 100)
  {
    alert("Please enter at most 100 characters in the \"email\" field.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.comments.value == "")
  {
    alert("Please enter a value for the \"comments\" field.");
    theForm.comments.focus();
    return (false);
  }

  if (theForm.comments.value.length < 20)
  {
    alert("Please enter at least 20 characters in the \"comments\" field.");
    theForm.comments.focus();
    return (false);
  }
  return (true);
}
