<!--

function trim(s)
{
    return s.replace(/^\s+|\s+$/, '');
} 

function validateFormOnSubmit(form) {

 	var reason = "";

  	reason += validateEmail(form.email_address);
  	reason += validateName(form.name);
	reason += validateAuth(form.local_authority);
  	reason += validateTitle(form.job_title);
      
  	if (reason != "") {
    		alert("You have entered invalid information:\n\n" + reason);
    		return false;
  	}

  return true;
}

function validateName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFF66'; 
        error = "You have not entered a name.\n"
    } else {
        fld.style.background = '#b9e382';
    }
    return error;  
}

function validateAuth(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFF66'; 
        error = "You have not entered a local authority.\n"
    } else {
        fld.style.background = '#b9e382';
    }
    return error;  
}

function validateTitle(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFF66'; 
        error = "You have not entered a job title.\n"
    } else {
        fld.style.background = '#b9e382';
    }
    return error;  
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#FFFF66';
        error = "You have not entered an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FFFF66';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FFFF66';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = '#b9e382';
    }
    return error;
}


//-->
