function setEditValue(edit, value) {
    var editControl = window.opener.document.getElementById(edit);
    if (editControl != null)
        editControl.value = value;
    window.close();
}

function checkAll(masterCheckClientId) {
    if (typeof (checks) != "undefined" && checks != null) {
        var check = document.getElementById(masterCheckClientId);
        for (counter = 0; counter < checks.length; counter++) {
            var option = document.getElementById(checks[counter]);
            if (option != null && !option.disabled)
                option.checked = check.checked;
        }
    }
}

function tryUncheckMasterCheck(slaveCheckClientId, masterCheckClientId) {
    masterCheck = document.getElementById(masterCheckClientId);
    slaveCheck = document.getElementById(slaveCheckClientId);

    if (!slaveCheck.checked && masterCheck.checked)
        masterCheck.checked = false;
}

function confirmation(text) {
    if (!window.confirm(text))
        event.returnValue = false;
}

function changeChecked(masterCheck) {
    var masterControl = document.getElementById(masterCheck);
    if (masterControl != null) {
        var list = rights_Forward;
        if (!masterControl.checked)
            list = rights_Backward;

        for (counter = 0; counter < list.length; counter++) {
            var check = document.getElementById(list[counter]);
            if (check == masterControl)
                break;

            check.checked = masterControl.checked;
        }
    }
}

function showInPopUpWindow(url, windowName) {
    var win = window.open(url, windowName, "width=1000,height=740,left=5,top=5,scrollbars=yes,resizable=yes");
    win.focus();
}

function showInPopUpWindowWithPosition(url, windowName, left, top) {
    var win = window.open(url, windowName, "width=1000,height=740,left=" + left + ",top=" + top + ",scrollbars=yes,resizable=yes");
    if (win != null)
        win.focus();
    else
        alert('Nepodařilo se otevřít nové okno. Pravděpodobně máte zakázáno otevírání PopUp oken.');
}

function submitOnEnter(submitButtonClientId) {
    if (window.event != null) {
        if (window.event.keyCode == 13) {
            var butt = document.getElementById(submitButtonClientId);
            butt.click();
            window.event.returnValue = false;
        }
    }
}

function getValueFromHidden(hidClientId) {
    hidValue = 0;
    hidClient = document.getElementById(hidClientId);
    colorId = (hidClient != null) ? colorId = hidClient.value : hidClientId.value;

    return parseInt(colorId);
}

function keepAlive() {
    window.status = "Session connection refreshed.";
    var img = new Image(1, 1);
    img.src = "KeepAlive.aspx";
}

function pageAutoRefresh(second) {
    setTimeout("window.location.reload(true)", second * 1000);
}

function disableObjects() {
    for (counter = 0; counter < disabledControls.length; counter++) {
        ctrl = document.getElementById(disabledControls[counter]);
        if (ctrl != null)
            ctrl.disabled = !ctrl.disabled;
    }
}

function GetE(elementId) {
    return document.getElementById(elementId);
}

function SetCssID(id) {
    GetE('lblLinkCSS').value = id;
}

function selectRadios(list) {
    for (counter = 0; counter < list.length; counter++) {
        radio = document.getElementById(list[counter]);
        if (!radio.checked)
            radio.checked = true;
    }
}

function ScriptFunction(url, itemId) {
    var xmlhttp = false;

    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E) {
            xmlhttp = false;
        }
    }

    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }

    xmlhttp.open("GET", url, true);

    xmlhttp.onreadystatechange = function() {

        if (xmlhttp.readyState == 4) {
            document.getElementById(itemId).innerHTML = xmlhttp.responseText;
        }
    }

    xmlhttp.send(null)
}

function ChangeSessionTimeout(targetTextItem, time, errorUrl) {
    time = time - 1;
    var minutes = Math.floor(time / 60);
    var seconds = time % 60;
    var timeText = "";
    if (minutes < 10)
        timeText = "0" + minutes;
    else
        timeText = minutes;
    if (seconds < 10)
        timeText = timeText + ":0" + seconds;
    else
        timeText = timeText + ":" + seconds;
    var item = document.getElementById(targetTextItem)
    if (time > 0) {
        if (item != null) {
            item.innerHTML = timeText;
            if (time < 180)
                item.style.color = "red";
        }

        window.setTimeout('ChangeSessionTimeout(\'' + targetTextItem + '\', ' + time + ', \'' + errorUrl + '\');', 1000);
    }
    else {
        //window.location.reload(true);	
        window.location.href = errorUrl;
    }
}


function LoadPngs(blankImagePath) {
    if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
        var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
        var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7.0);
        // debugger

        if (itsAllGood) {
            document.writeln('<style type="text/css">img { visibility:hidden; } </style>');
            for (var i = 0; i < document.all.length; i++) {
                var img = document.all[i]
                if (img.src != null) {
                    var imgName = img.src.toUpperCase()
                    if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
                        //alert('ok');
                        var src = img.src;
                        img.style.width = img.width + "px";
                        img.style.height = img.height + "px";
                        img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader  (src='" + src + "')";
                        img.src = blankImagePath;
                    }
                    img.style.visibility = "visible";
                }
            }
        }
    }
}

// modalni dialog Detail Uzivatelskeho uctu
function detailUctu_InicializaceAZobrazeni(text, url, velikost_sirka, velikost_vyska) {
    var headerDivWidth = eval(velikost_sirka.replace("px", "") - 20) + "px";
    var imgCloseUrl = url.substring(0, url.lastIndexOf('/') + 1) + "img/closeWindow.jpg";
//    backgroundDiv, ktery kryje pozadi aplikace, pokud je aktivni, tak nejde po naslednem otevreni komponenty psat do textboxu
//    var winW, winH;
//    if (parseInt(navigator.appVersion) > 3) {
//        if (navigator.appName == "Netscape") {
//            winW = window.innerWidth;
//            winH = window.innerHeight;
//        }
//        if (navigator.appName.indexOf("Microsoft") != -1) {
//            winW = document.body.offsetWidth;
//            winH = document.body.scrollHeight;
//        }
//    }
//    
//    divBackground = document.createElement('div');
//    divBackground.setAttribute('id', "divBack");
//    divBackground.className = "yui3-overlay-mask";
//    divBackground.style.width = winW;
//    divBackground.style.height = winH;
//    document.forms[0].appendChild(divBackground);

    YUI().use('overlay', function(Y) {
        var overlay = new Y.Overlay({
            centered: true,
            visible: false,
            zIndex: 9,
            headerContent: "<div style=\"position:relative;float:left;width: " + headerDivWidth + ";\">" + text + "</div>" + "<div style=\"position:relative;float:left;width:20px;text-align:right;\"><img id=\"imgCloseWindow\" src=\"" + imgCloseUrl + "\" style=\"cursor: pointer; visibility: visible !important;\"></div><div style=\"clear:both;\"></div>",
            bodyContent: "<div style=\"width:" + velikost_sirka + "; height:" + velikost_vyska + "\"><iframe src=\"" + url + "\" width=\"100%\" height=\"100%\" frameborder=0 scrolling=no /></div>"
        }).render();

        Y.one('#imgCloseWindow').on('click', function(e) {
//            var divBack = document.getElementById('divBack');
//            document.forms[0].removeChild(divBack);
            
            overlay.destroy();
        });
        
        overlay.show();
    });
}