
/*
function name: openReg()
purpose: To open the registration form in a new window with limited controls.
author: Lisa Bradley
date: 2/21/07
parameters: linkTarget - the variable is passed from the onclick event handler that is meant to open the registration form
*/
function openReg(linkTarget) {
	openWin = window.open(linkTarget, "RegWin", "toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes, height=700, width=650");
	openWin.focus();
}
			
			
/*
function name: openNews()
purpose: To open the newsletter in a new window with limited controls.
author: Lisa Bradley
date: 2/21/07
parameters: linkTarget - the variable is passed from the onclick event handler that is meant to open the newsletter
*/
function openNews(linkTarget) {
	openNewsWin = window.open(linkTarget, "newsWin", "toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes, height=700, width=650");
	openNewsWin.focus();
}


/*
function name: openDirections()
purpose: To open the printable directions page in a new window with limited controls.
author: Lisa Bradley
date: 2/21/07
parameters: linkTarget - the variable is passed from the onclick event handler that is meant to open the printable directions page
*/
function openDirections(linkTarget) {
	openDirectionsWin = window.open(linkTarget, "directionsWin", "toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes, height=700, width=650");
	openDirectionsWin.focus();
}

/*
function name: openContact()
purpose: To open the printable staff contact page in a new window with limited controls.
author: Lisa Bradley
date: 2/21/07
parameters: linkTarget - the variable is passed from the onclick event handler that is meant to open the printable staff contact page
*/
function openContact(linkTarget) {
	openStaffWin = window.open(linkTarget, "staffWin", "toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes, height=700, width=650");
	openStaffWin.focus();
}

/*
function name: openGroupReg()
purpose: To open the small group registration form in a new window with limited controls.
author: Lisa Bradley
date: 2/21/07
parameters: linkTarget - the variable is passed from the onclick event handler that is meant to open the registration form
*/
function openGroupReg(linkTarget) {
	openWin = window.open(linkTarget, "GroupRegWin", "toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes, height=700, width=650");
	openWin.focus();
}


/*
function name: chkRegForm()
purpose: This function will check that all required fields have been filled in accurately on the RCC registration form.
author: Lisa Bradley
date: 2/21/07
parameters: none
*/
function chkRegForm(){
	var blnConfirm = confirm("Are you sure you want to submit this form?");
	
	if (blnConfirm == true)
		{
		// checking that name field is filled in.
		if (document.forms[0].name.value == "") {
			alert("You must enter your first and last name to register");
			return false;
		}
		// checking that either a phone number, email or address is provided.
		if ((document.forms[0].phone.value == "") && (document.forms[0].address.value == "") && (document.forms[0].txtemail.value == "")) {
			alert("You must enter at least one method of contact - phone, email or street address.");
			return false;
		}
		// checking that if address is field in, that city is also filled in
		if ((document.forms[0].address.value != "") && (document.forms[0].city.value == "")) {
			alert("You must enter your city.");
			return false;
		}
		// checking that if address and city are filled in, state is also filled in
		if ((document.forms[0].address.value != "") && (document.forms[0].city.value != "") && (document.forms[0].state.value == "")) {
			alert("You must enter your state.");
			return false;
		}
		// checking that if address, city, and state are filled in, that zip is filled in as well
		if ((document.forms[0].address.value != "") && (document.forms[0].city.value != "") && (document.forms[0].state.value != "") && (document.forms[0].zip.value == "")) {
			alert("You must enter your zip code.");
			return false;
		}
		if ( (document.forms[0].elements[10].checked == false) && (document.forms[0].elements[12].checked == false) && (document.forms[0].elements[13].checked == false) && (document.forms[0].elements[14].checked == false) && (document.forms[0].elements[15].checked == false) && (document.forms[0].elements[16].checked == false) ) {
			alert("Please tell us what class/event you would like to register for.");
			return false;
		}
		
		return true;
		
		} // end confirm if
		
		
		if (blnConfirm == false) {
			return false;
		}
			
} //end of function chkRegForm


/*
function name: checkForNumber()
purpose: This function will check that all date entered into a field consists of only numbers.
author: Lisa Bradley
date: 2/21/07
parameters: fieldValue - the value passed to the function from the field.
*/
function checkForNumber(fieldValue) {
	var numberCheck = isNaN(fieldValue);
	if (numberCheck == true) {
		window.alert("You must enter a numeric value!");
		return false;
	}
	return true;
}

/*
function name: checkEmail()
purpose: This function will check that the email address fits the standard pattern.
author: Lisa Bradley
date: 2/21/07
parameters: emailValue
*/
function checkEmail(emailValue) {
	var strEmail = emailValue;
	
	if( (strEmail.indexOf("@", 0) == 0)
		|| (strEmail.lastIndexOf("@") == (strEmail.length -1)) 
		|| (strEmail.lastIndexOf(".") == (strEmail.length -1)) 
		|| (strEmail.length - strEmail.lastIndexOf(".") <= 2) 
		|| (strEmail.indexOf("@", 0) == -1) 
		|| (strEmail.indexOf(".", 0) == -1) ) {
		alert("Your email address does not seem to be properly formatted. \nPlease check the value.");
			
			return false;
		}
		
		return true;
}

// begin scripts for golf tournament form
/*
function name: calculateGolfTotal()
purpose: To calculate the amount owed on golf tournament registration form.
author: Lisa Bradley
date: 6/30/07
parameters: none
*/
function calculateGolfTotal() {
	var intLunch1 = 0;
	var intLunch2 = 0;
	var intLunch3 = 0;
	var intLunch4 = 0;
	var intLunchNum = 0;
	var intLunchCost = 0;
	var intPlayer1 = 0;
	var intPlayer2 = 0;
	var intPlayer3 = 0;
	var intPlayer4 = 0;
	var intPlayers = 0;
	var intPlayerCost = 0;
	var intMulligans = 0;
	var intMulliganCost = 0;
	var blnForgiveness = false;
	var intForgivenessCost = 0;
	var intTotal = 0;
	
	
	// verify player name is filled in - alerts but doesn't stop processing of form
	if ((document.forms[0].txtAddress1.value != "") || (document.forms[0].txtPhone1.value != "") || (document.forms[0].txtEmail1.value != "")) {
		if (document.forms[0].txtName1.value == "") {
			alert("You must fill in the player's name.");
			document.forms[0].txtName1.focus();
		}
	}
	if ((document.forms[0].txtAddress2.value != "") || (document.forms[0].txtPhone2.value != "") || (document.forms[0].txtEmail2.value != "")) {
		if (document.forms[0].txtName2.value == "") {
			alert("You must fill in the player's name.");
			document.forms[0].txtName2.focus();
		}
	}
	if ((document.forms[0].txtAddress3.value != "") || (document.forms[0].txtPhone3.value != "") || (document.forms[0].txtEmail3.value != "")) {
		if (document.forms[0].txtName3.value == "") {
			alert("You must fill in the player's name.");
			document.forms[0].txtName3.focus();
		}
	}
	if ((document.forms[0].txtAddress4.value != "") || (document.forms[0].txtPhone4.value != "") || (document.forms[0].txtEmail4.value != "")) {
		if (document.forms[0].txtName4.value == "") {
			alert("You must fill in the player's name.");
			document.forms[0].txtName4.focus();
		}
	}
	
	// calculate lunch cost
	if (document.forms[0].chkLunch1.checked == true ) {
		intLunch1 = 1;
	}
	if (document.forms[0].chkLunch2.checked == true ) {
		intLunch2 = 1;
	}
	if (document.forms[0].chkLunch3.checked == true ) {
		intLunch3 = 1;
	}
	if (document.forms[0].chkLunch4.checked == true ) {
		intLunch4 = 1;
	}
	intLunchNum = intLunch1 + intLunch2 + intLunch3 + intLunch4;
	intLunchCost = intLunchNum * 10;
	
	
	// calculate player cost
	if (document.forms[0].txtName1.value != "" ) {
		intPlayer1 = 1;
	}
	if (document.forms[0].txtName2.value != "" ) {
		intPlayer2 = 1;
	}
	if (document.forms[0].txtName3.value != "" ) {
		intPlayer3 = 1;
	}
	if (document.forms[0].txtName4.value != "" ) {
		intPlayer4 = 1;
	}
	intPlayers = intPlayer1 + intPlayer2 + intPlayer3 + intPlayer4;
	intPlayerCost = intPlayers * 50;
	
	
	
	// calculate mulligans cost
	intMulligans = document.forms[0].numberMulligans.value;
	if (intMulligans != 5) {
		intMulliganCost = intMulligans * 5;
	}
	else if(intMulligans = 5) {
		intMulliganCost = 20;
	}
	
	
	//calculate forgiveness cost
	if (document.forms[0].rdoForgiveness.checked == true) {
		intForgivenessCost = 20;
	}
	else {
		intForgivenessCost = 0;
	}
	
	
	// calculate total cost
	intTotal = intLunchCost + intPlayerCost + intMulliganCost + intForgivenessCost;
	
	document.forms[0].numberTickets.value = intLunchNum;
	document.forms[0].ticketCost.value = intLunchCost;
	document.forms[0].numberPlayers.value = intPlayers;
	document.forms[0].playerCost.value = intPlayerCost;
	document.forms[0].mulligansCost.value = intMulliganCost;
	document.forms[0].forgivenessCost.value = intForgivenessCost;
	document.forms[0].txtTotal.value = intTotal;
	
	return true;
	
}// end calculateGolfTotal() function


/*
function name: chkGolfForm()
purpose: To verify that fields have been filled in correctly before the golf reg form has been submitted.
author: Lisa Bradley
date: 6/30/07
parameters: none
*/
function chkGolfForm() {
	
	//verify at least 1 player entered
	if ((document.forms[0].txtName1.value == "") && (document.forms[0].txtName2.value == "") && (document.forms[0].txtName3.value == "") && (document.forms[0].txtName4.value == "")) {
	alert ("Please register at least one player before submitting the form.");
	return false;
	}
	
	// verify player name is filled in - alerts and stops processing of form
	if ((document.forms[0].txtAddress1.value != "") || (document.forms[0].txtPhone1.value != "") || (document.forms[0].txtEmail1.value != "")) {
		if (document.forms[0].txtName1.value == "") {
			alert("You must fill in the player's name.");
			document.forms[0].txtName1.focus();
			return false;
		}
	}
	if ((document.forms[0].txtAddress2.value != "") || (document.forms[0].txtPhone2.value != "") || (document.forms[0].txtEmail2.value != "")) {
		if (document.forms[0].txtName2.value == "") {
			alert("You must fill in the player's name.");
			document.forms[0].txtName2.focus();
			return false;
		}
	}
	if ((document.forms[0].txtAddress3.value != "") || (document.forms[0].txtPhone3.value != "") || (document.forms[0].txtEmail3.value != "")) {
		if (document.forms[0].txtName3.value == "") {
			alert("You must fill in the player's name.");
			document.forms[0].txtName3.focus();
			return false;
		}
	}
	if ((document.forms[0].txtAddress4.value != "") || (document.forms[0].txtPhone4.value != "") || (document.forms[0].txtEmail4.value != "")) {
		if (document.forms[0].txtName4.value == "") {
			alert("You must fill in the player's name.");
			document.forms[0].txtName4.focus();
			return false;
		}
	}
	
	// verify that one method of contact is filled in
	if (document.forms[0].txtName1.value != "") {
		if ((document.forms[0].txtAddress1.value == "") && (document.forms[0].txtPhone1.value == "") && (document.forms[0].txtEmail1.value == "")) {
			alert("Please enter at least one method of contact for Player Number 1.");
			document.forms[0].txtAddress1.focus();
			return false;
		}
	}
	if (document.forms[0].txtName2.value != "") {
		if ((document.forms[0].txtAddress2.value == "") && (document.forms[0].txtPhone2.value == "") && (document.forms[0].txtEmail2.value == "")) {
			alert("Please enter at least one method of contact for Player Number 2.");
			document.forms[0].txtAddress2.focus();
			return false;
		}
	}
	if (document.forms[0].txtName3.value != "") {
		if ((document.forms[0].txtAddress3.value == "") && (document.forms[0].txtPhone3.value == "") && (document.forms[0].txtEmail3.value == "")) {
			alert("Please enter at least one method of contact for Player Number 3.");
			document.forms[0].txtAddress3.focus();
			return false;
		}
	}
	if (document.forms[0].txtName4.value != "") {
		if ((document.forms[0].txtAddress4.value == "") && (document.forms[0].txtPhone4.value == "") && (document.forms[0].txtEmail4.value == "")) {
			alert("Please enter at least one method of contact for Player Number 4.");
			document.forms[0].txtAddress4.focus();
			return false;
		}
	}
	
	return true;
	
} // end chkGolfForm() function


// end scripts for golf tournament form



/*
function name: chk40DaysHostForm()
purpose: This function will check that all required fields have been filled in accurately on the 40 Days host registration form.
author: Lisa Bradley
date: 7/14/07
parameters: none
*/
function chk40DaysForm(){
	var blnConfirm = confirm("Are you sure you want to submit this form?");
	
	if (blnConfirm == true)
		{
		// checking that all contact fields (except email) are filled in.
		for (i=3; i<5; ++i) {
			if (document.forms[0].elements[i].value == "") {
				alert ("Please enter your " + document.forms[0].elements[i].id + " so that we may contact you.");
				document.forms[0].elements[i].focus();
				return false;
			}
		}
		
		// skip email requirement
		
		// checking that all contact fields (except email) are filled in.
		for (j=6; j<10; ++j) {
			if (document.forms[0].elements[j].value == "") {
				alert ("Please enter your " + document.forms[0].elements[j].id + " so that we may contact you.");
				document.forms[0].elements[j].focus();
				return false;
			}
		}
		
		return true;
		
		} // end confirm if
		
		
		if (blnConfirm == false) {
			return false;
		}
			
} //end of function chk40DaysHostForm
