
function validate() {
var pge=document.enq;

  // make sure they enter their name
  if (pge.cname.value.length == 0)
    {
    alert("Please enter a contact name.");
    pge.cname.focus();
    return false;
    }

   // make sure they enter their company
   if (pge.company.value.length == 0)
     {
     alert("Please enter a company name.");
     pge.company.focus();
     return false;
    }

 // make sure they enter their position
 if (pge.position.value.length == 0)
   {
   alert("Please enter your job title.");
   pge.position.focus();
   return false;
    }

   // make sure they enter their postcode
   if (pge.pc.value.length == 0)
     {
     alert("Please enter your postcode.");
     pge.pc.focus();
     return false;
    }

  // check to see if the email's valid
  if (!validEmail(pge.email.value)) {
    alert("We require a valid email address.");
    pge.email.focus();
    return false;
    }

    //check telephone number
  if (pge.tel.value == "" && pge.mobile.value == "") {
    alert("Please enter a contact number");
    pge.tel.focus();
    return false;
     }

   // make sure they enter the best time to call
   if (pge.thyme.value.length == 0)
     {
     alert("What is the best time for us to call you?");
     pge.thyme.focus();
     return false;
    }

   // make sure they enter their fleet size
   if (pge.vans.value.length == 0 && pge.cars.value.length == 0)
     {
     alert("Please enter your fleet size.");
     pge.cars.focus();
     return false;
    }

   // make sure they enter an enquiry
   if (pge.msg.value.length == 0)
     {
     alert("What are you interested in?");
     pge.msg.focus();
     return false;
    }

  // If we made it to here, everything's valid, so return true
  pge.submit();
  return true;
  }


// EMail Checker

function validEmail(email) {
 var invalidChars = " /:,;"
 var i

  if (email == "") {// cannot be empty
    return false;
  }
  for (i=0; i<invalidChars.length; i++) {  // does it contain any invalid characters?
    var badChar = invalidChars.charAt(i)
    if (email.indexOf(badChar,0) > -1) {
      return false;
    }
  }
  var atPos = email.indexOf("@",1)// there must be one "@" symbol
  if (atPos == -1) {
    return false;
  }
  if (email.indexOf("@",atPos+1) != -1) {  // and only one "@" symbol
    return false;
  }
  var periodPos = email.indexOf(".",atPos)
  if (periodPos == -1) {// and at least one "." after the "@"
    return false;
  }
  if (periodPos+3 > email.length) {// must be at least 2 characters after the "."
    return false;
  }
  return true;
}

