/*
* contact_form.js
* by Ron Newsome, Jr.
* 1/28/2008
*
* Try to save the user some typing by
* validating the form before it hits the server
*/

function validate() {
  $sender = document.contactform.sender;
  $email = document.contactform.email;
  $msg = document.contactform.message;
  $phone = document.contactform.phone;
  $errors = [];
	if (!/^[^@\s]+@([\-a-z0-9]+\.)+[a-z]{2,}$/i.test($email.value)) {
	  $errors.push('Please enter a valid email address.');
	}
	if ($sender.value=="") {
	  $errors.push('Please enter your name.');
	}
	if ($msg.value=="") {
	  $errors.push('You did not type a message!');
	}
	if ( !/^\d{7,10}$/.test($phone.value.replace(/[\-\)\(\s\.]*/g, "")) ) {
	  $errors.push('Please enter a valid 7 or 10 digit phone number.');
	}
	if($errors.length) {
	  alert( $errors.join("\n") );
	  return false;
	}
}

function addValidation() {
  document.contactform.onsubmit = validate;
}

window.onload = addValidation;