function simula(num) {

	var kw = new Array;
	var gas = new Array;
	var txt = new Array;
	kw[2] = 5364;
	kw[3] = 8656;
	kw[4] = 11534;
	kw[5] = 11060;
	kw[6] = 12270;
	gas[2] = 902;
	gas[3] = 202;
	gas[4] = 1043;
	gas[5] = 1143;
	gas[6] = 830;
	txt[2] = "differenza 2008-2009";
	txt[3] = "differenza 2007-2009";
	txt[4] = "differenza 2006-2009";
	txt[5] = "differenza 2005-2009";
	txt[6] = "differenza 2004-2009";

	intervallo = document.game.anni.value;
	if (intervallo<2) {
		intervallo = 2;
	}
	if (intervallo>6) {
		intervallo = 6;
	}
	switch (num) {
		case 0:
			if (document.game.giorni.value!="") {
				ngiorni=parseInt(document.game.giorni.value);
				if (ngiorni<1 || isNaN(ngiorni)) {
					ngiorni = 1;
					document.game.giorni.value = "1";
				}
				if (ngiorni>365) {
					ngiorni = 365;
					document.game.giorni.value = "365";
				}
				document.game.kw.value = ngiorni*kw[intervallo];
				document.game.gas.value = ngiorni*gas[intervallo];
				tgiorni = "giorni";
				if (ngiorni==1) {
					tgiorni = "giorno";
				}
				document.getElementById("kwd").innerHTML = ngiorni+" "+tgiorni+" ("+txt[intervallo]+")";
				document.getElementById("gasd").innerHTML = ngiorni+" "+tgiorni+" ("+txt[intervallo]+")";
			}
			break;
		case 1:
			if (document.game.kw.value!="") {
				nkw=parseInt(document.game.kw.value);
				if (isNaN(nkw) || nkw<1) {
					nkw = kw[intervallo];
					document.game.kw.value = kw[intervallo];
				} else {
					if (nkw>kw[intervallo]*365) {
						nkw = kw[intervallo]*365;
						document.game.kw.value = kw[intervallo]*365;
					}
					ngiorni = Math.ceil(nkw/kw[intervallo]);
					ngas = ngiorni*gas[intervallo];
					document.game.giorni.value = ngiorni;
					document.game.gas.value = ngas;
					tgiorni = "giorni";
					if (ngiorni==1) {
						tgiorni = "giorno";
					}
					document.getElementById("kwd").innerHTML = ngiorni+" "+tgiorni+" ("+txt[intervallo]+")";
					document.getElementById("gasd").innerHTML = ngiorni+" "+tgiorni+" ("+txt[intervallo]+")";
				}
			}
			break;
		case 2:
			if (document.game.gas.value!="") {
				ngas=parseInt(document.game.gas.value);
				if (isNaN(ngas) || ngas<1) {
					ngas = gas[intervallo];
					document.game.gas.value = gas[intervallo];
				} else {
					if (ngas>gas[intervallo]*365) {
						ngas = gas[intervallo]*365;
						document.game.gas.value = gas[intervallo]*365;
					}
					ngiorni = Math.ceil(ngas/gas[intervallo]);
					nkw = ngiorni*kw[intervallo];
					document.game.giorni.value = ngiorni;
					document.game.kw.value = nkw;
					tgiorni = "giorni";
					if (ngiorni==1) {
						tgiorni = "giorno";
					}
					document.getElementById("kwd").innerHTML = ngiorni+" "+tgiorni+" ("+txt[intervallo]+")";
					document.getElementById("gasd").innerHTML = ngiorni+" "+tgiorni+" ("+txt[intervallo]+")";
				}
			}
			break;
	}

}
