//var objHttp = getHTTPObject();

	var httpobj;
	var query;
	var newdiv;
	var boxname;
	var hiddenFieldName;
	var fieldName;
	var completed;
	
	// no comment, gewoon gekopiert
	function getHTTPObject() {
		var xmlhttp;
		try
    	{
        	// Firefox, Opera 8.0+, Safari
        	xmlhttp=new XMLHttpRequest();
    	}
    	catch (e)
    	{
    	    // Internet Explorer
    	    try
    	    {
    	        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    	    }
    	    catch (e)
    	    {
    	        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	    }
    	}
   	  return xmlhttp;
	}
			

	
	function ucfirst(string){
	    var first = string.charAt(0).toUpperCase();
	    return first + string.substr(1, string.length-1);
	}
	function trim(string){
		return trimmed = string.replace(/^\s+|\s+$/g, '') ;
	}
	function clearChildren(el){
		while(el.childNodes.length > 0)
		el.removeChild(el.childNodes[0]);
	}
	
	function setQuery(temp, box, hiddenField, field, popup, popupblank){
		popupDiv = popup;
		popupblanket = popupblank;
		hiddenFieldName = hiddenField;
		boxname = box;
		fieldName = field;
		//alert(hiddenFieldName + fieldName);
		temp = trim(temp);
		if(temp != ""){
			clearList();
			query = temp;
			getObjects();	
		}else{
			clearList();
		}
	}	
	function clearList(){
		div = document.getElementById(boxname);
		while ( div.hasChildNodes() ) { div.removeChild(div.firstChild); }	
			div.className="resultsBorderless";
			var hidden=document.getElementById(hiddenFieldName);
			hidden.value="";
		}	
	function click(id, name){
		clearList();
		var complete=document.getElementById(fieldName);
		complete.value=name;
		var hidden=document.getElementById(hiddenFieldName);
		hidden.value=id;
		//alert("field: " + fieldName + " value: " + name);
		var search=document.getElementById('search');
		search.value="";
	}
	function getObjects(){
		completed = false;
		//alert(query + "-" + hiddenFieldName  + "-" + fieldName + "-" + boxname );
		httpobj = getHTTPObject();
		//alert(httpobj.readyState);
		httpobj.open("GET", '../autofill.php?a=' + query, true);
		httpobj.onreadystatechange = handleGetObjects;
		
		httpobj.send(null);
	}
	
	function handleGetObjects(){
		//alert(httpobj.readyState);
		if (httpobj.readyState == 4 && !completed) {
			//alert("ready state 4");
			completed = true;
			var auto = document.getElementById(boxname);
			auto.className="results";
			//var xmldoc = httpobj.responseXML;
			try { var xmldoc = httpobj.responseXML; } catch(e) { alert(e); }
			var message_nodes = xmldoc.getElementsByTagName("domein"); 
			var n_messages = message_nodes.length;
			//create the array used by the search function
			for (i = 0; i < n_messages; i++) {
				var id_node = message_nodes[i].getElementsByTagName("id");
				var name_node = message_nodes[i].getElementsByTagName("name");
				//alert("in loop" + i);
				newdiv = document.createElement('div');
				newdiv.setAttribute('id',id_node[0].firstChild.nodeValue);
				newdiv.setAttribute('onMouseOver',"this.className='SubHover'");
				newdiv.setAttribute('onMouseOut',"this.className='Sub'");
				newdiv.setAttribute('onClick',"click(" + id_node[0].firstChild.nodeValue + ",'" + (name_node[0].firstChild.nodeValue) + "'); popup('"+popupDiv+"','"+popupblanket+"');");
				newdiv.className="Sub";
				newdiv.innerHTML=(name_node[0].firstChild.nodeValue);
				auto.appendChild(newdiv);

				auto.scrollTop = auto.scrollHeight;

			}
			if(n_messages < 1){clearList();}
					
		}
	}
	function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar, blanket) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById(blanket);
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	//popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	popUpDiv_height=150;
	popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-150;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}
function popup(windowname, blanket) {
	blanket_size(windowname, blanket);
	window_pos(windowname);
	toggle(blanket);
	toggle(windowname);		
}
function deleteLink(hiddenField, field){
	var clearName=document.getElementById(field);
	var clearID=document.getElementById(hiddenField);
	clearName.value="";
	clearID.value="";
}