function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}


// Vrátí část cesty obsahující název souboru
function basename(path)
{
    var filename = path.split('/');
    if (filename.length == 1) {
        var filename = path.split("\\");
    }
    filename = filename[filename.length-1];
    return filename;
}

// vloží do hlavičky script
function nactiScript(src)
{
    var scrptE = document.createElement("script");

    scrptE.setAttribute("type", "text/javascript");
    scrptE.setAttribute("language", "JavaScript");
    scrptE.setAttribute("src", src);

    document.getElementsByTagName("head")[0].appendChild(scrptE);
}

/**
* Vrátí object podle id
*/
function GetE(id,kontext)
{
    if(typeof kontext == "undefined")
        kontext = document;
    return kontext.getElementById(id);
}

/**
* oElement jenden nebo seznam elementů kterým se má nastavit styl
* Attributy asociativní pole. atribut=>hodnota
*/
function setAttribute(oElement,Attributy)
{
    if(typeof oElement == "object" && oElement.length > 0){
        for(var oElement_jeden in oElement){
            if(oElement[oElement_jeden] && oElement[oElement_jeden].nodeType==1){
                setAttribute(oElement[oElement_jeden],Attributy);
            }
        }
    } else if(typeof oElement == "object" && oElement.style) {
        for ( var atribut in Attributy ){
            //Toto je tu kvůli IE7 a starší!! Normální prohlížeče jako (FF,Chrome,Safari,Opera,IE8beta) umí vše nastavit přes oElement.setAttribute!!
            if(!isIE())
                oElement.setAttribute(atribut, Attributy[atribut]);
            else
            {
                if(atribut=='style'){ setTextStyle(oElement,Attributy[atribut]); }
                else {
                    switch(atribut)
                    {
                        case 'colspan':
                            JSatribut = 'colSpan';
                            break;
                        case 'class':
                            JSatribut = 'className';
                            break;
                        default:
                            JSatribut = atribut;
                            break;
                    }
                    oElement.setAttribute(JSatribut, Attributy[atribut]);
                }
            }
        }
    }
}

/**
* Přidá element do stránky
*/
function addElement(Tag,oNadrazenyElement,Attributy)
{
    var newElement = document.createElement(Tag);
    
    if(typeof Attributy != "undefined")
        setAttribute(newElement,Attributy);
    
    if(typeof oNadrazenyElement == "undefined" || oNadrazenyElement == null)
        return document.body.appendChild(newElement);
    else
        return oNadrazenyElement.appendChild(newElement);
}

/**
* Odtraní element ze stránky
*/
function removeElement(oElement)
{
   return oElement.parentNode.removeChild(oElement);
}

/**
* Kopíruje element do jiného
*/
function copyElement(oElement,oDestinace)
{
    var data = oElement.cloneNode(true);
    return oDestinace.appendChild(data) 
}

function insertElementBefore(oElement,oBefore)
{
    return oBefore.parentNode.insertBefore(oElement, oBefore);
}

// Add a new option to a SELECT object (combo or list)
function AddComboOption( combo, optionText, optionValue, documentObject, index )
{
    var oOption ;

    if ( documentObject )
        oOption = documentObject.createElement("OPTION") ;
    else
        oOption = document.createElement("OPTION") ;

    if ( index != null )
        combo.options.add( oOption, index ) ;
    else
        combo.options.add( oOption ) ;

    oOption.innerHTML = optionText.length > 0 ? optionText : '&nbsp;' ;
    oOption.value     = optionValue ;

    return oOption ;
}

/**
* Vrátí velikost ookna(framu)
*/
function velikostOkna(){
    if(window.innerHeight || window.innerWidth){
        return {
            width:window.innerWidth,
            height:window.innerHeight
        }
    } else{
        return {
            width:document.documentElement.clientWidth,
            height:document.documentElement.clientHeight
        }
    }
}

/**
* Vrátí velikost elementu
*/
function velikostElementu(oElement)
{
    return {
        width:oElement.offsetWidth,
        height:oElement.offsetHeight
    }
}

/**
* Vrátí pozici elementu na stránce
*/
function getPosElement(obj)
{
    var posX = obj.offsetLeft;
    var posY = obj.offsetTop;
    
    while(obj.offsetParent)
    {
        posX+=obj.offsetParent.offsetLeft;
        posY+=obj.offsetParent.offsetTop;
        if(obj==document.getElementsByTagName('body')[0]){break}
        else{obj=obj.offsetParent;}
    }
    
    return {X:posX,Y:posY};
}

/**
* Vrátí aktuální hodnotu scrollu stránky na souřadnicích X a Y
*/
function getScroll(){
    var scrOfX = 0;
    var scrOfY = 0;
    if( typeof( window.pageXOffset ) == 'number' ) {
      //Netscape compliant
      scrOfX = window.pageXOffset;
      scrOfY = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      //DOM compliant
      scrOfX = document.body.scrollLeft;
      scrOfY = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
      //IE6 standards compliant mode
      scrOfX = document.documentElement.scrollLeft;
      scrOfY = document.documentElement.scrollTop;
    }
    
    return {X:scrOfX,Y:scrOfY};
}

/**
* Vrátí velikost BODY
*/
function getBodySize()
{
    if(window.innerHeight && window.scrollMaxY)
    {
        SirkaStranky = document.body.scrollWidth;
        VyskaStranky = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight)
    {
        SirkaStranky = document.body.scrollWidth;
        VyskaStranky = document.body.scrollHeight;
    }
    else
    {
        SirkaStranky = document.body.offsetWidth;
        VyskaStranky = document.body.offsetHeight;
    }

    return {width:SirkaStranky,height:VyskaStranky};
}

/**
* Vrátí true když je na stránce sobrazen scrollbar, jinak false
*/
function isShowScrollbar(){
    if(isIE()){
        if(document.body.scroll=="yes")return true;
        if(!document.body.scroll)return true;
        if(document.body.scroll=="no")return false;
    }else{
        if(document.height>window.innerHeight||document.width>window.innerWidth)return true;
        if(document.height<=window.innerHeight&&document.width<=window.innerWidth)return false;
    }
}

/**
* Vrátí true když je prohlížeč IE, jinak false
*/
function isIE(){
    if(navigator.appVersion.indexOf("MSIE") != -1)
        return true;
    else 
        return false; 
}

/**
* Nastaví elementu mouse over a mouseout funkce
*/
function mousehover(oElement,over,out)
{
    if(typeof oElement == "object" && oElement.length > 0){
            for(var oElement_jeden in oElement){
                if(oElement[oElement_jeden].nodeType==1){
                    mousehover(oElement[oElement_jeden],over,out)
                }
            }
    } else{
        if(typeof over != "undefined")
            addEvent(oElement,'mouseover',over);
        if(typeof out != "undefined")
            addEvent(oElement,'mouseout',out);
    }
}

/**
* Vrátí tagy v elementu
* V className je možné použít ! jako negaci názvu třídy, pak vrátí tagy které namí nastavenou zadanou třídu.
*/
function findTag(oElement,Tag,className)
{
    var NalezeneTagy = oElement.getElementsByTagName(Tag);
    if(typeof className != "undefined"){
        var retTagy = new Array();
        for (var TagJeden=0; TagJeden < NalezeneTagy.length; TagJeden++)
        {
            // když první znak je !
            if(className.indexOf('!')==0)
            {
                if (typeof NalezeneTagy[TagJeden].className == "undefined" || !in_array(className.substr(1),explode(' ',NalezeneTagy[TagJeden].className)))
                {
                    //tagy které nemají třídu className
                    retTagy.push(NalezeneTagy[TagJeden]);
                }
            } else {
                if (NalezeneTagy[TagJeden].className && in_array(className,explode(' ',NalezeneTagy[TagJeden].className)))
                {
                    //tagy které mají třídu className
                    retTagy.push(NalezeneTagy[TagJeden]);
                }
            }
        }
        return retTagy;
    } else {
        return NalezeneTagy;
    }
}

/**
*
*/
function in_array(needle, haystack, argStrict)
{
    var found = false, key, strict = !!argStrict;

    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }

    return found;
}

function mpd(pole) {
    str = '';
    for (var id in pole) {
        str = str + id.toString() + ':' + pole[id].toString() + '\n';
    }
    alert(str);
}

function PS_escape( retesc )
{
    var retezec = new String(retesc);
    retezec = retezec.replace(/-/g,'-2D');
    retezec = retezec.replace(/=/g,'-3D');
    retezec = retezec.replace(/;/g,'-3B');
    retezec = retezec.replace(/&/g,'-26');
    retezec = retezec.replace(/%/g,'-25');
    retezec = retezec.replace(/,/g,'-2C');
    retezec = retezec.replace(/\x27/g,'-27');
    retezec = retezec.replace(/\x22/g,'-22');
    retezec = retezec.replace(/\x0A/g,'-0A');
    retezec = retezec.replace(/\x0D/g,'-0D');
    retezec = retezec.replace(/\x09/g,'-09');
    retezec = retezec.replace(/#/g,'-23');
    retezec = retezec.replace(/\+/g,'-2b');
    retezec = retezec.replace(/\</g,'-3C');
    return retezec;
}

function PS_unescape( retesc )
{
    var retezec = new String(retesc);
    retezec = retezec.replace(/-3C/g,'\<');
    retezec = retezec.replace(/-2b/g,'\+');
    retezec = retezec.replace(/-23/g,'#');
    retezec = retezec.replace(/-09/g,'\x09');
    retezec = retezec.replace(/-0D/g,'\x0D');
    retezec = retezec.replace(/-0A/g,'\x0A');
    retezec = retezec.replace(/-22/g,'\"');
    retezec = retezec.replace(/-27/g,'\'');
    retezec = retezec.replace(/-2C/g,',');
    retezec = retezec.replace(/-25/g,'%');
    retezec = retezec.replace(/-26/g,'&');
    retezec = retezec.replace(/-3B/g,';');
    retezec = retezec.replace(/-3D/g,'=');
    retezec = retezec.replace(/-2D/g,'-');
    return retezec;
}

// Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.  
    // 
    // version: 810.114
    // discuss at: http://phpjs.org/functions/explode
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
function explode( delimiter, string, limit )
{
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

/**
* Nastaví elementu display:block;
*/
function show(oElement)
{
    setStyle(oElement,{display:'block'});
}

/**
* Nastaví elementu display:none;
*/
function hide(oElement)
{
    setStyle(oElement,{display:'none'});
}

/**
* Přidá elementu class
*/
function addClass(oElement,novaTrida)
{
    var Tridy = getClass(oElement);
    
    var NoveTridy = novaTrida.split(' ');
    for(var i in NoveTridy){
        // pridat class
        var Pridat = true;
        for(var j in Tridy){
            // když už třídy je nastavená tak jí nepřidávat
            if(Tridy[j]==NoveTridy[i])
                Pridat = false;
        }
        if(Pridat)
            Tridy.push(NoveTridy[i]);
    }
    
    setClass(oElement,Tridy.join(' '));
}

function getClass(oElement)
{
    var Tridy = new Array();
    
    if (isIE())
    {
        if (oElement.getAttribute('className')!=null)
            var Tridy = oElement.getAttribute('className').split(' ');
    }else{
        if (oElement.getAttribute('class')!=null)
            var Tridy = oElement.getAttribute('class').split(' ');
    }
    
    return Tridy;
}

function setClass(oElement,Class)
{
    if (isIE())
        return oElement.setAttribute('className',Class);
    else
        return oElement.setAttribute('class',Class);
}

/**
* odstraní class elementu
*/
function removeClass(oElement,trida)
{
    var Tridy = new Array();
    
    if (isIE())
    {
        if (oElement.getAttribute('className')!=null)
            var Tridy = oElement.getAttribute('className').split(' ');
    }else{
        if (oElement.getAttribute('class')!=null)
            var Tridy = oElement.getAttribute('class').split(' ');
    }
    
    var odstranitTridy = trida.split(' ');
    for(var i in odstranitTridy){
        for(var j in Tridy){
            if(Tridy[j]==odstranitTridy[i])
                Tridy.splice(j,1);
        }
    }
    
    if (isIE())
        oElement.setAttribute('className',Tridy.join(' '));
    else
        oElement.setAttribute('class',Tridy.join(' '));
}

/**
* Změní Class elementu
*/
function changeElementClass(oElement,trida,novatrida)
{
    removeClass(oElement,trida);
    addClass(oElement,novatrida);
}

/*
* Vrátí hodnotu CSS property elementu
*/
function getStyle(oElement, strCssRule)
{
    var strValue = "";
    if(document.defaultView && document.defaultView.getComputedStyle)
    {
        strValue = document.defaultView.getComputedStyle(oElement, "").getPropertyValue(strCssRule);
    }
    else if(oElement.currentStyle)
    {
        strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
            return p1.toUpperCase();
        });
        strValue = oElement.currentStyle[strCssRule];
    }
    return strValue;
}

function getAllStyle(oElement)
{
    var Style = {};
    if(document.defaultView && document.defaultView.getComputedStyle)
    {
        var oStyle = document.defaultView.getComputedStyle(oElement, "");
        
        for(var i=0; i < oStyle.length;i++)
        {
            Style[oStyle.item(i)] = getStyle(oElement,oStyle.item(i));
        }
    }
    else if(oElement.currentStyle)
    {
        var oStyle = oElement.currentStyle;
        
        for(var properta in oStyle)
        {
            Style[properta] = oStyle[properta];
        }
    }
    
    return Style;
}

/**
* oElement jenden nebo seznam elementů kterým se má nastavit styl
* Properties asociativní pole. properta=>hodnota
*/
function setStyle(oElement,Properties)
{
    if(typeof oElement == "object" && oElement.length > 0)
    {
        for(var oElement_jeden in oElement)
        {
            if(oElement[oElement_jeden] && oElement[oElement_jeden].nodeType==1)
                setStyle(oElement[oElement_jeden],Properties);
        }
    }
    else if(typeof oElement == "object" && oElement.style)
    {
        for ( var CSSProperta in Properties )
        {
            //nahrazení pomlčky a zvětšení prvního znaku za pomlčkou
            Properta = CSSProperta.replace(/\-(\w)/g, function (strMatch, p1){
                return p1.toUpperCase();
            });
            
            try
            {
                oElement.style[Properta] = Properties[CSSProperta];
            }
            catch(exception)
            {
                //nepovedlo se
            }
        }
    }
}

function setTextStyle(oElement, declaration)
{
    declaration = String(declaration);
    if(declaration.length<1)
        return;
    if (declaration.charAt(declaration.length-1)==';')
        declaration = declaration.slice(0, -1);
    var Properta, hodnota;
    var splitted = declaration.split(';');
    for (var i=0, len=splitted.length; i<len; i++)
    {
        var Properties = {};
        Properta = trim(splitted[i].split(':')[0]);
        hodnota = splitted[i].split(':')[1];
        Properties[Properta] = hodnota;
        setStyle(oElement,Properties);
    }
}

/**
* Načte stránku do Elementu
*/
function load(url,callback)
{
    url_split = url.split('?');
    url = url_split[0];
    parametry = url_split[1];
    var load = new PS_Ajax();
    load.POST_URL = url;
    load.GetParametry = parametry;
    load.funkceProObsluhu = callback;
    load.typObsluhy = 'J';
    load.load();
}

/**
* Vrátí hodnotu GET proměnné
*/
function _GET( name, url)
{
  if(typeof url == "undefined")
        url = window.location.href;
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( url );
  if( results == null )
    return "";
  else
    return results[1];
}

/**
* Zablokuje označování prvků uvnitř elementu
*/
function disableSelection(element) {
    element.onselectstart = function() {
        return false;
    };
    element.unselectable = "on";
    element.style.MozUserSelect = "none";
    element.style.cursor = "default";
}

/**
* Povolí označování prvků uvnitř elementu
*/
function enableSelection(element) {
    element.onselectstart = null;
    element.unselectable = "off";
    element.style.MozUserSelect = "";
    element.style.cursor = "default";
}

function getSelectionText()
{
    var txt = '';
    if (window.getSelection)
    {
        txt = window.getSelection();
    }
    else if (document.getSelection)
    {
        txt = document.getSelection();
    }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
    }
    else return;
    
    return String(txt);
}

/* document.getElementsBySelector(selector)
   - returns an array of element objects from the current document
     matching the CSS selector. Selectors can contain element names, 
     class names and ids and can be nested. For example:
     
       elements = document.getElementsBySelect('div#main p a.external')
     
     Will return an array of all 'a' elements with 'external' in their 
     class attribute that are contained inside 'p' elements that are 
     contained inside the 'div' element which has id="main"

   New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
   See http://www.w3.org/TR/css3-selectors/#attribute-selectors

   Version 0.4 - Simon Willison, March 25th 2003
   -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
   -- Opera 7 fails 
*/

function getAllChildren(e) {
  // Returns all children of element. Workaround required for IE5/Windows. Ugh.
  return e.all ? e.all : e.getElementsByTagName('*');
}

document.getElementsBySelector = function(selector) {
  // Attempt to fail gracefully in lesser browsers
  if (!document.getElementsByTagName) {
    return new Array();
  }
  // Split selector in to tokens
  var tokens = selector.split(' ');
  var currentContext = new Array(document);
  for (var i = 0; i < tokens.length; i++) {
    token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
    if (token.indexOf('#') > -1) {
      // Token is an ID selector
      var bits = token.split('#');
      var tagName = bits[0];
      var id = bits[1];
      var element = document.getElementById(id);
      if (tagName && element.nodeName.toLowerCase() != tagName) {
        // tag with that ID not found, return false
        return new Array();
      }
      // Set currentContext to contain just this element
      currentContext = new Array(element);
      continue; // Skip to next token
    }
    if (token.indexOf('.') > -1) {
      // Token contains a class selector
      var bits = token.split('.');
      var tagName = bits[0];
      var className = bits[1];
      if (!tagName) {
        tagName = '*';
      }
      // Get elements matching tag, filter them for class selector
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      continue; // Skip to next token
    }
    // Code to deal with attribute selectors
    /* That revolting regular expression explained 
    /^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
      \---/  \---/\-------------/    \-------/
        |      |         |               |
        |      |         |           The value
        |      |    ~,|,^,$,* or =
        |   Attribute 
       Tag
    */
    if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
      var tagName = RegExp.$1;
      var attrName = RegExp.$2;
      var attrOperator = RegExp.$3;
      var attrValue = RegExp.$4;
      if (!tagName) {
        tagName = '*';
      }
      // Grab all of the tagName elements within current context
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      var checkFunction; // This function will be used to filter the elements
      switch (attrOperator) {
        case '=': // Equality
          checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
          break;
        case '~': // Match one of space seperated words 
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
          break;
        case '|': // Match start with value followed by optional hyphen
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
          break;
        case '^': // Match starts with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
          break;
        case '$': // Match ends with value - fails with "Warning" in Opera 7
          checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
          break;
        case '*': // Match ends with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
          break;
        default :
          // Just test for existence of attribute
          checkFunction = function(e) { return e.getAttribute(attrName); };
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (checkFunction(found[k])) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
      continue; // Skip to next token
    }
    // If we get here, token is JUST an element (not a class or ID selector)
    tagName = token;
    var found = new Array;
    var foundCount = 0;
    for (var h = 0; h < currentContext.length; h++) {
      var elements = currentContext[h].getElementsByTagName(tagName);
      for (var j = 0; j < elements.length; j++) {
        found[foundCount++] = elements[j];
      }
    }
    currentContext = found;
  }
  return currentContext;
}

/**
 *  Priradi urcite udalosti objektu zadanou obsluznou funkci. Rozhodne
 *  automaticky, zda pouzit attachEvent, nebo addEventListener. Resi problem
 *  s pouzitim this uvnitr obsluzne funkce.
 *  @param obj Objekt, u nehoz chceme udalost obsluhovat.
 *  @param event Udalost, jiz hodlame obslouzit - ve formatu click, load apod.
 *               (nikoliv onclick, onload).
 *  @param funct Nazev obsluzne funkce.
 */
function addEvent(obj, event, funct) {
  if (obj.attachEvent) { //IE
    obj['e' + event + funct] = funct;
    obj['x' + event + funct] = function() {
        return obj['e' + event + funct](window.event);
    }
    obj.attachEvent('on' + event, obj['x' + event + funct]);
  } else // other browser
    obj.addEventListener(event, funct, false);
}

/**
 *  Odstrani zadanou obsluznou funkci registrovanou u objektu.
 *  @param obj Objekt, u nehoz chceme obsluznou funkci odstrani.
 *  @param event Udalost, jiz doposud funkce obsluhovala - ve formatu click,
 *               load apod. (nikoliv onclick, onload).
 *  @param funct Nazev obsluzne funkce, jiz planujeme odstranit.
 */
function removeEvent(obj, event, funct) {
  if (obj.detachEvent) { // IE
    obj.detachEvent('on' + event, obj[event + funct]);
    obj['x' + event + funct] = null;
  } else // other browser
    obj.removeEventListener(event, funct, false );
}

function spamOchrana() {
    var currentTime = new Date();    
    var html = '<input type="hidden" name="ochranaPredSpamy" value="'+currentTime.getDate()+'bez'+(currentTime.getMonth()+1)+'Spamu'+currentTime.getFullYear()+'" />';                        
    return html;
}

function zobrazDetail(url, alt) {    
    var sirka, vyska;
    var html = url;
    var transparentniDiv; 
    var obsahDivu;   
    
    function zmenaRozmeruDivu() {
        var top = Math.max(document.body.scrollTop, document.documentElement.scrollTop);

        if(!transparentniDiv)
            return;
        
        var st = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
        var sl = Math.max(document.body.scrollLeft, document.documentElement.scrollLeft);
                        
        window.scrollTo(sl, st);
        setTimeout('window.scrollTo(' + sl + ',' + st + ');',10);
        
        var rozmery = vratRozmeryBrowseru();
        var sirkaBody = rozmery[0];
        var vyskaBody = rozmery[1];
        
        obsahDivu.style.width = sirka + 'px';
        obsahDivu.style.height = vyska + 'px';      
        
        var sirkaObsahu = obsahDivu.offsetWidth;    
        var vyskaObsahu = obsahDivu.offsetHeight;

        obsahDivu.style.left = Math.ceil((sirkaBody - sirkaObsahu) / 2) + 'px';         
        var horniPozice = vyskaBody - vyskaObsahu;
        if (horniPozice < 0)
            horniPozice = 0;    
        obsahDivu.style.top = (Math.ceil(horniPozice / 2) +  top) + 'px';
        
        zmenaPoziceDivu(); 
    }

    function zmenaPoziceDivu() {
        transparentniDiv.style.top = Math.max(document.body.scrollTop, document.documentElement.scrollTop) + 'px';
        transparentniDiv.style.left = Math.max(document.body.scrollLeft, document.documentElement.scrollLeft) + 'px';
        
        var rozmery = vratRozmeryStranky();
        var sirkaBody = rozmery[0];
        var vyskaBody = rozmery[1];
    
        transparentniDiv.style.width = sirkaBody + 'px';    
        transparentniDiv.style.height = vyskaBody + 'px';              
    }

    function vratRozmeryBrowseru() {
        var sirkaBody = document.documentElement.clientWidth;
        var vyskaBody = document.documentElement.clientHeight;
        
        if (self.innerHeight){ 
           // pro všechny kromě Explorer         
           sirkaBody = self.innerWidth; 
           vyskaBody = self.innerHeight; 
        } else if (document.documentElement && document.documentElement.clientHeight) {
           // Explorer 6       
           sirkaBody = document.documentElement.clientWidth; 
           vyskaBody = document.documentElement.clientHeight; 
        } else if (document.body) {
           // ostatní prohlížeče         
           sirkaBody = document.body.clientWidth; 
           vyskaBody = document.body.clientHeight; 
        }      
        
        return [sirkaBody, vyskaBody];       
    }
    
    function vratRozmeryStranky() {
        var sirkaStranky = document.documentElement.clientWidth;
        var vyskaStranky = document.documentElement.clientHeight;
        
        if(window.innerHeight && window.scrollMaxY) {
            sirkaStranky = document.body.scrollWidth;
            vyskaStranky = window.innerHeight + window.scrollMaxY;
        }
        else if (document.body.scrollHeight > document.body.offsetHeight) {
            sirkaStranky = document.body.scrollWidth;
            vyskaStranky = document.body.scrollHeight;
        }
        else {
            sirkaStranky = document.body.offsetWidth;
            vyskaStranky = document.body.offsetHeight;
        }
                
        return [sirkaStranky, vyskaStranky];       
    }  
    
    var rozmery = vratRozmeryBrowseru();
    var obr = new Image();
    obr.src = url + "?w=" + (rozmery[0] - 50);
    //alert(obr.src);
    if(isIE())
    {
        if (!obr.complete)
            obr.onload = vratOkno;
        else
            vratOkno();
    } else {        
        obr.onload = vratOkno;
    }
    
    function vratOkno() {
        sirka = obr.width;
        vyska = obr.height + 36;
        
        transparentniDiv = document.getElementById('transparentDiv');
        obsahDivu = document.getElementById('contentDiv');
            
        if (!transparentniDiv || !obsahDivu) {
            transparentniDiv = document.createElement('DIV');
            transparentniDiv.id = "transparentDiv";       
            obsahDivu = document.createElement('DIV');
            obsahDivu.id = "contentDiv";    
        }
        transparentniDiv.onclick = function(){ skryjDetail() }
        obsahDivu.onclick = function(){ skryjDetail() }
             
        transparentniDiv.style.left = '0px';
        transparentniDiv.style.top = '0px';
        
        document.body.appendChild(transparentniDiv);            
        
        obsahDivu.style.zIndex = 100000;   
         
        document.body.appendChild(obsahDivu);
            
        transparentniDiv.style.filter = 'alpha(opacity=40)';
        transparentniDiv.style.opacity = '0.4';
        transparentniDiv.style.backgroundColor = '#AAA';
        transparentniDiv.style.zIndex = '1';
        transparentniDiv.style.position = 'absolute';
        transparentniDiv.style.display='block';
        
        obsahDivu.style.border = '1px solid #000';
        obsahDivu.style.padding = '2px';
        obsahDivu.style.zIndex = '100';
        obsahDivu.style.position = 'absolute';
        obsahDivu.style.backgroundColor = '#FFF';
        obsahDivu.style.display = 'block';                   
        
        // pro IE, nepodporuje tuto metodu
        if(!Array.indexOf){
            Array.prototype.indexOf = function(obj){
                for(var i=0; i<this.length; i++){
                    if(this[i]===obj){
                        return i;
                    }
                }
                return -1;
            }
        } 
            
        zmenaRozmeruDivu();       

        var URLpredObr = '';
        var URLnaslObr = '';        
        var odkPredObr = '';
        var odkNaslObr = '';        
        
        if (poleSrcObr != undefined && poleAltObr != undefined) {                 
            var indexObr = poleSrcObr.indexOf(url);
                                            
            if (indexObr != 0) {                
                URLpredObr = "zobrazDetail('" + poleSrcObr[indexObr-1] + "', '" + poleAltObr[indexObr-1] + "')";
                odkPredObr = '<<';
            }
                            
            if (indexObr != poleSrcObr.length-1) {                
                URLnaslObr = "zobrazDetail('" + poleSrcObr[indexObr+1] + "', '" + poleAltObr[indexObr+1] + "')";            
                odkNaslObr = '>>';
            }
        }
                          
        html = '<p style="text-align: right; font-size: 14px; margin: 0px; padding: 0px 5px 0px 5px; font-weight: bolder;">';
        html += '<a href=\'#\' onclick=\'skryjDetail();return false\'>X</a></p>';        
        html += '<img src="' + url + '?w=' + sirka + '">';
        html += "<a style=\"display:block; float: left; font-weight: bold; font-size: 14px; width: 10%; margin: 2px 0px;\" href=\"#\" onclick=\"" + URLpredObr + "\">" + odkPredObr + "</a>";
        html += '<p style="float: left; text-align: center; font-size: 14px; width: 80%; margin: 2px 0px;">' + alt + '</p>';                                                                 
        html += "<a style=\"display:block; float: left; font-weight: bold; font-size: 14px; width: 10%; margin: 2px 0px;\" href=\"#\" onclick=\"" + URLnaslObr + "\">" + odkNaslObr + "</a>";                        
        
        obsahDivu.innerHTML = html;     
    }     
} 

function skryjDetail() {
    transparentniDiv = document.getElementById('transparentDiv');
    obsahDivu = document.getElementById('contentDiv');
    
    if (!transparentniDiv || !obsahDivu)
        return;
        
    transparentniDiv.style.display = 'none';
    obsahDivu.style.display = 'none';
}

function validujFormulare()
{
    jQuery("form").each(function(index, field){
        jQuery(field).validate();
    });
}
