var NeedReload=false;
var h_cechy;
var cena;
var kat;
var katnames=new Array('sprzedam', 'kupię', 'zamienię', 'oferuję', 'poszukuję', 'posiadam do wynajęcia', 'poszukuję do wynajęcia', 'posiadam do wydzierżawienia', 'poszukuję do wydzierżawienia');

function GetParams()
{
	var opcja,opts;


	addlist(document.forms[0].dz1.options,parent.outline.GetRootList());
	o=parent.outline.FindOutline1();
	h_cechy=o.h_cechy;
	cena=o.cena;
	kat=o.kat;
	br=parent.outline.BrId;
	if(br != 0)
		parent.outline.Navigate(2,o.id);
	else
	{
  		n=document.forms[0].dz1.length;
		opts=document.forms[0].dz1.options;
		document.forms[0].dz1.options[n]=new Option("[ wybierz z listy ]","");
		/*
		opcja=document.createElement("OPTION");
		opcja.text="[wybierz z listy]";
		opcja.value="";
		opts.add(opcja);
		*/
		document.forms[0].dz1.options[n].selected=true;
		NeedReload=true;
	}
	lok=parent.mapa.window.lokal;
	powiats=document.forms[0].powiaty.options;
	i=0;
	if(lok!=0)
	{
		//powiats[0]=null;
		while(powiats[i++].value!=lok);
		powiats[i-1].selected=true;
	}
	else
	{
		powiats[0]=new Option("[ wybierz z listy ]","-2");
		/*opcja=document.createElement("OPTION");
		opcja.text="[wybierz z listy]";
		opcja.value="-2";
		powiats[0]=opcja;*/
		powiats[0].selected=true;
	}
}
function dellist(opts)
{
	while(opts.length>0)
	{
		opts[0]=null;
		//opts.remove();
	}
}
function addlist(opts,arr)
{
	var opcja;

	for(i=0;i<arr.length;i++)
	{
		opts[opts.length]=new Option(arr[i].str,arr[i].id);
		/*
		opcja=document.createElement("OPTION");
		opcja.text=arr[i].str;
		opcja.value=arr[i].id;
		opts.add(opcja);
		*/
	}
}
function addkats(opts,arr)
{
	var opcja,i;

	for(i=0;i<arr[0].length;i++)
	{
		opts[opts.length]=new Option(arr[0][i],arr[1][i]);
		/*opcja=document.createElement("OPTION");
		opcja.text=arr[0][i];
		opcja.value=arr[1][i];
		opts.add(opcja);*/
	}
}
function SetKat()
{
	var j,i,kats1;

	dellist(document.forms[0].kats.options);
	j=0;
	kats1=new Array(new Array(),new Array());
	for(i=0;i<katnames.length;i++)
	{
		if(((kat>>i)&0x1)!=0)
		{
			kats1[0][j]=katnames[i];
			kats1[1][j++]=1<<i;
		}
	}
	addkats(document.forms[0].kats.options,kats1);
	//alert(parent.katpoz);
	document.forms[0].kats.selectedIndex=parent.katpoz;
}	
function SelDz1(flag)
{
	var i;
	//alert(document.forms[0].dz2.options);
	//if(document.forms[0].dz2.options!=undefined)
		dellist(document.forms[0].dz2.options);
	
	i=document.forms[0].dz1.selectedIndex;
	//alert(document.forms[0].dz1[i].value);
	//alert(i);
	if(i!=12)
	{
		addlist(document.forms[0].dz2,parent.frames["outline"].GetList1(document.forms[0].dz1[i].value));
		parent.frames["outline"].Navigate(0,document.forms[0].dz1[document.forms[0].dz1.selectedIndex].value);
		if(flag==true)
			SelDz2();
	}
	else
		if(flag==true)
			parent.frames["outline"].Navigate(2,104);
	
}
function SelDz2()
{
	parent.katpoz=0;
	parent.outline.Navigate(2,document.forms[0].dz2[document.forms[0].dz2.selectedIndex].value);
	
}
function SelKat(lst)
{
	parent.katpoz=document.forms[0].kats.selectedIndex;
	location.replace("sq.php?kategoria="+lst.value);
}

function formattb()
{
	var i,oTables,j,cl,rw;

	oTables=document.all.tags("table");
	if(oTables(2)!=null)
		rw=oTables(2).rows;
	else
		return;
	for(i=0;i<rw(0).cells.length;i++)
	{
		//alert(rw(0).cells(i).innerText);
		if(rw(0).cells(i).innerText.indexOf("cena")>=0)
		{
			k=i;
			//alert(k);
		}
	}
	for(i=1;i<rw.length;i++)
	{
		cl=rw(i).cells;
		for(j=0;j<cl.length;j++)
		{
			//alert(typeof(k)!="undefined");
			if((typeof(k)!="undefined")?(j!=k):true)
			{
				cl(j).style.textAlign="center";
				if(j==0)
				{
					cl(j).style.width=100;
				}
				else if(j==1)
				{
					cl(j).style.width=70;
				}
				else if(j==2 && parent.document.all.data.width<500)
				{
					if(typeof(k)!="undefined")
						cl(j).style.width=65;
				}
				else if((typeof(k)!="undefined")?(j==(k+1)):false)
				{
					cl(j).style.width=10;
				}
			}
			else
			{
				cl(j).style.textAlign="right";//cena
				cl(j).style.width=30;

			}
		}
	}
	//alert(oTables(2).innerHTML);
}
