/*****************************************************************
*                                                                *
*	validates00-network.js                                       *
*	For use with ProChoiceAmerica.org and affiliated websites    *
*                                                                *
*	written by Michael Rathmann                                  *
*	(c)2003 RathmannDesign.com. All rights reserved.             *
*                                                                *
*****************************************************************/

function validateForm(form) {

	alertStart = "In order to join, please ";

	if (!form.contactName01.value) {
		alert(alertStart + "enter your first name.");
		form.contactName01.focus(); return false;
	} if (!form.contactName03.value) {
		alert(alertStart + "enter your last name.");
		form.contactName03.focus(); return false;
	} if (!form.contactEmail.value) {
		alert(alertStart + "enter your e-mail address.");
		form.contactEmail.focus(); return false;
	} var str = form.contactEmail.value;
	if (!isEmail(str)) {
		alert("" + str + " is an invalid e-mail address! Please reenter.");
		form.contactEmail.focus(); form.contactEmail.select(); return false;
	} if (!form.contactAddress01.value) {
		alert(alertStart + "enter your mailing address.");
		form.contactAddress01.focus(); return false;
	} if (!form.contactCity.value) {
		alert(alertStart + "enter your city.");
		form.contactCity.focus(); return false;
	} if (!form.contactState.value) {
		alert(alertStart + "enter your state.");
		form.contactState.focus(); return false;
	} if (!form.contactZip.value) {
		alert(alertStart + "enter your zip code.");
		form.contactZip.focus(); return false;
	} if (!form.contactHome.value) {
		alert(alertStart + "enter your home phone number.");
		form.contactHome.focus(); return false;
	} var str = form.contactHome.value;
	if (!isPhoneNum(str)) {
		alert("" + str + " is invalid!\r\nPlease use this format: ###-###-####");
		form.contactHome.focus(); form.contactHome.select(); return false;
	} if (form.contactWork.value) {
		var str = form.contactWork.value;
		if (!isPhoneNum(str)) {
			alert("" + str + " is invalid!\r\nPlease use this format: ###-###-####");
			form.contactWork.focus(); form.contactWork.select(); return false;
		}
	}

	alert("THANK YOU!\nYour request to join the Choice Action Network will now be submitted.");
	return true; //change this to return false to disable
}

function isPhoneNum(str) {
	if (str.length != 12) { return false; }
	for (j=0; j<str.length; j++) {
		if (j == 3) { if (str.charAt(j) != "-") { return false; } }
		else if (j == 7) { if (str.charAt(j) != "-") { return false; } }
		else { if ((str.charAt(j) < "0") || (str.charAt(j) > "9")) { return false; } }
	} return true;
}