//document.writeln("In js external code - begin");
//*****************************************************************************
//
//    File: volleyball.js
//    Date: 10 November 2005
// Purpose: Javascript file for VBInfoRequestForm.html
//                              VBApplicationForm.asp (vbApplicationFormID)
//                              GetPassword.html (pwdFormID)
//  Author: John Knetzger
//
// Date      Who Comments
// ========= === ==============================================================
// 10Nov2005 JJK Copied from insurance.js
// 24Mar2007 JJK Expanded to support Volleyball Application System.
//*****************************************************************************

//###
//### Form: VBInfoRequestForm.html
//###
function insFormID_onreset() {
	if (confirm('Current data entered in this form will be cleared before creating a new request!  Are you sure?') == false)
		event.returnValue = false;
	document.forms.insFormID.insFirstNameID.focus();
}

function insFormID_onsubmit() {
	// To cancel a submission, return false or set event.returnValue = false;

	//###
	// ATHLETE/VOLUNTEER CONTACT INFO
	//###

	// VALIDATE first name
	OK = field_mustfill(insFormID.insFirstNameID, "Please enter your first name here.");
	if (!OK)
		return false;

	// VALIDATE middle initial
	OK = field_mustfill(insFormID.insMInitNameID, "Please enter your middle initial here.");
	if (!OK)
		return false;
	
	// VALIDATE last name
	OK = field_mustfill(insFormID.insLastNameID, "Please enter your last name here.");
	if (!OK)
		return false;

	// VALIDATE month of birth
	OK = field_mustfill(insFormID.insBirthMonthID, "Please enter month (01-12) of your birth here.");
	if (!OK)
		return false;

	// VALIDATE month, if entered
	OK = digit_validate(insFormID.insBirthMonthID, 2, false);
	if (!OK) {
		return false;
	}
	else {
		// VALIDATE day of birth
		OK = field_mustfill(insFormID.insBirthDayID, "Please enter day (01-31) of your birth here.");
		if (!OK)
			return false;

		// VALIDATE day, if entered
		OK = digit_validate(insFormID.insBirthDayID, 2, false);
		if (!OK) {
			return false;
		}
		else {
			// VALIDATE year of birth
			OK = field_mustfill(insFormID.insBirthYearID, "Please enter last 2 digits of year of your birth here.");
			if (!OK)
				return false;

			// VALIDATE year, if entered
			OK = digit_validate(insFormID.insBirthYearID, 2, false);
			if (!OK)
				return false;
		}
	}

	// VALIDATE name of parent/legal guardian
	if (insFormID.insBirthYearID > 88)
	{
		OK = field_mustfill(insFormID.insParentNameID, "Please enter the name of your parent(s) or legal guardian(s) here.");
		if (!OK)
			return false;
	}

	// VALIDATE phone number, if entered
	OK = phone_validate(insFormID.insPhoneAID,
	                    insFormID.insPhone3ID,
	                    insFormID.insPhone4ID);
	if (!OK)
		return false;

	// VALIDATE fax number, if entered
	OK = phone_validate(insFormID.insFaxAID,
	                    insFormID.insFax3ID,
	                    insFormID.insFax4ID);
	if (!OK)
		return false;

	// VALIDATE email
	OK = field_mustfill(insFormID.insEmailID, "Please enter your email address here.  " +
		"A copy of everything you enter on this form will be mailed to this email address.\r\n" +
		"WARNING: This form does NOT validate email addresses, so type the email address and check it for accuracy!");
	if (!OK)
		return false;
	
	// VALIDATE street
	OK = field_mustfill(insFormID.insStreetID, "Please enter the street address here.");
	if (!OK)
		return false;

	// VALIDATE postal address
	OK = address_validate(insFormID.insStreetID,
	                      insFormID.insCityID,
	                      insFormID.insStateID,
	                      insFormID.insZipID,
	                      insFormID.insZip4ID);
	if (!OK)
		return false;

	// VALIDATE at least one selection of interest
	CHOK = false;
	if (insFormID.insChk1ID.checked ||
		insFormID.insChk2ID.checked ||
		insFormID.insChk3ID.checked)
		CHOK = true;
	if (!CHOK) {
		alert('Please check the type of activity or activities you are interested in.');
		return false;
	}

/*
	if (event.returnValue != false) {
		// Information automatically sent to server
		alert("Your request has been e-mailed to the USADSF National Office for processing - thank you!");
	}
*/
}


//###
//### Form: VBApplicationForm.asp
//###
/*
function vbApplicationFormID_onreset() {
	if (confirm('Data displayed on this form will be cleared only!  Are you absolutely sure?') == false)
		event.returnValue = false;
	document.forms.vbApplicationFormID.vbAPFirstNameID.focus();
}
*/

function vbApplicationFormID_onsubmit() {
	// To cancel a submission, return false or set event.returnValue = false;

	//###
	// APPLICATION SECTION
	//###
return true;
	// VALIDATE first name
	OK = field_mustfill(vbApplicationFormID.vbAPFirstNameID, "Please enter your first name here.");
	if (!OK)
		return false;

	// VALIDATE middle name
	/*
	OK = field_mustfill(vbApplicationFormID.vbAPMiddleName, "Please enter your middle name here.");
	if (!OK)
		return false;
	*/
	
	// VALIDATE last name
	OK = field_mustfill(vbApplicationFormID.vbAPLastNameID, "Please enter your last name here.");
	if (!OK)
		return false;

	// VALIDATE month of birth
	OK = field_mustfill(vbApplicationFormID.vbAPBirthMonthID, "Please enter month (01-12) of your birth here.");
	if (!OK)
		return false;

	// VALIDATE month, if entered
	OK = digit_validate(vbApplicationFormID.vbAPBirthMonthID, 2, false);
	if (!OK) {
		return false;
	}
	else {
		// VALIDATE day of birth
		OK = field_mustfill(vbApplicationFormID.vbAPBirthDayID, "Please enter day (01-31) of your birth here.");
		if (!OK)
			return false;

		// VALIDATE day, if entered
		OK = digit_validate(vbApplicationFormID.vbAPBirthDayID, 2, false);
		if (!OK) {
			return false;
		}
		else {
			// VALIDATE year of birth
			OK = field_mustfill(vbApplicationFormID.vbAPBirthYearID, "Please enter the 4-digit year of your birth here.");
			if (!OK)
				return false;

			// VALIDATE year, if entered
			OK = digit_validate(vbApplicationFormID.vbAPBirthYearID, 4, false);
			if (!OK)
				return false;
		}
	}

	// VALIDATE name of parent/legal guardian
	if (vbApplicationFormID.vbAPBirthYearID > 86)
	{
		OK = field_mustfill(vbApplicationFormID.vbAPParentNameID, "Please enter the name of your parent(s) or legal guardian(s) here.");
		if (!OK)
			return false;
	}

	// VALIDATE phone number, if entered
	OK = phone_validate(vbApplicationFormID.vbAPHomePhoneAID,
	                    vbApplicationFormID.vbAPHomePhone3ID,
	                    vbApplicationFormID.vbAPHomePhone4ID);
	if (!OK)
		return false;

	// VALIDATE fax number, if entered
	OK = phone_validate(vbApplicationFormID.vbAPFaxAID,
	                    vbApplicationFormID.vbAPFax3ID,
	                    vbApplicationFormID.vbAPFax4ID);
	if (!OK)
		return false;

	// VALIDATE email
	OK = field_mustfill(vbApplicationFormID.vbAPEmailID, "Please enter your email address here.  " +
		"A copy of everything you enter on this form will be mailed to this email address.\r\n" +
		"WARNING: This form does NOT validate email addresses, so type the email address and check it for accuracy!");
	if (!OK)
		return false;
	
	// VALIDATE street
	OK = field_mustfill(vbApplicationFormID.vbAPStreet, "Please enter the street address here.");
	if (!OK)
		return false;

	// VALIDATE postal address
	OK = address_validate(vbApplicationFormID.vbAPStreet,
	                      vbApplicationFormID.vbAPCityID,
	                      vbApplicationFormID.vbAPStateID,
	                      vbApplicationFormID.vbAPZipID,
	                      vbApplicationFormID.vbAPZip4ID);
	if (!OK)
		return false;

	/*
	// VALIDATE at least one selection of interest
	CHOK = false;
	if (vbApplicationFormID.vbChk1ID.checked ||
		vbApplicationFormID.vbChk2ID.checked ||
		vbApplicationFormID.vbChk3ID.checked)
		CHOK = true;
	if (!CHOK) {
		alert('Please check the type of activity or activities you are interested in.');
		return false;
	}
	*/

/*
	if (event.returnValue != false) {
		// Information automatically sent to server
		alert("Your request has been e-mailed to the USADSF National Office for processing - thank you!");
	}
*/
	//###
	// ATHLETE PROFILE SECTION
	//###

	//###
	// HEALTH INSURANCE SECTION
	//###

}


//###
//### Form: GetPassword.html
//###
function pwdFormID_onreset() {
	if (confirm('Current data entered in this form will be cleared before creating a new request!  Are you sure?') == false)
		event.returnValue = false;
	document.forms.pwdFormID.pwdUserFirstNameID.focus();
}

function pwdFormID_onsubmit() {
	// To cancel a submission, return false or set event.returnValue = false;

	//###
	// USER NAME AND E-MAIL ADDRESS
	//###

	// VALIDATE first name
	OK = field_mustfill(pwdFormID.pwdUserFirstNameID, "Please enter your first name here.");
	if (!OK)
		return false;

	// VALIDATE last name
	OK = field_mustfill(pwdFormID.pwdUserLastNameID, "Please enter your last name here.");
	if (!OK)
		return false;

	// VALIDATE email
	OK = field_mustfill(pwdFormID.pwdUserEmailID, "Please enter your email address here.  " +
		"The password will be sent to this email address.\r\n\r\n" +
		"WARNING: This form does NOT know if your email address is legitimate, so type the\r\nemail address carefully and check it for accuracy!");
	if (!OK)
		return false;

	// VALIDATE email re-type
	OK = field_mustfill(pwdFormID.pwdUserEmailAgainID, "Please retype email address here for accuracy check.");
	if (!OK)
		return false;

	// VALIDATE email for accuracy
	OK = field_mustmatch(pwdFormID.pwdUserEmailID, pwdFormID.pwdUserEmailAgainID, "Email addresses do not match. Please double-check e-mail address for accuracy.");
	if (!OK)
		return false;

}

function logFormID_onreset() {
	if (confirm('Current data entered in this form will be cleared!  Are you sure?') == false)
		event.returnValue = false;
	document.forms.logFormID.logUserEmailID.focus();
}

function logFormID_onsubmit() {
	// To cancel a submission, return false or set event.returnValue = false;

	//###
	// E-MAIL ADDRESS and PASSWORD
	//###

	// VALIDATE email
	OK = field_mustfill(logFormID.logUserEmailID, "Please enter your email address here.");
	if (!OK)
		return false;

	// VALIDATE password
	OK = field_mustfill(logFormID.logUserPasswordID, "Please enter your password here.");
	if (!OK)
		return false;

	OK = field_mustlength(logFormID.logUserPasswordID, "The password length is 6 characters.", 6);
	if (!OK)
		return false;
	
}


function field_mustfill(eSrc, sMsg) {
	var strTxt = String(eSrc.value);

	if (strTxt.length < 1) {
		AbortEntry(eSrc, sMsg);
		return false;
	}
	else {
		AcceptEntry(eSrc);
	}
	return true;
}

function field_mustmatch(eSrc, eCpy, sMsg) {
	var strTxtSrc = String(eSrc.value);
	var strTxtCpy = String(eCpy.value);

	strTxtSrc = strTxtSrc.toUpperCase();
	strTxtCpy = strTxtCpy.toUpperCase();
	
	if (strTxtSrc != strTxtCpy) {
		AbortEntry(eSrc, sMsg);
		return false;
	}
	else {
		AcceptEntry(eSrc);
	}
	return true;
}

function field_mustlength(eSrc, sMsg, iLen) {
	var strTxt = String(eSrc.value);

	if (strTxt.length != iLen) {
		AbortEntry(eSrc, sMsg);
		return false;
	}
	else {
		AcceptEntry(eSrc);
	}
	return true;
}


function AcceptEntry(eSrc) {
	// reset the background color to normal
	eSrc.style.backgroundColor = ""
}

function AbortEntry(eSrc, sMsg) {
	// inform the user
	window.alert(sMsg);
	// set focus to the offending error and highlight it
	eSrc.style.backgroundColor = "Yellow";
	eSrc.focus();
	eSrc.select();
}

function AbortSelection(eSrc, sMsg) {
	// inform the user
	window.alert(sMsg);
	// set focus to the offending error and highlight it
	eSrc.style.backgroundColor = "Yellow";
	eSrc.focus();
}

function phone_validate(eAreaCode, eCityCode, eLocalNbr) {
	var strAreaCode = String(eAreaCode.value);
	var strCityCode = String(eCityCode.value);
	var strLocalNbr = String(eLocalNbr.value);

	if (strAreaCode.length > 0 ||
		strCityCode.length > 0 ||
		strLocalNbr.length > 0) {
		OK = digit_validate(eAreaCode, 3, true);
		if (!OK)
			return false;
		OK = digit_validate(eCityCode, 3, true);
		if (!OK)
			return false;
		OK = digit_validate(eLocalNbr, 4, true);
		if (!OK)
			return false;
	}
	return true;
}

function state_validate(eSrc) {
	var format = new RegExp("^[A-Z][A-Z]$", "g");
	var strText = eSrc.value

	eSrc.value = strText.toUpperCase();
	OK = format.test(eSrc.value);
	if (!OK) {
		sMsg = String("Please enter the 2-letter state code.");
		AbortEntry(eSrc, sMsg);
		return false;
	}
	AcceptEntry(eSrc)
	return true;
}

function digit_validate(eSrc, nDigits, fReqd) {
	var strText = String(eSrc.value)

	// if field entry is not required and no character entered yet, pass.
	if (!fReqd && strText.length == 0)
		return true;

	sRegExp = String("^\\d{" + nDigits + "}$");
	var format = new RegExp(sRegExp, "g");

	OK = format.test(eSrc.value);
	if (!OK) {
		sMsg = String("Please enter " + nDigits + " digits (0-9).");
		AbortEntry(eSrc, sMsg);
		return false;
	}
	AcceptEntry(eSrc)
	return true;
}

function address_validate(eStreet, eCity, eState, eZip, eZip4) {	
	var strTxt = String(eStreet.value);

	if (strTxt.length != 0) {
		OK = field_mustfill(eCity, "Please enter the city.");
		if (!OK)
			return false;
		OK = state_validate(eState);
		if (!OK)
			return false;
		OK = digit_validate(eZip, 5, true);
		if (!OK)
			return false;
		OK = digit_validate(eZip4, 4, false);
		if (!OK)
			return false;
	}
	return true;
}

