/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/
google.load("jquery", "1.3.1");
var $jSearch = jQuery.noConflict();
function lookup(page, inputString) {
	if(inputString.length == 0) {
		$jSearch('#suggestions').fadeOut(); // Hide the suggestions box
	} else {
		queryItemid = document.getElementById('queryJoomlaItemid').value;
		queryLang 	= document.getElementById('queryJoomlaLang').value;
		queryItemidParam = queryItemid ? "&queryItemid="+queryItemid : "";		
		queryLangParam   = queryLang ? "&queryLang="+queryLang : "";		
		$jSearch.post("sources/search/rpc.php?page="+page+queryItemidParam+queryLangParam, {queryString: ""+inputString+""}, function(data) { // Do an AJAX call
			$jSearch('#suggestions').fadeIn(); //Show the suggestions box
			$jSearch('#suggestions').html(data); //Fill the suggestions box
		});
	}
}

function hideResult(){
	//$jSearch('#suggestions').fadeOut();	
	document.getElementById('suggestions').style.display = 'none';
}

/**
 * Ajax INI
 */
var xmlHttp;
function GetXmlHttpObject(){ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest){
 		objXMLHttp=new XMLHttpRequest();
 	}
	else if (window.ActiveXObject){
 		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
 	}
	return objXMLHttp;
}

/**
 * AJAX 
 */
function save_stats_search(id, keyword, title, uri){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
	 	alert("Browser does not support HTTP Request");
	 	return;
	}
	var url="sources/search/save_stats.php?action=save";
	url=url+"&keyword="+keyword;
	url=url+"&title="+title;
	url=url+"&uri="+uri;
	//xmlHttp.onreadystatechange=state_save_stats_search;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	//id.removeAttribute("href");
	//id.disabled = true;
} 

//function state_save_stats_search(){ 
 	//if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
	//document.getElementById('test_stats').innerHTML = xmlHttp.responseText;
	//$jSearch('#suggestions').fadeIn(); // Show the suggestions box
	//$jSearch('#suggestions').html(xmlHttp.responseText); // Fill the suggestions box
//} 

function disable_link(id){
	id.removeAttribute("href");
}
