// JavaScript Document
function live_search(search_string, type)
{
	var vars = 'task=ajax_update&search_string='+search_string;
	if (type != null)
		vars += "&type="+type;
	new Ajax.Request("/inc/live_search.php", 
		{ 
			method: 'post', 
			postBody: vars,
			onComplete: showLiveResponse
		});
	
	return false;	//this is needed so page doesn't refresh
}

function showLiveResponse(req)
{
	var output = "";
	var type = "";
	try
	{
		var res = req.responseText.split("~@@@~");
		if (res.length == 2)
		{
			type = res[0];
			output = res[1];
		}
	}
	catch(e)
	{
		alert(e);
		//nothing	
	}
	
	results_box = document.getElementById("live_search"+((type!="") ? "_"+type : ""));
	container_box = document.getElementById("container_live_search"+((type!="") ? "_"+type : ""));
	if (output != "")
	{
		results_box.innerHTML = output;
		input_pos = findPos(document.getElementById(type));
		container_box.style.left = input_pos[0]+"px";
		container_box.style.top = (input_pos[1]+20)+"px";
		container_box.style.display = "";
	}
	else
	{
		container_box.style.display = "none";
	}
}

function trim(str)
{
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');	
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

function timedHide(this_id)
{
	setTimeout("document.getElementById('"+this_id+"').style.display='none'", 10);	//500
}

function checkShow(this_id)
{
	var search_div = document.getElementById(this_id);
	var container_div = document.getElementById("container_"+this_id);
	if (search_div.innerHTML != "")
	{
		container_div.style.display = "";
	}
}