// JavaScript Document
<!--
// email form validation
function Form1_Validator(theForm)
{
	if (theForm.captcha.value != 4 ) {
		window.location = 'http://www.glenivy.org/joinlist_thanks_blank.php'
		return (false);
	}
	else {
		
	if (theForm.emailWork.value != "") {
		window.location = 'http://www.glenivy.org/joinlist_thanks_blank.php'
		return (false);
	}
	
	else {
	// require a name always
	if (theForm.name.value == "")
	{
		alert("You must enter your name.");
		theForm.name.focus();
		return (false);
	}
	// check to see that at least one of the lists have been selected
	if (!(theForm.add_to_email_list.checked) && !(theForm.add_to_postal_list.checked))
	{
		alert("Please check the box for at least one list, email or postal.");
		theForm.add_to_email_list.focus();
		return (false);
	}

	// check if signing up for email list
	if (theForm.add_to_email_list.checked)
	{
		// check if email field is blank
		if (theForm.email.value == "")
		{
			alert("Please enter a value for the \"Email\" field.");
			theForm.email.focus();
			return (false);
		}
		// test if valid email address, must have @ and .
		var checkEmail = "@.";
		var checkStr = theForm.email.value;
		var EmailValid = false;
		var EmailAt = false;
		var EmailPeriod = false;
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkEmail.length;  j++)
			{
				if (ch == checkEmail.charAt(j) && ch == "@")
					EmailAt = true;
				if (ch == checkEmail.charAt(j) && ch == ".")
					EmailPeriod = true;
				if (EmailAt && EmailPeriod)
					break;
				if (j == checkEmail.length)
					break;
			}
			// if both the @ and . were in the string
			if (EmailAt && EmailPeriod)
			{
					EmailValid = true
					break;
			}
		}
		if (!EmailValid)
		{
			alert("The \"email\" field must contain a valid email address.");
			theForm.email.focus();
			return (false);
		}
	}
	
	// check if signing up for the postal list
	if (theForm.add_to_postal_list.checked)
	{
		// check to see if the field is blank
		if (theForm.address.value == "")
		{
			alert("You must enter your address.");
			theForm.address.focus();
			return (false);
		}
		// check to see if the field is blank
		if (theForm.city.value == "")
		{
			alert("You must enter your city.");
			theForm.city.focus();
			return (false);
		}
		// check to see if the field is blank
		if (theForm.state.value == "")
		{
			alert("You must enter your state.");
			theForm.state.focus();
			return (false);
		}
		// check to see if the field is blank
		if (theForm.zip.value == "")
		{
			alert("You must enter your zip code.");
			theForm.zip.focus();
			return (false);
		}
	}
	// wish to exit the page
	return (true);
	// replace the above with return(true); if you have a valid form to submit to
}
	}
}
//-->
				

