var xmlHttp = null;

function GetXmlHttpObject()
{
	try
	{ //Firefox, Opera 8.0+, Safari, new Internet Explorers
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{ //Old Internet Explorers
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function LoadStuff(targetObj, url)
{
	if(xmlHttp == null) xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null) return;

	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			targetObj.innerHTML = xmlHttp.responseText;
		}
	};
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function LoadList(page, key, order)
{
	o = document.getElementById("searchKey");
	if(o == null)
	{
		search = "";
	} else
	{
		search = o.value;
		search = search.replace("\&","%26");
		search = search.replace("\?","%3F");
		search = search.replace("\'","%27");
		search = search.replace("\"","%22");
		search = search.replace(" ", "%20");
	}

	var targetObj = document.getElementById("mainList");
	if(targetObj == null)
	{
		//List DIV doesn't "exist" yet. Try again later.
		var s = "LoadList("+page+",'"+key+"','"+order+"');";
		setTimeout(s, 5);
		return;
	}
	targetObj.innerHTML = "<img src=\"loader.gif\" alt=\"Loading...\" />";
	LoadStuff(targetObj, "fetch.php?page="+page+"&key="+key+"&order="+order+"&search="+search);
}

window.onload = function()
{
	LoadList(0, "id", "desc");
};

