﻿/* metody rozsirujici stavajici objekty */

Array.prototype.indexOf = function(value) 
{
    for (var i = 0, count = this.length; i < count; i++) {
        if (this[i] === value) return i;
    }
    return -1;
};

Array.prototype.contains = function(value) {
    return this.indexOf(value) > -1;
};

Array.prototype.remove = function(value) {
    var index = this.indexOf(value);
    if (index > -1) {
        return this.splice(index, 1);
    }
    return null;
}

String.prototype.trim = (function() {
    var ws = {},
        chars = ' \n\r\t\v\f\u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
    for (var i = 0; i < chars.length; i++)
        ws[chars.charAt(i)] = true;

    return function() {
        var s = -1,
            e = this.length;
        while (ws[this.charAt(--e)]);
        while (s++ !== e && ws[this.charAt(s)]);
        return this.substring(s, e + 1);
    };
})();

String.prototype.decodeHtml = function() {
    return this.replace(/&#(\d+);/g,
    function(a, b) {
        return String.fromCharCode(+b);
    });
};
String.prototype.camelize = function() {
    return this.replace(/\-(\w)/g, function(strMatch, p1) {
        return p1.toUpperCase();
    });
};


/******************************************************************************************/
/* obecně užitečné metody */


KAKTUS = (function() {
    var __tabs = new Array()
    function __debug(str) {
        var info = KAKTUS.getElement('info');
        if (info == null) return;
        info.value = str + '\n' + info.value;
        if (info.value.length > 500) info.value = info.value.substring(0, 500);
    }
    function constructorFn() {
    };
    constructorFn.__debug = __debug;
    constructorFn.tabsOnPage = __tabs;
    ///////////////////////////////////////////////////////////////////////////////////////////////  
    ///////////////////////////////////////////////////////////////////////////////////////////////  
    ///////////////////////////////////////////////////////////////////////////////////////////////  
    function __FindFirstFocusableChild(control) {
        if (!control || !(control.tagName)) {
            return null;
        }
        var tagName = control.tagName.toLowerCase();
        if (tagName == 'undefined') {
            return null;
        }
        var children = control.childNodes;
        if (children) {
            for (var i = 0; i < children.length; i++) {
                try {
                    if (__CanFocus(children[i])) {
                        return children[i];
                    }
                    else {
                        var focused = __FindFirstFocusableChild(children[i]);
                        if (__CanFocus(focused)) {
                            return focused;
                        }
                    }
                } catch (e) {
                }
            }
        }
        return null;
    }

    function __CanFocus(element) {
        if (!element || !(element.tagName)) return false;
        var tagName = element.tagName.toLowerCase();
        return (!(element.disabled) &&
            (!(element.type) || element.type.toLowerCase() != "hidden") &&
            __IsFocusableTag(tagName) &&
            __IsInVisibleContainer(element)
            );
    }
    function __IsFocusableTag(tagName) {
        tagName = tagName.toLowerCase()
        return (tagName == "input" || tagName == "textarea" || tagName == "select" || tagName == "button" || tagName == "a");
    }

    function __IsInVisibleContainer(ctrl) {
        var current = ctrl;
        /* zjistime, zda je v nejakem tabu a pripadne ho selectneme - ZACATEK*/
        for (var i = 0; i < __tabs.length; i++) {
            var indexOfTab = __tabs[i].getElementPageIndex(current);
            if (indexOfTab != -1) {
                __tabs[i].selectByIndex(indexOfTab);
            }
        }
        /* zjistime, zda je v nejakem tabu a pripadne ho selectneme  - KONEC */
        while ((typeof (current) != "undefined") && (current != null)) {

            if (current.disabled ||
            (typeof (current.style) != "undefined" &&
            ((typeof (current.style.display) != "undefined" &&
                current.style.display == "none") ||
                (typeof (current.style.visibility) != "undefined" &&
                current.style.visibility == "hidden")))) {
                return false;
            }
            if (typeof (current.parentNode) != "undefined" &&
                current.parentNode != null &&
                current.parentNode != current &&
                current.parentNode.tagName.toLowerCase() != "body") {
                current = current.parentNode;
            }
            else {
                return true;
            }
        }
        return true;
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////  
    ///////////////////////////////////////////////////////////////////////////////////////////////  
    ///////////////////////////////////////////////////////////////////////////////////////////////  
    constructorFn.FocusElement = function(element) {
        var targetControl = KAKTUS.getElement(element);
        if (targetControl && (!__CanFocus(targetControl))) {
            targetControl = __FindFirstFocusableChild(targetControl);
        }
        if (targetControl) {
            try {
                targetControl.focus();
                if (__nonMSDOMBrowser) {
                    targetControl.scrollIntoView(false);
                }
                if (window.__smartNav) {
                    window.__smartNav.ae = targetControl.id;
                }
            }
            catch (e) {
            }
        }
    };
    return constructorFn;

})();

KAKTUS.GetResource = function(txt, defaultValue) {
    if (typeof (KAKTUS__RESOURCES) != 'undefined' && KAKTUS__RESOURCES[txt]) return KAKTUS__RESOURCES[txt];
    return defaultValue;
}

KAKTUS.Event = (function() {
    function __getSrcElement(e) {
        var srcElement;
        if (e && e.target) {
            srcElement = e.target;
            while (srcElement.nodeType != 1) srcElement = srcElement.parentNode;
        }
        else if (e.srcElement) {
            srcElement = e.srcElement;
        }
        return srcElement;
    }

    function __getEvent(evt) {
        evt = evt ? evt : (window.event ? window.event : Event);
        return evt;
    }


    // funkce přiřadí eventhandler dané události pro daný element
    function __addHandler(element, eventId, fce) {
        if (element.addEventListener) {
            element.addEventListener(eventId, fce, false);
        } else if (element.attachEvent) {
            element.attachEvent("on" + eventId, fce);
        }
        else {
            var oldHandler = element["on" + eventId];
            if (typeof (oldHandler) == 'function') {
                element["on" + eventId] = function(ev) {
                    oldHandler(ev);
                    fce(ev);
                }
            }
            else {
                element["on" + eventId] = fce;
            }
        }
    }

    // funkce přiřadí eventhandler dané události pro daný element
    function __removeHandler(element, eventId, fce) {
        if (element.removeEventListener) {
            element.removeEventListener(eventId, fce, false);
        }
        else if (element.detachEvent) {
            element.detachEvent("on" + eventId, fce);
        }
    }

    function __stopPropagation(ev) {
        if (ev && ev.stopPropagation) ev.stopPropagation();
        else if (window.event)
            window.event.cancelBubble = true;
    }

    function __preventDefault(ev) {
        if (ev && ev.preventDefault) ev.preventDefault();
        else if (window.event)
            window.event.returnValue = false;
    }
    
    function constructorFn() {
    };
    constructorFn.getEvent = __getEvent;
    constructorFn.getSrcElement = __getSrcElement;
    constructorFn.addHandler = __addHandler;
    constructorFn.removeHandler = __removeHandler;
    constructorFn.stopPropagation = __stopPropagation;
    constructorFn.preventDefault = __preventDefault;
    return constructorFn;
})();

KAKTUS.HorizontalAlignEnum = { Left: "left", Right: "right", Center: "center" };
KAKTUS.SizeUnitEnum = { Pixel: "px", Point: "pt", Percentage: "%", Em: "em", Auto: "auto" };

KAKTUS.Size = (function() {
    function constructorFn(a, b) {
        this.value = a ? parseFloat(a) : NaN;
        this.unit = isNaN(this.value) ? KAKTUS.SizeUnitEnum.Auto : KAKTUS.SizeUnitEnum.Pixel;
        if (!b && a) {
            for (var su in KAKTUS.SizeUnitEnum) {
                if (a.indexOf(KAKTUS.SizeUnitEnum[su]) != -1) {
                    this.unit = KAKTUS.SizeUnitEnum[su];
                    break;
                }
            }
        }
        else {
            this.unit = b;
        }
    }
    constructorFn.prototype.toString = function() {
        if (isNaN(this.value)) {
            return (this.unit != KAKTUS.SizeUnitEnum.Auto) ? "" : this.unit;
        }
        var v = this.value ? this.value : "";
        var u = this.unit ? this.unit : "";
        return v + u;
    }
    return constructorFn;
})();

KAKTUS.CopyProperties = function(src, dest) {
    if (!src) return;
    for (var prop in dest) {
        if (src[prop]) dest[prop] = src[prop];
    }
}

KAKTUS.CopyStyles = function(src, dest, included, excluded) {
    if (!src || !dest || !src.style || !src.style) return;
    if (!included) included = src.style;
    if (included.length) {
        for (var i = 0; i < included.length; i++) {
            var prop = included[i];
            if (!excluded || excluded.indexOf(prop) == -1) {
                try {
                    var val = KAKTUS.getStyle(src, prop);
                    dest.style[prop.camelize()] = val;
                }
                catch (exc) { }

            }
        }
    }
    else {
        for (var prop in included) {
            if (!excluded || excluded.indexOf(prop) == -1) {
                try {
                    dest.style[prop] = KAKTUS.getStyle(src, prop);
                }
                catch (exc) { }
            }
        }
    }
}

KAKTUS.setOpacity = function(element, opacity) {
    element = KAKTUS.getElement(element);
    if (opacity > 100) opacity = 100;
    if (opacity < 0) opacity = 0;
    element.style["opacity"] = opacity / 100.0;
    element.style["-moz-opacity"] = opacity / 100.0;
    element.style["-khtml-opacity"] = opacity / 100.0;
    if (opacity == 100) {
        element.style.filter = "";
    }
    else {
        element.style.filter = "alpha(opacity=" + opacity.toFixed() + ")";
    }
}

KAKTUS.getOpacity = function(element) {
    element = KAKTUS.getElement(element);
    var opacity = 100;
    var styles = ["opacity", "-moz-opacity", "-khtml-opacity"];
    for (var i = 0; i < styles.length; i++) {
        var op = KAKTUS.getStyle(element, styles[i]);
        if (op && op != 1) opacity = Math.floor(100 * op);
    }
    if (opacity == 100) // je mozne, ze jsme nic nenasli, tak se podivame jeste do filtru
    {
        var filter = KAKTUS.getStyle(element, 'filter');
        if (filter) {
            var re = filter.match(/alpha\s*\(\s*opacity\s*=\s*([^)]*)\s*\)/i);
            if (re.length > 1) opacity = parseInt(re[1]);
        }
    }
    return opacity;
}

KAKTUS.getHttpRequest = function(url, callback) {
    var httpReq;
    if (typeof (XMLHttpRequest) != 'undefined') {
        httpReq = new XMLHttpRequest();
    }
    else if (typeof (ActiveXObject) != 'undefined') {
        httpReq = new ActiveXObject('Microsoft.XMLHTTP');
    }
    else return null;
    if (callback && typeof (callback) == 'function') {
        httpReq.onreadystatechange = function() {
            if (httpReq.readyState == 4 && (httpReq.status == 200 || httpReq.status == 304)) {
                callback(url, httpReq.responseXML);
            }
        };
    }
    httpReq.open('GET', url, true);
    httpReq.send('');
    return httpReq;
}

// HashTable
KAKTUS.Hashtable = function() {
    var __array = new Array();
    function __clear() {
        __array = new Array();
    }

    function __indexOfKey(key) {
        for (var i = 0, count = __array.length; i < count; i++) {
            var obj = __array[i];
            if (obj.key === key) return i;
        }
        return -1;
    }

    function __indexOfValue(value) {
        if (value != null) {
            for (var i = 0, count = __array.length; i < count; i++) {
                var obj = __array[i];
                if (obj.value === value) return i;
            }
        }
        return -1;
    }

    function __containsKey(key) {
        return __indexOfKey(key) == -1 ? false : true;
    }

    function __containsValue(value) {
        return __indexOfValue(value) == -1 ? false : true;
    }

    function __get(key) {
        var index = __indexOfKey(key);
        return index == -1 ? null : __array[index].value;
    }


    function __isEmpty() {
        return (__array.length == 0) ? true : false;
    }

    function __keys() {
        var keys = new Array();
        for (var i = 0, count = __array.length; i < count; i++) {
            var obj = __array[i];
            keys.push(obj.key);
        }
        return keys;
    }

    function __values() {
        var values = new Array();
        for (var i = 0, count = __array.length; i < count; i++) {
            var obj = __array[i];
            keys.push(obj.value);
        }
        return keys;
    }

    function __insert(key, value) {
        var index = __indexOfKey(key);
        if (index == -1) {
            __array.push({ key: key, value: value });
        }
        else {
            __array[index].value = value;
        }
    }

    function __removeAt(index) {
        if (index < 0 || index >= __array.length) return null;
        var value = __array[index].value;
        __array.splice(index, 1);
        return value;
    }

    function __remove(key) {
        return __removeAt(__indexOfKey(key));
    }

    function __size() {
        return __array.length;
    }

    function __toString() {
        var retval = '';
        for (var i = 0, count = __array.length; i < count; i++) {
            var obj = __array[i];
            if (i > 0) retval += '\n';
            retval += '{' + obj.key.id + ', ' + obj.value + '}';
        }
        return retval == '' ? '(empty)' : retval;
    }

    this.clear = __clear;
    this.get = __get;
    this.indexOfKey = __indexOfKey;
    this.indexOfValue = __indexOfValue;
    this.containsKey = __containsKey;
    this.containsValue = __containsValue;
    this.insert = __insert;
    this.isEmpty = __isEmpty;
    this.keys = __keys;
    this.removeAt = __removeAt;
    this.remove = __remove;
    this.size = __size;
    this.toString = __toString;
}

// QueryStringParser

KAKTUS.QueryString = function(qs) {
    this.params = new Object();
    this.getValue = function(key, defaultValue) {
        if (defaultValue == null) defaultValue = null;
        var value = this.params[key.toLowerCase()];
        return value == null ? defaultValue : value;
    }

    if (qs == null && window.location) qs = window.location.search.substring(1, location.search.length)
    if (qs.length == 0) return;
    qs = qs.replace(/\+/g, ' ')
    var args = qs.split('&') // parse out name/value pairs separated via &

    for (var i = 0; i < args.length; i++) {
        var value;
        var pair = args[i].split('=')
        var name = unescape(pair[0])

        if (pair.length == 2)
            value = unescape(pair[1])
        else
            value = name;
        this.params[name.toLowerCase()] = value
    }
}

KAKTUS.isElement = function(object) {
    return !!(object && object.nodeType == 1);
}

KAKTUS.getElement = function() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof (element) == 'string') { // v element je id elementu
            if (document.getElementById)
                element = document.getElementById(element);
            else
                element = document.all[element];
        }
        else if (element != null && !KAKTUS.isElement(element)) { // v element neni id a ani tam neni primo element, takze by to mohlo byt pole (ID nebo elementu nebo poli), tak volame rekurzi
            element = KAKTUS.getElement(element);
        }
        if (arguments.length == 1) return element;
        elements.push(element);
    }
    return elements;
}

KAKTUS.getStyle = function(element, cssRule) {
    element = KAKTUS.getElement(element);
    var value = null;
    if (element) {
        if (element.currentStyle) {
            value = element.currentStyle[cssRule.camelize()];
        }
        else if (document.defaultView && document.defaultView.getComputedStyle) {
            var style = document.defaultView.getComputedStyle(element, null);
            if (style) {
                value = style[cssRule];
                if (!value) value = style[cssRule.camelize()];
            }
        }

        if (!value && element.style.getPropertyValue) {
            value = element.style.getPropertyValue(cssRule.camelize());
        }
        if (!value && element.style.getAttribute) {
            value = element.style.getAttribute(cssRule.camelize());
        }
        if (!value && element.style) {
            value = element.style[cssRule];
            if (!value) value = element.style[cssRule.camelize()];
        }
    }

    if (window.opera && ['left', 'top', 'right', 'bottom'].indexOf(cssRule) != -1) {
        if (KAKTUS.getStyle(element, 'position') == 'static') value = 'auto';
    }
    return value == 'auto' ? null : value;
}

KAKTUS.isArray = function(obj) {
    return obj != null && (typeof (obj) == "object" && 'splice' in obj && 'join' in obj);
}

KAKTUS.getSize = function(element) {
    element = KAKTUS.getElement(element);
    if (KAKTUS.getStyle(element, 'display') != 'none') {
        return { w: element.offsetWidth, h: element.offsetHeight };
    }
    // All *Width and *Height properties give 0 on elements with display none,
    // so enable the element temporarily
    var els = element.style;
    var oVisibility = els.visibility;
    var oPosition = els.position;
    els.visibility = 'hidden';
    els.position = 'absolute';
    els.display = '';
    var oWidth = element.offsetWidth;
    var oHeight = element.offsetHeight;
    els.display = 'none';
    els.position = oPosition;
    els.visibility = oVisibility;
    return { w: oWidth, h: oHeight };
}

KAKTUS.setInnerHtml = function(element, text) {
    if (typeof (element.innerHTML) != 'undefined') {
        element.innerHTML = text;
    }
    else {
        if (element.firstChild == null) {
            var tn = document.createTextNode(text);
            element.appendChild();
        }
        else {
            element.firstChild.nodeValue = text;
        }
    }
}

KAKTUS.getScrollBarSize = function() {
    var scr = null;
    var inn = null;
    var wNoScroll = 0, hNoScroll = 0;
    var wScroll = 0, hScroll = 0;

    // Outer scrolling div
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '50px';
    scr.style.height = '50px';
    // Start with no scrollbar
    scr.style.overflow = 'hidden';
    // Inner content div
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '100%';

    // Put the inner div in the scrolling div
    scr.appendChild(inn);
    // Append the scrolling div to the doc
    document.body.appendChild(scr);

    // Width of the inner div sans scrollbar

    wNoScroll = inn.offsetWidth;
    hNoScroll = inn.offsetHeight;
    // Add the scrollbar
    scr.style.overflow = 'scroll';
    // Width of the inner div width scrollbar
    wScroll = inn.offsetWidth;
    hScroll = inn.offsetHeight;

    // Remove the scrolling div from the doc
    document.body.removeChild(scr);

    // Pixel width of the scroller
    return { w: (wNoScroll - wScroll), h: (hNoScroll - hScroll) };
}

KAKTUS.getScrollPosition = function() {
    var x = 0, y = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        x = window.pageXOffset;
        y = window.pageYOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        x = document.body.scrollLeft;
        y = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    }
    return { x: x, y: y };
}

KAKTUS.getWindowSize = function() {
    var x = 0, y = 0;
    if (typeof (window.innerWidth) == 'number') //Non-IE
    {
        x = window.innerWidth;
        y = window.innerHeight;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) //IE 6+ in 'standards compliant mode'
    {
        x = document.documentElement.clientWidth;
        y = document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) //IE 4 compatible
    {
        x = document.body.clientWidth;
        y = document.body.clientHeight;
    }
    return { x: x, y: y };
}

// funkce zjisti absolutni pozici elementu vzhledem k cele strance nebo elementu topElement
KAKTUS.getAbsolutePos = function(el, topElement, stopOnRelative) {
    stopOnRelative = !!stopOnRelative;
    el = KAKTUS.getElement(el);
    if (topElement) topElement = KAKTUS.getElement(topElement);
    var SL = 0, ST = 0;
    var is_div = /^div$/i.test(el.tagName);
    if (is_div && el.scrollLeft) SL = el.scrollLeft;
    if (is_div && el.scrollTop) ST = el.scrollTop;
    var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
    if (stopOnRelative && KAKTUS.getStyle(el, 'position') == 'relative') {
        r.x = 0;
        r.y = 0;
    }
    else {
        if ((!stopOnRelative || KAKTUS.getStyle(el, 'position') != 'relative') && el.offsetParent && (!topElement || topElement != el.offsetParent)) {
            var tmp = KAKTUS.getAbsolutePos(el.offsetParent, topElement, stopOnRelative);
            r.x += tmp.x;
            r.y += tmp.y;
        }
    }
    return r;
};

// třída Browser
KAKTUS.Browser = (function() {
    var ua = navigator.userAgent.toLowerCase();

    // browser engine name
    this.isGecko = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
    this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

    // browser name
    this.isKonqueror = (ua.indexOf('konqueror') != -1);
    this.isSafari = (ua.indexOf('safari') != -1);
    this.isOmniweb = (ua.indexOf('omniweb') != -1);
    this.isOpera = (ua.indexOf('opera') != -1);
    this.isIcab = (ua.indexOf('icab') != -1);
    this.isAol = (ua.indexOf('aol') != -1);
    this.isIE = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1));
    this.isMozilla = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
    this.isFirefox = (ua.indexOf('firefox/') != -1 || ua.indexOf('firebird/') != -1);
    this.isNS = ((this.isGecko) ? (ua.indexOf('netscape') != -1) : ((ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1)));

    // spoofing and compatible browsers
    this.isIECompatible = ((ua.indexOf('msie') != -1) && !this.isIE);
    this.isNSCompatible = ((ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);

    // rendering engine versions
    this.geckoVersion = ((this.isGecko) ? ua.substring((ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14)) : -1);
    this.equivalentMozilla = ((this.isGecko) ? parseFloat(ua.substring(ua.indexOf('rv:') + 3)) : -1);
    this.appleWebKitVersion = ((this.isAppleWebKit) ? parseFloat(ua.substring(ua.indexOf('applewebkit/') + 12)) : -1);

    // browser version
    this.versionMinor = parseFloat(navigator.appVersion);

    // correct version number
    if (this.isGecko && !this.isMozilla) {
        this.versionMinor = parseFloat(ua.substring(ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1));
    }
    else if (this.isMozilla) {
        this.versionMinor = parseFloat(ua.substring(ua.indexOf('rv:') + 3));
    }
    else if (this.isIE && this.versionMinor >= 4) {
        this.versionMinor = parseFloat(ua.substring(ua.indexOf('msie ') + 5));
    }
    else if (this.isKonqueror) {
        this.versionMinor = parseFloat(ua.substring(ua.indexOf('konqueror/') + 10));
    }
    else if (this.isSafari) {
        this.versionMinor = parseFloat(ua.substring(ua.lastIndexOf('safari/') + 7));
    }
    else if (this.isOmniweb) {
        this.versionMinor = parseFloat(ua.substring(ua.lastIndexOf('omniweb/') + 8));
    }
    else if (this.isOpera) {
        this.versionMinor = parseFloat(ua.substring(ua.indexOf('opera') + 6));
    }
    else if (this.isIcab) {
        this.versionMinor = parseFloat(ua.substring(ua.indexOf('icab') + 5));
    }

    this.versionMajor = parseInt(this.versionMinor);

    // dom support
    this.isDOM1 = (document.getElementById);
    this.isDOM2Event = (document.addEventListener && document.removeEventListener);

    // css compatibility mode
    this.mode = document.compatMode || 'BackCompat';

    // platform
    this.isWin = (ua.indexOf('win') != -1);
    this.isWin32 = (this.isWin && (ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1));
    this.isMac = (ua.indexOf('mac') != -1);
    this.isUnix = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
    this.isLinux = (ua.indexOf('linux') != -1);

    // specific browser shortcuts
    this.isNS4x = (this.isNS && this.versionMajor == 4);
    this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
    this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
    this.isNS4up = (this.isNS && this.versionMinor >= 4);
    this.isNS6x = (this.isNS && this.versionMajor == 6);
    this.isNS6up = (this.isNS && this.versionMajor >= 6);
    this.isNS7x = (this.isNS && this.versionMajor == 7);
    this.isNS7up = (this.isNS && this.versionMajor >= 7);

    this.isIE4x = (this.isIE && this.versionMajor == 4);
    this.isIE4up = (this.isIE && this.versionMajor >= 4);
    this.isIE5x = (this.isIE && this.versionMajor == 5);
    this.isIE55 = (this.isIE && this.versionMinor == 5.5);
    this.isIE5up = (this.isIE && this.versionMajor >= 5);
    this.isIE6x = (this.isIE && this.versionMajor == 6);
    this.isIE6up = (this.isIE && this.versionMajor >= 6);
    this.isIE7x = (this.isIE && this.versionMajor == 7);
    this.isIE7up = (this.isIE && this.versionMajor >= 7);

    this.isIE4xMac = (this.isIE4x && this.isMac);
})();

// Fader
KAKTUS.Fader = (function() {
    var __steps = 2;  // implicitne delame dva kroky (0 - 50 - 100)
    var __delayBetweenSteps = 50; // doba mezi kroky
    function constructorFn() { }
    var __activeAnims = new KAKTUS.Hashtable();
    var __countOfAnims = 0;

    constructorFn.toString = function() { return __activeAnims.toString(); }
    /*
    Desc: meni pruhlednost elementu v poli elements
    Param:
    elements - elementy, kterym se bude menit pruhlednost (jeden element, nebo pole)
    startOpacity - pocatecni pruhlednost (jedna hodnota nebo pole). v pripade jedne hodnoty zacinaji vsechny ze stejne hodnoty a v pripade pole, musi byt pocet polozek stejny jako v poli elements. Je-li hodnota null, pouzije se aktualni hodnota pruhlednosti.
    endOpacity - koncova pruhlednost (jedna hodnota nebo pole). v pripade jedne hodnoty konci vsechny ve stejne hodnote a v pripade pole, musi byt pocet polozek stejny jako v poli elements. Je-li hodnota null, pouzije se aktualni hodnota pruhlednosti.
    callbackStart - funkce(), ktera se vola pri zacatku animace
    callbackEnd - funkce(), ktera se vola na konci animace
    callBackStep - funkce(), ktera se vola po kazdem kroku animace
    stepsCount -
    delayBetweenSteps -
    */
    constructorFn.anime = function(elements, startOpacity, endOpacity, callbackStart, callbackEnd, callBackStep, stepsCount, delayBetweenSteps) {
        if (!stepsCount) stepsCount = __steps;
        if (!delayBetweenSteps) delayBetweenSteps = __delayBetweenSteps;
        var ident = __countOfAnims++;

        if (!KAKTUS.isArray(elements)) elements = [elements];
        if (!KAKTUS.isArray(startOpacity)) {
            var so = startOpacity;
            startOpacity = new Array(elements.length);
            if (so != null) for (var i = 0; i < elements.length; i++) startOpacity[i] = so;
        }

        if (!KAKTUS.isArray(endOpacity)) {
            var so = endOpacity;
            endOpacity = new Array(elements.length);
            if (so != null) for (var i = 0; i < elements.length; i++) endOpacity[i] = so;
        }

        var steps = new Array();
        var currentOpacity = new Array();
        for (var i = 0; i < elements.length; i++) {
            if (startOpacity[i] == null) startOpacity[i] = KAKTUS.getOpacity(elements[i]);
            currentOpacity.push(startOpacity[i]);
            if (endOpacity[i] == null) endOpacity[i] = KAKTUS.getOpacity(elements[i]);
            steps.push((endOpacity[i] - currentOpacity[i]) / stepsCount);
        }

        for (var i = 0; i < elements.length; i++) {
            elements[i] = KAKTUS.getElement(elements[i]);
            // pokud jiz animujeme dany element, tak mu nastavime, ze zacina ze sve aktualni hodnoty a predchozi animaci zrusime
            if (__activeAnims.containsKey(elements[i])) {
                startOpacity[i] = KAKTUS.getOpacity(elements[i]);
                __activeAnims[elements[i]] = ident + '_' + i;
            }
            else {
                __activeAnims.insert(elements[i], ident + '_' + i);
            }
        }

        function krok(elements, ident, callBackStep, aktualniKrok, pocetKroku) {
            var delatKrok = false;
            var bylaZmena = false;
            var delatElem = new Array(elements.length);
            for (var i = 0; i < elements.length; i++) {
                delatElem[i] = __activeAnims.containsValue(ident + '_' + i);
                if (delatElem[i]) {
                    bylaZmena = true;
                    KAKTUS.setOpacity(elements[i], currentOpacity[i]);
                    if ((steps[i] > 0 && currentOpacity[i] < endOpacity[i]) || (steps[i] < 0 && currentOpacity[i] > endOpacity[i])) {
                        delatKrok = true;
                        currentOpacity[i] += steps[i];
                    }
                }
            }

            if (bylaZmena) {
                if (callBackStep && typeof (callBackStep) == "function") // krok animace oznamime
                {
                    callBackStep(elements, startOpacity, endOpacity, currentOpacity, delatElem, aktualniKrok, pocetKroku);
                }
            }

            if (delatKrok) {
                window.setTimeout(function() { krok(elements, ident, callBackStep, aktualniKrok + 1, stepsCount); }, delayBetweenSteps);
            }
            else {
                for (var i = 0; i < elements.length; i++) {
                    if (delatElem[i]) {
                        __activeAnims.remove(elements[i]);
                    }
                }
                if (callbackEnd && typeof (callbackEnd) == "function") // konec animace oznamime
                {
                    callbackEnd(elements, startOpacity, endOpacity, currentOpacity, delatElem);
                }
            }
        }
        if (callbackStart && typeof (callbackStart) == "function") // zacatek animace oznamime
        {
            callbackStart(elements, startOpacity, endOpacity, currentOpacity);
        }
        krok(elements, ident, callBackStep, 0, stepsCount);
    }


    constructorFn.show = function(elements, opacity, callback) {
        if (!KAKTUS.isArray(elements)) elements = [elements];
        var start = new Array();
        for (var i = 0; i < elements.length; i++) {
            element = KAKTUS.getElement(elements[i]);
            if (KAKTUS.getStyle(element, 'visibility') == 'hidden')
                start.push(0);
            else
                start.push(null);
        }
        constructorFn.anime(elements, start, opacity, function(xElem) {
            for (var i = 0; i < xElem.length; i++) xElem[i].style.visibility = 'visible';
        }, callback);
    }

    constructorFn.hide = function(element, opacity, callback) {
        element = KAKTUS.getElement(element);
        constructorFn.anime(element, opacity, 0, null, function(xElem, xStart, xEnd, xCurr, xFinished) {
            for (var i = 0; i < xElem.length; i++) {
                if (xFinished[i]) {
                    xElem[i].style.visibility = "hidden";
                    KAKTUS.setOpacity(xElem[i], xStart[i]);
                }
            }
            if (callback && typeof (callback) == 'function') callback(xElem, xStart, xEnd, xCurr, xFinished);
        });
    }

    constructorFn.setDelay = function(delay) { __delayBetweenSteps = delay; };
    constructorFn.setStepsCount = function(steps) { __steps = steps; };
    return constructorFn;
}
)();


//// Fader
//KAKTUS.Ticker = function(settings) 
//{
//    this._settings = KAKTUS.merge(settings, { steps: 2, delay: 50 });
//    if (arg != null)
//    {
//      this._settings.steps = arg.steps || 2;
//    }
//    this._steps = 2;  // pocet kroku tickeru
//    this._delayBetweenSteps = 50; // doba mezi kroky
//}

//KAKTUS.Ticker.prototype.run = function(elements, start, end, callbackStart, callbackEnd, callBackStep, stepsCount, delayBetweenSteps) {
//        if (!stepsCount) stepsCount = __steps;
//        if (!delayBetweenSteps) delayBetweenSteps = __delayBetweenSteps;
//        var ident = __countOfAnims++;

//        if (!KAKTUS.isArray(elements)) elements = [elements];
//        if (!KAKTUS.isArray(startOpacity)) {
//            var so = startOpacity;
//            startOpacity = new Array(elements.length);
//            if (so != null) for (var i = 0; i < elements.length; i++) startOpacity[i] = so;
//        }

//        if (!KAKTUS.isArray(endOpacity)) {
//            var so = endOpacity;
//            endOpacity = new Array(elements.length);
//            if (so != null) for (var i = 0; i < elements.length; i++) endOpacity[i] = so;
//        }

//        var steps = new Array();
//        var currentOpacity = new Array();
//        for (var i = 0; i < elements.length; i++) {
//            if (startOpacity[i] == null) startOpacity[i] = KAKTUS.getOpacity(elements[i]);
//            currentOpacity.push(startOpacity[i]);
//            if (endOpacity[i] == null) endOpacity[i] = KAKTUS.getOpacity(elements[i]);
//            steps.push((endOpacity[i] - currentOpacity[i]) / stepsCount);
//        }

//        for (var i = 0; i < elements.length; i++) {
//            elements[i] = KAKTUS.getElement(elements[i]);
//            // pokud jiz animujeme dany element, tak mu nastavime, ze zacina ze sve aktualni hodnoty a predchozi animaci zrusime
//            if (__activeAnims.containsKey(elements[i])) {
//                startOpacity[i] = KAKTUS.getOpacity(elements[i]);
//                __activeAnims[elements[i]] = ident + '_' + i;
//            }
//            else {
//                __activeAnims.insert(elements[i], ident + '_' + i);
//            }
//        }

//        function krok(elements, ident, callBackStep, aktualniKrok, pocetKroku) {
//            var delatKrok = false;
//            var bylaZmena = false;
//            var delatElem = new Array(elements.length);
//            for (var i = 0; i < elements.length; i++) {
//                delatElem[i] = __activeAnims.containsValue(ident + '_' + i);
//                if (delatElem[i]) {
//                    bylaZmena = true;
//                    KAKTUS.setOpacity(elements[i], currentOpacity[i]);
//                    if ((steps[i] > 0 && currentOpacity[i] < endOpacity[i]) || (steps[i] < 0 && currentOpacity[i] > endOpacity[i])) {
//                        delatKrok = true;
//                        currentOpacity[i] += steps[i];
//                    }
//                }
//            }

//            if (bylaZmena) {
//                if (callBackStep && typeof (callBackStep) == "function") // krok animace oznamime
//                {
//                    callBackStep(elements, startOpacity, endOpacity, currentOpacity, delatElem, aktualniKrok, pocetKroku);
//                }
//            }

//            if (delatKrok) {
//                window.setTimeout(function() { krok(elements, ident, callBackStep, aktualniKrok + 1, stepsCount); }, delayBetweenSteps);
//            }
//            else {
//                for (var i = 0; i < elements.length; i++) {
//                    if (delatElem[i]) {
//                        __activeAnims.remove(elements[i]);
//                    }
//                }
//                if (callbackEnd && typeof (callbackEnd) == "function") // konec animace oznamime
//                {
//                    callbackEnd(elements, startOpacity, endOpacity, currentOpacity, delatElem);
//                }
//            }
//        }
//        if (callbackStart && typeof (callbackStart) == "function") // zacatek animace oznamime
//        {
//            callbackStart(elements, startOpacity, endOpacity, currentOpacity);
//        }
//        krok(elements, ident, callBackStep, 0, stepsCount);
//    }


//    constructorFn.show = function(elements, opacity, callback) {
//        if (!KAKTUS.isArray(elements)) elements = [elements];
//        var start = new Array();
//        for (var i = 0; i < elements.length; i++) {
//            element = KAKTUS.getElement(elements[i]);
//            if (KAKTUS.getStyle(element, 'visibility') == 'hidden')
//                start.push(0);
//            else
//                start.push(null);
//        }
//        constructorFn.anime(elements, start, opacity, function(xElem) {
//            for (var i = 0; i < xElem.length; i++) xElem[i].style.visibility = 'visible';
//        }, callback);
//    }

//    constructorFn.hide = function(element, opacity, callback) {
//        element = KAKTUS.getElement(element);
//        constructorFn.anime(element, opacity, 0, null, function(xElem, xStart, xEnd, xCurr, xFinished) {
//            for (var i = 0; i < xElem.length; i++) {
//                if (xFinished[i]) {
//                    xElem[i].style.visibility = "hidden";
//                    KAKTUS.setOpacity(xElem[i], xStart[i]);
//                }
//            }
//            if (callback && typeof (callback) == 'function') callback(xElem, xStart, xEnd, xCurr, xFinished);
//        });
//    }

//    constructorFn.setDelay = function(delay) { __delayBetweenSteps = delay; };
//    constructorFn.setStepsCount = function(steps) { __steps = steps; };
//    return constructorFn;
//}
//)();

/////////////////////////////////////////////

// FIXER
KAKTUS.Fixer = function(element, positionOrElement, padding, fixedStyle)
// element - element, který chceme ukotvit
// positionOrElement - pozice, kde se ma dany element drzet (nebo element, ktereho se ma drzet)
// padding - minimalni vzdalenost od shora
// fixedStyle - bool zda pouzit styl fixed nebo ne (pokud neni zadan, zvoli se dle moznosti prohlizece)
{
    var isFixedToElement = KAKTUS.isElement(positionOrElement);
    this.fixedStyle = arguments.length > 3 ? (fixedStyle ? true : false) : ((KAKTUS.Browser.isIE7up && KAKTUS.Browser.mode != 'BackCompat') || !KAKTUS.Browser.isIE);
    var position = isFixedToElement ? KAKTUS.getAbsolutePos(positionOrElement).y : positionOrElement;
    this.padding = arguments.length > 2 ? (padding != null ? padding : position) : position;
    element.style.position = fixedStyle ? "fixed" : "absolute";
    var that = this;
    this.fixIt = function() {
        var st = KAKTUS.getScrollPosition().y;
        var position = isFixedToElement ? KAKTUS.getAbsolutePos(positionOrElement).y : positionOrElement;
        if (that.fixedStyle) {
            element.style.top = (position - st > that.padding ? position - st : that.padding) + "px";
        }
        else {
            element.style.top = (position - st > that.padding ? position : st + that.padding) + "px";
        }
    };
    if (fixedStyle && !isFixedToElement && that.padding == positionOrElement) {
        element.style.top = that.padding + "px";
    }
    else {
        KAKTUS.Event.addHandler(window, "scroll", that.fixIt);
        KAKTUS.Event.addHandler(window, "resize", that.fixIt);
    }
    that.fixIt();
    if (isFixedToElement) {
        window.setTimeout(that.fixIt, 50);
        KAKTUS.Event.addHandler(positionOrElement, "move", that.fixIt);
    }
}

// trida zajistuje dynamicke zobrazovani napovedy
KAKTUS.Hint = function(hintsContainer, steps, delayBetweenSteps)
// hintsContainer - element, ktery bude zobrazovat (nebo uchovavat) napovedu
{
    hintsContainer = KAKTUS.getElement(hintsContainer);
    var hintsContainer2 = document.createElement('div');
    hintsContainer2.style.position = 'relative';
    hintsContainer2.style.overflow = 'hidden';
    hintsContainer.appendChild(hintsContainer2);

    var visibleSrcElement = null;
    var focusedSrcElement = null;
    var that = this;
    var elemHint = new KAKTUS.Hashtable();
    var hintsContainer2Size = KAKTUS.getSize(hintsContainer2);
    var destSize = KAKTUS.getSize(hintsContainer2);
    function __kaktusSwapElements(method, toHide, toShow) {
        var divToShow = elemHint.get(toShow);
        var divToHide = elemHint.get(toHide);
        if ((divToShow == null && divToHide == null) || (visibleSrcElement == toShow)) return;
        if (divToShow != null) {
            visibleSrcElement = toShow;
            var divToShowSize = KAKTUS.getSize(divToShow);
            destSize.w = divToShowSize.w;
            destSize.h = divToShowSize.h;
        }
        else {
            focusedSrcElement = visibleSrcElement = null;
            destSize.w = hintsContainer2Size.w;
            destSize.h = hintsContainer2Size.h;
        }
        if (divToHide != null && divToShow != null) {
            KAKTUS.Fader.anime([divToHide, divToShow], [100, 0], [0, 100],
         function() {
             divToShow.style.visibility = "visible";
         },
         function(xElem, xStart, xEnd, xCurr, xFinished) {
             if (xFinished[0]) {
                 divToHide.style.visibility = "hidden";
                 KAKTUS.setOpacity(divToHide, xStart[0]);
                 hintsContainer2.style.width = destSize.w + 'px';
                 hintsContainer2.style.height = destSize.h + 'px';
             }
         },
         function(xElem, xStart, xEnd, xCurr, xFinished, xInd, xCount) {
             if (xFinished[1]) {
                 var currentSize = KAKTUS.getSize(hintsContainer2);
                 var currX = Math.floor((destSize.w - currentSize.w) * xInd / xCount + currentSize.w);
                 var currY = Math.floor((destSize.h - currentSize.h) * xInd / xCount + currentSize.h);
                 hintsContainer2.style.width = currX + 'px';
                 hintsContainer2.style.height = currY + 'px';
             }
         }, steps, delayBetweenSteps);
        }
        else if (divToShow != null) {
            KAKTUS.Fader.anime(divToShow, 0, 100,
       function() {
           divToShow.style.visibility = "visible";
       },
       function(xElem, xStart, xEnd, xCurr, xFinished) {
           if (xFinished[0]) {
               KAKTUS.setOpacity(divToShow, xEnd[0]);
               hintsContainer2.style.width = destSize.w + 'px';
               hintsContainer2.style.height = destSize.h + 'px';
           }
       },
       function(xElem, xStart, xEnd, xCurr, xFinished, xInd, xCount) {
           if (xFinished[0]) {
               var currentSize = KAKTUS.getSize(hintsContainer2);
               var currX = Math.floor((destSize.w - currentSize.w) * xInd / xCount + currentSize.w);
               var currY = Math.floor((destSize.h - currentSize.h) * xInd / xCount + currentSize.h);
               hintsContainer2.style.width = currX + 'px';
               hintsContainer2.style.height = currY + 'px';
           }
       }, steps, delayBetweenSteps);
        }
        else {
            KAKTUS.Fader.anime(divToHide, 100, 0, null,
       function(xElem, xStart, xEnd, xCurr, xFinished) {
           if (xFinished[0]) {
               divToHide.style.visibility = "hidden";
               KAKTUS.setOpacity(divToHide, xStart[0]);
           }
       },
       function(xElem, xStart, xEnd, xCurr, xFinished, xInd, xCount) {
           if (xFinished[0]) {
               var currentSize = KAKTUS.getSize(hintsContainer2);
               var currX = Math.floor((destSize.w - currentSize.w) * xInd / xCount + currentSize.w);
               var currY = Math.floor((destSize.h - currentSize.h) * xInd / xCount + currentSize.h);
               hintsContainer2.style.width = currX + 'px';
               hintsContainer2.style.height = currY + 'px';
           }
       }, steps, delayBetweenSteps);
        }
    }

    // funkce pridava napovedu, ta se zobrazi pri najeti mysi nad srcElement. Text napovedy je v hintOrElement
    this.addHint = function(srcElement, hintOrElement) {
        srcElement = KAKTUS.getElement(srcElement);
        var hintCont;
        var existsBefore = false;
        if (elemHint.containsKey(srcElement)) {
            existsBefore = true;
            hintCont = elemHint.get(srcElement);
        }
        else {
            hintCont = document.createElement('div');
            hintCont.style.position = 'absolute';
            hintCont.style.margin = '0';
            hintCont.style.padding = '0';
            hintCont.style.border = '0 transparent none';
            hintCont.style.top = '0';
            hintCont.style.visibility = 'hidden';
            hintsContainer2.appendChild(hintCont);
            elemHint.insert(srcElement, hintCont);
        }

        var hint = KAKTUS.getElement(hintOrElement);
        if (hint == null) {
            hint = document.createElement("div");
            KAKTUS.setInnerHtml(hint, hintOrElement);
        }
        else {
            hint = hintOrElement;
        }
        hintCont.appendChild(hint);
        hint.style.width = KAKTUS.getSize(hint).w + 'px';

        if (!existsBefore) {
            KAKTUS.Event.addHandler(srcElement, "focus", function() {
                __kaktusSwapElements("focus", visibleSrcElement, srcElement);
                focusedSrcElement = visibleSrcElement;
            });

            KAKTUS.Event.addHandler(srcElement, "mouseover", function() {
                __kaktusSwapElements("mouseover", visibleSrcElement, srcElement);
            });

            KAKTUS.Event.addHandler(srcElement, "blur", function() {
                __kaktusSwapElements("blur", focusedSrcElement, null);
                focusedSrcElement = null;
            });

            KAKTUS.Event.addHandler(srcElement, "mouseout", function() {
                __kaktusSwapElements("mouseout", srcElement, focusedSrcElement);
            });
        }
    }
}

// prepinac mezi strankama
KAKTUS.Tabs = function(buttonContainer, divContainer, unselectedButtonCssClass, selectedButtonCssClass, onSelectedIndexChangedHandler, names, _steps, _delayBetweenSteps) {
    buttonContainer = KAKTUS.getElement(buttonContainer);
    divContainer = KAKTUS.getElement(divContainer);
    var divContainer2 = document.createElement('div');
    divContainer2.style.position = 'relative';
    divContainer2.style.padding = '0';
    divContainer2.style.margin = '0';
    divContainer2.style.border = '0px none transparent';
    divContainer2.style.overflow = 'hidden';
    divContainer.appendChild(divContainer2);
    KAKTUS.tabsOnPage.push(this);
    var buttons = new Array();
    var appropriateDivs = new Array();
    var __names = null;
    if (names != null) {
        if (!KAKTUS.isArray(names)) names = [names];
        if (names.length > 0 && !KAKTUS.isArray(names[0])) names = [names];
        __names = names;
    }
    this.shrinkSize = true;
    this.steps = _steps;
    this.delayBetweenSteps = _delayBetweenSteps;
    this.animate = true;
    var __selectedIndex = -1;
    var that = this;
    function getButton(index) {
        return buttons[index];
    }

    function getDiv(index) {
        return appropriateDivs[index];
    }

    var destHeight = null;

    function __swapElements(divToHide, divToShow) {
        if (divToHide == divToShow || divToShow == null) return;
        divToShow.parentNode.style.display = 'block';
        divToShow.style.visibility = '';
        destHeight = KAKTUS.getSize(divToShow).h;
        if (that.animate) {
            divContainer2.style.width = KAKTUS.getSize(divContainer2).w + 'px';
        }
        if (divToHide != null) {
            if (!that.animate) {
                divToHide.style.visibility = 'hidden';
                divToHide.parentNode.style.display = 'none';
                if (that.shrinkSize) {
                    divContainer2.style.height = destHeight + 'px';
                }
                return;
            }
            KAKTUS.Fader.anime([divToHide, divToShow], [100, 0], [0, 100], function() {
                divToShow.style.visibility = '';
            },
        function(xElem, xStart, xEnd, xCurr, xFinished) {
            if (xFinished[0]) {
                divToHide.style.visibility = 'hidden';
                divToHide.parentNode.style.display = 'none';
                divContainer2.style.width = '100%';
                if (that.shrinkSize) {
                    divToShow.style.width = '100%';
                    divContainer2.style.height = destHeight + 'px';
                }
            }
        },
        function(xElem, xStart, xEnd, xCurr, xFinished, xInd, xCount) {
            if (xFinished[1] && that.shrinkSize) {
                var currentHeight = KAKTUS.getSize(divContainer2).h;
                var currY = Math.floor((destHeight - currentHeight) * xInd / xCount + currentHeight);
                divContainer2.style.height = currY + 'px';
            }
        }, that.steps, that.delayBetweenSteps);
        }
        else if (divToShow != null) {
            if (!that.animate) {
                divToShow.style.visibility = '';
                if (that.shrinkSize) {
                    divContainer2.style.height = destHeight + 'px';
                }
                return;
            }

            KAKTUS.Fader.anime(divToShow, 0, 100, function() {
                divToShow.style.visibility = '';
            },
        function(xElem, xStart, xEnd, xCurr, xFinished) {
            if (xFinished[0]) {
                divContainer2.style.width = '100%';
                if (that.shrinkSize) {
                    divToShow.style.width = '100%';
                    divContainer2.style.height = destHeight + 'px';
                }
            }
        },
        function(xElem, xStart, xEnd, xCurr, xFinished, xInd, xCount) {
            if (xFinished[0] && that.shrinkSize) {
                var currentHeight = KAKTUS.getSize(divContainer2).h;
                var currY = Math.floor((destHeight - currentHeight) * xInd / xCount + currentHeight);
                divContainer2.style.height = currY + 'px';
            }
        }, that.steps, that.delayBetweenSteps);
        }
    }

    function __createDiv(name, title, appropriateDiv) {
        var button = document.createElement("li");
        if (selectedButtonCssClass != null) button.className = unselectedButtonCssClass;
        var anchor = document.createElement("a");
        var that = this;
        anchor.title = title;
        anchor.innerHTML = name + " <span>" + title + "</span>";
        anchor.href = "#";
        anchor.KAKTUS_DIVS = this;
        anchor.index = buttons.length;
        anchor.onclick = function() {
            var divToHide = null;
            var selectedButton = null;
            if (__selectedIndex != -1) {
                selectedButton = getButton(__selectedIndex);
                divToHide = getDiv(__selectedIndex);
                selectedButton.className = unselectedButtonCssClass != null ? unselectedButtonCssClass : '';
            }
            __selectedIndex = this.index;
            if (onSelectedIndexChangedHandler != null) onSelectedIndexChangedHandler(__selectedIndex);
            selectedButton = getButton(__selectedIndex);
            var divToShow = getDiv(__selectedIndex);
            selectedButton.className = selectedButtonCssClass != null ? selectedButtonCssClass : '';
            __swapElements(divToHide, divToShow);
        };
        button.appendChild(anchor);
        return button;
    }

    var isSelect = buttonContainer.tagName == "SELECT"
    if (isSelect) {
        buttonContainer.onchange = function() {
            var divToHide = null;
            if (__selectedIndex != -1) divToHide = getDiv(__selectedIndex);
            __selectedIndex = this.selectedIndex;
            if (onSelectedIndexChangedHandler != null) onSelectedIndexChangedHandler(__selectedIndex);
            var divToShow = getDiv(__selectedIndex);
            __swapElements(divToHide, divToShow);
        };
    }
    else // ul / ol
    {
        if (buttonContainer.tagName != "OL" && buttonContainer.tagName != "UL") {
            var ol = document.createElement("OL");
            buttonContainer.appendChild(ol);
            buttonContainer = ol;
        }
    }
    var __wasInitialised = false;
    function __updateSize() {
        var height = 0;
        if (that.shrinkSize) {
            height = KAKTUS.getSize(appropriateDivs[__selectedIndex]).h;
        }
        else {
            for (var i = 0, count = appropriateDivs.length; i < count; i++) {
                var elem = appropriateDivs[i];
                var newHeight = KAKTUS.getSize(elem).h;
                if (newHeight > height) height = newHeight;
            }
        }
        divContainer2.style.height = height + 'px';
    }

    function __init(names, visibleIndex) {
        if (!__wasInitialised) {
            __wasInitialised = true;
            KAKTUS.Event.addHandler(window, 'resize', __updateSize);
        }

        if (visibleIndex == null) visibleIndex = 0;
        var nodes = new Array();
        if (names != null) {
            if (!KAKTUS.isArray(names)) names = [names];
            if (names.length > 0 && !KAKTUS.isArray(names[0])) names = [names];
            __names = names;
        }
        for (var i = 0, count = divContainer.childNodes.length; i < count; i++) {
            var elem = divContainer.childNodes[i];
            if (elem == divContainer2) continue;
            if (elem.nodeType === 1) nodes.push(divContainer.childNodes[i]);
        }
        for (var i = 0, count = nodes.length; i < count; i++) {
            var name = nodes[i].title || nodes[i].alt || ('element' + (i + 1));
            var desc = '';
            if (__names != null) {
                for (var j = 0; j < __names.length; j++) {
                    if (__names[j] == null || !KAKTUS.isArray(__names[j]) || __names[j].length < 2) continue;
                    if (KAKTUS.getElement(__names[j][0]) == nodes[i]) {
                        name = __names[j][1];
                        if (__names[j].length > 2) desc = __names[j][2];
                    }
                }
            }
            this.addDiv(nodes[i], name, desc, i == visibleIndex);
        }
        this.selectByIndex(visibleIndex);
    }
    this.init = __init;
    this.addDiv = function(elem, divName, divTitle, useItsSize) {
        useItsSize = useItsSize == true && that.shrinkSize;
        elem = KAKTUS.getElement(elem);
        var div = document.createElement('div'); // toto je div, ktery umisti obsah zalozky nahoru (zalozky budou pres sebe)
        div.style.position = 'absolute';
        div.style.border = '0px transparent none';
        div.style.display = useItsSize || !that.shrinkSize ? 'block' : 'none';
        div.style.top = '0';
        div.style.left = '0';
        div.style.margin = '0';
        div.style.padding = '0';
        div.style.width = "100%";
        var div2 = document.createElement('div'); // toto je pomocny div kvuli pruhlednosti v IE - ma layout, tak funguje
        div2.style.border = '0px transparent none';
        div2.style.visibility = 'hidden';
        div2.style.margin = '0';
        div2.style.padding = '0';
        div2.style.width = '100%';
        div2.style.backgroundColor = KAKTUS.getStyle(elem, 'background-color');
        div2.appendChild(elem);
        div.appendChild(div2);
        divContainer2.appendChild(div);
        if (!that.shrinkSize) {
            var height = KAKTUS.getSize(div2).h;
            if (height > KAKTUS.getSize(divContainer2).h) {
                divContainer2.style.height = height + 'px';
            }
        }
        else if (useItsSize) {
            var height = KAKTUS.getSize(div2).h;
            divContainer2.style.height = height + 'px';
        }
        div.style.display = 'none';
        div = div2; // div je ten, ktery skryvame
        if (isSelect) {
            var option = document.createElement("option");
            option.text = divName;
            option.title = divTitle;
            buttonContainer.options.add(option);
        }
        else // je to nejaky div ci neco takoveho
        {
            var option = __createDiv(divName, divTitle, div);
            buttonContainer.appendChild(option);
        }
        buttons.push(option);
        appropriateDivs.push(div);
    }

    this.selectByIndex = function(index) {
        if (__selectedIndex == index) return;
        if (isSelect) {
            buttonContainer.selectedIndex = index;
            buttonContainer.onchange();
        }
        else {
            var newButton = buttons[index];
            newButton = newButton.getElementsByTagName("A")[0];
            newButton.onclick();
        }
    }

    this.getSelectedIndex = function() { return __selectedIndex; };
    this.getButtonCount = function() { return buttons.length; };
    this.getPage = function(index) {
        if (index < 0 || index >= buttons.length) return null;
        return getDiv(index);
    }
    this.getElementPageIndex = function(element) {
        element = KAKTUS.getElement(element);
        while (typeof (element) != 'undefined' && element != null) {
            var index = appropriateDivs.indexOf(element);
            if (index != -1) return index;
            element = element.parentNode;
        }
        return -1;
    }
}


/* skryvac */
KAKTUS.Skryvac = (function() {
    var enabled = false;
    var mZobrazitZaviratko = 3000; // pocet milisekund, po kterych se zobrazi zaviratko
    var opacity = [70, 100];  // defaultni zakrytost (okoli, infotext)
    var defaultText = KAKTUS.GetResource('WaitForRequestProccessed', 'Počkejte prosím, než bude dotaz zpracován.'); // def text skryvace
    var zakryvac = document.createElement('div'); // ten obsahuje zakryvatko cele stranky (ten polopruhledny)
    zakryvac.style.position = "absolute";
    zakryvac.style.overflow = "hidden";

    var container = document.createElement('div');
    container.style.zIndex = 999;
    container.style.position = "absolute";
    container.style.overflow = "hidden";

    var defaultElement = document.createElement("div"); // element obsahující text
    var defaultImageElement = document.createElement("div");
    defaultElement.appendChild(defaultImageElement);
    var defaultTextElement = document.createTextNode(defaultText);
    defaultElement.appendChild(defaultTextElement);
    container.appendChild(defaultElement);

    var progressElement = document.createElement("div"); // element obsahující progress info
    var progressImageElement = document.createElement("div");
    progressElement.appendChild(progressImageElement);
    var pom = document.createElement("table");
    progressElement.appendChild(pom);
    var pom2 = pom.insertRow(-1);
    var pom3 = pom2.insertCell(-1);
    KAKTUS.setInnerHtml(pom3, KAKTUS.GetResource("CurrentFileName", "Aktuální soubor:"));
    var progressElementAktualniSoubor = pom2.insertCell(-1);

    pom2 = pom.insertRow(-1);
    pom3 = pom2.insertCell(-1);
    KAKTUS.setInnerHtml(pom3, KAKTUS.GetResource("BytesSended", "Odesláno:"));
    var progressElementStazeno = pom2.insertCell(-1);
    pom2 = pom.insertRow(-1);
    pom3 = pom2.insertCell(-1);
    KAKTUS.setInnerHtml(pom3, KAKTUS.GetResource("Speed", "Rychlost:"));
    var progressElementRychlost = pom2.insertCell(-1);
    pom2 = pom.insertRow(-1);
    pom3 = pom2.insertCell(-1);
    KAKTUS.setInnerHtml(pom3, KAKTUS.GetResource("RemainingTime", "Zbývající čas:"));
    var progressElementZbyvajiciCas = pom2.insertCell(-1);
    var progressBarHolder = document.createElement("div");
    progressElement.appendChild(progressBarHolder);
    var progressBar = document.createElement("div");
    progressBarHolder.appendChild(progressBar);
    container.appendChild(progressElement);

    var zaviratko = document.createElement("div");  // obrazek zaviratka
    zaviratko.style.position = "absolute";
    zaviratko.style.cursor = "pointer";
    zaviratko.style.top = '0';
    zaviratko.style.right = '0';
    KAKTUS.Event.addHandler(zaviratko, "click", function() { KAKTUS.Skryvac.hide(); });
    zaviratko.style.zIndex = 1000;
    container.appendChild(zaviratko);

    function __hideElems() {
        zakryvac.style.width = '100px';
        zakryvac.style.height = '100px';
        zakryvac.style.top = '-1000px';
        zakryvac.style.left = '-1000px';
        container.style.top = '-1000px';
        container.style.left = '-1000px';
        zakryvac.style.visibility = 'hidden';
        container.style.visibility = 'hidden';
    }

    __setElement(defaultElement);
    __setCssClass('kaktusSkryvachtaebSPl3BG8sr1bVtiVkw');
    __hideElems();
    var selecty = new Array();
    KAKTUS.Event.addHandler(window, "load", function() {
        document.body.appendChild(zakryvac);
        document.body.appendChild(container);
        enabled = true;
    }
  );

    function __setCssClass(className) {
        defaultElement.className = className;
        zaviratko.className = className + 'CloseButton';
        zakryvac.className = className + 'Desktop';
        defaultImageElement.className = className + 'Image';
        progressElement.className = className + 'Progress';
        progressImageElement.className = className + 'ProgressImage';
        progressBarHolder.className = className + 'ProgressBarZone';
        progressBar.className = className + 'ProgressBar';
    }

    function __getSlovo(hodnota, slova) {
        if (hodnota == 1) return slova[0];
        if (hodnota > 1 && hodnota < 5) return slova[1];
        return slova[2];
    }

    function __secondsToTime(time) {
        var sec = time % 60; time = Math.floor(time / 60);
        var min = time % 60; time = Math.floor(time / 60);
        var hours = time;
        var s = '';
        if (hours > 0) {
            if (s != '') s += ', ';
            s += hours + ' ' + __getSlovo(hours, KAKTUS.GetResource("Hours", ['hodina', 'hodiny', 'hodin']));
        }
        if (s != '' || min > 0) {
            if (s != '') s += ', ';
            s += min + ' ' + __getSlovo(min, KAKTUS.GetResource("Minutes", ['minuta', 'minuty', 'minut']));
        }

        if (s != '') s += ', ';
        s += sec + ' ' + __getSlovo(sec, KAKTUS.GetResource("Seconds", ['sekunda', 'sekundy', 'sekund']));

        return s;
    }

    function __getSize(size) {
        var koncovky = ['B', 'KB', 'MB', 'GB', 'TB'];
        pom = size;
        for (var i = 0; i < koncovky.length; i++) {
            size = pom + ' ' + koncovky[i];
            pom = Math.floor(pom / 1024);
            if (pom == 0) break;
        }
        return size;
    }

    function __progressUpdate(state) {
        progressBar.style.width = state.progress + '%';
        KAKTUS.setInnerHtml(progressElementAktualniSoubor, state.currentFile);
        KAKTUS.setInnerHtml(progressElementStazeno, __getSize(state.readed) + ' / ' + __getSize(state.length) + ' (' + state.progress + '%)');
        KAKTUS.setInnerHtml(progressElementRychlost, __getSize(state.speed) + '/s');
        KAKTUS.setInnerHtml(progressElementZbyvajiciCas, __secondsToTime(state.totalSeconds - state.currentSeconds));
    }

    function zmenaOkna() {
        var scrSize = KAKTUS.getWindowSize();
        var scrOf = KAKTUS.getScrollPosition();

        zakryvac.style.width = scrSize.x + 'px';
        zakryvac.style.height = scrSize.y + 'px';
        zakryvac.style.top = scrOf.y + 'px';
        zakryvac.style.left = scrOf.x + 'px';
        var size = KAKTUS.getSize(container);
        container.style.top = (scrOf.y + (scrSize.y - size.h) / 2).toFixed() + 'px';
        container.style.left = (scrOf.x + (scrSize.x - size.w) / 2).toFixed() + 'px';
    }

    KAKTUS.Event.addHandler(window, "scroll", zmenaOkna);
    KAKTUS.Event.addHandler(window, "resize", zmenaOkna);
    function __setOpacity(val) {
        KAKTUS.setOpacity(zakryvac, val);
    }

    function __getOpacity() {
        return KAKTUS.getOpacity(zakryvac); ;
    }

    function __setBgColor(val) {
        zakryvac.style.backgroundColor = val;
    }

    function __getBgColor() {
        return KAKTUS.getStyle(zakryvac, 'background-color');
    }

    function __showCloseButton() {
        zmenaOkna(true);
        if (mZobrazitZaviratko > 0) {
            window.setTimeout(function() {
                KAKTUS.Fader.show(zaviratko);
            }, mZobrazitZaviratko);
        }
    }

    function __hideCloseButton() {
        KAKTUS.Fader.hide(zaviratko);
    }

    function __setCloseButtonTimeout(val) {
        mZobrazitZaviratko = val;
    }

    function __getCloseButtonTimeout() {
        return mZobrazitZaviratko;
    }

    function __setText2(val, nosave, nosetElem) {
        nosave = !!nosave;
        if (!nosave) defaultText = val;
        defaultTextElement.nodeValue = val;
        if (!nosetElem) __setElement(defaultElement);
    }

    function __setText(val) {
        __setText2(val);
    }

    function __getText() {
        return defaultTextElement.nodeValue;
    }

    function __strToArray(input) {
        var re = input.match(/(\d+)\s*:\s*(\d+)\s*:\s*(\d+)/);
        var array = new Array();
        if (re != null) {
            var prefix = '', postfix = '';
            if (re.index > 0) prefix = input.substring(0, re.index);
            if (re.index + re[0].length < input.length) postfix = input.substring(re.index + re[0].length, input.length);
            for (var i = parseInt(re[1]); i < parseInt(re[3]); i += parseInt(re[2])) {
                array.push(prefix + i + postfix);
            }
            array.push(prefix + re[3] + postfix);
        }
        else {
            array.push(input);
        }
        return array;
    }

    var interval = null;
    var pocitadlo = 0;
    var initAnimation = { indexes: __strToArray('-3400:200:3800px 0px'), speed: 100 };
    var downloadAnimation = { indexes: __strToArray('-0:200:1800px 0px'), speed: 100 };
    var interruprAnimation = { indexes: __strToArray('-2000px 0px'), speed: 100 };
    var finishAnimation = { indexes: __strToArray('-2200:200:3200px 0px'), speed: 250 };
    var currentAnimation = null; // dokoncime prave probihajici animaci (první parametr je rychlost animace)
    var waitingAnimation = null;

    function __setProgressBackground(animation) {
        if (animation == currentAnimation) return; // uz se to animuje - koncime
        if (interval == null && animation.indexes.length == 1 || animation.speed < 1) // tady neni co animovat a ani se nic nemaluje, tak to zobrazime
        {
            progressImageElement.style.backgroundPosition = animation.indexes[0];
        }
        else {
            if (interval == null) {
                pocitadlo = 1;
                currentAnimation = animation;
                progressImageElement.style.backgroundPosition = animation.indexes[0];
                interval = window.setInterval(__nastavPozadi, animation.speed);
            }
            else {
                waitingAnimation = animation;
            }
        }
    }

    function __nastavPozadi() {
        progressImageElement.style.backgroundPosition = currentAnimation.indexes[pocitadlo++];
        if (pocitadlo >= currentAnimation.indexes.length) {
            pocitadlo = 0;
        }
        if (waitingAnimation != null) {
            pocitadlo = 0;
            currentAnimation = waitingAnimation;
            waitingAnimation = null;
            window.clearInterval(interval);
            interval = window.setInterval(__nastavPozadi, currentAnimation.speed);
        }
        else if (currentAnimation.length == 1) {
            window.clearInterval(interval);
            interval = null;
        }
    }

    function __getProgressInfo(url) {
        if (typeof (KAKTUS) == 'undefined') return;
        KAKTUS.getHttpRequest(url, function(a, b) {
            var x = {
                progress: 0,
                length: 0,
                readed: 0,
                speed: 0,
                currentSeconds: 0,
                totalSeconds: 0,
                state: 0,
                currentFile: ''
            };
            b = b.documentElement;
            if (b.getAttribute('empty') != 'true') {
                x.progress = parseInt(b.getAttribute('progress'));
                x.length = parseInt(b.getAttribute('length'));
                x.readed = parseInt(b.getAttribute('readed'));
                x.speed = parseInt(b.getAttribute('speed'));
                x.currentSeconds = parseInt(b.getAttribute('currentSeconds'));
                x.totalSeconds = parseInt(b.getAttribute('totalSeconds'));
                x.currentFile = b.getAttribute('currentFile');
                x.state = b.getAttribute('state');
                switch (parseInt(x.state)) {
                    case 1: __setProgressBackground(downloadAnimation); break;
                    case 2: __setProgressBackground(interruprAnimation); break;
                    case 3: __setProgressBackground(finishAnimation); break;
                    default: __setProgressBackground(initAnimation); break;
                }
            }
            __progressUpdate(x);
            if (x.state < 2) window.setTimeout(function() { __getProgressInfo(url) }, 100);
        });
    }

    function ___updateFormsAction(key, value) {
        if (!enabled) { enabled = true; return; }
        var forms = document.getElementsByTagName("form");
        var pocet = 0;
        for (var i = 0; i < forms.length; i++) {
            pocet += __updateFormAction(forms[i], key, value);
        }
        if (pocet > 0) {
            KAKTUS.Skryvac.showProgress(false, 'kaktusUploadProgressInfo.ashx?' + key + '=' + escape(value) + '&ts=' + new Date().getTime());
        }
        else {
            __setElement(defaultElement);
            KAKTUS.Skryvac.show();
        }
    }

    function __updateFormAction(form, key, value) {
        var action = form.action;
        var inputs = form.getElementsByTagName('input');
        var pocet = 0;
        for (i = 0; i < inputs.length; i++) {
            if (inputs[i].type == 'file' && inputs[i].value != '') {
                pocet++;
                break;
            }
        }
        var re = new RegExp('&?' + key + '=[^&]*');
        re.ignoreCase = true;
        if (action.match(re)) action = action.replace(re, '');
        if (pocet > 0) {
            var index = action.indexOf('?');
            if (index == -1) {
                action += '?';
            }
            else if (index < action.length - 1) {
                action += '&';
            }
            action += key + '=' + escape(value);
        }
        form.action = action;
        return pocet;
    }

    function __showProgress(hideCloseButton, url, callback) {
        __setElement(progressElement);
        __show(hideCloseButton, null, callback);
        __setProgressBackground(initAnimation);
        if (url) window.setTimeout(function() { __getProgressInfo(url) }, 100);
    };

    function __show(hideCloseButton, text, callback) {
        hideCloseButton = !!hideCloseButton;
        var objs = document.getElementsByTagName("select");
        for (var i = 0; i < objs.length; i++) {
            var obj = objs.item(i);
            selecty.push({ element: obj, visibility: obj.style.visibility });
            obj.style.visibility = "hidden";
        }
        if (text) {
            __setText2(text, true);
        }
        else {
            __setText2(defaultText, true, true);
        }
        zmenaOkna(true);

        if (!hideCloseButton) __showCloseButton();
        KAKTUS.Fader.show([zakryvac, container], opacity, callback);
    }

    function __hide(callback) {
        KAKTUS.Fader.hide([zakryvac, container, zaviratko], null, function(xel, xs, xe, xc) {
            var obj = selecty.pop();
            while (obj != null) {
                obj.element.style.visibility = obj.visibility;
                obj = selecty.pop();
            }
            if (interval) { window.clearInterval(interval); interval = null; }
            if (callback && typeof (callback) == "function") callback();
            __hideElems();
        });
    }

    function __setEnabled(value) {
        enabled = value;
    }

    function __getEnabled(value) {
        return value;
    }


    function __setElement(element) {
        var contains = false;
        element = KAKTUS.getElement(element);
        for (var i = 0, count = container.childNodes.length; i < count; i++) {
            var node = container.childNodes[i];
            if (node.nodeType != 1) continue;
            node.style.visibility = 'hidden';
            if (node == element) contains = true;
        }
        if (!contains) container.appendChild(element);
        element.style.visibility = ''; // pokud dame na visible, tak se zobrazi rovnou a to nechceme (chceme, at se chova jako parent)
        element.style.position = 'absolute';
        element.style.top = '0';
        element.style.left = '0';
        var size = KAKTUS.getSize(element);
        container.style.width = size.w + 'px';
        container.style.height = size.h + 'px';
        zaviratko.style.left = size.w - KAKTUS.getSize(zaviratko).w + 'px';
    }

    function constructorFn() {
    };
    constructorFn.setOpacity = __setOpacity;
    constructorFn.getOpacity = __getOpacity;
    constructorFn.setBgColor = __setBgColor;
    constructorFn.getBgColor = __getBgColor;
    constructorFn.setElement = __setElement;
    constructorFn.show = __show;
    constructorFn.showProgress = __showProgress;
    constructorFn.hide = __hide;
    constructorFn.showCloseButton = __showCloseButton;
    constructorFn.hideCloseButton = __hideCloseButton;
    constructorFn.setCloseButtonTimeout = __setCloseButtonTimeout;
    constructorFn.getCloseButtonTimeout = __getCloseButtonTimeout;
    constructorFn.setText = __setText;
    constructorFn.getText = __getText;
    constructorFn.setEnabled = __setEnabled;
    constructorFn.getEnabled = __getEnabled;
    constructorFn.setCssClass = __setCssClass;
    constructorFn.progressUpdate = __progressUpdate;
    constructorFn.updateFormsAction = ___updateFormsAction;
    return constructorFn;
})();




/* otvirak */

// JScript File

KAKTUS.Dialog = (function() {
    var aktualniOkno = null;
    var parametryOkna = null;
    var returnValueOkna = null;
    var callbackFunction = null;
    var isfocus = false;
    var interval = null;

    function __getDialog() {
        return aktualniOkno;
    }

    function __getTopDialog() {
        var retVal = aktualniOkno;
        while (retVal && retVal.KAKTUS) {
            var nextDialog = retVal.KAKTUS.Dialog.getDialog();
            if (nextDialog) {
                retVal = nextDialog;
            }
            else {
                break;
            }
        }
        return retVal;
    }

    function __zablokujUdalosti(cb) {
        KAKTUS.Skryvac.show(true, KAKTUS.GetResource('ProcessDialog', 'Vyplňte údaje v dialogovém okně.'), function() {
        KAKTUS.Event.addHandler(window, "focus", __focus);
        KAKTUS.Event.addHandler(window, "click", __focus);
            if (!interval) {
                interval = window.setInterval(__zajistiModalitu, 50);
            }
            if (cb) cb();
        });
    }

    function __focus() {
        isfocus = true;
        return false;
    }

    function __odblokujUdalosti() {
        KAKTUS.Skryvac.hide();
        aktualniOkno = null;
        if (interval) {
            window.clearInterval(interval);
            interval = null;
        }
    }

    function __close(data) {
        if (aktualniOkno != null) {
            __odblokujUdalosti();
        }
        aktualniOkno = null;
        if (callbackFunction && typeof (callbackFunction) == "function") callbackFunction(data);
    }

    function __zajistiModalitu() {
        if (aktualniOkno) {
            if (aktualniOkno.closed) {
                __close(returnValueOkna);
            }
            else if (isfocus) {
                isfocus = false;
                var dialog = __getTopDialog();
                if (dialog) {
                    window.blur();
                    dialog.focus();
                }
            }
        }
        return false;
    }

    // tato funkce se smi volat pouze v dialogovem okne  
    function __getParameters(deep) {
        if (window.showModalDialog) return window.top.dialogArguments;
        deep = !!deep;
        if (!deep && window.top.opener && window.top.opener.KAKTUS.Dialog) return window.top.opener.KAKTUS.Dialog.getParameters(true);
        return parametryOkna;
    }

    // tato funkce se smi volat pouze v dialogovem okne
    function __setReturnValue(value, deep) {
        if (window.showModalDialog) return window.top.returnValue = value;
        deep = !!deep;
        if (!deep && window.top.opener && window.top.opener.KAKTUS.Dialog) return window.top.opener.KAKTUS.Dialog.setReturnValue(value, true);
        return returnValueOkna = value;
    }

    function __show(url, parametry, vzhled, callback, nazevOkna) {
        if (!nazevOkna) nazevOkna = "_blank";
        if (!aktualniOkno || (aktualniOkno && aktualniOkno.closed)) {
            aktualniOkno = null;
            if (arguments.length < 1) return; // neni url
            if (arguments.length < 3 || vzhled == null) vzhled = "location=no,menubar=no,resizable=no,scrollbars=no,titlebar=no,toolbar=no,status=yes,dialog=yes";
            var sirka = null, vyska = null;
            var re = (/width[:=]([0-9]+)/i).exec(vzhled);
            if (re != null) {
                sirka = RegExp.$1;
            }
            else {
                sirka = 400;
                vzhled = "width=400px," + vzhled;
            }

            re = (/height[:=]([0-9]+)/i).exec(vzhled);
            if (re != null) {
                vyska = RegExp.$1;
            }
            else {
                vyska = 200;
                vzhled = "height=200px," + vzhled;
            }

            vzhled = "dialogWidth=" + sirka + "px,dialogHeight=" + (parseInt(vyska) + 50) + "px," + vzhled;
            if (vyska != null && sirka != null) {
                var oknoVelikost = KAKTUS.getWindowSize();
                var left = 50;
                var top = 50;
                if (window.screenX && window.outerWidth) {
                    // do stredu okna
                    left = window.screenX + ((window.outerWidth - sirka) / 2);
                    top = window.screenY + ((window.outerHeight - vyska) / 2);
                }
                else {
                    // do stredu obrazovky
                    left = (screen.width - sirka) / 2;
                    top = (screen.height - vyska) / 2;
                }

                if (vzhled.indexOf('left') == -1) vzhled = "dialogLeft=" + left + ",left=" + left + "," + vzhled;
                if (vzhled.indexOf('top') == -1) vzhled = "dialogTop=" + top + ",top=" + top + "," + vzhled;
                if (vzhled.indexOf('screenX') == -1) vzhled = "screenX=" + left + "," + vzhled;
                if (vzhled.indexOf('screenY') == -1) vzhled = "screenX=" + top + "," + vzhled;
            }
            parametryOkna = parametry;
            returnValueOkna = null;
            callbackFunction = null;
            if (window.showModalDialog) {
                KAKTUS.Skryvac.show(true, KAKTUS.GetResource('ProcessDialog', 'Vyplňte údaje v dialogovém okně.'), function() {
                    var dialogUrl = 'WebResource.axd?d=oIC-y_HHzursqmbP9_Dla01I5cRdsn88RdReWuRCfE5KJRgINs4hbbd1LuIkquet0&t=634096878488330000';
                    dialogUrl += (dialogUrl.indexOf('?') == -1) ? '?' : '&';
                    dialogUrl += 'kaktusdialogpageurl=' + escape(url);
                    returnValueOkna = showModalDialog(dialogUrl, parametry, vzhled.replace(/=/g, ':').replace(/,/g, ';'));
                    KAKTUS.Skryvac.hide(function() {
                        if (callback && typeof (callback) == "function") callback(returnValueOkna);
                    });
                });
            }
            else // modalitu musime zajistit my
            {
                callbackFunction = callback;
                var a = function() {
                    var okno = window.open(url, nazevOkna, vzhled.replace(/:/g, "=").replace(/;/g, ","));
                    okno.focus();
                    aktualniOkno = okno;
                };
                __zablokujUdalosti(a);
            }
        }
        else {
            var dialog = __getTopDialog();
            if (dialog) {
                window.blur();
                dialog.focus();
            }
        }
    }
    function constructorFn() {
    };
    constructorFn.getDialog = __getDialog;
    constructorFn.getTopDialog = __getTopDialog;
    constructorFn.show = __show;
    constructorFn.getParameters = __getParameters;
    constructorFn.setReturnValue = __setReturnValue;
    return constructorFn;
})();