/* load form submit detector */
window.onload = function () {
	document.getElementById("mailing_form").onsubmit = function () {
		return validateContact()
	}
}

/* validate Contact form */
function validateContact() {

	if ( document.getElementById("mailing_form").name.value == "" ) {
		document.getElementById("formError").innerHTML = "<p class=\"adminmessage\">Error: Please enter your name.</p>";
		document.getElementById("mailing_form").name.focus();
		return false;
	}
	
	if ( !valid_email(document.getElementById("mailing_form").email.value)) {
		document.getElementById("formError").innerHTML = "<p class=\"adminmessage\">Error: Please check your email address is correct.</p>";
		document.getElementById("mailing_form").email.focus();
		return false;
	}

}

function valid_email(email) {

// Description: Checks to see if the specified email address is valid.
// Parameters:
//    email: The address to test.

   at = email.indexOf("@");
   dot = email.lastIndexOf(".");

   if((at >= 3) && (dot > at))
      return(true);
   else
      return(false);
}