

function validate() {
	
  if(!document.getElementById) return;

  // get form variables
  var firstname = document.getElementById("firstname").value;
  var lastname = document.getElementById("lastname").value;
  var email = document.getElementById("email").value;
  var postal = document.getElementById("postal").value;
  var eveningphone = document.getElementById("eveningphone").value;
  var dayphone = document.getElementById("dayphone").value;
  var mobilephone = document.getElementById("mobilephone").value;

  var incorrect = new Array();
  var no = 0;
  var regExp = /[A-Za-z]{1,}/;
  
  //Get the domain that was used and add that to the passback url
  var url = window.location.href;
  n = url.indexOf("request")-1;
  url = url.substring(0,n);
  document.getElementById("passbackurl").value = url + "/request-a-quote-thanks.php?email="+email+"&";


 	if(regExp.test(firstname)) {
   	firstname = firstname;
  } else {
   	incorrect[no] = "1";
  	no++;
  } 	
  
 
	regExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if(regExp.test(email)) {
   	email = email;
  } else {
   	incorrect[no] = "3";
  	 no++;
  }

   postal = postal.toUpperCase();
  regExp = /[ABCEGHJKLMNPRSTVXY]\d[A-Z]\s?\d[A-Z]\d/;
  if(regExp.test(postal)) {
   	if(postal.indexOf(" ") < 0) {
    		postal = postal.substring(0,postal.length-3) + " " + postal.substring(postal.length-3,postal.length);
   	}
  } else {
    incorrect[no] = "4";
    no++;
    postal = "";
  }

regExp = /^([0-9\-])+$/;

  if(regExp.test(eveningphone)) {
  	  	eveningphone = eveningphone;
    }else{
		eveningphone = eveningphone.replace(/[^0-9\-]*/g,'');
		incorrect[no] = "5";
  	 	no++;
	}

 if(dayphone.length > 0) {
  if(regExp.test(dayphone)) {
  	  	dayphone = dayphone;
    }else{
		var dayphone = dayphone.replace(/[^0-9\-]*/g,'');
		incorrect[no] = "6";
  	 	no++;
	}
  }
  
  
   if(mobilephone.length > 0) {
  if(regExp.test(mobilephone)) {
  	  	mobilephone = mobilephone;
    }else{
		var mobilephone = mobilephone.replace(/[^0-9\-]*/g,'');
		incorrect[no] = "7";
  	 	no++;
	}
   }

  for(i=1;i<7;i++) {
  		document.getElementById(i).style.color="#000000";
  }

  for(j=0;j<no;j++) {
  		document.getElementById(incorrect[j]).style.color="#FF0000";
  }



  document.getElementById("firstname").value = firstname;
  document.getElementById("lastname").value = lastname;
  document.getElementById("email").value = email;
  document.getElementById("postal").value = postal;
  document.getElementById("eveningphone").value = eveningphone;
  document.getElementById("dayphone").value = dayphone;
  document.getElementById("mobilephone").value = mobilephone;
    if(no > 0) {
   	document.getElementById("errors").innerHTML = "<span class=\"error\">There was an error with your form submission. Please fill in the neccessary fields.</span><br />";
	return false;
  }else{
	  return true;
	  }
}





function Check() {
ToCheck = document.form.comments.value;
var ckw1 = ToCheck.replace(/<\S[^><]*>/g,"");
var ckw2 = ckw1.replace(/(<([^>]+)>)/ig,"");
Checked = ckw2;
document.form.comments.value = Checked;

}

function Checkall(){
	window.parent.scroll(0,0);
	Check();

	if( validate()){
		
		return true;
	}else{
		return false;
	}
}