// Form Validator
function form_val(theForm)
{

  if (theForm.fname.value == "")
  {
    alert("Please provide your First name in the \"First Name\" box.");
    theForm.fname.focus();
    return (false);
  }

  if (theForm.fname.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"First Name\" box.");
    theForm.fname.focus();
    return (false);
  }
  
  if (theForm.lname.value == "")
  {
    alert("Please provide your Last name in the \"Last Name\" box.");
    theForm.lname.focus();
    return (false);
  }

  if (theForm.lname.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Last Name\" box.");
    theForm.lname.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.htel.value == "")
  {
    alert("Please provide a valid telephone number in the \"Home Telephone\" box.");
    theForm.htel.focus();
    return (false);
  }

  if (theForm.htel.value.length < 9)
  {
    alert("Please enter at least 9 characters in the \"Home Telephone\" box.");
    theForm.htel.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.htel.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 \"Home Telephone\" box.");
    theForm.htel.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please provide a valid telephone number in the \"Home Telephone\" box.");
    theForm.htel.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.ccno.value == "")
  {
    alert("Please provide your 16 digit Credit Card number in the \"Card No.\" box.");
    theForm.ccno.focus();
    return (false);
  }

  if (theForm.ccno.value.length < 16)
  {
    alert("Your Card No. is less than 16 digits. Please Check the \"Card No.\" box.");
    theForm.ccno.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.ccno.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 \"Card No.\" box.");
    theForm.ccno.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please provide your 16 digit Credit Card number in the \"Card No.\" box.");
    theForm.ccno.focus();
    return (false);
  }

  if (theForm.expdate.value == "")
  {
    alert("Please provide the expiry date of your card in the \"Expiry Date\" box.");
    theForm.expdate.focus();
    return (false);
  }

  if (theForm.expdate.value.length < 7)
  {
    alert("Please the expiry date in the format mm/yyyy in the \"Expiry Date\" box.");
    theForm.expdate.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);
}