// bind the recalc function to the quantity fields


jQuery(document).ready(function($){
	$("[id^=f_Qty_]").bind("change", recalc);
	recalc();



});

	
function recalc(){
    // run the calc() method on each of the "total" fields
    jQuery("[id^=sub_total_]").calc(
        // the equation to use for the calculation
        "qty * price",
        // we now define the values for the variables defined in the equation above
        {
            // instead of using a static value, we use a jQuery object which grabs all the quantities
            qty: jQuery("[id^=f_Qty_]"),
            // now we define the jQuery object which reads in the "price" from the table cell
            price: jQuery("[id^=price_]")
        },
        // this function is execute after the calculation is completed, which allows us to
        // add formatting to our value
        function (s){
            // return the number as a dollar amount
            return "$" + s.toFixed(0);
        },
        // once all calculations are completed, we execute the code below
        function (jQuerythis){
            // now we get the sum() of all the values we just calculated
            var sum = jQuerythis.sum();

            // now that we have the grand total, we must update the screen
            jQuery("#grand_total").text(
                // round the results to 2 digits
                "$" + sum.toFixed(0)
            );
        }
    );
}

function getCrusieDetails(){
	jQuery("#ticket_container").load("gift_voucher_ajax.php", {f_CruiseType: jQuery("#f_CruiseType").val() }, function(){
	
		jQuery("[id^=f_Qty_]").bind("change", recalc);
		recalc();
	});
}
