
function CreateXmlHttpReq3(handler){
      var xmlhttp = null;
      try
	 {
	 // Firefox, Opera 8.0+, Safari
	 xmlhttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
	 // Internet Explorer
	 try
	  {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e)
	  {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	 }
      xmlhttp.onreadystatechange = handler;
      return xmlhttp;
    }
	////////////////////////////////////////////////////////////////////////////////////////////////
	//			PROVINCIE E COMUNI //
	//Funzione Scelta provincie in base alla regione
	var myRequesta = null;
	function provincie(){
      if(myRequesta.readyState == 4 && myRequesta.status == 200){
        var er = document.getElementById("provincie") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequesta.responseText;
	    document.getElementById('attendi').className="attendih"
      }
    }
    function SelProvincie(reg,provincia,city){
      myRequesta = CreateXmlHttpReq3(provincie);
      myRequesta.open("GET",dir+"/ajax/provincie.php?reg="+escape(reg)+"&provincia="+escape(provincia)+"&city="+escape(city));
      myRequesta.send(null);
	  document.getElementById('attendi').className="attendiv"
    }
	//Funzione Scelta Comuni in base alla Provincia
	var myRequest = null;
	function comuni(){
      if(myRequest.readyState == 4 && myRequest.status == 200){
        var er = document.getElementById("comuni") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequest.responseText;
	    document.getElementById('attendi2').className="attendih"
      }
    }
    function SelComuni(val,city){
      myRequest = CreateXmlHttpReq3(comuni);
      myRequest.open("GET",dir+"/ajax/comuni.php?val="+escape(val)+"&city="+escape(city));
      myRequest.send(null);
	  document.getElementById('attendi2').className="attendiv"
    }
	/////////////////////////////////////////////////////////////////////////////
	
	///////////////////////////////////////////////////////////////////////////////
	//   		PUNTI D'INTERESE SETUP STRUTTURA 
	//Funzione per visualizzare i punti di interesse di una tipologia nel setup-struttura
	var myRequest = null;
	function punti(){
      if(myRequest.readyState == 4 && myRequest.status == 200){
        var er = document.getElementById("PuntiInteresse") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequest.responseText;
	  document.getElementById('attendi2').className="attendih"
      }
    }
    function ShowPoint(cat){
      myRequest = CreateXmlHttpReq3(punti);
	  document.getElementById('pointDetails').style.display='none'
	  document.getElementById('MappaPointInterest').style.display='none'
      myRequest.open("GET",dir+"/ajax/elenco_punti.php?cat="+escape(cat));
      myRequest.send(null);
	  document.getElementById('attendi2').className="attendiv"
    }
	
	//Funzione per visualizzare la distanza di un punto di interesse nel setup-struttura
	var myRequest = null;
	function distance(){
      if(myRequest.readyState == 4 && myRequest.status == 200){
        var er = document.getElementById("DistPuntiInteresse") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequest.responseText;
      }
    }
    function ShowDistance(point){
      myRequest = CreateXmlHttpReq3(distance);
      myRequest.open("GET",dir+"/ajax/distanza.php?point="+escape(point));
      myRequest.send(null);
    }
	
	//Funzione per visualizzare la posizione di un punto di interesse nel setup-struttura
	var myRequest2 = null;
	function position(){
      if(myRequest2.readyState == 4 && myRequest2.status == 200){
        var er = document.getElementById("PosPuntiInteresse") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequest2.responseText;
      }
    }
    function ShowPosition(point){
      myRequest2 = CreateXmlHttpReq3(position);
      myRequest2.open("GET",dir+"/ajax/posizione.php?point="+escape(point));
      myRequest2.send(null);
    }
	
	
	//Funzione per visualizzare i dettagli di un punto di interesse nel setup-struttura
	var myRequest3 = null;
	function details(){
      if(myRequest3.readyState == 4 && myRequest3.status == 200){
        var er = document.getElementById("Details") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequest3.responseText;
      }
    }
    function ShowDetails(point,cat){
      myRequest3 = CreateXmlHttpReq3(details);
	  document.getElementById('pointDetails').style.display='';
      myRequest3.open("GET",dir+"/ajax/details.php?cat="+escape(cat)+"&point="+escape(point));
      myRequest3.send(null);
    }
	//Funzione per visualizzare la mappa di un punto di interesse nel setup-struttura
	var myRequest4 = null;
	function MapPoint(){
      if(myRequest4.readyState == 4 && myRequest4.status == 200){
        var er = document.getElementById("MapPoint") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequest4.responseText;
	  document.getElementById('attendi').className="attendih"
      }
    }
    function ShowMappa(point){
	  document.getElementById('MappaPointInterest').style.display=''
      myRequest4 = CreateXmlHttpReq3(MapPoint);
      myRequest4.open("GET",dir+"/ajax/mappa.php?point="+escape(point));
      myRequest4.send(null);
	  document.getElementById('attendi').className="attendiv"
    }
	//Funzione di salvataggio dei punti di interesse nel setup-struttura
	var myRequest = null;
	function save_point(){
      if(myRequest.readyState == 4 && myRequest.status == 200){
        var er = document.getElementById("stato_punto") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequest.responseText;
	    ahahEvalJS("stato_punto");
      }
    }
    function salva_punto(){
	  var point=document.getElementById('point').value
	  var distance=document.getElementById('distance').value
	  var posizione=document.getElementById('posizione').value
      myRequest = CreateXmlHttpReq3(save_point);
      myRequest.open("POST",dir+"/ajax/salva_punto.php?point="+escape(point)+"&distance="+escape(distance)+"&posizione="+escape(posizione));
      myRequest.send(null);
    }
	
	function AddPunto()
	{
	  document.getElementById('point').value=''
	  document.getElementById('distance').value=''
	  document.getElementById('posizione').value=''
	  document.getElementById('salva').style.display='';
	  document.getElementById('reset').style.display='none';
	  document.getElementById('stato_punto').style.display='none';
	}
	//Funzione per visonare i punti d'interesse già inseriti nel setup-struttura
	var myRequestShow = null;
	function InsertPoint(){
      if(myRequestShow.readyState == 4 && myRequestShow.status == 200){
        var er = document.getElementById("puntiinseriti") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequestShow.responseText;
      }
    }
    function showInsertPoint(){
      myRequestShow = CreateXmlHttpReq3(InsertPoint);
      myRequestShow.open("GET",dir+"/ajax/pointsinseriti.php");
      myRequestShow.send(null);
    }
	
	/////////////////////////////////////////////////////////////////////////////////////
	
	
	//////////////////////////////////////////////////////////////////////////////////////
	// 			TIPOLOGIA STANZE SETUP STRUTTURA
	
	//Funzione per inserire nuove tipologie di stanze nel setup-struttura
	var myRequest = null;
	function tipologie(){
      if(myRequest.readyState == 4 && myRequest.status == 200){
        var er = document.getElementById("nuova_tipologia") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML += myRequest.responseText;
      }
    }
    function add_tipologia(){
	  var tot=document.getElementById('tot_tipologie').value
	  document.getElementById('tot_tipologie').value=Number(tot)+1;
      myRequest = CreateXmlHttpReq3(tipologie);
      myRequest.open("GET",dir+"/ajax/add_tipo.php?tot="+escape(Number(tot)+1));
      myRequest.send(null);
	  val=Number(tot)
	  document.getElementById('box_'+val).style.display='none'
    }
	//Funzione di salvataggio delle tipologie di stanza nel setup-struttura
	var myRequest = null;
	function salvataggio(){
      if(myRequest.readyState == 4 && myRequest.status == 200){
	    indice=document.getElementById('transazione_indice').value
        var er = document.getElementById("stato_"+indice) //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequest.responseText;
	    ahahEvalJS("stato_"+indice);
      }
    }
    function salva(indice){
	  document.getElementById('transazione_indice').value=indice
	  var type_room=document.getElementById('type_room_'+indice).value
	  var code=document.getElementById('code_'+indice).value
	  var desc_room=document.getElementById('desc_room_'+indice).value
	  var occupancy=document.getElementById('occupancy_'+indice).value
	  var occu_roll=document.getElementById('occu_roll_'+indice).value
	  var type_bed=document.getElementById('type_bed_'+indice).value
	  var max_rate=document.getElementById('max_rate_'+indice).value
	  var num_room=document.getElementById('num_room_'+indice).value
      myRequest = CreateXmlHttpReq3(salvataggio);
      myRequest.open("POST",dir+"/ajax/salva.php?type_room="+escape(type_room)+"&code="+escape(code)+"&desc_room="+escape(desc_room)+"&occupancy="+escape(occupancy)+"&occu_roll="+escape(occu_roll)+"&type_bed="+escape(type_bed)+"&max_rate="+escape(max_rate)+"&num_room="+escape(num_room)+"&indice="+escape(indice));
      myRequest.send(null);
    }
	
	//Funzione per visonare le tipologie già inserite nel setup-struttura
	var myRequestShow = null;
	function InsertRoom(){
      if(myRequestShow.readyState == 4 && myRequestShow.status == 200){
        var er = document.getElementById("stanzeinserite") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequestShow.responseText;
      }
    }
    function showInsertRoom(){
      myRequestShow = CreateXmlHttpReq3(InsertRoom);
      myRequestShow.open("GET",dir+"/ajax/stanzeinserite.php");
      myRequestShow.send(null);
    }
	//////////////////////////////////////////////////////////////////////////////
	
	//////////////////////////////////////////////////////////////////////////////
	
	//Funzione Di Salvataggio nuovo punto d'interesse
	var myRequestShow = null;
	function salvapunto(){
      if(myRequestShow.readyState == 4 && myRequestShow.status == 200){
        var er = document.getElementById("SalvaPunto") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequestShow.responseText;
	    document.getElementById('AttSalvaPunto').className="attendih"
	    ahahEvalJS("SalvaPunto");
      }
    }
    function SalvaPunto(){
	  var cat=document.getElementById('cat').value
	  var nome=document.getElementById('nome').value
	  var regione=document.getElementById('regione').value
	  var provincia=document.getElementById('provincia_sel').value
	  var address=document.getElementById('address').value
	  var descrizione=document.getElementById('descrizione').value
	  var longitude=document.getElementById('longitude').value
	  var latitude=document.getElementById('latitude').value
      myRequestShow = CreateXmlHttpReq3(salvapunto);
      myRequestShow.open("GET",dir+"/ajax/salvanewpunto.php?cat="+escape(cat)+"&nome="+escape(nome)+"&regione="+escape(regione)+"&provincia="+escape(provincia)+"&address="+escape(address)+"&descrizione="+escape(descrizione)+"&longitude="+escape(longitude)+"&latitude="+escape(latitude));
      myRequestShow.send(null);
	    document.getElementById('AttSalvaPunto').className="attendiv"
    }
	function AggiungiPunto()
	{
	  document.getElementById('cat').value=''
	  document.getElementById('nome').value=''
	  document.getElementById('regione').value=''
	  document.getElementById('address').value=''
	  document.getElementById('descrizione').value=''
	  document.getElementById('longitude').value=''
	  document.getElementById('latitude').value=''
	  document.getElementById('salva').style.display='';
	  document.getElementById('reset').style.display='none';
	  document.getElementById('SalvaPunto').style.display='none';
	  document.getElementById('indirizzo').value=''
	}
	
	
	//Funzione Di Salvataggio nuovo punto d'interesse
	var myRequestShow = null;
	function aggiornapunto(){
      if(myRequestShow.readyState == 4 && myRequestShow.status == 200){
        var er = document.getElementById("SalvaPunto") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequestShow.responseText;
	    document.getElementById('AttSalvaPunto').className="attendih"
	    ahahEvalJS("SalvaPunto");
		setTimeout("torna('gestisci-interesse.html')",3000)
      }
    }
    function AggiornaPunto(){
	  var cat=document.getElementById('cat').value
	  var nome=document.getElementById('nome').value
	  var regione=document.getElementById('regione').value
	  var provincia=document.getElementById('provincia_sel').value
	  var address=document.getElementById('address').value
	  var descrizione=document.getElementById('descrizione').value
	  var longitude=document.getElementById('longitude').value
	  var latitude=document.getElementById('latitude').value
	  var id=document.getElementById('id').value
      myRequestShow = CreateXmlHttpReq3(aggiornapunto);
      myRequestShow.open("GET",dir+"/ajax/aggiorna_punto.php?cat="+escape(cat)+"&nome="+escape(nome)+"&regione="+escape(regione)+"&provincia="+escape(provincia)+"&address="+escape(address)+"&descrizione="+escape(descrizione)+"&longitude="+escape(longitude)+"&latitude="+escape(latitude)+"&id="+escape(id));
      myRequestShow.send(null);
	    document.getElementById('AttSalvaPunto').className="attendiv"
    }
	
	//Funzione Di Salvataggio nuovo punto d'interesse
	var myRequestShow = null;
	function eliminapunto(){
      if(myRequestShow.readyState == 4 && myRequestShow.status == 200){
        var er = document.getElementById("statodel") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequestShow.responseText;
	    ahahEvalJS("statodel");
      }
    }
    function DelPunto(id){
      myRequestShow = CreateXmlHttpReq3(eliminapunto);
      myRequestShow.open("GET",dir+"/ajax/elimina_punto.php?id="+escape(id));
      myRequestShow.send(null);
    }
	//Funzione Di Salvataggio nuovo punto d'interesse
	var myRequestShow = null;
	function delcont(){
      if(myRequestShow.readyState == 4 && myRequestShow.status == 200){
        var er = document.getElementById("delcontenuto") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequestShow.responseText;
	    ahahEvalJS("delcontenuto");
      }
    }
    function DelContent(id,tb,cont){
      myRequestShow = CreateXmlHttpReq3(delcont);
      myRequestShow.open("GET",dir+"/ajax/elimina_contenuto.php?id="+escape(id)+"&type="+escape(tb)+"&cont="+escape(cont));
      myRequestShow.send(null);
    }
	//Funzione Abilita menu
	var myRequestShow = null;
	function abl(){
      if(myRequestShow.readyState == 4 && myRequestShow.status == 200){
        var er = document.getElementById("ablmenu") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequestShow.responseText;
	    ahahEvalJS("ablmenu");
	    document.getElementById('attendi').className="attendih"
      }
    }
    function Abilita(id){
      myRequestShow = CreateXmlHttpReq3(abl);
      myRequestShow.open("GET",dir+"/ajax/abilita.php?id="+escape(id));
      myRequestShow.send(null);
	    document.getElementById('attendi').className="attendiv"
    }
	//Funzione Sposta menu
	var myRequestShow = null;
	function sposta(){
      if(myRequestShow.readyState == 4 && myRequestShow.status == 200){
        var er = document.getElementById("ablmenu") //qui è dove andrà a scrivere il contenuto 
        er.innerHTML = myRequestShow.responseText;
	    ahahEvalJS("ablmenu");
	    document.getElementById('attendi').className="attendih"
      }
    }
    function SpostaMenu(prop_id,id,attuale,nuova){
      myRequestShow = CreateXmlHttpReq3(sposta);
      myRequestShow.open("GET",dir+"/ajax/sposta.php?id="+escape(id)+"&attuale="+escape(attuale)+"&nuova="+escape(nuova)+"&prop_id="+escape(prop_id));
      myRequestShow.send(null);
	    document.getElementById('attendi').className="attendiv"
    }
	///////////////////////////////////////////////////////////////////////////////
	
	///////////////////////////////////////////////////////////////////////////////
	
	//Funzione per prelevare codice Javascript all'interno delle pagine AJAX
	ahahEvalJS = function(elementId) 
	{
		var scripts = document.getElementById(elementId).getElementsByTagName('script');
		var code;
		for (var i = 0; i < scripts.length; i++) 
		{
			code =	scripts[i].innerHTML ? scripts[i].innerHTML : 
				scripts[i].text ? scripts[i].text : 
				scripts[i].textContent;
			try {
				eval(code);
			} catch(e) {
				alert(e);
			}
		}
	}
	
function mostra(div)
{	
	var stile=document.getElementById(div).style.display
	if(stile=='')
		document.getElementById(div).style.display='none'
	else
		document.getElementById(div).style.display=''
}