

var t, hrs, mins, h, m;

function roundingoff(x) {
	x = Math.round(x); // Arrotondamento all'intero più vicino
	return(x);
}

function clearvalues(){ // cancella i contenuti della form

	document.data.weight_kgs.value=''
	document.data.hrs.value=''
	document.data.mins.value=''

}

function initialise() { // initialise the variables
	

	if (document.data.weight_kgs.value == '') {
		document.data.weight_kgs.value = 0;
	}
	
}

function compute() { // routine principale
	initialise();

	w_kgs = parseFloat(document.data.weight_kgs.value);

	if (document.data.bird[0].checked == true) {
	   if (w_kgs > 5.0) {
		    alert("Se hai un pollo di queste dimensioni, è meglio chiamare la Protezione Civile!"); } 
		t=roundingoff(45*w_kgs)+20;}
	   
	if (document.data.bird[1].checked == true) {
		  if (w_kgs > 10.0) {
		    alert("Se hai un tacchino di queste dimensioni, è meglio chiamare la Protezione Civile!"); } 
		if (w_kgs < 4.5) {
		    t=roundingoff(45*w_kgs)+20;}
		  if (w_kgs >= 4.5 || w_kgs == 6.5) {
		    t=roundingoff(40*w_kgs); }
		  if (w_kgs > 6.5) {
		    t=roundingoff(35*w_kgs); } 
		}
		
	if (document.data.bird[2].checked == true){
		if (w_kgs > 7.0) {
		    alert("Se hai un'oca di queste dimensioni, è meglio chiamare la Protezione Civile!");}  
		t=roundingoff(35*w_kgs);}
	if (document.data.bird[3].checked == true){
		if (w_kgs > 7.0) {
		    alert("Se hai un'anatra di queste dimensioni, è meglio chiamare la Protezione Civile!");}   
		t=roundingoff(45*w_kgs);}

	h=parseInt(t/60);
	m=parseInt(60*h);
	m=t-m;
	document.data.hrs.value=h;
	document.data.mins.value= parseInt(m);

}