
// GLOBÁLNÍ PROMĚNNÉ
  
  T_NEAREST_ERROR_1 = 'Žádný záznam neodpovídá zadání.';
  T_NEAREST_ERROR_2 = 'Vrstva není na tomto území k dispozici.';
  
  T_NEAREST_START = 'Probíhá hledání...';
  
  T_POPUP_CENTER = 'Centrovat &raquo;';
  T_POPUP_MAX = 'Maximální detail mapy &raquo;';
  T_POPUP_200 = 'Mapa 1 : 200 000';
  T_POPUP_DETAIL = 'Detail objektu &raquo;';
  T_TITLE_MORE = '(více)';
  
  T_TITLE_TEL = 'Tel.:&nbsp;';
  T_TITLE_FAX = 'Fax.:&nbsp;';

  T_TITLE_PROV_DOBA = 'Provozní doba:';
  T_TITLE_PO = 'Po';  
  T_TITLE_UT = 'Út';  
  T_TITLE_ST = 'St';  
  T_TITLE_CT = 'Čt';  
  T_TITLE_PA = 'Pa';  
  T_TITLE_SO = 'So';  
  T_TITLE_NE = 'Ne';
  T_TITLE_UMISTENI = 'Umístění:&nbsp;'
  T_TITLE_ZAVRENO = 'zavřeno';
  T_DETAIL_MORE_INFO = 'Více informací';
  T_TITLE_CONTACT_PERSON = 'Kontaktní osoby';
  T_TITLE_MEMBERSHIP_LIST = 'Seznam členů IO';
  T_TITLE_DISTRIBUTION_TRACE = 'Rozvozové trasy:';
  T_TITLE_PONDELI = 'Pondělí:';  
  T_TITLE_UTERY = 'Úterý:';  
  T_TITLE_STREDA = 'Středa:';  
  T_TITLE_CTVRTEK = 'Čtvrtek:';  
  T_TITLE_PATEK = 'Pátek:';  


  var NG_SEARCH_NEAREST = null; //ukazatel na třídu vyhledávání

/*
 * funkce vrátí objekt podle idéčka zadaného řetězcem
 */ 
function ngNearestFnc_GEBI(id) {
  if (typeof(id=='string')) {
    var o = document.getElementById(id);
    if (o) return o;
  }

  return false;
}

/*
 * funkce zjistí zda je proměnná typu string a zda není prázdná
 */ 
function ngNearestFnc_ST(s) {
  if (typeof(s)=='string')
    if (s!= '') return true;

  return false;
}

/*
 * funkce zjsití zda je proměnná definovaná a je true
 */ 
function ngNearestFnc_DT(o) {
  if (typeof(o)!= 'undefined')
    if (o) return true;

  return false;
}

/*
 * funkce zjistí zda je "p" object a zda je nadefinován
 */ 
function ngNearestFnc_OT(p) {
  if (typeof(p)=='object')
    if (p) return true;

  return false;
}


/*
 * třída obsahující vlastnosti použité pro vyhledávání
 */ 
function ngGuiNearestApi() {

  // --- vlastnosti
  this.country = 'CR'; //stát ve kterém se provádí vyhledání adresy
  this.lang='cz';
  this.nearest = null;
  this.dynamicCntLine = true; //proměnný počet řádku, které má navrátit vyhledávání
  this.pageSize = 0; //počet řádků, které má vyhledávání vrátit
  this.id = ''; //element pro celé výsledky vyhledávání
  this.errorId = ''; //element pro errorovou hlášku
  this.ulId = ''; //element pro seznam výsledků
  this.counterId = ''; //element pro počítadlo
  this.btnPrevId = ''; //idéčko tlačítka previous
  this.btnNextId = ''; //idéčko tlačítka next
  this.locateIcon = ''; //ikonka, která se zobrazuje nad místem nad mapou

  this.idDetail = ''; //element pro detail jednoho výsledku hledání 
  this.errorIdDetail = ''; 
  this.ulIdDetail = '';
  
  this.title_nearest = ''; //titulek právě hledaných objektů nearest
  this.title_detail_id = '';
  this.title_detail_nearest = '';
  this.is_scroll_detail = false; //nemá se skrolovat na zobrazený výsledek
  this.current_detail = false;
  this.current_detail_id = ''; //idéčko načteného detailu
  this.current_detail_nearest = ''; // typ načteného detailu

//  this.resultsWindow = null; // ukazatel na okno ve kterém jsou výsledky
  this.onBeforeStart = false; //funkce prováděná před začátkem vyhledávání
  this.onBeforeStartDetail = false; //funkce prováděná před začátkem vyhledávání detailu

  this.listIconUrl = ''; //počátek URL obrázku
  this.listIconStart = 0; //počáteční číslo ikony
  this.listIconMax = 0; //počet obrázku
  this.listIconUrlSuffix = ''; //koncovka
  this.listIconWidth = 0; //šířka ikony
  this.listIconHeight = 0; //výška ikony
  this.counterVisible = 0; //ukazatel zda je zobrazen tag s počítadlem / stránkovadlem
  
  //hodnoty posunutí odrážky v seznamu výsledků (UL)  
  this.imgWidth = 0; //odsunutí textu v pravo aby nebyla zmizelá odrážka
  this.imgHeight = 0; //odsunutí textu od odrážky směrem nahoru
  this.imgShift = 0; //velikost odsunutí mezi odrážkou a textem
  this.leftSpacing = 0; //odsazení zleva
  this.rightSpacing = 0; //odsun ukončení řádku od pravého okraje
  this.lineSpacing = 3; //mezera mezi řádky
  this.bottomSpacing = 0; //šířka řádku pod textem
  
  this.moreShift = 0; //levé odsunutí odkazu "více"
  this.distShift = 0; //levé odsunutí výpisu distance
  
  //margin okraje seznamu výsledků (UL)
  this.marginUl_T = 0;
  this.marginUl_R = 0;
  this.marginUl_B = 0;
  this.marginUl_L = 0;
  
  this.classOdd = '';
  this.classEven = '';
  this.classOverText = '';
  this.classOutText = '';
  this.classOverTextMore = '';
  this.classOutTextMore = '';
  this.classOverTextDist = '';
  this.classOutTextDist = '';
  this.classNameText = '';
  this.classActiveLine = '';
  this.activeLineKey = ''; //klíč vybraného řádku z výsledků vyhledávání
  this.classDistText = '';
   
  // --- funkce
  this.searchNearest = ngNearestFnc_searchNearest; //provede vyhledání nearest
  this.detail = ngNearestFnc_searchDetail; //vyhledá detail
  this.setNearest = ngNearestFnc_setNearest; //nastavím si ukazatel na třídu vyhledávání
  this.displayNearestResults = ngNearestGui_displayNearestResults; //funkce složí výsledky do seznamu UL a zobrazího
  this.displayDetailResults = ngNearestGui_displayDetailResults; //funkce složí výsledky do seznamu UL a zobrazího
  this.displayNearestError = ngNearestGui_displayNearestError; //funkce vypíše error, když se nepodařilo nalézt žádný výsledek
  this.displayDetailError = ngNearestGui_displayDetailError; //funkce vypíše error, když se nepodařilo nalézt žádný výsledek
  this.nearestPopupMenu = ngNearestGui_popupMenu; //funkce skládá popup okno, pro výsledky vyhledávání
  this.setResults = ngNearestGui_setResults; //nastaví výsledky do některého z DIV elementů
  this.setResultsDetail = ngNearestGui_setResultsDetail; //nastaví výsledky detailu do některého z DIV elementů
  this.setNearestParams = ngNearestGui_setNearestParams; //funkce nastaví parametry vyhledávání
  this.addResults = ngNearestGui_addResults; //funkce nastaví a přidá výsledky
  this.addResultsDetail = ngNearestGui_addResultsDetail; //funkce nastaví a přidá výsledky
  this.addCounter = ngNearestGui_addCounter; //funkce nastaví a přidá počítadlo / paging
  this.setResultsTextClass = ngNearestGui_setResultsTextClass; //nastavím CSS třídu pro vypsané výsledky
  this.setErrorTextClass = ngNearestGui_setErrorTextClass; //nastavím CSS třídu boxu pro vypisování chybových hlášek
  this.setResultsTextImg = ngNearestGui_setResultsTextImg; //nastavím odrážku výsledkům vyhledávání
  this.setColor2ResultsTextUnderline = ngNearestGui_setColor2ResultsTextUnderline; //nastavím podtržení a barvu podtržení vypsaných výsledků
  this.setUlMargin = ngNearestGui_setUlMargin; //nastavím margin okraje seznamu UL
  this.getResultCntLine = ngNearestGui_getResultCntLine; //funkce vrátí počet řádků, které chci aby vrátil výsledek vyhledání
  this.setResultsTextWithoutImg = ngNearestGui_setResultsTextWithoutImg; //nastavím seznam UL bez odrážek
  this.setLineSpacing = ngNearestGui_setLineSpacing; //nastaví mezeru mezi řádky
  this.setRightSpacing = ngNearestGui_setRightSpacing; //nastaví odsazení konce řádku od pravého okraje seznamu UL
  this.setLeftSpacing = ngNearestGui_setLeftSpacing; //nastaví odsazení konce řádku od pravého okraje seznamu UL
  this.setBottomSpacing = ngNearestGui_setBottomSpacing; //nastaví šířku řádku pod textem
  this.setMoreDistSpacing = ngNearestGui_setMoreDistSpacing; //odsunutí příkazu více a vypsaného distance 
  this.setOddAndEvenLine = ngNearestGui_setOddAndEvenLine; //nastaví střídající se vlastnosti lichému a sudému řádku
  this.setOverOutText = ngNearestGui_setOverOutText; //nastaví CSS třídy, které se aktivují po najetí / odjetí myše nad/z textu
  this.setOverOutTextMore = ngNearestGui_setOverOutTextMore;
  this.setOverOutTextDist = ngNearestGui_setOverOutTextDist;
  this.setClassActiveLine = ngNearestGui_setClassActiveLine; //nastavím CSS třídu vybranému výsledku hledání
  this.setClassLi = ngNearestGui_setClassLi; //funkce sestaví CSS třídy pro jeden řádek výsledku
  this.setClassText = ngNearestGui_setClassText; //funkce sestaví CSS třídy pro text jednoho výsledku
  this.setClassTextMore = ngNearestGui_setClassTextMore;
  this.setClassTextDist = ngNearestGui_setClassTextDist;
  this.setActiveLine = ngNearestGui_setActiveLine; //funkce nastaví řádku výsldku do formy aktivný vybrené řádky, ale neprovádí lokalizaci vyhledané oblasti
  this.setLocateIcon = ngNearestGui_setLocateIcon; //funkce nastaví adresu ikonky, která se zobrazuje v mapě na vyhledaným místem
  this.setPageSize = ngNearestGui_setPageSize; //funkce nastaví pevný počet ádků, která má navracet vyhledávání
  this.setNearestIcon = ngNearestGui_setNearestIcon; //funkce nastaví URL adresu pro ikonky do seznamu výsledků hledání nejbližších
  this.clearDisplayedItems = ngNearestGui_clearDisplayedItems; //smaže ikonky s mapy
  this.addDetailIcon = ngNearestGui_addDetailIcon;
  this.razdva = 'dsada';
  
  this.createBtn = ngNearestGui_createBtn; //funkce vytvoří tlačítkla next a previous
  
  // ********** funkce pro stránkování výsledky ************* //
  this.nextPage = ngNearestGui_nextPage;
  this.prevPage = ngNearestGui_prevPage;
  
  this.LocateItem = ngNearestGui_LocateItem; //obslouží vybrání výsledku (zobrazí výsledek nad mapou)
  this.LocateItems = ngNearestGui_LocateItems; //zobrazí všechny výsledky nad mapou
  
  // --- event
  this.onStartNearest = ngNearestFnc_startNearest; //funkce, která se provede po začátku vyhledávání
  this.onStartDetail = ngNearestFnc_startDetail; //funkce, která se provede po začátku vyhledávání detailu
  
  this.sizeRefresh = ngNearestGui_sizeRefresh; //přepočítá rozmístění výsledků a počítadla
  this.sizeRefreshDetail = ngNearestGui_sizeRefreshDetail;
}


/*
 * funkce nahradí mezeru html znakem &nbsp;
 */ 
function ngNearestFnc_controlText(t) {
  var s = '';
  var ch = 0;
  for(var i=0; i < t.length;i++) {
    ch =t.charAt(i); 
    if (ch == ' ') s +='&nbsp;';
    else s += ch;
  }

  return s;
}





/*
 * funkce provede vyhledání
 * i ... rozlišuje mezi (cmdline, advanced, highway) druhem vyhledávání 
 */ 
function ngNearestFnc_searchNearest(pos, nearest, keylist, titleNearest) {
  if (this.nearest) {
    this.title_nearest = titleNearest;
    this.setNearestParams(); //nestavím počet řádků, které chci aby vrátil výsledek vyhledávání
    this.nearest.Nearest(pos, nearest, keylist, this.country, this.lang);
  }

  return;
}


/*
 * funkce vyhledá detail jednoho objektu
 */ 
function ngNearestFnc_searchDetail(id, isScroll) {
  if (this.nearest) {
    var li = this.nearest.LocateIconId+'_';
    var i = li.length;
    if (i>0) id = id.substring(i); //získám idéčko do DB
    var near = '';
    if (ngNearestFnc_OT(this.nearest.NearestDS))
      if (ngNearestFnc_OT(this.nearest.NearestDS.Params))
        near = this.nearest.NearestDS.Params.Nearest; //získám klíč hledaného typu objektu nearest
    this.title_detail_id = id;
    this.title_detail_nearest = near;
    if ((typeof(isScroll)!='undefined')&&(isScroll)) this.is_scroll_detail = true;
    else this.is_scroll_detail = false;
    this.nearest.Detail(id, near, this.country, this.lang);
  }
}




/*
 * funkce nastaví třídu která provádí své vlastní vyhledávání
 */ 
function ngNearestFnc_setNearest(nr) {
  if (typeof(nr)=='object') {
    if (nr) {
      this.nearest = nr;
      NG_SEARCH_NEAREST = nr;
      nr.PageSize = this.pageSize; //číslo udávající počet řádků, které má vyhledávání vrátit
      var w = this;
      if (this.locateIcon!='') nr.LocateIcon = this.locateIcon;
      nr.LoadIcon(this.listIconUrl, this.listIconUrlSuffix, this.listIconStart, this.listIconMax, Math.round(this.listIconWidth/2), Math.round(this.listIconHeight/2)); //url, koncovka url, počátek a konec čísel ikonek, hotspotX, hotspotY 
      nr.OnNearestSearch = function(o) { return w.onStartNearest(o); } //funkce která se provede po začátku vyhledávání ... (přesýpací hodiny + smazání předchozích výsledků)
      nr.OnNearestResults = function(o, p, loc) { return w.displayNearestResults(o, p, loc); } //vypsání výsledků  
      nr.OnNearestError = function(err, p) { return w.displayNearestError(err, p); }
      nr.OnItemPopupMenu = function(map, ic) { return w.nearestPopupMenu(map, ic); }
      nr.OnDetailSearch = function(o) { return w.onStartDetail(o); }
      nr.OnDetailResults = function(o, p) { return w.displayDetailResults(o, p); } //vypsání výsledků  
      nr.OnDetailError = function(err, p) { return w.displayDetailError(err, p); }
    }
  }
        
  return;
}

/*
 * nastaví výsledky do HTML elementu (přidá DIV pro error, UL pro výsledky a DIV pro counter)
 * id ... element do kterého vkládám výsledky
 * fce ... fce provedená při startu hledání  
 */   
function ngNearestGui_setResults(id, fce) {
  var o = ngNearestFnc_GEBI(id);
  var t = '';
  if (o) {
//    if ((typeof(w)=='object')&&w) this.resultsWindow = w;
    if (typeof(fce)=='function') this.onBeforeStart = fce;
    this.id = id;
    this.errorId = id + '_error';
    this.ulId = id + '_ul';
    this.counterId = id + '_counter';
//    this.counterPagerId = this.counterId + '_pager';
    t = '<div id="'+this.errorId+'" style="position:absolute;"></div><ul id="'+this.ulId+'" style="overflow:auto;position:absolute;margin:0;"></ul><div style="position:absolute;" class="counter" id="'+this.counterId+'"></div><div id="nearest_scroll">nearest_scroll</div>';
    o.innerHTML = t; //přidám prvky do HTML elementu

    // přidám tlačítka do počítadla
    /*
    this.nextCmd = new ngGuiUseCmd_typButtonText(null,'next', 'over', this.counterId); //tlačítko next
    this.prevCmd = new ngGuiUseCmd_typButtonText(null, 'prev', 'over', this.counterId); //tlačítko předchozí
    */
  }

  return;
}

/*
 * nastaví výsledky do HTML elementu (přidá DIV pro error, DIV pro výsledky)
 * id ... element do kterého vkládám výsledky
 * fce ... fce provedená při startu hledání  
 */   
function ngNearestGui_setResultsDetail(id, fce) {
  var o = ngNearestFnc_GEBI(id);
  var t = '';
  if (o) {
    if (typeof(fce)=='function') this.onBeforeStartDetail = fce;
    this.idDetail = id;
    this.errorIdDetail = id + '_error';
    this.ulIdDetail = id + '_ul';
    t = '<div id="'+this.errorIdDetail+'" style="position:absolute;"></div><div id="'+this.ulIdDetail+'" style="overflow:auto;position:absolute;margin:0;"></div><div id="nearestdetail_scroll">nearestdetail_scroll</div>';
    o.innerHTML = t; //přidám prvky do HTML elementu
  }

  return;
}


/*
 * funkce spuštěná po začátku vyhledávání
 */ 
function ngNearestFnc_startNearest(nearest) {
  this.activeLineKey = '';

  var o = ngNearestFnc_GEBI(this.ulId);
  if (o) o.style.display='none'; //schovám seznam s výsledky
  var c = ngNearestFnc_GEBI(this.counterId);
  if (c) c.style.display='none'; //schovám počítadlo
  var e = ngNearestFnc_GEBI(this.errorId);
  if (e) {
    e.style.display='block'; //zobrazím error
    e.innerHTML = T_NEAREST_START;
    this.sizeRefresh(); //nastavím umístění erroru do celého okna
  }
  
  var isScroll = false;
  // skroluj jen pokud nebylo stištěno NEXT nebo PREVIOUS
  if((typeof(nearest['NearestDS'])=='object')&&(nearest['NearestDS'])) {
    if ((nearest.NearestDS.Params.NextVisible==false)&&(nearest.NearestDS.Params.PrevVisible==false)) isScroll='scroll';
  }
  if (typeof(this.onBeforeStart)=='function') this.onBeforeStart(this, isScroll); //fce zobrazí panel pro výsledky vyhledávání
//  if ((typeof(this.resultsWindow)=='object')&&this.resultsWindow) { //zjistí zda jsou výsledky v okně
//    if (!this.resultsWindow.display) this.resultsWindow.setDisplay(true, true); //je zavřené okno pro výsledky, zobrazího
//  }
  // TODO, přepni se na panel

  //TODO ... pokud je zavřené okno s výsledky tak ho zobraz

  return true; //musím vracet true, jinak se neprovede vyhledávání
}


/*
 * funkce spuštěná po začátku vyhledávání
 */ 
function ngNearestFnc_startDetail(nearest) {
  if ((this.current_detail_id!=this.title_detail_id) || (this.current_detail_nearest!=this.title_detail_nearest) ) { 
    var o = ngNearestFnc_GEBI(this.ulIdDetail);
    if (o) o.style.display='none'; //schovám seznam s výsledky
    var e = ngNearestFnc_GEBI(this.errorIdDetail);
    if (e) {
      e.style.display='block'; //zobrazím error
      e.innerHTML = T_NEAREST_START;
      this.sizeRefreshDetail(); //nastavím umístění erroru do celého okna
    }
    ret = true; //dotáhni data ze serveru
  }
  else {
    ret = false; //nechod na server, jen zobraz panel
  }

  var isScroll = false;
  if (this.is_scroll_detail) isScroll = 'scroll';
  if (typeof(this.onBeforeStartDetail)=='function') this.onBeforeStartDetail(this, isScroll); //fce zobrazí panel pro výsledky detailu
  this.is_scroll_detail = false;

  return ret; //musím vracet true, jinak se neprovede vyhledávání
}


/*
 * funkce složí popisek pro jeden řádek výsledku
 */ 
function ngNearestFnc_setResultDescription(res) {
  var t = '';
  if (ngNearestFnc_OT(res)) {
    if (ngNearestFnc_ST(res.name)) t = res.name; //přidám ulici
    if (ngNearestFnc_ST(res.street)) {
      if (t != '') t+= ', ';
      t += res.street; //přidám ulici
    }
    if (ngNearestFnc_ST(res.city)) { //přidám  město
      if (t != '') t+= ', ';
      t += res.city;
    }
    if (ngNearestFnc_ST(res.psc)) { //přidám psč
      if (t != '') t+= ', ';
      t += res.psc;
    }
  }

  return t;
}

function ngNearestFnc_setPopupDescription(res) {
  var t = '';
  var is_psc=0;
  if (ngNearestFnc_OT(res)) {
    if (ngNearestFnc_ST(res.name)) t = res.name; //přidám název
    if (ngNearestFnc_ST(res.street)) {
      if (t != '') t+= '<br />';
      t += res.street; //přidám ulici
    }
    if (ngNearestFnc_ST(res.psc)) { //přidám psč
      if (t != '') t+= '<br />';
      t += res.psc;
      is_psc = 1;
    }
    if (ngNearestFnc_ST(res.city)) { //přidám  město
      if (is_psc) t += '&nbsp;';
      else if (t != '') t+= '<br />';
      t += res.city;
    }
    if (ngNearestFnc_ST(res.phone)){ //telefon
      if (t!='') t+= '<br />';
      t += T_TITLE_TEL + res.phone;
    }
    else if (ngNearestFnc_ST(res.fax)) { //fax
      if (t!='') t+= '<br />';
      t += T_TITLE_FAX + res.fax;
    }
  }

  return t;
}


function ngNearestFnc_addSpan(o, idIcon, key, fce, descr) {
  if ((sp = document.createElement('SPAN'))) { //přidání elementu
    var w = o;
    sp.id = o.ulId+'_'+key; //nastavení idéčka
    sp.key = key;
    sp.icon = idIcon;
    sp.onclick = fce;
    sp.innerHTML = descr;
    sp.style.cursor = 'pointer';
    sp.mouse_over = false; //nastavím příznak, že nad textem není najetá myš

    //nastavím události myše onmouseover a onmouseout
    sp.onmouseover = function() {
      this.mouse_over = true;
      ngNearestFce_showPopup(this);
      if (this.typ=='text') w.setClassText(this);
      else if (this.typ=='more') w.setClassTextMore(this);
    }
          
    sp.onmouseout = function() {
      this.mouse_over = false;
      ngNearestFce_hidePopup();
      if (this.typ=='text') w.setClassText(this);
      else if (this.typ=='more') w.setClassTextMore(this);
    }

  }

  return sp;
}


/*
 * funkce sestaví a vloží výsledky pro zobrazení
 * res ... pole výsledků
 */
function ngNearestGui_addResults(res) {
  var o = ngNearestFnc_GEBI(this.ulId);
  if (o) { //je seznam pro výsledky
    o.innerHTML = '';
    var li = null;
    var sp = null;
    var w = this;
    var even = false;
    var locIc = NG_SEARCH_NEAREST.LocateIconId+'_';
    for(var key in res) { //projdu výsledky a přidám je do HTML stránky
      if ((li = document.createElement('LI'))) { //přidání elementu
        locateIcon = locIc+res[key].id;
        li.id = this.ulId+'_li_'+key;
        li.even = even; //nastavím příznak řádku, zda je sudý nebo lichý
        even = !even;
        li.active_line = false;
        this.setClassLi(li); //nastavím řádku CSS třídu
        li.style.margin = '0 0 '+this.lineSpacing+'px 0'; //okraj na pravé straně, aby se text tolik nelepil do sebe a mezera mezi řádky
        o.appendChild(li); //přidání elementu do seznamu UL

        //nastavím ikonku
        obr_key = parseInt(key)+1;
        if (obr_key<this.listIconStart) obr_key = this.listIconStart;
        else if(obr_key>this.listIconMax) obr_key = this.listIconMax;
        obr_url = this.listIconUrl + obr_key + this.listIconUrlSuffix; 

        imId = ngGuiUseFnc_addImg(li.id, false, this.ulId+'_i_'+key, '1', obr_url, '', this.listIconWidth, this.listIconHeight);
        var im = ngNearestFnc_GEBI(imId);
        if (im) {
          im.key = key;
          im.icon = locateIcon;
          im.style.display = 'inline';
          im.style.position = 'relative';
          im.style.cssFloat = 'left';
          im.style.styleFloat = 'left';
          im.style.margin = '0 '+this.imgShift+'px 0 '+this.leftSpacing+'px'; //odsunutí textu od odrážky
          im.onclick = function() { w.LocateItem(this.key); }

          im.mouse_over = false; //nastavím příznak, že nad textem není najetá myš
          //nastavím události myše onmouseover a onmouseout
          im.onmouseover = function() {
            this.mouse_over = true;
            ngNearestFce_showPopup(this);
          }
          im.onmouseout = function() {
            this.mouse_over = false;
            ngNearestFce_hidePopup();
          }
        }
        
//ngNearestFce_showPopup        

        if ((sp = document.createElement('SPAN'))) { //přidání elementu
          sp.style.position = 'static';
          sp.style.top = '-'+this.imgHeight+'px'; //odsunutí nahoru (vycentrování textu k odrážce)

          // --- textovej popisek v řádku
          var descr = ngNearestFnc_setResultDescription(res[key]);
          sp_descr = ngNearestFnc_addSpan(this, locateIcon, key, function() { w.LocateItem(this.key); }, descr);
          if (sp_descr) {
            sp_descr.typ = 'text';
//            res[key].descr = popupdescr;
            sp_descr.style.margin = '0 '+this.moreShift+'px 0 0';
            this.setClassText(sp_descr); //nastavím CSS třídy
            sp.appendChild(sp_descr);
          }

          // --- odkaz "VÍCE"
          sp_more = ngNearestFnc_addSpan(this, locateIcon, 'more_'+key, function() { w.detail(this.icon); }, T_TITLE_MORE);
          if (sp_more) {
            sp_more.typ = 'more';
            sp_more.style.margin = '0 '+this.distShift+'px 0 0';
            this.setClassTextMore(sp_more); //nastavím CSS třídy
            sp.appendChild(sp_more);
          }

          // --- popisek "dist"
          sp_dist = document.createElement('SPAN');
          if (sp_dist) {
            sp_dist.typ = 'dist';
            sp_dist.className=this.classDistText;
            sp_dist.innerHTML = res[key].dist;
            this.setClassTextDist(sp_dist); //nastavím CSS třídy
            sp.appendChild(sp_dist);
          }

          li.appendChild(sp); //přidání elementu do tagu LI
        }
      }
    }
    o.style.display = 'block'; //zobrazím seznam UL
  }

  return;
}

/*
 * funkce naplní seznam ul výsledky hledání
 * places ... ukazatel na třídu s výsledky vyhledávání 
 */ 
function ngNearestGui_displayNearestResults(results, params, loc) {
  if (ngNearestFnc_OT(results)) {
    // zobrazím titulek podle vyhledaných výsledků
    
    //skryju error
    var e = ngNearestFnc_GEBI(this.errorId);
    if (e) e.style.display='none';
    
    // zobrazím výsledky
    if ((typeof(loc)=='undefined') || loc==true) {
      this.LocateItems(results); //zazoomuju nad ikonky
    }
    this.addResults(results);
/*
    if(params.offset==0) //jen pokud šlo o první hledání
      if(results.length==1) this.LocateItem(0); //vložím popum menu do mapy, pokud byl nalezen pouze jeden výsledek
 */   
    // sestavím a zobrazím počítadlo / paging
    this.addCounter(params);
  }

  this.sizeRefresh(); //nastavím umístění seznamu UL a počítadla do celého okna
  
  return;
}


/*
 * funkce vloží jeden řádek provozní doby
 */ 
function ngNearestGuiFnc_addPD(t_title, t) {
  if (t=='-') t = T_TITLE_ZAVRENO;
  var s = '<tr><td>'+t_title+'</td><td> - </td><td>'+t+'</td></tr>';

  return s;
}

/*
 * funkce vloží jeden řádek rozvozové trasy
 */ 
function ngNearestGuiFnc_addRT(t_title, t) {
  var s = '<tr><td class="cn_detail_distribution_trace_days">'+t_title+'</td><td>'+t+'</td></tr>';
  return s;
}

/*
 * funkce sestaví řetězec HTML pro rozvozové trasy
 */ 
function ngNearestGuiFnc_addRozvozoveTrasy(res) {
  var t='';
  if ((res.trasaDen=='A')||(res.trasaDen=='a')) {
    t+='<table style="border-collapse:collapse;">';
    if (res.trasa_po) t+=ngNearestGuiFnc_addRT(T_TITLE_PONDELI, res.trasa_po);
    if (res.trasa_ut) t+=ngNearestGuiFnc_addRT(T_TITLE_UTERY, res.trasa_ut);
    if (res.trasa_st) t+=ngNearestGuiFnc_addRT(T_TITLE_STREDA, res.trasa_st);
    if (res.trasa_ct) t+=ngNearestGuiFnc_addRT(T_TITLE_CTVRTEK, res.trasa_ct);
    if (res.trasa_pa) t+=ngNearestGuiFnc_addRT(T_TITLE_PATEK, res.trasa_pa);
    t+='</table>';
  }
  else if ((res.trasaDen=='N')||(res.trasaDen=='n')) {
    if (res.trasa_po) t+=((t!='')?'<br />':'')+res.trasa_po;
    if (res.trasa_ut) t+=((t!='')?'<br />':'')+res.trasa_ut;
    if (res.trasa_st) t+=((t!='')?'<br />':'')+res.trasa_st;
    if (res.trasa_ct) t+=((t!='')?'<br />':'')+res.trasa_ct;
    if (res.trasa_pa) t+=((t!='')?'<br />':'')+res.trasa_pa;
  }
  if (res.trasaPozn) t+='<div class="cn_detail_distribution_trace_pozn">'+res.trasaPozn+'</div>';

  return t;
}


/*
 * funkce sestaví a vloží výsledky pro zobrazení
 * res ... pole výsledků
 */
function ngNearestGui_addResultsDetail(res, params) {
  var o = ngNearestFnc_GEBI(this.ulIdDetail);
  if (o && ngNearestFnc_OT(res) && ngNearestFnc_OT(params)) { //je seznam pro výsledky
    for(var k in res) { res = res[k]; break; } //když je pole, vezmu první položku
    var t = '<div class="cn_nr_detail_object">';
    if (res.name) t+='<div class="cn_nr_detail_name">'+res.name+'</div>';
    t +='<div class="cn_nr_detail_address">';
    if (res.street) t+='<div>'+res.street+'</div>';
    if (res.city) t+='<div>'+res.city+'</div>';
    if (res.psc) t+='<div>'+res.psc+'</div>';
    t+='</div>';
    var tel = '';
    if (res.phone) tel += '<div><span class="cn_nr_title_tel">'+T_TITLE_TEL+'</span>'+res.phone+'</div>';
    if (res.fax) tel += '<div><span class="cn_nr_title_tel">'+T_TITLE_FAX+'</span>'+res.fax+'</div>';
    if (tel!='') t += '<div class="cn_nr_phone">'+tel+'</div>';
    if(res.umisteni) t+='<div class="cn_nr_umisteni"><span class="cn_nr_title_umisteni">'+T_TITLE_UMISTENI+'</span><span>'+res.umisteni+'</span></div>';
    var pd = '', poznPD='';
    if (res.t_po) pd +=ngNearestGuiFnc_addPD(T_TITLE_PO, res.t_po);
    if (res.t_ut) pd +=ngNearestGuiFnc_addPD(T_TITLE_UT, res.t_ut);    
    if (res.t_st) pd +=ngNearestGuiFnc_addPD(T_TITLE_ST, res.t_st);    
    if (res.t_ct) pd +=ngNearestGuiFnc_addPD(T_TITLE_CT, res.t_ct);    
    if (res.t_pa) pd +=ngNearestGuiFnc_addPD(T_TITLE_PA, res.t_pa);    
    if (res.t_so) pd +=ngNearestGuiFnc_addPD(T_TITLE_SO, res.t_so);    
    if (res.t_ne) pd +=ngNearestGuiFnc_addPD(T_TITLE_NE, res.t_ne);    
    if (res.poznPD) poznPD = '<div class="cn_nr_prov_doba_pozn">'+res.poznPD+'</div>';
    if (pd!='') t += '<div class="cn_nr_prov_doba"><div class="cn_nr_title_prov_doba">'+T_TITLE_PROV_DOBA+'</div><table>'+pd+'</table>'+poznPD+'</div>';

    // --- sestavím kontaktní osoby
    var cPers = fnc_addPersonList(res.contactperson);
    if (cPers!='') t+='<div class="cn_detail_contact"><div class="cn_detail_title_contact_person">'+T_TITLE_CONTACT_PERSON+'</div><div class="cn_detail_body_contact_person">'+cPers+'</div></div>';

    // --- sestavím seznam členů
    var membershipList = fnc_addPersonList(res.membershiplist);
    if (membershipList!='') t+='<div class="cn_detail_membership_list"><div class="cn_detail_title_membership_list">'+T_TITLE_MEMBERSHIP_LIST+'</div><div class="cn_detail_body_membership_list">'+membershipList+'</div></div>';

    // --- sestavím rozvozové trasy
    if (res.trasaDen) {
      var trace = ngNearestGuiFnc_addRozvozoveTrasy(res);
      if (trace!='') t+='<div class="cn_detail_distribution_trace"><div class="cn_detail_title_distribution_trace">'+T_TITLE_DISTRIBUTION_TRACE+'</div><div class="cn_detail_body_distribution_trace">'+trace+'</div></div>';
    }

    if (res.pos) t+='<br /><span class="cn_nr_detail_onmap" onclick="ngNearestFce_detail_showonmap(\''+res.id+'\')" onmouseover="fce_detail_mouseover(this, \'cn_nr_detail_onmap\');" onmouseout="fce_detail_mouseout(this, \'cn_nr_detail_onmap\');" unselectable="on">'+T_DETAIL_ON_MAP+'</span>';
    if (res.web) t+='<br /><a class="cn_nr_more_info" onclick="fce_reloadLocationHref(\''+res.web+'\');" href="'+res.web+'" onmouseover="fce_detail_mouseover(this, \'cn_nr_more_info\');" onmouseout="fce_detail_mouseout(this, \'cn_nr_more_info\');" unselectable="on">'+T_DETAIL_MORE_INFO+'</a>';

    t+='</div>';

    o.innerHTML = t;
    o.style.display = 'block'; //zobrazím výsledek

    this.current_detail = res;
    this.current_detail_id = params.Id; // uložím si příznaky, pro které je formulář načtený  
    this.current_detail_nearest = params.Nearest; // uložím si příznaky, pro které je formulář načtený  
  }

  return;
}

/*
 * funkce lokalizuje objekt nad mapou
 */ 
function ngNearestFce_detail_showonmap(id) {
  if (nearestGui) {
    if (nearestGui.nearest) {
      var key = nearestGui.nearest.FindItemByID(id);
      nearestGui.LocateItem(key);
    }
  }

}


/*
 * funkce naplní panel výsledky
 */ 
function ngNearestGui_displayDetailResults(results, params) {
  if (ngNearestFnc_OT(results)) {
    var e = ngNearestFnc_GEBI(this.errorIdDetail);
    if (e) e.style.display='none';
    this.addResultsDetail(results, params); // zobrazím výsledky
  }
  this.sizeRefreshDetail();
  
  return;
}

/*
 * funkce vypíše error, pokud vyhledávání nenalezlo žádný výsledek
 */ 
function ngNearestGui_displayDetailError(err, params) {
  var o = ngNearestFnc_GEBI(this.ulIdDetail);
  if (o) o.style.display='none'; //schovám seznam s výsledky
  var e = ngNearestFnc_GEBI(this.errorIdDetail);
  if (e) {
    e.style.display='block'; //zobrazím error
    var t = '';
    switch(err) {
      case -1: t = T_NEAREST_ERROR_1; break;
      case -2: t = T_NEAREST_ERROR_2; break;
      default: break;      
    }
    e.innerHTML = t;
    this.sizeRefreshDetail(); //nastavím umístění erroru do celého okna
  }

  return true;
}


/*
 * funkce vytvoří tlačítko "další / předchozí"
 */ 
function ngNearestGui_createBtn(key, obr, obrover, cn, t) {
  var c = ngNearestFnc_GEBI(this.counterId);
  if (c) {
    var btn = document.createElement('SPAN');
    if (btn) {
      var w = this;
      id = this.counterId+'_'+key;
      btn.id = id;
      if (typeof(cn)=='string') btn.className = cn;
      if (key=='previous') {
        this.btnPrevId = id; 
        btn.onclick = function() { w.prevPage(); }
      }
      else if (key=='next') {
        this.btnNextId = id;
        btn.onclick = function() { w.nextPage(); }
      }
      btn.onmouseover = function() { this.className+="_"; }
      btn.onmouseout = function() { this.className = cn; }
      btn.style.visibility='hidden';
      btn.unselectable = 'on'; //pro MSIE nelze vybrat text (ani dvojklikem)
      btn.style.MozUserSelect = 'none';
      btn.innerHTML = '<span unselectable="on">'+t+'</span><img id="'+key+'_img" src="'+obr+'" class="counter_img" /><img id="'+key+'_imgover" src="'+obrover+'" class="counter_img_over" />';
    
      c.appendChild(btn);
    }
  }

  return;
}

/*
 * funkce sestaví a zobrazí počítadlo
 */ 
function ngNearestGui_addCounter(params) {
  var c = ngNearestFnc_GEBI(this.counterId);
  if (c) {
    if (typeof(params)=='object') {
      var sp = null;
      var w = this;
//      c.innerHTML = '';

      var o = ngNearestFnc_GEBI(this.btnPrevId);
      if (o) {
        if (params.PrevVisible) o.style.visibility='visible';
        else o.style.visibility = 'hidden';
      }
      var o = ngNearestFnc_GEBI(this.btnNextId);
      if (o) {
        if (params.NextVisible) o.style.visibility='visible';
        else o.style.visibility = 'hidden';
      }

      c.style.display='block'; //zobrazím počítadlo
      this.counterVisible = 1;
    }
  }


  return;
}

/*
 * funkce vypíše error, pokud vyhledávání nenalezlo žádný výsledek
 */ 
function ngNearestGui_displayNearestError(err, params) {
  var o = ngNearestFnc_GEBI(this.ulId);
  if (o) o.style.display='none'; //schovám seznam s výsledky
  var c = ngNearestFnc_GEBI(this.counterId);
  if (c) c.style.display='none'; //schovám počítadlo
  var e = ngNearestFnc_GEBI(this.errorId);
  if (e) {
    e.style.display='block'; //zobrazím error
    var t = '';
    switch(err) {
      case -1: t = T_NEAREST_ERROR_1; break;
      case -2: t = T_NEAREST_ERROR_2; break;
      default: break;      
    }
    e.innerHTML = t;
    this.sizeRefresh(); //nastavím umístění erroru do celého okna
  }

  return true;
}


/*
 * funkce skládá popup okno vyhledávání
 */ 
function ngNearestGui_popupMenu(map, ic) {
  menu = '<a href="javascript:ngNearestGui_PopupDetail(\''+ic.id+'\')">'+T_POPUP_DETAIL+'</a>';
  menu += '<br /><a href="javascript:ngNearestGui_PopupMaxDetail(\''+ic.pos+'\')">'+T_POPUP_MAX+'</a>';
  menu += '<br /><a href="javascript:ngNearestGui_PopupCenter()">'+T_POPUP_CENTER+'</a>';
//  menu += '<br /><a href="javascript:ngSearchGui_PopupScale200()">'+T_POPUP_200+'</a>';

  return map.CreatePopupHTML(ic.descr, menu);
}

function ngNearestGui_PopupCenter() {
  if (map) {
    map.Center(map.PopupX,map.PopupY);
    map.HidePopup();
  }
}

function ngNearestGui_PopupMaxDetail(pos) {
  if (map) {
//    map.MaxDetail(map.PopupX,map.PopupY);
    map.LocateScaleXY('max', pos)
    map.HidePopup();
  }
}

function ngNearestGui_PopupDetail(id) {
  if (nearestGui) nearestGui.detail(id, true);
  if (map) {
    map.HidePopup();
  }
}

function ngNearestGui_PopupScale200() {
  if (map) {
    map.SetScale(200000,map.PopupX,map.PopupY);
    map.HidePopup();
  }
}


/*
 * funkce přepočítá umístění seznamu výsledků a počítadla
 */ 
function ngNearestGui_sizeRefresh() {
//  this.sizeRefreshDetail();
  var L = 0;
  var T = 0;
  var W = 0;
  var H = 0; 

  var p = ngNearestFnc_GEBI(this.id);
  if (p) { //je rodičovské okno seznamu, získám jeho šířku a výšku
    W = p.clientWidth;
    H = p.clientHeight;
  }

  //nastav počítadlo
  var CT = 0;
  var CH = 0;
  var BH = 12; //mezera pod počítadlem 
  var c = ngNearestFnc_GEBI(this.counterId);
  if (c) { //je počítadlo
    if (this.counterVisible) {
//      CH = c.clientHeight + 10; //výška plus mezera
      CH = 23; //magická hodnota (výška počítadla)
      CT = H - CH - BH; //mezera mezí stránkovadlem a výsledky + mezera pod počítadlem
    }
    c.style.left = (L + this.marginUl_L)+'px';
    c.style.top = CT+'px';
    var w_ = (W - this.imgWidth - this.marginUl_L - this.marginUl_R);
    if (w_<0) w_ = 0;
    c.style.width = w_ +'px';
    c.style.height = CH+'px';
    if(CH > 0)CH += 5;
  }
  
  //nastavím velikost seznamu UL
  var o = ngNearestFnc_GEBI(this.ulId);
  if (o) { //je seznam UL
    o.style.left = (L + this.marginUl_L)+'px';
    o.style.top = (T + this.marginUl_T)+'px';
    var w_ = (W - this.imgWidth - this.marginUl_L - this.marginUl_R);
    if (w_<0) w_ = 0;
    var h_ = (H - this.imgHeight - this.marginUl_T - this.marginUl_B - CH - BH - 5); //výška - odsunutí ul (nad a pod) - výška počítadla (výška, odsun pod počítadlem, magický odsun nad počítadlem (5))
    if (h_ < 0) h_ = 0;
    o.style.width = w_ +'px';
    o.style.height= h_ +'px';
  }
  
  //nastav error
  var e = ngNearestFnc_GEBI(this.errorId);
  if (e) {
    e.style.left = (L + this.marginUl_L)+'px';
    e.style.top = (T + this.marginUl_T)+'px';
    var w_ = (W - this.marginUl_L - this.marginUl_R);
    if (w_ < 0) w_ = 0;
    var h_ = (H - this.marginUl_T - this.marginUl_B);
    if (h_ < 0) h_ = 0;
    e.style.width = w_ +'px';
    e.style.height= h_ +'px';
  }
  
  return;
}


/*
 * funkce přepočítá umístění seznamu výsledků a počítadla
 */ 
function ngNearestGui_sizeRefreshDetail() {
  var L = 0;
  var T = 0;
  var W = 0;
  var H = 0; 

  var p = ngNearestFnc_GEBI(this.idDetail);
  if (p) { //je rodičovské okno seznamu, získám jeho šířku a výšku
    W = p.clientWidth;
    H = p.clientHeight;
  }

  
  //nastavím velikost seznamu UL
  var o = ngNearestFnc_GEBI(this.ulIdDetail);
  if (o) { //je seznam UL
    o.style.left = (L + this.marginUl_L)+'px';
    o.style.top = (T + this.marginUl_T)+'px';
    var w_ = (W - this.imgWidth - this.marginUl_L - this.marginUl_R);
    if (w_<0) w_ = 0;
    var h_ = (H - this.imgHeight - this.marginUl_T - this.marginUl_B); //výška - odsunutí ul (nad a pod) - výška počítadla (výška, odsun pod počítadlem, magický odsun nad počítadlem (5))
    if (h_ < 0) h_ = 0;
    o.style.width = w_ +'px';
    o.style.height= h_ +'px';
  }
  
  //nastav error
  var e = ngNearestFnc_GEBI(this.errorIdDetail);
  if (e) {
    e.style.left = (L + this.marginUl_L)+'px';
    e.style.top = (T + this.marginUl_T)+'px';
    var w_ = (W - this.marginUl_L - this.marginUl_R);
    if (w_ < 0) w_ = 0;
    var h_ = (H - this.marginUl_T - this.marginUl_B);
    if (h_ < 0) h_ = 0;
    e.style.width = w_ +'px';
    e.style.height= h_ +'px';
  }
  
  return;
}



function ngNearestFce_showPopup(obj) {
  if(!map) return false;
  var ic=map.PopupIcons[obj.icon];
  if(!ngNearestFnc_OT(ic)) return false;
  
  var img = ngNearestFnc_GEBI(obj.icon)
  if (!img) return false; //není vidět ikonka

  var o = document.getElementById(map.MapID+'_Popup');
  if(o) {
    var popuphtml;
    if(ic.onpopup) popuphtml=ic.onpopup(map, ic);
    else popuphtml=ic.descr;
 	  if(popuphtml=='') return false;
 	  else {
      clearTimeout(map.HidePopupTimer);
 	    map.InPopupObj=true;
      if(map.ActivePopupIcon) map.ActivePopupIcon.style.zIndex = "10";
      if(img) img.style.zIndex = "500";
      map.MapPopupX=ic.popupx;
      map.MapPopupY=ic.popupy;
      map.PopupX=map.MapPopupX;
      map.PopupY=map.MapPopupY;
      map.CreatePopup(o,ic.popupx+ic.offsetx,ic.popupy+ic.offsety,popuphtml,-map.TileOffsetX,-map.TileOffsetY);
      map.ActivePopupIcon=img;
    }
  }
  return true;
}


function ngNearestFce_hidePopup() {
  if(!map) return false;

  map.InPopupObj=false;
  map.HidePopupTimer=setTimeout('ng_HidePopupRectTimer(\''+map.MapID+'\');', 100);
}

/*
 * funkce nastaví barvu podtržení pro výsledky vyhledávání
 */ 
function ngNearestGui_setColor2ResultsTextUnderline(col) {
  var o = ngNearestFnc_GEBI(this.ulId);
  if (o) {
    if (typeof(col)=='string') {
      o.style.textDecoration = 'underline';
      o.style.color = col;
    }
  }
  
  return;
}

/*
 * funkce nastaví styl písma pro výsledky
 */ 
function ngNearestGui_setResultsTextClass(cn) {
  if (typeof(cn)=='string') this.classNameText = cn;

  return;
}

/*
 * funkce nastaví styl písma pro errorový hlášky
 */ 
function ngNearestGui_setErrorTextClass(cn) {
  var e = ngNearestFnc_GEBI(this.errorId);
  if (e) {
    if (typeof(cn)=='string') e.className = cn;
  }

  return;
}

/*
 * funkce nastaví odrážku výsledkům vyhledávání
 * obr ... url adresa obrázku odrážky
 * w... šířka, h... výška odrážky
 * ods ... odsun odrážky od textu  
 */ 
function ngNearestGui_setResultsTextImg(obr, w, h, ods) {
  var o = ngNearestFnc_GEBI(this.ulId);
  if (o) {
    if (typeof(obr)=='string') {
      var mag_hodn = 10; //odsunutí odrážky a textu dané prohlížečem
      //nastavím si hodnoty pro odsun odrážky a textu .... aby byl správně zarovnaný text s odrážkou
      if (typeof(w)=='number') this.imgWidth = w + mag_hodn; //10 je magická hodnota, zadaná prohklížeči jako mezera mezi odrážkou a textem
      if (typeof(h)=='number') this.imgHeight = Math.floor(h/2); //odsunutí je potřeba jen o polovinu odrážky (odsunutí nahoru v MSIE a opeře)
      if (typeof(ods)=='number') this.imgShift = ods - mag_hodn; //odsunutí je potřeba jen o polovinu odrážky (odsunutí nahoru v MSIE a opeře)

      //FireFox se nesmí posunovat, je zarovnán dobře sám od sebe, posunuji jen MSIE a Operu
      if(typeof(document.all) == 'undefined') { 
        this.imgHeight = 0;
        this.imgShift = 0; 
      }

      //nastavím vlastnosti do CSS
      o.style.listStyle = 'disc url("'+obr+'") outside';
      o.style.padding = this.imgHeight+'px 0 0 '+this.imgWidth+'px'; //2px odsunutí kuli háčkům nad velkými písmeny, 17px odsunutí kuli odrážce
    }
  }
    
  return;   
}


/*
 * funkce načte margin rozměry pro UL seznam
 * s = "margin-top, margin-right, margin-bottom, margin-left";
 */ 
function ngNearestGui_setUlMargin(top, right, bottom, left) {
  if (typeof(top)=='number') this.marginUl_T = top;
  if (typeof(right)=='number') this.marginUl_R = right;
  if (typeof(bottom)=='number') this.marginUl_B = bottom;
  if (typeof(left)=='number') this.marginUl_L = left;
  
  return;
}


/*
 * funkce složí className pro element LI = jeden řádek ve výsledcích vyhledávání
 */ 
function ngNearestGui_setClassLi(li) {
  if (li) {
    var cnOE = this.classOdd; //třída pro lichý řádek
    if (li.even) cnOE = this.classEven; //řádek je sudý
    var cnAL = '';
    if (li.active_line) cnAL = this.classActiveLine;
    li.className = cnOE+' '+cnAL;  
  }

  return;
}


/*
 * funkce složí className pro element span = obsahuje text jednoho výsledku 
 */ 
function ngNearestGui_setClassText(sp) {
  if(sp) {
    var cnOT = this.classOutText;
    if(sp.mouse_over) cnOT = this.classOverText; 
    var cnAL = '';
    if (sp.active_line) cnAL = this.classActiveLine;
    sp.className = this.classNameText + ' ' +cnOT + ' '+cnAL;  
  }

  return;
}

/*
 * funkce nastaví řádku výsledku jako aktivní, ale neprovádí lokalizaci vyhledané adresy
 */ 
function ngNearestGui_setActiveLine(key) {
  var o = ngNearestFnc_GEBI(this.ulId+'_'+key);
  if (o) {
    o.active_line = true;
    this.setClassText(o); //nastavím řádku CSS třídu
    this.activeLineKey = key; 
  }

  return;
}

function ngNearestGui_setClassTextMore(sp) {
  if(sp) {
    var cnOT = this.classOutTextMore;
    if(sp.mouse_over) cnOT = this.classOverTextMore; 
    var cnAL = '';
    if (sp.active_line) cnAL = this.classActiveLine;
    sp.className = this.classNameText + ' ' +cnOT + ' '+cnAL;  
  }
}

function ngNearestGui_setClassTextDist(sp) {
  if(sp) {
    var cnOT = this.classOutTextDist;
    if(sp.mouse_over) cnOT = this.classOverTextDist; 
    var cnAL = '';
    if (sp.active_line) cnAL = this.classActiveLine;
    sp.className = this.classNameText + ' ' +cnOT + ' '+cnAL;  
  }
}


/*
 * funkce zobrazí vybraný výsledek hledýní nad mapou
 */ 
function ngNearestGui_LocateItem(key) {
  var ao = ngNearestFnc_GEBI(this.ulId+'_'+this.activeLineKey);
  if (ao) {
    ao.active_line = false;
    this.setClassText(ao); //nastavím řádku CSS třídu
    this.activeLineKey = ''; 
  }
  var o = ngNearestFnc_GEBI(this.ulId+'_'+key);
  if (o) {
    o.active_line = true;
    this.setClassText(o); //nastavím řádku CSS třídu
    this.activeLineKey = key; 
  }
  if (NG_SEARCH_NEAREST) {
    key = parseInt(key);
    NG_SEARCH_NEAREST.LocateItem(key);
  }

  return;
}


/*
 * funkce zobrazí všechny výsledky nad mapou
 */ 
function ngNearestGui_LocateItems(results, params) {
  if (NG_SEARCH_NEAREST) {
    for(var key in results) {
      results[key].descr = ngNearestFnc_setPopupDescription(results[key]);
      NG_SEARCH_NEAREST.DisplayItem(key); //vložím všechny ikony nad mapu
      NG_SEARCH_NEAREST.LocateItems(undefined);
/*      if (ngNearestFnc_OT(params) {
        if (ngNearestFnc_ST(params.BoundRect)) {
          if (map) map.MapCommand('ZBR', ng_URLEncode(params.BoundRect)); //zazoomuju nad ikonky
        }
      }*/
    }
  }
  

  return;
}


/*
 * odstránkuje na další stránku s výsledky
 */ 
function ngNearestGui_nextPage() {
  this.setNearestParams(); //nestavím počet řádků, které chci aby vrátil výsledek vyhledávání
  if (NG_SEARCH_NEAREST) {
    NG_SEARCH_NEAREST.NextPage();
  }

  return;
}

/*
 * odstránkuje na předchozí stránku s výsledky
 */ 
function ngNearestGui_prevPage() {
  this.setNearestParams(); //nestavím počet řádků, které chci aby vrátil výsledek vyhledávání
  
  if (NG_SEARCH_NEAREST) {
    NG_SEARCH_NEAREST.PrevPage();
  }

  return;
}

/*
 * Funkce vrátí číslo udávající počet řádků, které chci zobrazit ve
 * výsledcích vyhledávání
 */ 
function ngNearestGui_getResultCntLine() {
  if (this.dynamicCntLine) { //je nastavena dynamická výška boxu pro zobrazení výsledků vyhledávání
    var H = 0;
    var o = ngNearestFnc_GEBI(this.id);
    if (o) H = o.clientHeight;
  
//  if(this.counterVisible) {
  //vždy uvažuji že může být stránkovadlo, proto výšku odněj zmenšuji
      H -= 30; //magické číslo (výška stránkovadla)
//  }
    var lh = 13 + this.lineSpacing + this.bottomSpacing; //lineHeight = výška fontu + mezera mezi řádky + šířka řádku pod textem
    var num = Math.floor(H / lh) ; //13 ... magické číslo ... výška řádku CSS line-height
    num -= 1; //o jeden řádek méně,aby se krásně vešlo do svého prostoru
    if (num < 5) num = 5; // minimum vrací pět řádků
    this.pageSize = num;
  }
/*  else {
    var num = this.pageSize; //vezmu pevně nastavený počet řádků výsledku vyhledávání
  }
*/

  return this.pageSize;
}


/*
 * funkce nastaví velikost stránky, kterou má vyhledávání dodat
 */ 
function ngNearestGui_setNearestParams() {
  if (NG_SEARCH_NEAREST) NG_SEARCH_NEAREST.PageSize = this.getResultCntLine();
  
  return;
}


/*
 * funkce nastaví seznam výsledků bez odrážek
 * is ... imageShift ... odsun textu od levého okraje
 * ls ... lineSpacing ... mezera mezi řádky
 * rs ... rightSpacing ... odsun konce řádku od pravého okraje   
 */
function ngNearestGui_setResultsTextWithoutImg(is, ls, rs) {
  var o = ngNearestFnc_GEBI(this.ulId);
  if (o) {
    o.style.listStyleType = 'none';
    o.style.margin = '0';
    o.style.padding = '0';
    if (typeof(is)=='number') this.imgShift = is;
    if (typeof(rs)=='number') this.rightSpacing = rs;
    if (typeof(ls)=='number') this.lineSpacing = ls; 
  }

  return;
} 

/*
 * funkce nastaví mezeru mezi řádky
 */ 
function ngNearestGui_setLineSpacing(ls) {
  if (typeof(ls)=='number') this.lineSpacing = ls;

  return;
}

/*
 * funkce nastaví odsazení konce řádku od pravého okraje seznamu UL
 */ 
function ngNearestGui_setRightSpacing(rs) {
  if (typeof(rs)=='number') this.rightSpacing = rs;

  return;
}

/*
 * funkce nastaví odsazení konce řádku od levého okraje seznamu UL
 */ 
function ngNearestGui_setLeftSpacing(ls) {
  if (typeof(ls)=='number') this.leftSpacing = ls;

  return;
}


/*
 * funkce nastaví šířku řádku pod textem
 */ 
function ngNearestGui_setBottomSpacing(bs) {
  if (typeof(bs)=='number') this.bottomSpacing = bs;

  return;
}


/*
 * funkce nastaví odsunutí příkazu "více" a odsunutí vypsané vzdálenosti
 */ 
function ngNearestGui_setMoreDistSpacing(moreShift, distShift) {
  if (typeof(moreShift)=='number') this.moreShift = moreShift;
  if (typeof(distShift)=='number') this.distShift = distShift;
}


/*
 * funkce nastaví střídající se className u řádků
 */ 
function ngNearestGui_setOddAndEvenLine(cn_odd, cn_even) {
  if (ngNearestFnc_ST(cn_odd)) this.classOdd = cn_odd;
  if (ngNearestFnc_ST(cn_even)) this.classEven = cn_even;

  return;
}

/*
 * funkce nastaví CSS třídy pro najetí a odjetí myše nad/z textu 
 */ 
function ngNearestGui_setOverOutText(cn_over, cn_out) {
  if (ngNearestFnc_ST(cn_over)) this.classOverText = cn_over;
  if (ngNearestFnc_ST(cn_out)) this.classOutText = cn_out;

  return;
}


/*
 * funkce nastaví CSS třídy pro najetí a odjetí myše nad/z příkazu "více" 
 */ 
function ngNearestGui_setOverOutTextMore(cn_over, cn_out) {
  if (ngNearestFnc_ST(cn_over)) this.classOverTextMore = cn_over;
  if (ngNearestFnc_ST(cn_out)) this.classOutTextMore = cn_out;
}


/*
 * funkce nastaví CSS třídy pro najetí a odjetí myše nad/z výpisu vzdálenosti 
 */ 
function ngNearestGui_setOverOutTextDist(cn_over, cn_out) {
  if (ngNearestFnc_ST(cn_over)) this.classOverTextDist = cn_over;
  if (ngNearestFnc_ST(cn_out)) this.classOutTextDist = cn_out;
}

/*
 * funkce nastaví CSS třídu pro vybraný výsledek hledání
 */  
function ngNearestGui_setClassActiveLine(cn) {
  if (ngNearestFnc_ST(cn)) this.classActiveLine = cn;

  return;
}


/*
 * funkce nastaví pevný počet řádků, které má navrátit vyhledávání
 */ 
function ngNearestGui_setPageSize(i) {
  if (typeof(i)=='number')
    if (i>0) {
      this.pageSize = i;
      this.dynamicCntLine = false;
    }

  return;
}


function ngNearestGui_setLocateIcon(url) {
  if (typeof(url)=='string') this.locateIcon = url; 

  return;
}


/*
 * funkce nastaví url a maximální počet ikon pro seznam výsledků hledání nearest
 */ 
function ngNearestGui_setNearestIcon(url, urlSuffix, startIcon, maxIcon, widthIcon, heightIcon) {
  if (typeof(url)=='string') this.listIconUrl = url;
  if (typeof(urlSuffix)=='string') this.listIconUrlSuffix = urlSuffix;
  if ((typeof(maxIcon)=='number')&&(maxIcon>0)) this.listIconMax = maxIcon;
  if ((typeof(startIcon)=='number')&&(startIcon>=0)&&(startIcon<=this.listIconMax)) this.listIconStart = startIcon;
  if ((typeof(widthIcon)=='number')&&(widthIcon>0)) this.listIconWidth = widthIcon;
  if ((typeof(heightIcon)=='number')&&(heightIcon>0)) this.listIconHeight = heightIcon;
}

/*
 * funkce smaže ikonky z mapy
 */ 
function ngNearestGui_clearDisplayedItems() {
  if (ngNearestFnc_OT(this.nearest)) {
    this.nearest.ClearDisplayedItems();
  }
}

/*
 * funkce přidá ikonku do hlavičky detailu
 */ 
function ngNearestGui_addDetailIcon(sp_id) {
  var sp = document.getElementById(sp_id);
  if (sp) {
    id = this.title_detail_id;
    key = NG_SEARCH_NEAREST.FindItemByID(id);
    locateIcon = NG_SEARCH_NEAREST.LocateIconId+'_'+id;
    obr_key = parseInt(key)+1;
    if (obr_key<this.listIconStart) obr_key = this.listIconStart;
    else if(obr_key>this.listIconMax) obr_key = this.listIconMax;
    var obr_url = this.listIconUrl + obr_key + this.listIconUrlSuffix; 
    imId = ngGuiUseFnc_addImg(sp.id, false, this.ulId+'_id_'+key, '1', obr_url, T_DETAIL_ON_MAP, this.listIconWidth, this.listIconHeight);
    var im = ngNearestFnc_GEBI(imId);
    if (im) {
      im.key = key;
      im.icon = locateIcon;
      im.style.display = 'inline';
      var w = this;
      im.onclick = function() { w.LocateItem(this.key); }

      im.mouse_over = false; //nastavím příznak, že nad textem není najetá myš
      im.onmouseover = function() {
        this.mouse_over = true;
        ngNearestFce_showPopup(this);
      }
      im.onmouseout = function() {
        this.mouse_over = false;
        ngNearestFce_hidePopup();
      }
    }
  } 
}
