var onResults=false;

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
var http = createRequestObject();
function sndReq(action) {
    http.open('get', action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function handleResponse() {
    if(http.readyState == 4){
		document.getElementById('searchResultsDiv').innerHTML = http.responseText;
    }
}

function search_out() {
	this.onResults=false;
}

function search_in() {
	this.onResults=true;
}

function qclick() {
	var val=document.getElementById('q').value;
	if (val=="Cerca") {
		document.getElementById('q').value="";
	}
}

function rclose() {
	var search_results=document.getElementById('search_results');
	search_results.innerHTML='';
}

function qOut() {
	var val=document.getElementById('q').value;
	if (val=="") {
		document.getElementById('q').value="Cerca";
	}
	if (this.onResults==false) {
		var search_results=document.getElementById('search_results');
		search_results.innerHTML='';
	}
}

function searchResultRowOver (div) {
	div.style.backgroundColor="#cccccc";
}

function searchResultRowOut (div) {
	div.style.backgroundColor="#ffffff";
}

function doSearch() {
	
	var val=document.getElementById('q').value;
	var rightcap_img = document.getElementById("rightcap_img");
	if (val && val!="Cerca") {
		rightcap_img.src="../library/searchbox/spinner_1.gif";
		var val = 'search_engine/do_search.php?q=' + document.getElementById('q').value; 
		sndReq(val);
		rightcap_img.src="../library/searchbox/searchbox_close.gif";
		rightcap_img.onclick=function(){
			document.getElementById('q').value='Cerca';
			var search_results=document.getElementById('search_results');
			search_results.innerHTML='';
			rightcap_img.src="../library/searchbox/searchbox_rightcap.gif";
		}
		
		return false;
	} else {
		//document.getElementById('q').value='Cerca';
		rightcap_img.src="../library/searchbox/searchbox_rightcap.gif";
	}
}
function openWindow(url) {
  window.open(url,'popupWindow','resizable=no,scrollbars=yes,toolbar=no,status=no,height=650,width=720');
}
function expandOrClose(arrow_id, list_num, list_name)  {
	/*
	var a = document.getElementById(arrow_id);
	if(a.name=='d') { 
		a.src='../library/searchbox/arrowRight.gif';
		a.name='r';
		hideSearchTypes(list_num,list_name);
	}
	else {
		a.src='../library/searchbox/arrowDown.gif';
		a.name='d';
		showSearchTypes(list_num,list_name);
	}
	return false;
	*/
}
function hideSearchTypes (i,j) { 
	/*
	var theDiv = document.getElementById(j).getElementsByTagName('li');
	for(var d = 1; d < theDiv.length; d++) {
		var theID = 'res-'+i+'-'+d;
		Effect.DropOut(theID);
	}
	*/
	
	
}	
function showSearchTypes (i,j) { 
	/*
	var theDiv = document.getElementById(j).getElementsByTagName('li');
	for(var d = 1; d < theDiv.length; d++) {
		var theID = 'res-'+i+'-'+d;
		
		Effect.Appear(theID);
	}
	*/
}