$(document).ready(
function(){
$("#alloggio,#camera,#trattamento,#numcam,#start-date,#end-date").bind("change keypress", recalc);
recalc();

function recalc(){
var startArr = $('#start-date').val().split('/');
var endArr = $('#end-date').val().split('/');
var startTime = new Date('20' + startArr[2],startArr[1],startArr[0]).getTime();
var endTime = new Date('20' + endArr[2],endArr[1],endArr[0]).getTime();
var daysBetween = (endTime - startTime) / 86400000;
var camera1 = $("#alloggio").val().split('-');
var camera2 = camera1[1];
var posti = camera1[2];
var pensione = $("#trattamento").val().split('-');
var trattamento = pensione[1]; 
var numcam = $("#numcam").val();
var ddd = daysBetween + 1 ;
//alert (camera2 + " + (" + posti + " * " + trattamento + ")) * " + ddd + " * " + numcam);
    // run the calc() method on each of the "total" fields 
    $("#grandTotal").calc( 
    // the equation to use for the calculation 
        "(camera * days * numcam + (posti * trattamento * days * numcam))", 
        // 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 
            camera: camera2,
		posti : posti,
	trattamento : trattamento,
	numcam : numcam,
	 
            // now we define the jQuery object which reads in the "price" from the table cell 
		days: daysBetween 
        }, 
        // 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(2); 
        }, 
        // once all calculations are completed, we execute the code below 
        function ($this){ 
            // now we get the sum() of all the values we just calculated 
            var sum = $this.sum(); 

            // now that we have the grand total, we must update the screen 
            $("#grandTotal").val( 
                // round the results to 2 digits 
                "EUR " + sum.toFixed(2) 
            ); 
            $("#notti").val( 
                // round the results to 2 digits 
                daysBetween 
            );         
	} 
    ); 
}
});
