function formValidator(){
// Make quick references to our fields
var name = document.getElementById('name');
var add1 = document.getElementById('add1');
var add2 = document.getElementById('add2');
var town = document.getElementById('town');
var pc = document.getElementById('pc');
var tel = document.getElementById('tel');
var mob = document.getElementById('mob');
var email = document.getElementById('email');

var house_type = document.getElementById('house_type');
var house_bathrooms = document.getElementById('house_bathrooms');
var house_bedrooms = document.getElementById('house_bedrooms');
var house_toilets = document.getElementById('house_toilets');
var house_reception = document.getElementById('house_reception');
var house_garage = document.getElementById('house_garage');
var house_condition = document.getElementById('house_condition');

var house_hold = document.getElementById('house_hold');
var house_built = document.getElementById('house_built');
var house_structural = document.getElementById('house_structural');
var house_flat = document.getElementById('house_flat');
var house_floor = document.getElementById('house_flat_floor');
var house_value = document.getElementById('house_value');
var house_market = document.getElementById('house_market');
var house_market_price = document.getElementById('house_market_price');

var house_loans = document.getElementById('house_loans');
var house_loan_amount = document.getElementById('house_loan_amount');
var house_mortgage = document.getElementById('house_mortgage');

// Check each input in the order that it appears in the form!
if ((notEmpty(name, "Please enter your name"))&&(notEmpty(add1, "Please enter the first line of your address"))&&(notEmpty(town, "Please enter your town"))&&(notEmpty(pc, "Please enter your postcode"))&&(notEmpty(tel, "Please enter your telephone number"))&&(notEmpty(mob, "Please enter your mobile number"))&&(notEmpty(email, "Please enter your email"))&&(notEmpty(house_type, "Please enter the type of house"))&&(notEmpty(house_bedrooms, "Please enter the number of bedrooms"))&&(notEmpty(house_bathrooms, "Please enter the number of bathrooms"))&&(notEmpty(house_toilets, "Please enter number of seperate toilets"))&&(notEmpty(house_reception, "Please enter the number of reception rooms"))&&(notEmpty(house_garage, "Please say whether the property has a garage. If it does not - please enter 'no'"))&&(notEmpty(house_garden, "Please say whether the property has a garden. If it does not - please enter 'no'"))&&(notEmpty(house_condition, "Please enter the overall condition of the property"))&&(notEmpty(house_hold, "Please enter whether the property is freehold or leasehold"))&&(notEmpty(house_built, "Please enter the year the property was built - if you are unsure please estimate or enter '0'"))&&(notEmpty(house_structural, "Please enter the structutal condition of the property"))&&(notEmpty(house_flat, "Please answer whether the property is a flat. If it is not simply enter 'no'"))&&(notEmpty(house_floor, "If the property is not a flat please enter '0' otherwise enter the floor of the flat"))&&(notEmpty(house_value, "Please enter the estimated value of the property"))&&(notEmpty(house_market, "Please say whether the the property is on the market, if it is not simply enter 'no'"))&&(notEmpty(house_market_price, "If the house is not on the market, simply enter '0' otherwise enter market price"))&&(notEmpty(house_loans, "Please say whether there are any outstanding loans on the property"))&&(notEmpty(house_loan_amount, "If there are no outstanding loans, simply enter '0' otherwise enter the loan amount"))&&(notEmpty(house_mortgage, "If there is no outstanding mortgage, simply enter '0' otherwise enter the mortgage amount")))
{
    return true;
}
else
{
    return false;
}                                
}

function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
        alert(helperMsg);
        elem.focus(); // set the focus to this input
        return false;
}
return true;
}

function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
        return true;
}else{
        alert(helperMsg);
        elem.focus();
        return false;
}
}

function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
        return true;
}else{
        alert(helperMsg);
        elem.focus();
        return false;
}
}

function isAlphanumeric(elem, helperMsg){
var alphaExp = /^[0-9a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
        return true;
}else{
        alert(helperMsg);
        elem.focus();
        return false;
}
}

function lengthRestriction(elem, min, max){
var uInput = elem.value;
if(uInput.length >= min && uInput.length <= max){
        return true;
}else{
        alert("Please enter between " +min+ " and " +max+ " characters");
        elem.focus();
        return false;
}
}

function madeSelection(elem, helperMsg){
if(elem.value == "Please Choose"){
        alert(helperMsg);
        elem.focus();
        return false;
}else{
        return true;
}
}

function emailValidator(elem, helperMsg){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){
        return true;
}else{
        alert(helperMsg);
        elem.focus();
        return false;
}
}
