function trim(tmp) {
	pat = /^\s+/;
	tmp = tmp.replace(pat, "");
	pat = /\s+$/;
	tmp = tmp.replace(pat, "");
	return tmp;
}

var nW,nH,oH,oW;
document.onclick=check;
function check(e) {
	var target = (e && e.target) || (event && event.srcElement);
	var obj = document.getElementById('suggestions');
	if(obj && target!=obj) {
		obj.style.display='none'
	}
}

function lookup(inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.post("rpc.php", {queryString: ""+inputString+""}, function(data) {
			if(trim(data).length >0) {
				var divheight=((Number(screen.availHeight)*6)/10) + "px";
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
				var lv = document.getElementById('suggestions');
				lv.style.height = divheight;
			} else {
				$('#suggestions').hide();
			}
		});
	}
} // lookup

function doSearch() {
	document.fm.categoryvalue.value= document.fm.inputString.value;
	document.fm.categoryname.value='';
	document.fm.page.value = 0;
	var url='&categoryname='+escape(document.fm.categoryname.value)+"&categoryvalue="+escape(document.fm.categoryvalue.value)+"&inputString="+escape(document.fm.inputString.value);
	document.fm.action='./?c=search'+ url;
	document.fm.submit();
}

function fill(thisValue,category) {
	setTimeout("$('#suggestions').hide();", 200);
	document.fm.categoryname.value=category;
	document.fm.categoryvalue.value= thisValue;
	document.fm.page.value = 0;
	var url='&categoryname='+escape(category)+"&categoryvalue="+escape(thisValue)+"&inputString="+escape(document.fm.inputString.value);
	document.fm.action='./?c=search'+ url;
	document.fm.submit();
}

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
