//alert("Including MailFormProcessor.js.");
var Version = "1.00";

var MenuBuilt = false;
var Results = new Array();
var ResultsArrayLength = 0;
var ResultsString = new String();

var isClubCodeFilterSet = Boolean();
var isLastNameFilterSet = Boolean();
var isFirstNameFilterSet = Boolean();
var areNameFiltersSet = Boolean();
var isAgeGroupFilterSet = Boolean();
var isGenderFilterSet = Boolean();

function ResetAll() {
	document.getElementById("MailListSignUpForm").reset();
	return false;
}

var SubmitType = "";
function SetSubmitType(SubmitValue) {
	SubmitType = SubmitValue;
}

function CheckForm() {
	
	var FirstName = document.getElementById("FirstName").value;
	var LastName  = document.getElementById("LastName").value;
	var Address   = document.getElementById("Address").value;
	var Island    = document.getElementById("Island").value;
	var ClubCode  = document.getElementById("ClubCode").value;
	var ListType = document.getElementById("ListType").value;
	if (document.getElementById("Phone") != null) { var Phone = document.getElementById("Phone").value; }
	if (document.getElementById("TShirt") != null) { var TShirt = document.getElementById("TShirt").value; }
	
	var isFirstNameValid = FirstName.match(/^([a-z]|[A-Z])+([-]?([a-z]|[A-Z])+)?$/);
	var isLastNameValid  = LastName.match(/^([a-z]|[A-Z])+([-]?([a-z]|[A-Z])+)?$/);
	var isAddressValid   = Address.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{3})+$/);
	var isIslandSet      = (Island != "");
	var isClubCodeSet    = (ClubCode != "");
	var isListTypeSet   = (ListType != "");
	var isSubscribeSet   = (SubmitType == "subscribe");
	var isUnSubscribeSet = (SubmitType == "unsubscribe");
	
	SubmitType = ""; // clear for subsequent form correction submits
	
	if (!isFirstNameValid) {
		alert ("Your First Name does not appear to be valid.\n"+
				"No special characters except for a hypen (-) are supported."+
				"Please check it and re-submit your form.");
		return false;
	}
	if (!isLastNameValid) {
		alert ("Your Last Name does not appear to be valid.\n"+
				"No special characters except for a hypen (-) are supported."+
				"Please check it and re-submit your form.");
		return false;
	}
	if (!isAddressValid) {
		alert ("Your E-mail Address does not appear to be valid.\n"+
				"Please check it and re-submit your form.");
		return false;
	}
	if (!isIslandSet) {
		alert ("Please select an Island of residence\n"+
				"and re-submit your form.");
		return false;
	}
	if (!isClubCodeSet) {
		alert ("Please select a Club Affiliation.\n"+
				"If you do not have one please select the\n"+
				"\"none\" option and re-submit your form.");
		return false;
	}
	if (!isListTypeSet) {
		alert ("Please select the Club Function you perform.\n"+
				"If you do not perform one of the listed functions\n"+
				"please select the \"none\" option and re-submit your form.");
		return false;
	}
	if (!isSubscribeSet && !isUnSubscribeSet) {
		alert ("Please select either the \"Subscribe\"\n"+
				"button or the \"UnSubscribe\" button.");
		return false;
	}

	if (ListType == "TeamHawaii") {
		if (isSubscribeSet) {
			return confirm(""+
				"Please verify your SUBSCRIBE information:\n"+
				" \n"+
				"First Name - "+ FirstName +"\n"+
				"Last Name - "+ LastName +"\n"+
				"E-mail Address - "+ Address +"\n"+
				"Club Abbreviation - "+ ClubCode);
			}
		if (isUnSubscribeSet) {
			return confirm(""+
				"Please verify your UN-SUBSCRIBE information:\n"+
				" \n"+
				"First Name - "+ FirstName +"\n"+
				"Last Name - "+ LastName +"\n"+
				"E-mail Address - "+ Address +"\n"+
				"Club Abbreviation - "+ ClubCode);
		}
	} else if (ListType == "SeniorCamp") {
		if (isSubscribeSet) {
			return confirm(""+
				"Please verify your SUBSCRIBE information:\n"+
				" \n"+
				"First Name - "+ FirstName +"\n"+
				"Last Name - "+ LastName +"\n"+
				"E-mail Address - "+ Address +"\n"+
				"Club Abbreviation - "+ ClubCode +"\n"+
				"Phone Number - "+ Phone +"\n"+
				"T-Shirt Size - "+ TShirt);
			}
		if (isUnSubscribeSet) {
			return confirm(""+
				"Please verify your UN-SUBSCRIBE information:\n"+
				" \n"+
				"First Name - "+ FirstName +"\n"+
				"Last Name - "+ LastName +"\n"+
				"E-mail Address - "+ Address +"\n"+
				"Club Abbreviation - "+ ClubCode +"\n"+
				"Phone Number - "+ Phone +"\n"+
				"T-Shirt Size - "+ TShirt);
		}
	} else {
		if (isSubscribeSet) {
			return confirm(""+
				"Please verify your SUBSCRIBE information:\n"+
				" \n"+
				"First Name - "+ FirstName +"\n"+
				"Last Name - "+ LastName +"\n"+
				"E-mail Address - "+ Address +"\n"+
				" \n"+
				"Island Residence - "+ Island +"\n"+
				"Club Abbreviation - "+ ClubCode +"\n"+
				"Your Club Function - "+ ListType);
			}
		if (isUnSubscribeSet) {
			return confirm(""+
				"Please verify your UN-SUBSCRIBE information:\n"+
				" \n"+
				"First Name - "+ FirstName +"\n"+
				"Last Name - "+ LastName +"\n"+
				"E-mail Address - "+ Address +"\n"+
				" \n"+
				"Island Residence - "+ Island +"\n"+
				"Club Abbreviation - "+ ClubCode +"\n"+
				"Your Club Function - "+ ListType);
		}
	}
	return false;
	
}

function CheckListType(id) {
	if (id == "Other") {
		if (document.getElementById("BoardList") != null) { document.getElementById("BoardList").checked = false; }
		if (document.getElementById("CoachesList") != null) { document.getElementById("CoachesList").checked = false; }
		if (document.getElementById("EntriesList") != null) { document.getElementById("EntriesList").checked = false; }
		if (document.getElementById("DelegatesList") != null) { document.getElementById("DelegatesList").checked = false; }
		if (document.getElementById("OfficialsList") != null) { document.getElementById("OfficialsList").checked = false; }
		if (document.getElementById("RegistrarsList") != null) { document.getElementById("RegistrarsList").checked = false; }
	} else {
		if (document.getElementById("OtherList") != null) { document.getElementById("OtherList").checked = false; }
	}
}

function CheckListReset() {
	if (document.getElementById("BoardList") != null) { document.getElementById("BoardList").checked = false; }
	if (document.getElementById("CoachesList") != null) { document.getElementById("CoachesList").checked = false; }
	if (document.getElementById("EntriesList") != null) { document.getElementById("EntriesList").checked = false; }
	if (document.getElementById("DelegatesList") != null) { document.getElementById("DelegatesList").checked = false; }
	if (document.getElementById("OfficialsList") != null) { document.getElementById("OfficialsList").checked = false; }
	if (document.getElementById("RegistrarsList") != null) { document.getElementById("RegistrarsList").checked = false; }
	if (document.getElementById("OtherList") != null) { document.getElementById("OtherList").checked = false; }
}

addOnload(CheckListReset);