
/*
 * Promocode Sajax functions
 */
/*function get_promo_code( code )
 {
 document.getElementById("promo_text_cell").innerHTML = "Searching for matching/valid promotional code...";
 include_all = (editMode && preFill);
 //alert("include_all: "+include_all);
 x_get_promo_code( code, include_all, get_promo_code_cb );
 }

 function get_promo_code_cb( response )
 {
 //alert("response: "+response);
 var data = response.parseJSON();
 //alert("data: "+data);
 //alert("data.length: "+data.length);

 if (data.length > 0)
 {
 applyPromoCode( data[0] );
 } else {
 denyPromoCode();
 }
 //alert("response: "+data[0]);
 }*/

/*
 * Promo code functions
 */
/*function applyPromoCode( promo )
 {
 promoFixedDiscount = parseFloat(promo['am_discount_fixed']);
 promoPercentDiscount = parseFloat(promo['am_discount_percent']);

 if (promoFixedDiscount>0)
 {
 document.getElementById("promo_text_cell").innerHTML = "<strong>Promotional Code : </strong>"+promo['nm_promotion_code']+" accepted. This gives you a fixed "+dispPrefix+promoFixedDiscount.toFixed(2)+" accommodation discount.";
 } else {
 document.getElementById("promo_text_cell").innerHTML = "<strong>Promotional Code : </strong>"+promo['nm_promotion_code']+" accepted. This gives you a "+(promoPercentDiscount*100)+"% accommodation discount.";
 }

 changeGuestTotal();
 }

 function denyPromoCode()
 {
 promoFixedDiscount = 0;
 promoPercentDiscount = 0;

 document.getElementById("am_promo_discount").value = dispZero;
 document.getElementById("promo_text_cell").innerHTML = "No matching promotional code found";

 changeGuestTotal();
 }


 function removePromoCode()
 {
 document.getElementById("div_promo_code").style.display = "none";
 document.getElementById("tr_promo_field").style.display = "none";

 changeGuestTotal();
 }

 function showPromoCode()
 {
 document.getElementById("div_promo_code").style.display = "block";
 document.getElementById("tr_promo_field").style.display = rowDisplay;
 }*/

/*
 * Prefill form and adjust all dynamic areas according to the data in the Booking Object
 */
/*function preFillForm()
 {
 changeCateringType();
 if ( cateringType == 0 && document.getElementById('tx_promo_code').value != "" )
 {
 get_promo_code(document.getElementById('tx_promo_code').value);
 }

 changeNumAdult();
 changeNumChild();
 changeNumInfant();

 document.getElementById('am_adult_breakfast').selectedIndex = numAdultBrkFasts;
 document.getElementById('am_adult_evemeals').selectedIndex = numAdultEveMeals;
 document.getElementById('am_child_breakfast').selectedIndex = numChildBrkFasts;
 document.getElementById('am_child_evemeals').selectedIndex = numChildEveMeals;
 changeCatering();

 for ( var i=0; i<selectedExtras.length; i++)
 {
 document.getElementById('id_extra['+selectedExtras[i]+']').checked = true;
 changeExtras(selectedExtras[i]);
 }

 preFill = false;
 }*/

/*
 * Handler for when the Catering Type selector is changed
 */
function changeCateringType() {
	var selCateringType = document.getElementById("id_catering_type");
	/*
	 * if (preFill) { selCateringType.selectedIndex = cateringType; }
	 */
	switch (selCateringType.options[selCateringType.selectedIndex].value) {
	case "0": // fully catered
		//document.getElementById("div_part_catered").style.display = "none";
		document.getElementById("tr_empty_bed_field").style.display = rowDisplay;
		document.getElementById("tr_additional_person_field").style.display = rowDisplay;
		//document.getElementById("summary_meals_total_row").style.display = "none";
		document.getElementById("am_security_deposit_row").style.display = "none";
		document.getElementById("am_catering_adult_price_label").innerHTML = '&nbsp;@&nbsp;'
				+ currencySymbol
				+ ' '
				+ Number(amBrochurePrice).toFixed(2)
				+ ' each';
		document.getElementById("am_catering_child_price_label").innerHTML = '&nbsp;@&nbsp;'
				+ currencySymbol
				+ ' '
				+ Number(amBrochurePrice * amChildDiscount).toFixed(2)
				+ ' each';
		document.getElementById("am_catering_infant_price_label").innerHTML = '&nbsp;@&nbsp;'
				+ currencySymbol + ' ' + amInfantPrice + ' each';
		document.getElementById("am_accommodation_price_row").style.display = "none";
		document.getElementById("am_catering_guest_total").style.display = "block";

		document.getElementById("am_additional_person_label1").style.display = "";
		document.getElementById("am_additional_person_label2").style.display = "";
		document.getElementById("am_catering_adult_nmbr1").style.display = "";
		document.getElementById("am_catering_adult_nmbr2").style.display = "";

		document.getElementById("am_catering_sub_total_label").innerHTML = "<label for=\"am_catering_guest_total\"><strong>"
				+ labelStringCateredAccom + " : </strong></label>";
		showCaterTotals(true);
		// showPromoCode();
		fullyCatered = true;
		partCatered = false;
		break;

	case "1": // self catered
		//document.getElementById("div_part_catered").style.display = "none";
		document.getElementById("tr_empty_bed_field").style.display = "none";
		document.getElementById("tr_additional_person_field").style.display = "none";
		//document.getElementById("summary_meals_total_row").style.display = "none";
		document.getElementById("am_security_deposit_row").style.display = "none";
		document.getElementById("am_security_deposit_row").style.display = "none";
		document.getElementById("am_catering_guest_total").style.display = "none";
		document.getElementById("am_accommodation_price_row").style.display = rowDisplay;

		document.getElementById("am_catering_adult_nmbr1").style.display = "none";
		document.getElementById("am_catering_adult_nmbr2").style.display = "none";
		document.getElementById("am_additional_person_label1").style.display = "none";
		document.getElementById("am_additional_person_label2").style.display = "none";

		document.getElementById("am_catering_sub_total_label").innerHTML = "";// <label
																				// for=\"am_catering_guest_total\"><strong>"+labelStringAccom+"
																				// :
																				// </strong></label>
		showCaterTotals(false);
		// removePromoCode();
		fullyCatered = false;
		partCatered = false;
		break;
		
	}

	changeNumAdult();
}

/*
 * Show or hide the sub totals fields in the Accommodation fieldset
 */
function showCaterTotals(show) {
	var visible = show ? "visible" : "hidden";

	document.getElementById("am_catering_adult_price_cell").style.visibility = visible;
	document.getElementById("am_catering_child_price_cell").style.visibility = visible;
	document.getElementById("am_catering_infant_price_cell").style.visibility = visible;

	// document.getElementById("am_catering_sub_total_row").style.display =
	// (show) ? rowDisplay : "none";

	showFullyCateredPrices(show);
}

/*
 * Show or hide the sub totals fields in the Accommodation fieldset
 */
function showFullyCateredPrices(show) {
	if (!show) {
		document.getElementById("am_catering_adult_price_label").style.display = "none";
		document.getElementById("am_catering_adult_dd_cell").style.width = "50";

		document.getElementById("am_catering_child_price_label").style.display = "none";
		document.getElementById("am_catering_child_nmbr1_email_text").value = '';
		document.getElementById("am_catering_child_dd_cell").style.width = "50";

		document.getElementById("am_catering_infant_price_label").style.display = "none";
		document.getElementById("am_catering_infant_dd_cell").style.width = "50";

	} else {

		document.getElementById("am_catering_adult_price_label").style.display = "inline";
		document.getElementById("am_catering_adult_dd_cell").style.width = "300";

		document.getElementById("am_catering_child_dd_cell").style.width = "300";
		document.getElementById("am_catering_infant_dd_cell").style.width = "300";

		document.getElementById("am_catering_child_price_label").style.display = (numChildren > 0) ? "inline"
				: "none";
		document.getElementById("am_catering_infant_price_label").style.display = (numInfants > 0) ? "inline"
				: "none";
//		if(!(numChildren > 0)){
//			document.getElementById("am_catering_child_nmbr1_email_text").value = '';
//		}
	}
}

/*
 * Handler for when the number of adults are changed in the acommodation fieldset
 */
function changeNumAdult() {
	var selCateringType = document.getElementById("id_catering_type");
	var selAmCateringAdult = document.getElementById("am_catering_adult");

	//var selAdultBreakfast = document.getElementById("am_adult_breakfast");
//	var selAdultEveMeals = document.getElementById("am_adult_evemeals");

	var inpManualPricing = document.getElementById("inp_manual_pricing"); //alert(inpManualPricing);
	var inpPricePerAdult = document.getElementById("am_brochure_adult_price"); //alert(inpPricePerAdult);

	var selAmCateringNumChild = document.getElementById("am_catering_num_child");

//	var inpManualPricing = document.getElementById("inp_manual_pricing");
	var inpPricePerChild = document.getElementById("am_brochure_child_price");

	var factor1 = 1;
	var cost1 = 0;
	var factor2 = 1;
	var cost2 = 0;
	// First we get the factor = numAdult if Fully Catered, otherwise its 1
	numAdult = selAmCateringAdult.selectedIndex; 
	numChildren = selAmCateringNumChild.selectedIndex;
	//alert(numAdult +" "+ numChildren +" "+ chaletMaxCapacity);
	// if ( (numAdult + numChildren) > (admin_mode ? chaletMaxCapacity :
	// chaletCapacity) )
//	if ((numAdult + numChildren) > chaletMaxCapacity) {
//		window.alert("Chalet capacity exceeded");
//
//		// selAmCateringAdult.selectedIndex = ((admin_mode ? chaletMaxCapacity :
//		// chaletCapacity) - numChildren)-1;
//		selAmCateringAdult.selectedIndex = (chaletMaxCapacity - numChildren);
//		numAdult = selAmCateringAdult.selectedIndex;
//
//		selAmCateringNumChild.selectedIndex = (chaletMaxCapacity - numAdult);
//		numChildren = selAmCateringNumChild.selectedIndex;
//	}

	factor1 = fullyCatered ? numAdult : 1;
	factor2 = fullyCatered ? numChildren : 0;
	var additionalPerson = 0;
	
	if(!disableAdditionalPersonPricing){
		additionalPerson = (factor1 + factor2) - chaletCapacity;
	}
	else {
		additionalPerson = (factor1 + factor2) - chaletMaxCapacity;
	}
	
	additionalPerson = additionalPerson > 0 ? additionalPerson : 0;

	if (fullyCatered) {
		factor1 = numAdult - additionalPerson;
//		alert(numAdult+" "+additionalPerson+" "+additionalPerson+" "+numChildren);
	} else {
		// Pro-rate additional persons 		
		if ((numAdult + numChildren) > chaletCapacity) {
			additionalPerson = (numAdult + numChildren) - chaletCapacity;
			am_selfcatered_price_pro = Number((am_selfcatered_price + ((am_selfcatered_price / chaletCapacity) * additionalPerson))
					.toFixed(2));
			//alert(am_selfcatered_price+" "+additionalPerson);
			document.getElementById('am_accommodation_price_inp').value = currencySymbol
					+ " " + am_selfcatered_price_pro;
		} else {
			document.getElementById('am_accommodation_price_inp').value = currencySymbol
					+ " " + am_selfcatered_price.toFixed(2);
		}
	}

	// Next we work out the cost part - different for each type of catering option.
	switch (selCateringType.options[selCateringType.selectedIndex].value) {
	default:
	case "0": // Fully catered
		if (inpManualPricing != undefined && inpManualPricing.checked) {
			cost1 = checkNaN(inpPricePerAdult.value);
			inpPricePerAdult.value = cost1.toFixed(2);
		} else {
			cost1 = amBrochurePrice;
		}
		break;

	case "1": // Self catered
		cost1 = amCurrentPrice + am_security_deposit;
		break;
	}

	// Now we calculate the price, format it and display it in the field
	adultPrice = factor1 * cost1;
	if (!((additionalPerson > 0) && cateringType == 0 && numChildren > 0)){
		document.getElementById("am_catering_adult_price").value = dispPrefix + adultPrice.toFixed(2);
	}
	// changeCateringSelectOptions("am_adult_breakfast", 6);
	// changeCateringSelectOptions("am_adult_evemeals", 6);

	// Next we work out the cost part - for children we just discount the adult
	// price per person.
	if (inpManualPricing != undefined && inpManualPricing.checked) {
		cost2 = checkNaN(inpPricePerChild.value);
		inpPricePerChild.value = cost2.toFixed(2);
	} else {
		cost2 = amBrochurePrice * amChildDiscount;
	}

	// Now we calculate the price and format it and display it in the field
	childPrice = factor2 * cost2;
	if (!((additionalPerson > 0) && cateringType == 0 && numChildren > 0)){
		document.getElementById("am_catering_child_price").value = dispPrefix + childPrice.toFixed(2);
	}

	showFullyCateredPrices(fullyCatered);

	// changeCateringSelectOptions("am_child_breakfast", 6);
	// changeCateringSelectOptions("am_child_evemeals", 6);

	// adjustNumAdultRows();

	// adjustNumChildRows();
	// 	
	// adjustPartCatered();

	changeNumInfant();
	// changeNumChild();
}
/* 
 function changeNumAdult()
 {
 var selCateringType = document.getElementById("id_catering_type");
 var selAmCateringAdult = document.getElementById("am_catering_adult");
 var selAmCateringChildren = document.getElementById('am_catering_num_child')

 var selAdultBreakfast = document.getElementById("am_adult_breakfast");
 var selAdultEveMeals = document.getElementById("am_adult_evemeals");

 var factor = 1;
 var cost = 0;
 numAdult = selAmCateringAdult.selectedIndex;
 numChildren = selAmCateringChildren.selectedIndex;
 // First we get the factor = numAdult if Fully Catered, otherwise its 1

 if ( (numAdult + numChildren) > chaletMaxCapacity )
 {
 window.alert("Chalet capacity exceeded");

 selAmCateringAdult.selectedIndex = ((admin_mode ? chaletMaxCapacity : chaletCapacity) - numChildren)-1;
 numAdult = selAmCateringAdult.selectedIndex+1;
 }

 factor = fullyCatered ? numAdult : 1;

 // Next we work out the cost part - different for each type of catering
	// option.
 switch (selCateringType.options[selCateringType.selectedIndex].value)
 {
 default:
 case "0": // Fully catered
 cost = amBrochurePrice;
 break;

 case "1": // Self catered
 cost = amCurrentPrice + am_security_deposit;
 document.getElementById('am_catering_guest_total').value = cost
 break;
 }

 // Now we calculate the price, format it and display it in the field
 adultPrice = factor * cost;
 document.getElementById("am_catering_adult_price").value = dispPrefix+adultPrice.toFixed(2);

 changeNumChild();
 }
 */

/*
 * Handler for when the number of children is changed in the accommodation
 * fieldset
 */
function changeNumChild() {
	var selAmCateringNumChild = document
			.getElementById("am_catering_num_child");
	var factor = 1;
	var cost = 0;
	numChildren = selAmCateringNumChild.selectedIndex;
	
	// First we get the factor = numChildren if Fully Catered, otherwise its 0
	/*
	 * if (preFill) { selAmCateringNumChild.selectedIndex = numChildren; } else {
	 * //numAdult = selAmCateringAdult.selectedIndex+1;
	 *  }
	 */

//	if ((numAdult + numChildren) > (admin_mode ? chaletMaxCapacity
//			: chaletCapacity)) {
//		window.alert("Chalet capacity exceeded");
//
//		// selAmCateringNumChild.selectedIndex = ((admin_mode ?
////		// chaletMaxCapacity : chaletCapacity) - (numAdult + numInfants));
//		selAmCateringNumChild.selectedIndex = ((admin_mode ? chaletMaxCapacity
//				: chaletCapacity) - numAdult);
//		numChildren = selAmCateringNumChild.selectedIndex;
//	}

	factor = fullyCatered ? numChildren : 0;

	// Next we work out the cost part - for children we just discount the adult
	// price per person.
	cost = amBrochurePrice * amChildDiscount;

	// Now we calculate the price and format it and display it in the field
	childPrice = factor * cost;
//	document.getElementById("am_catering_child_price").value = dispPrefix
			+ childPrice.toFixed(2);

	showFullyCateredPrices(fullyCatered);

	// changeCateringSelectOptions("am_child_breakfast", numChildren);
	// changeCateringSelectOptions("am_child_evemeals", numChildren);
	// changeCateringSelectOptions("am_child_breakfast", 6);
	// changeCateringSelectOptions("am_child_evemeals", 6);

	// adjustNumChildRows();
	// adjustPartCatered();
	changeNumInfant();
}

/*
 * Handler for when the number of infants are changed in the accommodation fieldset
 */
function changeNumInfant() {
	var selAmCateringNumInfant = document
			.getElementById("am_catering_num_infant");
	var factor = 0;
	var cost = 0;

	numInfants = selAmCateringNumInfant.selectedIndex;

	// First we get the factor = numInfants if Fully Catered, otherwise its 0
	// First we get the factor = numChildren if Fully Catered, otherwise its 0
	/*
	 * if (preFill) { selAmCateringNumInfant.selectedIndex = numInfants; } else {
	 * //numAdult = selAmCateringAdult.selectedIndex+1; //numChildren =
	 * selAmCateringNumChild.selectedIndex; numInfants =
	 * selAmCateringNumInfant.selectedIndex; }
	 */

	/*
	 * if ( (numAdult + numChildren + numInfants) > (admin_mode ?
	 * chaletMaxCapacity : chaletCapacity) ) { window.alert("Chalet capacity
	 * exceeded");
	 * 
	 * selAmCateringNumInfant.selectedIndex = ((admin_mode ? chaletMaxCapacity :
	 * chaletCapacity) - (numAdult + numChildren)); numInfants =
	 * selAmCateringNumInfant.selectedIndex; }
	 */

	factor = fullyCatered ? numInfants : 0;

	// The cost is direct.
	cost = amInfantPrice;

	// Now we calculate the price format it and display it in the field
	infantPrice = factor * cost;
	document.getElementById("am_catering_infant_price").value = dispPrefix
			+ infantPrice.toFixed(2);

	showFullyCateredPrices(fullyCatered);

	// adjustNumInfantRows();
	changeSubTotal();
}

/*
 * Changes the subtotal field in the accommodation fieldset
 */
function changeSubTotal() {
	// alert("typeof: "+typeof(subTotalPrice));
	// document.getElementById("am_catering_sub_total").value =
	// dispPrefix+subTotalPrice.toFixed(2);

	calculateEmptyBedCharges();
}

/*
 * function to calculate the empty bed charges
 */
function calculateEmptyBedCharges() {
	//var emptyBeds = chaletCapacity - ( numAdult + numChildren + numInfants );
	var emptyBeds = chaletCapacity - (numAdult + numChildren);
	var emptyBedCost = 0;

	if (fullyCatered) {
		if (emptyBeds > 2) {
			emptyBedCost = (emptyBeds - 2) * amBrochurePrice;
		}

		if (emptyBeds > 1) {
			emptyBedCost += amBrochurePrice * amSecondEmptyBedPercentage;
		}

		if (emptyBeds > 0) {
			emptyBedCost += amBrochurePrice * amFirstEmptyBedPercentage;
		}
	}

	emptyBedTotalPrice = emptyBedCost;
	document.getElementById("am_catering_empty_bed").value = dispPrefix
			+ emptyBedTotalPrice.toFixed(2);

	calculateAdditionalPersonCharges();
}

/*
 * function to calculate the additional persons charges
 */
function calculateAdditionalPersonCharges() {
	
//	var disableAdditionalPersonPricing = document.getElementById("disable_additional_person").value;	
//	alert(disableAdditionalPersonPricing);
	if(Number(disableAdditionalPersonPricing) != 1){				
		var inpPriceAdditionalPerson = document.getElementById("am_additional_person");
//		alert(inpPriceAdditionalPerson.value);
		var inpManualPricing = document.getElementById("inp_manual_pricing");
		var selCateringType = document.getElementById("id_catering_type");
		// alert(inpPriceAdditionalPerson.value);
	
		var additionalPerson = (numAdult + numChildren) - chaletCapacity;
	//	alert(numAdult +" "+ numChildren +" "+ chaletCapacity);
		var additionalPersonPrice = additionalPersonCharge;
		additionalPersonTotalPrice = 0;
		var cateringType = Number(selCateringType.options[selCateringType.selectedIndex].value);
	
		//if ((additionalPerson > 0) && cateringType == 0) { this only apply when no children booking exists 
		if ((additionalPerson > 0) && cateringType == 0 && numChildren == 0) {
			//re- calculate adult price
			adultPrice =  Number((amBrochurePrice * (numAdult - additionalPerson)).toFixed(2));
			
			additionalPersonTotalPrice = Number((additionalPersonPrice * additionalPerson)
					.toFixed(2));
			document.getElementById("am_additional_person_label1").style.display = '';
			document.getElementById("am_additional_person_label2").style.display = '';
			document.getElementById("am_catering_adult_nmbr1").style.display = '';
			document.getElementById("am_catering_adult_nmbr2").style.display = '';
			//alert(numAdult+" "+additionalPerson);
			document.getElementById("am_catering_adult_nmbr1").innerHTML = "&nbsp;"
					+ (numAdult - additionalPerson);
			document.getElementById("am_catering_adult_nmbr2").innerHTML = additionalPerson 
					+ " @ "
					+ dispPrefix
					+ additionalPersonPrice.toFixed(2) + " each";
			
			document.getElementById("am_catering_adult_nmbr1_email_text").value = 
			(numAdult - additionalPerson)
			+' @ '
			+ currencySymbol
			+ ' '
			+ Number(amBrochurePrice).toFixed(2);
			
			document.getElementById("am_catering_adult_nmbr2_email_text").value = 
				additionalPerson 
				+ " @ "
				+ dispPrefix
				+ additionalPersonPrice.toFixed(2);
			// clean children price if there was any items
			document.getElementById("am_additional_person_label_child").style.display ='none';
			document.getElementById("am_catering_child_price_label").style.display = 'none';
			document.getElementById("am_catering_child_nmbr1_email_text").value = '';
			document.getElementById("am_catering_child_nmbr1").style.display = 'none';
			document.getElementById("am_catering_child_nmbr2").style.display = 'none';
			document.getElementById("am_catering_child_nmbr2_email_text").value = '';
		} else if (((additionalPerson > 0) && cateringType == 0 && numChildren > 0)){
	//		alert('go here');
			if (numChildren >= additionalPerson){ //addtional Person will all be children
				//calculate addtional children's price
				additionalPersonTotalPrice = Number((additionalPersonCharge * additionalPerson).toFixed(2)); 
				numChildrenNormalPrice = numChildren - additionalPerson; //number of children apply normal price
				
				//re calculate normal adult and child price 
				adultPrice =  Number((amBrochurePrice * numAdult).toFixed(2));
				childPrice =  Number((amBrochurePrice * amChildDiscount * numChildrenNormalPrice).toFixed(2));
				
				//display normal adult price 
				document.getElementById("am_catering_adult_price").value = dispPrefix + (numAdult*amBrochurePrice).toFixed(2);
				//display normal children price
				document.getElementById("am_catering_child_nmbr1").style.display ='';
				document.getElementById("am_catering_child_nmbr1").innerHTML = "&nbsp;"	+ numChildrenNormalPrice;
			
				document.getElementById("am_catering_child_price").value = dispPrefix
				+ (numChildrenNormalPrice*amChildDiscount*amBrochurePrice).toFixed(2);
				
				document.getElementById("am_catering_child_nmbr1_email_text").value = numChildrenNormalPrice + " @ " + currencySymbol + " " + Number(amBrochurePrice * amChildDiscount).toFixed(2);
				//hide adult addtional price section
				document.getElementById("am_additional_person_label1").style.display ='none';
				// hide child normal price 
				if(numChildrenNormalPrice == 0){
					document.getElementById("am_catering_child_price_label").style.display ='none';
					document.getElementById("am_catering_child_nmbr1_email_text").value = '';
					document.getElementById("am_catering_child_nmbr1").style.display = 'none';
				}
				
				//display discount children price and red symbol
				document.getElementById("am_additional_person_label_child").style.display ='';
				document.getElementById("am_additional_person_label2").style.display = '';
				document.getElementById("am_catering_child_nmbr2").style.display = '';
				if(numChildrenNormalPrice == 0){
					document.getElementById("am_catering_child_nmbr2").innerHTML = 
						+ additionalPerson
						+ " @ "
						+ dispPrefix
						+ additionalPersonCharge.toFixed(2) + " each";
					document.getElementById("am_catering_child_nmbr2_email_text").value = additionalPerson + " @ " + dispPrefix + additionalPersonCharge.toFixed(2);
				} else {
					document.getElementById("am_catering_child_nmbr2").innerHTML = 
						"<br />" 
						+ additionalPerson
						+ " @ "
						+ dispPrefix
						+ additionalPersonCharge.toFixed(2) + " each";
					document.getElementById("am_catering_child_nmbr2_email_text").value = additionalPerson + " @ " + dispPrefix + additionalPersonCharge.toFixed(2);
				}
			} else if (numChildren < additionalPerson){ //addtional Person will all be child(s) and adult(s)
				//all children should apply discount children price
				//display children price
				document.getElementById("am_additional_person_label_child").style.display ='';
				document.getElementById("am_catering_child_price_label").style.display = '';
				document.getElementById("am_catering_child_nmbr1").style.display = '';
				document.getElementById("am_catering_child_nmbr2").style.display = '';
				
				//empty children price
				document.getElementById("am_catering_child_price").value = dispPrefix + "0.00";
				document.getElementById("am_catering_child_nmbr1").innerHTML = "0";
				// hide child normal price 
				document.getElementById("am_catering_child_price_label").style.display ='none';
				document.getElementById("am_catering_child_nmbr1_email_text").value = '';
				document.getElementById("am_catering_child_nmbr1").style.display = 'none';
				additionalPersonTotalPrice = (numChildren * additionalPersonCharge).toFixed(2);
				document.getElementById("am_additional_person_label_child").style.display ='';
				document.getElementById("am_catering_child_nmbr2").innerHTML = numChildren
					+ " @ "
					+ dispPrefix
					+ additionalPersonCharge.toFixed(2) + " each";
				document.getElementById("am_catering_child_nmbr2_email_text").value = additionalPerson + " @ " + dispPrefix + additionalPersonCharge.toFixed(2);
				//calculate addtional price = additional adult price + addtional child price
				additionalPersonTotalPrice = parseFloat(additionalPersonTotalPrice) + parseFloat((additionalPerson - numChildren) * additionalPersonCharge.toFixed(2));
	//			alert(additionalPersonTotalPrice);
				//reveal adult price panel
				document.getElementById("am_additional_person_label1").style.display = '';
				document.getElementById("am_additional_person_label2").style.display = '';//alert('come here');
				document.getElementById("am_catering_adult_nmbr1").style.display = '';
				document.getElementById("am_catering_adult_nmbr1").innerHTML = "&nbsp;"
					+ (numAdult - (additionalPerson - numChildren));
				document.getElementById("am_catering_adult_nmbr2").style.display = '';
				//display normal adult price 
				document.getElementById("am_catering_adult_price").value = dispPrefix + ((numAdult - (additionalPerson - numChildren))*amBrochurePrice).toFixed(2);
				//re-calculate normal adult price
				adultPrice =  Number(((numAdult - (additionalPerson - numChildren))*amBrochurePrice).toFixed(2));
				childPrice = 0;
				document.getElementById("am_additional_person_label1").style.display ='';
				//display addtional adult price
				document.getElementById("am_catering_adult_nmbr2").innerHTML = (additionalPerson - numChildren)
					+ " @ "
					+ dispPrefix
					+ additionalPersonPrice.toFixed(2) + " each";
				
				document.getElementById("am_catering_adult_nmbr2_email_text").value = 
					additionalPerson 
					+ " @ "
					+ dispPrefix
					+ additionalPersonPrice.toFixed(2);
				//calculate addtional children's price + addtional adult price 
	//			alert(additionalPerson - numChildren);
	//			alert(additionalPerson - (additionalPerson - numChildren));
				//additionalPersonTotalPrice = (additionalPersonCharge * (additionalPerson - numChildren) + (additionalPerson - (additionalPerson - numChildren))*amBrochurePrice )).toFixed(2);
				//alert(additionalPersonTotalPrice);
			}
		} else {//no additional people
			document.getElementById("am_additional_person_label1").style.display = 'none';
			document.getElementById("am_additional_person_label2").style.display = 'none';
			document.getElementById("am_catering_adult_nmbr1").style.display = 'none';
			document.getElementById("am_catering_adult_nmbr2").style.display = 'none';
			document.getElementById("am_catering_child_nmbr1").style.display = 'none';
			document.getElementById("am_catering_child_nmbr2").style.display = 'none';
			document.getElementById("am_catering_child_nmbr2_email_text").value = '';
			document.getElementById("am_additional_person_label_child").style.display ='none';
			document.getElementById("am_additional_person_label1").style.display ='none';
			
			//email text
			document.getElementById("am_catering_adult_nmbr1_email_text").value = 
				numAdult
				+' @ '
				+ currencySymbol
				+ ' '
				+ Number(amBrochurePrice).toFixed(2);
			//empty additionall adults
			document.getElementById("am_catering_adult_nmbr2_email_text").value = "";
			
			document.getElementById("am_catering_child_nmbr1_email_text").value = 
				numChildren + " @ " + currencySymbol + " " + Number(amBrochurePrice * amChildDiscount).toFixed(2);
			document.getElementById("am_catering_child_nmbr2_email_text").value = "";
		}
	
		inpPriceAdditionalPerson.value = dispPrefix + additionalPersonTotalPrice.toFixed(2);
	// inpPriceAdditionalPerson.value = additionalPersonTotalPrice;
	}
	changeGuestTotal();
}

/*
 * function to change the guest totals 
 */
function changeGuestTotal() {
	// Check if there are any discounts
	var discount = 0;
	if (fullyCatered) {
		if (promoFixedDiscount > 0) {
			discount = 0 - promoFixedDiscount;
			document.getElementById("am_promo_discount").value = dispPrefix
					+ discount.toFixed(2);
		} else if (promoPercentDiscount > 0) {
			discount = 0 - (subTotalPrice * promoPercentDiscount);
			document.getElementById("am_promo_discount").value = dispPrefix
					+ discount.toFixed(2);
		}
	}
	
//	alert('subTotalPrice ' + subTotalPrice);
//	alert('discount ' + discount);
//	alert('emptyBedTotalPrice ' + emptyBedTotalPrice);
//	alert('additionalPersonTotalPrice ' + additionalPersonTotalPrice);
//	alert('adultPrice ' + adultPrice);
//	alert('childPrice ' + childPrice);
//	alert('infantPrice ' + infantPrice);
	subTotalPrice = adultPrice + childPrice + infantPrice;
	guestTotalPrice = subTotalPrice + discount + emptyBedTotalPrice
			+ additionalPersonTotalPrice;
	// alert(guestTotalPrice +" "+ subTotalPrice +" "+ discount +" "+
	// emptyBedTotalPrice +" "+ additionalPersonTotalPrice);
	document.getElementById("am_catering_guest_total").value = dispPrefix
			+ guestTotalPrice.toFixed(2);
	// document.getElementById("tx_summary_accom_total_price").value =
	// dispPrefix+guestTotalPrice.toFixed(2);

	updateGrandTotal();
}

/*
 * adjusts the html to add/remove table rows that correspond to the number of adults selected
 */
/*
 * function adjustNumAdultRows() { var theTableBody =
 * document.getElementById('groupDetailsTable').tBodies[0];
 * 
 * if ( numAdult > numAdultRows ) { for ( var i=numAdultRows; i<numAdult; i++) {
 * newRow = document.createElement('tr'); //newRow.className = "stdRow";
 *  // Add the Label cell var y1 = document.createElement('td'); //y1.innerHTML = "<li style=\"color:#CC0000;\"><strong>Adult
 * "+(numAdultRows+1)+" : </strong></li>"; y1.innerHTML = "<strong>Adult
 * "+(numAdultRows+1)+" : </strong>"; y1.align = "right";
 *  // Add the Firstname field cell var y2 = document.createElement('td');
 * y2.align = "center"; var input2 = createInputField(
 * "tx_firstname_adult["+(numAdultRows+1)+"]", "", "20", "50" );
 *  // Add the Firstname field cell var y3 = document.createElement('td');
 * y3.align = "center"; var input3 = createInputField(
 * "tx_surname_adult["+(numAdultRows+1)+"]", "", "20", "50" );
 *  // Add the Age field cell var y4 = document.createElement('td'); y4.align =
 * "center";
 *  // Add the Special Requests field cell var y5 =
 * document.createElement('td'); y5.align = "center"; var input5 =
 * createInputField( "tx_special_reqs_adult["+(numAdultRows+1)+"]", "", "30",
 * "300" );
 *  // Add the ID hidden field var input6 = createHiddenInputField(
 * "id_workflow_booking_party_adult["+(numAdultRows+1)+"]", "" );
 * 
 * if (guestAdult[i+1] != null && guestAdult[i+1] != "") { input2.value =
 * guestAdult[i+1][0]; input3.value = guestAdult[i+1][1]; input5.value =
 * guestAdult[i+1][2]; input6.value = guestAdult[i+1][3]; }
 * 
 * y2.appendChild(input2); y3.appendChild(input3); y5.appendChild(input5);
 * y5.appendChild(input6);
 * 
 * newRow.appendChild(y1); newRow.appendChild(y2); newRow.appendChild(y3);
 * newRow.appendChild(y4); newRow.appendChild(y5);
 * 
 * if ( numChildren+numInfants > 0 && !preFill ) { //if (preFill) //{ //
 * theTableBody.appendChild(newRow); //} else { theTableBody.insertBefore(
 * newRow, theTableBody.rows[i+1] ); //} } else {
 * theTableBody.appendChild(newRow); }
 * 
 * numAdultRows++; } }
 * 
 * if ( numAdult < numAdultRows ) { for ( var i=numAdultRows; i>numAdult; i--) {
 * if (guestAdult[i] == null || guestAdult[i] == undefined) { guestAdult[i] =
 * new Array(); } guestAdult[i][0] =
 * document.getElementById("tx_firstname_adult["+i+"]").value; // firstname
 * guestAdult[i][1] = document.getElementById("tx_surname_adult["+i+"]").value; //
 * surname guestAdult[i][2] =
 * document.getElementById("tx_special_reqs_adult["+i+"]").value; // special
 * requirements guestAdult[i][3] =
 * document.getElementById("id_workflow_booking_party_adult["+i+"]").value; //
 * id
 * 
 * var row = theTableBody.rows[i]; theTableBody.removeChild( row );
 * numAdultRows--; } } }
 */

/*
 * adjusts the html to add/remove table rows that correspond to the number of
 * children selected
 */
function adjustNumChildRows() {
	var theTableBody = document.getElementById('groupDetailsTable').tBodies[0];
	var ptr = numChildrenRows + 1;

	if (numChildren > numChildrenRows) {
		for ( var i = numChildrenRows + numAdultRows; i < numChildren
				+ numAdult; i++, ptr++) {
			newRow = document.createElement('tr');
			// newRow.className = "stdRow";

			// Add the Label cell
			var y1 = document.createElement('td');
			// y1.innerHTML = "<li style=\"color:#CC0000;\"><strong>Child
			// "+(numChildrenRows+1)+" : </strong></li>";
			y1.innerHTML = "<strong>Child " + (numChildrenRows + 1)
					+ " : </strong>";
			y1.align = "right";

			// Add the Firstname field cell
			var y2 = document.createElement('td');
			y2.align = "center";
			var input2 = createInputField("tx_firstname_child["
					+ (numChildrenRows + 1) + "]", "", "20", "50");

			// Add the Firstname field cell
			var y3 = document.createElement('td');
			y3.align = "center";
			var input3 = createInputField("tx_surname_child["
					+ (numChildrenRows + 1) + "]", "", "20", "50");

			// Add the Age field cell
			var y4 = document.createElement('td');
			y4.align = "center";
			var input4 = createAgeSelectField("tx_age_child["
					+ (numChildrenRows + 1) + "]", [ "-", "3", "4", "5", "6",
					"7", "8", "9", "10", "11", "12" ], [ -1, 3, 4, 5, 6, 7, 8,
					9, 10, 11, 12 ]);

			// Add the Special Requests field cell
			var y5 = document.createElement('td');
			y5.align = "center";
			var input5 = createInputField("tx_special_reqs_child["
					+ (numChildrenRows + 1) + "]", "", "30", "300");

			// Add the ID hidden field
			var input6 = createHiddenInputField(
					"id_workflow_booking_party_child[" + (numChildrenRows + 1)
							+ "]", "");

			if (guestChild[ptr] != null && guestChild[ptr] != "") {
				input2.value = guestChild[ptr][0];
				input3.value = guestChild[ptr][1];
				// window.alert(parseInt(guestChild[ptr][2])-2);
				if ((parseInt(guestChild[ptr][2]) - 2) > -1) {
					input4.selectedIndex = parseInt(guestChild[ptr][2]) - 2; // -2
																				// adjusts
																				// for
																				// the
																				// infant
																				// upper
																				// age
																				// limit
				}
				input5.value = guestChild[ptr][3];
				input6.value = guestChild[ptr][4];
			}

			y2.appendChild(input2);
			y3.appendChild(input3);
			y4.appendChild(input4);
			y5.appendChild(input5);
			y5.appendChild(input6);

			newRow.appendChild(y1);
			newRow.appendChild(y2);
			newRow.appendChild(y3);
			newRow.appendChild(y4);
			newRow.appendChild(y5);

			if (numInfants > 0) {
				if (preFill) {
					theTableBody.appendChild(newRow);
				} else {
					theTableBody.insertBefore(newRow, theTableBody.rows[i + 1]);
				}
			} else {
				theTableBody.appendChild(newRow);
			}

			numChildrenRows++;
		}
		numChildrenRows = numChildren;
	}

	if (numChildren < numChildrenRows) {
		--ptr;
		for ( var i = numChildrenRows + numAdultRows; i > numChildren
				+ numAdult; i--, ptr--) {
			if (guestChild[ptr] == null || guestChild[ptr] == undefined) {
				guestChild[ptr] = new Array();
			}
			guestChild[ptr][0] = document.getElementById("tx_firstname_child["
					+ ptr + "]").value; // firstname
			guestChild[ptr][1] = document.getElementById("tx_surname_child["
					+ ptr + "]").value; // surname
			guestChild[ptr][2] = document.getElementById("tx_age_child[" + ptr
					+ "]").options[document.getElementById("tx_age_child["
					+ ptr + "]").selectedIndex].value; // age
			guestChild[ptr][3] = document
					.getElementById("tx_special_reqs_child[" + ptr + "]").value; // special
																					// requirements
			guestChild[ptr][4] = document
					.getElementById("id_workflow_booking_party_child[" + ptr
							+ "]").value; // id

			var row = theTableBody.rows[i];
			theTableBody.removeChild(row);
			numChildrenRows--;
		}
	}
}

/*
 * adjusts the html to add/remove table rows that correspond to the number of infants selected
 */
function adjustNumInfantRows() {
	var theTableBody = document.getElementById('groupDetailsTable').tBodies[0];
	var ptr = numInfantsRows + 1;

	if (numInfants > numInfantsRows) {
		for ( var i = numInfantsRows + numChildrenRows + numAdultRows; i < numInfants
				+ numChildren + numAdult; i++, ptr++) {
			newRow = document.createElement('tr');
			// newRow.className = "stdRow";

			// Add the Label cell
			var y1 = document.createElement('td');
			// y1.innerHTML = "<li style=\"color:#CC0000;\"><strong>Infant
			// "+(numInfantsRows+1)+" : </strong></li>";
			y1.innerHTML = "<strong>Infant " + (numInfantsRows + 1)
					+ " : </strong>";
			y1.align = "right";

			// Add the Firstname field cell
			var y2 = document.createElement('td');
			y2.align = "center";
			var input2 = createInputField("tx_firstname_infant["
					+ (numInfantsRows + 1) + "]", "", "20", "50");

			// Add the Firstname field cell
			var y3 = document.createElement('td');
			y3.align = "center";
			var input3 = createInputField("tx_surname_infant["
					+ (numInfantsRows + 1) + "]", "", "20", "50");

			// Add the Age field cell
			var y4 = document.createElement('td');
			y4.align = "center";
			var input4 = createAgeSelectField("tx_age_infant["
					+ (numInfantsRows + 1) + "]", [ "-", "<1", "1", "2" ], [
					-1, 0, 1, 2 ]);

			// Add the Special Requests field cell
			var y5 = document.createElement('td');
			y5.align = "center";
			var input5 = createInputField("tx_special_reqs_infant["
					+ (numInfantsRows + 1) + "]", "", "30", "300");

			// Add the ID hidden field
			var input6 = createHiddenInputField(
					"id_workflow_booking_party_infant[" + (numChildrenRows + 1)
							+ "]", "");

			if (guestInfant[ptr] != null && guestInfant[ptr] != "") {
				input2.value = guestInfant[ptr][0];
				input3.value = guestInfant[ptr][1];
				// window.alert(guestInfant[ptr][2]);
				input4.selectedIndex = parseInt(guestInfant[ptr][2]) + 1;
				input5.value = guestInfant[ptr][3];
				input6.value = guestInfant[ptr][4];
			}

			y2.appendChild(input2);
			y3.appendChild(input3);
			y4.appendChild(input4);
			y5.appendChild(input5);
			y5.appendChild(input6);

			newRow.appendChild(y1);
			newRow.appendChild(y2);
			newRow.appendChild(y3);
			newRow.appendChild(y4);
			newRow.appendChild(y5);

			theTableBody.appendChild(newRow);

			numInfantsRows++;
		}
		numInfantsRows = numInfants;
	}

	if (numInfants < numInfantsRows) {
		--ptr;
		for ( var i = numInfantsRows + numChildrenRows + numAdultRows; i > numInfants
				+ numChildren + numAdult; i--, ptr--) {
			if (guestInfant[ptr] == null || guestInfant[ptr] == undefined) {
				guestInfant[ptr] = new Array();
			}
			guestInfant[ptr][0] = document
					.getElementById("tx_firstname_infant[" + ptr + "]").value; // firstname
			guestInfant[ptr][1] = document.getElementById("tx_surname_infant["
					+ ptr + "]").value; // surname
			guestInfant[ptr][2] = document.getElementById("tx_age_infant["
					+ ptr + "]").options[document
					.getElementById("tx_age_infant[" + ptr + "]").selectedIndex].value; // age
			guestInfant[ptr][3] = document
					.getElementById("tx_special_reqs_infant[" + ptr + "]").value; // special
																					// requirements
			guestInfant[ptr][4] = document
					.getElementById("id_workflow_booking_party_infant[" + ptr
							+ "]").value; // id

			var row = theTableBody.rows[i];
			theTableBody.removeChild(row);
			numInfantsRows--;
		}
	}
}

/*
 * function to create an input field with the passed properties
 */
function createInputField(idName, value, size, maxlen) {
	var input = document.createElement('input');
	input.id = idName;
	input.name = idName;
	input.type = "text";
	input.value = value;
	input.size = size;
	input.maxLength = maxlen;

	return input;
}

/*
 * function to create a hidden input field
 */
function createHiddenInputField(idName, value) {
	var input = document.createElement('input');
	input.id = idName;
	input.name = idName;
	input.type = "hidden";
	input.value = value;

	return input;
}

/*
 * function to create an age selector with the passed number of age options/values
 */
function createAgeSelectField(idName, labels, values) {
	var numAges = labels.length;
	var input = document.createElement('select');
	input.id = idName;
	input.name = idName;
	input.length = 0;
	input.style.textAlign = "center";

	for ( var i = 0; i < numAges; i++) {
		input.options[i] = new Option();
		input.options[i].text = labels[i];
		input.options[i].value = values[i];
	}
	input.selectedIndex = 0;

	return input;
}

/*
 * function to change the catering select options
 */
function changeCateringSelectOptions(idName, qty) {
	var sel = document.getElementById(idName);
	// var selIndex = sel.selectedIndex;
	// window.alert(selIndex);
	sel.length = 0;
	for ( var i = 0; i <= qty; i++) {
		sel.options[i] = new Option();
		sel.options[i].text = i;
		sel.options[i].value = i;
	}
	sel.selectedIndex = qty;
}

/*
 * function to show/hide the part catered panel
 */
function adjustPartCatered() {
	document.getElementById("part_catered_child_row").style.display = (numChildren == 0) ? "none"
			: rowDisplay;
	changeCatering();
}

/*
 * function to handle the changes to the catering options and update the field views
 */
function changeCatering() {
	// Do Adults first
	adultBreakfastCateringPrice = numAdult
			* document.getElementById("am_adult_breakfast").value
			* amBreakfastCatering;
	adultEveCateringPrice = numAdult
			* document.getElementById("am_adult_evemeals").value
			* amAdultEveCatering;
	adultCateringPrice = adultBreakfastCateringPrice + adultEveCateringPrice;

	// Only do Children if there are any
	if (numChildren > 0) {
		childBreakfastCateringPrice = numChildren
				* document.getElementById("am_child_breakfast").value
				* amBreakfastCatering;
		childEveCateringPrice = numChildren
				* document.getElementById("am_child_evemeals").value
				* amChildEveCatering;
		childCateringPrice = childBreakfastCateringPrice
				+ childEveCateringPrice;
	} else {
		childBreakfastCateringPrice = 0;
		childEveCateringPrice = 0;
		childCateringPrice = 0;
	}

	cateringTotalPrice = adultBreakfastCateringPrice + adultEveCateringPrice
			+ childBreakfastCateringPrice + childEveCateringPrice;

	// Update display fields
	document.getElementById("am_adult_evemeals_price").value = dispPrefix
			+ adultCateringPrice.toFixed(2);
	document.getElementById("am_child_evemeals_price").value = dispPrefix
			+ childCateringPrice.toFixed(2);

	document.getElementById("tx_total_meal_price").value = dispPrefix
			+ cateringTotalPrice.toFixed(2);
	document.getElementById("tx_summary_meals_total_price").value = dispPrefix
			+ cateringTotalPrice.toFixed(2);

	updateGrandTotal();
}

/*
 * called when the user checks/uncheck an extras checkbox
 */
function changeExtras(id) {
	if (extrasIds.length > 0) {
		var checkBox = document.getElementById("id_extra[" + id + "]");
		var charge = checkBox.checked ? parseFloat(document
				.getElementById("am_extra[" + id + "]").value) : 0;
		document.getElementById("am_extra_price[" + id + "]").value = dispPrefix
				+ charge.toFixed(2);

		totalExtras();
	}
}

/*
 * handles the totaling and displaying of the extras totals
 */
function totalExtras() {
	extrasTotalPrice = 0;
	var numIds = extrasIds.length;

	for ( var i = 0; i < numIds; i++) {
		extrasTotalPrice += (document.getElementById("id_extra[" + extrasIds[i]
				+ "]").checked) ? parseFloat(document
				.getElementById("am_extra[" + extrasIds[i] + "]").value) : 0;
	}

	document.getElementById("tx_total_extras_price").value = dispPrefix
			+ extrasTotalPrice.toFixed(2);
	document.getElementById("tx_summary_extras_total_price").value = dispPrefix
			+ extrasTotalPrice.toFixed(2);

	updateGrandTotal();
}

function checkPriceAdjust(inp_am_price_adjust) {
	if (isNaN(parseFloat(inp_am_price_adjust.value))) {
		inp_am_price_adjust.value = "0.00";
	}

	updateGrandTotal();
}

function updateAdjustmentsTotalPrice() {
	adjustmentsTotalPrice = (parseFloat(document
			.getElementById("am_price_adjust_1").value)
			+ parseFloat(document.getElementById("am_price_adjust_2").value)
			+ parseFloat(document.getElementById("am_price_adjust_3").value)
			+ parseFloat(document.getElementById("am_price_adjust_4").value) + parseFloat(document
			.getElementById("am_price_adjust_5").value))

	tx_adjustmentsTotalPrice = parseFloat(adjustmentsTotalPrice).toFixed(2);
	document.getElementById("am_price_adjust_total").value = tx_adjustmentsTotalPrice;
	document.getElementById("tx_summary_adjustments_total_price").value = tx_adjustmentsTotalPrice;
}

/*
 * updates the grand total and balance
 */
function updateGrandTotal() {
	if ((numAdult + numChildren) > chaletMaxCapacity) {
		window.alert("Chalet capacity exceeded");
		//clean every thing.
		document.getElementById("am_catering_adult").selectedIndex = 0;
		document.getElementById("am_catering_num_child").selectedIndex = 0;
		document.getElementById("am_catering_num_infant").selectedIndex = 0;
		document.getElementById("am_catering_child_nmbr1").value = 0;
		document.getElementById("am_catering_adult_nmbr1").value = 0;
		document.getElementById("am_additional_person_label1").style.display = 'none';
		document.getElementById("am_additional_person_label2").style.display = 'none';
		document.getElementById("am_catering_adult_nmbr1").style.display = 'none';
		document.getElementById("am_catering_adult_nmbr2").style.display = 'none';
		document.getElementById("am_catering_adult_nmbr1_email_text").value = '';
		document.getElementById("am_catering_adult_nmbr2_email_text").value = '';
		document.getElementById("am_catering_child_nmbr1").style.display = 'none';
		document.getElementById("am_catering_child_nmbr1_email_text").value = '';
		document.getElementById("am_catering_child_nmbr2").style.display = 'none';
		document.getElementById("am_catering_child_nmbr2_email_text").value = '';
		document.getElementById("am_additional_person_label_child").style.display ='none';
		document.getElementById("am_additional_person_label1").style.display ='none';
		document.getElementById("am_catering_adult_price").value = dispPrefix + " 0.00";
		document.getElementById("am_catering_child_price").value = dispPrefix + " 0.00";
		document.getElementById("am_catering_infant_price").value = dispPrefix + " 0.00";
		document.getElementById("am_catering_empty_bed").value = dispPrefix + " 0.00";
		document.getElementById("am_additional_person").value = dispPrefix + " 0.00";
		document.getElementById("am_catering_guest_total").value = dispPrefix + " 0.00";
	}
	if (admin_mode) {
		updateAdjustmentsTotalPrice();
	}

	//grandTotal = guestTotalPrice + (partCatered ? cateringTotalPrice : 0) + extrasTotalPrice;
	// grandTotal = guestTotalPrice + adjustmentsTotalPrice + (partCatered ?
	// cateringTotalPrice : 0);
	grandTotal = guestTotalPrice + adjustmentsTotalPrice
			+ (partCatered ? cateringTotalPrice : 0) + extrasTotalPrice;
	// document.getElementById("am_total_price").value =
	// dispPrefix+grandTotal.toFixed(2);

	// balanceDue = grandTotal - depositPaid;
	// document.getElementById("am_balance").value =
	// dispPrefix+balanceDue.toFixed(2);
}

function formValidation(form) {
	var valid = true;

	/*
	 * if ( document.getElementById("cancel_form").value != "cancel" ) {
	 * 
	 * for ( var i=1; i<=numAdult && valid; i++ ) { if (
	 * document.getElementById("tx_firstname_adult["+i+"]").value == "" ||
	 * document.getElementById("tx_surname_adult["+i+"]").value == "" ) { valid =
	 * false; } }
	 * 
	 * for ( var i=1; i<=numChildren && valid; i++ ) { if (
	 * document.getElementById("tx_firstname_child["+i+"]").value != "" ||
	 * document.getElementById("tx_surname_child["+i+"]").value != "" ) { valid =
	 * false; } }
	 * 
	 * for ( var i=1; i<=numInfants && valid; i++ ) { if (
	 * document.getElementById("tx_firstname_infant["+i+"]").value != "" ||
	 * document.getElementById("tx_surname_infant["+i+"]").value != "" ) { valid =
	 * false; } }
	 * 
	 * if (!valid) { window.alert("Please complete all Firstname and Surname
	 * fields\nand if there are any children or infants please select their
	 * age"); }
	 *  }
	 */

	return valid;
	// return false;
}
