// JavaScript Document
	function calcola() {
		var i = 1;
		var sommavoti = 0;
		var golfatti = 0;
		var assist = 0;
		var golsubiti = 0;
		var ammonizioni = 0;
		var espulsioni = 0;
		var rigoreno = 0;
		var rigoresi = 0;
		var totale = 0;
		
		while (i < 12) {
			sommavoti += parseFloat(document.getElementById("voto"+i).value);
			golfatti += parseInt(document.getElementById("golfatti"+i).value);
			assist += parseInt(document.getElementById("assist"+i).value);
			golsubiti += parseInt(document.getElementById("golsubiti"+i).value);
			if (document.getElementById("ammonito"+i).checked) {
				++ammonizioni;
			}
			if (document.getElementById("espulso"+i).checked) {
				++espulsioni;
			}
			rigoreno += parseInt(document.getElementById("rigore-"+i).value);
			rigoresi += parseInt(document.getElementById("rigore+"+i).value);

			++i;
		}
		
		totale  = sommavoti + golfatti*3 + assist + rigoresi*3 - golsubiti - ammonizioni/2 - espulsioni - rigoreno*3;
		if (document.getElementById("modulo").value == 4 | document.getElementById("modulo").value == 5) {
			var sommavotidif = 0;
			if (document.getElementById("modulo").value == 4) {
				sommavotidif = parseFloat(document.getElementById("voto2").value) + parseFloat(document.getElementById("voto3").value) + parseFloat(document.getElementById("voto4").value) + parseFloat(document.getElementById("voto5").value);
			} else {
				sommavotidif = parseFloat(document.getElementById("voto2").value) + parseFloat(document.getElementById("voto3").value) + parseFloat(document.getElementById("voto4").value) + parseFloat(document.getElementById("voto5").value) + parseFloat(document.getElementById("voto6").value);			
			}
			if  ( (sommavotidif / parseInt(document.getElementById("modulo").value) >= 6) & ((sommavotidif / parseInt(document.getElementById("modulo").value)) < 6.5) ) {
				totale += 1;
			} else if  ( (sommavotidif / parseInt(document.getElementById("modulo").value) >= 6.5) & ((sommavotidif / parseInt(document.getElementById("modulo").value)) < 7) ) {
				totale += 3;
			} else if  ( (sommavotidif / parseInt(document.getElementById("modulo").value) >= 7) ) {
				totale += 6;
			}			
			
		}
		
		document.getElementById("totpunt").value = totale;
		
		if (totale < 66) {
			document.getElementById("totgol").value = "0";
		} else if (totale <= 71.5) {
			document.getElementById("totgol").value = "1";
		} else if (totale <= 77.5) {
			document.getElementById("totgol").value = "2";
		} else if (totale <= 83.5) {
			document.getElementById("totgol").value = "3";
		} else if (totale <= 89.5) {
			document.getElementById("totgol").value = "4";
		} else if (totale <= 95.5) {
			document.getElementById("totgol").value = "5";
		} else if (totale <= 101.5) {
			document.getElementById("totgol").value = "6";
		} else {
			document.getElementById("totgol").value = "La fess d sord!";
		}

	}
	
	function cambiacoloreamm(i) { 
		if (document.getElementById("amm" + i).bgColor == '#e6e8f9') { //Begin IF 1
			document.getElementById("amm" + i).bgColor = "yellow";
		}
		else {
			if (document.getElementById("amm" + i).bgColor == "") { //Begin IF 2
				document.getElementById("amm" + i).bgColor = "yellow";
			}
			else {
				document.getElementById("amm" + i).bgColor = '#e6e8f9';			
			} //End IF 2
		} // End IF 1
		document.refresh;
	} //End function

	function cambiacoloreesp(i) { 
		if (document.getElementById("esp" + i).bgColor == '#e6e8f9') { //Begin IF 1
			document.getElementById("esp" + i).bgColor = "red";
		}
		else {
			if (document.getElementById("esp" + i).bgColor == "") { //Begin IF 2
				document.getElementById("esp" + i).bgColor = "red";
			}
			else {
				document.getElementById("esp" + i).bgColor = '#e6e8f9';			
			} //End IF 2
		} // End IF 1
		document.refresh;
	} //End function
