    function xmlEntities(arg)
    {
        var foo = arg;
        entitiesTab = ["nbsp", "ndash", "mdash", "prime"];
        replaceTab = ["&#160;", "\u2013", "\u2014", "´"];
        for (var en = 0; en < entitiesTab.length; ++en)
            foo = foo.replace(new RegExp("&" + entitiesTab[en] + ";", "g"), replaceTab[en]);
       // foo = foo.replace(new RegExp("&(\\w)", "g"), "&amp;\\1");
        return foo;
    }

    function mainPageFrameStart(left, top, width, height, idx)
    {

        return "<div id='" + idx + "' class='mainPageFrame' style='left:" + left + "px; top:" + top + "px; width: " + width + "; height: " + height + ";'>\n";
    }

    function mainPageFrameEnd()
    {
        return "</div>\n";
    }

    function menu_wyswietl_ramke(arg, x, y, w, h, idx)
    {
        arg = xmlEntities(decodeURIComponent(arg));

        w = (w == parseInt(w)) ? w + "px" : w;
        h = (h == parseInt(h)) ? h + "px" : h;
        idx = !isNaN(parseInt(idx)) ? 'tabLeftFrame' + idx : idx;
      //  if (idx == "okno")
      //      w = "auto";

        var el = document.getElementById(idx);
        if (el === undefined || el === null)
        {
            if(idx=='Xokno')
            {
                $.newWindow({id:idx, posx:x, posy:y, width:w+25, height:h, title:"Ajax Window Sample"});
                $.updateWindowContent(idx, arg);
            } else {
                el = document.createElement("div");
                el.className = 'mainPageFrame';
                el.id = idx;
                el.style.left   = x + "px";
                el.style.top    = y + "px";
                el.style.width  = w;
                el.style.height = h;
                el.innerHTML = arg;
                document.getElementById('container').appendChild(el);
                //el.innerHTML += mainPageFrameStart(x, y, w, h, idx) + arg + mainPageFrameEnd();
            }
        }
        else
        {
            if(idx=='Xokno')
            {
                //$.newWindow({id:idx, posx:x, posy:y, width:w+10, height:h, title:"Ajax Window Sample"});
                $.updateWindowContent(idx, arg);
            } else {
                el.style.left = x + 'px';
                el.style.top = y + 'px';
                el.style.width = w;
                el.style.height = h;
                el.innerHTML = arg;
            }
        }
    }

    function menu_zabij_ramke(id)
    {
        $.closeAllWindows();
        id = !isNaN(parseInt(id)) ? 'tabLeftFrame' + id : id;
        var cnt = document.getElementById('container');
        var el = document.getElementById(id);
        if (el !== undefined && el !== null)
        {
            cnt.removeChild(el);
            return true;
        }
        return false;
    }

    function menu_przebuduj_layout(num)
    {
        var mp, w1, w2, h1, h2, cnt, tlo, tlo2, elLogo;
        var x = 20;
        if (num == 1) // menu -> gra
        {
            menu_zabij_ramke(1);
            document.getElementById('strona').removeChild(document.getElementById('navbar'));
            document.getElementById('strona').removeChild(document.getElementById('logo'));
            cnt = document.getElementById('container');
            tlo = document.getElementById('tloswf1');
            if (tlo !== null) tlo.style.display = "none";
            tlo2 = document.getElementById('tloswf2');
            if (tlo2 !== null) tlo2.style.display = "none";
            cnt.style.backgroundImage = 'none';
            cnt.style.minHeight = "0px";
            document.getElementById('divCopyright').style.display = "none";
            //document.getElementById('divScrollFrame').style.display = "block";
            mp = 10 * 2 + 5 * 2; // brzeg + padding
            w1 = 460 - mp, h1 = 130 - mp - 5;
            w2 = 530 - mp, h2 = window.innerHeight - 111 - mp - 5;
            
            menu_wyswietl_ramke('', 0, 0, w1, h1, 'top_stats');
            menu_wyswietl_ramke('', w1 + x, 0, w2, h1, 'top_info');
            menu_wyswietl_ramke('', 0, h1 + x, 210 - mp, h2, 'menu');
            menu_wyswietl_ramke('', 210 - mp + x, h1 + x+61, 780 - mp, h2-61, 'main');
            menu_wyswietl_ramke('', 210 - mp + x+4, h1 + x+3, 780 - mp, 41, 'mini_menu');
            menu_wyswietl_ramke('', x, x, w1 + w2 - x/2, h1 + h2 - x/2, 'underFrame');
        }
        else if (num == 2) // gra -> menu
        {
            menu_zabij_ramke('top_stats');
            menu_zabij_ramke('top_info');
            menu_zabij_ramke('main');
            menu_zabij_ramke('menu');
            menu_zabij_ramke('underFrame');
            menu_zabij_ramke('mini_menu');
            cnt = document.getElementById('container');
            elLogo = document.createElement('div');
            elLogo.id = "logo";
            elLogo.className = 'logoduze';
            document.getElementById('strona').insertBefore(elLogo, cnt);
            var el = document.createElement('div');
            el.id = "navbar";
            document.getElementById('strona').insertBefore(el, cnt);
            cnt.style.backgroundImage = null;
            cnt.style.minHeight = "700px";
            document.getElementById('tloswf1').style.display = "inline";
            document.getElementById('tloswf2').style.display = "inline";
            document.getElementById('divCopyright').style.display = "block";
            //document.getElementById('divScrollFrame').style.display = "none";
        }
        else if (num == 3) // menu -> panel
        {
            menu_zabij_ramke(1);
            document.getElementById('strona').removeChild(document.getElementById('navbar'));
            document.getElementById('strona').removeChild(document.getElementById('logo'));
            cnt = document.getElementById('container');
            tlo = document.getElementById('tloswf1');
            if (tlo !== null) tlo.style.display = "none";
            tlo2 = document.getElementById('tloswf2');
            if (tlo2 !== null) tlo2.style.display = "none";
            cnt.style.backgroundImage = 'none';
            mp =  10 * 2 + 5 * 2; // brzeg + padding
            menu_wyswietl_ramke('', 0, 0, 210 - mp, window.innerHeight - 130 - mp - 5, 'menu');
            menu_wyswietl_ramke('', 210 - mp + x, 0, 780 - mp, window.innerHeight - 130 - mp - 5, 'main');
        }
        else if (num == 4) // panel -> menu
        {
            menu_zabij_ramke('menu');
            menu_zabij_ramke('main');
            elLogo = document.createElement('div');
            elLogo.id = "logo";
            elLogo.className = 'logoduze';
            document.getElementById('strona').insertBefore(elLogo, document.getElementById('container'));
            var elNav = document.createElement('div');
            elNav.id = "navbar";
            document.getElementById('strona').insertBefore(elNav, document.getElementById('container'));
            document.getElementById('tloswf1').style.display = "inline";
            document.getElementById('tloswf2').style.display = "inline";
        }
        else if (num == 5) // panel -> gra
        {
            if (document.getElementById('menu') === null) return menu_przebuduj_layout(1);
            menu_zabij_ramke('menu');
            menu_zabij_ramke('main');
            mp = 10 * 2 + 5 * 2; // brzeg + padding
            w1 = 460 - mp, h1 = 130 - mp - 5;
            w2 = 530 - mp, h2 = window.innerHeight - 111 - mp - 5;
            menu_wyswietl_ramke('', 0, 0, w1, h1, 'top_stats');
            menu_wyswietl_ramke('', w1 + x, 0, w2, h1, 'top_info');
            menu_wyswietl_ramke('', 0, h1 + x, 210 - mp, h2, 'menu');
            menu_wyswietl_ramke('', 210 - mp + x, h1 + x, 780 - mp, h2, 'main');
        }
        else if (num == 6) // gra -> panel
        {
            menu_zabij_ramke('top_stats');
            menu_zabij_ramke('top_info');
            menu_zabij_ramke('underFrame');
        }
        return null;
    }

    function menu_rozwin_grupe(id)
    {
        if($('#listMenuGroup' + id).is(":visible"))
        {
            $('#listMenuGroup' + id).hide("fast");
        } else {
            $('#listMenuGroup' + id).show("fast");
            var i = 0;
            /*while (document.getElementById('listMenuGroup' + (++i)) !== null)
                if (i != id && $('#listMenuGroup' + i).is(":visible"))
                    $('#listMenuGroup' + i).hide("fast");*/
        }
    }

