var timer=0;
var t2=0;
var old,head,scrNum=0
var wait=0
var livesearchresults;
var defaultext = "search...";

function rpc(str,path){
 head=document.getElementsByTagName('head').item(0);
 script=document.createElement('script');
 script.id='scr'+scrNum
 script.src=path+'livesearch/livesearch_rpc.php?'+str+'&s='+script.id;
 script.type='text/javascript';
 script.defer=true;
 scrNum++
 void(head.appendChild(script));
 //prompt('',script.src);
}

function removeScript(scriptid){
 old=document.getElementById(scriptid);
 if(old)head.removeChild(old);
}

function clearSearch(obj){
 if(obj.value == defaultext){
  obj.value="";
 }else if(obj.value == ""){
  obj.value=defaultext;
 }
 clearTimeout(wait);
}

function checkKey(kc){
 if(document.all){
  k=event.keyCode;
 }else{
  k=kc.which
 }
 if(k=='13'){ // carriage return
  return false;
 }
}

function startTimer(){
 t2++;
 timer=setTimeout("startTimer()",1);
}

function stopTimer(){
 t2=0;
 clearTimeout(timer)
}

function checkSearch(val,path){
 livesearchresults=document.getElementById('livesearchresults');
 clearTimeout(wait);
 if(val.length <= 2){
  livesearchresults.innerHTML='';
  livesearchresults.style.display='none';
 }else{
  if((val!="")&&(val!=defaultext)){
   livesearchresults.style.display='block';
   livesearchresults.innerHTML='<p class=\"msg\">Searching for &#8216;'+val+'&#8217;<\/p>';
   wait=setTimeout("doSearch('"+val+"','"+path+"')",250);
  }
 }
}

function doSearch(val,path){
 if(val != defaultext){
  startTimer();
  rpc('q='+val,path);
  clearTimeout(wait);
 }
}

function clearSearchResults(){
 livesearchresults=document.getElementById('livesearchresults');
 livesearchresults.innerHTML='';
 livesearchresults.style.display='none';
 document.getElementById('livesearch').value=defaultext;
}


