// JavaScript Document

function validateEmail(email) {

	invalidChars = " /:,;";
	if (email == "") 
		return false

	for (i=0; i<invalidChars.length; i++) 
	{
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) != -1) 
			return false
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) 
		return false

	if (email.indexOf("@",atPos+1) != -1)
		return false

	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1)
		return false
	if (periodPos+3 > email.length) 
		return false

	return true
}

function validateForm()
{
	var sEmail;
	var bValid;
	bValid = true;
	if (document.volunteer_app.Name.value == "")
	{
		alert("Please fill in the Name section.");
		bValid = false;	
	}
	if (document.volunteer_app.Address1.value == "")
	{
		alert("Please fill in the Street Address section.");
		bValid = false;
	}
	if (document.volunteer_app.City.value == "")
	{
		alert("Please fill in the City section.");
		bValid = false;
	}
	if (document.volunteer_app.ZipCode.value == "")
	{
		alert("Please fill in the Zip Code section.");
		bValid = false;
	}						
	if ((document.volunteer_app.HomePhone.value == "") && (document.volunteer_app.CellPhone.value == ""))
	{
		alert("Please fill in a phone number.");
		bValid = false;
	}						
	if (document.volunteer_app.Email.value == "")
	{
		alert("Please fill in the Email Address section.");
		bValid = false;
	}
	if ((!(document.volunteer_app.ReasonApplying[0].checked)) && (!(document.volunteer_app.ReasonApplying[1].checked)) && (!(document.volunteer_app.ReasonApplying[2].checked)))
	{
		alert("Please specify if a Reason for Applying.");
		bValid = false;
	}
	
	if(bValid)
	{
		sEmail = document.volunteer_app.Email.value;							
		if(!validateEmail(sEmail))
		{
			alert("Please supply a valid email address.");
			bValid = false;
		}	
	}
	return bValid;
}


