  /*================================================================*/
 /* Trees for Cities Javascript Document                           */
/*================================================================*/

function toggleDisplay(id) {

	// toggles the visibility of an element
	if (document.getElementById(id).style.display == 'none') {
	
		// if hidden, show it
		document.getElementById(id).style.display = 'block';
	}
	else{	
	
		// otherwise, if showing, hide it
		document.getElementById(id).style.display = 'none';
	}
}

function hideElement(id) {
	
	// sets an element's display to none
	document.getElementById(id).style.display = 'none';
}

function showElement(id) {
	
	// sets an element's display to block
	document.getElementById(id).style.display = 'block';
}

function MM_jumpMenu(targ,selObj,restore) {
	
	// Dreamweaver's jumpmenu script
  eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
  if (restore) selObj.selectedIndex = 0;
}

function highlight(membershipType) {
	
	// used in membership.html to highlight membership types
	document.getElementById('donationLevel_' + membershipType).style.backgroundColor = "#F1FFCC";
	document.getElementById('memberPack_' + membershipType).style.backgroundColor = "#F1FFCC";
	
	switch(membershipType) {
	
		case 1:
			document.getElementById('img_member_sapling').src = "images/membership_sapling_over.gif";
			break;
		case 2:
			document.getElementById('img_member_oak').src = "images/membership_oak_over.gif";
			break;
		case 3:
			document.getElementById('img_member_pear').src = "images/membership_pear_over.gif";
			break;
		case 4:
			document.getElementById('img_member_family').src = "images/membership_family_over.gif";
			break;
	}
}

function clearHighlight(membershipType) {

	// used in membership.html to turn off the highlighting
	document.getElementById('donationLevel_' + membershipType).style.backgroundColor = "#FFFFFF";
	document.getElementById('memberPack_' + membershipType).style.backgroundColor = "#FFFFFF";
	
	switch(membershipType) {
	
		case 1:
			document.getElementById('img_member_sapling').src = "images/membership_sapling.gif";
			break;
		case 2:
			document.getElementById('img_member_oak').src = "images/membership_oak.gif";
			break;
		case 3:
			document.getElementById('img_member_pear').src = "images/membership_pear.gif";
			break;
		case 4:
			document.getElementById('img_member_family').src = "images/membership_family.gif";
			break;
	}
}

function toggleSectionSelector() {
	
	// used in editPage.php
	if (document.getElementById("changeParentPage").checked == true) {
		
		// checked, so show all the section selector table rows
		document.getElementById("hiddenSectionSelect").style.display = ''; // IE doesn't understand 'table-row'
		document.getElementById("hiddenParentSelect").style.display = '';
		document.getElementById("hiddenChildSelect").style.display = '';
	}
	else {
		
		// hide them again
		document.getElementById("hiddenSectionSelect").style.display = 'none';
		document.getElementById("hiddenParentSelect").style.display = 'none';
		document.getElementById("hiddenChildSelect").style.display = 'none';
	}
}

function calculateTotal() {

	// script to calculate totals for membership/t-shirts
	form = document.getElementById('formRegistration');

	// work out the total number of t-shirts bought at which price
	var total = 0;
	
	var num_child_1to2 = 0;
	var num_child_3to4 = 0;
	var num_child_5to6 = 0;
	var num_child_7to8 = 0;
	var num_child_9to11 = 0;
	
	var num_adult_skinny_S = 0;
	var num_adult_skinny_M = 0;
	var num_adult_skinny_L = 0;
	var num_adult_skinny_XL = 0;
	
	var num_adult_unisex_S = 0;
	var num_adult_unisex_M = 0;
	var num_adult_unisex_L = 0;
	var num_adult_unisex_XL = 0;
	
	// check each value and assign or kick out
	
	// children's t-shirts
	if (isNaN(form.tshirt_child_1to2.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for children's t-shirts for 1 to 2 year-olds isn't a valid number.");
		form.tshirt_child_1to2.value = "0";
	}
	else {
	
		// was a number, update total
		num_child_1to2 = form.tshirt_child_1to2.value * 7.5;
	}
	
	if (isNaN(form.tshirt_child_3to4.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for children's t-shirts for 3 to 4 year-olds isn't a valid number.");
		form.tshirt_child_3to4.value = "0";
	}
	else {
	
		// was a number, update total
		num_child_3to4 = form.tshirt_child_3to4.value * 7.5;
	}
	
	if (isNaN(form.tshirt_child_5to6.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for children's t-shirts for 5 to 6 year-olds isn't a valid number.");
		form.tshirt_child_5to6.value = "0";
	}
	else {
	
		// was a number, update total
		num_child_5to6 = form.tshirt_child_5to6.value * 7.5;
	}
	
	if (isNaN(form.tshirt_child_7to8.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for children's t-shirts for 7 to 8 year-olds isn't a valid number.");
		form.tshirt_child_7to8.value = "0";
	}
	else {
	
		// was a number, update total
		num_child_7to8 = form.tshirt_child_7to8.value * 7.5;
	}
	
	if (isNaN(form.tshirt_child_9to11.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for children's t-shirts for 9 to 11 year-olds isn't a valid number.");
		form.tshirt_child_9to11.value = "0";
	}
	else {
	
		// was a number, update total
		num_child_9to11 = form.tshirt_child_9to11.value * 7.5;
	}
	
	// women's skinny fit t-shirts
	if (isNaN(form.tshirt_S_w.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for small women's skinny-fit t-shirts isn't a valid number.");
		form.tshirt_S_w.value = "0";
	}
	else {
	
		// was a number, update total
		num_adult_skinny_S = form.tshirt_S_w.value * 11;
	}
	
	if (isNaN(form.tshirt_M_w.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for medium women's skinny-fit t-shirts isn't a valid number.");
		form.tshirt_M_w.value = "0";
	}
	else {
	
		// was a number, update total
		num_adult_skinny_M = form.tshirt_M_w.value * 11;
	}
	
	if (isNaN(form.tshirt_L_w.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for large women's skinny-fit t-shirts isn't a valid number.");
		form.tshirt_L_w.value = "0";
	}
	else {
	
		// was a number, update total
		num_adult_skinny_L = form.tshirt_L_w.value * 11;
	}
	
	if (isNaN(form.tshirt_XL_w.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for extra-large women's skinny-fit t-shirts isn't a valid number.");
		form.tshirt_XL_w.value = "0";
	}
	else {
	
		// was a number, update total
		num_adult_skinny_XL = form.tshirt_XL_w.value * 11;
	}
	
	// unisex t-shirts
	if (isNaN(form.tshirt_S_u.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for small unisex t-shirts isn't a valid number.");
		form.tshirt_S_u.value = "0";
	}
	else {
	
		// was a number, update total
		num_adult_unisex_S = form.tshirt_S_u.value * 11;
	}
	
	if (isNaN(form.tshirt_M_u.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for medium unisex t-shirts isn't a valid number.");
		form.tshirt_M_u.value = "0";
	}
	else {
	
		// was a number, update total
		num_adult_unisex_M = form.tshirt_M_u.value * 11;
	}
	
	if (isNaN(form.tshirt_L_u.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for large unisex t-shirts isn't a valid number.");
		form.tshirt_L_u.value = "0";
	}
	else {
	
		// was a number, update total
		num_adult_unisex_L = form.tshirt_L_u.value * 11;
	}
	
	if (isNaN(form.tshirt_XL_u.value)) {
	
		// not a number, kick and replace value
		alert("The value you chose for extra-large unisex t-shirts isn't a valid number.");
		form.tshirt_XL_u.value = "0";
	}
	else {
	
		// was a number, update total
		num_adult_unisex_XL = form.tshirt_XL_u.value * 11;
	}
	
	// set total
	total = num_child_1to2 + num_child_3to4 + num_child_5to6 + num_child_7to8 + num_child_9to11;
	total += num_adult_skinny_S + num_adult_skinny_M + num_adult_skinny_L + num_adult_skinny_XL;
	total += num_adult_unisex_S + num_adult_unisex_M + num_adult_unisex_L + num_adult_unisex_XL;
	
	total = total.toFixed(2);
	
	document.getElementById('formRegistration_total').innerHTML = '&pound;' + total;
}

function submitForm() {

	calculateTotal();
	form.submit();
}