function createXHR() {
	var obj;
	if (window.XMLHttpRequest) {	// Non Internet Explorer
		obj = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // Internet Explorer
		obj = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return obj;
}

obj=createXHR();

function onStateChange() {	// Cambiamento Stato
	if (obj.readyState == 4) { // Caricamento Avvenuto
		if (obj.status == 200) { // con successo
					
				
			var div = document.getElementById('risultato');
			if ( document.uniqueID ) {
				var select = document.createElement("<select id='district' name='district' onchange='invia2();'></select>");
			} else {
				var select = document.createElement("select");
			}
				select.setAttribute("name","district");
				select.setAttribute("id","district");	
				select.setAttribute("onchange","invia2();");				
				
				list = new Array();		
				list1 = new Array();		
				list2 = new Array();		
				string = obj.responseText;
				list = string.split(";");
				list1 = list[0].split("\n");				
				list2 = list[1].split("\n");				
				
				for ( i=0; i < list1.length; i++ ) {					
					op = new Option(list2[i], list1[i]);
					select.options[i] = op;		
				}
				document.getElementById("risultato").innerHTML="";
				div.appendChild(select);
				
		} else {
			document.getElementById("risultato").innerHTML="?";
			alert("Errore: "+obj.statusText);
		}
	}	
}

function invia() {
	
	inviaXHR(obj,"http://www.marcolecce.com/blog/Esempi/esempio2/xmlHttpRequest.php");
}

function inviaXHR(obj,url) {
	try {	
		obj.open("POST", url, true);	// Preparazione comunicazione
		document.getElementById("risultato").innerHTML="caricamento in corso..."; // caricamento in corso...
		obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		obj.onreadystatechange = onStateChange;
		country=escape(document.getElementById('country').value);	
		obj.send("country="+country);	// Trasferimento
		
	} catch (e) {
		document.getElementById("risultato").innerHTML="?";
		alert("Errore: "+e);
	}
	
}