function GetWindowWidth() {
    var width = 0;
    if (typeof (window.innerWidth) == 'number') {//Non-IE
        width = window.innerWidth;
    }
    else if (document.documentElement && (document.documentElement.clientWidth
		|| document.documentElement.clientHeight)) {//IE 6+ in 'standards compliant mode'
        width = document.documentElement.clientWidth;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {//IE 4 compatible
        width = document.body.clientWidth;
    }
    return width;
}

function GetWindowHeight() {
    if (typeof (window.innerWidth) == 'number') {
        return window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        return document.documentElement.clientHeight;
    }
    else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    else {
        return 0;
    }
}

function ResizeW(corr) {
    if (corr == null)
        corr = 25;
    var width = GetWindowWidth();
    if (typeof (maxwidth) != "undefined")
        if (width > maxwidth)
        return;
    if (control) {
        control.width = width - corr;
    }
    if (typeof (control2) != "undefined")
        if (control2) {
        control2.width = width - corr;
    }
}

function ResizeH() {
    var height = GetWindowHeight();
    if (typeof (maxheight) != "undefined")
        if (height > maxheight)
        return;
    if (control) {
        control.height = height - 20;
    }
    if (typeof (control2) != "undefined")
        if (control2) {
        control2.height = height - 20;
    }
}

function KeyDownHandler(evt, btn) {
    if (evt.keyCode == 13) {
        evt.returnValue = false;
        evt.cancel = true;
        __doPostBack(btn, '');
    }
}

function createCookie(name, value, days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function shiftOpacity(id, millisec) {
    if (document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    }
    else {
        opacity(id, 100, 0, 0);
        opacity(id, 0, 100, millisec);
    }
}

function opacity(id, opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    if (opacStart > opacEnd) {
        for (i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        }
    }
    else if (opacStart < opacEnd) {
        for (i = opacStart; i <= opacEnd; i++) {
            setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        }
    }
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function HidePanel(crossobj, cookieName) {
    crossobj.style.visibility = "Hidden";
    createCookie(cookieName, true, 1);
}

function ShowPanel(crossobj, cookieName) {
    crossobj.style.visibility = "Visible";
    createCookie(cookieName, true, 1);
}

function PositionPanel(crossobj) {
    if (!crossobj)
        return;
    var dsoctop = document.all ? document.body.scrollTop : pageYOffset;
    var dsocleft = document.all ? document.body.scrollLeft : pageXOffset;
    var window_width = document.all ? document.body.clientWidth : window.innerWidth;
    if (document.all || document.getElementById) {
        crossobj.style.left = (parseInt(dsocleft) + parseInt(window_width) - parseInt(crossobj.style.width)) / 2;
        crossobj.style.top = dsoctop + 405;
    }
    else if (document.layers) {
        crossobj.left = dsocleft + window_width - parseInt(crossobj.width) - 5;
        crossobj.top = dsoctop + 305;
    }
}

function SetObjectMaxHeight(crossobj, linkButton) {
    crossobj.style.height = "100%";
    linkButton.style.visibility = "Hidden";
}

function SetObjectHeight(crossobj, height) {
    crossobj.style.height = height;
}

function RefreshParent(parentPage) {
    window.parent.location.href = parentPage;
}

function textCounter(pocet, id_input, id_counter, warning) {
    var field = document.getElementById(id_input);
    var cntfield = document.getElementById(id_counter);
    if (field.value.length <= pocet) {
        cntfield.value = 'Zbývá ' + String(pocet - field.value.length) + ' znaků.';
        if (warning) {
            cntfield.value += ' Tlačítkem "Vložit text" dokončíte změny.';
        }
    }
    else if (warning) {
        cntfield.value = 'Upozornění: text bude automaticky zalomen na další řádky.';
    }
    else {
        field.value = field.value.substring(0, pocet);
    }
}



function setFooter() {
    if (document.getElementById) {
        var windowHeight = GetWindowHeight();
        if (windowHeight > 0) {
            var content = document.getElementById('ctl00_ewpz1_mainTemplateCtrl');
            var contentHeight = content.offsetHeight;
            if (content.offsetHeight) {
                contentHeight = content.offsetHeight;
            }
            else if (content.style.pixelHeight) {
                contentHeight = content.style.pixelHeight;
            }

            var footerElement = document.getElementById('footer');
            if (footerElement) {
                var footerHeight = footerElement.offsetHeight;
                if (windowHeight - (contentHeight + footerHeight) >= 0) {
                    footerElement.style.position = 'relative';
                    footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
                }
                else {
                    footerElement.style.position = 'static';
                }
            }
        }
    }
}
