var xmlHttp

function showTravel(str)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request")
	 	return
	}
	var url="../includes/travel_location_search.php"
	url=url+"?q="+str
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function showFly(str)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request")
	 	return
	}
	var url="../includes/fly_arrival_search.php"
	url=url+"?q="+str
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedFly 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function addOption(select, value, text) {
	//Aggiunge un elemento <option> ad una lista <select>
	var option = document.createElement("option");
	option.value = value,
	option.text = text;
	
	try {
		select.add(option, null);
	} catch(e) {
		//Per Internet Explorer
		select.add(option);
	}
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	var select = document.getElementById("Vlocation")
	var resp = xmlHttp.responseText

	if(resp) {
		//Le coppie di valori nella striga di risposta sono separate da ;
		var values = resp.split('|');
		
		//Il primo elemento è l'ID della lista.
		var select = document.getElementById("Vlocation");
		//Elimina i valori precedenti
				while (select.options.length) {
					select.remove(0);
				} 
				
				var limit = values.length;
				addOption(select, "", "Seleziona");
				for(i=0; i < limit-1; i++) {
				
					//aggiunge un elemento <option>
					addOption(select, values[i], values[i]);
				}
				
			}
 } 
}

function stateChangedFly() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	var select = document.getElementById("arrival")
	var resp = xmlHttp.responseText

	if(resp) {
		//Le coppie di valori nella striga di risposta sono separate da ;
		
		var values = resp.split('|');
		
		//Il primo elemento è l'ID della lista.
		var select = document.getElementById("arrival");
		
		//Elimina i valori precedenti
				while (select.options.length) {
					select.remove(0);
				} 
				
				var limit = values.length;
				addOption(select, "", "Seleziona");
				for(i=0; i < limit-1; i++) {
				
					//aggiunge un elemento <option>
					var valori = values[i].split('$');					
					addOption(select, valori[0], valori[1]);
				}
				
			}
 } 
}

function GetXmlHttpObject()
{
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");
  }
 }
return xmlHttp;
}
