// JavaScript Document

// Email check the address is valid and has been entered

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "Please enter a email address in the box.\n";
}

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


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "Please enter a home phone number in the box.\n";
} 

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The home phone number contains illegal characters.";
  
    }
    if (!(stripped.length == 11)) {
	error = "The home phone number is the wrong length. Make sure you included an area code with no gaps.\n";
    } 
return error;
}


// non-empty surname textbox

function isSurname(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter your surname in the box.\n"
  }
return error;	  
}

// non-empty forename textbox

function isForename(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter your forename in the box.\n"
  }
return error;	  
}


// non-empty comment textbox

function isComment(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter a comment in the box.\n"
  }
return error;	  
}

// non-empty address textbox

function isAddress(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter your address in the box.\n"
  }
return error;	  
}

// non-empty postcode textbox

function isPostcode(strng) {
var error = "";
  if (strng.length == 0) {
     error = "The postcode area has not been filled in.\n"
  }
return error;	  
}



function checkWholeForm(theForm){
	var why="";
	why+=isForename(document.theForm.forename.value);	
	why+=isSurname(document.theForm.surname.value);
	why+=isAddress(document.theForm.address.value);
	why+=isPostcode(document.theForm.postcode.value);
	why+=checkPhone(document.theForm.phone.value);
	why+=checkEmail(document.theForm.email.value);
	why+=isComment(document.theForm.comment.value);
	
if(why!=""){
alert(why);
return false;
}
return true;
}