// This function takes the number of males and number of females and updates the total text box.
function updateTotals(source)
{
	

	
	var male = document.getElementById(source + "_m").value;
	var female = document.getElementById(source + "_f").value;
	
	if(female == "")
		female = 0;
		
	if(male == "")
	   male = 0;
	
	
	var total = parseInt(male) + parseInt(female);
	
	document.getElementById(source + "_total").value = total;
	
	
	updateSportsTotal();
	
	
	
	return true;
	
	
	
}

//this function updates the total for all males and females and the grand total of players
function updateSportsTotal()
{
	
	var maleTotal = 0;
	var femaleTotal = 0;
	
	
	//this loop gets all the values of male sports column
	for(i=9; i < 102; i += 3)
	{
		
		//we have to skip these numbers because there are extra fields at the end of the form
		if(i == 93 || i==97 || i==101) i++;
		if(document.forms[0].elements[i].value != "")
			maleTotal += parseInt(document.forms[0].elements[i].value);
	}
	
	//get the values from the female column
	for(i=10; i < 103; i += 3)
	{
		if(i == 94 || i==98 || i==102) i++;
		
		if(document.forms[0].elements[i].value != "")
			femaleTotal += parseInt(document.forms[0].elements[i].value);
	}
	
	//update the text fields with the totals
	document.forms[0].elements[105].value = maleTotal;
	document.forms[0].elements[106].value = femaleTotal;
	document.forms[0].elements[107].value = maleTotal + femaleTotal;
	
	
	//alert("Male Total: " + maleTotal);
	//alert("Female Total: " + femaleTotal);
	

	
}




// This function takes the number of males and number of females and updates the total text box.
function updateTotals2(source)
{
	

	
	var male = document.getElementById(source + "_m").value;
	var female = document.getElementById(source + "_f").value;
	
	if(female == "")
		female = 0;
		
	if(male == "")
	   male = 0;
	
	
	var total = parseInt(male) + parseInt(female);
	
	document.getElementById(source + "_total").value = total;
	
	
	updateSportsTotal2();
	
	
	
	return true;
	
	
	
}




//this function updates the total for all males and females and the grand total of players
function updateSportsTotal2()
{
	
	var maleTotal = 0;
	var femaleTotal = 0;
	
	
	//this loop gets all the values of male sports column
	for(i=0; i < 117; i += 3)
	{
		
		//we have to skip these numbers because there are extra fields at the end of the form
		if(i == 84 || i==88 || i==92 || i==96 || i==100 || i==104 || i==108 || i==112 || i==116) i++;
		if(document.forms[0].elements[i].value != "")
			maleTotal += parseInt(document.forms[0].elements[i].value);
	}
	
	//get the values from the female column
	for(i=1; i < 118; i += 3)
	{
		if(i == 85 || i==89 || i==93 || i==97 || i==101 || i==105 || i ==109 || i==113 || i==117) i++;
		
		if(document.forms[0].elements[i].value != "")
			femaleTotal += parseInt(document.forms[0].elements[i].value);
	}
	
	//update the text fields with the totals
	document.forms[0].elements[120].value = maleTotal;
	document.forms[0].elements[121].value = femaleTotal;
	document.forms[0].elements[122].value = maleTotal + femaleTotal;
	
	
	//alert("Male Total: " + maleTotal);
	//alert("Female Total: " + femaleTotal);
	

	
}