function validateCar(theForm) {
var reason = "";
var value = document.getElementById("trtype").value;
  reason += validateName(theForm.name);
  reason += validateEmail(theForm.email);
  reason += validatePhone(theForm.phone);
  reason += validateCountry(theForm.country);
  reason += validateService(theForm.service);
  if (value == 'Yes')
  {
  reason += validateTransferType(theForm.transfertype);
  }
  reason += validatePayment(theForm.payment);
  reason += validateDay(theForm.day);
  reason += validateMonth(theForm.month);
  reason += validateYear(theForm.year);
  reason += validateDays(theForm.ndays);
  reason += validateClients(theForm.nclients);
  
  if (reason != "") {
    alert("Some required fields are not filled out:\n" + reason);
    return false;
  }

   
}
function validateTransferType(fld) {
    var error = "";
 
    if (fld.value == "no") {
        fld.style.background = '#fcbf03'; 
        error = "- No tranfer type selected\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#fcbf03'; 
        error = "- Full Name\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateService(fld) {
    var error = "";
    var value = fld.value;
    if (fld.value == "no") {
        fld.style.background = '#fcbf03'; 
        error = "- No service selected\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
    
}
function validatePayment(fld) {
    var error = "";
 
    if (fld.value == "no") {
        fld.style.background = '#fcbf03'; 
        error = "- No payment selected\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateDay(fld) {
    var error = "";
 
    if (fld.value == "no") {
        fld.style.background = '#fcbf03'; 
        error = "- No day selected\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateMonth(fld) {
    var error = "";
 
    if (fld.value == "no") {
        fld.style.background = '#fcbf03'; 
        error = "- No month selected\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateYear(fld) {
    var error = "";
    
    if (fld.value == "no") {
        fld.style.background = '#fcbf03'; 
        error = "- No year selected\n";
    } 
    else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateCountry(fld) {
    var error = "";
    var country = document.getElementById("c").value;
    var bg = document.getElementById("c");
    if (country == "no") {
        bg.style.background = '#fcbf03'; 
        error = "- No country selected\n";
    } 
    else 
    {
        bg.style.background = 'White';
    }
    return error;  
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#fcbf03';
        error = "- Email address\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#fcbf03';
        error = "- Please enter a valid email address\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#fcbf03';
        error = "- The email address contains illegal characters\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
    var illegalChars = /[\a-z]/;
    if (fld.value == "") {
        fld.style.background = '#fcbf03';
        error = "- Phone\n";
    }  else if (isNaN(parseInt(stripped))) 
    {
        error = "- Phone must contain digits and + only\n";
        fld.style.background = '#fcbf03';
    }
    else if  (illegalChars.test(fld.value))
    {
        error = "- Phone must contain digits and + only\n";
        fld.style.background = '#fcbf03';
    }
    else if (stripped.length < 9) {
        error = "- Make sure you included country and city code.\n";
        fld.style.background = '#fcbf03';
    }
    else {
        fld.style.background = 'White';
    }
   return error;
}
function validateDays(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    
    var illegalChars = /[\W_a-z]/;
   if (fld.value == "") {
        error = "- Number of Days\n";
        fld.style.background = '#fcbf03';
    }  
    else if (illegalChars.test(fld.value))
    {
      error = "- #Days should be a number\n";
      fld.style.background = '#fcbf03';
    }
    else if (isNaN(parseInt(stripped))) {
        error = "- #Days should be a number\n";
        fld.style.background = '#fcbf03';
    }
    else {
        fld.style.background = 'White';
    }

    return error;

}
function validateClients(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    
    var illegalChars = /[\W_a-z]/;
   if (fld.value == "") {
        error = "- Number of Tourists\n";
        fld.style.background = '#fcbf03';
    }  
    else if (illegalChars.test(fld.value))
    {
      error = "- #Tourists should be a number\n";
      fld.style.background = '#fcbf03';
    }

    else if (isNaN(parseInt(stripped))) {
        error = "- #Tourists should be a number\n";
        fld.style.background = '#fcbf03';
    }
    else {
        fld.style.background = 'White';
    }

    return error;

}





