//form_validator.js

var WEBMASTER = "cristy@hawaii.rr.com";
var DEBUG = 0;

function Form_Validate(theForm)
{

  if (theForm.First_Name.value == "")
  {
    alert("Please enter a value for the \"First Name\"field.");
    theForm.First_Name.focus();
    return (false);
  }

  if (theForm.Last_Name.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.Last_Name.focus();
    return (false);
  }

  if (theForm.Address_1.value == "")
  {
    alert("Please enter a value for the \"Address 1\" field.");
    theForm.Address_1.focus();
    return (false);
  }

  if (theForm.City.value == "")
  {
    alert(" Please Enter A Value In The \"City\" field.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.State.value == "")
  {
    alert("Please enter a value for the \"State\" field.");
    theForm.State.focus();
    return (false);
  }

  if (theForm.Zip.value == "")
  {
    alert("Please enter a value for the \"Postal (Zip) Code\" field.");
    theForm.Zip.focus();
    return (false);
  }

  if (theForm.Email.value == "")
  {
    alert("Please enter a value for the \"Email Address\" field.");
    theForm.Email.focus();
    return (false);
  }

  if (theForm.Method_Of_Contact.selectedIndex <= 0)
  {
    alert("Please select one of the \"Preferred Method Of Contact\"options.");
    theForm.Method_Of_Contact.focus();
    return (false);
  }

  if (theForm.Vessel_Type.selectedIndex <= 0)
  {
    alert("Please select one of the \"Vessel Type\"options.");
    theForm.Vessel_Type.focus();
    return (false);
  }

   if (theForm.Length_Of_Vessel.value == "")
  {
    alert("Please enter a value for the \"Length Of Vessel\" field.");
    theForm.Length_Of_Vessel.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.Length_Of_Vessel.value;
  var allValid = 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;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Length Of Vessel\" field.");
    theForm.Length_Of_Vessel.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"Length Of Vessel\" field.");
    theForm.Length_Of_Vessel.focus();
    return (false);
  }

  if (theForm.Hull_Material.selectedIndex == 0)
  {
    alert("The first \"Hull Material\"option is not a valid selection.\nPlease choose one of the other options.");
    theForm.Hull_Material.focus();
    return (false);
  }

  if (theForm.Fuel.selectedIndex == 0)
  {
    alert("The first \"Fuel\" option is not a valid selection.\nPlease choose one of the other options.");
    theForm.Fuel.focus();
    return (false);
  }

  if (theForm.Vessel_Location.value == "")
  {
    alert("Please enter a value for the \"Vessel Location\" field.");
    theForm.Vessel_Location.focus();
    return (false);
  }

  if (theForm.Type_Of_Survey_Required.selectedIndex < 0)
  {
    alert("Please select one of the \"Type Of Survey Required\"options.");
    theForm.Type_Of_Survey_Required.focus();
    return (false);
  }

  if (theForm.Type_Of_Survey_Required.selectedIndex == 0)
  {
    alert("The first \"Type Of Survey Required\" option is not a valid selection.\nPlease choose one of the other options.");
    theForm.Type_Of_Survey_Required.focus();
    return (false);
  }

  if (theForm.Date_Survey_Required_By.value == "")
  {
    alert("Please enter a value for the \"Date Survey Required By\" field.");
    theForm.Date_Survey_Required_By.focus();
    return (false);
  }
  
  if(DEBUG == 1){
       theForm.recipient.value = WEBMASTER;
  }
   return (true);
}
