
    var searchCriteria = '';
    var openMenu = -1;
    var activeMenu = '';
    
    function athHighlight(id)
    {
        var o = document.getElementById(id);
        if (o)
        {
            var r = o.getElementsByTagName('td')[0];
            if (r)
            {
                r.style.backgroundColor = '#A8A7A7';
                var s = r.getElementsByTagName('span')[0];
                if (s)
                    s.style.color = '#FFFFFF';
            }
        }
    }
    
    function athDarken(id)
    {
        if (activeMenu == id)
            return;
            
        var o = document.getElementById(id);
        if (o)
        {
            var r = o.getElementsByTagName('td')[0];
            if (r)
            {        
                r.style.backgroundColor = '';
                var s = r.getElementsByTagName('span')[0];
                if (s)
                    s.style.color = '';
            }
        }
    }
    
    function menuFadeIn(id, timeout)
    {
        if (openMenu == id) return;
        
        if (openMenu != -1)
            menuFadeOut(openMenu, timeout);
        
        if (timeout == -1) timeout = 30;
        
        var i = 0;
        var o;
        
        while (o = document.getElementById('menu' + id + 'sub' + i))
        {
            setTimeout("document.getElementById('menu" + id + "sub" + i + "').style.display = '" + displayMode + "';",i*timeout);
            i++;
        }
        
        openMenu = id;
    }
    
    function menuFadeOut(id, timeout)
    {
        if (timeout == -1) timeout = 30;
        
        var i = 0;
        var o;
        
        while (o = document.getElementById('menu' + id + 'sub' + i))
          i++;

        var lastItem = --i;
        
        while (i>=0)
        {
            setTimeout("document.getElementById('menu" + id + "sub" + i + "').style.display = 'none';",(lastItem-i)*timeout);
            i--;
        }
    }
    
    function searchBoxKeyPress(e)
    {
        var theEvent = ((this == window)?window.event:e);
        if (e.keyCode == 13)
        {
            var obj = document.getElementById('searchforminput');
            if (obj)
            {
                var tp = document.getElementById('SearchTypeAllWords');
                var appd = ((tp)&&(tp.checked)) ? 'all' : '';
                location = '/queryidx' + appd + ':' + encodeURIComponent(obj.value);
            }
        }
        
        return false;
    }
    
    function searchButtonClick(e)
    {
        var obj = document.getElementById('searchforminput');
        if (obj)
        {
            var tp = document.getElementById('SearchTypeAllWords');
            var appd = ((tp)&&(tp.checked)) ? 'all' : '';
            location = '/queryidx' + appd + ':' + encodeURIComponent(obj.value);
        }
    }
    
    function newsletterBoxKeyPress(e)
    {
        var theEvent = ((this == window)?window.event:e);
        if (e.keyCode == 13)
        {
            var obj = document.getElementById('WebForm');
            if (obj)
            {
                obj.action = '';
                obj.submit();
            }
        }
        
        return false;    
    }
    
    function submitComment(e)
    {
        var ih = document.getElementById('usercomment_hidden');
        if (ih)
        {
            ih.value = "1";            
            var obj = document.getElementById('WebForm');
            if (obj)
            {
                obj.action = '';
                obj.submit();
            }
        }
        
        return false;    
    }
    
    function showContent(contentid)
    {
        var content = document.getElementById(contentid + '_content');
        var show = document.getElementById(contentid + '_show');
        var hide = document.getElementById(contentid + '_hide');
        
        if ((content)&&(show)&&(hide))
        {
            if (content.style.display == 'none')
            {
                content.style.display = '';
                show.style.display = 'none';
                hide.style.display = '';
            }
            else
            {
                content.style.display = 'none';
                show.style.display = '';
                hide.style.display = 'none';
            }
        }
        
	    return false;
    }
    
    function maintainHeight()
    {
        var viewport;
        
        viewport = document.documentElement.clientHeight;        
        var g = document.getElementById('navigationcolumn');
        g.style.height = (viewport-152) + 'px';
        
        viewport = document.getElementById('contentcell').clientWidth;
        var h;
        h = document.getElementById('history_content');
        h.style.left = (viewport-44) + 'px';
        h = document.getElementById('comment_content');
        h.style.left = (viewport-244) + 'px';
        
        if (scrollMode == 'off')
            return;

        viewport = document.getElementById('contentcell').clientWidth;
        var o = document.getElementById('addresscont');
        if (o.style.position == 'fixed')
            o.style.width = (viewport-38) + 'px';
    }
    
    function topLayer()
    {
        if (scrollMode == 'off')
            return;
            
        var o = document.getElementById('addresscont');
        var g = document.getElementById('fill');
        var h = document.getElementById('history_content');
        var j = document.getElementById('comment_content');
        if (document.documentElement.scrollTop > 130)
        {
            var x = o.clientWidth;
            o.style.position = 'fixed';
            o.style.top = '0px';
            o.style.width = x + 'px';
            g.style.display = 'block';
            h.style.position = 'fixed';
            h.style.top = '35px';
            j.style.position = 'fixed';
            j.style.top = '35px';
        }
        else
        {
            o.style.position = 'relative';
            o.style.top = '0px';
            o.style.width = '';
            g.style.display = 'none';
            h.style.position = 'absolute';
            h.style.top = '165px';
            j.style.position = 'absolute';
            j.style.top = '165px';
        }
        maintainHeight();
    }
    
    function getCookie(name)
    {
        var cname = name + "=";               
        var dc = document.cookie;           
        if (dc.length > 0) 
        {
            begin = dc.indexOf(cname);       
            if (begin != -1) 
            {
                begin += cname.length;       
                end = dc.indexOf(";", begin);
                if (end == -1) end = dc.length;
                return dc.substring(begin, end);
            }
        }
        return '';
    }

    function setCookie(name, value) 
    { 
        document.cookie = name + "=" + value;
    }
    
    var currentHistory = -1;
    
    function addHistory(link1, link2, link3, clear)
    {
        if (clear)
            clearHistory();

        var s = getCookie('athenahistory');
        if (s != '')
        {
            var a = s.split('//');
            if (currentHistory != -1)
            {
                a = a.slice(0, currentHistory + 1);
            }
            //else
                //a = new Array();
            while (a.length > 9) a.shift();
            if (a.length > 0)
                s = a.join('//');
            else
                s = '';
        }
        s = s + (s != '' ? '//' : '') + encodeURIComponent(link1) + '/' + encodeURIComponent(link2) + '/' + encodeURIComponent(link3);
        setCookie('athenahistory',s);
    }
    
    function displayNoHistory()
    {
        var o = document.getElementById('history_content');
        if (!o) return;
        o.innerHTML = '<span style="color: silver; font-style: italic">brak elementów historii</span>';
    }
    
    function loadHistory()
    {
        var o = document.getElementById('history_content');
        if (!o) return;
        
        var s = getCookie('athenahistory');
        if (s != '')
        {
            var a = s.split('//');
            if (a.length > 0)
            {
                for (i=0;i<a.length;i++)
                {
                    var b = a[i].split('/');
                    if (b.length == 3)
                    {
                        if (b[1] == document.location.pathname.substr(document.location.pathname.lastIndexOf('/') + 1))
                            currentHistory = i;
                    }
                }
                for (i=0;i<a.length;i++)
                {
                    var b = a[i].split('/');
                    if (b.length == 3)
                    {
                        if (i > 0) o.innerHTML += '<br /><img src="visual/images2/arrow.gif" alt="" /><br />';
                        if (i == currentHistory) cls = ' style="font-weight: bold"'; else cls = '';
                        if (b[0] != '')
                            o.innerHTML += '(' + decodeURIComponent(b[0]) + ')<br />';
                        o.innerHTML += '<a href="/' + decodeURIComponent(b[1]) + '"' + cls + '>' + decodeURIComponent(b[2]) + '</a>';
                    }
                }
            }
            else
                displayNoHistory();
        }
        else
            displayNoHistory();
    }
    
    function clearHistory()
    {
        setCookie('athenahistory','');
    }
    
    function start(page,name,width,height)
    {
	    window.open(page, name, "width="+width+",height="+height+",scrollbars=yes,statusbar=no");
    }
    
    function initPage()
    {
        loadHistory();
        maintainHeight();
    }
    
    function addFavorites()
    {
        var title = 'Biblioteka Polskiej Piosenki';
        var href = 'http://www.bibliotekapiosenki.pl';

        if (window.sidebar)
        {
            window.sidebar.addPanel(title, href, ""); 
        }
        
        if (window.external)
        {
            window.external.AddFavorite(title, href); 
        }
        
        if (window.opera && window.print)
        {
            var a = document.createElement('a');
            a.setAttribute('href', href);
            a.setAttribute('title', title);
            a.setAttribute('rel','sidebar');
            a.click();
        }
    }
    
    function DisplayVariant(name, number)
    {
	    var i = 0;
	    var o;
    	
	    while (o = document.getElementById(name + i))
	    {
		    o.style.display = ((number == i) ? 'block' : 'none');
		    i++;
	    }
    }
    
    
    function displayPicture(src)
    {
	    var cd = document.getElementById('ImageListCoverDiv');
	    cd.style.width = '' + (document.documentElement.scrollWidth) + 'px';
	    cd.style.height = '' + (document.documentElement.scrollHeight) + 'px';

	    var pd = document.getElementById('ImageListPictureDiv');
	    pd.style.width = '200px';
	    pd.style.height = '200px';
	    pd.style.top = '' + (((document.documentElement.clientHeight - 200) / 2) + document.documentElement.scrollTop) + 'px';
	    pd.style.left = '' + ((document.body.clientWidth - 200) / 2) + 'px';
    	
	    var pl = document.getElementById('ImageListLoader');	
	    pl.style.display = 'block';
    	
	    pd.style.visibility = 'visible';
    	
	    pi = document.getElementById('ImageListImage');
	    pi.style.display = 'none';
	    pi.src = src;
    }

    function showPicture()
    {
	    var pi = document.getElementById('ImageListImage');
	    pi.style.visibility = 'hidden';
	    pi.style.display = 'block';

	    var pd = document.getElementById('ImageListPictureDiv');
	    pd.style.width = 'auto';
	    pd.style.height = 'auto';
	    pd.style.top = '' + (((document.documentElement.clientHeight - pi.clientHeight) / 2) + document.documentElement.scrollTop) + 'px';
	    pd.style.left = '' + ((document.body.clientWidth - pi.clientWidth) / 2) + 'px';

	    pl = document.getElementById('ImageListLoader');
	    pl.style.display = 'none';
	    pi = document.getElementById('ImageListImage');
	    pi.style.visibility = 'visible';
    }

    function hidePicture()
    {
	    var pd = document.getElementById('ImageListPictureDiv');
	    pd.style.visibility = 'hidden';
    	
	    pi = document.getElementById('ImageListImage');
	    pi.style.display = 'none';	
    	
	    var cd = document.getElementById('ImageListCoverDiv');
	    cd.style.width = '0px';
	    cd.style.height = '0px';	
    }

    function browserPicture(src)
    {
        var bc = document.getElementById('browser_content');
        var bi = document.getElementById('browser_image');
        var bl = document.getElementById('browser_loader');
        
        if ((bc) && (bi) && (bl))
        {
            var full = (bi.src.match(/\/D_/));
            bi.src = (full ? src : src.replace('/D_','/S_').replace('binaries/','thumbs/'));
            bc.style.width = (full ? '100%' : '770px');
            bc.style.height = bc.clientHeight.toString() + 'px';
            bc.style.overflow = (full ? 'scroll' : 'hidden');
            bl.style.display = 'block';
        }
    }
    
    function browserSwitch()
    {
        var bc = document.getElementById('browser_content');
        var bi = document.getElementById('browser_image');
        var bl = document.getElementById('browser_loader');
        
        if ((bc) && (bi) && (bl))
        {
            var full = (bi.src.match(/\/D_/));
            bi.src = (full ? bi.src.replace('/D_','/S_').replace('binaries/','thumbs/') : bi.src.replace('/S_','/D_').replace('thumbs/','binaries/'));
            bc.style.width = '100%';
            bc.style.height = bc.clientHeight.toString() + 'px';
            bc.style.overflow = 'scroll';
            bl.style.display = 'block';
        }
    }
    
    function browserLoad()
    {
        var bc = document.getElementById('browser_content');
        var bi = document.getElementById('browser_image');
        var bl = document.getElementById('browser_loader');
        
        if ((bc) && (bi) && (bl))
        {
            bl.style.display = 'none';
            bc.style.height = (bi.clientHeight > 400 ? 'auto' : '400px');
        }
    }