/* load form submit detector */
window.onload = function () {
	document.getElementById("form_contact").onsubmit = function () {
		return validateContact();
	}
}


/* validate contact form */
function validateContact() {

	/* Validate personal details */
	if (document.getElementById("form_contact").name.value == "") {
		document.getElementById("contact_error").innerHTML = "Please select your name.";
		document.getElementById("form_contact").name.focus();
		document.getElementById("form_contact").name.style.border = "1px solid #00A7EB";
		return false;
	}
	document.getElementById("form_contact").name.style.border = "1px solid #090";
	
	if (document.getElementById("form_contact").email.value == "") {
		document.getElementById("contact_error").innerHTML = "Please enter your email address.";
		document.getElementById("form_contact").email.focus();
		document.getElementById("form_contact").email.style.border = "1px solid #00A7EB";
		return false;
	}
	document.getElementById("form_contact").email.style.border = "1px solid #090";
	
	if (!valid_email(document.getElementById("form_contact").email.value)) {
		document.getElementById("contact_error").innerHTML = "Please enter a valid email address.";
		document.getElementById("form_contact").email.focus();
		document.getElementById("form_contact").email.style.border = "1px solid #00A7EB";
		return false;
	}
	document.getElementById("form_contact").email.style.border = "1px solid #090";
	
	/*if (document.getElementById("form_contact").problem.value == '') {
		document.getElementById("contact_error").innerHTML = "Please select a problem.";
		document.getElementById("form_contact").problem.focus();
		document.getElementById("form_contact").problem.style.border = "1px solid #00A7EB";
		return false;
	}
	document.getElementById("form_contact").problem.style.border = "1px solid #090";*/
	
	if (document.getElementById("form_contact").question.value == '') {
		document.getElementById("contact_error").innerHTML = "Please enter your question.";
		document.getElementById("form_contact").question.focus();
		document.getElementById("form_contact").question.style.border = "1px solid #00A7EB";
		return false;
	}
	document.getElementById("form_contact").question.style.border = "1px solid #090";
	
	document.getElementById("contact_error").innerHTML = "";
}

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);
}