//otwórz stronę
function loaddoc(link) {
var link;
window.location.href=link;
}

//otwarcie zdjęcia w nowym oknie
function new_img(link, width, height) {
var link;
var width;
var height;
window.open('window.php?bimage='+link+'', 'foto' ,'left=20,top=20, width='+width+' , height='+height+', menubar=0, resizable=1, scrollbars=1');
}

//otwarcie zdjęcia w nowym oknie
function new_win(link, width, height) {
var link;
var width;
var height;
window.open(link, 'noweokno' ,'left=20,top=20, width='+width+' , height='+height+', menubar=0, resizable=1, scrollbars=1');
}


//sprawdzenie czy login istnieje
function check_login()
{
	var p_log = document.getElementById('log').value;
	new_win('window.php?page=register&run=check&login='+p_log,'550','120');
}

//w zależnosci od wybranej wartosci pola select 1 pokaz odpowiedni select 2
function subsel(sel1)
{
	if (!subtab)
	{
		alert ('Nie ma tablicy subtab ! Wstaw do index.php $tab[3]');
	}
	else
	{
		main = document.getElementById(sel1).value; //glowny select
		for (i=0; i<subtab.length; i++) //w petli sprawdz wszystkie divy z selectami - pokaz jeden wlasciwy
		{
			sub = "sub"+subtab[i];
			p = document.getElementById(sub);

			if (main == subtab[i])
			p.style.display="inline";
			else
			p.style.display="none";
		}
	}
}

//pokaż - schowaj wyszukiwarkę, pokaz-schowaj odp. pole w formularzu do ogloszen
function show_hide(w)
{
	c = "";
	var e1 = document.getElementById('s1');
	var e2 = document.getElementById('s2');
	if (document.getElementById('kolor'))
	c = document.getElementById('kolor');
	
	if (w=="show")
	{
		e1.style.display="block";
		e2.style.display="none";
		if (c) //dodaj ogłoszenie
		c.style.background="#c6f26d";
		else
		ustawCookie("szukaj","on",null); //zapisz do cookie właczenie wyszukiwarki
	}
	else
	{
		e1.style.display="none";
		e2.style.display="block";
		if (c)
		c.style.background="#fbbf24";
		else
		ustawCookie("szukaj","off",null); //zapisz wylaczenie
	}
}

//zakladki w wyszukiwarce
function sea(e)
{
	//pokaż odpowiednia zakładę i zmien kolor
	var usr = document.getElementById("sea_usr");
	var ogl = document.getElementById("sea_ogl");

	//zakladki
	usr_z = document.getElementById("z_usr");
	ogl_z = document.getElementById("z_ogl");

	if (e=="sea_usr") //szukaj w userach
	{
		loaddoc('?page=users&run=reload');
		usr.style.display = "block";
		ogl.style.display = "none";
		usr_z.setAttribute("class", "se_act");
		usr_z.setAttribute("className", "se_act");
		ogl_z.setAttribute("class", "se_nact");
		ogl_z.setAttribute("className", "se_nact");
	}
	if (e=="sea_ogl") //szukaj w ogloszeniach
	{
		loaddoc('?page=ogloszenia&run=reload');
		usr.style.display = "none";
		ogl.style.display = "block";
		usr_z.setAttribute("class", "se_nact");
		usr_z.setAttribute("className", "se_nact");
		ogl_z.setAttribute("class", "se_act");
		ogl_z.setAttribute("className", "se_act");
	}

}

function ustawCookie(nazwa, wartosc, expire) 
{
	document.cookie = nazwa + "=" + escape(wartosc) + ((expire==null)?"" : ("; expires=" + expire.toUTCString()))
}

