/* Email validation routines */
/* Copyright (c) Crazy Dog Design [www.crazydogdesign.com] */

/* Validate an Email address */
function validateEmail(email)
{

/* These characters don't belong in a valid email address */
invalidChars = " /:,;";

/* You must enter something */
	if (email == "")
	{
		window.alert("You must enter your email!");
		return false;
	}
	
/* There must be something BEFORE the at sign */	
	if (email.indexOf("@", 0) == 0)
	{
		window.alert("No username in email address!");
		return false;
	}
	
/* There must be an at sign at, or after, the second character */
	if (email.indexOf("@", 1) == -1)
	{
		window.alert("No @ sign in email address!");
		return false;
	}
	
/* There must be a period somewhere */
	if (email.indexOf(".", 0) == -1)
	{
		window.alert("No period in email address!");
		return false;
	}
		
/* There must be something after the period */
	if (email.charAt(email.length -1) == ".")
	{
		window.alert("There must be a domain after the period!");
		return false;
	}		
		
/* There must be something after the at sign */
	if (email.charAt(email.length -1) == "@")
	{
		window.alert("There must be a domain after the @ sign!");
		return false;
	}			
			
/* Check for invalid characters */
	for (i=0; i<invalidChars.length; i++)
	{
		if (email.indexOf(invalidChars.charAt(i), 0) > -1)
		{
			window.alert("Bad character(s) in email address!" + invalidChars.charAt(i), i);
			return false;
		}
	} 

				
/* We made it! The email looks good! */
	return true;
}

/* Verify a form */
function formVerify(myform)
{

/* Check that the user entered a name */
	if (myform.visitorName.value == "")
	{
		window.alert("You must enter your name");
		myform.visitorName.focus();
		myform.visitorName.select();
		return false;
	}
	
/* Check that the user entered a comment */
	if (myform.comments.value == "")
	{
		window.alert("You need to add a comment");
		myform.comments.focus();
		myform.comments.select();
		return false;
	}
	
	
/* Check that email == confirmEmail */
	if(myform.email.value != myform.confirmEmail.value)
	{
		window.alert("Your email doesn't match the confirm email");
		myform.email.focus();
		myform.email.select();
		return false;
	}
	
	
/* Go validate the email address */
	else if(!validateEmail(myform.email.value))
	{
		myform.email.focus();
		myform.email.select();
		return false;
	}
	
	else
		return true;
}

function setFieldFocus(emailForm)
{

emailForm.visitorName.focus();

}