
////////////////////////////////////////////////////////////////////////////////
//	NAME: jsFunctions.js
//	DESCRIPTION:
//	AUTHOR: Scott LePage
//	DATE: 6/14/2001
//	NOTES:
//	REVISION HISTORY:
//	Paul Vilents 12/08/2001  - Email Validation script added
////////////////////////////////////////////////////////////////////////////////

function submitMailForm() {
	if (checkMailForm()) document.emailForm.submit();
}

function checkMailForm()
{
	if( badEmailField(document.emailForm.email) )
		{
		alert("Please enter your email address correctly.");
		document.emailForm.email.focus();
		return false;
		}
		
	if(document.emailForm.comments.value == "")
		{
		alert("Please enter your comments.");
		document.emailForm.comments.focus();
		return false;
		}
				
	return true;
}

function badEmailField(textObj)
{
	var thisChar;
	var atCount = 0;
	var dotCount = 0;
	
	// www. check
	thisChar = textObj.value.substring(0, 4);
	if (thisChar == "WWW.")	return true;	
	if (thisChar == "www.")	return true;
	
	
	for (var i=0; i < textObj.value.length; i++) 
		{
			thisChar = textObj.value.substring(i, i+1);
			
			if ( thisChar == "." ) 
				{
				if ( (i == textObj.value.length - 1) || (i == 0) ) return true;
				else 
					{
					dotCount++;
					}
				}	
				
			if ( thisChar == "@" ) 
				{
				if ( (i == textObj.value.length - 1) || (i == 0) ) return true;
				else
					{
					atCount++;
					}
				}
					
			if ( thisChar == " " ) return true;
			if ( atCount > 1 ) return true;
		}
		
	if ( atCount == 0 ) return true;		

	return ( dotCount == 0 ) ? true : false;			
}


