  var win = null;
  function newWindow(mypage,myname,w,h,features) {
  var winl = (screen.width-w)/0;
  var wint = (screen.height-h)/0;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
  }
  
  var win = null;
function newWindow2(mypage,myname,w,h,features) {
  var winl = (screen.width-w)/1;
  var wint = (screen.height-h)/0;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}


  function formValidator(){
  // Make quick references to our fields
  var firstname = document.getElementById('firstname');
  var lastname = document.getElementById('lastname');
  var email = document.getElementById('email');
  var postcode = document.getElementById('postcode');
  var subject = document.getElementById('subject');
  var mhmake = document.getElementById('mhmake');
  var mhmodel = document.getElementById('mhmodel');
  var varient = document.getElementById('varient');
  var fuel = document.getElementById('fuel');
  var miles = document.getElementById('miles');
  var age = document.getElementById('age');
  var verifymail = document.getElementById('verifymail'); 
  var BuyerAlert = document.getElementById('BuyerAlert');
  
  // Check each input in the order that it appears in the form!
  if(isAlphanumeric(firstname, "Please enter a contact name. No brackets, square brackets or quotation marks please.")){
    if(isAlphanumeric(lastname, "Please enter your company name. No brackets, square brackets or quotation marks please.")){
      if(emailValidator(email, "Please enter a valid email address")){
        if(isAlphanumeric(postcode, "Please enter your postcode.")){
          if(madeSelection(subject, "Please select a subject for your message")){
            if(isAlphanumeric(mhmake, "Please enter the vehicle make.")){
              if(isAlphanumeric(mhmodel, "Please enter the vehicle model.")){
                if(isAlphanumeric(varient, "Please enter the variant of your vehicle.")){
                  if(madeSelection(fuel, "Please select the fuel type of your vehicle")){
                    if(madeSelection(miles, "Please select the number of miles on your vehicle.")){
                      if(madeSelection(age, "Please select the year of your vehicles manufacture")){
                        if(checkboxSelection(verifymail, "Please tick the checkbox to confirm permission to contact you by email")){
						  if(isAlphabet(BuyerAlert, "Please enter the correct adcode in the add code box. Numbers only please")){
			
			            return true;
			              }
			            }
			          }
			       }
			     }
			   }
		     }
		   }
     	 }
       }
     }
   }
 }
 
  return false;

  }

  function isEmpty(elem, helperMsg){
  if(elem.value.length == 0){
    alert(helperMsg);
    elem.focus(); // set the focus to this input
    return true;
  }
  return false;
  }


  function isAlphabet(elem, helperMsg){
  var alphaExp = /^[0-9]+$/;
  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 madeSelection(elem, helperMsg){
  if(elem.selectedIndex == 0){
    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;
  }
  }

  function checkboxSelection(elem, helperMsg){
  if(elem.checked == 0){
    alert(helperMsg);
    elem.focus();
    return false;
  }else{
    return true;
  }
  }