
var tutSearch = {

	initiate: function(id, result_id, mode, sec)
	{
		tutSearch.txtId = id;
		tutSearch.resId = result_id;
		tutSearch.run = false;
		tutSearch.mode = mode;
		tutSearch.md5check = sec;

		tutSearch.attachEvent();
	},

	attachEvent: function()
	{
		var id = document.getElementById(this.txtId);

		id.onkeyup = function()
		{
			if (tutSearch.run)
				clearTimeout(tutSearch.run);
			tutSearch.run = setTimeout(function()
			{
				tutSearch.runSearch(id.value);
			}
			,1000);
		}
	},

	runSearch: function(terms)
	{
		var ajax = false;
		var id = document.getElementById(this.txtId);
		var resId = document.getElementById(this.resId);
		var file = "/ajax.php?mode=" + this.mode;

		try
		{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				ajax = false;
			}
		}

		if (!ajax && typeof XMLHttpRequest != "undefined")
		{
			ajax = new XMLHttpRequest();
		}

		if (ajax)
		{
			ajax.open("GET", file + "&search=" + terms + "&md5check=" + this.md5check, true);
			ajax.send(null);

			ajax.onreadystatechange = function()
			{
				if (ajax.readyState == 4)
				{
					var results = ajax.responseText;
					resId.innerHTML = results;
				}
			}
		}
		else
		{
			id.value = "Sorry, ajax is not supported by your browser";
		}
	}
};