function googleSuggest(q) {
 var url = 'http://www.google.com/complete/search?hl=en&client=suggest&js=true&q='+encodeURIComponent(q);
 return jsRemote(url);
}

function jsRemote(url) {
 if (document && document.getElementsByTagName) {
  var head = document.getElementsByTagName('head')[0];
  var script = document.createElement('script');
  script.src = url;
  script.type = 'text/javascript';
  head.appendChild(script);
  return true;
 }
 return false;
}
var highlighted = -1;

window['google']['ac'] = {};

window['google']['ac'] = {
  Suggest_apply: function(frameElement, keyword, results, arr) {
  var datc = '';
  s = 0;
   for(var i = 0; i < results.length; i=i+2) {
    if (i > 0) {
	t=results[i].replace(' results', "");
	t=t.replace(' result', "");
     datc += "<li title='"+results[i-1]+"'><a href='' onClick=\"word('"+results[i-1]+"');return false\">"+results[i-1]+"<div align=right>"+t+"</div></a></li>";
	 s = 1;
    }
   } 
   if(s==1){
	$b('debug').style.display = '';
	$b('debug').innerHTML = datc;
	}
	else{
	$b('debug').style.display = 'none';
	$b('debug').innerHTML = '';
	}
  }
};

 function changeHighlight ()
	{
		var lis = document.getElementById("debug").getElementsByTagName('LI');
		if(highlighted > (lis.length-1)){
			highlighted = 0;
		}
		if(highlighted < 0){
			highlighted = lis.length-1;
		}
		for (i in lis)
		{
			var li = lis[i];

			if (highlighted == i)
			{
				
				document.getElementById("q").value = li.title;
				li.className = "ses";
				
			}
			else
			{
				li.className = "";
			}
			
		}
	}

var loading = false;
var opt = new Array();
var opb = false;
get_opt('oscroll');
get_opt('odebug');
get_optv(opt['oscroll'],opt['odebug']);

window.onload = function() {

bro();

document.form.q.focus();

 $b('q').onkeyup = function() {

  if (this.value.length > 0 && this.value.match(/[a-zA-Z0-9]\s$/)) {
   googleSuggest(this.value);
  }
 };
 
 $b('q').onkeyup = function(ev) {
 if(opt['odebug']==0){
  var q = $b('q').value;
  if (q.length > 0) {
  

		if(ev)
		{
			var key =  ev.keyCode;
		}
		if(window.event)
		{
			var key =  window.event.keyCode;
		}
		

		switch(key)
		{
			case 27:
			$b('debug').style.display = 'none';
			break;
			case 38:
				highlighted--;
			changeHighlight();
			break;
			case 13:
			$b('debug').style.display = 'none';
			break;
			case 40:
				highlighted++;
			changeHighlight();
			break;
			default:
			highlighted=-1;
			googleSuggest(q);
		}
	

	
  }else{
  $b('debug').style.display = 'none';
  $b('debug').innerHTML = '';
  }
 }
 };


};

function rep(){
var highlighted = -1;
var lis = document.getElementById("debug").getElementsByTagName('LI');
		for (i in lis)
		{
			var li = lis[i];
				li.className = "";
		}
}
