Event.observe(window, 'load', init, false);
function init(){
     //$('greeting-submit').style.display = 'none';
     //Event.observe('greeting-name', 'keyup', greet, false);
	// Event.observe('region', 'change', fillSelect, false);
	// Event.observe('country', 'change', fillSelect, false);
	// Event.observe('city', 'change', fillSelect, false);

}
var ajaxRealm = '';

function fillSelect(realm,caller,fill,showCitiesWithHotelCoordsOnly,showAllEntry,categoryFrom,categoryTo){
    if ( !categoryFrom || categoryFrom == 'undefined' ){
    	categoryFrom = '';
    }
    if ( !categoryTo || categoryFrom == 'undefined' ){
    	categoryTo = '';
    }
    ajaxRealm = realm ;
    //alert('categoryFrom: '+categoryFrom);
    var url = '/cms/includes/functions.ajax.php';
    var pars = 'ajaxAction=fillSelects&realm='+realm+'&fill='+fill+'&code='+escape($F(caller))+'&showCitiesWithHotelCoordsOnly='+showCitiesWithHotelCoordsOnly+'&showAllEntry='+showAllEntry+'&hotelCategoryFrom='+categoryFrom+'&hotelCategoryTo='+categoryTo;
	//alert(pars);
	//var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
	var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: ajax_response});
}

function ajax_response(response){
   //alert(response.responseText);
   var string = response.responseText;
   var arrFill = string.split("::");
   var fill = arrFill[0];

  var rows = arrFill[1].split("|");
  //optionValue = new Option("WErt",2);
  //alert(optionValue);
  //alert(document.getElementById('city_to').length);
  //document.getElementById('country').options[0] = optionValue;

  if (fill == "flight_countryFrom"){
  	unsetOptions("flight_cityFrom");
    unsetOptions("flight_cityDetailFrom");
  }
  if (fill == "flight_cityFrom"){
  	unsetOptions("flight_cityDetailFrom");
  }

  if (fill == "flight_countryTo"){
  	unsetOptions("flight_cityTo");
    unsetOptions("flight_cityDetailTo");
  }
  if (fill == "flight_cityTo"){
  	unsetOptions("flight_cityDetailTo");
  }

  if (fill == "CityCode"){
  	//alert('unset');
    unsetOptions("HotelCodes[]");
  }

  unsetOptions(fill);

  for ( var i=0;i<(rows.length-1);i++){
  	var values = rows[i].split("@@");
	  //alert(values[0]+" -> "+values[1]);
	  option = new Option(values[1],values[0]);
	  document.getElementById(fill).options[i] = option;
  }

  // Wenn auf der Scuhseite eine Stadt gewählt wurde, sollen die Hotels zu der Stadt sofort angezeigt werden
  if ( ajaxRealm == 'academShowCityList' ){
      fillSelect('academShowHotelList','CityCode','HotelCodes[]','','1');
      changeMapLink();
      changeFlightToolLink();
  }

  if ( ajaxRealm == 'BE_showCityList' ){
      fillSelect('BE_showHotelList','cityId','hotelCommonIds[]','','1');
  }
}

function unsetOptions(element){
  //alert(element);
  if ( document.getElementById(element) ){
      for ( var i=document.getElementById(element).options.length; i>=0 ;i--){
    		document.getElementById(element).options[i] = null;
      }
  }
}

function searchCity(destinationField,target){
	//alert($F('flight_airportFrom'));
	var url = '/cms/includes/functions.ajax.php';
    var pars = 'ajaxAction=searchCity&target='+target+'&destinationField='+destinationField+'&search='+escape($F(destinationField));

	var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
}

