// JavaScript Document

function resultOver(number,stars) {
	document.getElementById('result'+number).style.backgroundColor="#275af2";
	document.getElementById('result'+number).style.color="#FFFFFF";
	document.getElementById('star'+number).src="pic/search/stars/star"+stars+"-hover.gif";
}

function resultOut(number,stars) {
	document.getElementById('result'+number).style.backgroundColor="";
	document.getElementById('result'+number).style.color="";
	document.getElementById('star'+number).src="pic/search/stars/star"+stars+".gif";
}

function getHTML() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById('result-container').innerHTML=xmlHttp.responseText;
	}
	else if (document.getElementById('result-container').innerHTML == '')
	{
		document.getElementById('result-container').innerHTML="<p>&nbsp;</p><p align='center'><img src='pic/search/ajax-loader.gif' border='0' /></p><p>&nbsp;</p>";
	}
}

function getResults(url) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	url = url + "&sid="+Math.random();
	xmlHttp.onreadystatechange=getHTML;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
	{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
	}
  catch (e)
	{
	// Internet Explorer
	try
	  {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	catch (e)
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	}
  return xmlHttp;
}

function changeSearch() {
	offset = findPos(document.getElementById('search-div'));
	document.getElementById('result-container').style.left=(offset[0]-70)+'px';
	document.getElementById('result-container').style.top=(offset[1]+25)+'px';

	if (document.getElementById('search-field').value != '')
	{
		document.getElementById('result-container').style.visibility = 'visible';
		query = document.getElementById('search-field').value.replace(/&/gi,'');
		getResults('search.php?query='+query);
	}
	else
	{
		document.getElementById('result-container').style.visibility = 'hidden';
		document.getElementById('result-container').innerHTML = '';
	}
}

function focusSearch() {
//	document.getElementById("search-div").style.backgroundImage="url(pic/search/bg-active.jpg)";
//	document.getElementById("search-field").style.backgroundColor="#FFFFFF";

	if (document.getElementById('search-field').value != '')
	{
		document.getElementById('result-container').style.visibility = 'visible';
		query = document.getElementById('search-field').value.replace(/&/gi,'');
		getResults('search.php?query='+query);
	}
}

function blurSearch() {
//	document.getElementById("search-div").style.backgroundImage="url(pic/search/bg.jpg)";
//	document.getElementById("search-field").style.backgroundColor="#FFFFFF";

	setTimeout(hideResults,200);
}

function hideResults() {
	document.getElementById('result-container').style.visibility = 'hidden';
	document.getElementById('result-container').innerHTML = '';
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

