 function findKeywords()
 {
  var d=new Date();
  ans=makeHttpRequest("/runSmallScript.php?searchingFor="+getObj('search').value+"&rand="+d.getTime(), 'searchReturn','', false);
 }

 function updateSearch(ans)
 {
  ans=ans.replace("<strong>","");
  ans=ans.replace("</strong>","");
  getObj('search').value=ans;

  findKeywords();
 }

 var searchTop=0;
 var searchLeft=0;
 function searchReturn(response)
 {
  var ans=response.split("#$%");
  var out="";
  if(ans.length>1)
  {
   for(i=0;i<ans.length;i+=2)
    out+="<li class=\"highlight\"><span onclick='updateSearch(\""+ans[i]+"\")' title='"+ans[i]+"' class='searchKeyword'>"+ans[i]+"</span><span onclick='updateSearch(\""+ans[i]+"\")' title='"+ans[i]+"' class='searchCount'>"+ans[i+1]+"</span></li><br>";
   if(searchTop==0 && searchLeft==0)
   {
    temp=getObj('search');
    while(temp.tagName!="BODY")
    {
		searchTop+=temp.offsetTop;
		searchLeft+=temp.offsetLeft;
		temp=temp.offsetParent;
    }
    searchTop=getObj('search').style.height
   }
  }
   getObj('ajaxSearch').innerHTML="<ul style='position:absolute; top:28px; left:66px; background:#fff; list-style:none; margin:0; padding:0'>"+out+"</ul>";
 }

 function sMore(id)
 {
  if(getObj(id+"_id").className=="showMore")
  {
   getObj(id+"_id").className="showLess";
   getObj(id+"Link").innerHTML="Show Less";
  }
  else
  {
   getObj(id+"_id").className="showMore";
   getObj(id+"Link").innerHTML="Show More";
  }
  return false;
 }

 function changeSort(val)
 {
  url=document.location.href;
  if(url.indexOf('?')>1)
  {
   if(url.indexOf('sort=')>1)
   {
	loc=url.indexOf('sort=')+5;
	tmp=url.substring(0,loc)+val;
	if(url.indexOf('&',loc)>1)
     tmp+=url.substring(url.indexOf('&',loc))
    document.location.href=tmp;
   }
   else
    document.location.href+="&sort=" + val;
  }
  else
   document.location.href+="?sort="+val;
 }
 
 function parseUrl(url)
 {
  if(url.indexOf('?')>1)
  {
	  tmp=Array();
	  prams=url.substr(url.indexOf('?')+1);
	eq=true
	i=0;
  	while(prams!="")
	{
	 if(eq)
	 {
	  tmp[i]=prams.substr(0,prams.indexOf("="));
	  prams=prams.substr(prams.indexOf("=")+1);
	  eq=false;
	 }
	 else
	 {
	  if(prams.indexOf("&")==-1)
	  {
		tmp[i]=prams;
		prams="";
	  }
	  else
	  {
	   tmp[i]=prams.substr(0,prams.indexOf("&"));		
	   prams=prams.substr(prams.indexOf("&")+1);
	  }
	  eq=true;
	 }
	 i++;
	}
	return tmp;
  }
  else
   return Array();
}
 
 function changePram(val,pram,def)
 {
  url=document.location.href;
  if(url.indexOf('?')>1)
  {
   prams=parseUrl(url);
   urlStr="";
   found=false;
   for(i=0;i<prams.length;i+=2)
   {
	if(prams[i]==pram)
	{
	 if(val!=def)
	 urlStr+="&"+prams[i]+"="+val;
	 found=true
	}
	else
	 urlStr+="&"+prams[i]+"="+prams[i+1];
   }
   if(!found && val!=def)
	  urlStr+="&"+pram+"="+val; 
   if(urlStr!="")
    document.location.href=url.substr(0,url.indexOf('?'))+"?"+urlStr.substr(1);
   else
    document.location.href=url.substr(0,url.indexOf('?'));   
  }
  else if(val!=def)
   document.location.href+="?"+pram+"="+val;
 }
 
 function toggleFilter(id)
 {
  if(getObj('filter'+id).className=="showFilter")
  {
   getObj('filter'+id).className="hideFilter";
   getObj('filterVal'+id).style.display="none";
  }
  else
  {
   getObj('filter'+id).className="showFilter";
   getObj('filterVal'+id).style.display="block";
  }
 }
 
 var showcat=false;
 function showCats()
 {
  if(!showcat)
  {
   getObj('showcatsId').innerHTML="<img src='/images/hidecat.jpg' width='200' height='90'>";
   getObj('categoryInfo').style.display='block';
   showcat=true;
  }
  else
  {
   getObj('showcatsId').innerHTML="<img src='/images/findcat.jpg' width='200' height='90'>";
   getObj('categoryInfo').style.display='none';	 
   showcat=false;
  }
 }