// JavaScript Document
function ls_live_search(search_string, type)
{
	var vars = 'task=ajax_update&search_string='+search_string;
	if (type != null)
		vars += "&type="+type;
	$.post("/inc/live_search.php", vars, function(data)
	{
		var output = "";
		var type = "";
		try
		{
			var res = data.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";
		}
	});
	
	return false;	//this is needed so page doesn't refresh
}

function ls_trim(str)
{
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');	
}

function ls_findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

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 ls_timedHide(this_id)
{
	setTimeout("document.getElementById('"+this_id+"').style.display='none'", 10);	//500
}

function ls_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 = "";
	}
}
