// JavaScript Document

function validateForm(){

var invalidChars = " /:,;";		//invalid character in email addresses

//alert("Inside validate Form of test script.");

//verify name exists
if(document.frmFriendEmail.txtName.value == "")
{
	alert("Please enter your name in the Your Name field. Thank you.");
	document.frmFriendEmail.txtName.focus();
	document.frmFriendEmail.txtName.select();
	return false;
}

//make sure email was even entered
//check that email and verify email have been entered
if(document.frmFriendEmail.txtEmail.value == "")
	{
	 	alert("It appears you forgot to enter an email address");
		document.frmFriendEmail.txtEmail.focus();
		document.frmFriendEmail.txtEmail.select();
		return false;
	}

//make sure email and verify email are the same
if(document.frmFriendEmail.txtEmail.value != document.frmFriendEmail.txtVerifyEmail.value)
{
	alert("It appears your email and verify email do not match.\nPlease re-enter these values. Thank you.");
	document.frmFriendEmail.txtEmail.focus();
	document.frmFriendEmail.txtEmail.select();
	return false;
}

//two emails are same so continue
//check for invalid characters
for( i=0;i<invalidChars.length;i++)
	{
		
		badChar = invalidChars.charAt(i);	//supposed to return the char at position i in invalidChars
		//alert("Checking for bad chars at position " + i + " bad char is " + badChar + " in " + invalidChars);
		//alert("Length of invalidChars is " + invalidChars.length);
		if(document.frmFriendEmail.txtEmail.value.indexOf(badChar,0) > -1)
		{
			alert("It appears you have entered an invalid email address.\nPlease double check the address.");
			document.frmFriendEmail.txtEmail.focus();
			document.frmFriendEmail.txtEmail.select();
			return false;
		}
	}


//check for @ sign
atPos = document.frmFriendEmail.txtEmail.value.indexOf("@",1);
		if( atPos == -1)
		{
			alert("It appears you have entered an invalid email address.\nDid you forget the @ sign?\nPlease double check the address.");
			frmFriendEmail.txtEmail.focus();
			frmFriendEmail.txtEmail.select();
			return false;
		}

//
//check that only 1 @ SIGN
		if (document.frmFriendEmail.txtEmail.value.indexOf("@", atPos + 1) > -1){
			alert("It appears you entered an invalid email address.\nDid you enter multiple @ signs?\nPlease double check the address.");
			frmFriendEmail.txtEmail.focus();
			frmFriendEmail.txtEmail.select();
			return false;
		}

//check that period is after @ sign
		periodPos = document.frmFriendEmail.txtEmail.value.indexOf(".", atPos);
		if (periodPos == -1)
		{
			alert("It appears you entered an invalid email address.\nDid you forget a period?\nPlease double check the address.");
			frmFriendEmail.txtEmail.focus();
			frmFriendEmail.txtEmail.select();
			return false;
		}

//check that at least 2 char after period
		if(periodPos + 3 > document.frmFriendEmail.txtEmail.value.length)
		{
			alert("It appears you entered an invalid email address.\nDid you enter the proper address after the period?\nPlease double check the address.");
			frmFriendEmail.txtEmail.focus();
			frmFriendEmail.txtEmail.select();
			return false;
		}


}