// JavaScript Document

function searchBoxChanged() {
	
	if (document.getElementById("zoekwaarde").value=="" || document.getElementById("zoekwaarde").value.length < 3) {
		document.getElementById("div-resultscontainer").innerHTML = "";
	} else {
		xmlhttp = getXmlHttpObject();
		if (xmlhttp == null) {
			alert("Unable to build dynamic menu. Check browser scripting restrictions...");
			return;
		}	
		var term
		term = document.getElementById("zoekwaarde").value;
		var url = "ajx/ajx_zoeksuggesties.asp?zoekterm=" + term;
		xmlhttp.onreadystatechange=populateSearchBox;
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
	}
}

function populateSearchBox() {
	
	var divinhoud = "";
	
	
	if(xmlhttp.readyState == 4) {
		
		//check browsertype IE of Moz
		var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined');
		
		if (moz) {			
			var xmlDoc = xmlhttp.responseXML.getElementsByTagName("zoekres");
			var myRes = xmlDoc[0].getElementsByTagName("zoekItem");
			
			if (myRes.length > 0) {			
				var aantallijnen = myRes.length;			
				//divinhoud = "<div id='test' onMouseOut='document.getElementById(\"div-resultscontainer\").innerHTML = \"\";'>";
				for (i=0; i<aantallijnen; i++) {
					divinhoud = divinhoud + "<div id='result-2'><a href='method.asp?id=" + myRes[i].childNodes[3].firstChild.nodeValue + "'>" + myRes[i].childNodes[1].firstChild.nodeValue + "</a></div>";				
				}
				//divinhoud = divinhoud + "</div>";
			} 
		}
		else 
		{
			var xmlDoc = xmlhttp.responseXML.documentElement;
			
			if (xmlDoc.hasChildNodes()==true) {
				var aantallijnen = xmlDoc.childNodes.length;
				//divinhoud = "<div id='test' onMouseOut='document.getElementById(\"div-resultscontainer\").innerHTML = \"\";'>";
				for (i=0; i<aantallijnen; i++) {
					divinhoud = divinhoud + "<div id='result-2'><a href='method.asp?id=" + xmlDoc.childNodes[i].getElementsByTagName("methId")[0].firstChild.text + "'>" + xmlDoc.childNodes[i].getElementsByTagName("methOms")[0].firstChild.text + "</a></div>";
				}
				//divinhoud = divinhoud + "</div>";
			}			
		}						
	}
		
divinhoud = divinhoud + "<div id='result'><p class='result'>Niet gevonden wat u zocht?<br /><a href='klantenservice.asp'>Contacteer onze klantenservice</a><br /><br />";
divinhoud = divinhoud + "<a href='search.asp'>Uitgebreid zoeken</a></p></div>";

document.getElementById("div-resultscontainer").innerHTML = divinhoud;
}


