var waittime = 300;
var v1;
var sloc;
function timeout(v1){
	// set the activity img and get the final value
	$('search-activity').style.visibility = 'visible';
	// get the search field's value
 var v2 = $('search-field').value;
 if(v1 == v2){
  search();
 }
 else
  return false;
}

function ajaxsearch(val,loc) {
	// val = search value | loc = search location
	sloc = loc;
	if($('search-field').value != "" && v1 != val){ // second check (v1!=val) is to prevent another search over the same query
	  v1 = val;
    setTimeout('timeout("'+v1+'");', waittime);
	}
	if($('search-field').value == ""){
		v1 = "";
		$('search-results').style.display = "none";
	}
}

var sobject = createRequestObject();

function search_handler() {
    if(sobject.readyState == 4){
          $('search-results').style.display = "block";
          var response = sobject.responseText;
          $('search-results').innerHTML = response;
  				$('search-activity').style.visibility = 'hidden';
    }
}

function search(){
	// get the final value
  value = $('search-field').value;
  // remove any wrong chars (./) from the search location
  if (sloc.charAt(0) == "." && sloc.charAt(1) == "/")
  	sloc = sloc.substring(2);
  //Do the ajax-request
  //sobject.open('post', './ajax.php?mod='+mod+'&pag='+pag+'&sub='+sub+'&id='+id);
  sobject.open('post', sloc);
  sobject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
  sobject.onreadystatechange = search_handler;
  sobject.send('query='+value);
}
