        function showDeposito(id,nome) { 
	       if (document.getElementById("anteprima_assegnazioni").style.display=="block")
        {
        document.getElementById("anteprima_assegnazioni").style.display="none";
        document.getElementById("report_assegnazioni").style.display="block";
        }
        document.getElementById("dep_name").innerHTML=nome;
        var ajax = assegnaXMLHttpRequest(); 
        var nomefile = "/deposito_printer.php?cod_deposito="+id;
        if(ajax)
        {
            usalink=false;     
            ajax.open("GET",nomefile,true);
            ajax.setRequestHeader("connection", "close");
            
            ajax.onreadystatechange = function() 
            {
               if(ajax.readyState === 4) 
                {
                    if(ajax.status == 200)
                    {    
                        var splittaggio = ajax.responseText.split("#-#");
                        
                        var unita = splittaggio[0].split("#@#");
                        document.getElementById("elenco_unita").innerHTML="";
                        for (var i=0; i < unita.length-1; i++)
                        {
                            var valori=unita[i].split("-");
                            var nodo = document.createElement("DIV");
                            var classe = "t_1";
                          
                            nodo.className=classe;
                            var valore = document.createTextNode(valori[0]);
                            nodo.appendChild(valore);
                            nodo.onclick =function () {
                            alert(this.className);
                            }
                            nodo.setAttribute("title",valori[1]);
                            document.getElementById("elenco_unita").appendChild(nodo);
                        }
                        document.getElementById("num_tot").innerHTML=splittaggio[1];
                        document.getElementById("num_656").innerHTML=splittaggio[2];
                        document.getElementById("num_655").innerHTML=splittaggio[3];
                        document.getElementById("num_scmt_si").innerHTML=splittaggio[4];
                        document.getElementById("num_scmt_no").innerHTML=splittaggio[5];
                        document.getElementById("num_pax").innerHTML=splittaggio[6];
                        document.getElementById("num_cargo").innerHTML=splittaggio[7];
                        document.getElementById("num_tmr").innerHTML=splittaggio[8];
		            }
                    else
                    {
                        alert("errore");
                    }
                }
            }
            ajax.send(null);
           
        }
    }















function initLoader()
{
document.getElementById("loading").style.display = "block";
}
function stopLoader()
{
document.getElementById("loading").style.display = "none";
}
function cambiaGIF(object)
{
    if (object.className=="icona_close_risultati2")
    {
    object.className="icona_close_risultati";
    }
    else
    {
    object.className="icona_close_risultati2";
    }
}
function goTo(url)
{
location.href=url;
}
function colora(object)
{
   }
function linker(object)
{
    if (object.className.indexOf("hover")==-1)
    {
    var nome = object.className;
    object.className = nome+"hover";
    }
    else
    {
    object.className=object.className.replace("hover","");
    }
}


  // funzione per assegnare un oggetto XMLHttpRequest
		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;
		};
        
         
    // funzione per cambiare dinamicamente il contenuto di un contenitore
        function getWithAjax(nomefile,contenitore) { 
         var ajax = assegnaXMLHttpRequest(); 
        usalink=true;   
        if(ajax)
        {
            usalink=false;     
            ajax.open("GET",nomefile,true);
            ajax.setRequestHeader("connection", "close");
            
            ajax.onreadystatechange = function() 
            {
               if(ajax.readyState === 4) 
                {
                    if(ajax.status == 200)
                    {    
                    
		            document.getElementById(contenitore).innerHTML = ajax.responseText;		
		            }
                    else
                    {
                        document.getElementById(contenitore).innerHTML = "ERRORE IN QUALCOSA";   
                    }
                }
            }
            ajax.send(null);
           
        }
        return usalink;

}



function stampaTreni(staz)
{
    var start_i=0;
    var x=setInterval(function() {
     var ajax = assegnaXMLHttpRequest(); 
     var nomefile="/getter_treni.php?limite="+start_i+"&where="+staz;
        usalink=true;   
        if(ajax)
        {
            usalink=false;     
            ajax.open("GET",nomefile,true);
            ajax.setRequestHeader("connection", "close");
            
            ajax.onreadystatechange = function() 
            {
               if(ajax.readyState === 4) 
                {
                    if(ajax.status == 200)
                    {    
                        if(ajax.responseText!="     " || start_i > 100)
                        {   
                            var tmp =ajax.responseText.split("@");
                            if(tmp.length >1)
                            {
                            document.getElementById("num_treni").innerHTML = parseInt(document.getElementById("num_treni").innerHTML)+tmp.length;
                            
                            for(var i=0; i < tmp.length; i++)
                            {   
                                var tr = document.createElement("TR");
                                tr.style.border="1px solid #8AA8E6";
                                if(i%2==0) tr.style.backgroundColor="white"; else tr.style.backgroundColor="rgb(208,218,234)";
                                var tmp2=tmp[i].split("#");
                                if(tmp2.length > 1)
                                {
                                    for(var j=0; j<tmp2.length; j++)
                                    {
                                        if(tmp2[j]!="")
                                        {
                                            var td = document.createElement("TD");
                                            td.innerHTML=tmp2[j];
                                            tr.appendChild(td);
                                        }
                                    }
                                }
                                document.getElementById("tabella_treni").appendChild(tr);
                            }
		                //    document.getElementById("tabella_treni").innerHTML += ajax.responseText;	
                            start_i+=10;   
                            }
                            else
                            {
                            document.getElementById("caricatore").innerHTML="";
                            }
                            
                        }
                        else
                        {
							document.getElementById("caricatore").innerHTML="";
    	                    clearInterval(x);
                        }
		            }
                    else
                    {
                        document.getElementById("tabella_treni").innerHTML = "ERRORE IN QUALCOSA";   
                    }
                }
            }
            ajax.send(null);
           
        }
        return usalink;
    
    },800);
}

function riempiRicercaConAjax(cond)
{
var nomefile = "/ricercaWriter.php?cond="+cond;
getWithAjax(nomefile,"risultato_ricerca")
}

function ricercaConAjax(e)
{

 document.getElementById("risultati").innerHTML ="Ricerca in corso..";
 
    if (document.getElementById("blocco_risultati").style.display=="none")
    {
        document.getElementById("blocco_risultati").style.display = "block";
    }
    var chiave = document.getElementById("keyword").value;
    var keynum;
    var keychar;
    if(window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
    keynum = e.which;
    }
    keychar = String.fromCharCode(keynum);
    chiave = chiave+keychar;   
    var url = "/searcher.php?key="+chiave;
    getWithAjax(url,"risultati");
}

function ricercaConAjax2()
{

 document.getElementById("risultati").innerHTML ="Ricerca in corso..";
 
    if (document.getElementById("blocco_risultati").style.display=="none")
    {
        document.getElementById("blocco_risultati").style.display = "block";
    }
    var chiave = document.getElementById("keyword").value;
    if(chiave.length > 3)
    {
    chiave = document.getElementById("keyword").value = chiave.substr(0,3);
    }
    var url = "/searcher.php?key="+chiave;
    getWithAjax(url,"risultati");
    
}



function getPaginaWithAjax(url,contenitore)
{
 return getPaginaWithAjax(url,contenitore,"450px")
}




function getPaginaWithAjax(url,contenitore,dimensione,style,pagina)
{
document.getElementById("loading").style.display = "block";
   document.getElementById(contenitore).innerHTML = "";
    var ajax = assegnaXMLHttpRequest(); 
        usalink=true;   
        if(ajax)
        {
            usalink=false;     
            ajax.open("GET",url,true);
            ajax.setRequestHeader("connection", "close");
            ajax.onreadystatechange = function(){
                if(ajax.readyState === 4) 
                {
                    if(ajax.status == 200)
                    {    
		                document.getElementById(contenitore).style.height=dimensione;
                        document.getElementById("local_style").href=style;
                        document.getElementById(contenitore).innerHTML = ajax.responseText;
                        var titolo = document.title;
                        if (titolo.indexOf("pagina: ")==-1)
                        {
                        titolo = titolo + " pagina: "+pagina;
                        document.title = titolo;
                        }
                        else
                        {
                        var esploso = titolo.split(":");
                        document.title = esploso[0]+": "+pagina;
                        }
			        }
                    else
                        document.getElementById(contenitore).innerHTML = "ERRORE IN QUALCOSA";   
                }
            }
            ajax.send(null);
                
        }
        
      
        return usalink;



}


function pulisciNodi(id)
{
var to = document.getElementById(id).childNodes[0];
	/*for (var i = 0; i <to.length; i++)
	{
		to.removeChild
	}*/
	//for (j=to.length-1; j >= 1; j--) 
	for (j=to.length-1; j >= to.length-10; j--) 
	{
	to[j].parentNode.removeChild(to[j]);
	}

}
 function riempiSelectConAjax(nomefile,contenitore) { 
        var ajax = assegnaXMLHttpRequest(); 
        usalink=true;   
        if(ajax)
        {
            usalink=false;     
            ajax.open("GET",nomefile,true);
            ajax.setRequestHeader("connection", "close");
            
            ajax.onreadystatechange = function() 
            {
                if(ajax.readyState === 4) 
                {
                    if(ajax.status == 200)
                    {    
			var risposta = ajax.responseText;
			
			if (risposta=="")
			{
				alert("ATTENZIONE!!!  \nNessuna stazione trovata secondo questa chiave di ricerca");
			}
			else
			{
			
				var risp = risposta.split("#");
				//svuoto il contenitore attuale
				pulisciNodi(contenitore);
				
				for (var i = 0; i < risp.length-1; i++)
				{
				
					var risp_tmp = risp[i].split("-");
					var nuovo = document.createElement("OPTION");
					nuovo.setAttribute("value",risp_tmp[0]);
					nuovo.innerHTML =risp_tmp[1];
					document.getElementById(contenitore).childNodes[0].appendChild(nuovo);
				}
				document.getElementById("status").style.visibility="hidden";
			}
				
		     }
                    else
		    {
                        document.getElementById(contenitore).innerHTML = "ERRORE IN QUALCOSA";   
		    }
                }
            }
            ajax.send(null);
           
        }
        return usalink;

}



function noCache(uri){return uri.concat(/\?/.test(uri)?"&":"?","noCache=",(new Date).getTime(),".",Math.random()*1234567)};



function mostraPosTreno(treno,tipo,da,a)
{ 

var iniziale = "<img src = '/gfx/gif.gif' alt = 'ciao' />     Attendere Prego,<br />Rilevamento informazioni sulla posizione in corso...";
document.getElementById("provatreno").innerHTML=iniziale;
  var ajax = assegnaXMLHttpRequest(); 
  var nomefile = "/dammiritardo.php?treno="+treno;
  usalink=true;   
  if(ajax)
    {
      usalink=false;     
      ajax.open("GET",noCache(nomefile),true);
      ajax.setRequestHeader("connection", "close");
      ajax.onreadystatechange = function() {
        if(ajax.readyState === 4) 
        {
          if(ajax.status == 200)
          {
                  
            var risposta = ajax.responseText;
            
            if (risposta=="")
              {
                alert("ATTENZIONE!!!  \nNessun treno trovato con questa classificazione");
              }
              else
              {			
              var risp = risposta.split("#");
              if (risp[2]=="ND")
              {
                document.getElementById("provatreno").innerHTML="Informazione non disponibile per il treno <b>"+treno+"</b>";
              }
              else
              {
                var testo = "Il treno "+tipo+" <b>"+treno+"</b> da "+da+" a "+a+" viaggia ";
                if (risp[2]==0){
                testo = testo+ "in orario.<br />";
                }
                else if (risp[2]<1)
                {
                  if (parseInt((risp[2]*-1))==1)
                  {
                    testo = testo+ "con <b>"+parseInt(risp[2])*-1+"</b> minuto di anticipo.<br />";
                  }
                  else 
                  {
                   testo = testo+ "con <b>"+parseInt(risp[2])*-1+"</b> minuti di anticipo.<br />";
                  }
                }
                else if (risp[2]>0)
                {
                  if (parseInt(risp[2])==1)
                  {
                    testo = testo + "con <b>"+parseInt(risp[2])+"</b> minuto di ritardo.<br />";
                  }
                  else
                  {
                    testo = testo + "con <b>"+parseInt(risp[2])+"</b> minuti di ritardo.<br />";
                  }
                }
                testo = testo + "Ultimo Rilevamento: <b>"+risp[1]+"</b> alle ore: <b>"+risp[3]+"</b>";
                document.getElementById("provatreno").innerHTML=testo;
                }
              }
          }
          else
          {
            alert("Errore generale");  
          }
        }
      }
      ajax.send(null);
    }
  return usalink;
}























function mostraImpostazioniDaClassificazione(nomefile,nome)
{ 
	    var contenitore = document.getElementById("localita_container");
	    var numNodi = contenitore.childNodes.length;
		var nuovoSpan =document.createElement("SPAN");
		nuovoSpan.className="dovesei";
		var newText = document.createTextNode(" >> ");
		nuovoSpan.appendChild(newText);
		var nuovoLink = document.createElement("A");
		nuovoLink.setAttribute("href","#");
		var newText = document.createTextNode(nome);
		nuovoLink.appendChild(newText);
		nuovoLink.onclick=function() {
		return mostraImpostazioniDaClassificazione(nomefile,nome);
		}
	
	if (numNodi > 1)
	{
		
		var j = numNodi-1;
		while (j > 0) {
		contenitore.removeChild(contenitore.childNodes[j]);
		j--;
		}
	}
	nuovoSpan.appendChild(nuovoLink);
	contenitore.appendChild(nuovoSpan);
	
	
        var ajax = assegnaXMLHttpRequest(); 
        usalink=true;   
        if(ajax)
        {
            usalink=false;     
            ajax.open("GET",nomefile,true);
            ajax.setRequestHeader("connection", "close");
            
            ajax.onreadystatechange = function() 
            {
                if(ajax.readyState === 4) 
                {
                    if(ajax.status == 200)
                    {
                      var risposta = ajax.responseText;
                    
                        var risposta = ajax.responseText;
                        if (risposta=="")
                        {
                            alert("ATTENZIONE!!!  \nNessun treno trovato con questa classificazione");
                        }
                        else
                        {
                            //document.getElementById("contenitoreicone").innerHTML = ajax.responseText;
                            var risp = risposta.split("@");
                            svuotaContenitoreDaId("contenitoreicone");
                            for (var i=0 ; i <risp.length-1; i++)
                            {
                                
                                var prova = risp[i].split("#");
                                if (prova.length==2)
                                {
                                var id_riga= "info_"+prova[0];
                                }
                                else if (prova.length==3)
                                {
                                var id_riga= "info_"+prova[0]+"_"+prova[2];
                                }
                                var newElem =document.createElement("DIV");
                                newElem.id=id_riga;
                                newElem.className="riga_info";
                                
                                if (prova.length > 0)
                                {
                                var newText = document.createTextNode(prova[1]);
                                newElem.appendChild(newText);
                                newElem.onmouseover=function(){return coloraR(this.id,"1");}
                                newElem.onmouseout=function(){ return coloraR(this.id,"2");}
                                newElem.onclick=function()
                                    {
                                        var identificativo = (this.id).split("_");
                                        var url;
                                        
                                        if (identificativo[2]!=undefined)
                                        {
                                        url = "/stampaimpostazioni.php?like="+identificativo[2];
                                        mostraImpostazioniDaLocomotore(url,identificativo[2]);
                                        }
                                        else
                                        {
                                        url = "/stampaimpostazioni.php?composizione="+identificativo[1];
                                        mostraImpostazioniDaLocomotore(url,this.innerHTML);
                                        }
                                        
                                        
                                    }
                                document.getElementById("contenitoreicone").appendChild(newElem);
                                }
                                
                            }
                            
                              //window.prompt("pigiatelo",document.getElementById("contenitoreicone").innerHTML);
                            
                        }
				
		        }
                    else
		    {
                        alert("Errore generale");  
		    }
                }
            }
            ajax.send(null);
           
        }
        return usalink;
}



function mostraImpostazioniDaLocomotore(nomefile,nome)
{ 

	var contenitore = document.getElementById("localita_container");
	var numNodi = contenitore.childNodes.length;
		var nuovoSpan =document.createElement("SPAN");
		nuovoSpan.className="dovesei";
		var newText = document.createTextNode(" >> ");
		nuovoSpan.appendChild(newText);
		var nuovoLink = document.createElement("A");
		nuovoLink.setAttribute("href","#");
		var newText = document.createTextNode(nome);
		nuovoLink.appendChild(newText);
		nuovoLink.onclick=function() {
		return mostraImpostazioniDaLocomotore(nomefile,nome);
		}
		
	if (numNodi > 2)
	{
		
		var j = numNodi-1;
		while (j > 1) {
		contenitore.removeChild(contenitore.childNodes[j]);
		j--;
		}
	}
	nuovoSpan.appendChild(nuovoLink);
	contenitore.appendChild(nuovoSpan);
	
	
        var ajax = assegnaXMLHttpRequest(); 
        usalink=true;   
        if(ajax)
        {
            usalink=false;     
            ajax.open("GET",nomefile,true);
            ajax.setRequestHeader("connection", "close");
            
            ajax.onreadystatechange = function() 
            {
                if(ajax.readyState === 4) 
                {
                    if(ajax.status == 200)
                    {    
			var risposta = ajax.responseText;
			
			if (risposta=="")
			{
				alert("ATTENZIONE!!!  \nNessun treno trovato con questa classificazione");
			}
			else
			{
			
				var risp = risposta.split("@");
				svuotaContenitoreDaId("contenitoreicone");
				for (var i=0 ; i <risp.length-1; i++)
				{
						var prova = risp[i].split("#");
						var id_riga= "info_"+prova[0]+"_"+prova[1];
							var newElem =document.createElement("DIV");
							newElem.id=id_riga;
							newElem.className="riga_info";
							
							var newText = document.createTextNode(prova[1]);
							newElem.appendChild(newText);
							
							newElem.onmouseover=function(){return coloraR(this.id,"1");}
							newElem.onmouseout=function(){ return coloraR(this.id,"2");}
							newElem.onclick=function(){
							var identificativo = (this.id).split("_");
							var url = "/stampatreni.php?impostazione="+identificativo[1];
							
							return mostraTreni(url,identificativo[2]);
							
							
							}
							
							
						document.getElementById("contenitoreicone").appendChild(newElem);
				}
				
				
				
			}
				
		     }
                    else
		    {
                        alert("Errore generale");  
		    }
                }
            }
            ajax.send(null);
           
        }
        return usalink;
}



function mostraTreni(nomefile,nome)
{
	var contenitore = document.getElementById("localita_container");
	var numNodi = contenitore.childNodes.length;
		var nuovoSpan =document.createElement("SPAN");
		nuovoSpan.className="dovesei";
		var newText = document.createTextNode(" >> ");
		nuovoSpan.appendChild(newText);
		var nuovoLink = document.createElement("A");
		nuovoLink.setAttribute("href","#");
		var newText = document.createTextNode(nome);
		nuovoLink.appendChild(newText);
		nuovoLink.onclick=function() {
		return mostraTreni(nomefile,nome);
		}
	if (numNodi > 3)
	{
		var j = numNodi-1;
		
		while (j > 2) {
		contenitore.removeChild(contenitore.childNodes[j]);
		j--;
		}
	}
	nuovoSpan.appendChild(nuovoLink);
	contenitore.appendChild(nuovoSpan);
	document.getElementById("waiting").style.display="block";
        var ajax = assegnaXMLHttpRequest(); 
        usalink=true;   
        if(ajax)
        {
            usalink=false;     
            ajax.open("GET",nomefile,true);
            ajax.setRequestHeader("connection", "close");
            
            ajax.onreadystatechange = function() 
            {
		if(ajax.readyState === 4) 
                {
			if(ajax.status == 200)
			{    
				var risposta = ajax.responseText;
				if (risposta=="")
				{
					alert("ATTENZIONE!!!  \nNessun treno trovato con questa classificazione");
				}
				else
				{
					var risp = risposta.split("@");
					document.getElementById("waiting").style.display="none";
					svuotaContenitoreDaId("contenitoreicone");
					if (risp.length > 1)
						{
							var divContainer =document.createElement("DIV");
							divContainer.className="riga_treno";
							var tabella = document.createElement("TABLE");
							tabella.className="table_treni";
							var tbody = document.createElement("TBODY");
							for (var i=0 ; i <risp.length-1; i++)
							{
								var prova = risp[i].split("#");
								var riga = document.createElement("TR");
								riga.id="treno-"+prova[1];
								riga.className="normal";
								
								riga.onmouseover=function(){
								this.className="over";
								}
								riga.onmouseout=function(){
								this.className="normal";
								}
								
								riga.onclick=function(){
								var aa = this.id.split("-");
								window.open("/orario/treno/"+aa[1]+".html","");
								}
								
								for (var j = 0; j < prova.length-1 ; j++)
								{
								var tmp = document.createElement("TD");
								if (prova[j]=="") prova[j]=" ";
								var newText = document.createTextNode(prova[j]);
								tmp.appendChild(newText);
								riga.appendChild(tmp);
								}
								tbody.appendChild(riga);
							}
							tabella.appendChild(tbody);
							divContainer.appendChild(tabella);
							document.getElementById("contenitoreicone").appendChild(divContainer);
						}
						else
						{
							alert("Non ci sono treni per l'opzione selezionata");
						}
				}
			}
				
		     
                    else
		    {
                        alert("Errore generale");  
		    }
                }
            }
            ajax.send(null);
           
        }
        return usalink;
}












function stampaIndice(nomefile)
{ 
	var contenuto = '<span id = "dovesei"><a href = "#" onclick = "stampaIndice(\'/printIndex.php\');">indice</a>';
	document.getElementById("localita_container").innerHTML=contenuto;
        var ajax = assegnaXMLHttpRequest(); 
        usalink=true;   
        if(ajax)
        {
            usalink=false;     
            ajax.open("GET",nomefile,true);
            ajax.setRequestHeader("connection", "close");
            
            ajax.onreadystatechange = function() 
            {
                if(ajax.readyState === 4) 
                {
                    if(ajax.status == 200)
                    {    
			var risposta = ajax.responseText;
			
			if (risposta=="")
			{
				alert("ATTENZIONE!!!  \nErrore durante la stampa dell'indice");
			}
			else
			{
			
				var risp = risposta.split("@");
				svuotaContenitoreDaId("contenitoreicone");
				var impostazioni = new Array(risp.length);
				var i =0;
				for (; i <risp.length-1; i++)
				{
					var indice = i;
					var tmp = risp[i].split("#");
					impostazioni[i]= tmp[1];
					var newElem =document.createElement("DIV");
					newElem.id=tmp[0]+"_"+tmp[3];
					newElem.className="icona";
					var stringa = "<img src = '/images/icone/"+tmp[2]+"' alt = 'icona' /><br />"+tmp[3];
					newElem.innerHTML=stringa;
							
							newElem.onmouseover=function(){return colora(this.id,"1");}
							newElem.onmouseout=function(){ return colora(this.id,"2");}
							newElem.onclick=function(){
							var numero = this.id;
							var esplosione = numero.split("_");
							var num = parseInt(esplosione[1]);
							num=num+1;
							
							searchByDenominazione(num,esplosione[2]);
							}
					document.getElementById("contenitoreicone").appendChild(newElem);
				}
				
				
				
			}
				
		     }
                    else
		    {
                        alert("Errore generale");  
		    }
                }
            }
            ajax.send(null);
           
        }
        return usalink;
}



function svuotaContenitoreDaId(id)
{
	var ci= document.getElementById(id);
	while (ci.childNodes[0]) {
	ci.removeChild(ci.childNodes[0]);
	}
}




        function postWithAjax(nomefile,contenitore,infotosend) { 
	   
	   //Creo un nuovo oggetto XMLHTTPRequest
            var req = assegnaXMLHttpRequest(); 
            if(req)
            {
                  //Invio la richiesta
				req.open("POST", nomefile, true);
				req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				
                //Invio i dati POST
				req.send(infotosend);
				
				//Gestore dell'evoluzione dello stato dell'oggetto req
				req.onreadystatechange = function() 
                {
                    if(req.readyState === 4) 
                    {
                        if(req.status == 200)
                        {    
			
                
                            document.getElementById(contenitore).innerHTML = req.responseText;
			}
                        else
                            document.getElementById(contenitore).innerHTML = "ERRORE IN QUALCOSA";   
                    }
                }   
                
            }
          
}


function mostraOspiti(val,autore)
{
    var pagina = document.getElementById("pagina").value;
    var page = "";
    if (val >0)
    {
        page = parseInt(parseInt(pagina)+1);
    }
    else
    {
        page = parseInt(parseInt(pagina)-1);
    }
    var url = "/printUnita.php?pagina="+page+"&autore="+autore;
    alert(url);
    getWithAjax(url,"cont_last_corpo")
    document.getElementById("pagina").value = "";
    document.getElementById("pagina").value = parseInt(0+page);    
}


function doAutoSuggest()
{
	var value = (document.getElementById("staz").value).toLowerCase();
	if(value.length < 3) 
	{
		var node = document.getElementById("autosuggestion");
		if(node.childNodes.length > 0)
		{
			removeChildrenFromNode(node);
		}
	}
	else if(value.length == 3)
	{
		autoSuggesterStazioni(value);
	}
	else if(value.length > 3)
	{
		showMatches(value);
	}
}

function autoSuggesterStazioni(staz)
{
	arrayMatches = new Array();
	var ajax = assegnaXMLHttpRequest(); 
    if(ajax)
        {
			var url = "/autosuggestion_stazioni.php?staz="+staz;
            ajax.open("GET",url,true);
            ajax.setRequestHeader("connection", "close");
            ajax.onreadystatechange = function() 
            {
                if(ajax.readyState === 4) 
                {
                    if(ajax.status == 200)
                    {    
						var result = ajax.responseText;
						if(result.indexOf("NoResults") > 0 || result.indexOf("NoMatches") > 0)
						{
							addTextItemToList("Nessuna stazione corrispondente.");
						}
						else
						{
							var str = result.split("@");
							for(var i = 0; i < str.length; i++)
							{
								var strFinded = str[i].split("#");
								arrayMatches.push(strFinded);	
							}
							showMatches(staz);
						}

					}
			     }
                else
			    {

			    }	
             }
            ajax.send(null);
        }
}

function showMatches(keyWord)
{
	var autosuggestion = document.getElementById("autosuggestion");
	removeChildrenFromNode(autosuggestion);
	document.getElementById("autosuggestion").removeChild
	var printed = 0;
	for(var i = 0; i < arrayMatches.length && printed < 8; i++)
	{
		if((arrayMatches[i][0].toLowerCase()).indexOf(keyWord) > -1)
		{
			addItemToList(arrayMatches[i]);
			printed++;
		}
	}
	if(printed >= 8)
	{
		addTextItemToList("... e altri "+(arrayMatches.length-8)+" risultati");
	}
	else if(printed==0)
	{
		addTextItemToList("Nessuna stazione corrispondente.");
	}

}

function removeChildrenFromNode(node)
{
   var len = node.childNodes.length;
	while (node.hasChildNodes())
	{
	  node.removeChild(node.firstChild);
	}
}

function addItemToList(aItem)
{
	var div = document.createElement("DIV");
	var link = document.createElement("a");
	var testo = document.createTextNode(aItem[0]);
	link.setAttribute("href", "/orario/stazione/"+aItem[1]+".html");
	link.appendChild(testo);
	div.appendChild(link);	
	div.onmouseover = function() { div.setAttribute("style", "background-color: #C7C4B3;"); }
	div.onmouseout = function() { div.removeAttribute("style"); }		
	document.getElementById("autosuggestion").appendChild(div);
}

function addTextItemToList(strItem)
{
	var div = document.createElement("DIV");
	var text = document.createTextNode(strItem);
	div.appendChild(text);
	document.getElementById("autosuggestion").appendChild(div);
}




/** OGGETTI / ARRAY */
	// oggetto di verifica stato
		var readyState = {
			INATTIVO:	0,
			INIZIALIZZATO:	1,
			RICHIESTA:	2,
			RISPOSTA:	3,
			COMPLETATO:	4
		};

	// array descrittivo dei codici restituiti dal server
	// [la scelta dell' array è per evitare problemi con vecchi browsers]
		var statusText = new Array();
		statusText[100] = "Continue";
		statusText[101] = "Switching Protocols";
		statusText[200] = "OK";
		statusText[201] = "Created";
		statusText[202] = "Accepted";
		statusText[203] = "Non-Authoritative Information";
		statusText[204] = "No Content";
		statusText[205] = "Reset Content";
		statusText[206] = "Partial Content";
		statusText[300] = "Multiple Choices";
		statusText[301] = "Moved Permanently";
		statusText[302] = "Found";
		statusText[303] = "See Other";
		statusText[304] = "Not Modified";
		statusText[305] = "Use Proxy";
		statusText[306] = "(unused, but reserved)";
		statusText[307] = "Temporary Redirect";
		statusText[400] = "Bad Request";
		statusText[401] = "Unauthorized";
		statusText[402] = "Payment Required";
		statusText[403] = "Forbidden";
		statusText[404] = "Not Found";
		statusText[405] = "Method Not Allowed";
		statusText[406] = "Not Acceptable";
		statusText[407] = "Proxy Authentication Required";
		statusText[408] = "Request Timeout";
		statusText[409] = "Conflict";
		statusText[410] = "Gone";
		statusText[411] = "Length Required";
		statusText[412] = "Precondition Failed";
		statusText[413] = "Request Entity Too Large";
		statusText[414] = "Request-URI Too Long";
		statusText[415] = "Unsupported Media Type";
		statusText[416] = "Requested Range Not Satisfiable";
		statusText[417] = "Expectation Failed";
		statusText[500] = "Internal Server Error";
		statusText[501] = "Not Implemented";
		statusText[502] = "Bad Gateway";
		statusText[503] = "Service Unavailable";
		statusText[504] = "Gateway Timeout";
		statusText[505] = "HTTP Version Not Supported";
		statusText[509] = "Bandwidth Limit Exceeded";
