	/********************************************************************************************
	Filename:		scripts.js
	Created by:		Allison Corbett ~ www.willowtree.net
	Modifications: 	1/11/05--finalized and posted. 
	Description: 	This page contains all of the javascript for the main end user site--primarily
					form vaidation scripts for the mailing list and volunteer application forms. 
					This file is referenced as an external script file by those pages.        
	*********************************************************************************************/

// This script ensures that the user has entered a valid email address in the format
// someone@somewhere.com (or .org. .net, etc)
function validEmail (email1) {
	invalidChars = " /:,;"
	if (email1 == "") {
		return false
	}
	
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email1.indexOf(badChar,0) != -1) {
			return false
		}
	}
	
	atPos = email1.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	
	if(email1.indexOf("@",atPos+1) != -1) {
		return false
	}
	
	periodPos = email1.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	
	if (periodPos+3 > email1.length) {
		return false
	}
return true
}

function checkAge(form) {
	// Loop through all age-related radio buttons on the page
	for (i=0; i<form.over18.length; i++) {
		if (form.over18[i].checked==true) {
			return true;				
		}
	}
	return false;
}

// Scripts for the Join Mailing List page. 
function submitMailList(form) {
	if (form.fname.value=="") {
		alert("Please enter your first name.");
		form.fname.focus();
		form.fname.select();
		return false;
	}
	if (form.lname.value=="") {
		alert("Please enter your last name.");
		form.lname.focus();
		form.lname.select();
		return false;
	}
	if (form.address1.value=="") {
		alert("Please enter your street address.");
		form.address1.focus();
		form.address1.select();
		return false;
	}
	if (form.city.value=="") {
		alert("Please enter your city.");
		form.city.focus();
		form.city.select();
		return false;
	}
	if (form.state.value=="") {
		alert("Please enter your state.");
		form.state.focus();
		form.state.select();
		return false;
	}
	if (form.zip.value=="") {
		alert("Please enter your zip code.");
		form.zip.focus();
		form.zip.select();
		return false;
	}
	if (!validEmail(form.email.value)) {
		alert("Please enter a valid email address.")
		form.email.focus()
		form.email.select()
		return false
	}
	
return true;
}

// Scripts for the Volunteer Application. 
function submitVolunteer(form) {
	if (form.app_position.value=="") {
		alert("Please enter the position for which you are applying.");
		form.app_position.focus();
		form.app_position.select();
		return false;
	}
	if (form.fname.value=="") {
		alert("Please enter your first name.");
		form.fname.focus();
		form.fname.select();
		return false;
	}
	if (form.lname.value=="") {
		alert("Please enter your last name.");
		form.lname.focus();
		form.lname.select();
		return false;
	}
	if (form.address1.value=="") {
		alert("Please enter your street address.");
		form.address1.focus();
		form.address1.select();
		return false;
	}
	if (form.city.value=="") {
		alert("Please enter your city.");
		form.city.focus();
		form.city.select();
		return false;
	}
	if (form.state.value=="") {
		alert("Please enter your state.");
		form.state.focus();
		form.state.select();
		return false;
	}
	if (form.zip.value=="") {
		alert("Please enter your zip code.");
		form.zip.focus();
		form.zip.select();
		return false;
	}
	if (form.homephone.value=="") {
		alert("Please enter your home phone number.");
		form.homephone.focus();
		form.homephone.select();
		return false;
	}
	if (!validEmail(form.email.value)) {
		alert("Please enter a valid email address.")
		form.email.focus()
		form.email.select()
		return false
	}
	if (form.time_at_address.value=="") {
		alert("Please enter the length of time you've lived at your current address.");
		form.time_at_address.focus();
		form.time_at_address.select();
		return false;
	}
	if (!checkAge(document.volunteer_app)) {
		alert("Please specify whether or not you are over 18.");
		form.over18[1].focus();
		return false;
	}	
return true;
}