
var _tms_map_;

function print_bubble(id, x, y, lg, layer) {
  var coords = { x: x, y: y };
  _tms_map_.setCenter(coords);
  window.open("index_print" + (lg=="en" ? "_en" : "") + ".php#db_layer="+layer+"&id="+id+"&lg="+lg+"&"+_tms_map_.tmsInterface.getQuery());
}

function tmsInit() {

  _tms_map__params = {
      //bbox: {minx:3292688,miny:5380097,maxx:3779363,maxy:5658655},
      //bbox: {minx:3280025,miny:5306384,maxx:3792026,maxy:5732368},
      bbox: {minx:2860000,miny:5070000,maxx:4150000,maxy:6160000}, //evropa

      _interface:true,
      zoom:0,
      center:"3536025,5519376",
      client_lang:"cz",
      client_type:"default",
      client_mode:"ajax",
      project_type:"default",
      image_path:"/tms/ajax/client/default/images/"
  };
  _tms_map_ = new tmsMap("mapa",_tms_map__params,"_tms_map_");

  /* LOADING INDICATOR */
  if(!document.getElementById('tmsMapLoading')) {
    var loadingDiv = document.createElement('div');
    loadingDiv.id = 'tmsMapLoading';
//    loadingDiv.innerHTML = 'Načítání...';
    loadingDiv.innerHTML = '<img src="./../.././ajax/client/default/images/loading_anim.gif">';
    //loading_anim.gif
//      loadingDiv.style.left=300;
//      loadingDiv.style.top=250;
//      loadingDiv.style.zindex=99999;
    
    document.body.appendChild(loadingDiv);
  }
/* ZOOMBAR */  
  var zoombar_params = {
    visible:1
  };
  _tms_zoombar_ = new tmsLeaf.ZoomBar('zoombar', zoombar_params, '_tms_zoombar_');
  _tms_map_.connectLeaf(_tms_zoombar_);

/* SCALEBAR */  
  var scale_params = {
    visible:1
  };
  _tms_scale_ = new tmsLeaf.Scalebar('scalebar', scale_params, '_tms_scale_');
  _tms_map_.connectLeaf(_tms_scale_);

/* TOC */  
  var _tms_toc__params = {
    visible:1,
    target:'sidebar|1'
  };
  _tms_toc_ = new tmsLeaf.TOC.Simple('sidebar|1', _tms_toc__params, '_tms_toc_');
  _tms_map_.connectLeaf(_tms_toc_);

/* OVERVIEW */  

  var overview_params = {
    visible:1,
    minRatio: 15,
    maxRatio: 35,
    //resolutions: [4,8,16,32,64,128,256,512,1024,2048]
    resolutions: [4096,2048,1024,512,256,128,64,32,16,8]

  };
  _tms_overview_ = new tmsLeaf.Overview('ov', overview_params, '_tms_overview_');
  _tms_map_.connectLeaf(_tms_overview_);

/* COPYRIGHT */
  var copy_params = {
    visible:1
  };
  _tms_copy_ = new tmsLeaf.Copyright('copyright', copy_params, '_tms_copy_');
  
  _tms_map_.connectLeaf(_tms_copy_);

/* PANEL */
  var panel_params = {
    visible:1};
  _tms_panel_ = new tmsLeaf.Panel('panel', panel_params, '_tms_panel_');
  
  _tms_map_.connectLeaf(_tms_panel_);

/* LANG */
  //LANG LINE AT THE TOP
  var lang_line = document.getElementById("header");

  //CZECH
  _lang_czech_ = document.createElement("div");
  _lang_czech_.className = "lang_cz_passive";
  //ENGLISH
  _lang_english_ = document.createElement("div");

  _lang_english_.className = "lang_en_active";_lang_english_.onclick = function(e){
              location.href="index.php?lg=en#"+_tms_map_.tmsInterface.getQuery();
            }
  //GERMAN
  _lang_german_ = document.createElement("div");
  _lang_german_.className = "lang_de_active";_lang_german_.onclick = function(e){
              location.href="index.php?lg=de#"+_tms_map_.tmsInterface.getQuery();
            }
  //POLAND
  _lang_poland_ = document.createElement("div");
  _lang_poland_.className = "lang_pl_active";_lang_poland_.onclick = function(e){
              location.href="index.php?lg=pl#"+_tms_map_.tmsInterface.getQuery();
            }
  var _lang_separator_ = document.createElement("div");
  _lang_separator_.innerHTML = "&nbsp;";
  _lang_separator_.className = "separator";

  lang_line.appendChild(_lang_czech_);
  lang_line.appendChild(_lang_english_);
  lang_line.appendChild(_lang_german_);
  lang_line.appendChild(_lang_poland_);
  
/* SIDEBAR */
  var sidebar_params = {
    visible:1,
    strings:[
              'Skrýt',
              'Zobrazit boční panel'
            ],
    sheets:[
            {
              title:'Mapa',
              default_content:'',
              active:1,
              pre_content:'<b>Mapové vrstvy</b>',
              post_content:'\n    <div id="panel_datalist" class="panel_datalist">\n    <h4>Rychlá nápověda</h4>\n  <ul class="panel_datalist_help">\n      <li>Hledejte <strong>body zájmu</strong> nebo <strong>adresy</strong></li>\n      <li>U <strong>adres</strong> zadejte ulici a číslo, popř. obvod</li>\n      <li>Seznam typů bodů najdete v záložce <strong>Legenda</strong></li>\n      <li>Pro zobrazení adresy v mapě klikněte na nalezený záznam</li>\n    </ul>\n          </div>\n        <div class="copy_info">\n                                          Powered by: <a href="http://www.tmapy.cz/" target="_blank">T-MapServer</a>\n                                          <br><a href="../cuzk_zabaged_copyright.php?t=c&client_lang=cz_iso" target="_cuzk_zabaged_copyright">Podkladová data &copy; ČÚZK</a></div>'
            },
            {
              title:'Hledání',
              pre_content:'',
              default_content:''
            },
            {
              title:'Legenda',
              pre_content:'',
              default_content:'<p><div class=\"filterblock\">RZM10 (1:10 000, WMS ČÚZK)</div><table><tr><td><ul><li><a class="legend" href="./.././ajax/legend/zm10/budovy.gif" style="border-color:black" border=0 target="_blank"\>Sídla a jednotlivé objekty, Porost a využití půdy</a><li><a class="legend" href="./.././ajax/legend/zm10/komunikace.gif" style="border-color:black" border=0 target="_blank">Komunikace, Vodstvo</a><li><a class="legend" href="./.././ajax/legend/zm10/teren.gif" style="border-color:black" border=0 target="_blank">Hranice, Terénní reliéf, Bodová pole, Souřadnicové sítě</a></ul></td></tr><tr><td><a class="legend" href="./.././ajax/legend/dmu25/dmu25.gif" style="border-color:black" border=0 target="_blank">DMÚ 25 (WMS Cenia)</a></td></tr><tr><td><a class="legend" href="./.././ajax/legend/kn/wmskn.gif" style="border-color:black" border=0 target="_blank">WMS KN</a></td></tr></table></p><p><div name="legenda" id="legenda" style="width:260px;overflow:auto;"></div></p>'
            },
            {
              title:'Informace',
              pre_content:'',
              default_content:'\n    <div class="copy_info">\n            <h4>Informace z mapy</h4>\n            <p>Po kliknutí v mapě se v tomto místě vypíší dostupné informace vážící se k místu kliknutí a dané záložce.</p>\n            <p><small><i>Kliknutí do mapy pro podrobnější informace o konkrétním objektu-bodu je doporučeno až od měřítka cca 1:500 000.</i></small></p>\n          </div>'
            }
          ]
  };
  _tms_sidebar_ = new tmsLeaf.Sidebar('sidebar', sidebar_params, '_tms_sidebar_');
  _tms_map_.connectLeaf(_tms_sidebar_);

/* MEASURE */
  var _tms_measure__params = {
    strings: {
        measure_line: 'Vzdálenost', //'Vzdálenost', //label for measuring line
        measure_polygon: 'Plocha' //'Plocha' //label for measuring polygon
    },
    //Optional - custom symbols:
    symbols: {             
        "Point": {
            pointRadius: 4,
            graphicName: "square",
            fillColor: "white",
            fillOpacity: 1,
            strokeWidth: 1,
            strokeOpacity: 1,
            strokeColor: "#333333"
        },
        "Line": {
            strokeWidth: 3,
            strokeOpacity: 1,
            strokeColor: "#DD0000",
            strokeDashstyle: "dash"
        },
        "Polygon": {
            strokeWidth: 2,
            strokeOpacity: 1,
            strokeColor: "#DD0000",
            fillColor: "#DD0000",
            fillOpacity: 0.3
        }
    }
  };
 
 _menu_measure_ = new tmsLeaf.PanelOp({
      content:'Měření'
    }
  ); 
  _menu_measure_.cell.onclick = function(e){
                              _tms_measure_.toggle();
                            };
  _tms_panel_.addOp(_menu_measure_)
 
  //creating object
  _tms_measure_ = new tmsLeaf.Measure('measure', _tms_measure__params, '_tms_measure_');
 
  //connecting to main map
  _tms_map_.connectLeaf(_tms_measure_);

/* INFO */  
  var _tms_info__params = {
    visible:0
  };
  _tms_info_ = new tmsLeaf.Info('sidebar|4', _tms_info__params, '_tms_info_');
  _tms_map_.connectLeaf(_tms_info_);
  
  _tms_map__params.project_type = "prumysl";
  var tmsService_params = {
    path: '/tms/crr_a/prumysl/',
//    resolutions: [4,8,16,32,64,128,256,512,1024]
    resolutions: [1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25]
    //resolutions: [1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.1]
    //resolutions: [1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25],
    
  }
  _tms_map_.addTMSService(tmsService_params);  

/***************************************/
/* SIDEBAR - z duvodu prazdneho stromu temat !!! redefinice*/
  var sidebar_params = {
    visible:1,
    strings:[
              'Skrýt',
              'Zobrazit boční panel'
            ],
    sheets:[
            {
              title:'Mapa',
              default_content:'',
              active:1,
              pre_content:'',
              post_content:'\n    <div id="panel_datalist" class="panel_datalist">\n    <h4>Rychlá nápověda</h4>\n  <ul class="panel_datalist_help">\n      <li>Hledejte <strong>body zájmu</strong> nebo <strong>adresy</strong></li>\n      <li>U <strong>adres</strong> zadejte ulici a číslo, popř. obvod</li>\n      <li>Seznam typů bodů najdete v záložce <strong>Legenda</strong></li>\n      <li>Pro zobrazení adresy v mapě klikněte na nalezený záznam</li>\n    </ul>\n          </div>\n        <div class="copy_info">\n                                          Powered by: <a href="http://www.tmapy.cz/" target="_blank">T-MapServer</a>\n                                          <br><a href="../cuzk_zabaged_copyright.php?t=c&client_lang=cz_iso" target="_cuzk_zabaged_copyright">Podkladová data &copy; ČÚZK</a></div>'
            },
            {
              title:'Hledání',
              pre_content:'',
              default_content:''
            },
            {
              title:'Legenda',
              pre_content:'',
              sheet_index:2,
              default_content:'<p><div class=\"filterblock\">RZM10 (1:10 000, WMS ČÚZK)</div><table><tr><td><ul><li><a class="legend" href="./.././ajax/legend/zm10/budovy.gif" style="border-color:black" border=0 target="_blank"\>Sídla a jednotlivé objekty, Porost a využití půdy</a><li><a class="legend" href="./.././ajax/legend/zm10/komunikace.gif" style="border-color:black" border=0 target="_blank">Komunikace, Vodstvo</a><li><a class="legend" href="./.././ajax/legend/zm10/teren.gif" style="border-color:black" border=0 target="_blank">Hranice, Terénní reliéf, Bodová pole, Souřadnicové sítě</a></ul></td></tr><tr><td><a class="legend" href="./.././ajax/legend/dmu25/dmu25.gif" style="border-color:black" border=0 target="_blank">DMÚ 25 (WMS Cenia)</a></td></tr><tr><td><a class="legend" href="./.././ajax/legend/kn/wmskn.gif" style="border-color:black" border=0 target="_blank">WMS KN</a></td></tr></table></p><p><div name="legenda" id="legenda" style="width:260px;overflow:auto;"></div></p>'
            },
            {
              title:'Informace',
              pre_content:'',
              sheet_index:3,
              default_content:'\n    <div class="copy_info">\n            <h4>Informace z mapy</h4>\n            <p>Po kliknutí v mapě se v tomto místě vypíší dostupné informace vážící se k místu kliknutí a dané záložce.</p>\n            <p><small><i>Kliknutí do mapy pro podrobnější informace o konkrétním objektu-bodu je doporučeno až od měřítka cca 1:500 000.</i></small></p>\n          </div>'
            }
          ]
  };
  _tms_sidebar_ = new tmsLeaf.Sidebar('sidebar', sidebar_params, '_tms_sidebar_');
  _tms_map_.connectLeaf(_tms_sidebar_);
    _tms_sidebar_.switchSheet = function (index,from_action) {
        this.divs.main.removeChild(this.curr_sheet.content);
        for(var i=0; i<this.sheets.length; i++) {
            var sh = this.sheets[i];
            if(i==index) {
                this.curr_sheet = sh;
                sh.active = true;
                sh.menu_item.className = 'sb_active';
                this.divs.main.appendChild(this.curr_sheet.content);
            }
            else {
                sh.active = false;
                sh.menu_item.className = 'sb_pasive';          
            } 
        }
        switch(index) {
            case 2:  //DYNAMICKA LEGENDA
                showLegend();
            break;
            case 3:  //INFORMACE
                if(from_action!="info") {
                    showActInfo();
                }    
            break;
        } 
    };
    
/* SEARCH */
  var search_params = {
    id:6,
    visible:1,
    parent:'sidebar|2',
    strings:[
              'Nic nenalezeno',
              'Nalezeno záznamů',
              '',
              'Zrušit',
              'Hledej'
            ],
    agendas:[
              {
                label:'Adresy',
                results_label:'Nalezeno záznamů:',
                search_example:'<b>Příklady:</b><br> 1) Jungmannova 35 2) město hradec<br>3) ulice hradec 4) Mariánské n*<br><i>Pozn.: * nahrazuje následující znaky</i>',
                path:'/tms/ajax/services/srv_geocode_ftext/',
                id_field:'ID',
                query_field:'FULLTEXT'
                //point_resolution: 8,
                //min_resolution: 4
              },
              {
                label:'Letiště ',
                results_label:'Nalezeno letišť:',
                search_example:'<b>Příklady:</b><br> 1) Vrchlabí 2) Vrch*<br><i>Pozn.: * nahrazuje následující znaky</i>',
                path:'/ost/letiste/',
                id_field:'LETISTE_ID',
                query_field:'NAZEV'
              },
//               {
//                 label:'Kraje ',
//                 results_label:'Nalezeno krajů:',
//                 search_example:'<b>Příklady:</b><br> 1) Hradec 2) Hrad*<br><i>Pozn.: * nahrazuje následující znaky</i>',
//                 path:'/ost/kraje/',
//                 id_field:'NUTS3',
//                 query_field:'NAZEV'
//               },
//               {
//                 label:'Okresy ',
//                 results_label:'Nalezeno okresů:',
//                 search_example:'<b>Příklady:</b><br> 1) Hradec 2) Hrad*<br><i>Pozn.: * nahrazuje následující znaky</i>',
//                 path:'/ost/okresy/',
//                 id_field:'NUTS4',
//                 query_field:'NAZEV'
//               },              
//               {
//                 label:'NUTSII ',
//                 results_label:'Nalezeno NUTS II:',
//                 search_example:'<b>Příklady:</b><br> 1) Praha 2) Pra*<br><i>Pozn.: * nahrazuje následující znaky</i>',
//                 path:'/ost/nuts2/',
//                 id_field:'OBL_NUTS2',
//                 query_field:'NAZEV'
//               },
//               {
//                 label:'Obce&nbsp;s&nbsp;roz.&nbsp;působností ',
//                 results_label:'Nalezeno obcí s rozšířenou působností:',
//                 search_example:'<b>Příklady:</b><br> 1) Hradec 2) Hrad*<br><i>Pozn.: * nahrazuje následující znaky</i>',
//                 path:'/ost/obce_roz/',
//                 id_field:'KODRO3',
//                 query_field:'NAZEV'
//               },              
              {
                label:'Železniční&nbsp;stanice ',
                results_label:'Nalezeno železničních stanic:',
                search_example:'<b>Příklady:</b><br> 1) Hradec 2) Hrad*<br><i>Pozn.: * nahrazuje následující znaky</i>',
                path:'/ost/zel_stan/',
                id_field:'IDCKO',
                query_field:'NAZEV'
              },              
              {
                label:'Hraniční&nbsp;přechody ',
                results_label:'Nalezeno hraničních přechodů:',
                search_example:'<b>Příklady:</b><br> 1) Náchod 2) Ná*<br><i>Pozn.: * nahrazuje následující znaky</i>',
                path:'/ost/hr_prech/',
                id_field:'ID_HR',
                query_field:'NAZEVCZ'
              },
//               {
//                 label:'Pamětihodnosti ',
//                 results_label:'Nalezeno pamětihodností:',
//                 search_example:'<b>Příklady:</b><br> 1) zámek 2) zá*<br><i>Pozn.: * nahrazuje následující znaky</i>',
//                 path:'/ost/pametihodnosti/',
//                 id_field:'ID_LOCAL',
//                 query_field:'NAZEV'
//               },              
              {
                label:'Průmyslové&nbsp;zóny ',
                results_label:'Nalezeno průmyslových zón:',
                search_example:'<b>Příklady:</b><br> 1) hradec 2) hr*<br><i>Pozn.: * nahrazuje následující znaky</i>',
                path:'/ost/prum_zony/',
                id_field:'KOD',
                query_field:'NAZEV'
              },
              {
                label:'Rozvojové&nbsp;plochy ',
                results_label:'Nalezeno rozvojových ploch:',
                search_example:'<b>Příklady:</b><br> 1) hradec 2) hr*<br><i>Pozn.: * nahrazuje následující znaky</i>',
                path:'/ost/rozvoj_plochy/',
                id_field:'ID',
                query_field:'NAZEV'
              },              
              {
                label:'Brownfields ',
                results_label:'Nalezeno brownfieldů:',
                search_example:'<b>Příklady:</b><br> 1) hradec 2) hr*<br><i>Pozn.: * nahrazuje následující znaky</i>',
                path:'/ost/brownfields/',
                id_field:'ID_RIS',
                query_field:'NAZEV'
              },              
//               {
//                 label:'Chr.&nbsp;úz.&nbsp;velkoplošné ',
//                 results_label:'Nalezeno velkoplošných území:',
//                 search_example:'<b>Příklady:</b><br> 1) orlické hory 2) orl*<br><i>Pozn.: * nahrazuje následující znaky</i>',
//                 path:'/ost/chr_uz_vp/',
//                 id_field:'KOD',
//                 query_field:'NAZEV'
//               },
//               {
//                 label:'Chr.&nbsp;úz.&nbsp;malooplošné ',
//                 results_label:'Nalezeno maloplošných území:',
//                 search_example:'<b>Příklady:</b><br> 1) orlické hory 2) orl*<br><i>Pozn.: * nahrazuje následující znaky</i>',
//                 path:'/ost/chr_uz_mp/',
//                 id_field:'KOD',
//                 query_field:'NAZEV'
//               },              
//               {
//                 label:'Turist.&nbsp;oblasti ',
//                 results_label:'Nalezeno turistických oblastí:',
//                 search_example:'<b>Příklady:</b><br> 1) orlické hory 2) orl*<br><i>Pozn.: * nahrazuje následující znaky</i>',
//                 path:'/ost/turistika_obl/',
//                 id_field:'KOD',
//                 query_field:'NAZEV'
//               },
//               {
//                 label:'Turist.&nbsp;regiony ',
//                 results_label:'Nalezeno turistických regionů:',
//                 search_example:'<b>Příklady:</b><br> 1) orlické hory 2) orl*<br><i>Pozn.: * nahrazuje následující znaky</i>',
//                 path:'/ost/turistika_reg/',
//                 id_field:'KOD',
//                 query_field:'NAZEV'
//               },              
              {
                label:'Vodní&nbsp;plochy ',
                results_label:'Nalezeno vodních ploch:',
                search_example:'<b>Příklady:</b><br> 1) rozko 2) ro*<br><i>Pozn.: * nahrazuje následující znaky</i>',
                path:'/ost/vodstvo_plo/',
                id_field:'KOD',
                query_field:'NAZEV'
              },
              {
                label:'Vodní&nbsp;toky ',
                results_label:'Nalezeno vodních toků:',
                search_example:'<b>Příklady:</b><br> 1) labe 2) l*<br><i>Pozn.: * nahrazuje následující znaky</i>',
                path:'/ost/vodstvo_tok/',
                id_field:'KOD',
                query_field:'NAZEV'
              }
//               {
//                 label:'Euroregiony ',
//                 results_label:'Nalezeno euroregionů:',
//                 search_example:'<b>Příklady:</b><br> 1) Náchod 2) Ná*<br><i>Pozn.: * nahrazuje následující znaky</i>',
//                 path:'/ost/euroregiony/',
//                 id_field:'ID',
//                 query_field:'NAZEV'
//               }              
                            
                            
            ],
    results:{
              target:'sidebar|2'
            }
  };
  

//    _tms_search_ = new tmsLeaf.Search.Simple('main_search', search_params, '_tms_search_');
//    _tms_search_.paging_radius = 4;
//    _tms_map_.connectLeaf(_tms_search_);
     
  _tms_search_ = new tmsLeaf.Search.Simple('main_search', search_params, '_tms_search_');
  _tms_search_.paging_radius = 3;
  _tms_search_.tips = document.createElement('div');

/*rychla napoveda ??
  _tms_search_.tips.className = 'tips';
  _tms_search_.tips.innerHTML = '\n    <div id="panel_datalist" class="panel_datalist">\n    <h4>Rychlá nápověda</h4>\n  <ul class="panel_datalist_help">\n      <li>Hledejte <strong>body zájmu</strong> nebo <strong>adresy</strong></li>\n      <li>U <strong>adres</strong> zadejte ulici a číslo, popř. obvod</li>\n      <li>Seznam typů bodů najdete v záložce <strong>Legenda</strong></li>\n      <li>Pro zobrazení adresy v mapě klikněte na nalezený záznam</li>\n    </ul>\n          </div>\n        ';
*/

  _tms_search_.showLoading = function () {
    if(this.result_elem) {
      this.map_obj.sidebar.curr_sheet.content.removeChild(this.result_elem);
      this.result_elem = false;
    }
    if(!this.loading_elem) {
      this.loading_elem = document.createElement('div');
      this.loading_elem.style.textAlign = 'center';
      this.loading_elem.style.width = '100%';
      this.loading_elem.style.position = 'absolute';
      this.loading_elem.style.top = '110px';
      var loading = document.createElement('img');
      loading.src = this.map_obj.image_path+'loading_anim.gif';
      this.loading_elem.appendChild(loading);
      this.map_obj.sidebar.curr_sheet.content.appendChild(this.loading_elem);
    }
  };

  _tms_search_.showResult = function (elem) {
    this.hideLoading();
    var sidebar_sheet = this.map_obj.sidebar.curr_sheet.content;
    if(this.result_elem) {
      sidebar_sheet.removeChild(this.result_elem);
    }
    if(this.tips.on) { 
      sidebar_sheet.removeChild(this.tips);
      this.tips.on = false;
    }
//         this.map_obj.sidebar.setSheetContent(this.params.results.sheet-1,'');
//         this.map_obj.sidebar.curr_sheet.content.appendChild(document.createElement('br'));
    sidebar_sheet.appendChild(elem);
    this.result_elem = elem;
  };
        
  _tms_search_.clearAll = function () {
    if(this.result_elem) {
      var sidebar_sheet = this.map_obj.sidebar.curr_sheet.content;
      sidebar_sheet.removeChild(this.result_elem);
      if(!this.tips.on) {
        sidebar_sheet.appendChild(this.tips);
        this.tips.on = true;
      }
      this.result_elem = false;
    }
    this.clearSelections();
      //NASTRAVENI TEMATICKE VRSTVY NAD OSTATNI - VIDITELNOST
    var serviceIndex_tematic = _tms_map_.getServiceIndex("ajax_prumysl_plochy");
    var service_tematic = this.map_obj.services[serviceIndex_tematic];
    if(service_tematic) {
        service_tematic.cl_params.layer.setZIndex(999);    
    }
  }; 

  _tms_search_.prepareContainer = function () {
    this.content = document.getElementById(this.target);
    var sidebar_sheet = this.map_obj.sidebar.sheets[this.target_sheet-1].content;
    sidebar_sheet.appendChild(this.content);
    sidebar_sheet.appendChild(this.tips);
    this.tips.on = true;
  };

//REDEFINICE SEARCH/SIMPLE - INTERFACE POSILANI DALSICH POLOZEK VE FORMULARI !!!!!
  _tms_search_.goSubmit = function(use_last,iface) { 
      if (this.search_form.value == '') return false;
      if (!this.map_obj.sidebar.expanded) this.map_obj.sidebar.toggle();
      this.map_obj.sidebar.switchSheet(this.params.results.sheet - 1);
      this.showLoading();
      var url = '';
      if (!use_last) {
          if(!iface) {
            this.url_params = {
                path: this.params.agendas[this.curr_ag].path + 'ag_service.php',
                command: 'table',
                pagepos: 0,
                pagesize: 10,
                search_query: this.params.agendas[this.curr_ag].query_field + '=' + this.search_form.value
            };
          }
          else {
            switch(iface) {
                case "4": //prumysl
                case "6": //brownfields
                    this.url_params = {
                        path: this.params.agendas[this.curr_ag].path + 'ag_service.php',
                        command: 'table',
                        pagepos: 0,
                        pagesize: 10,
                        search_query: this.params.agendas[this.curr_ag].query_field + '=' + this.search_form.value + "&KOD=" + this.search_form.value
                    };
                break;
                case "5": //rplochy
                    this.url_params = {
                        path: this.params.agendas[this.curr_ag].path + 'ag_service.php',
                        command: 'table',
                        pagepos: 0,
                        pagesize: 10,
                        search_query: this.params.agendas[this.curr_ag].query_field + '=' + this.search_form.value + "&ID_RIS=" + this.search_form.value
                    };
                break;
            }
          }  
      }
      url = encodeURI((this.createURL(this.url_params)));
      //window.open(url);
      dojo.io.bind({
          url: url,
          encoding: "utf-8",
          load: this.getResult,
          srch_obj: this
      });
  };
  _tms_search_.switchFold = function (ag) {
      this.curr_ag = ag;
      this.clearAll();
      this.write();
  };

  _tms_map_.connectLeaf(_tms_search_);

/* TABS */
function getParamsURL(new_subprj)
{
  var q = '';
  var params = _tms_map_.tmsInterface.getQParams();
  for(var i=0; i<params.length; i++) {
    if(params[i].name.toLowerCase()=='c') {
      q += 'c='+params[i].value+'&';
    }
    else if(params[i].name.toLowerCase()=='z') {
      q += 'z='+_tms_map_.tmsInterface.urlDecode(params[i].value)+'&';
    }
     else if(params[i].name.toLowerCase()=='l') {
       q += 'l='+_tms_map_.tmsInterface.urlDecode(params[i].value);
       if(new_subprj) {
         if(new_subprj=='prumysl') {
           q += ',ajax_prumysl_plochy';
         }
         if(new_subprj=='priroda') {
           q += ',ajax_priroda_plochy';
         }
         if(new_subprj=='turist') {
           q += ',ajax_turist_plochy';
         }
         if(new_subprj=='mikro') {
           q += ',ajax_mikro_plochy';
         }
         if(new_subprj=='euro') {
           q += ',ajax_euro_plochy';
         }
         if(new_subprj=='admin') {
           q += ',ajax_admin_zabaged';
         }
         if(new_subprj=='es') {
           q += ',ajax_es_zabaged';
         }
         if(new_subprj=='eu') {
           q += ',ajax_eu_zabaged';
         }
         if(new_subprj=='imesta') {
           q += ',ajax_imesta_zabaged';
         }
	 if(new_subprj=='default') {
           q += ',ajax_default_zabaged';
         }

       }  
       q += ',cak&';
     }
    else if(params[i].name.toLowerCase()=='hs') {
      q += 'hs='+params[i].value+'&';
    }
    else if(params[i].name.toLowerCase()=='p') {
      //nothing
    }
  }
  return q;        
}

//DEFAULT
_tab_default_ = document.createElement("div");
_tab_default_.innerHTML = "obecná mapa";
//if(_tms_map__params.client_type=='default')

if(_tms_map__params.project_type=='default')
{
    _tab_default_.className = "tab_active";
}
else
{
    _tab_default_.className = "tab_passive";
   _tab_default_.onmouseover = function(e){this.className="tab_over";};
   _tab_default_.onmouseout = function(e){this.className="tab_passive";};

    _tab_default_.onclick = function(e)
    {

        //location.href="index.php?"+_tms_map_.tmsInterface.getQuery();
        q = getParamsURL();
        location.href = './../default/index.php?lg=cz#' + q;
    };
}

//ADMIN
_tab_admin_ = document.createElement("div");
_tab_admin_.innerHTML = "admin. členění";
if(_tms_map__params.project_type=='admin')
{
    _tab_admin_.className = "tab_active";
}
else
{
    _tab_admin_.className = "tab_passive";

   _tab_admin_.onmouseover = function(e){this.className="tab_over";};
   _tab_admin_.onmouseout = function(e){this.className="tab_passive";};
   _tab_admin_.onclick = function(e)
    {
        q = getParamsURL();
        location.href = './../admin/index.php?lg=cz#' + q;
    };
}

//EURO
_tab_euro_ = document.createElement("div");
_tab_euro_.innerHTML = "euroregiony";
if(_tms_map__params.project_type=='euro')
{
    _tab_euro_.className = "tab_active";
}
else
{
    _tab_euro_.className = "tab_passive";
   _tab_euro_.onmouseover = function(e){this.className="tab_over";};
   _tab_euro_.onmouseout = function(e){this.className="tab_passive";};
    _tab_euro_.onclick = function(e)
    {
        q = getParamsURL('euro');
        location.href = './../euro/index.php?lg=cz#' + q;
    };
}

//MIKRO
_tab_mikro_ = document.createElement("div");
_tab_mikro_.innerHTML = "mikroregiony";
if(_tms_map__params.project_type=='mikro')
{
    _tab_mikro_.className = "tab_active";
}
else
{
    _tab_mikro_.className = "tab_passive";
   _tab_mikro_.onmouseover = function(e){this.className="tab_over";};
   _tab_mikro_.onmouseout = function(e){this.className="tab_passive";};
    _tab_mikro_.onclick = function(e)
    {
        q = getParamsURL('mikro');
        location.href = './../mikro/index.php?lg=cz#' + q;
    };
}

//EU
_tab_eu_ = document.createElement("div");
_tab_eu_.innerHTML = "projekty EU";
if(_tms_map__params.project_type=='eu')
{
    _tab_eu_.className = "tab_active";
}
else
{
    _tab_eu_.className = "tab_passive";
   _tab_eu_.onmouseover = function(e){this.className="tab_over";};
   _tab_eu_.onmouseout = function(e){this.className="tab_passive";};
    _tab_eu_.onclick = function(e)
    {
        q = getParamsURL();
        location.href = './../eu/index.php?lg=cz#' + q;
    };
}

//ES
_tab_es_ = document.createElement("div");
_tab_es_.innerHTML = "ekonom. subjekty";
if(_tms_map__params.project_type=='es')
{
    _tab_es_.className = "tab_active";
}
else
{
    _tab_es_.className = "tab_passive";
   _tab_es_.onmouseover = function(e){this.className="tab_over";};
   _tab_es_.onmouseout = function(e){this.className="tab_passive";};
    _tab_es_.onclick = function(e)
    {
        q = getParamsURL();
        location.href = './../es/index.php?lg=cz#' + q;
    };
}

//IMESTA
_tab_imesta_ = document.createElement("div");
_tab_imesta_.innerHTML = "weby obcí";
if(_tms_map__params.project_type=='imesta')
{
    _tab_imesta_.className = "tab_active";
}
else
{
    _tab_imesta_.className = "tab_passive";
   _tab_imesta_.onmouseover = function(e){this.className="tab_over";};
   _tab_imesta_.onmouseout = function(e){this.className="tab_passive";};
    _tab_imesta_.onclick = function(e)
    {
        q = getParamsURL();
        location.href = './../imesta/index.php?lg=cz#' + q;
    };
}

//PRIRODA
_tab_priroda_ = document.createElement("div");
_tab_priroda_.innerHTML = "příroda";
if(_tms_map__params.project_type=='priroda')
{
    _tab_priroda_.className = "tab_active";
}
else
{
    _tab_priroda_.className = "tab_passive";
   _tab_priroda_.onmouseover = function(e){this.className="tab_over";};
   _tab_priroda_.onmouseout = function(e){this.className="tab_passive";};
    _tab_priroda_.onclick = function(e)
    {

        //location.href="index.php?"+_tms_map_.tmsInterface.getQuery();
        q = getParamsURL('priroda');
        location.href = './../priroda/index.php?lg=cz#' + q;
        
    };
}

//TURIST
_tab_turist_ = document.createElement("div");
_tab_turist_.innerHTML = "turistika";
if(_tms_map__params.project_type=='turist')
{
    _tab_turist_.className = "tab_active";
}
else
{
    _tab_turist_.className = "tab_passive";
   _tab_turist_.onmouseover = function(e){this.className="tab_over";};
   _tab_turist_.onmouseout = function(e){this.className="tab_passive";};
    _tab_turist_.onclick = function(e)
    {
        q = getParamsURL('turist');
        location.href = './../turist/index.php?lg=cz#' + q;
    };
}

//PRUMYSL
_tab_prumysl_ = document.createElement("div");
_tab_prumysl_.innerHTML = "rozvojové plochy";
if(_tms_map__params.project_type=='prumysl')
{
    _tab_prumysl_.className = "tab_active";
}
else
{
    _tab_prumysl_.className = "tab_passive";
   _tab_prumysl_.onmouseover = function(e){this.className="tab_over";};
   _tab_prumysl_.onmouseout = function(e){this.className="tab_passive";};
    _tab_prumysl_.onclick = function(e)
    {
        q = getParamsURL('prumysl');
        location.href = './../prumysl/index.php?lg=cz#' + q;
    };
}

document.getElementById('tabs').appendChild(_tab_default_);
document.getElementById('tabs').appendChild(_tab_admin_);
document.getElementById('tabs').appendChild(_tab_euro_);
document.getElementById('tabs').appendChild(_tab_mikro_);
document.getElementById('tabs').appendChild(_tab_eu_);
document.getElementById('tabs').appendChild(_tab_es_);
document.getElementById('tabs').appendChild(_tab_imesta_);
document.getElementById('tabs').appendChild(_tab_priroda_);
document.getElementById('tabs').appendChild(_tab_turist_);
document.getElementById('tabs').appendChild(_tab_prumysl_);

window.name = "TMS_AJAX";
/* METAINFO */
  _tms_metainfo_ = new tmsLeaf.PanelOp({content:'Metainfo'});
  _tms_metainfo_.cell.onclick = function(e){
                              window.open('http://mapy.crr.cz/tgs/metis/pages/listPage.jsf?pageId=metIdsListPage&filterId=gis&identifiers=7,76,77,75');
                            };
  _tms_panel_.addOp(_tms_metainfo_);

/* RIS LINK */
  _tms_ris_ = new tmsLeaf.PanelOp({content:'<div class="ris_link" />'});
  _tms_ris_.cell.onclick = function(e){
                              window.open('http://www.risy.cz');
                            };
  _tms_panel_.addOp(_tms_ris_);

/* CRR LINK */
  _tms_crr_ = new tmsLeaf.PanelOp({content:'<div class="crr_link" />'});
  _tms_crr_.cell.onclick = function(e){
                              window.open('http://www.crr.cz');
                            };
  _tms_panel_.addOp(_tms_crr_);

/* HELP LINK */
  _show_help_ = new tmsLeaf.PanelOp({content:'Nápověda'});
  // _show_help_.cell.style.color = '#DDDDDD';
  // _show_help_.cell.style.cursor = 'default';

  _show_help_.cell.onclick = function(e){
    _lng_help='../help/help_cz.html';    window.open(_lng_help);
  }
  _tms_panel_.addOp(_show_help_);

/* PRINT LINK */
  _tms_print_ = new tmsLeaf.PanelOp({content:'Vytisknout mapu'});
  _tms_print_.cell.onclick = function(e){
  //debugger;
 
        var qpx = _tms_map_.tmsInterface.getQParams();
        var new_params = false;
        if(qpx) {
            for(var px=0;px<qpx.length;px++) {
                var podm = qpx[px]["name"];
                if(podm == "l") {
                    var layers = qpx[px].value.split(",");
                    if(layers.length>1) {
                        var layers_array = [];
                        for(var l=0;l<layers.length;l++) {
                            layers_array[layers[l]] = true;
                        }
                        //SETTING ABSOLUTE LAYERS ONLY - PLANY MEST BUG !!!
                        if(layers_array["plany_mest"]) {
                            new_params += "&l=plany_mest,ajax_prumysl_plochy";
                        } 
                        else {
                            new_params += "&"+qpx[px].name+"="+qpx[px].value;
                        }
                    }
                    else {
                        new_params += "&"+qpx[px].name+"="+qpx[px].value;
                    }
                }
                else {
                    new_params += "&"+qpx[px].name+"="+qpx[px].value;
                }
            }
        }
        else {
            new_params = _tms_map_.tmsInterface.getQuery();
        }
                              //window.open('index_print.php?'+_tms_map_.tmsInterface.getQuery()+'#'+new_params);
                              window.open('index_print.php?'+new_params);
                            };
  _tms_panel_.addOp(_tms_print_); 
  
/* AKTUALITY */
  _tms_aktuality_ = new tmsLeaf.PanelOp({content:'Aktuality'});
    _tms_aktuality_.cell.onclick = function(e){    window.open('../aktuality/aktuality_cz.php');};  
  _tms_panel_.addOp(_tms_aktuality_);

/* FULL EXTENT */
  _tms_fullextent_ = new tmsLeaf.PanelOp({content:'Výřez na celé území'});
  _tms_fullextent_.cell.onclick = function(e){ 
                                var cntr = new _tms_map_.OL.LonLat(3536025, 5519376);
                                _tms_map_.map.setCenter(cntr,1);
                             };
  _tms_panel_.addOp(_tms_fullextent_);

/* CLEAR SELECTION */
  _tms_clearselection_ = new tmsLeaf.PanelOp({content:'Zrušit výběr'});
  _tms_clearselection_.cell.onclick = function(e){
                                _tms_clearselection_.cell.style.color = '#DDDDDD';
                                _tms_clearselection_.cell.style.cursor = 'default';  
//                                 var BBOX = _tms_map_.getBBOX();
//                                 arrayBBOX = BBOX.split(',');
//                                 BBOX = (arrayBBOX[0]+0.5)+','+(arrayBBOX[1]+0.5)+','+(arrayBBOX[2]-0.5)+','+(arrayBBOX[3]-0.5);
//                                 window.frames["map_interface"].location.href = "db_interface.php?FORMAT=ajax&interface=tmv&Theme=clear_sel&BBOX="+BBOX;
                                window.frames["map_interface"].location.href = "db_interface.php?FORMAT=ajax&interface=tmv&Theme=clear_sel";
                             };
  _tms_panel_.addOp(_tms_clearselection_); 
  _tms_clearselection_.cell.style.color = '#DDDDDD';
  _tms_clearselection_.cell.style.cursor = 'default'; 

  // ziskani parametru URL
  //_tms_map_.tmsInterface.getQParam("parametr")
  

//INTERFACE
  if(_tms_map_.tmsInterface.getQParam("Theme") && _tms_map_.tmsInterface.getQParam("Values")) {
    function setInterface() {
      if(document.getElementById("main_search")) {
        _tms_search_.curr_ag = _tms_map_.tmsInterface.getQParam("Theme"); //prumysl=4
        _tms_search_.switchFold(_tms_search_.curr_ag);
        _tms_search_.search_form.value = _tms_map_.tmsInterface.getQParam("Values");
        
//         invisible_search_param = document.createElement('input');
//         invisible_search_param.type = 'hidden';
//         invisible_search_param.name = 'KOD';
//         invisible_search_param.value = _tms_map_.tmsInterface.getQParam("Values");
//         _tms_search_.search_form.appendChild(invisible_search_param);        
        
        _tms_search_.goSubmit(false,_tms_search_.curr_ag);
      }  
      else {
        window.setTimeout(setInterface, 500); //pocka az se nainicializuje v DOM search
      }  
    }
    _tms_sidebar_.switchSheet(1); //prepne zallozku na vyhledavani - inicializace samotne akce
    setInterface();
  }  

//REAKCE NA ZMENU ZOOMU
  _tms_map_.map.events.register('zoomend',null,myZoomReaction);
//REAKCE NA HNUTI S MAPOU
  _tms_map_.map.events.register('moveend',null,myMoveReaction);


//ZAVISLOSTI WMS-KN vs. ORTOFOTO

  _ortofoto_wms_kn_leaf_ = {
   
    afterConnect: function() {},
    
    onServiceSwitched: function(info) 
    {
      var serviceIndex_kn = _tms_map_.getServiceIndex("ajax_wms_kn");
      var service_kn = this.map_obj.services[serviceIndex_kn];
      var serviceIndex_kni = _tms_map_.getServiceIndex("ajax_wms_kn_i");
      var service_kni = this.map_obj.services[serviceIndex_kni];
       
      var serviceIndex_ortorgb1m = _tms_map_.getServiceIndex("ajax_wms_ortorgb1m_sde");
      var service_ortorgb1m = _tms_map_.services[serviceIndex_ortorgb1m];

      //chovani WMS KN nad ORTOFOTO WMS CENIA
      if(service_ortorgb1m.params.visible)
      {
        if(service_kn.params.visible)
        {
        //prepne WMS-KN na inverzni a prenese ORTOFOTO do spodni vrstvy pod BASE
          _tms_map_.switchService(serviceIndex_kni,false,false);
          service_ortorgb1m.cl_params.layer.setZIndex(100);
          service_kni.cl_params.layer.setZIndex(900);
          _tms_toc_.refresh();
        }
        else
        { 
          if(service_kni.params.visible)
          {
            service_ortorgb1m.cl_params.layer.setZIndex(100);
            service_kni.cl_params.layer.setZIndex(900);
          }
          else
          {
            service_ortorgb1m.cl_params.layer.setZIndex(900);
          }
        }
      }
      else
      {
        if(service_kni.params.visible)
        {
        //prepne WMS-KN inverzni zpet na neinverzni        
          _tms_map_.switchService(serviceIndex_kn,false,false);
          _tms_toc_.refresh();
        }
      }

      //NASTRAVENI TEMATICKE VRSTVY NAD OSTATNI - VIDITELNOST
      //debugger;
        var serviceIndex_tematic = _tms_map_.getServiceIndex("ajax_prumysl_plochy");
        var service_tematic = this.map_obj.services[serviceIndex_tematic];
        service_tematic.cl_params.layer.setZIndex(999);      
      
    }
     
  };
  
  _tms_map_.connectLeaf(_ortofoto_wms_kn_leaf_);
  
  
//WAITLAYER NAD MAPOU
  _tms_map_.map.showLoading = function () {
    if(!this.loading_elem) {
      this.loading_elem = document.createElement('div');
      this.loading_elem.style.textAlign = 'center';
      this.loading_elem.style.width = '100%';
      this.loading_elem.style.position = 'absolute';
      this.loading_elem.style.top = '110px';
      var loading = document.createElement('img');
      loading.src = this.map_obj.image_path+'loading_anim.gif';
      this.loading_elem.appendChild(loading);
    }
  }; 
  //PRETIZENI METODY ONWINDOWRESIZE - VIZUALIZACE OBJEKTU V SIDEBAR
  dojo.event.connect(window, 'onresize', this, 'onWindowResize');
  //VYVOLANI PRVOTNIHO NASTAVENI ZOBRAZENI OBJEKTU V SIDEBAR (FOTOGALERIE, PODROBNE INFORMACE) - INIT
  initSidebarObject();   

  _tms_map_.handleInterfaceResponse = function(intResponse) {
      var clear_selection = window.top._tms_clearselection_;
      if(clear_selection) {
                 clear_selection.cell.style.color = "#00466B";
                 clear_selection.cell.style.cursor = "pointer";
      }
      
      _tms_map_.setBBOX(intResponse.bbox);
      var id = _tms_map_.getServiceIndex(intResponse.service);
      if(_tms_toc_ && !_tms_map_.services[id].params.visible) {
        _tms_toc_.switchServiceMap(id,true);
      }
  }   
  
}

function myMoveReaction() {
    //showActInfo(); 
}

function myZoomReaction() {

  var resolution = _tms_map_.map.getResolution();  
  if(_tms_map_.lastResolutionReaction && _tms_map_.lastResolutionReaction == resolution) {
    return false;
  }
  _tms_map_.lastResolutionReaction = resolution;
  
  var serviceIndex_default = _tms_map_.getServiceIndex("ajax_prumysl");
  var serviceIndex_zabaged = _tms_map_.getServiceIndex("zabaged_tile");
  var serviceIndex_kn = _tms_map_.getServiceIndex("ajax_wms_kn");

  var serviceIndex_zm10 = _tms_map_.getServiceIndex("ajax_wms_zm10");
  var serviceIndex_dmu25 = _tms_map_.getServiceIndex("ajax_wms_dmu25");
  var serviceIndex_ortorgb1m = _tms_map_.getServiceIndex("ajax_wms_ortorgb1m_sde");

  if( resolution <= 1 ) //PREPNUTI NA WMS-KN
  {
    //nucene vypnuti zm10
    var service_zm10 = _tms_map_.services[serviceIndex_zm10];
    if(service_zm10.params.visible) {
      _tms_map_.switchServiceOff(service_zm10,false,false);
      _tms_toc_.refresh();
    }
    //nucene vypnuti dmu25
    var service_dmu25 = _tms_map_.services[serviceIndex_dmu25];
    if(service_dmu25.params.visible) {
      _tms_map_.switchServiceOff(service_dmu25,false,false);
      _tms_toc_.refresh();
    }
    
    var service_kn = _tms_map_.services[serviceIndex_kn];
    var service_ortorgb1m = _tms_map_.services[serviceIndex_ortorgb1m];
    if(!service_kn.params.visible && !service_ortorgb1m.params.visible)
    {
    _tms_map_.switchService(serviceIndex_kn,false,false);
    _tms_toc_.refresh();
    }
  }
  else if( resolution <= 4 )  //PREPNUTI NA ZABAGED
  {
    var service_zabaged = _tms_map_.services[serviceIndex_zabaged];
    if(!service_zabaged.params.visible)
    {
    _tms_map_.switchService(serviceIndex_zabaged,false,false);
    _tms_toc_.refresh();
    }
  }
  else //PREPNUTI NA SHOCART
  {
    var service_default = _tms_map_.services[serviceIndex_default];
    if(!service_default.params.visible)
    {
    _tms_map_.switchService(serviceIndex_default,false,false);
    _tms_toc_.refresh();
    }
  }  
//TODO IN CODE - OPENLAYRES - ? - VYPNUTI WMS V MERITCICH, KTERE JIZ NEZOBRAZUJI  
  if( resolution > 2 ) //VYPNUTI VRSTEV NAD ROZLISENIM 2
  {
    //WMS ORTOFOTO CENIA
    var serviceIndex_ortorgb1m = _tms_map_.getServiceIndex("ajax_wms_ortorgb1m_sde");
    var service_ortorgb1m = _tms_map_.services[serviceIndex_ortorgb1m];
    if(service_ortorgb1m.params.visible)
    {
      _tms_map_.switchService(serviceIndex_ortorgb1m,false,false);
      _tms_toc_.refresh();
    }  
    //WMS VOJENSKE MAPY
    var serviceIndex_2vojmap = _tms_map_.getServiceIndex("ajax_wms_2vojmap");
    var service_2vojmap = _tms_map_.services[serviceIndex_2vojmap];
    if(service_2vojmap.params.visible)
    {
      _tms_map_.switchService(serviceIndex_2vojmap,false,false);
      _tms_toc_.refresh();
    }  
  }
  if( resolution > 3 ) //VYPNUTI VRSTEV NAD ROZLISENIM 3
  {
    //TMS PLANY MEST
    var serviceIndex_planym = _tms_map_.getServiceIndex("plany_mest");
    var service_planym = _tms_map_.services[serviceIndex_planym];
    if(service_planym.params.visible)
    {
      _tms_map_.switchService(serviceIndex_planym,false,false);
      _tms_toc_.refresh();
    }  
  }  
  
  if( resolution > 4 ) //VYPNUTI VRSTEV NAD ROZLISENIM 2
  {
    //WMS ZM10
    var serviceIndex_zm10 = _tms_map_.getServiceIndex("ajax_wms_zm10");
    var service_zm10 = _tms_map_.services[serviceIndex_zm10];
    if(service_zm10.params.visible)
    {
      _tms_map_.switchService(serviceIndex_zm10,false,false);
      _tms_toc_.refresh();
    }  
    //WMS DMU25
    var serviceIndex_dmu25 = _tms_map_.getServiceIndex("ajax_wms_dmu25");
    var service_dmu25 = _tms_map_.services[serviceIndex_dmu25];
    if(service_dmu25.params.visible)
    {
      _tms_map_.switchService(serviceIndex_dmu25,false,false);
      _tms_toc_.refresh();
    }  
  }

  showLegend();
  //showActInfo(); 

  }
//PREPNUTI VYHLEDAVACE NA DEFAULT K DANEMU PODPROJEKTU
function setSearchAg() { 
    if(document.getElementById("main_search")) {
        _tms_search_.switchFold(5);
    }  
    else {
        window.setTimeout(setSearchAg, 500); //pocka az se nainicializuje v DOM search
    }  
}
setSearchAg();

//DYNAMICKA LEGENDA new
function showLegend() {
    if(_tms_map_.mapLoading) {
        window.setTimeout(showLegend, 500);
    }
    else {
        showLegendAJAX();
    }    
}

function showLegendAJAX() {
    if(_tms_sidebar_) {
        if(_tms_sidebar_.curr_sheet.sheet_index && _tms_sidebar_.curr_sheet.sheet_index==2) {
            var m_width = _tms_map_.map.size.w;
            var m_height = _tms_map_.map.size.h;
            var m_BBOX = _tms_map_.getBBOX();
            var m_url = _tms_map_.tms_map_url;
            var m_lang = _tms_map_.client_lang;
            var m_map = _tms_map_.map.baseLayer.name;
            var url_legend = _tms_map_.tms_path+"legend.php?WIDTH="+m_width+"&HEIGHT="+m_height+"&BBOX="+m_BBOX+"&MAP="+m_map+"&client_lang="+m_lang;

            dojo.io.bind({
                url: url_legend,
                encoding: "utf-8",
                load: getAjaxLegend
            });
        }
    }
}
function getAjaxLegend (type, data, event, kwArgs) {
      var frm_lg = document.getElementById("legenda");
      if(frm_lg) {
            frm_lg.innerHTML = data;
      }
}

function showActInfo() {
    if(_tms_sidebar_) {
        if(_tms_sidebar_.curr_sheet.sheet_index && _tms_sidebar_.curr_sheet.sheet_index==3) {
            var px = _tms_map_.getCenter();
            var q_layers_arr = [];
            for (var i = 0; i < _tms_map_.services.length; i++) {
                var curr_s = _tms_map_.services[i];
                if (!curr_s.params.visible) continue;
                q_layers_arr.push(curr_s.params.name);
                q_layers_arr = q_layers_arr.concat(curr_s.visLayers);
            }
            var q_layers = q_layers_arr.join(',')
            var bbox = _tms_map_.getBBOX();
            var width = _tms_map_.div.offsetWidth;
            var height = _tms_map_.div.offsetHeight;
            var info_url = encodeURI(_tms_map_.tms_path + 'info.php?FORMAT=ajax&QUERY_LAYERS=' + q_layers + '&BBOX=' + bbox + '&WIDTH=' + width + '&HEIGHT=' + height + '&client_lang=' + _tms_map_.client_lang + '&client_type=' + _tms_map_.client_type);

            dojo.io.bind({
                url: info_url,
                encoding: "utf-8",
                load: _tms_info_.writeResult,
                q_layers: q_layers,
                event: "",
                this_obj: _tms_info_
            });
        }
    }
    else {
        window.setTimeout(showActInfo, 500);
    }
}
  

//NASTRAVENI TEMATICKE VRSTVY NAD OSTATNI - VIDITELNOST
// function setTematicLayerVisible() {
// debugger;
    // if(this._tms_map_) {
        // var serviceIndex_tematic = this._tms_map_.getServiceIndex("ajax_prumysl_plochy");
        // var service_tematic = this.map_obj.services[serviceIndex_tematic];
        // service_tematic.cl_params.layer.setZIndex(999);
    // }  
    // else {
        // window.setTimeout(setTematicLayerVisible, 500); //pocka az se nainicializuje _tms_map_
    // }
// }
// setTematicLayerVisible();
//NASTAVENI ZOBRAZENI OBJEKTU V SIDEBAR (PODROBNE INFORMACE) - ZMENA VELIKOSTI MAP OKNA
function onWindowResize(e) {
  _tms_map_.propagateEvent('windowResize', e);
  checkSidebarHeight();
}

//PRVOTNI NASTAVENI ZOBRAZENI OBJEKTU V SIDEBAR (FOTOGALERIE, PODROBNE INFORMACE) - INIT
function initSidebarObject() {
    if(window.document.getElementById('panel_datalist')) {
        checkSidebarHeight();
    }
    else {
        window.setTimeout(initSidebarObject, 500);
    }
}

function checkSidebarHeight() {
    var obj_panel_datalist = window.document.getElementById('panel_datalist');
    
    //KONTROLA MOZNOSTI VIZUALIZACE OBJEKTU PODROBNE INFORMACE
    if(_tms_sidebar_.div.clientHeight < 510) {
        if(obj_panel_datalist) {
            obj_panel_datalist.style.visibility = "hidden";
        }
    }
    else {
        if(obj_panel_datalist) {
            obj_panel_datalist.style.visibility = "visible";
        }
    }
}
