var objDiv,objQ;
var ix=0;
var intTop;
var intLeft;
var formLeft;
var	formTop;
var move=false;
function makeXMLobj(){
	var xmlHttp = false;
	if (typeof(XMLHttpRequest) != 'undefined') {
    xmlHttp = new XMLHttpRequest();
	}
	if (!xmlHttp) {
	    try {
	        xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch(e) {
	        try {
	            xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
	        } catch(e) {
	            xmlHttp  = false;
	        }
	    }
	}
	return xmlHttp;
}
function getXML(strURL){
	document.onkeyup = notMove;
	if(!move){
	writeText("Daten werden geladen..");
	var strResult;
	xmlHttp = makeXMLobj();
	if (xmlHttp) {
		strURL = strURL.replace(/ü/g,"[u]")
		strURL = strURL.replace(/ä/g,"[a]")
		strURL = strURL.replace(/ö/g,"[o]")
	    xmlHttp.open('GET', strURL, true);
	    xmlHttp.setRequestHeader("Pragma", "no-cache");
	    xmlHttp.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-1"); 
	    xmlHttp.onreadystatechange = function () {
	        if (xmlHttp.readyState == 4) {
	            strResult = xmlHttp.responseText;
				if (strResult!=""){
					writeResult(strResult);
				}else{
					writeText("Es konnten keine zugehörigen Daten ermittelt werden.");
				}
	        }
		};
	    xmlHttp.send(null);
	}else{
		writeText("Bitte aktivieren Sie ActiveX.");
	}
	return strResult;
	}
}
function searchhelp(tq,strlocation,country) {
	objQ = tq;
	var q = objQ.value;
	formLeft = getAbsPos(objQ,"Left");
	formTop = getAbsPos(objQ,"Top")+20;
	if(q!=""){
	if (q.length > 2){
	var strURL = "/xml/orte2.htm?region="+strlocation+"&land=" +country+"&suchstr=" +q;
	var strResult = getXML(strURL);
	}
	}
}
function makeDIV(){
	objDiv=document.createElement("DIV");
	objDiv.id="divErg" + objQ.id
	objDiv.style.zIndex="1";
	objDiv.style.padding="0";
	objDiv.style.position="absolute";
	objDiv.style.top=formTop+"px";
	objDiv.style.left=formLeft+"px";
	objDiv.style.height="200px";
	objDiv.style.minwidth="200px";
	objDiv.style.overflow="auto";
	objDiv.style.backgroundColor="white";
	objDiv.style.border="1px solid black"; 
	objDiv.style.display="block";
	document.body.appendChild(objDiv);
	
}
function writeText(strtext){
	if (!objDiv) makeDIV();
	while(objDiv.childNodes.length>0)
	objDiv.removeChild(objDiv.childNodes[0]);
	
	objSpan=document.createElement("div");
	objSpan.style.display="block";
	objSpan.style.margin="0px";
	objSpan.style.width="295px";
	objDiv.appendChild(objSpan)
	objSpan.innerHTML="";
	objSpan=document.createElement("div");
	objSpan.style.display="block";
	objSpan.style.margin="0px";
	objSpan.style.width="295px";
	objDiv.appendChild(objSpan)
	objSpan.innerHTML="";
	
	objSpan=document.createElement("div");
	objSpan.style.display="block";
	objSpan.style.margin="0px";
	objSpan.style.width="295px";
	objDiv.appendChild(objSpan)
	objSpan.innerHTML=strtext;
}
function writeResult(strResult){
	if (!objDiv) makeDIV();
	while(objDiv.childNodes.length>0)
	objDiv.removeChild(objDiv.childNodes[0]);
	var arrResult = strResult.split("<br />");
	if (arrResult.length > 1){
		objDiv.style.display="block";
	}
	ix = 0;
	objSpan=document.createElement("div");
	objSpan.style.display="block";
	objSpan.style.margin="0px";
	objSpan.style.width="295px";
	objSpan.onmouseover = selectMouseRecord;
	objSpan.onmouseout = deselectMouseRecord;
	objSpan.onmousedown = returnMouseValue;
	objDiv.appendChild(objSpan)
	objSpan.innerHTML="keine Auswahl";
	for(i=0; i < arrResult.length; i++) {
		objSpan=document.createElement("div");
		objSpan.style.display="block";
		objSpan.style.margin="0px";
		objSpan.style.width="295px";
		objSpan.onmouseover = selectMouseRecord;
		objSpan.onmouseout = deselectMouseRecord;
		objSpan.onmousedown = returnMouseValue;
		objDiv.appendChild(objSpan)
		objSpan.innerHTML=arrResult[i];
	}
}
function moveDown(){
	document.onkeydown = checkKeyCode;
}
function checkKeyCode(Ereignis) {
	if(navigator.appName == "Netscape"){
		strKey = Ereignis.which;
	}else{
		strKey = window.event.keyCode;
	}
	
	if(strKey==40){
		move = true;
		if (ix>=0)deselectRecord();
		ix++;
		selectRecord();
		
	}else if(strKey==38){
		move = true;
		deselectRecord();
		ix--;
		selectRecord();
	}else if(strKey==13 || strKey==9) {
		closeDD2();
		
	}
	
}
function notMove(Ereignis){
	if(navigator.appName == "Netscape"){
		strKey = Ereignis.which;
	}else{
		strKey = window.event.keyCode;
	}
	if(strKey==40||strKey==38){
		move = true;
	}else{
		move = false;
	}
}

function selectRecord() {
	objSpan = objDiv.childNodes[ix]
	objSpan.style.backgroundColor="#ececec";
	returnValue(objSpan.innerHTML);
	//objSpan.focus();
	
}
function selectMouseRecord() {
	objSpan = this;
	objSpan.style.backgroundColor="#ececec";
	//returnValue(objSpan.innerHTML);
}
function deselectRecord() {
	objSpan = objDiv.childNodes[ix]
	objSpan.style.backgroundColor="#ffffff";
	objSpan.focus();
}
function deselectMouseRecord() {
	objSpan = this;
	objSpan.style.backgroundColor="#ffffff";
	objSpan.focus();
}
function getAbsPos(obj,typ){
	count=0;
	while(obj!=null){
		count=count+obj["offset"+typ];
		obj=obj.offsetParent;}
		return count;	
}
function returnValue(strValue) {
	strValue = strValue.replace(/&nbsp;/g, " ");
	strValue = strValue.replace(/&nbsp;/g, " ");
	strValue = strValue.replace(/&szlig;/g, "ß");
	//strValue = strValue.replace(/&uuml;/, "ü");
	//strValue = strValue.replace(/&auml;/, "ä");
	//strValue = strValue.replace(/&ouml;/, "ö");
	//strValue = strValue.replace(/&Uuml;/, "Ü");
	//strValue = strValue.replace(/&Auml;/, "Ä");
	//strValue = strValue.replace(/&Ouml;/, "Ö");
	objQ.value = strValue;
}
function returnMouseValue() {
	objSpan = this;
	var strValue = objSpan.innerHTML;
	strValue = strValue.replace(/&nbsp;/g, " ");
	strValue = strValue.replace(/&nbsp;/g, " ");
	strValue = strValue.replace(/&szlig;/g, "ß");
	//strValue = strValue.replace(/"&uuml;"/, "ü");
	//strValue = strValue.replace(/"&auml;"/, "ä");
	//strValue = strValue.replace(/"&ouml;"/, "ö");
	//strValue = strValue.replace(/"&Uuml;"/, "Ü");
	//strValue = strValue.replace(/"&Auml;"/, "Ä");
	//strValue = strValue.replace(/"&Ouml;"/, "Ö");
	objQ.value = strValue;
	closeDD();
}
function closeDD(){
	document.body.removeChild(objDiv);
	objDiv = '';
}
function closeDD2() {
    var Ergebnis = false;
    if (objQ) {
        var strValue = objQ.value;
        var Suche = /^(\d\d\d\d\d).+\B/;
        Ergebnis = Suche.test(strValue);
    }
    if (Ergebnis != false) {
        if (objDiv) {
            document.body.removeChild(objDiv);
            objDiv = '';
        }
	}else{
		if (objDiv) {
		objSpan = objDiv.childNodes[1]
		
		if(objSpan.innerHTML!=""){
			returnValue(objSpan.innerHTML);
			document.body.removeChild(objDiv);
			objDiv = '';
		}else{
			if(strValue!='')writeText("<span class='err'>Es konnten keine zugehörigen Daten ermittelt werden oder Ihre Eingabe ist nicht eindeutig. <br <br>Bitte überprüfen Sie die Eingabe.</span>");
			document.body.removeChild(objDiv);
			objDiv = '';
		}
		}
	}	
}