// JavaScript Document
function error() {
 var fault = "";
 fault += checkfName(document.querey.fname.value);
  fault += checklName(document.querey.lname.value);
 fault += checkCompany(document.querey.company.value);
 fault += checkEmail(document.querey.email.value);
 fault += checkTel(document.querey.tel.value);
if(document.querey.email.value != document.querey.cEmail.value){
		fault += checkComEmail();
	}
 if (fault != "") {
	alert(fault);
	return false;
 }
 return true;
}


function checkfName (strng) {
 var error = "";
 var illegalChars = /[\W\d(\)\<\>\,\;\:\\\/\"\[\]_]/;
  //allow only letters
    if (illegalChars.test(strng)) {
       error = "Your first name contains illegal characters.\n";
    } 
 if (strng == "") {
   error = "You didn't enter a first name.\n";
}
return error;
}
function checklName (strng) {
 var error = "";
 var illegalChars = /[\W\d(\)\<\>\,\;\:\\\/\"\[\]_]/;
  //allow only letters
    if (illegalChars.test(strng)) {
       error = "Your last name contains illegal characters.\n";
    } 
 if (strng == "") {
   error = "You didn't enter a last name.\n";
}
return error;
}

function checkCompany (strng) {
 var error = "";
 if (strng == "") {
   error = "You didn't enter a company name.\n";
}
return error;
}

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

function checkTel (strng) {
	var error ="";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters

if (!(stripped.length == 11)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
}
if (isNaN(parseInt(stripped))) {
   error = "The phone number contains illegal characters.";
}
 if (strng == "") {
   error = "You didn't enter a telephone Number.\n";
}
return error;
}


function checkComEmail () {
var error = "";

	error = "Emails not the same please re-enter.\n";

return error;
}
