//
//  .biz Search Complete
//
//  by Dave May
//

var biz_search_complete_current;

var biz_search_complete_xml;

function search_complete(ob)
{

	var cval = ob.value;

	if (biz_search_complete_current == cval) return;

	biz_search_complete_current = cval;

	if (cval == '') return search_complete_clear();

	var ef = encodeURIComponent || escape;

	try { req = new XMLHttpRequest(); } catch(e) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { req = new ActiveXObject("Microsoft.XMLHTTP"); } }
	req.onreadystatechange = function()
		{
			if (req.readyState == 4 && req.status == 200 && cval == biz_search_complete_current)
			{
				cobox = document.getElementById('biz_search_key_complete');
				search_complete_display(ob, cobox, req.responseXML);
			}
		}
	req.open('GET', '/search_complete.amp?key=' + ef(cval), true);
	req.send(null);
}

function search_complete_display(ob, cobox, xml)
{
	var root = xml.documentElement;
	if (root)
	{
		var key_list = xml.getElementsByTagName('key');
		var n = key_list.length;
		if (n > 0)
		{
      	 		cobox.style.display = 'block';
			cobox.style.zIndex = 1000;
			var h = '';
			for (var m = 0; m < n; m++)
			{
				var u = key_list[m].getAttribute('url');
				var col = key_list[m].getAttribute('color');
				var img = key_list[m].getAttribute('image');
				if (!img){var img = "/images/blank.gif"}
				if (h != '')
					h += "<IMG SRC=\"/images/blank.gif\" WIDTH=100% HEIGHT=1 STYLE=\"background-color: #22B24B;\"><BR>"

				if (u)
				{
					h += "<DIV STYLE=\"cursor: pointer; width: 278px; height: 24px; padding: 4px; overflow: hidden;"
						+ (col ? " color: " + col + ";" : "") + "\""
						+ " ONMOUSEOVER=\"this.style.backgroundColor = '#FFFFFF';\""
						+ " ONMOUSEOUT=\"this.style.backgroundColor = '#EEEEEE';\""
						+ " ONMOUSEDOWN=\"location.href = '" + u + "';\">" + "<IMG SRC=\"" + img + "\" ALIGN=ABSMIDDLE>&nbsp;&nbsp;" + key_list[m].firstChild.nodeValue + "</DIV>";
				}
				else
				{
					h += "<DIV STYLE=\"cursor: pointer; width: 278px; height: 24px; padding: 4px; overflow: hidden;\""
						+ " ONMOUSEOVER=\"this.style.backgroundColor = '#FFFFFF';\""
						+ " ONMOUSEOUT=\"this.style.backgroundColor = '#EEEEEE';\""
						+ " ONMOUSEDOWN=\"document.getElementById('biz_search_key').value = this.innerText; document.getElementById('biz_search_form').submit();\">" + key_list[m].firstChild.nodeValue + "</DIV>";
				}
			}
			cobox.innerHTML = h;
			return;
		}
	}

	return search_complete_clear();
}

function search_complete_clear()
{
	biz_search_complete_current = null;
	cobox = document.getElementById('biz_search_key_complete');
	cobox.style.display = 'none';
	cobox.innerHTML = '';
}
