// JavaScript Document

<!--
  var xmlhttp
	var numRows = 0
	
	function loadXMLDoc(e,url,searchString) {
		if (searchString != '' && e.keyCode != 38 && e.keyCode != 40 && e.keyCode != 13) {
			xmlhttp=null
			xmlhttp = (window.XMLHttpRequest)? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ;
			if (xmlhttp!=null) {
				xmlhttp.onreadystatechange=onResponse
				xmlhttp.open("GET",url+searchString,true)
				xmlhttp.send(null)
			} else {
				alert("Your browser does not support XMLHTTP.")
			}
		}
	}
	
	function checkReadyState() {
		if (xmlhttp.readyState==4) {
		  // if "OK"
		  if (xmlhttp.status==200) {
				return true
			} else {
		    return false
			}
		} else {
			return false
		}
	}

	function onResponse() {
		var loaded = checkReadyState()
		
	  if (loaded) {
		  var response = xmlhttp.responseXML.documentElement;

			if (response != null) {
				var txt = '<table id="tblVeje" width="248" cellpadding="0" cellspacing="2" border="0" style="background-color:#ffffff;">'
				var x = response.getElementsByTagName("vej")
				var i
				for (i=0 ; i < x.length ; i++) {
					txt += '<tr>'
					xx = x[i].getElementsByTagName("navn")
					yy = x[i].getElementsByTagName("postnummer")
					try {
						txt += '<td width="248" valign="top" onclick="javascript:selectStreet(\'' + i + '\')" style="cursor:pointer; background-color:#ffffff;" id="td_' + i + '" onmouseover="rowOver(' + i + ')">' + xx[0].firstChild.data + ', ' + yy[0].firstChild.data + '</td>'
					}
					catch (er) {
						txt += '<td> </td>'
					}
					txt += '</tr>'
				}
				
				numRows = i
				
				txt += '</table>'
			
				xmlhttp=null
				document.getElementById('xmldiv').style.visibility = "visible"
			  document.getElementById('xmldiv').innerHTML = txt
				
				rowOver(0)
				
			}
	  }
	}

	var prevRow = 0 

	function rowOver(rowId) {
		if (document.getElementById("td_" + prevRow)) {
			document.getElementById("td_" + prevRow).style.backgroundColor = "#FFFFFF";
			document.getElementById("td_" + prevRow).style.color = "#000000";
		}
		if (document.getElementById("td_" + rowId)) {
			document.getElementById("td_" + rowId).style.backgroundColor = "#227F4F";
			document.getElementById("td_" + rowId).style.color = "#ffffff";
		}
		prevRow = rowId
	}
	
	function scrollSelection(e) {
		var tempRow = 0
		//document.getElementById("alertdiv").innerHTML = numRows 
		var divHeight = 135
		
		if (e.keyCode == 40) {
			if (prevRow >= numRows - 1) {
				tempRow = numRows - 1
			} else {
				tempRow = prevRow + 1
				if ((tempRow * 15) > divHeight + xmldiv.scrollTop) {
					xmldiv.scrollTop = (tempRow * 15) - divHeight
					//document.getElementById("alertdiv").innerHTML = xmldiv.scrollTop 
				}
			}
			rowOver(tempRow)
		} else if (e.keyCode == 38) {
			if (prevRow > 0) {
				tempRow = prevRow - 1
				
				if ((tempRow * 15) < xmldiv.scrollTop) {
					xmldiv.scrollTop = (tempRow * 15)
					//document.getElementById("alertdiv").innerHTML = xmldiv.scrollTop 
				}
			}
			rowOver(tempRow)
		} else if (e.keyCode == 13) {
			selectStreet(prevRow)
		}
	}
	
	function selectStreet(id) {
		document.getElementById('vejnavn').value = document.getElementById("td_" + id).innerHTML
		document.getElementById('xmldiv').style.visibility = "hidden"
	}
	
	function hideStreets() {
		var t = setTimeout("swapText()", 500)
	}

	/*
	function hideDiv() {
		document.getElementById('xmldiv').style.visibility = "hidden"
	}
	*/

  //-->
