


window.gsearch = function(hash, skip, paging)
{

	if(window.location.hash.replace("#","")=="")
	{

		if(/^\/naised/.test(window.location.pathname)) 
			bookmarks.sethash("#gender=2");
		else if(/^\/mehed/.test(window.location.pathname)) 
			bookmarks.sethash("#gender=1");
		else if(/^\/kuulutused/.test(window.location.pathname)) 
		{
			bookmarks.sethash("#ads=1");
		}
		else 
			bookmarks.sethash("#home=1");
	}


	if(paging==null) ge('content').innerHTML='<div class="blockCaption"><div id="editor" class="profileEditor"></div><div id="search_progress"><img src="/images/progress7.gif"></div></div>';


	if(hash==null)
	{

		params = {};

		params.u=null;

		hash='#'+ajx2q(params);	


	}
	else {

		params=q2o(hash.replace('#',''));
	}

	/*
	if(params.home==1)
	{

		Ajax.Send('/home.php', {'u':params.u}, function(o,t) {
			show('content');
			ge('content').innerHTML=t;
		});

	}
	*/
	if(params.u)
	{

		Ajax.Send('/auto.php', {'u':params.u}, function(o,t) {
			show('content');
			ge('content').innerHTML=t;
		});
	
	}
	else {

		if(/^\/naised/.test(window.location.pathname)) params.gender=2;
		else if(/^\/mehed/.test(window.location.pathname)) params.gender=1;
		else params.gender=0;


		if(params.gender==0)
		{

			Ajax.Send('/ads.php', params, function(o,t) {
				show('content');
				ge('content').innerHTML=t;
			});
		}
		else {

			Ajax.Send('/search.php', params, function(o,t) {
				show('content');
				ge('content').innerHTML=t;
			});
		}
		
	}


	if(skip==null)
	{

		bookmarks.sethash(hash);
	}


	window.scrollTo(0, 0);
}








function show_paging(pid)
{


	if(/^\/postkast/.test(window.location.pathname))
	{

		window.location.href="?pid="+pid;
		return;
	}

	ge('paging_progress').style.visibility='';
	ge('paging_progress_bottom').style.visibility='';

	params={};

	if(h=window.location.hash.replace('#',''))
	{

		params=q2o(h);
	}

	params.pid = pid;

	hash='#'+ajx2q(params);	

	gsearch(hash,null,1);
}





onDomReady(function() {
	bookmarks.initialize();
});

function gsearch_onchange(obj)
{


	if(v==-1) return;

	if(v==obj.getAttribute('placeholder') && trim(obj.value)=="") return;
	if(v == obj.value) return;

	gsearch();
}
