if (document.documentElement) document.documentElement.className="havejs";

window.onload=function()
{
	init_up_menu();
	init_zwin();
}

function add_zwin(li)
{
	var el,h4,ul;
	for (el=li.firstChild;el;el=el.nextSibling) {
		var sn=el.nodeName.toLowerCase();
		if (sn.charAt(0)=='h' && !h4) h4=el;
		else if ((sn=="ul" || sn == "ol") && !ul) ul=el;
	}
	if (!h4 || !ul) return;
	h4.className += ' cursorclick';
	h4.setAttribute('tabindex','0');
	h4.onclick=function()
	{
		zwin_rozwin(ul);
	}
	h4.onkeydown=function(ev)
	{
		if (!ev) ev=event;
		if (ev.keyCode == 13) zwin_rozwin(ul);
	}
}

function zwin_rozwin(ul)
{
	if (ul.className.indexOf('rozwi')<0) ul.className='rozwiniety';
	else ul.className='zwiniety';
}


function init_zwin()
{
	var zlista=document.getElementById('roczniki');
	if (!zlista) return;
	var li;
	for (li=zlista.firstChild;li;li=li.nextSibling) add_zwin(li);
}


function test_search_params()
{
	var fm=document.getElementById('main_search_form');
	if (!fm) return true;
	var inp=fm.getElementsByTagName('input');
	var i;
	for (i=0;i<inp.length;i++) if (inp[i].type == "text") {
		if (inp[i].value.length > 2) return true;
	}
	inp=fm.getElementsByTagName('select');
	for (i=0;i<inp.length;i++) {
		if (inp[i].selectedIndex>0) return true;
	}
	alert("Prosze wprowadzic pytanie do wyszukiwarki");
	return false;
}

function add_hover_umenu(li)
{
	var el,ul,a;
	function add_hm(lin)
	{
		if (!lin.firstChild) return;
		lin.firstChild.onmouseover=function() {
			lin.className="podswietlone";
		}
		lin.firstChild.onmouseout=function() {
			lin.className="";
		}
	}
	
	for (el=li.firstChild;el;el=el.nextSibling) {
		if (el.nodeName.toLowerCase()=='a') a=el;
		else if (el.nodeName.toLowerCase()=='ul') ul=el;
	}
	if (!ul || !a) return;
	ul.style.left=a.offsetLeft+'px';
	li.onmouseover=function() {
		li.className="nieschowane";
	}
	li.onmouseout=function() {
		li.className="schowane";
	}
	for (el=ul.firstChild;el;el=el.nextSibling) add_hm(el);
}


function init_up_menu()
{
	var ul=document.getElementById('topMenu');
	var li;
	for (li=ul.firstChild;li;li=li.nextSibling) if (li.className && li.className == "schowane") {
		add_hover_umenu(li);
	}
}
