var globalAutoCompFID = "";
var globalAutoCompDistanceX = 0;
var globalAutoCompDistanceY = 16;

/*
if (document.attachEvent) 
	window.attachEvent("onresize", auCoOnResize);
else if	(document.addEventListener)
	window.addEventListener("resize", auCoOnResize, false);

function auCoOnResize(){
    var ObjID = ''
    if ()
	var div = ge("div_AutoCompletion"+AutoCompObjName);
	var refEl = ge(globalAutoCompFID);
	if (div){
		if (div.display = 'block'){
			div.style.left = getLeft(refEl) + globalAutoCompDistanceX;
			div.style.top = getTop(refEl) + globalAutoCompDistanceY;
		}
	}
}
*/
var globalAutoCompFID = "";
var globalAutoCompDistanceX = 0;
var globalAutoCompDistanceY = 16;
var globalAutoCompIsOpen = false;

function AutoCompletion(sID) {
    var AutoCompObjName = "";
    var AutoCompFID = "";
    var AutoCompWidth = 0;
    var AutoCompStillAlive = false;
    var AutoCompKC = null;
    var AutoCompUrl = "";
    var AutoCompColWidth = 0;
    var AutoCompColWidthSum;
    var AutoCompColName;
    var AutoCompColAlign;
    var AutoCompRowText = "";
    var AutoCompRowHeight = 0;
    var AutoCompColText = 0;
    var AutoCompRowCount = 0;
    var AutoCompClassSelectRow = "ac_rowSelect";
    var AutoCompClassRow = "ac_row";
    var AutoCompClassTbl = "ac_tb";
    var AutoCompMaxHeight = 0;
    var AutoCompMaxWidth = 0;
    var AutoCompMaxRows = 0;
    var AutoCompDiv;
    var AutoCompDistanceY = 16;
    var AutoCompDistanceX = 0;
    var AutoCompSBarWidth = 20;
    var AutoCompColDiff = 0;
    var AutoCompShowAll = true;
    var AutoCompWriteAllRow = true; 
    var AutoCompMaxRowCount = 20;
    var AutoCompColValue = 0;
    var AutoCompSumRowHeight = 0;
    var AutoCompColSpan = 0;
    var AutoCompSuppress = false;
    var AutoCompSelectedCol = 0;
    var AutoCompReset = true;
    var AutoCompIsOpen = false;
    var AutoCompNoKeyUpDown = false;
    var AutoCompHiddenFields;
    var AutoCompHiddenFieldsOK = false;
    var AutoCompMarkTxt = false;
    var AutoCompSelectFirstEntry = true;

    this.AutoCompTextAllEntry = "Alle Einträge anzeigen"
    
    var _self = this;
    var _AutoCompID = '';
    if (typeof(sID) != 'undefined')
        _AutoCompID = sID;
    
    //#### Propertys ####
    
    this.pSearchType = 0; 
    
    this.setSelectFirstEntry = function(sVal){
        AutoCompSelectFirstEntry = sVal;
    }
    
	this.setObjName = function(sVal){
        AutoCompObjName = sVal;
    }
	
	this.setRefID = function(sVal){
        AutoCompFID = sVal;
        globalAutoCompFID = sVal;
    }
	this.getRefID = function(){
        return AutoCompFID;
    }
    
	this.setColText = function(sVal){
        AutoCompColText = sVal;
    }
	
	this.setColValue = function(sVal){
        AutoCompColValue = sVal;
    }
	
	this.setDistanceY = function(sVal){
        AutoCompDistanceY = sVal;
        globalAutoCompDistanceY = sVal;
    }
    
	this.setDistanceX = function(sVal){
        AutoCompDistanceX = sVal;
        globalAutoCompDistanceX = sVal;
    }
    
	this.setRowHeight = function(sVal){
        AutoCompRowHeight = sVal;
    }
	
	this.setAutoCompMaxRowCount = function(sVal){
	    AutoCompMaxRowCount = sVal;
	}
	this.getAutoCompMaxRowCount = function(){
	    return AutoCompMaxRowCount;
	}
	
	this.setAutoCompSuppress = function(sVal){
	    AutoCompSuppress = sVal;
	}
	this.getAutoCompSuppress = function(){
	    return AutoCompSuppress;
	}
	
    this.onStillAlive = function(sVal){
        AutoCompStillAlive = sVal;
    }
    
	this.setColDiff = function(sVal){
        AutoCompColDiff= sVal;
    }
	
	this.setMaxRows = function(sVal){
        AutoCompMaxRows = sVal;
    }
	
	this.setClassSelectRow = function(sVal){
        AutoCompClassSelectRow = sVal;
    }
	
	this.setClassRow = function(sVal){
        AutoCompClassRow = sVal;
    }
	
	this.setClassTable = function(sVal){
        AutoCompClassTbl = sVal;
    }
	
    this.setAutoCompUrl = function(sVal){
        AutoCompUrl = sVal;
    }
    
    this.setNoKeyUpDown = function(sVal){
        AutoCompNoKeyUpDown = sVal;
    }
    
    this.setReset = function (sVal){
		AutoCompReset = sVal; 
	}
	this.setMarkTxt = function (sVal){
		AutoCompMarkTxt = sVal; 
	}
	
	this.setHiddenFields = function (sVal){
	    if (sVal.length > 0){
	        AutoCompHiddenFields = new Array();
	        var Arr = sVal.split(";")
			for (var i=0; i<Arr.length;i++)
				AutoCompHiddenFields.push(Arr[i]);
		    AutoCompHiddenFieldsOK = true;
		}
	}
	
    this.setShowAll = function(sVal){
		AutoCompSuppress = sVal;
		if (ge(AutoCompFID))
		    ge(AutoCompFID).focus();
		this.showAllAutoComp(sVal);
	}
    
    //#### Methoden ####
    
    this.reset = function (){
		AutoCompRowText = "";
		AutoCompRowCount = 0;
		AutoCompShowAll = true;
		AutoCompWriteAllRow = true; 
	}
    
    this.clear = function(){
		AutoCompRowCount = 0;
        AutoCompRowText = "";
    }
    
    this.isOpen = function(){
	    return AutoCompIsOpen;
	}
    
	this.addColWidth = function(sVal){
		if (AutoCompShowAll){
			AutoCompColWidth = new Array();
			sVal += ";"
			var lOk = false;
			var Arr = sVal.split(";")
			var Str = "";
			for (var i=0; i<Arr.length;i++){
				AutoCompColWidth.push(Arr[i]);
				/*if (!lOk && Number(AutoCompColWidth[i])!='NaN' && AutoCompColWidth[i] > 3){
		            AutoCompColWidth[i] = parseInt(AutoCompColWidth[i])-3;
		            lOk = true;
		        }*/
			}
		}
	}
	
	this.addRowWidth = function(sVal){ //muss entfernt werden, wenn die abhängigen Komponenten angepasst sind
		if (AutoCompShowAll){
			AutoCompColWidth = new Array();
			sVal += ";"
			var Arr = sVal.split(";")
			var Str = "";
			for (var i=0; i<Arr.length;i++)
				AutoCompColWidth.push(Arr[i]);
		    
		}
	}
	
	this.addColName = function(sVal){
		if (AutoCompShowAll){
			AutoCompColName = new Array();
			sVal += ";"
			var Arr = sVal.split(";")
			var Str = "";
			for (var i=0; i<Arr.length;i++){
				//alert(Arr[i])
				AutoCompColName.push(Arr[i]);
				
			}
		}
	}
	
	this.addRowName = function(sVal){ //muss entfernt werden, wenn die abhängigen Komponenten angepasst sind
		if (AutoCompShowAll){
			AutoCompColName = new Array();
			sVal += ";"
			var Arr = sVal.split(";")
			var Str = "";
			for (var i=0; i<Arr.length;i++){
				//alert(Arr[i])
				AutoCompColName.push(Arr[i]);
				
			}
		}
	}
	
	this.addColAlign = function(sVal){
		if (AutoCompShowAll){
			AutoCompColAlign = new Array();
			sVal += ";"
			var Arr = sVal.split(";")
			var Str = "";
			for (var i=0; i<Arr.length;i++)
				AutoCompColAlign.push(Arr[i]);
		}
	}
	
	this.addRowAlign = function(sVal){ //muss entfernt werden, wenn die abhängigen Komponenten angepasst sind
		if (AutoCompShowAll){
			AutoCompColAlign = new Array();
			sVal += ";"
			var Arr = sVal.split(";")
			var Str = "";
			for (var i=0; i<Arr.length;i++)
				AutoCompColAlign.push(Arr[i]);
		}
	}
	
	this.init = function (sVal){
		this.setRefID(sVal);
		this.createDiv();
	}
	
	this.createDiv = function(){
		var html = '';
		var div;
		//html =  '<table cellpadding=0 cellspacing=0 border=0 class="'+AutoCompClassTbl+'">'
		//html += '<tr><td id="td_AutoCompletion" class="ac_row"></td></tr></table>'
		
		div = document.createElement('DIV');
		div.id = 'div_AutoCompletion'+AutoCompObjName; 
		div.style['position'] = 'absolute';
		div.style['display'] = 'none';
		div.style['zIndex'] = '2000'
		div.className = 'ac_tb bgWhite';
		
		div.innerHTML = html;
		
		AutoCompDiv = document.body.appendChild(div);
		//AutoCompDiv = ge("ssuForm").appendChild(div);
	}
	
	function checkPartOf(sVal){
	    var lText = sVal;
	    
	    if (AutoCompMarkTxt){
	        var lRefObj = ge(AutoCompFID);
	        if (lRefObj){
	            var lRefObjText = lRefObj.value;
	            lText = ftMarkName(lText,lRefObjText);
	        }
	    }
	    
	    return lText;
	}
	
	this.addRow = function(sVal){
		var colText = "";
		var colWidth = 0;
		var colSpan = 0;
		var selectColClass = AutoCompClassSelectRow;
		var colAlign = "";
		var colCount = 0;
		
		if ((AutoCompRowCount < AutoCompMaxRowCount) || (AutoCompSuppress)){
			AutoCompColSpan = 0;
			AutoCompColWidthSum = 0;
			// Spalten schreiben
		    for (var i=0; i<AutoCompColWidth.length;i++){
			    colWidth = 0;
			    if (AutoCompColWidth[i]!='')
				    colWidth = parseInt(AutoCompColWidth[i]);
			    if (AutoCompColAlign[i]!='')
				    colAlign = AutoCompColAlign[i];
			    AutoCompColWidthSum += colWidth
			    if (colWidth > 0){
					colText += '<div class="ac_col" id="c_'+i+'_'+AutoCompRowCount+AutoCompObjName+'" style="overflow:hidden;width:'+AutoCompColWidth[i]+'px">'
					if (!AutoCompMarkTxt)
					    colText += '<nobr>&nbsp;'+AutoCompColName[i]+'</nobr>'
					else
					    colText += '<nobr>&nbsp;'+checkPartOf(AutoCompColName[i])+'</nobr>'
					colText += '</div>'
			    }
		    }
		    
			
			//Zeilen Schreiben
			AutoCompRowText += '<div'
			if (AutoCompRowCount == 0)
				AutoCompRowText += ' class="'+selectColClass+'"'
			AutoCompRowText += ' id="ac_row_'+AutoCompRowCount+AutoCompObjName+'" style="cursor:pointer;height:'
			if (AutoCompRowCount == 0)
			    AutoCompRowText += AutoCompRowHeight;
			else
			    AutoCompRowText += AutoCompRowHeight+1;
			    
			AutoCompRowText += 'px;" title="'+AutoCompColName[AutoCompColText]+'" rowBez="'+AutoCompColName[AutoCompColText]+'" rowVal="'+AutoCompColName[AutoCompColValue]+'" onclick="'+AutoCompObjName+'.onClickAuCo(\''+AutoCompColName[AutoCompColText]+'\',\'' + AutoCompColName[AutoCompColValue] + '\');'+AutoCompObjName+'.onFrmSubmit();'+AutoCompObjName+'.onCloseAuCo();" onmouseover="'+AutoCompObjName+'.setRowClassNameAuCo(this.id)" onmouseout="'+AutoCompObjName+'.onStillAlive(false)">';
			//AutoCompRowText += '<nobr>' + colText + '</nobr>';
			AutoCompRowText += colText;
			AutoCompRowText += '</div>';
			AutoCompRowCount += 1
			AutoCompSumRowHeight = AutoCompRowCount * AutoCompRowHeight;
		}
		else{
			AutoCompShowAll = false;
		}
		// Zeile alle Einträge anzeigen
		if ((!AutoCompShowAll) && (AutoCompWriteAllRow)){
			AutoCompRowText += '<div style="height:'+(AutoCompRowHeight-1)+'px;">'
			AutoCompRowText += '<div id="ac_row_all_'+AutoCompRowCount+AutoCompObjName+'" class="ac_BTop" style="cursor:pointer;height:'+(AutoCompRowHeight-1)+'px;padding-left:3px;" onclick="'+AutoCompObjName+'.setShowAll(true)"><b>'+this.AutoCompTextAllEntry+'</div>'
			AutoCompRowText += '</div>';
			AutoCompWriteAllRow = false;
		}
		
	}
	
    this.onClickAuCo = function(sText, sVal){
        
        var elAutoComp = ge(AutoCompFID);
        if (_self.pSearchType == 1)
            elAutoComp.value = sText;
		elAutoComp.focus();
        AutoCompStillAlive = false;
		this.setAutoCompValue(sVal);
    }
	
	this.setCol_0 = function(sVal){
		var temp;
		
		for (var i=0; i<AutoCompRowCount;i++){
			if (ge("c_"+AutoCompColDiff+"_"+i+AutoCompObjName)){
				temp = parseInt(ge("c_"+AutoCompColDiff+"_"+i+AutoCompObjName).style.width);
				temp = temp - sVal;
				ge("c_"+AutoCompColDiff+"_"+i+AutoCompObjName).style.width = temp + "px";
			}
		}
	}
	
	this.setSelectedRow = function(sVal){
	    var divAutoComp = ge("div_AutoCompletion"+AutoCompObjName);
	    var elAutoComp = ge(AutoCompFID);
		if (ge("ac_row_"+sVal+AutoCompObjName) || ge("ac_row_all_"+sVal+AutoCompObjName)){
		    if (ge("ac_row_all_"+sVal+AutoCompObjName)){    
			    ge("ac_row_all_"+sVal+AutoCompObjName).scrollIntoView(false);
			}
			else{
			    this.setRowClassNameAuCo("ac_row_"+sVal+AutoCompObjName);
			    ge("ac_row_"+sVal+AutoCompObjName).scrollIntoView(false);
			}

		}
    }
	
	this.showDivAutoComp = function(KC){
		var divAutoComp = ge("div_AutoCompletion"+AutoCompObjName);
		var divScroll = ge("div_ac_erg"+AutoCompObjName);
		var lText = "";
		var lVal = "";
		var lTempCount = AutoCompRowCount;
		//if (AutoCompShowAll)
		//	lTempCount -= 1;
	    
		switch(KC){
			case 13: case 9:
				if (ge("ac_row_"+AutoCompSelectedCol+AutoCompObjName) && AutoCompSelectFirstEntry){
					if (ge("ac_row_"+AutoCompSelectedCol+AutoCompObjName).getAttribute("rowShowAll"))
						this.setShowAll(true);
					else{
					    if (this.isOpen())
						    this.onClickAuCo(ge("ac_row_"+AutoCompSelectedCol+AutoCompObjName).getAttribute("rowBez"), ge("ac_row_"+AutoCompSelectedCol+AutoCompObjName).getAttribute("rowVal"));
					}
					this.onCloseAuCo();
					AutoCompSelectedCol = 0;
				}
				break;
			case 27:
				AutoCompSelectedCol = 0;
				this.onCloseAuCo();
				return false;
				break;
			default:
				if ((KC!=39) && (KC!=37)){
					AutoCompSelectedCol = 0;
					this.onShowDivAutoComp();
				}
				break;
		}
		AutoCompStillAlive = false;
    }
	
	this.onKeyUpDown = function(KC){
	    var divAutoComp = ge("div_AutoCompletion"+AutoCompObjName);
		var divScroll = ge("div_ac_erg"+AutoCompObjName);
		var hidCount = ge("hid_ac_ergCount");
		var lTempCount = 0;
		if (hidCount)
		    lTempCount = hidCount.value;
		
		switch(KC){
	        case 38:
				if (divAutoComp){
					if (AutoCompSelectedCol >= 0){
						AutoCompSelectedCol -= 1;
						if (AutoCompSelectedCol < 0){
							divAutoComp.style.display = "none";
							this.setRowClassNameAuCo("");
					    }
						else{
							this.setSelectedRow(AutoCompSelectedCol);
						}
					}
				}
				break;
			case 40:
				if (divAutoComp){
					if (AutoCompSelectedCol < lTempCount){
						if (AutoCompSelectedCol < 0)
							divAutoComp.style.display = "block";
						AutoCompSelectedCol += 1;
						this.setSelectedRow(AutoCompSelectedCol);
					}
				}
				break;
	    }
	}
	
	this.onShowDivAutoComp = function(){
		if (!ge("div_AutoCompletion"+AutoCompObjName))
			this.createDiv();
        var divAutoComp = ge("div_AutoCompletion"+AutoCompObjName);
        //var tdAutoComp = ge("td_AutoCompletion");
        var elAutoComp = ge(AutoCompFID);
		//elAutoComp.AutoComplete = "off";
		var tblAutoCompText = "";
		var divAutoCompErg = ge("div_ac_erg"+AutoCompObjName);
		//var tblAutoCompErg = ge("tbl_ac_erg");
		//alert(AutoCompRowText)
		
		
		if (parseInt(AutoCompRowCount) > parseInt(AutoCompMaxRows)){
			AutoCompMaxHeight = AutoCompMaxRows * (AutoCompRowHeight+1) - 1;
			AutoCompMaxWidth = AutoCompColWidthSum - AutoCompRowHeight;
		}
        else{
			AutoCompMaxHeight = AutoCompRowCount * (AutoCompRowHeight+1) - 1;
		}
		
		
        if (divAutoComp){
            if (!divAutoCompErg){
                divAutoCompErg = document.createElement("div");
                divAutoCompErg.id = 'div_ac_erg'+AutoCompObjName;
                divAutoCompErg.style.width = AutoCompColWidthSum + 'px';
                divAutoCompErg.style.height = AutoCompMaxHeight + 'px';
                divAutoCompErg.style.overflow = 'auto';
                divAutoCompErg.onmouseover = function(){_self.onStillAlive(true)};
                divAutoCompErg.onmouseout = function(){_self.onStillAlive(false)};
		        divAutoCompErg.onmouseblur = this.onCloseAuCo;
		        divAutoCompErg.innerHTML = AutoCompRowText + '<input type="hidden" id="hid_ac_ergCount" value="'+AutoCompRowCount+'">';
                
                //divAutoComp.innerHTML = tblAutoCompText;
			    divAutoComp.appendChild(divAutoCompErg);
			}
			else{
			    divAutoCompErg.style.width = AutoCompColWidthSum + 'px';
                divAutoCompErg.style.height = AutoCompMaxHeight + 'px';
                divAutoCompErg.style.overflow = 'auto';
			    divAutoCompErg.innerHTML = AutoCompRowText + '<input type="hidden" id="hid_ac_ergCount" value="'+AutoCompRowCount+'">';
			}    
			if (AutoCompRowCount > AutoCompMaxRows)
				this.setCol_0(AutoCompSBarWidth + 4);
				
            divAutoComp.style.width = AutoCompColWidthSum;
            divAutoComp.style.top = getTop(elAutoComp) + AutoCompDistanceY + "px";
            divAutoComp.style.left = getLeft(elAutoComp) + AutoCompDistanceX + "px";
            
            this.HideFields();
            divAutoComp.style.display = "block";
            
        }
        AutoCompIsOpen = true;
        globalAutoCompIsOpen = true;
        if (AutoCompReset) 
            this.reset();
	}
	
	this.HideFields = function(){
	    if (AutoCompHiddenFieldsOK){
	        for (var li=0; li<AutoCompHiddenFields.length;li++){
	            ge(AutoCompHiddenFields[li]).style.display = "none";
	        }
	    }
	}   
	
	this.ShowHiddenFields = function(){
	    if (AutoCompHiddenFieldsOK){
	        for (var li=0; li<AutoCompHiddenFields.length;li++){
	            ge(AutoCompHiddenFields[li]).style.display = "block";
	        }
	    }
	} 
	
    this.onCloseAuCo = function(){
        
        var divAutoComp = ge("div_AutoCompletion"+AutoCompObjName);
        if (!AutoCompStillAlive){
			if(divAutoComp){
				if (divAutoComp.style.display == "block"){
				    var element = ge(AutoCompFID);
		            var temp = element.value;
					element.focus();
					if (document.all)
					    element.value = temp;
				}
				this.ShowHiddenFields();
	            divAutoComp.style.display = "none";
	            this.clear();
				this.afterCloseAutoComp();
				AutoCompIsOpen = false;
				globalAutoCompIsOpen = false;
			}
		}
    }
    
    this.killAuCo = function(){
        var divAutoComp = ge("div_AutoCompletion"+AutoCompObjName);
        divAutoComp.style.display = "none";
    }
    
    this.setRowClassNameAuCo = function(sID){
        //AutoCompStillAlive = true;
        var divAutoComp = ge("div_AutoCompletion"+AutoCompObjName);
	    for(var li=0;li<divAutoComp.getElementsByTagName("div").length;li++){
		    if (divAutoComp.getElementsByTagName("div")[li].id.indexOf("ac_row_")!=-1){
		        if (divAutoComp.getElementsByTagName("div")[li].id.indexOf("ac_row_all")==-1)
		            divAutoComp.getElementsByTagName("div")[li].className = AutoCompClassRow;
		    }
	    }
	    if (ge(sID))
            ge(sID).className = AutoCompClassSelectRow;
    }
    
    this.getSelectedRow = function (){
        var divAutoComp = ge("div_AutoCompletion"+AutoCompObjName);

	    for(var li=0;li<divAutoComp.getElementsByTagName("div").length;li++){
		    if (divAutoComp.getElementsByTagName("div")[li].className == AutoCompClassSelectRow) {
		        this.onClickAuCo(divAutoComp.getElementsByTagName("div")[li].getAttribute("rowbez"),divAutoComp.getElementsByTagName("div")[li].getAttribute("rowval"));
		        break;    
		    }
	    }
    }
    
    this.setAutoCompValue = function(sVal){
	    
    }

    this.afterCloseAutoComp = function(){
        
    }

    this.showAllAutoComp = function(sVal){
        
    }
    
    function getLeft(el) {
	    var xPos = el.offsetLeft;
	    var tempEl = el.offsetParent;

	    xPos = $(el).offset().left;

	    /*while (tempEl != null) {
		    xPos += tempEl.offsetLeft;
		    tempEl = tempEl.offsetParent;
	    }*/
	    return xPos;
    }

    function getTop(el) {
	    var yPos = el.offsetTop;
	    var tempEl = el.offsetParent;
    //	alert(tempEl + '-' + tempEl.style['position']+ '-' +tempEl.id );
	    yPos = $(el).offset().top;

	    /*while (tempEl != null) {
            yPos += tempEl.offsetTop;
		    tempEl = tempEl.offsetParent;
	    }*/
	    return yPos;
    }
}

function ssuComp(){
    var fAcObj = new AutoCompletion();
    var fEvent = null;
    var fRefID = "";
    var fFormID = "";
    var fLasid = "";
    var fGeoSL = "";
    var fRefHiddenID = "";
    var fLandRefID = ""
    var fNoKeyUpDown = true;
    var fMaxRows = 5;
    var fRowHeight = 16;
    var fColValue = 0;
    var fColText = 1;
    var fColDiff = 1;
    var fDistanceX = -1;
    var fDistanceY = 16;
    var fAddColWidth = "0;135";
    var fAddRowAlign = ";";
    var fItemsArr = new Array();
    var fGeoSearch = true;
    var fUrl = "";
    var fPartOf = true;
    var fTextBoxName = "";
    var fRadioName = "";
    var fSelName = "";
    var fHiddenFields = "";
    var fShotInSamePage = false;
    var fGeoSel = false;
    var fRadioArr = new Array();
    var fExterneID = "";
    var fFrmSubmit = false;
    var _self = this;
    var fJson = false;
    var fJsonItemArr = new Array();
    var fJsonReq = false;
    var fTxtChanged = 0;
    var fMinChar = 2;
    var fSearchByKey = false;
    var fReadAllFrmElem = false;
    var fSearchType = 0;
    var fTextBoxtext = "";
    var fOrtArtID = "";
    var fMarkTxt = false;
    var fSelectFirstEntry = true;
    
    var _BufferedVal = '';
    
    
    this.pTxtVal = "";
    this.pRefID = "";
    this.pFormID = "";
    this.pLasid = "";
    this.pGeoSL = "";
    this.pRefHiddenID = "";
    this.pNoKeyUpDown = true;
    this.pMaxRows = 5;
    this.pRowHeight = 16;
    this.pColValue = 0;
    this.pColText = 1;
    this.pColDiff = 1;
    this.pDistanceX = -1;
    this.pDistanceY = 16;
    this.pAddColWidth = "0;135";
    this.pAddRowAlign = ";";
    this.pLandRefID = ""
    this.pGeoSearch = true;
    this.pUrl = "";
    this.pPartOf = false;
    this.pTextBoxName = "RegWert";
    this.pRadioName = "";
    this.pSelName = "RegTyp";
    this.pHiddenFields = ""; 
    this.pShotInSamePage = false;
    this.pGeoSel = false;
    this.pRadioArr = new Array();
    this.pExterneID = "";
    this.pFrmSubmit = false;
    this.pJson = false;
    this.pJsonReq = false;
    this.pTxtChanged = 0;
    this.pMinChar = 2;
    this.pSearchByKey = false;
    this.pReadAllFrmElem = false;
    this.pSearchType = 0;
    this.pTextBoxtext = "";
    this.pOrtArtID = "";
    this.pMarkTxt = false;
    this.pSelectFirstEntry = true;
    
    this.CreateAcObj = function(sObjName){
        fAcObj.setObjName(sObjName);
    }
    
    this.SetOrtsCombo = function(Items){
        var lJson = false;
        var itemsArr = null;

        if (fJson){
            itemsArr = JSON.parse(Items);
            fItemsArr = itemsArr;
	        GenerateDiv(itemsArr, fJson);
        }
        else{
	        itemsArr = Items.getElementsByTagName("ort");
	        fItemsArr = itemsArr;
	        GenerateDiv(itemsArr);
	    }
	    
    }
    
    this.SetItemsCombo = function(Items){
        var lJson = false;
        var itemsArr = null;

        if (fJson){
            itemsArr = JSON.parse(Items);
            fItemsArr = itemsArr;
	        GenerateDiv(itemsArr, fJson);
        }
        else{
	        itemsArr = Items.getElementsByTagName("item");
	        fItemsArr = itemsArr;
	        GenerateDiv(itemsArr);
	    }
    }
        
    this.init = function (){
        var lElem = ge(this.pRefID);
	    if (lElem){
	        var lObj = this;
	        
	        multihandle_append(ge(this.pRefID),"onkeydown",function (e){
                var lSelVal = lObj.SelValue(lObj.pFormID, lObj.pSelName);
                if (lSelVal=='0'){
                    return KeyDigit(e);   
                }
                else{
                     return lObj.handleKeycode(e) ;              
                }
            });
            multihandle_append(ge(this.pRefID),"onblur",function (e){
                lObj.onCloseAuCo();
            });
            multihandle_append(ge(this.pRefID),"onkeyup",function (e){
                lObj.TxtBoxChanged(lElem.value,e);
                lObj.CheckTxtBox(lElem.value);
            });
	    }
    }
    
    function KeyDigit(Ereignis)
	{
	    AllowedChar = new Array(8, 12, 13, 16, 17, 18, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105);
	    //AllowedChar: 48-57="null-neun"
	    //alert(Ereignis.keyCode)
	    ErrorMsg = "Bitte nur Ziffern eingeben!";
	    return CheckKeyCode(Ereignis);
	}
    
    function CheckKeyCode(Ereignis)
	{
	    var CharOK = false;
	    var shiftPressed = Ereignis.shiftKey;
        var altPressed = Ereignis.altKey;
        var ctrlPressed = Ereignis.ctrlKey;
        
	    //if (Ereignis.charCode == 0) //d.h. Navigationstaste unter Netscape, dann OK
		//    return true;
	    // gedrücktes Zeichen einlesen (verschiedene Browser benutzen verschiedene Befehle)
	    if (!Ereignis)
	        Ereignis = window.event;
	    var CurrentChar = Ereignis.keyCode ? Ereignis.keyCode : Ereignis.charCode ? Ereignis.charCode : Ereignis.which;
	    if (CurrentChar > 255) //d.h. Navigationstaste unter Opera, dann OK
		    return true;
		if (CurrentChar == 17 || CurrentChar == 18){
		    return true;
		}
	    if (CurrentChar) 
		    for (var i in AllowedChar) 
			    if (AllowedChar[i] == CurrentChar) 
				    CharOK = true;
		if (shiftPressed || altPressed || ctrlPressed)
		    CharOK = true;
	    return CharOK;
	}
    
    function IsNumeric(entry) {
       var strValidChars = "0123456789";
       var c;
       var i;
       var blnResult = true;

       if (entry.length == 0) return false;

       for (i = 0; i < entry.length; i++) {
	      c = entry.charAt(i);
          if (strValidChars.indexOf(c) == -1) {
		    blnResult = false;
		    break;
		    }
       }
       return blnResult;
    }
    
    
    function GenerateDiv(sItemsArr, sJson){
        var lJson = false;
        var li = 0;
        var lRowOk = false;
        
        if (typeof(sJson)!='undefined')
            lJson = sJson;
            
        if (sItemsArr.length > 0){
            //_self.pJsonReq = true;
            fAcObj.pSearchType = fSearchType;
	        fAcObj.setRefID(fRefID);
	        fAcObj.setNoKeyUpDown(fNoKeyUpDown);
	        fAcObj.setMaxRows(fMaxRows);
	        fAcObj.setRowHeight(fRowHeight);
	        fAcObj.setMarkTxt(fMarkTxt);
	        fAcObj.setColValue(fColValue);
	        fAcObj.setColText(fColText);
	        fAcObj.setColDiff(fColDiff);
	        fAcObj.setDistanceX(fDistanceX);
	        fAcObj.setDistanceY(fDistanceY);
	        fAcObj.setHiddenFields(fHiddenFields);
	        fAcObj.addColWidth(fAddColWidth);
	        fAcObj.addRowAlign(fAddRowAlign);
	        fAcObj.setSelectFirstEntry(fSelectFirstEntry);
	        
	        for (var i = 0; i < sItemsArr.length; i++){
		        
		            if (lJson){
		                if (li <= fAcObj.getAutoCompMaxRowCount() || fAcObj.getAutoCompSuppress() == true){
		                    lRowOk = false
		                    if (fPartOf){
		                        if (sItemsArr[i].bez.toLowerCase().indexOf(_self.pTxtVal.toLowerCase()) != -1)
		                            lRowOk = true;
		                    }
		                    else{
	                            if (sItemsArr[i].bez.toLowerCase().substring(0,_self.pTxtVal.length) == _self.pTxtVal.toLowerCase())
	                                lRowOk = true;
	                        }
		                        
		                    //if (sItemsArr[i].bez.toLowerCase().indexOf(_self.pTxtVal.toLowerCase()) != -1){
		                    if (lRowOk){
		                        fAcObj.addRowName(sItemsArr[i].id + ";" + sItemsArr[i].bez);
		                        fAcObj.addRow();
		                        li += 1;
		                    }
		                }
		                else
			                break;
		            }
		            else{
		                if (li <= fAcObj.getAutoCompMaxRowCount() || fAcObj.getAutoCompSuppress() == true){
			                if (fGeoSearch)
			                    fAcObj.addRowName(sItemsArr[i].getElementsByTagName("geosl")[0].firstChild.nodeValue + ";" + sItemsArr[i].getElementsByTagName("ortsbez")[0].firstChild.nodeValue);
			                else
			                    fAcObj.addRowName(sItemsArr[i].getElementsByTagName("id")[0].firstChild.nodeValue + ";" + sItemsArr[i].getElementsByTagName("bez")[0].firstChild.nodeValue);
			                
			                fAcObj.addRow();
			                li += 1;
			            }
			            else
			                break;
			        }
			        
		    }
		    if (li == 0)
		        fAcObj.onCloseAuCo();
		    else
	            fAcObj.showDivAutoComp(fEvent);
	    }
	    else
		    fAcObj.onCloseAuCo();
		_self.onSearchAfter();    
	    document.getElementsByTagName("body")[0].style.cursor = "auto";
    }
    
    this.TxtBoxChanged = function(sVal, sEvent){
        var AuCoMod = 0;
        var AuCoOk = false;
        var AuCoModRF=new Array(4);
        
        if (sVal.length == 0){
            fAcObj.onCloseAuCo();
            return;
        }
        
        fRefID = this.pRefID;
        fFormID = this.pFormID;
        fLasid = this.pLasid;
        fGeoSL = this.pGeoSL;
        fLandRefID = this.pLandRefID;
        if (fGeoSL==''){
            if (fLandRefID != '')
                fGeoSL = ge(fLandRefID).value
        }
            
        fRefHiddenID = this.pRefHiddenID;
        fNoKeyUpDown = this.pNoKeyUpDown;
        fMaxRows = this.pMaxRows;
        fRowHeight = this.pRowHeight;
        fColValue = this.pColValue;
        fColText = this.pColText;
        fColDiff = this.pColDiff;
        fDistanceX = this.pDistanceX;
        fDistanceY = this.pDistanceY;
        fAddColWidth  = this.pAddColWidth;
        fAddRowAlign  = this.pAddRowAlign;
        fGeoSearch = this.pGeoSearch;
        fUrl = this.pUrl;
        fPartOf = this.pPartOf;
        fTextBoxName = this.pTextBoxName;
        fRadioName = this.pRadioName;
        fSelName = this.pSelName;
        fHiddenFields = this.pHiddenFields;
        fShotInSamePage = this.pShotInSamePage;
        fGeoSel = this.pGeoSel;
        fRadioArr = this.pRadioArr;
        fExterneID = this.pExterneID;
        fFrmSubmit = this.pFrmSubmit;
        fJson = this.pJson;
        fTxtChanged = this.pTxtChanged;
        fMinChar = this.pMinChar;
        fSearchByKey = this.pSearchByKey;
        fReadAllFrmElem = this.pReadAllFrmElem;
        fSearchType = this.pSearchType;
        fTextBoxtext = this.pTextBoxtext;
        fOrtArtID = this.pOrtArtID
        fMarkTxt = this.pMarkTxt;
        fSelectFirstEntry = this.pSelectFirstEntry;
        
        _self.pTxtVal = sVal;
        
        if (fTxtChanged == 0 && fJson && !fSearchByKey)
            sVal = left(sVal,fMinChar);
        
        if (!sEvent)
	        sEvent = window.event;
        
	    if (typeof(sEvent)!="undefined"){
	        fEvent = sEvent.keyCode ? sEvent.keyCode : sEvent.which;
    	    if (fAcObj.isOpen()){
    	        if (fEvent == 37 || fEvent == 38 || fEvent == 39 || fEvent == 40){
    	            fAcObj.onKeyUpDown(fEvent)
    	            return false; 
    	        }
    	    }
    	    
    	    
    	    
    	    if (fGeoSearch){
    	        if (fGeoSel) {
		            if (document.forms[fFormID].elements[fTextBoxName].value.length > (fMinChar-1))
		                AuCoOk = true;
		            else
		                _self.pJsonReq = false;
    	        }	     
    	        
    	        if (_BufferedVal.length == 0)
		            _BufferedVal = sVal;
		        if (_BufferedVal.length > 0 && sVal.length > 0 && _BufferedVal.toLowerCase().substr(0, fMinChar) != sVal.toLowerCase().substr(0, fMinChar)){
	                _BufferedVal = sVal; 
	                _self.pJsonReq = false;
	            }
    	            
	            if (AuCoOk){
	                _self.onSearchBefore();
                    var lURL = '/scr/inc/suche/getSumRegion.asp?LASID='+fLasid;
                    lURL +='&Ort=' + escape(sVal);
                    if (fGeoSel){
				        if (document.forms[fFormID].elements[fSelName]) {
				            var lSelVal = this.SelValue(this.pFormID, this.pSelName);
				            if (lSelVal == '0')
				                return false;
				            else if (lSelVal == '1')
				                 lURL +='&OrtArt=4';    
				            else if (lSelVal == '2')
				                 lURL +='&OrtArt=3';
				            else if (lSelVal == '3')
				                 lURL +='&OrtArt=2';
				            else if (lSelVal == '5')
				                 lURL +='&OrtArt=1';
				            else if (lSelVal == '7')
				                 lURL +='&OrtArt=9';
				            else if (lSelVal == '9')
				                 lURL +='&OrtArt=8';
				            else if (lSelVal == '11')
				                 lURL +='&OrtArt=11';
				            else if (lSelVal == '12')
				                 lURL +='&OrtArt=12';
				            else
				                lURL +='&OrtArt=13';
				        } 
				        else
				            if (ge(fOrtArtID))
				                lURL +='&OrtArt='+ge(fOrtArtID).value;
				            else
					            lURL +='&OrtArt=1';
					}
				    if (fJson){
	                    if (!_self.pJsonReq){
							document.getElementsByTagName('body')[0].style.cursor = 'wait';
							if (!fSearchByKey)
							    _self.pJsonReq = true;
    	                    new AjaxRequest(lURL,this.SetOrtsCombo);
	                    }
	                    else
	                        GenerateDiv(fItemsArr, true);
	                }
	                else{
	                    document.getElementsByTagName('body')[0].style.cursor = 'wait';
	                    new AjaxRequest(lURL,this.SetOrtsCombo,true)
	                }
                }
	        }
	        else{
	            AuCoOk = false;
	            if (sVal.length > (fMinChar-1))
	                AuCoOk = true;
	            else
		            _self.pJsonReq = false;
		            
		        if (_BufferedVal.length == 0)
		            _BufferedVal = sVal;
		        if (_BufferedVal.length > 0 && sVal.length > 0 && _BufferedVal.toLowerCase().substr(0, fMinChar) != sVal.toLowerCase().substr(0, fMinChar)){
	                _BufferedVal = sVal; 
	                _self.pJsonReq = false;
	            }
	            
	            
	            if (AuCoOk){
	                _self.onSearchBefore();
		            var lURL = fUrl;
		            var lSelRadio = '';
		            var lSSUTyp = ge('ssu_Sel');
		            if(lURL.indexOf('?') > -1)
		                lURL += '&'
		            else
		                lURL += '?'
		            lURL += 'SWord=' + escape(sVal);
		            
		            if (fReadAllFrmElem){
		                for (var i = 0; i < document.forms[fFormID].elements.length;i++){
		                    if (lURL.indexOf(document.forms[fFormID].elements[i].name + '=')==-1){
		                        if (document.forms[fFormID].elements[i].type.toLowerCase() == 'checkbox')
		                            lURL += '&' + document.forms[fFormID].elements[i].name + '=' + document.forms[fFormID].elements[i].checked;
		                        else if (document.forms[fFormID].elements[i].type.toLowerCase() == 'radio'){
		                            lURL += '&' + document.forms[fFormID].elements[i].name + '=' 
		                            if (document.forms[fFormID].elements[i].checked)
		                                lURL += document.forms[fFormID].elements[i].value;
		                        }
		                        else
		                            lURL += '&' + document.forms[fFormID].elements[i].name + '=' + document.forms[fFormID].elements[i].value;
		                    
		                    }
		                }
		            }
		            
	                if (fRadioArr.length > 0){
	                    for (var li=0; li<fRadioArr.length;li++){
	                        if(ge(fRadioArr[li])){
	                            if (ge(fRadioArr[li]).checked)
	                                lSelRadio = ge(fRadioArr[li]).value;
	                        }
	                    }
	                }
	                if (lSelRadio != '')
	                    lURL += '&rad='+ lSelRadio;
	                if (document.forms[fFormID].elements[fRadioName]){
	                    for (var i=0;i<document.forms[fFormID].elements[fRadioName].length;i++){
	                        if (document.forms[fFormID].elements[fRadioName][i].checked)
	                            lURL += '&radVal='+ document.forms[fFormID].elements[fRadioName][i].value;
	                    }
	                }
	                if (fExterneID != '')
	                    lURL += '&extID=' + fExterneID;
	                if (lSSUTyp)
	                    lURL += '&typ=' + lSSUTyp.value;
	                if (fJson){
	                    if (!_self.pJsonReq){
	                    
	                    }
	                }
	                if (fJson){
	                    if (!_self.pJsonReq){
	                        if (!fSearchByKey)
	                            _self.pJsonReq = true;
							document.getElementsByTagName('body')[0].style.cursor = 'wait';
    	                    new AjaxRequest(lURL,this.SetItemsCombo);
	                    }
	                    else
	                        GenerateDiv(fItemsArr, true);
	                }
	                else{
	                    document.getElementsByTagName('body')[0].style.cursor = 'wait';
	                    new AjaxRequest(lURL,this.SetItemsCombo,true)
	                }
	            }
	        }
	    }
	    else{
	        _self.pJsonReq = false;
		    fAcObj.onCloseAuCo();
	    }
    }
    
    this.resetRequest = function(){
        _self.pJsonReq = false;
    }
    
    this.SelValue = function(sFormID, sSelName){
        var lSelVal = ''
        if (document.forms[sFormID].elements[sSelName]){
	        if (document.forms[sFormID].elements[sSelName].options)
	            lSelVal = document.forms[sFormID].elements[sSelName].options[document.forms[sFormID].elements[sSelName].options.selectedIndex].value;
	        else{
	            if (document.forms[sFormID].elements[sSelName].length > 0){
	                for (var li=0;li<document.forms[sFormID].elements[sSelName].length;li++){
	                    if (document.forms[sFormID].elements[sSelName][li].checked)
	                        lSelVal = document.forms[sFormID].elements[sSelName][li].value;
	                }
	            }
	            else
	                lSelVal = document.forms[sFormID].elements[sSelName].value;
	        }
	    }
	    return lSelVal;
    }
    
    this.handleKeycode = function (sEvent){
        var lKeycode = 0;
        if (!sEvent)
	        sEvent = window.event;
        lKeycode = sEvent.keyCode ? sEvent.keyCode : sEvent.which;
        if (fAcObj.isOpen()){
            switch(lKeycode){
                case 9: 
                    fAcObj.getSelectedRow();
                    return true;
                    break;
                case 13:
                    if (fSearchType == 1 && fSelectFirstEntry)
                        fAcObj.getSelectedRow();
                    return true;
                    break;
                case 39:
                    fAcObj.getSelectedRow();
                    return true;
                    break;
                case 38: case 40:
                    return false;
                    break;
            }
        }
    }
    
    this.setRowClassNameAuCo = function(sVal){
        fAcObj.setRowClassNameAuCo(sVal);
    }
    
    this.onStillAlive = function(sVal){
        fAcObj.onStillAlive(sVal);
    }
    
    this.onClickAuCo = function(sVal1, sVal2){
        fAcObj.onClickAuCo(sVal1, sVal2);
    }
    
    this.onFrmSubmit = function(){
        var lFrmName = this.pFormID;
        if (this.pFrmSubmit){
            var frm = document.forms[lFrmName];
	        if (frm)
	            frm.submit();
	    }
    }
    
    this.onCloseAuCo = function(sThis){
        fAcObj.onCloseAuCo();
    }
    
    this.setShowAll = function(sVal){
        fAcObj.setShowAll(sVal);
    }
    
    fAcObj.setAutoCompValue = function(SelValue){
	    ge(fRefHiddenID).value = SelValue;
    }
    
    fAcObj.showAllAutoComp = function(){
	    document.getElementsByTagName("body")[0].style.cursor = "wait";
	    fAcObj.onCloseAuCo();
	    GenerateDiv(fItemsArr, fJson);
	    fAcObj.setAutoCompSuppress(false);
    }
    
    fAcObj.afterCloseAutoComp = function(){
         _self.onBlur();
    }
    
    this.PruefMenuForm = function(sFormID, sAus){
        var lRet = true;
	    if (document.forms[sFormID].elements[_self.pTextBoxName].value == "" || document.forms[sFormID].elements[_self.pTextBoxName].value == _self.pTextBoxtext || document.forms[sFormID].elements[_self.pTextBoxName].value == sAus)
		    lRet = false;
		return lRet;
		
    }
    this.onBlur = function(){}
    this.CheckTxtBox = function(sVal){}
    this.onSearchBefore = function(){}
    this.onSearchAfter = function(){}
}
