function createRequestObject(){  	  
  var request_o; //dichiarazione della variabile che conterrą l'oggetto.  	  
  var browser = navigator.appName; //nome del browser  	  
  if(browser == "Microsoft Internet Explorer"){  			 
    request_o = new ActiveXObject("Microsoft.XMLHTTP");  // per IE	  
    }else{  		    
      request_o = new XMLHttpRequest(); // per altri browser 	  
    }  	
    return request_o; //ritorna l'oggetto 
    }

var http = createRequestObject();

function handleHttpResponse() {
  if (http.readyState == 4) {
    response = http.responseText;
	arrValori = response.split("||");
          document.getElementById("id_comune").options.length=1;       
          for(i=0;i<arrValori.length;i++)
          {
			  if (arrValori[i].split("|")[1] != '' && arrValori[i].split("|")[0] != '') {
         document.getElementById("id_comune").options[document.getElementById("id_comune").options.length] = new Option(arrValori[i].split("|")[1],arrValori[i].split("|")[0]);
			  }
          }
   }
}

function handleHttpResponse2() {
  if (http.readyState == 4) {
    response = http.responseText;
	arrValori = response.split("||");
          document.getElementById("id_provincia").options.length=1;       
          for(i=0;i<arrValori.length;i++)
          {
			  if (arrValori[i].split("|")[1] != '' && arrValori[i].split("|")[0] != '') {
         document.getElementById("id_provincia").options[document.getElementById("id_provincia").options.length] = new Option(arrValori[i].split("|")[1],arrValori[i].split("|")[0]);
			  }
          }
   }
}

function leggi_province_web() {
  var tipo = document.getElementById("id_tipo_ann").value;
  http.open('POST', '_lib/province_ajax_web.php', true);
  http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  http.onreadystatechange = handleHttpResponse2;
  http.send("tipo="+tipo);	
}

function leggi_ajax_web() {
  var selectValue = document.getElementById("id_provincia").value;
  var tipo = document.getElementById("id_tipo_ann").value;
  http.open('POST', '_lib/comuni_ajax_web.php', true);
  http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  http.onreadystatechange = handleHttpResponse;
  http.send("id_provincia="+selectValue+"&tipo="+tipo);
}
