var search_cart = document.getElementById("search_cart");

function get_search() {

	if (http) {
		http.open("GET", "/ajax/search.php?query="+search.value+"&rnd="+parseInt(Math.random()*99999999), true);
		http.onreadystatechange = SearchProcessHttpChange;
		http.send(null);
	}
}

function SearchProcessHttpChange() {

	if (http.readyState == 1) {
		load.style.display = "block";
		get_search_begin();

	} else if (http.readyState == 4) {

		load.style.display = "none";

		if (http.status == 200) {

			xmlRoot = http.responseXML.documentElement;

			txt_error = xmlRoot.getElementsByTagName('error')[0].firstChild.data;
			txt_status = xmlRoot.getElementsByTagName('status')[0].firstChild.data;
			array_value = new Array;

			for (var i=0; i<xmlRoot.getElementsByTagName('val').length; i++) {
				array_value[i] = xmlRoot.getElementsByTagName('val').item(i).firstChild.data;
			}
	
			if (txt_error == 1)	{ get_search_error(); }
			else		{ get_search_end(); }
		} else {
			get_search_error();
		}
	}
}

function get_search_begin() {

	search_cart.style.display = "none";
	search_cart.innerHTML = "";
}

function get_search_end() {

	status.style.display = "none";

	if (search.value != "") {
		search_cart.style.display = "block";
	}

	var div = "<table border='0' cellspacing='0' cellpadding='1' width='100%' class='text' bgcolor='#949494'>";
	div += "<tr>";
	div += "<td>";
	div += "<table border='0' cellpadding='3' cellspacing='1' width='100%' class='text' bgcolor='#FFFFFF'>";

	for (var i=0; i<array_value.length; i++) {
		url_array = array_value[i].split("|");

		div += "<tr><td><small>"+url_array[1]+":</small></td></tr>";
		div += "<tr><td><img src='/images/li.gif' width='9' height='9' border='0'>&nbsp;<a href='"+url_array[2]+"'>"+url_array[0]+"</a></td></tr>";
		div += "<tr><td height='1' background='/images/dots1.gif'></td></tr>";
	}

	div += "</table>";

	search_cart.innerHTML = div;
}

function get_search_error() {

	if (txt_status != 0) {
		status.style.display = "block";
		status.className = "status_error";
		status.innerHTML = txt_status;
	}
	search_cart.style.display = "none";
}