//////////////////////////////////////////
// Seat selection page
//////////////////////////////////////////
/**
 * Update the total amount of the seat selection page base on selected tickets in the price grid.
 * This function is executed as page onLoad
 * This function required the following variable to work properly: 
 *      + selectedQuantityForSeatCatAndAudience_ 
 *      + unitPriceForSeatCatAndAudience_
 */
function updateTotalAmount() {
	var ticketPrice = 0;
	var totalAmount = 0;
	var quantity = 0;
	var elementNamePrefix = "SelectTypeTarif";
	for ( var i = 0; i < document.main_form.length; i++) {
		current = document.main_form.elements[i];
		if (current.name.substring(0, elementNamePrefix.length) == elementNamePrefix) {
			var priceHtmlId = current.name.substring(elementNamePrefix.length);
			var price = document.getElementById("InputTarif"+priceHtmlId);
			if (current.type == "select-one" || current.type == "text") {
				var q = parseInt(current.value);
				if (isNaN(q)) {
					current.value = 0;
					q = 0;
				}
				quantity += q;
				ticketPrice += q * parseFloat(price.value);
				
				// find the audience sub category id
				var seperate_of_asc_id = priceHtmlId.indexOf('_');
				var asc_id = parseFloat(priceHtmlId.substring(seperate_of_asc_id + 1));
				// find the audience sub category id fee
				//var asc_fee = document.getElementById("fee_For_AudienceSubCat_" + asc_id);
				//if (asc_fee) {
				//	bookingFee += asc_fee.value * q;
				//}
			}
		}
	}
	//total amount includes booking fee and ticket price
	totalAmount = ticketPrice;
	
	//if(document.getElementById("bookingFee")) {
	//	document.getElementById("bookingFee").innerHTML = (bookingFee.toFixed(2));
	//}
	document.getElementById("totalAmount").innerHTML = (totalAmount.toFixed(2)); //totalAmount.toFixed(2)
	var ticketsNb = document.getElementById("ticketsNb");
	if (ticketsNb != null) {
		var ticketStr = document.getElementById('ticketStr').value;
		var ticketsStr = document.getElementById('ticketsStr').value;
		if (quantity == 0) {
			document.getElementById("ticketsNb").innerHTML = ("-");
		} else if (quantity == 1) {
			document.getElementById("ticketsNb").innerHTML = (quantity + " " + ticketStr);
		} else {
			document.getElementById("ticketsNb").innerHTML = (quantity + " " + ticketsStr);
		}
	}
	return quantity;
}


