var dl_root;
var sis_timer;

function getE(id)
{
   if (typeof id != "string")
   {
         return id;
   }
   else if (Boolean(document.getElementById))
   {
         return document.getElementById(id);
   }
   else if (Boolean(document.all))
   {
         return eval("document.all."+id);
   }
   else if (Boolean(document.ids))
   {
         return eval("document.ids."+id);
   }
   else
   {
         return null;
   }
}


dl_getElementsByClassName = function(clsName)
{
   var retVal = new Array();
   var elements = document.getElementsByTagName("*");
   for(var i = 0;i < elements.length;i++)
   {
      if(elements[i].className.indexOf(" ") >= 0)
      {
         var classes = elements[i].className.split(" ");
         for(var j = 0;j < classes.length;j++)
         {
            if(classes[j] == clsName)
            {
               retVal.push(elements[i]);
            }
         }
      }
      else if (elements[i].className == clsName)
      {
         retVal.push(elements[i]);
      }
   }
   return retVal;
}

function wo(link,name,attr,dat)
{
      if (getE(dat)!=null)
      {
            if (getE(dat).value != "")
            {
                  var sd = getE(dat).value;

                  while(sd.search(String.fromCharCode(10)) != -1)
                  {
                     sd = sd.replace(String.fromCharCode(10),"$");
                  }

                  link = link + "&sd=" + sd;
            }
      }

     nove_okno = window.open(link,name,attr);

     if (name != '')
     {
           nove_okno.focus();
     }
}

function dlg_clear(id)
{
   if (getE(id)!=null)
   {
         SetValKomu(id,"");
   }

   if (getE(id+"_nazev")!=null)
   {
         SetValKomu(id+"_nazev"," - ");
   }
}

function SetValKomu(komu,val)
{
   if (getE(komu).tagName=="INPUT" || getE(komu).tagName=="TEXTAREA")
   {
         getE(komu).value = val;

         if (typeof getE(komu).onchange == 'function')
         {
               getE(komu).onchange();
         }
   }
   else if (getE(komu).tagName=="SPAN" || getE(komu).tagName=="DIV")
   {
         getE(komu).innerHTML = val;

         if (typeof getE(komu).onchange == 'function')
         {
               getE(komu).onchange();
         }
   }
}

function SetVal(kod,nazev,kod_val,nazev_val)
{
   if (kod != ""   && getE(kod)!=null)
   {
         SetValKomu(kod, kod_val);
   }

   if (nazev != "" && getE(nazev)!=null)
   {
         SetValKomu(nazev, nazev_val);
   }
}

function ParentSetVal(kod,nazev,kod_val,nazev_val,close)
{
   try
   {
         self.opener.SetVal(kod,nazev,kod_val,nazev_val);
   }
   catch(e)
   {
   }

   if (close=="a")
   {
         self.close();
   }
}

function ParentRefresh(close)
{
   try
   {
         self.opener.document.location.reload(true);
   }
   catch(e)
   {
   }

   if (close=="a")
   {
         self.close();
   }
}

function switch_filtr(filter_id)
{
   _div  = getE(filter_id);
   _href = getE("filtr_href_" + filter_id);

   if (_div == null || _href == null) return;

   if (_div.style.display == "")
   {
         _div.style.display = "none";
         _href.className = "filtr_off";
   }
   else
   {
         _div.style.display = "";
         _href.className = "filtr_on";
   }
}

function ShowHide(div,stav)
{
   var d = getE(div);
   var _stav = stav;

   if (d == null) return;

   if (stav == 3)
   {
         if (d.style.display == "") _stav = 0;
         else                       _stav = 1;
   }

   if (_stav == 0)
   {
         d.style.visibility = "hidden";
         d.style.display    = 'none';
   }
   else
   {
         d.style.visibility = "visible";
         d.style.display    = '';
   }
}

/*global alert, document, window, class_session, getE, str_session_expired  */

/**
 *  Hlida vyprseni session
 *  @class class_session
 */
class_session = function()
{
   this.sessionCD       = 3600;  // vyprseni session
   this.timer           = null;  // reference na casovac
   this.interval        = 1000;  // interval skoku casovace [ms]
   this.notifyLimit     = 60;    // varovat pri vyprseni session
   this.refreshCD       = false; // jak casto se prodluzuje session
   this.sessionLifetime = 0;     // platnost session
   this.sessionPojistka = 30;    // pojistka - obnovovat x vterin predem
   this.started         = false; // pomocna promenna, zda je inicializovan
   this.allowExtend     = false;
   this.t1              = false; // pomocna promenna, cas


   this.start = function()    // spusteni casovace
   {
      this.started = true;
      if (document.uniqueID) // msie crazy timer
      {
         var t = this;
         this.timer = window.setInterval(function(){t.runSessionCountDown();}, this.interval, this);
      }
      else
      {
         this.timer = window.setInterval(function(self) {self.runSessionCountDown.call(self);} ,this.interval,this);
      }
   };
   
   this.xhr_session = function () // prodlouzeni session volani
   {
      dt = new Date();
      this.t1 = Math.round(dt.getTime() / 1000); // klientsky cas (timestamp)
            
      myConn = new XHConn();
      myConn.connect(dl_root+"/lib_class/sess_ext.php", "POST", "id="+dl_id, this.fnSessExtend, this);
   };

 
   this.fnSessExtend = function(data) // prodlouzeni session hotovo
   {
      var resp;
      
      try
      {
         resp = data.responseXML.getElementsByTagName("session")[0];
         if (resp.getAttribute('extended') === "true")
         {
            this.xhr_inProgress = false;
            t1 = this.t1;
            resp = data.responseXML.getElementsByTagName("session")[0];
            
            dt = new Date();
            t2 = parseInt(resp.getAttribute('time')); // serverovy cas (timestamp)   
            s  = parseInt(resp.getAttribute('expire')); // platnost sessiony (sek)
            z  = parseInt(resp.getAttribute('maxextend')); // celkova zivotnost prihlaseni
            t3 = Math.round(dt.getTime() / 1000); // klientsky cas (timestamp)
   
            // floor(T2-((T1+T3)/2))
            d = Math.floor(t2 - ((t1+t3)/2) );
            // S-(T4+D-T2)   kde T4 = T3
            sek = s-(t3+d-t2);

            this.refreshCD = (dt.getTime()/1000)+sek;            
            if (!this.started)
            {
               this.sessionLifetime = sek;
               this.sessionCD = (dt.getTime()/1000)+z-(t3+d-t2);
               this.start();         
            }
         }
         else
         {
            window.clearTimeout(this.timer);
            alert("Vypršelo vám přihlášení, neuložené změny budou ztraceny.");
         }
      }
      catch (e) // chyba vystupu, mozna uzivatel klikl na libovolny odkaz drive nez se stihl nacist. Budeme delat ze se nic nedeje.
      {
         // window.clearTimeout(this.timer);
         // alert("Prodloužení platnosti přihlášení se nezdařilo. Neuložené změny mohou být ztraceny.");
      }
   };
   
   this.runSessionCountDown = function()
   {
      curr_dt = new Date();
      logof_dt = new Date(this.sessionCD*1000);
      zbyva = Math.round((logof_dt - curr_dt)/1000);

      
      if (this.allowExtend == true) // je nastaven cfg stev_ajax_refresh
      {
         refresh_dt = new Date(this.refreshCD*1000);
         refresh_sec = Math.round((refresh_dt - curr_dt)/1000);
         
         if (zbyva <= this.sessionLifetime) // posledni obnoveni, dale uz neprovadet aby nam to vyslo presne
         {
            this.allowExtend = false;
            this.xhr_session();
         }
         else if ((refresh_sec <= this.sessionPojistka)) // zacneme o par sek. pred vyprsenim
         {
            if (this.xhr_inProgress != true)
            {                     
               this.xhr_inProgress = true;
               this.xhr_session();
            }            
         }
      }

      if ((zbyva == this.notifyLimit) && (this.notifyLimit>0)) // zbyva X sek do odhlaseni a je nastaven cfg session_notify_expired
      {
         tm = numfix(logof_dt.getHours(), 2) + ":" + numfix(logof_dt.getMinutes(), 2) + ":" + numfix(logof_dt.getSeconds(), 2);
         str_session_expired = "Za "+this.notifyLimit+"s budete odhlášeni. Pokud chcete bez odhlášení pokračovat v práci, klikněte na libovolný odkaz. (Ohlášeno v "+tm+").";
         alert(str_session_expired);
      }
      
      if (zbyva < 0) // session vyprsela
      {
         window.clearTimeout(this.timer);
         str_session_expired = "Sezení je ukončeno. Pro další práci s IS se znovu přihlašte.\nVeškerá neuložená data budou ztracena.";
         window.status = str_session_expired;
         getE("session").innerHTML = "--:--";
         getE("session").title = str_session_expired;

         if (this.warnExpired) // je nastaven cfg session_notify_expired
         {
            alert(str_session_expired);
         }
      }
      else // odpocitavame
      {
         var m   = Math.floor(zbyva/60);
         var s   = Math.floor((zbyva % 60) % 60);
         var cas = "";

         if (m<10)
         {
            cas = cas+"0";
         }
         cas = cas+m+":";
         if (s<10)
         {
            cas = cas+"0";
         }

         cas = cas+s;
         getE("session").innerHTML = cas;
      }
   };
};

/*
 * @param sek        integer     platnost session
 * @param logonsek   integer     cas naxteni stranky
 * @param varovat    integer     varovat pred vyprsenim v sec   
 * @param ajax_limit integer     jak dlouho obnovovat session 
 */  
function showSession(sek, logonsek, varovat, ajax_limit)
{

   sis_timer = new class_session();
   sis_timer.notifyLimit = varovat;
   
   if (!ajax_limit)
   {
      sis_timer.sessionCD = sek+logonsek;
      sis_timer.refreshCD = false;
      sis_timer.start();
   }
   else // ajaxove obnovovani sessiony
   {
      sis_timer.allowExtend = true;
      sis_timer.xhr_session();
   }
}

/**
 * Invertuje checkboxy ve formuláři.
 * @param _frm Id prvku formuláře, může být prázdné v případě použití classname
 * @param _stav Stav, který se nastaví. 0=Off,1=On,ostatní=přepnout
 * @param classname CSS třída prvků, na které to platí. Pokud je _frm prázdné, pak všechny elementy s touto třídou na stránce
 * POZOR: classname musí být přesná shoda s atributem class daného checboxu
 */
function invert_form(_frm, _stav, classname)
{
   
   if (!classname) classname=false;
   if(_frm!="")
   {
      if ((getE(_frm) == null)) return;
   }
   
   if((_frm=="")&&(classname==false))
   {
      return;
   }
   var _form;
   
   if(getE(_frm) != null)
   {
      _form = getE(_frm).getElementsByTagName("input");
   }else{
      _form = document.getElementsByTagName("input");
   }

   for (var i = 0; i < _form.length; i++)
   {
         var e = _form[i];

         if (e.type == "checkbox")
         {
               if ((classname==false) || (e.className==classname))
               {
                     if (_stav == 1)
                     {
                           e.checked = true;
                     }
                     else if (_stav == 0)
                     {
                           e.checked = false;
                     }
                     else
                     {
                           e.checked = !e.checked;
                     }
               }
               else
               {

               }
         }
   }

   return false;
}

function dopln_datum(did)
{
   var t = getE(did).value;
   var den,dden,mesic,mmesic,rok,p;

   p = t.indexOf(".");
   if (p == -1) return;

   dden  = t.substring(0,p);
   den   = parseInt(dden);
   mesic = t.substring(p+1,t.length);

   p = mesic.indexOf(".");

   if (p == -1) return;

   rok   = mesic.substring(p+1,mesic.length);
   mmesic= mesic.substring(0,p);
   mesic = parseInt(mmesic);

   if (isNaN(den) == true || isNaN(mesic) == true || den != dden || mesic != mmesic) return;

   if (den < 1 || den > 31 || mesic < 1 || mesic > 12) return;

   if (rok.length == 0)
   {
         var dt = new Date();
         var rok=dt.getFullYear();
         getE(did).value = getE(did).value + rok;
   }
}

function dl_select_dual(__obj, __checked, __sel_array)
{
   var obj_select = getE(__obj);

   if (!obj_select || obj_select.type != "select-one") return;

	obj_select.options.length = 0;

   if (__checked == true)
   {
         var opt = __sel_array[1];
   }
   else
   {
         var opt = __sel_array[0];
   }

	obj_select.options[0] = new Option('---', '');

	for (i=0; i < opt.length; i+=2)
	{
         obj_select.options[(i/2 + 1)] = new Option(opt[i+1], opt[i]);
	}
}

function dl_select_povinn(select_id, obj_data)
{
      var obj_select = document.getElementById(select_id);

      if (!obj_select || obj_select.type != "select-one") return;

      var obj_value = obj_select.options[obj_select.selectedIndex].value;

      obj_select.options.length = 0;

      if (obj_data.mode == "kod")
      {
            for (key in obj_data.data)
            {
                  obj_select.options[obj_select.length] = new Option(obj_data.data[key] + ' - ' + key, key);
            }

            obj_data.mode = 'text';

            var items = obj_select.options.length;
            var tmpArray = new Array(items);

            for (var i=0; i < items; i++ )
            {
                  tmpArray[i] = new Option(obj_select.options[i].text,obj_select.options[i].value);
            }

            tmpArray.sort(dl_select_povinn_sort);

            obj_select.options[0] = new Option('---', '');

            for (i = 0; i < items; i++ )
            {
                  obj_select.options[i + 1] = new Option(tmpArray[i].text,tmpArray[i].value);
            }
      }
      else
      {
            obj_select.options[0] = new Option('---', '');

            for (key in obj_data.data)
            {
                  obj_select.options[obj_select.length] = new Option(key + ' - ' + obj_data.data[key], key);
            }

            obj_data.mode = 'kod';
      }

      if (obj_value != '')
      {
            obj_select.value = obj_value;
      }
}


function dl_select_povinn_sort(a,b)
{
   return a.text != b.text ? a.text < b.text ? -1 : 1 : 0;
}

function dl_showhide(obj, obj_data)
{
      if (!obj || !(obj_data instanceof Array)) return;

      for (i in obj_data)
      {
            ShowHide(obj_data[i], 0);
      }

      if (obj.value in obj_data)
      {
            ShowHide(obj_data[obj.value], 1);
      }
}


/* :::::::::::::::: HINT ::::::::::::::::::: */

var tt_db = (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body? document.body : null,
tt_n = navigator.userAgent.toLowerCase(),
tt_nv = navigator.appVersion;
var tt_op = !!(window.opera && document.getElementById),
tt_op6 = tt_op && !document.defaultView,
tt_op7 = tt_op && !tt_op6,
tt_ie = tt_n.indexOf("msie") != -1 && document.all && tt_db && !tt_op,
tt_ie6 = tt_ie && parseFloat(tt_nv.substring(tt_nv.indexOf("MSIE")+5)) >= 5.5;
tt_n4 = (document.layers && typeof document.classes != tt_u),
tt_n6 = (!tt_op && document.defaultView && typeof document.defaultView.getComputedStyle != tt_u),
tt_w3c = !tt_ie && !tt_n6 && !tt_op && document.getElementById;
var tt_u = "undefined";

function tt_Int(t_x)
{
	var t_y;
	return isNaN(t_y = parseInt(t_x))? 0 : t_y;
}

function getDivW(id)
{
   return tt_Int( tt_n4 ? getE(id).clip.width : (getE(id).style.pixelWidth || getE(id).offsetWidth) );
}
function getDivH(id)
{
   return tt_Int( tt_n4 ? getE(id).clip.height : (getE(id).style.pixelHeight || getE(id).offsetHeight) );
}

var timerId = null;
var t_id;
var t_mod;
var ex = 0;
var ey = 0;

function ShowHint(id,mod,tout,text)
{
   HideHint(id);
   t_id = id;

   if (text!=undefined && text!="")
   {
         mod = text;
   }
   else if (mod!=undefined && mod!="")
   {
         mod  = eval(mod);
   }

   if (mod!="")
   {
         t_mod = mod;

         if (tout == 0)
         {
               ShowHintTimeOut();
         }
         else
         {
               timerId = setTimeout("ShowHintTimeOut()", tout);
         }
   }
}

function ShowHintTimeOut()
{
   if (timerId!=null)
   {
         clearTimeout(timerId);
         timerId=null;
   }

   getE(t_id+"lbl").innerHTML = t_mod;
   ShowHide(t_id,1);

   SetHintPos();
}

function SetHintPos()
{
   if (getDivH(t_id)>winH())
   {
         getE(t_id).style.top = document.body.scrollTop + ((winH()-getDivH(t_id))/2) - 15;
   }
   else if ((ey+getDivH(t_id)+20)>winH())
   {
         if ((getDivH(t_id)+10) > ey)
         {
               getE(t_id).style.top = document.body.scrollTop + ((winH() - getDivH(t_id))/2) - 15;
         }
         else
         {
               getE(t_id).style.top = document.body.scrollTop + ey - getDivH(t_id) - 20;
         }
   }
   else
   {
         getE(t_id).style.top = document.body.scrollTop + ey + 4;
   }

   if (getDivW(t_id)>winW())
   {
         getE(t_id).style.left = document.body.scrollLeft+((winW()-getDivW(t_id))/2)-15;
   }
   else if ((ex+getDivW(t_id)+20)>winW())
   {
         if ((getDivW(t_id)+10)>ex)
         {
               getE(t_id).style.left = document.body.scrollLeft+((winW()-getDivW(t_id))/2)-15;
         }
         else
         {
               getE(t_id).style.left=document.body.scrollLeft+ex-getDivW(t_id)-20;
         }
   }
   else
   {
         getE(t_id).style.left=document.body.scrollLeft+ex+4;
   }
}

function HideHint(id)
{
   if (timerId != null)
   {
         clearTimeout(timerId);
         timerId=null;
   }

   ShowHide(id,0);
}

function setxy(e)
{
   ex = document.all?window.event.clientX:e.clientX;
   ey = document.all?window.event.clientY:e.clientY;
}

document.onmousemove=setxy;

function winH()
{
   if (window.innerHeight)
   {
         return window.innerHeight;
   }
   else if (document.documentElement && document.documentElement.clientHeight)
   {
         return document.documentElement.clientHeight;
   }
   else if (document.body && document.body.clientHeight)
   {
         return document.body.clientHeight;
   }
   else
   {
         return null;
   }
}

function winW()
{
   if (window.innerWidth)
   {
         return window.innerWidth;
   }
   else if (document.documentElement && document.documentElement.clientWidth)
   {
         return document.documentElement.clientWidth;
   }
   else if (document.body && document.body.clientWidth)
   {
         return document.body.clientWidth;
   }
   else
   {
         return null;
   }
}

function js_confirm(text,url)
{
   if (confirm(text))
   {
         location.href = url;
   }
   else
   {
         return false;
   }
}

function textarea_check_limit(obj_ref, obj_len, lang_zbyva, lang_prebyva)
{
   obj_ref_id=obj_ref.id;

   obj_txt_zadano = document.getElementById('textarea_limit_'+obj_ref_id+'_zadano');
   obj_txt_zbyva  = document.getElementById('textarea_limit_'+obj_ref_id+'_zbyva');
   obj_txtlang_zbyva  = document.getElementById('textarea_limit_'+obj_ref_id+'_txt_zbyva');
   txt_length = obj_ref.value.replace(/\r/g,'').replace(/\n/g,'nl').length;

   if (txt_length > obj_len)
   {
      obj_ref.className='inp3';
      obj_txt_zadano.parentNode.parentNode.className = 'error';
      obj_txtlang_zbyva.innerHTML = lang_prebyva;
      obj_txt_zbyva.innerHTML  = (obj_len-txt_length)*(-1);
   }
   else
   {
      obj_ref.className='inp2';
      obj_txt_zadano.parentNode.parentNode.className = null;
      obj_txtlang_zbyva.innerHTML = lang_zbyva;
      obj_txt_zbyva.innerHTML  = obj_len-txt_length;
   }

   obj_txt_zadano.innerHTML = txt_length;
}


function in_array(value, arr)
{
   var i;

   if(value != null && arr != null && (arr instanceof Array))
   {
      for (i = 0; i < arr.length; i++)
      {
         if (arr[i] === value)
         {
            return true;
         }
      }
   }

   return false;
}


var registered_divs = new Array();

function addRegDiv(divid)
{
   registered_divs[registered_divs.length] = divid;
}

function HideAllRegisteredDivs()
{
   for(i=0; i<registered_divs.length; i++)
   {
      ShowHide(registered_divs[i], 0);
   }
}

function isChildOfRegDiv(child)
{
   var retval = false;

   if(typeof(ContainerObject) == "string")
   {
      child = document.getElementById(child);
   }

   if(child != null)
   {
      //alert(registered_divs.length);
      for(i=0; i<registered_divs.length; i++)
      {
         if(isChildOf(child, registered_divs[i]))
         {
            retval = true;
            break;
         }
      }
   }

   return retval;
}


function isChildOf(ChildObject, ContainerObject)
{
   var retval = false;
   var curobj;

   if(typeof(ContainerObject) == "string")
   {
      ContainerObject = document.getElementById(ContainerObject);
   }

   if(typeof(ChildObject) == "string")
   {
      ChildObject = document.getElementById(ChildObject);
   }

   if(ChildObject != null && ContainerObject != null)
   {
      curobj = ChildObject.parentNode;

      while(curobj != null)
      {
         if(curobj == document.body)
         {
            break;
         }

         if(curobj.id == ContainerObject.id)
         {
            retval = true;
            break;
         }
         curobj = curobj.parentNode;
      }
   }

   return retval;
}


function getEventSourceElement(event)
{
   if(Boolean(event.srcElement))
   {
      return event.srcElement;
   }
   else
   {
      return event.target;
   }
}

function multiple_select_title(select_id)
{
   var dta="";
   el = document.getElementById(select_id).options;
   for (i=0;i<el.length;i++)
   {
      if (el[i].selected == true)
      {
         dta += el[i].innerHTML+"<br>";
      }
   }

   var hint = document.getElementById(select_id+"_hint");

   if (dta!="")
   {
      hint.style.visibility = "visible";
      hint.customdata = '<b>'+dl_lang['stev.js_selected_multiple']+'</b><br>'+dta;
   }
   else
   {
      hint.style.visibility = "hidden";
      hint.customdata = '';
   }
}

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
  catch (e) {try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
  catch (e) {try {xmlhttp = new XMLHttpRequest();}
  catch (e) {xmlhttp = false;}}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone, vThis)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          if (vThis)
          {
            fnDone.call(vThis, xmlhttp);
          }
          else
          {
            fnDone(xmlhttp);
          }
        }};
      xmlhttp.send(sVars);
    }
    catch(z) {return false;}
    return true;
  };
  return this;
}

function xhr_tooltip(obj, url, param, evt, autohint)
{
   this.obj = obj;
   this.url = url;
   this.xhr = false;
   this.req_data = (param)?param:"";
   this.evt = (!evt)?"click":evt;
   this.timer = null;
   this.timeout = 500;
   this.obj_hint = (!autohint)?getE("hint"):false;
   this.obj_hint_auto = (autohint);

   this.install = function(hint)
   {
      var t = this;

      t.create_hint();
      t.obj.title = t.obj.alt = ''; 
      
      if (!XmlHttpRequest)
      {
            return false;
      }

      if (this.evt == "click")
      {
            this.obj.onclick = function()
            {
               t.start_xhr.call(t);
            }
      }
      else
      {
            this.obj.onmouseover = function()
            {
               t.timer = window.setTimeout(function()
               {
                     t.start_xhr.call(t);
               }, t.timeout, t);
               

            }

            this.obj.onmouseout = function()
            {
                  t.showhide_hint();
                  window.clearTimeout(t.timer);
            }
      }
   }
   
   this.create_hint = function()
   {
      var t = this;
      
      if (this.obj_hint_auto)
      {
            this.obj_hint = document.createElement('div');
            this.obj_hint.style.position = "absolute";
            this.obj_hint.style.backgroundColor = "#FEF7C1";            
            //vlastnost bottom se nastavuje až při vlastním zobrazení
            
            if (this.obj.parentNode.nodeName.toLowerCase() == 'span')
            {
                  this.obj_hint.style.zindex = "1";
                  this.obj_hint.style.display = "none";
                  this.obj_hint.style.left = "0";
                  this.obj.parentNode.style.position = "relative";
            }
      
            obj_hintlbl = document.createElement('div');
            this.obj_hint.appendChild(obj_hintlbl);
            this.obj.parentNode.appendChild(this.obj_hint);
      }
      else
      {
            this.obj_hint.style.width = null;
      }
      
      this.obj_hint.onclick = function(){t.showhide_hint();};
   }

   this.showhide_hint = function(show)
   {
      if (this.obj_hint_auto)
      {
         if (show)
         {
               this.obj_hint.style.bottom = (parseInt(this.obj.offsetHeight)+2)+"px"; //IE poskytuje offsetHeight až po načtení celé stránky, proto nejde zjišťovat hned v create_hint 
               this.obj_hint.style.display = 'block';               
         }
         else
         {
               this.obj_hint.style.display = 'none';
         }
      }
      else
      {if (show) 
               ShowHint(this.obj_hint.id, false,0, '<div style="text-align:center;"><img src="../img/ajax-loader_big.gif" /></div>Načítám... / Loading ...');
            else
               HideHint(this.obj_hint.id);
      }
   }
   
   this.start_xhr = function()
   {
      this.obj_hint
      this.showhide_hint(true);
      var t = this;

      var bComplete = false;
      this.xhr = XmlHttpRequest;
      this.xhr.open("POST", this.url, true);

      this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      this.xhr.setRequestHeader("Content-length", this.req_data.length);
      this.xhr.setRequestHeader("Connection", "close");
      this.xhr.onreadystatechange = function()
      {
            if (t.xhr.readyState == 4 && !bComplete)
            {
                  bComplete = true;
                  t.load_done();
            }
      };
      this.xhr.send(this.req_data);
   }

   this.load_done = function()
   {
      if (this.obj_hint_auto)
      {
         el = this.obj_hint;
      }
      else
      {
         el = getE(this.obj_hint.id+"lbl");
         t_id = this.obj_hint.id;
      }
      
      el.innerHTML = this.xhr.responseText;
         
      if (!this.obj_hint_auto)
      {
         SetHintPos();
      }
   }

   this.install();
}

/**
 **   focusObjIf_maxLength(source, target)
 **
 **   source potrebuje nastavenou maxLength
 **   kdyz je text v source dlouhy jak maxlength, skoc na target
 **/
function focusObjIf_maxLength(source, target)
{
      if (source.value.length==source.maxLength)
      {
            getE(target).focus();
      }
}

function Popup()
{
   this.source = null;
   this.divs = {"main": null, "bg": null};
   this.hasCloseButton = true;
      
   this.open = function (par)
   {
      var t;
      
      this.button = document.createElement("input");
      this.button.setAttribute("type", "button");
      this.button.setAttribute("value", "Ok");
      this.button.className = "but2";
      
      centerdiv = document.createElement("div");
      centerdiv.className = "popup_bottom";
      if (this.hasCloseButton)
      {
            centerdiv.appendChild(this.button);
      }
      
      obj_in = document.createElement("div");
      obj_in.className = "popup_in";
      obj_in.appendChild(this.source.cloneNode(true));
      obj_in.appendChild(centerdiv);
      
      try
      {
         this.source.parentNode.removeChild(this.source);
      }
      catch(e)
      {
         // nic
      }

      this.divs.main = document.createElement("div");
      this.divs.main.appendChild(obj_in);
      this.divs.main.className = "popup";
      document.body.appendChild(this.divs.main);
      
      this.divs.bg = document.createElement("div");
      this.divs.bg.className = "popup_bg";
      document.body.appendChild(this.divs.bg);
      
      t = this;

      this.button.onclick = function ()
      {
         t.remove.call(t);
      };
   };
   
   this.remove = function ()
   {
      document.body.removeChild(this.divs.main);
      document.body.removeChild(this.divs.bg);
   };
}

pageLoaded = function()
{
   var el = dl_getElementsByClassName("ispopup");
   for (i=0;i<el.length;i++)
   {
      var p = new Popup();
      p.source = el[i];
      if (el[i].className.indexOf('callback')!=-1) // pokud ma prvek navic css class callback, tak schovame tlacitko ok, autor scriptu si to obslouzi sam 
      {
            p.hasCloseButton = false;
      }
      p.open();
   }
}

/**
 * @param n    cislo
 * @param len  delka retezce, pripadne budou doplneny nuly pred retezec
 */ 
function numfix(n, len)
{
   n = n.toString();

   if (n.length < len)
   {
      for (var i = n.length; i < len ; i++)
      {
         n = "0"+n;
      }
      return n;
   }
   else
   {
      return n;
   }
}


/**
 * Přidá naslouchač událostí
 * @param eventName Název události (bez předpony "on"), například "click","change"
 * @param element Element, na který se má událost vázat (například vrácený funkcí getE)
 * @param func Funkce, která zachytí událost
 */
function dl_addEventListener(eventName, element, func) 
{
   if (element.addEventListener) // W3C DOM
   {
         element.addEventListener(eventName,func,false);
   }
   else if (element.attachEvent) // IE DOM 
   {   
         var r = element.attachEvent("on"+eventName, func);
         return r;   
   }
   else 
   {
      //nepodporovany prohlizec
   }
}

