var show_div = 0;

function LoadSearchAjax(force) {
	var query = '' + document.getElementById('substring_id').value;
	var req = new Subsys_JsHttpRequest_Js();
	var txt = "";
	
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if (req.responseJS[0]) {
				for (i=0; i<req.responseJS.length; i++) {
					if(req.responseJS[i]['product'] == "more results...") {
						txt = txt + "<a style=\"color:black;\" class=\"ajaxSearch\" onmouseover=\"setShowDiv(1)\" onmouseout=\"setShowDiv(0)\" onclick=\"document.productsearchform.submit();\">";
					}
					else {
						txt = txt + "<a style=\"color:black;\" class=\"ajaxSearch\" onmouseover=\"setShowDiv(1)\" onmouseout=\"setShowDiv(0)\" href=\"" + req.responseJS[i]['link'] + "\">";
					}
					txt = txt + req.responseJS[i]['product'];
					txt = txt + "</a><br>";
				}
				// alert(txt);
				document.getElementById('result_str').innerHTML = txt;
				document.getElementById('result_str').style.visibility = 'visible';
			}
			else {
				document.getElementById('result_str').innerHTML = '';
				document.getElementById('result_str').style.visibility = 'hidden';
				show_div = 0;
			}
		}
	}

	req.caching = false;
	req.open('GET', 'ajax_search.php', true);
	req.send({quest: query});
}

var timeout = null;
function doLoadSearch() {
	if (document.getElementById('substring_id').value != '') {
		if (timeout) clearTimeout(timeout);
			timeout = setTimeout(LoadSearchAjax, 200);
	}
}

function checkResults() { if(show_div == 0) { document.getElementById('result_str').style.visibility = 'hidden'; } }

function setShowDiv(num) { show_div = num; }

/* xCartmod.com - AJAX Search Results */
