var oToolTip = null;
    
    document.onmousemove = updateToolTip;
    
    function updateToolTip(e) {
        if (oToolTip) {
            oToolTip.style.left = (((document.all) ? window.event.x + document.body.scrollLeft : e.pageX) + 20) + "px";
            oToolTip.style.top     = (((document.all) ? window.event.y + document.body.scrollTop  : e.pageY) + 20) + "px";
        }
    }
    
    function showToolTip(id) {
        oToolTip = byId(id);
        oToolTip.style.display = "block"
    }
    
    function hideToolTip(id) {
        byId(id).style.display = "none";
    }
    function lockSection(id){
        var oSection = byId(id);
        if(oSection){
            if(byId(id + "_l")) return;
            
            var n = document.createElement("div");
            n.setAttribute("id", id + "_l");
            n.setAttribute("style", "position: relative;");
            var n2 = document.createElement("div");
            n2.setAttribute("class", "filter");
            n2.setAttribute("style", "position: absolute; width: " + oSection.offsetWidth + "px; height: " + oSection.offsetHeight + "px;");
            n.appendChild(n2);
            oSection.parentNode.insertBefore(n, oSection);    
        }
    }
    function unlockSection(id){
        var oSection = byId(id);
        if(oSection){
        
            var oSectionLockDiv = byId(id + "_l");
            if(oSectionLockDiv){    
        
                for(var i = 0; i < oSection.parentNode.childNodes.length; i++){
                    if(oSection.parentNode.childNodes[i]==oSectionLockDiv){
                        oSection.parentNode.removeChild(oSectionLockDiv);
                    }
                }
            }
        }
    }
    function setSectionError(id, nErrorType, text){
        var oSection = byId(id);
        if(oSection){
            if(byId(id + "_e")) return;
            
            var n = document.createElement("div");
            n.setAttribute("id", id + "_e");
            n.setAttribute("style", "position: relative;");
            var n2 = document.createElement("div");
            n2.setAttribute("class", "error" + nErrorType);
            n2.setAttribute("valign", "center");
            n2.setAttribute("align", "center");
            n2.setAttribute("style", "position: absolute; width: " + oSection.offsetWidth + "px; height: " + oSection.offsetHeight + "px;");
            var n3 = document.createElement("table");
            n3.setAttribute("border", "0");
            n3.setAttribute("cellpadding", "0");
            n3.setAttribute("cellspacing", "0");
            n3.setAttribute("height", "100%");
            n3.setAttribute("width", "100%");
            var n4 = document.createElement("tr");
            var n5 = document.createElement("td");
            n5.setAttribute("align", "middle");
            n5.setAttribute("valign", "middle");
            var n6 = document.createElement("table");
            n6.setAttribute("border", "0");
            n6.setAttribute("cellpadding", "10");
            n6.setAttribute("width", "80%");
            var n7 = document.createElement("tr");
            var n8 = document.createElement("td");
            n8.setAttribute("class", "errorText" + nErrorType);
            var tn = document.createTextNode(text);
            n8.appendChild(tn);
            n7.appendChild(n8);
            n6.appendChild(n7);
            n5.appendChild(n6);
            n4.appendChild(n5);
            n3.appendChild(n4);
            n2.appendChild(n3);
            n.appendChild(n2);
            oSection.parentNode.insertBefore(n, oSection);    
        }
    }
    function createToolTip(id, nToolTipType, text){
        var oSection = byId(id);
        if(oSection){
            if(byId(id + "_tt")) return;
            
            var n2 = document.createElement("div");
            n.setAttribute("id", id + "tt");
            n2.setAttribute("class", "tooltip" + nToolTipType);
            var n3 = document.createElement("table");
            n3.setAttribute("border", "0");
            n3.setAttribute("cellpadding", "0");
            n3.setAttribute("cellspacing", "0");
            var n4 = document.createElement("tr");
            var n5 = document.createElement("td");
            var tn = document.createTextNode(text);
            n5.appendChild(tn);
            n4.appendChild(n5);
            n3.appendChild(n4);
            n2.appendChild(n3);
            oSection.parentNode.insertBefore(n2, oSection);    
        }
    }
    function clearSectionError(id){
        var oSection = byId(id);
        if(oSection){
        
            var oSectionLockDiv = byId(id + "_e");
            if(oSectionLockDiv){    
        
                for(var i = 0; i < oSection.parentNode.childNodes.length; i++){
                    if(oSection.parentNode.childNodes[i]==oSectionLockDiv){
                        oSection.parentNode.removeChild(oSectionLockDiv);
                    }
                }
            }
        }
    }
    function getGermanWeekDay(d){
          return d.getDay();
          var w = d.getDay();
          w--;
          return (w < 0)? 6 : w;                    
    }
    function getHtmArray(a){
        var htm = "<table border='1'>";
        for(var r = 0; r < a.length; r++){
            htm += "<tr>";
            for(var c = 0; c < a[r].length; c++){
                htm += "<td><nobr>"+a[r][c]+"</nobr></td>";
            }
            htm += "</tr>";
        }
        return  htm + "</table>";
    }
  function readDate(id) {
    if(byId(id).value!=""){
      var aDay = (byId(id).value).split(".");
      var iYear = parseInt10(aDay[2]);
      
      return new Date((iYear < 2000)? iYear + 2000 : iYear, parseInt10(aDay[1])-1, parseInt10(aDay[0]));
    }
  }
    function setCss(id,cssAttribute,cssValue){
        if(byId(id))byId(id).style[cssAttribute] = cssValue;
        if(byId(id + '0'))byId(id + '0').style[cssAttribute] = cssValue;
        if(byId(id + '1'))byId(id + '1').style[cssAttribute] = cssValue;
        for(var i=2;i<100;i++){
            if(!byId(id+i))return;
            byId(id+i).style[cssAttribute] = cssValue;
        }
    }
    function parseInt10(i){return parseInt(i,10)}
    function byId(id){return document.getElementById(id)}
    function viewSection(id){setCss(id,'display','block')}
    function hideSection(id){setCss(id,'display','none')}
    function isSectionVisible(id){return byId(id).style['display'] != 'none'}
    function switchSectionVisible(id){
        if(isSectionVisible(id)){
            hideSection(id);
        }
        else{
            viewSection(id);
        }
    }

    function switchSectionWithAction(id,action){
        if(isSectionVisible(id)){
            hideSection(id);
        }
        else{
            viewSection(id);
            dojo.event.topic.publish(action);
        }
    }

    function getOption(sOptionName,aOptions){
        if(aOptions != null){
            for(var iOption = 0 ; iOption  < aOptions.length ; iOption ++) {
        
                var aOption = (aOptions[iOption]).split("=");
                if(aOption[0] == sOptionName){
                    return aOption[1];
                }
            }
        }
        return '';
    }
    
    function getArrayIndexByColumnAndValue(a,c,v){
        for(var i = 0; i < a.length; i++){
            if(a[i][c] == v){
                 return i;
            }
        }
        return -1;
    } 
    
    function getElement(id) {
        return document.getElementById(id);
}
function getStatus(element) {
    return element.style.display;
}
function getOpenerElement(id) {
    return opener.document.getElementById(id);
}
function ShowElement(element){
    element.style.display="block";
}
function HideElement(element){
    element.style.display="none";
}
function SwapBackground(Id,src) {
    SwapBackgroundImage(eval('getElement("'+Id+'")'),src);
}
function VisibleHidden(Id,show){    
    if (show==true){
        ShowElement(eval('getElement("'+Id+'")'));
    }
    else {
        HideElement(eval('getElement("'+Id+'")'));
    }    
}
function switchVisibleHidden(Id){    
    if (eval('getElement("'+Id+'")').style.display=="none" || eval('getElement("'+Id+'")').style.display==0){
        ShowElement(eval('getElement("'+Id+'")'));
    }
    else {
        HideElement(eval('getElement("'+Id+'")'));
    }    
}
function VisibleHiddenMulti(truefalse,Id,n){    
    if (truefalse==true){
        for (i=1;i<=n;i++) {
            ShowElement(eval('getElement("'+Id+i+'")'));
            SwapBackground(Id+i,'leer.png');
        }
    }
    else {
        for (i=1;i<=n;i++) {
            HideElement(eval('getElement("'+Id+i+'")'));
        }
    }    
}
