/*Function contact_email()
 * No Paramaters expected
 * Function: Validate the form on the contact us page
 * Author: 	 Joseph Zanotelli
 * Created:  10/16/2005

-Revisions-
10/16/2005 - Created
*/
 
function contact_email() {
	//Define form fields into local variables
	var from	 	= document.emailform.from.value;
	var message 	= document.emailform.message.value;
	var name		= document.emailform.name.value;
	
	//Verify that the name is filled in
	if (name ==""){
		alert("Name is a required field");
		document.emailform.name.focus();
		return false;
	}
	
	//Verify that the from address is filled in and valid
	if (from == "" || isValidEmail(from) == false){
		alert("A valid E-Mail Address must be in the From: field");
		document.emailform.from.focus();
		return false;
	}
	
	//Verify that the message box contains text
	if (message ==""){
		alert("The message box can not be empty");
		document.emailform.message.focus();
		return false;
	}

}

/*Function isValidEmail()
 * 1 Paramaters expected (Email address - String)
 * Function: Validates that the string conformes to a email address
 * Author: 	 Joseph Zanotelli
 * Created:  10/16/2005

-Revisions-
10/16/2005 - Created
*/
function isValidEmail(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){return false}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false}
		if (str.indexOf(at,(lat+1))!=-1){return false}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false}
		if (str.indexOf(dot,(lat+2))==-1){return false}
		if (str.indexOf(" ")!=-1){return false}
 		return true					
	}