// CALCULATE RATE V1.0
function calculate_rate(total,arrival_date,departure_date,number_of_nights,discount_id){
	
	
	$('input[type=submit]').attr("disabled", "true");	
	$("#booking_accomodation_form").bind("keypress", function(e) {	if (e.keyCode == 13) return false;	});
	
	$('#total_charges_label').html('<img src="img/preloader-s.gif" >').fadeIn(500);	
	
	
	var discount_id = new Array();
	discount_id = $('#discount').val();
	
	
	
	// GET REFID
	var refid = new Array();
	for (ctr=1; ctr<=total; ctr++){
		refid[ctr] = $('#refid'+ctr).val();
	} 
	
	
	// GET QTY
	var qty = new Array(); 
	for (ctr=1; ctr<=total; ctr++){
		//alert($('#qty'+ctr).val());
		var str = $('#qty'+ctr).val();
		if(str.length == 0 ){	qty[ctr] = parseInt(0);			}
		else				{	qty[ctr] = parseInt(str);		}
	} 
	// GET ADULT QTY
	var adult = new Array();
	for (ctr=1; ctr<=total; ctr++){
		var str = $('#adult'+ctr).val();
		if(str.length == 0 ){	adult[ctr] = parseInt(0);		}
		else				{	adult[ctr] = parseInt(str);		}
	} 		
	
	// GET CHILD QTY
	var child = new Array();
	for (ctr=1; ctr<=total; ctr++){
		var str = $('#child'+ctr).val();
		if(str.length == 0 ){	child[ctr] = parseInt(0);		}
		else				{	child[ctr] = parseInt(str);		}
	} 		
	
	// GET EXTRA PAX QTY
	var extrapax = new Array();
	for (ctr=1; ctr<=total; ctr++){
		var str = $('#extrapax'+ctr).val();
		if(str.length == 0 ){	extrapax[ctr] = parseInt(0);	}
		else				{	extrapax[ctr] = parseInt(str);	}
	} 		
	
	////////////////////////////////////////////////////////// OUTPUT
	/*$.get('plug/auto.calculator.php', {
		'id[]': id,
		'qty[]': qty,
		'adult[]': adult,
		'child[]': child,
		'extra_pax[]': extra_pax,
	},function(data){
		//alert(data);
		
	});*/
	////////////////////////////////////////////////////////// OUTPUT
	autocalculate=new XMLHttpRequest();
	autocalculate.onreadystatechange=function(){
		if (autocalculate.readyState==4 && autocalculate.status==200){
			var result = autocalculate.responseText;
			var t;
			var z;
			var subtotal = new String(result);
			var subtotalitems = subtotal.split(';'); // split on commas
			for (ctr=1; ctr<=total; ctr++){
				var subtotal = new String(result);
				var subtotalitems = subtotal.split(';'); // split on commas
				if(subtotalitems[ctr] > 0)
				{
					$("#price"+ctr).val(subtotalitems[ctr]);
					//$('#whole_charges').val(subtotalitems[ctr]);
					
		
				}
			}
			////alert(subtotalitems[ctr]));
			$('#total_charges_label').text(subtotalitems[ctr]).fadeIn(500);	
			$('#total_charges').val(subtotalitems[ctr]);
		
			//hide continue button
			var total_room = $('#total_charges').val();
			var total_room =parseInt(total_room);
			if(total_room > 0)
			{
			$('#btn_continue').fadeIn();
			}
			else
			{
			//$('#btn_continue').fadeOut();
			}
			
			
			$('input[type=submit]').removeAttr("disabled");
			$("#booking_accomodation_form").bind("keypress", function(e) {	if (e.keyCode == 13) return true;	});
		}
	}
	autocalculate.open("GET","plug/auto.calculator.php?refid="+refid+"&qty="+qty+"&adult="+adult+"&child="+child+"&extrapax="+extrapax+"&arrival_date="+arrival_date+"&departure_date="+departure_date+"&number_of_nights="+number_of_nights+"&discount_id="+discount_id,true);
	autocalculate.send();
	
}
	
