

function validate_contactUs(thisform)
{

   with (thisform){

     if(whoto.selectedIndex == 0){
        whoto.focus();
        giveFeedback("Please choose a recipient.");
        return false;
     }
     else if (!make.value){
        make.focus();
        giveFeedback("Please type in the make of your vehicle.");
        return false;
     }
     else if (!model.value){
        model.focus();
        giveFeedback("Please type in the model of your vehicle.");
        return false;
     }
     else if (!valButton(fuel)){
        fuelNone = document.getElementById('fuel_none');
        fuelNone.focus();
        giveFeedback("Please tell us the type of engine in your vehicle.");
        return false;
     }
     else if (vanSize.value=="Van Size..."){
        vanSize.focus();
        giveFeedback("Please tell us the size of your vehicle.");
        return false;
     }  
     else if (!colour.value){
        colour.focus();
        giveFeedback("What colour is your vehicle?");
        return false;
     }
     else if (!year.value){
        year.focus();
        giveFeedback("Please type in the model of this vehicle.");
        return false;
     }
     else if (!reg.value){
        reg.focus();
        giveFeedback("Please type in the registration number of this vehicle.");
        return false;
     }
     else if (!mileage.value){
        mileage.focus();
        giveFeedback("Please tell us the mileage of this vehicle.");
        return false;
     }
     else if (mot_month.value=="Month..."){
        mot_month.focus();
        giveFeedback("Please tell us the month the MOT for this vehicle runs out.");
        return false;
     }
     else if (mot_year.value=="Year..."){
        mot_year.focus();
        giveFeedback("Please tell us the year the MOT for this vehicle runs out.");
        return false;
     }
     else if (!valButton(service)){
        serviceNone = document.getElementById('service_none');
        serviceNone.focus();
        giveFeedback("Please indicate the service history of this vehicle.");
        return false;
     }
     else if (!valButton(condition)){
        conditionPoor = document.getElementById('condition_poor');
        conditionPoor.focus();
        giveFeedback("Please tell us the condition of the vehicle.");
        return false;
     }
     else if (!name.value){
        name.focus();
        giveFeedback("Please type in your name.");
        return false;
     }
     else if (!validate_email(email)){
        email.focus();
        giveFeedback("Your email doesn't seem to be valid.");
        return false;
     }
     else if (!mobile.value){
        mobile.focus();
        giveFeedback("Please type in your phone number. ");
        return false;
     }
     else if (!postcode.value){
        postcode.focus();
        giveFeedback("Please type in your postcode. ");
        return false;
     }
     else{
        return true;
     }
  }

  return true;

}


function validate_email(field)
{
  //alert("validate_email");
  reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

  //alert("field: "+field.value);
  if (!reg.test(field.value)){
    // Basic check
    //alert(' failed against reg expression');
    return false;
  }
  else{
    return true;
  }
}
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function giveFeedback(feedbackString){
   //alert("failed validation");
   var feedback = document.getElementById('contactUsFeedback');
   feedback.innerHTML = feedbackString;
   feedback.style.display="block";

   var feedback2 = document.getElementById('contactUsFeedback2');
   feedback2.innerHTML = feedbackString;
   feedback2.style.display="block";
}

