// JavaScript Document
function caricaComuni(id_provincia){
//	alert("id comune caricato:" + id_provincia);
	var oXHR = new XMLHttpRequest();
	oXHR.open("get","includes/loadComuni.php?id_provincia=" + id_provincia,true);
	oXHR.setRequestHeader("Content-type","application/x-www-form-urlencoded");

	oXHR.send(null);
	oXHR.onreadystatechange = function(){
		if (oXHR.readyState == 4){					
			listaComuni =  oXHR.responseText;
			// aggiungo l'opzione seleziona...
			listaComuni = "\"\"#seleziona...|"+listaComuni;
			var selectBoxComuni = document.getElementById("comune");
			var arrayComuni = listaComuni.split("|");
			//alert("lista comuni " + listaComuni);
			emptySelect("comune");
			for (i=0;i<arrayComuni.length;i++){	
				var datiComune = arrayComuni[i].split("#");
				try {
					var idComune = datiComune[0];
					var nomeComune = datiComune[1];				
					 // doesn't work in Firefox
					selectBoxComuni.add(new Option(nomeComune,idComune ));
				} catch(ex) {
					//codice FireFox compatibile
					var elOptNew = document.createElement('option');
					elOptNew.value = datiComune[0];
					elOptNew.text = datiComune[1];
					selectBoxComuni.options.add(elOptNew);
				}
			}
		}
	}
}
/*###########################################################*/
function emptySelect(name){
	var selectBox = document.getElementById(name);		
	while(selectBox.length != 0 ){
		selectBox.remove(0);	
	}
}
