var running = null;

function onCalc(id, ok, response)
{
	if( ok ) {
		document.getElementById("estBox").value = response.costs + " €";	
	} 
	running = null;
}


function calc()
{
	var parentf = document.forms["convegni"];
	var din = parentf["DaGiorno"].value;
	var dout = parentf["AlGiorno"].value;
	var min = parentf["DaMese"].value -1;
	var mout = parentf["AlMese"].value -1;
	var yin = parentf["DaAnno"].value;
	var yout = parentf["AlAnno"].value;
	var dateIn = new Date(yin, min, din);
	var dateOut = new Date(yout, mout, dout);
	var diff = Math.ceil((dateOut.getTime()-dateIn.getTime())/ (60 * 60 * 24 * 1000));
	var rid = new String( parentf["TipoCamera"].options[ parentf["TipoCamera"].selectedIndex ].value );
	var oid = new String( parentf["selConv"].options[ parentf["selConv"].selectedIndex ].value );
	var sid = new String( parentf["Trattamento"].options[ parentf["Trattamento"].selectedIndex ].value );
	var d = new String(diff);
	var data = "rid="+rid+"&oid="+oid+"&sid="+sid+"&d="+d;
	if(diff <= 0) 
		document.getElementById("estBox").value = "-";
	if( (diff > 0) && (running == null) ) {
		running = new Question( "gc", "/php/costs.php", data, onCalc );
		running.ask();
	}
	
}


