/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();


//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------


function caricaProvince(n){
		
		var select1=document.getElementById('regione'+n);
		var idregione= encodeURI(select1.options[select1.selectedIndex].value);
		
		// Set te random number to add to URL request
		nocache = Math.random();
		// Pass the login variables like URL variable
		//http.open('get', 'salva_doc.php?titolo='+titolo+'&testo='+testo+'&update='+update+'&sezione='+sezione+'&image='+imgnews+agg);
		//http.onreadystatechange = insertResponse;
		//http.send(null);
		
		var url = "dati_province.php";
		var params = 'idr='+idregione;
		http.open("POST", url, true);
		
		
		//Send the proper header information along with the request
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		//http.setRequestHeader("Content-type", "text/html; charset=UTF-8");
		http.setRequestHeader("Connection", "close");
		
		http.onreadystatechange = function() {//Call a function when the state changes.
			if(http.readyState == 4 && http.status == 200) {
				
				eval(http.responseText);
				
				var sez='<select name="province" id="province'+n+'" onchange="caricaCitta('+n+')">';
				sez+='<option></option>';
				var i;
				
				for(i=0;i<sect.length; i=i+2){
					sez+='<option value="'+sect[i]+'">'+URLDecode(sect[i+1])+'</option>';
				}
				
				sez+='</select>&nbsp;<span class="inputRichiesto">*</span>';
				
				document.getElementById('divprovince'+n).innerHTML = sez;
				
			}
		}
		http.send(params);


		
}


//---------------------------------------------------------------------------------------------------


//---------------------------------------------------------------------------------------------------


function caricaCitta(n){
		
		var select1=document.getElementById('province'+n);
		var siglaprov= encodeURI(select1.options[select1.selectedIndex].value);
		
		// Set te random number to add to URL request
		nocache = Math.random();
		// Pass the login variables like URL variable
		//http.open('get', 'salva_doc.php?titolo='+titolo+'&testo='+testo+'&update='+update+'&sezione='+sezione+'&image='+imgnews+agg);
		//http.onreadystatechange = insertResponse;
		//http.send(null);
		
		var url = "dati_citta.php";
		var params = 'prov='+siglaprov;
		http.open("POST", url, true);
		
		
		//Send the proper header information along with the request
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		//http.setRequestHeader("Content-type", "text/html; charset=UTF-8");
		http.setRequestHeader("Connection", "close");
		
		http.onreadystatechange = function() {//Call a function when the state changes.
			
			if(http.readyState == 4 && http.status == 200) {
				
				eval(http.responseText);
				
				
				var sez='<select name="citta" id="citta'+n+'">';
				sez+='<option></option>';
				var i;
				
				for(i=0;i<sect.length; i=i+2){
					sez+='<option value="'+sect[i]+'">'+URLDecode(sect[i+1])+'</option>';
				}
				
				sez+='</select>&nbsp;<span class="inputRichiesto">*</span>';
				
				document.getElementById('divcitta'+n).innerHTML = sez;
				
			}
		}
		http.send(params);


		
}


//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------


function caricaCodice(){
		
		
		var randomnumber=Math.floor(Math.random()*91);
		
		document.getElementById('securecode').src="code.php?key="+randomnumber;
		document.getElementById('codiceid').value=randomnumber;
		

		
}


//---------------------------------------------------------------------------------------------------


