

//***************** EMAIL VALIDATION **************************
//
// THIS FUNCTION TAKES IN 1 ARGUMENT:
//    1. email address 
// THIS FUNCTION RETURNS:
//                     0  no errors - email address is in valid format
//                     -1  (error- email is null)
//                     -2  (error- incorect length. min length=7: "x@y.com" )
//                     -3  (error-  invalid format  )
//
//***********************************************************
function ValidateEmail(email)
{
error=0
if (email == "")
    return(-1);
else
	{
		var	lnth = email.length;
		if (lnth<7)
		{
			return(-2);		
		}
		else
		{
			if ((email.charAt(0) == '@')||(email.charAt(lnth-1) == '@'))
			{
				return(-3)		//Character '@' can not be in first or last position in Email address;
			}
			j = 0
			for(i=1; i<(lnth-1); i++)
			{
				if  (email.charAt(i) == '@') 
					j= j + 1;
			}
			if (j == 0)
				{
					return(-3)		//Email address must contain '@' character
				}
			if (j > 1)
				{
					return(-3)		//Email address cannot contain more than one '@' character
				}
		}
		j = 0
			for(i=1; i<(lnth-1); i++)
			{
				
				if  (email.charAt(i) == '.') 
					{
						j= j + 1;
					}
			}
			if (j == 0)
				{
					return(-3)		//Email address must contain '.' character
				}
	}
return (0);
}

	function verify() {
		var themessage = "Please fill in the following fields: ";
		if (document.contactform.firstname.value=="") {
		themessage = themessage + "First Name, ";
		}
		if (document.contactform.lastname.value=="") {
		themessage = themessage + "Last Name, ";
				}
		
		if (document.contactform.phone_area.value=="") {
		themessage = themessage + "Phone Area Code, ";
		}
		if (document.contactform.phone_2.value=="") {
		themessage = themessage + "Phone - First 3 Digits, ";
		}
		if (document.contactform.phone_3.value=="") {
		themessage = themessage + "Phone - Last 4 Digits, ";
		}
		if (document.contactform.emailaddress.value=="") {
		themessage = themessage + "Email Address, ";
		}
	
		
		///// check for valid email format
		var iEmail = ValidateEmail(document.forms[0].emailaddress.value)
		if (iEmail<-1)
		{
			alert ("Please enter a valid Email Address.");
			document.forms[0].emailaddress.focus();
			return false;
		}
						
		//alert if fields are empty and cancel form submit
		if (themessage == "Please fill in the following fields: ") {
		return true;
		}		
		else { 
		alert(themessage);
		return false; 
	  	}	  	
	}
 

