Event.observe(window, 'load', function() {
  Event.observe('pickup_city', 'change', changePickupCity);
  Event.observe('dropoff_city', 'change', changeDropoffCity);
  Event.observe('pickup_type', 'change', changePickupType);
});

function changePickupType()
{
	var pickup_type_selected = $('pickup_type').options[$('pickup_type').selectedIndex].value;
	var pickup_city_selected = $('pickup_city').options[$('pickup_city').selectedIndex].value;
	
	switch(pickup_type_selected)
	{
		case '1': /* accomodation */
			$('pickup_airport_select').innerHTML = '';
			$('pickup_airport_select_span').hide();
			break;
		case '2': /* airport */
			url = "ajax/get_locations_options.php?type=2&city_id=" + escape(pickup_city_selected) + "&label=" + escape(ht_phrase_select_airport)+ "&lang=" + window.current_language_short ;
			new Ajax.Request(url, {
			  method: 'get',
			  onSuccess: function(transport) {
			  		$('pickup_airport_select').innerHTML = '<select style="margin-left:0px;" name="pickup_airport">' + transport.responseText + '</select>';
			  		$('pickup_airport_select_span').show();
			  },
			  onFailure: function(){
			  		
			  }
			});
			
			break;
	}
}
function changePickupCity()
{
	var pickup_city_selected = $('pickup_city').options[$('pickup_city').selectedIndex].value;
	url = "ajax/city_have_airports.php?city_id=" + escape(pickup_city_selected);
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	  	var options = window.accomodation_option;
	  	if(transport.responseText == '1')
	  	{
	  		options = options + window.airport_option;
	  	}
  		$('pickup_type_select').innerHTML = '<select name="pickup_type" id="pickup_type">' + options + '</select>';
  		Event.observe('pickup_type', 'change', changePickupType);
  		$('pickup_airport_select_span').hide();
	  },
	  onFailure: function(){
	  		
	  }
	});
}function changeDropoffType()
{
	var dropoff_type_selected = $('dropoff_type').options[$('dropoff_type').selectedIndex].value;
	var dropoff_city_selected = $('dropoff_city').options[$('dropoff_city').selectedIndex].value;
	
	switch(dropoff_type_selected)
	{
		case '1': /* accomodation */
			$('dropoff_airport_select').innerHTML = '';
			$('dropoff_airport_select_span').hide();
			break;
		case '2': /* airport */
			url = "ajax/get_locations_options.php?type=2&city_id=" + escape(dropoff_city_selected) + "&label=" + escape(ht_phrase_select_airport)+ "&lang=" + window.current_language_short ;
			new Ajax.Request(url, {
			  method: 'get',
			  onSuccess: function(transport) {
			  		$('dropoff_airport_select').innerHTML = '<select style="margin-left:0px;" name="dropoff_airport">' + transport.responseText + '</select>';
			  		$('dropoff_airport_select_span').show();
			  },
			  onFailure: function(){
			  		
			  }
			});
			
			break;
	}
}
function changeDropoffCity()
{
	var dropoff_city_selected = $('dropoff_city').options[$('dropoff_city').selectedIndex].value;
	url = "ajax/city_have_airports.php?city_id=" + escape(dropoff_city_selected);
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	  	var options = window.accomodation_option;
	  	if(transport.responseText == '1')
	  	{
	  		options = options + window.airport_option;
	  	}
  		$('dropoff_type_select').innerHTML = '<select name="dropoff_type" id="dropoff_type">' + options + '</select>';
  		Event.observe('dropoff_type', 'change', changeDropoffType);
  		$('dropoff_airport_select_span').hide();
	  },
	  onFailure: function(){
	  		
	  }
	});
}