function assegnaXMLHttpRequest() {
	var
	XHR = null,
	browserUtente = navigator.userAgent.toUpperCase();
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
	XHR = new XMLHttpRequest();
	else if(
	window.ActiveXObject &&
	browserUtente.indexOf("MSIE 4") < 0
	) {
	if(browserUtente.indexOf("MSIE 5") < 0)
	XHR = new ActiveXObject("Msxml2.XMLHTTP");
	else
	XHR = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return XHR;
}
//-------------------------------------------------------------------------------------
function loadLocalita(valore){
	document.getElementById('cerca-localita').options.length=1;
	if (valore){
		var ajax = assegnaXMLHttpRequest();
		if(ajax) {
			ajax.open("post", "library/loadlocalita.php?id="+valore, true);
			ajax.setRequestHeader("content-type", "application/x-www-form-urlencoded");
			ajax.setRequestHeader("connection", "close");
			dati='';
			ajax.send(dati);
			ajax.onreadystatechange = function(){
				if(ajax.readyState == 4){
					var localita = Array(); 
					var localitaB = Array(); 
					var res=ajax.responseText;
					localita=ajax.responseText.split("|");
					
					for (i in localita) {

						localitaB=localita[i].split(";");

						newoption = document.createElement('option'); 
						newoption.setAttribute("value", localitaB[1]); 
						var optionName = document.createTextNode(localitaB[0]); 
						newoption.appendChild(optionName); 
						document.getElementById('cerca-localita').appendChild(newoption); 
					}
					document.getElementById('cerca-localita').options.length=document.getElementById('cerca-localita').options.length-1;				
				}
			}
		 }
	 }
	 return false;
}

