// JavaScript Document
// check for blank fields
function isblank(s)
{
for (var i = 0; i < s.length; i++)	{
	var c = s.charAt(i);
	if ((c != ' ') && (c != '\n') && (c != '\t'))
		return false;
	}
	return true;
}

//verification
function verify(f)
{
	var msg;
	var empty_fields = "";
	var errors = "";
	for (var i = 0; i < f.length; i++)	{
		var e = f.elements[i];
		if (((e.type == "text") || (e.type == "textarea")) && !e.optional)	{
			//is field empty?
			if ((e.value == null) || (e.value == "") || isblank(e.value))	{
				empty_fields += "\n\t\t* " + e.name;
				continue;
			}
			//verify numerical input
			if (e.numeric || (e.min != null) || (e.max != null))	{
				var v = parseFloat(e.value);
				if (isNaN(v) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max)))	{
					errors += " - The field " + e.name + " must be a valid number.";
			}
		}
			//verify email address format
			var pattern = /.+@.+\..+/;
			if (e.name == "email")
			{
				if (!pattern.test(e.value))
					errors += "Please enter a valid email address.\n ";
			}
	}
	
}
if  (!empty_fields && !errors)	return true;
msg = "_______________________________________________________________\n\n";
msg += "    The form was not submitted because of the following error(s).\n";
msg += "    Please correct the form and re-submit it.\n";
msg += "_______________________________________________________________\n\n";

if (empty_fields)	{
	msg += "    The following required field(s) are empty:" + empty_fields + "\n";
	if (errors)	msg += "\n";
	}
	msg += errors;
	alert(msg);
	return false;
}

function verifysyslang(f)
{
	var pattern = /.+@.+\..+/;
	if (pattern.test(document.contactinfo.email.value) && ((!document.contactinfo.name.value == null) ||  (!contactinfo.name.value == "") || !isblank(contactinfo.name)))
		return true;
	else
	{	
		alert("Please enter your name and email address!");
		return false;
	}
}

function verifymethod(f)
{
	var radio_choice = false;
	var pattern = /.+@.+\..+/;
	var zipcode = /^\d{5}([\-]\d{4})?$/;
	//	make sure 'Other' box is filled in
	if (document.contactinfo.Info10){
	if (document.contactinfo.Info9.checked)
	{
		if ((!document.contactinfo.Info10.value == null) ||  (!document.contactinfo.Info10.value == "") || !isblank(document.contactinfo.Info10))
			return true;	
		else	{
			alert("Please specify the other way you can help!");
			return false;	}
	}}
	if (document.contactinfo.MethodofNotice[0].checked)
	{
		if (pattern.test(document.contactinfo.email.value))
			return true;
		else
			alert("You have requested notification by e-mail!\n\nPlease enter your email address!");
	return false;
	}
	if (document.contactinfo.MethodofNotice[1].checked)
	{
					if (((!document.contactinfo.name.value == null) ||  (!document.contactinfo.name.value == "") || !isblank(document.contactinfo.name)) 
					&& ((!document.contactinfo.StreetAddress.value == null) ||  (!document.contactinfo.StreetAddress.value == "") || !isblank(document.contactinfo.StreetAddress)) 
					&& ((!document.contactinfo.town.value == null) ||  (!document.contactinfo.town.value == "") || !isblank(document.contactinfo.town)) 
					&& ((!document.contactinfo.zip.value == null) ||  (!document.contactinfo.zip.value == "") || !isblank(document.contactinfo.zip))
					&& (document.contactinfo.State.selectedIndex >= 1))
						return true;
					else
						alert("You have requested notification by US mail!\n\nPlease enter your name and complete address!");
					return false;
	}
	if (document.contactinfo.MethodofNotice[2].checked)
	{
		if ((!document.contactinfo.telephone.value == null) || (!document.contactinfo.telephone.value == "") || !isblank(document.contactinfo.telephone))
			return true;
		else
			alert("You have requested notification by telephone!\n\nPlease enter your phone number including area code!");
	return false;
	}
	if (!radio_choice)
	{
	// If there were no selections made display an alert box 
		alert("No button has been selected!\n\nPlease select a method of contact!");
	return false;
	}
	return true;
}

/*function verifysyslang(f)
{
	var pattern = /.+@.+\..+/;
	if (pattern.test(document.contactinfo.email.value) && ((!document.contactinfo.name.value == null) ||  (!contactinfo.name.value == "") || !isblank(contactinfo.name)))
		return true;
	else
	{	
		alert("Please enter your name and email address!");
		return false;
	}
}*/


/*function emailchoice(f)
{
	var radio_choice = false;
	var format;
	var pattern = /.+@.+\..+/;
	if (pattern.test(document.contactinfo.email.value) && ((!document.contactinfo.name.value == null) ||  (!contactinfo.name.value == "") || !isblank(contactinfo.name)))
		format="";
	else
	{	
		alert("Please enter your name and email address!");
		return false;
	}
	if (document.contactinfo.radiobutton[0].checked)
		{
		format = "";
		return true;
		}
	if (document.contactinfo.radiobutton[1].checked)
		{
		format = "digest";
		return true;
		}
	if (document.contactinfo.radiobutton[2].checked)
		{
		format = "announcement only";
		return true;
		}
	if (!radio_choice)
	{
	// If there were no selections made display an alert box 
	alert("Please choose which type of list you want to subscribe to!\n\nSelect \"Individual messages\" to receive messages as they are posted,\nSelect \"Daily digest\" to receive one message per day containing the that day\'s postings,\nSelect \"Announcements only\" to receive only selected postings.")
	return false;
	}
return true;
}*/