/*-----------------------------------------------------------------------------
File:			formVal.js
Author:			Neal Krouse
Copyright:		Copyright (c) 2006 Neal Krouse
				All Rights Reserved.
Created:		1/11/06

Notes:			

Change History:
1/11/06			Started source.
-----------------------------------------------------------------------------*/

/*
	=======================================================
	validateForm() looks at Salmon Run's form and checks
	its elements before send it to the PHP file on 
	the server.
	=======================================================
*/

// RegEx for phone numbers and emails
reTel= /^\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/]?(\d{4})$/;
re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

function validateForm(thisForm) {
	
	// Go down the form elements one by one
	// and check if the values are there
	// and if there formatted correctly.
	
	if (thisForm.firstName.value == "") {
		thisForm.firstName.focus();
		thisForm.firstName.select();
		self.alert("Please, add your First Name.");
		return false;
	}
	
	if (thisForm.lastName.value == "") {
		thisForm.lastName.focus();
		thisForm.lastName.select();
		self.alert("Please, add your Last Name.");
		return false;
	}
	
	// test for valid phone number
	//var validPhone = reTel.exec(thisForm.tel.value);
	if (!reTel.test(thisForm.tel.value)) {
		// number is okay
		self.alert("Please, add your phone number in this format: (000) 000-0000.");
		thisForm.tel.focus();
		thisForm.tel.select();
		return false;
	}
	
	// test email
	if (!re.test(thisForm.email.value)) {
		self.alert("Please add a valid email address.");
		thisForm.email.focus();
		thisForm.email.select();
		return false;
	}
	
}