function getSecondSelectHTML() {
    sResult = "<label for=\"region_hotel\">Bundesland:</label>\n<select name=\"region_hotel\" id=\"region_hotel\" onChange=\"getAreas(this.value)\">\n<option id=\"default_region\" name=\"default_region\" value=\"0\">Bitte w&auml;hlen</option>\n";
    return sResult;
}

function getThirdSelectHTML() {
    sResult = "\n<label for=\"area_hotel\">Skigebiet:</label>\n<select name=\"area_hotel\" id=\"area_hotel\" onChange=\"getCities(this.value)\">\n<option id=\"default_area\" name=\"default_area\" value=\"0\">Bitte w&auml;hlen</option>\n";
    return sResult;
}

function updateThemeBundeslaender(){
    if (requestBL.readyState == 4) {

        var jsondata = eval('(' + requestBL.responseText + ')');
        blandselect = getSecondSelectHTML();

        for(i=0;i<jsondata.blaender.length; i++){
          selected='';
          blandselect += "<option value=\"" + jsondata.blaender[i]['wellness.p_wls_navigation.sec_id'] + "\"" + selected + ">" + jsondata.blaender[i]['wellness.p_wls_navigation.sec_name'] + "</option>";
        }
        blandselect += "</select>\n";

      sDoThis = "document.getElementById('" + sSwapBLName + "').innerHTML = blandselect";
      eval(sDoThis);

      if ( document.getElementById("area_hotel") != null ) {
            disableRegionSelectBox(sFormName, false);
            disableThirdSelectBox(sFormName, true);
            disableCitySelectBox(sFormName, true);
      }
    }
}

function updateBundeslaenderByThemeInitPageLoad(){
    if (requestBL.readyState == 4) {
        var jsondata = eval('(' + requestBL.responseText + ')');
        blandselect = getSecondSelectHTML();

        myRegion = getValueFromURLSearchParameter("region_hotel");
        for(i=0;i<jsondata.blaender.length; i++){
          //CH:Pruefen, ob Parameter mitgegeben wurden und dann selecten
          if ( jsondata.blaender[i]['wellness.p_wls_navigation.sec_id'] == myRegion & myRegion != '') {
            selected=' selected=\"true\" ';
          }
          else {
            selected='';
          }
          blandselect += "<option value=\"" + jsondata.blaender[i]['wellness.p_wls_navigation.sec_id'] + "\"" + selected + ">" + jsondata.blaender[i]['wellness.p_wls_navigation.sec_name'] + "</option>";
        }
        blandselect += "</select>\n";

      sDoThis = "document.getElementById('" + sSwapBLName + "').innerHTML = blandselect";
      eval(sDoThis);

      if ( document.getElementById("area_hotel") != null ) {
          if (myRegion != 0) {
              getAreas(myRegion);
          }
          else {
            disableRegionSelectBox(sFormName, false);
            disableCitySelectBox(sFormName, true);
          }
      }
    }
}

function getAreas(region) {
    createAreaRequest();

    if (-1 != region) {
        var url = "/ajaxGetAreas/" + region;
        arearequest.open("GET", url, true);
        arearequest.onreadystatechange = updateAreaBox;
        arearequest.send(null);
    }
}


function updateAreaBox(){
    if (arearequest.readyState == 4) {

      sDoThis = "document.getElementById('swapArea" + sFormName + "')";
      oElement = eval(sDoThis);
      if ( oElement != null ) {

          var jsondata = eval('(' + arearequest.responseText + ')');
          areaselect = "\n<label for=\"area_hotel\">Ferienregion:</label>\n<select name=\"area_hotel\" id=\"area_hotel\" onChange=\"getCities(this.value)\">\n<option id=\"default_area\" name=\"default_area\" value=\"0\">Bitte w&auml;hlen</option>\n";

          myArea = getValueFromURLSearchParameter("area_hotel");

        if (jsondata.areas != null) {

          for(i=0;i<jsondata.areas.length; i++){
            //CH:Pruefen, ob Parameter mitgegeben wurden und dann selecten
            if ( jsondata.areas[i][0] == myArea ) {
              selected=' selected=\"true\" ';
            }
            else {
              selected='';
            }
            areaselect += "<option value=\"" + jsondata.areas[i][0] + "\"" + selected + ">" + jsondata.areas[i][1] + "</option>";
          }
          areaselect += "</select>\n";
        }

          sDoThis = "document.getElementById('swapArea" + sFormName + "').innerHTML = areaselect";
          eval(sDoThis);

          disableCitySelectBox(sFormName, true);

          if ( oElement != null ) {
            if (myArea != 0) {
              getCities(myArea);
            }
        }
       }
    }
}


function getCities(area) {
    createRequestBL();

    if (0 != area) {
        var url = "/ajaxGetCities/" + area;
        requestBL.open("GET", url, true);
        requestBL.onreadystatechange = updateCityBox;
        requestBL.send(null);
    }
}

function updateCityBox(){
    if (requestBL.readyState == 4) {
        var jsondata = eval('(' + requestBL.responseText + ')');
        cityselect = "\n<label for=\"city_hotel\">Ort(e):</label>\n<select name=\"city_hotel\" id=\"city_hotel\" style=\"height:75px\" multiple>\n<option id=\"default_city\" name=\"default_city\" value=\"0\">Bitte w&auml;hlen</option>\n";

       myCities =getMultipleValuesFromURLSearchParameter("city_hotel");

        for(i=0;i<jsondata.cities.length; i++){
          //CH:Pruefen, ob Parameter mitgegeben wurden und dann selecten
          for(iCity=0;iCity<myCities.length; iCity++){
              if ( jsondata.cities[i][0] == myCities[iCity] ) {
                selected=' selected=\"true\" ';
                break;
              }
              else {
                selected='';
              }
           }
          cityselect += "<option value=\"" + jsondata.cities[i][0] + "\"" + selected + ">" + jsondata.cities[i][1] + "</option>";
        }
        cityselect += "</select>\n";

    if ( document.getElementById("swapCity") != null ) {
          document.getElementById("swapCity").innerHTML = cityselect;
      }
    }
}

function disableRegionSelectBox(sFormname, bDisable) {
    sDoThis = "document." + sFormname + ".region_hotel";
    var oSelect = eval(sDoThis);
    if ( oSelect != null ) {
      oSelect.disabled=bDisable;
   }
}

function disableAreaSelectBox(sFormname, bDisable) {
    sDoThis = "document." + sFormname + ".area_hotel";
    var oSelect = eval(sDoThis);
    if ( oSelect != null ) {
      oSelect.selectedIndex = 0;
      oSelect.disabled=bDisable;
      }
}

function disableCitySelectBox(sFormname, bDisable) {
    sDoThis = "document." + sFormname + ".city_hotel";
    var oSelect = eval(sDoThis);
    if ( oSelect != null ) {
      oSelect.disabled=bDisable;
      oSelect.selectedIndex = 0;
    }

}

