// Form Validator Script - 10/1/04
// Chris Gonzales <chris@irisfx.net>


function checkIt() {

	var errmsg = ""; // hold error messages.

	if (document.filer.strname.value == "")
		{ errmsg += "\n      Please enter your Name." }
	
	if (validEmail(document.filer.strfrom.value) == false)
		{ errmsg += "\n      Please enter a valid Email address." }	

	if (document.filer.strcomment.value == "")
		{ errmsg += "\n      Please enter a Comment." }
	
	if (errmsg == "")
		{ return true; }
	else
		{ 
		  alert("Please provide the following infomation:" + errmsg);
		  return false;
		}
}


function validEmail(email) {
	
	if (email == "") // check to see if blank
		{ return false; }

	var invalidChars = " /:,;" // check for invalid characters
	for (i=0; i < invalidChars.length; i++)
	{
		var badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1)
			{ return false; }
	}
	
	var atPos = email.indexOf("@",1) // check for the "@" sign
	if (atPos == -1)
		{ return false; }

	if (email.indexOf("@",atPos+1) > -1) // make sure only 1 "@" sign
		{ return false; }
	
	var periodPos = email.indexOf(".",atPos) // make sure there is a "." after the "@"
	if (periodPos == -1)
		{ return false; }
	
	if (periodPos-1 == atPos) // make sure "." is not right after the "@"
		{ return false; }		
	
	if (email.indexOf("..",1) > -1) // make sure there is not ".."
		{ return false; }		

	if (email.lastIndexOf(".") == (email.length-1)) // make sure "." is not the last character
		{ return false; }		

	var ext = email.length-(email.lastIndexOf(".")+1) // check for >1 or <5 char extension after last "." 
	if ((2 > ext) || (ext > 4 )) 
		{ return false; }

	var invalidChars = "0123456789" // check for numbers after last "."
	for (i=0; i < invalidChars.length; i++)
	{
		var badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,email.lastIndexOf(".")) > -1)
			{ return false; }
	}
	
	return true; // PASSED ALL OF 10 CHECKS TO SEE IF EMAIL IS VALID
}