// Form Validator
function form_val(theForm)
{

  if (theForm.Name.value == "")
  {
    alert("Please provide your full name in the \"Name\" box.");
    theForm.Name.focus();
    return (false);
  }

  if (theForm.Name.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Name\" box.");
    theForm.Name.focus();
    return (false);
  }

 // if (theForm.Company.value == "")
  //{
  //  alert("Please enter a value for the \"Company\" field.");
  //  theForm.Company.focus();
  //  return (false);
 // }

  //if (theForm.Company.value.length < 3)
  //{
 //   alert("Please enter at least 3 characters in the \"Company\" field.");
  //  theForm.Company.focus();
  //  return (false);
  //}

  if (theForm.Post_Code.value == "")
  {
    alert("Please provide your Post Code the \"Post_Code\" box.");
    theForm.Post_Code.focus();
    return (false);
  }

  if (theForm.Post_Code.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"Post_Code\" box.");
    theForm.Post_Code.focus();
    return (false);
  }

  if (theForm.Telephone.value == "")
  {
    alert("Please provide a valid telephone or mobile number in the \"Telephone\" box.");
    theForm.Telephone.focus();
    return (false);
  }

  if (theForm.Telephone.value.length < 9)
  {
    alert("Please enter at least 9 characters in the \"Telephone\" box.");
    theForm.Telephone.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.Telephone.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;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Telephone\" box.");
    theForm.Telephone.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please provide a valid telephone or mobile number in the \"Telephone\" box.");
    theForm.Telephone.focus();
    return (false);
  }

  if (theForm.Make.value == "")
  {
    alert("Please provide your vehicle\'s Make in the \"Make\" box.");
    theForm.Make.focus();
    return (false);
  }

  if (theForm.Make.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Make\" box.");
    theForm.Make.focus();
    return (false);
  }

  if (theForm.Model.value == "")
  {
    alert("Please provide your vehicles model type in the \"Model\" box.");
    theForm.Model.focus();
    return (false);
  }

  if (theForm.Model.value.length < 2)
  {
    alert("Please Provide at least 2 characters in the \"Model\" box.");
    theForm.Model.focus();
    return (false);
  }

  if (theForm.Engine_Size.value == "")
  {
    alert("Please provide the engine size (cc) in the \"Engine_Size\" box.");
    theForm.Engine_Size.focus();
    return (false);
  }

  if (theForm.Engine_Size.value.length < 3)
  {
    alert("Please provide at least 3 characters in the \"Engine_Size\" box.");
    theForm.Engine_Size.focus();
    return (false);
  }

  if (theForm.Year.value == "")
  {
    alert("Please provide the year of manufacture of your vehicle in the \"Year\" box.");
    theForm.Year.focus();
    return (false);
  }

  if (theForm.Year.value.length < 4)
  {
    alert("Please enter at least 4 numbers in the \"Year\" box.");
    theForm.Year.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.Year.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;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Year\" box.");
    theForm.Year.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please provide the year of manufacture of your vehicle in the \"Year\" box.");
    theForm.Year.focus();
    return (false);
  }

  if (theForm.Registration_Number.value == "")
  {
    alert("Please provide your vehicles registration number in the \"Registration_Number\" box.");
    theForm.Registration_Number.focus();
    return (false);
  }

  if (theForm.Registration_Number.value.length < 3)
  {
    alert("Please provide at least 3 characters in the \"Registration_Number\" box.");
    theForm.Registration_Number.focus();
    return (false);
  }

  if (theForm.Email.value == "")
  {
    alert("Please provide your valid email address in the \"Email\" box.");
    theForm.Email.focus();
    return (false);
  }

  if (theForm.Email.value.length < 6)
  {
    alert("Please provide at least 6 characters in the \"Email\" box.");
    theForm.Email.focus();
    return (false);
  }

  if (theForm.Enquiry_Details.value == "")
  {
    alert("Please provide details of your enquiry in the \"Enquiry Details\" box.");
    theForm.Email.focus();
    return (false);
  }
   return (true);
}