﻿// See http://binnyva.blogspot.com/2005/10/dump-function-javascript-equivalent-of.html
function dump(arr,level) {
    var dumped_text = "";
    if(!level) level = 0;
    
    //The padding given at the beginning of the line.
    var level_padding = "";
    for(var j=0;j<level+1;j++) level_padding += "    ";
    
    if(typeof(arr) == 'object') { //Array/Hashes/Objects 
        for(var item in arr) {
            var value = arr[item];
            
            if(typeof(value) == 'object') { //If it is an array,
                dumped_text += level_padding + "'" + item + "' ...\n";
                dumped_text += dump(value,level+1);
            } else {
                dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
            }
        }
    } else { //Stings/Chars/Numbers etc.
        dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
    }
    return dumped_text;
}

/*
    *
    * Date: 20080508
    * Name: ajaxAutoComplete
    * Desc: opens a Suggestion layer for inserted Words
    * Author: Florian Neumair
    * Company: ecomplexx
    *
    * Working+Layout: 
    *     Windows: IE 6.0, IE 7.0, FF 1.5, FF 2.0, FF 3.0, Safari 3.1.1, Opera 9.27
    *    MAC: Safari, FF 1.5, FF 2.0, FF 3.0
    *    Linux: FF 1.5, FF 2.0, FF 3.0, Konqueror
    * Working:
    *    Windows: IE 5.5
    *
    
    var as = new ajaxAutoComplete(elemID or elem,XMLUrl,{properties});
    
    properties:
        * delay [int]: time in ms for delau between end of insert and displaying Layer.
        * autoText [string]: text to display as default value of the input element (can be also set in value of input itself).
        * autoFocus [true/false]: focuses te field on load of the page.
        * minChars [int]: minimum chars to insert befor suggestion starts
        * top[int]: top position relative to the input elem.
        * left[int]: left position relative to the input elem.
        * width [int]: width of the layer.
        * followEnter [true/false]: if the link node is defined inside the XML it changes your location to this link.
        * submitEnter [true/false]: if input elem is inside an for this attribute submitts the form.
        * functionEnter [function ref]: if input element is inside an form this attributes containing function will be called an overgiven its form elements
        
    methods:
        * obj.close() : closes the open layer
        * obj.isSuggestionActive() return [true/false]: returns the actual state (if true the layer will open ) [cookie based].
        * obj.disableSuggestion()  : disables the layer from opening [cookie based].
        * obj.enableSuggestion()  : enables the layer from opening [cookie based].
        * obj.toggleSuggestion() : toggles the 2 above.
        
    usage:
    
    var as=new ajaxAutoComplete("trythis","./data.xml?search=",{delay:600,autoText:"Suchbegriff",top:24,left:0,width:201,submitEnter:true});
    
    <input name="testinput" id="trythis" value="" type="text"/>
*/

function ajaxAutoComplete(){
    /* def configs */
    this._delay=800;
    this._minChars=0;
    /* internal Vars */
    
    var _self=this;
    var _args = arguments;
    var _req;
    var data=new Object;
    this._inputElem=false;
    this._inputDefText="";
    this._sugBaseLayer;
    this._top = 0;
    this._left = 0;
    this._width = 201; 
    this._timeOut = false;
    this._position = -1;
    this._linkArr = new Array();
    this._textLength = 0;
    this._enterFollow=false;
    this._enterSubmit=false;
    this._enterCallFkt=false;
    this._helpIframe=false;
    this._autoSuggestionActive=true;
    this._imageClass="";
    
    this._Initialize=function(){
        try{
        this._autoSuggDisabled=(this._getCookie("autoSuggestionActive")=="false")?false:true;
        
        if(typeof(_args[0]) == "object"){
            this._inputElem = _args[0];
        } else {
            this._inputElem = this._getElementId(_args[0]);
        }
        this._inputElem.setAttribute("autocomplete", "off", 1);
        
        /* defaulttext automatisch verschwinden lassen */
        this._inputDefText=this._inputElem.value;
        this._adEventHandler(this._inputElem,"focus",function(){
            if(_self._inputElem.value == _self._inputDefText){
                _self._inputElem.value="";
            }
        });
        
        this._adEventHandler(this._inputElem,"blur",function(){
            if(_self._inputElem.value == ""){
                _self._inputElem.value=_self._inputDefText;
            }
            _self._finishBox();
        });
        
        this._adEventHandler(this._inputElem,"keyup",function(event){
            _self._handleKeypress(event);
        });
        
        if(this._inputElem.disabled){
            this._inputElem.disabled = false;
        }
        
        /* setting extra values */
        if(_args.length==3){
            if(_args[2]["delay"]){
                this._delay=_args[2]["delay"];
            }
            if(_args[2]["autoText"]){
                this._inputElem.value=_args[2]["autoText"];
                this._inputDefText=_args[2]["autoText"];
            }
            if(_args[2]["autoFocus"]){
                this._inputElem.focus();
            }
            if(_args[2]["top"]){
                this._top=_args[2]["top"];
            }
            if(_args[2]["left"]){
                this._left=_args[2]["left"];
            }
            if(_args[2]["width"]){
                this._width=_args[2]["width"];
            }
            if(_args[2]["followEnter"]){
                this._enterFollow=_args[2]["followEnter"];
            }
            if(_args[2]["submitEnter"]){
                this._enterSubmit=_args[2]["submitEnter"];
            }
            if(_args[2]["functionEnter"]){
                if(typeof(_args[2]["functionEnter"])=="function"){
                    var fkt=_args[2]["functionEnter"];
                    this._enterCallFkt=function(_data){fkt(_data);};
                }
            }
            if(_args[2]["minChars"]){
                this._minChars=_args[2]["minChars"];
            }
            if(_args[2]["imageClass"]){
                this._imageClass=_args[2]["imageClass"];
            }
            
            if(this.BrowserDetect.browser=="Explorer"){
                if(_args[2]["ie"]){
                    var data = _args[2]["ie"];
                }
                
                if(_args[2]["ie6"] && this.BrowserDetect.version==6){
                    var data = _args[2]["ie6"];
                }
                if(_args[2]["ie7"] && this.BrowserDetect.version==7){
                    var data = _args[2]["ie7"];
                }
                if(_args[2]["ie8"] && this.BrowserDetect.version==8){
                    var data = _args[2]["ie8"];
                }
                if (data) {
                    if (data["top"]) {
                        this._top = data["top"];
                    }
                    if (data["left"]) {
                        this._left = data["left"];
                    }
                    if (data["width"]) {
                        this._width = data["width"];
                    }
                }
            }
        }
        
        /* building basic layer HTML */
        this._sugBaseLayer = document.createElement("div");
        this._sugBaseLayer.className="ajaxAutoCompleteMainLayer";
        this._sugBaseLayer.style.position="absolute";
        this._sugBaseLayer.style.zIndex="999";
        this._sugBaseLayer.style.overflow="hidden";
        if(this._width != -1){
            this._sugBaseLayer.style.width=this._width+"px";
        }
        
        document.getElementsByTagName("body")[0].appendChild(this._sugBaseLayer);
        var ePos = this._getElementPosition(this._inputElem);
        this._sugBaseLayer.style.left=(ePos["left"]+this._left)+"px";
        this._sugBaseLayer.style.top=(ePos["top"]+this._top)+"px";
        
        /* IE Selectbox fix */
        if((navigator.userAgent.indexOf("MSIE ")>-1) 
            && (navigator.userAgent.match(/MSIE ([0-9|.]{1,4})/g)[0].replace(/MSIE /,"").substr(0,navigator.userAgent.match(/MSIE ([0-9|.]{1,4})/g)[0].replace(/MSIE /,"").indexOf("."))+"."+navigator.userAgent.match(/MSIE ([0-9|.]{1,4})/g)[0].replace(/MSIE /,"").substr(navigator.userAgent.match(/MSIE ([0-9|.]{1,4})/g)[0].replace(/MSIE /,"").indexOf("."),navigator.userAgent.match(/MSIE ([0-9|.]{1,4})/g)[0].replace(/MSIE /,"").length).split(".").join("")) < 7){
            this._helpIframe=document.createElement("iframe");
            if(document.location.protocol == "https:"){
                this._helpIframe.src="//0";
            } else if(window.opera != "undefined") {
                this._helpIframe.src="";
            } else {
                this._helpIframe.src="javascript:false";
            }
            this._helpIframe.style.zIndex="998";
            this._helpIframe.style.position="absolute";
            this._helpIframe.style.display="none";
            this._helpIframe.style.filter="Alpha(opacity=0)";
            this._helpIframe.style.width=this._width+"px";
            this._helpIframe.style.left=(ePos["left"]+this._left)+"px";
            this._helpIframe.style.top=(ePos["top"]+this._top)+"px";
            this._helpIframe.frameborder="0";
            this._helpIframe.scrolling="no";
            document.body.appendChild(this._helpIframe);
        }
        
        }catch(e){}
    };
    
    this.BrowserDetect = {
        init: function(){
            this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
            this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
            this.OS = this.searchString(this.dataOS) || "an unknown OS";
        },
        searchString: function(data){
            for (var i = 0; i < data.length; i++) {
                var dataString = data[i].string;
                var dataProp = data[i].prop;
                this.versionSearchString = data[i].versionSearch || data[i].identity;
                if (dataString) {
                    if (dataString.indexOf(data[i].subString) != -1) 
                        return data[i].identity;
                }
                else 
                    if (dataProp) 
                        return data[i].identity;
            }
        },
        searchVersion: function(dataString){
            var index = dataString.indexOf(this.versionSearchString);
            if (index == -1) 
                return;
            return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
        },
        dataBrowser: [{
            string: navigator.userAgent,
            subString: "Chrome",
            identity: "Chrome"
        }, {
            string: navigator.userAgent,
            subString: "OmniWeb",
            versionSearch: "OmniWeb/",
            identity: "OmniWeb"
        }, {
            string: navigator.vendor,
            subString: "Apple",
            identity: "Safari",
            versionSearch: "Version"
        }, {
            prop: window.opera,
            identity: "Opera"
        }, {
            string: navigator.vendor,
            subString: "iCab",
            identity: "iCab"
        }, {
            string: navigator.vendor,
            subString: "KDE",
            identity: "Konqueror"
        }, {
            string: navigator.userAgent,
            subString: "Firefox",
            identity: "Firefox"
        }, {
            string: navigator.vendor,
            subString: "Camino",
            identity: "Camino"
        }, {
            string: navigator.userAgent,
            subString: "Netscape",
            identity: "Netscape"
        }, {
            string: navigator.userAgent,
            subString: "MSIE",
            identity: "Explorer",
            versionSearch: "MSIE"
        }, {
            string: navigator.userAgent,
            subString: "Gecko",
            identity: "Mozilla",
            versionSearch: "rv"
        }, {
            string: navigator.userAgent,
            subString: "Mozilla",
            identity: "Netscape",
            versionSearch: "Mozilla"
        }],
        dataOS: [{
            string: navigator.platform,
            subString: "Win",
            identity: "Windows"
        }, {
            string: navigator.platform,
            subString: "Mac",
            identity: "Mac"
        }, {
            string: navigator.userAgent,
            subString: "iPhone",
            identity: "iPhone/iPod"
        }, {
            string: navigator.platform,
            subString: "Linux",
            identity: "Linux"
        }]
    };
    this.BrowserDetect.init();
    
    this.URLEncode = function(plaintext){
        var SAFECHARS = "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()";
        var HEX = "0123456789ABCDEF";
        var encoded = "";
        for (var i = 0; i < plaintext.length; i++) {
            var ch = plaintext.charAt(i);
            if (ch == " ") {
                encoded += "+"; // x-www-urlencoded, rather than %20
            }
            else 
                if (SAFECHARS.indexOf(ch) != -1) {
                    encoded += ch;
                }
                else {
                    var charCode = ch.charCodeAt(0);
                    if (charCode > 255) {
                        encoded += "+";
                    }
                    else {
                        encoded += "%";
                        encoded += HEX.charAt((charCode >> 4) & 0xF);
                        encoded += HEX.charAt(charCode & 0xF);
                    }
                }
        }
        return encoded;
    };
    
    this._fetchFormData=function(_form){
        try{
            var formData=new Object();
                formData.type="FORM";
                formData.len=0;
            var inputs=_form.getElementsByTagName("input");
            var selects=_form.getElementsByTagName("select");
            var textareas=_form.getElementsByTagName("textarea");
            for(var i=0;i<inputs.length;i++){
                if(inputs[i].name != ""){
                    formData[inputs[i].name]=inputs[i].value.replace(/^\s+|\s+$/g, "");
                } else {
                    formData[_cnt]=inputs[i].value.replace(/^\s+|\s+$/g, "");
                }
                formData.len++;
            }
            for(var i=0;i<selects.length;i++){
                if(inputs[i].name != ""){
                    formData[selects[i].name]=selects[i][selects[i].selectedIndex].value.replace(/^\s+|\s+$/g, "");
                } else {
                    formData[_cnt]=selects[i][selects[i].selectedIndex].value.replace(/^\s+|\s+$/g, "");
                }
                formData.len++;
            }
            for(var i=0;i<textareas.length;i++){
                if(textareas[i].name != ""){
                    formData[textareas[i].name]=textareas[i].value.replace(/^\s+|\s+$/g, "");
                } else {
                    formData[_cnt]=textareas[i].value.replace(/^\s+|\s+$/g, "");
                }
                formData.len++;
            }
                            
            return formData;
        }catch(e){}
    };
    
    this._buildQueryString=function(url,data){
        var retStr = "";
        for (key in data) {
            if(retStr == ""){
                retStr = url+((url.indexOf('?') == -1) ? "?" : "&")+key+"="+this.URLEncode(data[key]);
            } else {
                retStr += "&"+key+"="+this.URLEncode(data[key]);
            }            
        }
        if(retStr == "") 
            return url;
        return retStr;
    };
    
    this._handleKeypress=function(event){
        try{            
        if(this.isSuggestionActive()){
            if (this._timeOut) window.clearTimeout(this._timeOut);
            if (event.keyCode == 40){/* cursor down */
                (this._position < (this._linkArr.length -1))?this._doSelect(this._position +1):this._doSelect(this._position);
                return;
            } else if (event.keyCode ==38 && this._position > -1){/* cursor up */
                (this._position > 0)?this._doSelect(this._position-1):this._doSelect(0);
                return;
            } else if(event.keyCode == 27){ /* ESC Key */
                this._finishBox();
            } else if(event.keyCode == 13){ /* ENTER Key */
                if(this._position > -1 && typeof(this._linkArr[this._position]) == "object" && this._enterFollow){
                    document.location.href=this._linkArr[this._position].href;
                    this._finishBox();
                    return true;
                } else if(this._enterSubmit){
                    this._submitParentForm();
                    this._finishBox();
                    return true;
                } else if(this._enterCallFkt){
                    this._callFunction();
                    this._finishBox();
                    return true;
                } 
            }
            /* no selection */
            if(this._position > -1) this._position=-1;
            /* timeout fuer Datenaktualisierung */
            this._timeOut = window.setTimeout(function(){_self._getData();}, this._delay);
        }
        } catch(e){}
    };
    
    this._getData=function(){
    try{
        this._textLength=this._inputElem.value.length;
        if (this._textLength > this._minChars){
            if (window.XMLHttpRequest){
                    _req = new XMLHttpRequest();
                    _req.onreadystatechange = _self._fetchData;
                    var form = this._getParentForm();
                    if(form != false)
                        _req.open("GET", this._buildQueryString(_args[1],this._fetchFormData(form)), true);
                    else
                        _req.open("GET", _args[1]+"&text="+this._inputElem.value, true);
                    _req.send(null);
                } 
                else if (window.ActiveXObject) {
                    _req = new ActiveXObject("Microsoft.XMLHttp");
                    if (_req) 
                    {
                        _req.onreadystatechange = _self._fetchData;
                        var form = this._getParentForm();
                        if(form != false)
                            _req.open("GET", this._buildQueryString(_args[1],this._fetchFormData(form)), true);
                        else
                            _req.open("GET", _args[1]+"&text="+this._inputElem.value, true);
                        _req.send();
                    }
                }
        } else {
            this._finishBox();
        }
    } catch(e){alert(e)}
    };
    
    this._fetchData=function(){
        try{
            if (_req.readyState == 4){         
                data = _self._parseXMLData(_req.responseXML);
                _self._linkArr = new Array();
                _self._handelData();
            }
        }catch(e){}
    };
    
    this._handelData=function(){
        try{
            if(data["suggestions"] && data["suggestions"]["suggestion"] && typeof(data["suggestions"]["suggestion"].length) != "number" && data["suggestions"]["suggestion"]["value"]){
                var tmp = data["suggestions"]["suggestion"]["value"];
                data["suggestions"]["suggestion"]=new Array();
                data["suggestions"]["suggestion"][0]=tmp;
            }
            if(data["suggestions"] && data["suggestions"]["suggestion"] && data["suggestions"]["suggestion"].length > 0)
            {
            this._sugBaseLayer.innerHTML = "";
            this._removeChildNodes(this._sugBaseLayer);
            
                    var elemImgDiv = document.createElement("div");    
                        elemImgDiv.className = "ajax_ImgTop_" + this._imageClass;
                        elemImgDiv.style.width = this._width+"px";
                        
                    var elemSpacerDiv = document.createElement("div");    
                        elemSpacerDiv.style.display = "none";
                        elemSpacerDiv.style.width = "100%";
                        elemSpacerDiv.style.height = "100%";
                        
                    var elemTextDiv = document.createElement("div");
                        elemTextDiv.style.display = "none";
                        elemTextDiv.className = "ajax_TxTDiv";
                        elemTextDiv.style.width = (this._width-4)+"px";
                    
                    var elemTextSpan = document.createElement("div");
                        elemTextSpan.className = "ajax_TxTSpan";
                        try {
                            elemTextSpan.innerHTML = data["suggestions"]["header"].value;
                        } catch (e) {}
                        elemTextSpan.style.width = this._width + "px";
                        
                    var elemButtonDiv = document.createElement("div");
                        elemButtonDiv.className = "ajax_ButtonDiv";
                    
                    var elemButtonLnk = document.createElement("a");
                        elemButtonLnk.href = 'JavaScript:void(0);';
                        this._adEventHandler(elemButtonLnk,"click",function(){_self._finishBox();});
                        
                    var elemButtonImg = document.createElement("img");
                    elemButtonImg.style.display = "none";
                    if (typeof egm == "object" && egm.imagepath != "") {
                        elemButtonImg.src = egm.imagepath+"/ajax/ajax_close.gif";
                    }
                    else {
                        //elemButtonImg.src = "../images/ajax_close.gif";
                        elemButtonImg.src = "";
                    }
                    elemButtonImg.style.border = "0";
                    
                    var elemListDiv = document.createElement("div");
                        elemListDiv.className = "ajax_ListItems";
                        elemListDiv.style.width = (this._width-4)+"px";
                        
                    var elemShadowBottom = document.createElement("div");
                        /*elemShadowBottom.className = "ajax_ShadowBottom";
                        /elemShadowBottom.style.marginLeft = "5px";*/
                        elemShadowBottom.className = "ajax_ShadowBottom_" + this._imageClass;
                        
                    var elemShadowRight = document.createElement("div");
                        elemShadowRight.className = "ajax_ShadowRight";
                        elemShadowRight.style.width = (this._width-4)+"px";

                        this._sugBaseLayer.appendChild(elemImgDiv);
                            elemSpacerDiv.style.height = "5px";
                            elemTextDiv.appendChild(elemSpacerDiv.cloneNode(true));
                            elemTextDiv.appendChild(elemTextSpan);
                                elemButtonLnk.appendChild(elemButtonImg);
                                elemButtonDiv.appendChild(elemButtonLnk);
                            elemTextDiv.appendChild(elemButtonDiv);
                        elemShadowRight.appendChild(elemTextDiv);
                            //elemSpacerDiv.style.height = "12px";
                            elemSpacerDiv.style.display = "none";
                            elemListDiv.appendChild(elemSpacerDiv.cloneNode(true));                            
                            for (var id = 0; id < data["suggestions"]["suggestion"].length; id++) 
                                {
                                var child = data["suggestions"]["suggestion"][id]["text"].value;
                                    this._createListItem(id,elemListDiv,child);
                                }
                            //elemSpacerDiv.style.height = "10px";
                            elemSpacerDiv.style.display = "none";
                            elemListDiv.appendChild(elemSpacerDiv.cloneNode(true));
                        elemShadowRight.appendChild(elemListDiv);
                        this._sugBaseLayer.appendChild(elemShadowRight);
                        this._sugBaseLayer.appendChild(elemShadowBottom);
                        
                    this._sugBaseLayer.style.visibility = "visible";

                    if(this._helpIframe){
                        this._helpIframe.style.width = this._elemWidth(this._sugBaseLayer);
                        this._helpIframe.style.height = this._elemHeight(this._sugBaseLayer);
                        this._helpIframe.style.display = "inline";
                    }
                
            } else {
                this._sugBaseLayer.style.visibility = "hidden";
            }
        }catch(e){}
    }
    
    this._createListItem=function(id,elemListDiv,child){
    try{
        var elemDiv = document.createElement("div");
        //elemDiv.style.width =(this._width-33)+"px";
        if(id == 0){
            elemDiv.className="ajax_Link ajax_First";
        } else {
            elemDiv.className="ajax_Link";
        }
        this._adEventHandler(elemDiv,"mouseover",function(){_self._doSelect(id);});
            
        var elemLnk = document.createElement("a");
            //elemLnk.appendChild(document.createTextNode(child));
            elemLnk.innerHTML=child;
            
            if(typeof(data["suggestions"]["suggestion"][id]["link"]) == "object"){
                elemLnk.href = data["suggestions"]["suggestion"][id]["link"].value;
            } else {
                elemLnk.href = 'JavaScript:void(0);';
            }
            
        this._adEventHandler(elemDiv,"mousedown",function(){
            if(_self._position > -1 && typeof(_self._linkArr[_self._position]) == "object" && _self._enterFollow){
                document.location.href=_self._linkArr[_self._position].href;
                _self._finishBox();
                return false;
            } else if(_self._enterSubmit){
                _self._submitParentForm();
                _self._finishBox();
                return false;
            } else if(_self._enterCallFkt){
                _self._callFunction();
                _self._finishBox();
                return true;
            } 
        });

        this._adEventHandler(elemLnk,"mouseover",function(){_self._doSelect(id);});
            elemDiv.appendChild(elemLnk);
        
        this._linkArr[id] = elemLnk;
        
            elemListDiv.appendChild(elemDiv);
        }catch(e){}
    }
    
    this._doSelect = function(id){
        try{
        var elem = this._linkArr[id];
        if (this._position > -1){
            this._linkArr[this._position].parentNode.className = this._linkArr[this._position].parentNode.className.split(" ajax_Over").join("");
        }
        this._linkArr[id].parentNode.className = this._linkArr[id].parentNode.className + " ajax_Over";
        this._inputElem.value = this._stripHTML(this._linkArr[id].innerHTML);
        this._position = id;
        } catch(e) {}
    };
    
    this._selectTextRange=function(){
    try{
        if (this._inputElem.createTextRange){
            var oRange = inputField.createTextRange();
                oRange.moveStart("character", this._textLength);
                oRange.moveEnd("character", this._inputElem.value.length);
                oRange.select();
                this._inputElem.focus();
        } else {
            this._inputElem.setSelectionRange(this._textLength, this._inputElem.value.length);
        }
    } catch(e) {}
    };
    
    this._stripHTML = function(oldString) {
          return oldString.replace(/<(?:.|\s)*?>/g, "");
      };
        
    this._removeChildNodes=function(node){
    try{
        for (var i=node.childNodes.length-1; i>= 0; i--)
            node.removeChild(node.childNodes[i]);
    }catch(e){}
    }
    
        
    this._finishBox=function(){
    try{
        if (this._timeOut) window.clearTimeout(this._timeOut);
        this._sugBaseLayer.style.visibility = 'hidden';
        if(this._helpIframe){
            this._helpIframe.style.display="none";
        }
        this._removeChildNodes(this._sugBaseLayer);
        this._position = -1;
    }catch(e){}
    };
    
    this.close=function(){
        this._finishBox();
    }
    
    this._getParentForm=function(node){
    try{
        if(!node) node=this._inputElem;
        if(node.nodeName=="FORM"){
            return node;
        } else if(typeof(node.parentNode) == "object"){
            return this._getParentForm(node.parentNode);
        }
        return false;
    }catch(e){}
    };
    
    this._submitParentForm=function(){
    try{
        this._getParentForm().submit();
    }catch(e){}
    };
    
    this._fetchFormData=function(_form){
    try{
        var formData=new Object();
            formData.type="FORM";
            formData.len=0;
        var _cnt=0;
        var inputs=_form.getElementsByTagName("input");
        var selects=_form.getElementsByTagName("select");
        var textareas=_form.getElementsByTagName("textarea");
        for(var i=0;i<inputs.length;i++){
            if(inputs[i].name != ""){
                formData[inputs[i].name]=inputs[i].value;
            } else {
                formData[_cnt]=inputs[i].value;
            }
            formData.len++;
        }
        for(var i=0;i<selects.length;i++){
            if(inputs[i].name != ""){
                formData[selects[i].name]=selects[i][selects[i].selectedIndex].value;
            } else {
                formData[_cnt]=selects[i][selects[i].selectedIndex].value;
            }
            formData.len++;
        }
        for(var i=0;i<textareas.length;i++){
            if(textareas[i].name != ""){
                formData[textareas[i].name]=textareas[i].value;
            } else {
                formData[_cnt]=textareas[i].value;
            }
            formData.len++;
        }
                
        return formData;
    }catch(e){}
    };
    
    this._callFunction=function(){
    try{
        if(this._getParentForm()){
            var _data=this._fetchFormData(this._getParentForm());
            if(_data.length!=0){
                delete _data.length;
                this._enterCallFkt(_data);
            }
        }
    }catch(e){}
    };

    this._parseXMLData=function(xmlDoc,parent_count){
    try{
        var arr = false;
        var parent = "";
        var parent_count = parent_count || new Object;
        
        /* IE Fix */
        if(xmlDoc.nodeName && xmlDoc.nodeName == "#document" && xmlDoc.hasChildNodes() && xmlDoc.lastChild.hasChildNodes())
            return this._parseXMLData(xmlDoc.lastChild);
        
        if(xmlDoc.nodeName && xmlDoc.nodeName.charAt(0) != "#") {
            if(xmlDoc.childNodes.length > 1) {
                arr = new Object;
                parent = xmlDoc.nodeName;
            }
        }
        var value = xmlDoc.nodeValue;
        if(xmlDoc.parentNode && xmlDoc.parentNode.nodeName && value) {
            if(new RegExp(/[^\s]/).test(value)) {
                arr = new Object;
                arr[xmlDoc.parentNode.nodeName] = value;
            }
        }
        if(xmlDoc.hasChildNodes() && xmlDoc.childNodes.length) {
            if(xmlDoc.childNodes.length == 1) {
                arr = this._parseXMLData(xmlDoc.childNodes[0],parent_count);
            } else {
                var index = 0;
                for(var i=0; i<xmlDoc.childNodes.length; i++) {
                    var temp = this._parseXMLData(xmlDoc.childNodes[i],parent_count);
                    if(temp) {
                        var assoc = false;
                        var arr_count = 0;
                        for(key in temp) {
                            if(isNaN(key)) assoc = true;
                            arr_count++;
                            if(arr_count>2) break;
                        }
                        if(assoc && arr_count == 1) {
                            if(arr[key]) {
                                if(!parent_count || !parent_count[key]) {
                                    parent_count[key] = 0;
                                    var temp_arr = arr[key].value;
                                    arr[key] = new Array(temp_arr);
                                }
                                parent_count[key]++;
                                arr[key][parent_count[key]] = temp[key];
                            } else {
                                parent_count[key] = 0;
                                arr[key] = temp[key];
                                if(xmlDoc.childNodes[i].attributes.length) {
                                    for(var j=0; j<xmlDoc.childNodes[i].attributes.length; j++) {
                                        var nname = xmlDoc.childNodes[i].attributes[j].nodeName;
                                        if(nname) {
                                            var temp_arr = arr[key];
                                            arr[key] = new Object;
                                            if(temp_arr == "true"){
                                                arr[key].value = true;
                                            } else if (temp_arr == "false"){
                                                arr[key].value = false;
                                            } else {
                                                arr[key].value = temp_arr;
                                            }
                                            arr[key].attribute = new Object;
                                            arr[key].attribute[nname] = xmlDoc.childNodes[i].attributes[j].nodeValue;
                                        }
                                    }
                                } else {
                                    var temp_arr = arr[key];
                                    arr[key] = new Object;
                                    arr[key].value = temp_arr;
                                    arr[key].attribute = new Object;
                                }
                            }
                        } else {
                            arr[index] = temp;
                            index++;
                        }
                    }
                }
            }
        }
        
        if(parent && arr != false) {
            var temp = arr;
            arr = new Object;
            arr[parent] = temp;
        }
        return arr;
    } catch(e){}
    };
    
    this._elemWidth=function(e){
    try{
        if (e.clip && e.clip.width)
            {return e.clip.width;}
        else if (e.offsetWidth)
            {return e.offsetWidth;}
        else if (e.style.pixelWidth)
            {return e.style.pixelWidth;}
        return -1;
    }catch(e){}
    };

    this._elemHeight=function(e){
    try{
        if (e.clip && e.clip.height)
            {return e.clip.height;}
        else if (e.offsetHeight)
            {return e.offsetHeight;}
        else if (e.style.pixelHeight)
            {return e.style.pixelHeight;}
        return -1;
    }catch(e){}
    };
    
    this._getElementId=function(id){
    try{
        if (document.getElementById)return document.getElementById(id);    /* DOM*/
        else if (document.all)        return document.all[id];            /*  IE 4 und h&ouml;her*/   
        else if (document.layers)     return document.layers[id];            /* NS 4 u. h&ouml;her*/  
        return false;    
    }catch(e){}
    };
    
    this._adEventHandler=function(obj,eventName,functionRef){
    try{
            if (obj.addEventListener){
                obj.addEventListener(eventName,functionRef,false);
            } else if (obj.attachEvent) {
                obj.attachEvent("on"+eventName,functionRef);
            } else {
                if(typeof obj["on"+eventName] == "function"){
                    var _ool=obj["on"+eventName];
                    obj["on"+eventName]=function(){_ool();functionRef();}
                } else {
                    obj["on"+eventName]=functionRef;
                }
            }
    }catch(e){}
    };
    
    this._setCookie=function(designator,value,duration){
    try{
        now=new Date();
        timeOut=new Date(now.getTime()+duration*86400000);
        document.cookie=escape(designator)+"="+escape(value)+";expires="+timeOut.toGMTString()+";path=/;";
    }catch(e){}
    };
    
    this._getCookie=function(designator){
    try{
        var tmp = document.cookie.split("; ");
        for(i=0;i<tmp.length;i++)
        {
            tmp2 = tmp[i].split("="); 
            if(tmp2.length > 0 && tmp2[0]==escape(designator))
                return unescape(tmp2[1]);
        }
        return "true";
    }catch(e){}
    };
    
    this.isSuggestionActive=function(){
        return this._autoSuggestionActive;
    };
    
    this.disableSuggestion=function(){
        this._setCookie("autoSuggestionActive","false",365);
        this._autoSuggestionActive=false;
    };
    
    this.enableSuggestion=function(){
        this._setCookie("autoSuggestionActive","true",365);
        this._autoSuggestionActive=true;
    };
    
    this.toggleSuggestion=function(){
        if(this.isSuggestionActive()){
            this.disableSuggestion();
        } else {
            this.enableSuggestion();
        }
    };    
    
    this._getElementPosition=function(Obj) {
    try{
        var offsetLeft = this._getPosLeft(Obj,true);
        var offsetTop =this._getPosTop(Obj,true);
        return {left:offsetLeft, top:offsetTop};
    }catch(e){}
    };
    
    this._getPosLeft=function(Obj,recursive){
        try{
               var offset = 0;
            if (Obj.offsetLeft)
                offset = offset + Obj.offsetLeft;
            var parent = Obj.offsetParent;
            while (parent) {
                if (parent.offsetLeft)
                    offset = offset + parent.offsetLeft;
                parent = parent.offsetParent;
            }
            return offset;
        }catch(e){}
    };
    
    this._getPosTop=function(Obj,recursive){
        try{
            var offset = 0;
            if (Obj.offsetTop)
                offset = offset + Obj.offsetTop;
            var parent = Obj.offsetParent;
            while (parent) {
                if (parent.offsetTop)
                    offset = offset + parent.offsetTop;
                parent = parent.offsetParent;
            }
            return offset;
        }catch(e){}
    };
    
    try{
        var oldonload = window.onload;
        if (typeof window.onload != 'function'){
            window.onload = function() {_self._Initialize();}; 
        } else {
            window.onload = function() {oldonload();_self._Initialize();};
        }
    }catch(e){}
}
