
function validate(){
    var errs="";
    errs += checkFName(document.sform.first_name.value);
    errs += checkLName(document.sform.last_name.value);
    errs += checkPhone(document.sform.phone.value);
    errs += checkEmail(document.sform.email.value);
    errs += checkCompany(document.sform.company.value);
    errs += checkCity(document.sform.city.value);

    if(errs!=""){
        alert(errs); 
        return false;
    }
    return true;
    
}

function checkFName(strng){
    var error = "";
    if(strng.length < 2){
        error = "Please enter your first name.\n";
    }
    return error;
}

function checkLName(strng){
    var error = "";
    if(strng.length < 2){
        error = "Please enter your last name.\n";
    }
    return error;
}

function checkCompany(strng){
    var error = "";
    if(strng.length < 2){
        error = "Please enter the name of your company or dealership.\n";
    }
    return error;
}
function checkCity(strng){
    var error = "";
    if(strng.length < 2){
        error = "Please enter your city.\n";
    }
    return error;
}

function checkPhone (strng) {
    var error = "";
    if (strng == "") {
        return "Please enter your phone number.\n";
    }

    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); 
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
    }else{
        if (!(stripped.length == 10)) {
            error = "The phone number should be 10 digits. Make sure you included an area code.\n";
        } 
    }
    return error;
}

function checkEmail(strng){
    var error="";
    if(strng == ""){
        return "Please enter your email address.\n";
    }
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error += "Please enter a valid email address.\n";
    }else{
        var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
        if (strng.match(illegalChars)) {
            error += "The email address contains illegal characters.\n";
        }
    }
    return error;
}
