﻿function show(index) {
    if (index > 0) {

        var kpsPolozekMenu = getCookie('kpsPolozekMenu');
        if (kpsPolozekMenu == null) kpsPolozekMenu = 4;

        for (var i = 1; i <= kpsPolozekMenu; i++) {
            document.getElementById('submenu' + i).style.display = 'none';
            document.getElementById('menuItem' + i).className = 'inactive';
        }
        
        document.getElementById('menuItem' + index).className = 'active';     
        document.getElementById('submenu' + index).style.display = 'block';
    }

    document.cookie = "kpsSubmenu=" + index;
};


function getCookie(cName) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(cName + "=");
        if (c_start != -1) {
            c_start = c_start + cName.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
};


function showDefaultSubmenu() {
    show(getCookie('kpsSubmenu'));
};


function showImg(docid, width, height) {
    width += 100;
    height += 100;

    if (height + 100 > screen.height) {
        height = screen.height - 200;
    }
    if (width + 100 > screen.width) {
        width = screen.width - 100;
    }

    x = (screen.width - width) / 2;
    y = (screen.height - height) / 2;

    window.open("imgDetail.aspx?docid=" + docid, "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,left=" + x + ",top=" + y + ",resizable=yes,width=20,height=20");
};

function browser() {
  var userAgent = navigator.userAgent.toLowerCase();
  if(userAgent.indexOf("msie") != -1){
    return "ie";
  }
  else if(userAgent.indexOf("firefox") != -1){
    return "firefox";
  }
  else if(userAgent.indexOf("opera") != -1){
    return "opera";
  }
  else return "other";
};


function remanipulator(width, height, descCharCount)
{
    if(height + 100 > screen.height)
        height= screen.height - 200;
    if(width + 100 > screen.width)
        width = screen.width - 100;

    posX = (screen.width  -  width) / 2;
    posY = (screen.height - height) / 2;

    window.moveTo(posX, posY);

    var charWidth = 7;
    var lineHeight = 15;
    var imgWidth = width;

    if (descCharCount > 0) {
        stringWidth = Math.ceil(descCharCount * charWidth);
        pomer = Math.ceil(stringWidth / imgWidth);

        descHeight = Math.ceil(pomer * lineHeight);
    }
    else {
        descHeight = 0;
    }

    if (browser() == "ie") {
        finalWidth = width + 12;
        finalHeight = height + 110;
        if (descHeight != 0) finalHeight += descHeight + 15; 
    }
    else if (browser() == "firefox") {
        finalWidth = width + 9;
        finalHeight = height + 95;
        if (descHeight != 0) finalHeight += descHeight + 8;
    }
    else if (browser() == "opera") {
        finalWidth = width + 10;
        finalHeight = height + 50;
        if (descHeight != 0) finalHeight += descHeight + 10;
    }
    else {
        finalWidth = width + 100;
        finalHeight = height + 100;
        if (descHeight != 0) finalHeight += descHeight + 20; 
    }
    
    window.resizeTo(finalWidth, finalHeight);
};
