function setSection(val,name,id) {
	if(val=='') {
		$('#tickets').hide();
		types = ['adult','senior','student','subscriber'];
		for (t in types) {
			$('#'+id+'-'+types[t]+'-amount').val(0);
		}
		$('#'+id+'-tickets-quantity').html('');
		$('#ticket-rows').html('');
		return;
	}
	
	section = val.substr(0,1);
	types = ['adult','senior','student','subscriber'];
	for (t in types) {
		$('#'+id+'-'+types[t]+'-amount').val(section_prices[section][types[t]]);
	}
	
	$('#tickets').show();
	
	if(val == 'A1' || val == 'A2' || val == 'A3' || val == 'A4') {
		max_tickets = 2;
	} else max_tickets = 8;
	
	// $('#tickets-max-quantity').html(max_tickets);
	$('#'+id+'-tickets-quantity').html('');
	for(i=1;i<=max_tickets;i++) {
		$('#'+id+'-tickets-quantity').append('<option value="'+i+'">'+i+'</option>');
	}
	setTicketRows($('#'+id+'-tickets-quantity').val(),name,id);
}

function setPrice(tag,id) {
	if(tag.value=='') {
		$(tag).next().html('');
		calculateTotal();
		return;
	}
	price = $('#'+id+'-'+tag.value+'-amount').val();
	$(tag).next().html('@ $'+price);
	calculateTotal();
}

function setTicketRows(num,name,id) {
	$('#ticket-rows').html('');
	for(i=1;i<=num;i++) {
		$('#ticket-rows').append('<li><select name="'+name+'-tickets[]" onChange="setPrice(this,\''+id+'\');"><option value="">Please choose</option><option value="adult">Adult</option><option value="senior">Senior</option><option value="student">Student</option><option value="subscriber">Subscriber</option></select> <span class="notes"></span></li>');
	}
	calculateTotal();
}

function calculateTotal() {
	var tickets = $('#ticket-rows :input');
	total = 0;
	for(var i=0; i<tickets.length; i++){
		amount=parseFloat($(tickets.get(i)).next().html().substr(3));
		if(isNaN(amount)) amount = 0;

		total += amount;
	}
	
	opt_fees = $(':input.payment-input');
	for(var i=0; i<opt_fees.length; i++){
		if(opt_fees.get(i).id == $('#payment-total').val()) continue;
		
		amount=parseFloat(opt_fees.get(i).value);
		if(isNaN(amount)) amount = 0;
		
		total += amount;
	}
	
	var fees = $(':input.fee-input');
	for(var i=0; i<fees.length; i++){
		qty = parseInt(fees.get(i).value);
		price = parseFloat($('#'+fees.get(i).id+'-fee').html());
		
		if(isNaN(qty)) qty = 0;
		
		total += qty*price;
	}
	
	$('#'+$('#payment-total').val()).val(total.toFixed(2));
}
