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

function validateForm(form) {
	alertStart = "To submit this form, please ";

	if (!volPref(form)) {
		alert(alertStart + "indicate your Volunteer Preference(s).");
		form.volPref01.focus(); return false;
	}

	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;
	} if (!isEmail(form.contactEmail.value)) {
		alert("'" + form.contactEmail.value + "' 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 #.");
		form.contactHome.focus(); return false;
	} var str = form.contactHome.value;
	if (!isPhoneNum(form.contactHome.value)) {
		alert("'" + form.contactHome.value + "' is invalid!\r\nPlease use this format: ###-###-####\r\n\r\nIf you have an extension, please enter it in the associated field.");
		form.contactHome.focus(); form.contactHome.select(); return false;
	} if (form.contactMethod[3].checked && !form.contactWork.value) {
		alert(alertStart + "enter your WORK PHONE #.");
		form.contactWork.focus(); return false;
	} if (form.contactWork.value && !isPhoneNum(form.contactWork.value)) {
		alert("'" + form.contactWork.value + "' is invalid!\r\nPlease use this format: ###-###-####\r\n\r\nIf you have an extension, please enter it in the associated field.");
		form.contactWork.focus(); form.contactWork.select(); return false;
	} if (!contactChecked(form)) {
		alert(alertStart + "indicate your CONTACT PREFERENCE.");
		form.contactMethod[0].focus(); return false;
	} if (!studentChecked(form)) {
		alert(alertStart + "answer the question 'ARE YOU A STUDENT?'");
		form.studentStatus[0].focus(); return false;
	} if (form.studentStatus[0].checked && !form.studentSchool.value) {
		alert(alertStart + "enter name of SCHOOL ATTENDING.");
		form.studentSchool.focus(); return false;
	}

	input_box=confirm('Press \'OK\' to submit');
	if (input_box) { return true; } else { return false; }
}

function volPref(form) {
	if ((form.volPref01.checked) || (form.volPref02.checked) || (form.volPref03.checked) || (form.volPref04.checked) || (form.volPref05.checked)) {
		return true;
	} else { return false; }
}

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;
}

function contactChecked(form) {
	for (i=0; i<form.contactMethod.length; i++) {
		if (form.contactMethod[i].checked) { return true; }
	} return false;
}

function studentChecked(form) {
	for (i=0; i<form.studentStatus.length; i++) {
		if (form.studentStatus[i].checked) { return true; }
	} return false;
}
