function setInitialHeight( panel )
{
var panel = document.getElementById("advanced_tabblet");
initialHeight=panel.style.height;
}

function showAdvanced( par )
{
var panel = document.getElementById("advanced_tabblet");
var keywords = document.getElementById("keyword_index_tabblet");
var linkTxt = document.getElementById("advanced_tabblet_link");
var linkSearch = document.getElementById("szukajLink");
var searchMode = document.forms.constraints.mode;

if ( par==undefined )
{
	if ( panel.style.display=="block" )
		par=false;
	else	
		par=true;
}

	if ( par )
	{
	// pokazujemy dodatkowy panel
		
		//ukryj baner
		if (document.getElementById("banerG")) document.getElementById("banerG").style.display = 'none';
		column(6);
		
		panel.style.display="block";
		panel.style.height=initialHeight;
		//panel.style.position="relative";
		//panel.style.top="0px";

		searchMode.value="advanced";
		linkTxt.innerHTML = "<img src=\""+basicIcon+
		"\" border=\"0\"/>"+
		basicText;
		keywords.style.display="none";
		
	}else{
	// ukrywamy dodatkowy panel
		panel.style.display="none";
		panel.style.height="0px";
		//panel.style.position="absolute";
		//panel.style.top="0px";
		searchMode.value="basic";
		linkTxt.innerHTML = "<img src=\""+advancedIcon+
		"\" border=\"0\"/>"+
		advancedText;
		keywords.style.display="block";
		//keywords.style.position="absolute";
		//keywords.style.top="300px"; 
		// uwaga!!! ze wzgledu na blad w IE trzeba bylo wprowadzic ta stala ktora blokuje uklad strony
	}
}

// funkcja obslugujaca stronnicowanie wynikow, wymaga zadeklarowanej globalnie w JS zmiennej /limit/
function strona ( page )
{
	if ( page >= 0 )
	{
		document.forms[0].offset.value= page*limit;
		document.forms[0].submit();
	}
}
// funkcja propagujaca ustawienia wyszukiwania miedzy zakladkami
function mangleURI ( el )
{
	// patch
	if ( document.forms[0].menu.value==1)
		menuList = 1;
	else 
		menuList = 0;
	
	el.href+="menu="+menuList;

	// wybrany tryb wyszukiwania
	el.href+="&mode="+document.forms[0].mode.value;

	// przenosimy zaznaczone dzialy
		for ( i=0; document.forms[0]["dzial"+i]!=undefined ; i++ )
		{
			if ( document.forms[0]["dzial"+i].checked )
				el.href+="&dzial"+i+"="+document.forms[0]["dzial"+i].value;
		}
	

	// fraze
	if ( document.forms[0].phrase.value.length > 0 )
	{
		el.href+="&phrase="+encodeURIComponent(document.forms[0].phrase.value);
	}
	// spojnik dla frazsy
	for ( i=0; i< document.forms[0].and_or.length; i++ )
		if ( document.forms[0].and_or[i].checked )
		{
			el.href+="&and_or="+document.forms[0].and_or[i].value;	
		}
	
	// ograniczenia czasowe
	if ( document.forms[0].dateconstraints.options.selectedIndex >= 0 )
		el.href+="&dateconstraints="+document.forms[0].dateconstraints.options[document.forms[0].dateconstraints.selectedIndex].value;
	// miesiac/rok
// 	if ( checkDate(document.forms[0].day.value, document.forms[0].month.value, document.forms[0].year.value ) )
// 	{
// 		el.href+="&day="+document.forms[0].day.value;
// 		el.href+="&month="+document.forms[0].month.value;
// 		el.href+="&year="+document.forms[0].year.value;
// 	}

	if ( document.forms[0].month.options[document.forms[0].month.selectedIndex].value )
		el.href+="&month="+document.forms[0].month.options[document.forms[0].month.selectedIndex].value;
	if ( document.forms[0].year.options[document.forms[0].year.selectedIndex].value )
		el.href+="&year="+document.forms[0].year.options[document.forms[0].year.selectedIndex].value;
	// sygnatury
	if ( document.forms[0].sygnatura.value.length > 0 )
		el.href+="&sygnatura="+encodeURIComponent(document.forms[0].sygnatura.value);
	if ( document.forms[0].sygnaturazdj.value.length > 0 )
		el.href+="&sygnaturazdj="+encodeURIComponent(document.forms[0].sygnaturazdj.value);
	// slowa kluczowe
	if ( document.forms[0].keywords.value.length > 0 )
		el.href+="&keywords="+encodeURIComponent(document.forms[0].keywords.value);
}

// funkcja zaznacza zadane pole checkbox dzialow
function selectDzialCheckbox( iddzialu )
{
	for ( i=0; document.forms[0]["dzial"+i] != undefined; i++ )
	{
		if ( document.forms[0]["dzial"+i].value == iddzialu )
			document.forms[0]["dzial"+i].checked = true;
	}
}
// funkcja wysyla formularz kryteriow wyszukiwania do panelu slow kluczowych
function slowa( iddzialu )
{
	document.forms[0].elements['iddzialu'].value=iddzialu;
	document.forms[0].action="slowa_kluczowe.php";
	document.forms[0].submit();
}

 
// Funkcja sprawdza poprawnosc daty wzgledem kalendarza gregorianskiego
function checkDate(day, month, year) {

var myDate = new Date( year, month-1, day-1 );
var parsedDate = new Date ( myDate.toGMTString());


// porownujemy miesiace - to wystarczy do poprawnej weryfikacji
if ( parsedDate.getMonth() != month-1 ) {
  return false;
} else {
  return true;
}
}
