

// Globaler Debugmodus für diese Lib
var debug = false;
/////////////////////////////////////////////////////////////////////////
function hideElement(EltId)
{
    var Elt = document.getElementById(EltId);
    if (Elt)
        Elt.style.display = "none";
}
function showElement(EltId)
{
    var Elt = document.getElementById(EltId);
    if (Elt)
        Elt.style.display = "";
}


function blibsClientDetection(){
    var agt = navigator.userAgent.toLowerCase();

    this.platform = navigator.platform.toLowerCase();
    this.name = agt;

    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);

    this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)));
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));
    this.nav4 = (this.nav && (this.major == 4));
    this.nav6 = (this.nav && (this.major == 5));

    this.ie   = (agt.indexOf("msie") != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major == 4));

    this.opera = (agt.indexOf("opera") != -1);
    this.safari = (agt.indexOf("safari") != -1);
    this.konqueror = (agt.indexOf("konqueror") != -1);

    this.nav6up = this.nav && (this.major >= 5);
    this.ie4up  = this.ie  && (this.major >= 4);

    if (debug)
    {
        test = "";
        for (var i in this)
        {
            test += "[" + i + "] - " + this[i] + "\n";
        }
        alert(test);
    }
}
// End blibsClientDetection
var cD = new blibsClientDetection();

/////////////////////////////////////////////////////////////////////////

function appendClientDetectionToNextRequest()
{
    blibsCDObject = new Array();
    for (var i in cD)
    {
        blibsCDObject.push("blibsCD[" + i + "]=" + cD[i]);
    }
    blibsCDObjectString = blibsCDObject.join("&");

    allAnchors = document.getElementsByTagName("a");
    for (var key in allAnchors)
    {
        if (!isNaN(key) && allAnchors[key])
        {
            hrefWithCD = allAnchors[key].getAttribute('href');
            if (hrefWithCD.indexOf('javascript') != 0)
            {
                if (!hrefWithCD.indexOf("?"))
                    hrefWithCD += "?" + blibsCDObjectString;
                else
                    hrefWithCD += "&" + blibsCDObjectString;

                allAnchors[key].setAttribute('href', hrefWithCD);
            }
        }
    }

    var allForms = document.getElementsByTagName("form");

    for (var key = 0; key < allForms.length; key++)
    {
        if (allAnchors[key])
        {
            for (var i in cD)
            {
                var Input = document.createElement("input");
                Input.setAttribute("type", "hidden");
                Input.setAttribute("name", "blibsCD[" + i + "]");
                Input.setAttribute("value", cD[i]);
                allForms[key].appendChild(Input);
            }
        }
    }
}

/////////////////////////////////////////////////////////////////////////

var blibsToggleImageCache = new Array();
function blibstoggleimg(ImageElt, mode)
{
    imageIdent = ImageElt.src.replace(/_lo\..*/, "");
    imageIdent = imageIdent.replace(/_hi\..*/, "");

    extension = ImageElt.src.substring(ImageElt.src.lastIndexOf(".") + 1,ImageElt.src.length);

    if (!blibsToggleImageCache[imageIdent])
    {
        blibsToggleImageCache[imageIdent] = new Array();
        blibsToggleImageCache[imageIdent]["hi"] = new Image();
        blibsToggleImageCache[imageIdent]["hi"].src = imageIdent + "_hi." + extension;
        blibsToggleImageCache[imageIdent]["lo"] = new Image();
        blibsToggleImageCache[imageIdent]["lo"].src = imageIdent + "_lo." + extension;
    }
    ImageElt.src = blibsToggleImageCache[imageIdent][mode].src;
}
// End blibsToggleImageCache

// globales Array mit Referenzen auf andere Fenster
function openPopup(path,popName,width,height,left,top,scrolling,resize)
{
   if (scrolling == "")
   {
      scrolling = "no";
   }
   if (top == "")
   {
      top = 10;
   }
   if (left == "")
   {
      left = 10;
   }
   if (resize == "")
   {
      resize = "yes";
   }
   resizable = ",resizeable=" + resize + "";
   settings = 'height=' + height + ', width=' + width + ', top=' + top + ',left=' + left + ',scrollbars=' + scrolling + ',resizable=' + resize;
   var newWin = window.open(path, popName, settings);

   if(newWin.innerWidth != width)
       newWin.innerWidth = width;

   if(newWin.innerHeight != height)
       newWin.innerHeight = height;

   newWin.focus();

   return false;
}
// openPopup

/////////////////////////////////////////////////////////////////////////

/**
 * Setzt den übergebenen CMD ind angegebene form und fragt mit optionaleer
 * Nachricht ob man sicher ist.
 */
var copyboxitems = Array();

function setCmdAndSubmit(formname, cmd, msg)
{
    var formular = !formname? document.forms[0] : eval("document.forms." + formname);

    if(!formular)
    {
        if (debug)
            alert("FEHLER! Das Formular '" + formname + "' existiert nicht");

        return false;
    }

    formular.cmd.value = cmd;
    checkMultiSelectboxes();

    if(msg && !confirm(msg))
        return false;

    formular.submit();
    return true;
}

/////////////////////////////////////////////////////////////////////////

function setCmdAndSubmitValue(formname, cmd, name, value, msg)
{
   if (!formname)
   {
      var Form = document.forms[0];
      formname = Form.name;
   }
   else
      var Form = eval ("document." + formname);

   var Input = document.createElement("input");
   Input.setAttribute("type", "hidden");
   Input.setAttribute("name", name);
   Input.setAttribute("value", value);
   Form.appendChild(Input);

   return setCmdAndSubmit(formname, cmd, msg);
}
// End setCmdAndSubmitValue

/////////////////////////////////////////////////////////////////////////

function resetForm(formname)
{
   formular = eval("document." + formname);
   if (formular)
   {
      formular.reset();
   }
   else
   {
      if (debug)
         alert("FEHLER! Das Formular '" + formname + "' existiert nicht");

      return false;
   }
}
// End resetForm

/////////////////////////////////////////////////////////////////////////

function checkMultiSelectboxes()
{
    for (i = 0; i < copyboxitems.length; i++)
    {
        var pairs = copyboxitems[i].split(",");
        copyMultiselectItems(pairs[0], pairs[1]);
    }
}
// End checkMultiSelectboxes

/////////////////////////////////////////////////////////////////////////

function copyMultiselectItems(formname, box)
{
    box = eval("document." + formname + "." + box);
    if (box)
    {
        for(var i=0; i < box.length; i++)
        {
            box.options[i].selected = true;
        }
        box.name += "[]";
    }
    return false;
}

/////////////////////////////////////////////////////////////////////////

function removeSelectedItemsFromBox(destName, formname)
{
    Destbox = eval("document." + formname + "." + destName);

    zaehler = Destbox.length;
    for(var i=0; i < zaehler; i++)
    {
        if(Destbox.options[i].selected)
        {
            Destbox.options[i] = null;
            i = 0;
            zaehler = Destbox.length;
        }
    }
    return false;
}

/////////////////////////////////////////////////////////////////////////

function copySelectedItemsToBox(sourceName, destName, formname)
{
    Sourcebox = eval("document." + formname + "." + sourceName);
    Destbox = eval("document." + formname + "." + destName);
    for(var i=0; i < Sourcebox.length; i++)
    {
        if(Sourcebox.options[i].selected == true)
        {
            if (!item_exists_in_box(formname, destName, Sourcebox.options[i]))
            {
                NeuerEintrag = new Option(Sourcebox.options[i].text, Sourcebox.options[i].value, false,false);
                Destbox.options[Destbox.length] = NeuerEintrag;
            }
        }
    }
    return false;
}
/////////////////////////////////////////////////////////////////////////

function item_exists_in_box(formname, boxname, OptionElt)
{
    Box = eval("document." + formname + "." + boxname);
    retval = false;
    for(var k=0; k < Box.length; k++)
    {
        if (Box.options[k].value == OptionElt.value)
        {
            retval = true;
        }
    }
    return retval;
}


/////////////////////////////////////////////////////////////////////////
function getEltPosTop(elt)
{
    if (elt.offsetParent)
    {
        //alert("class='"+  elt.offsetParent.getAttribute("class") + "' top: " + elt.offsetParent.offsetTop);
        retVal = elt.offsetTop + getEltPosTop(elt.offsetParent);
    }
    else
    {
        retVal = elt.offsetTop;
    }

    return retVal;
}
// getEltPosTop

/////////////////////////////////////////////////////////////////////////

function getEltPosLeft(elt)
{
    return (elt.offsetParent) ? elt.offsetLeft+getEltPosLeft(elt.offsetParent) : elt.offsetLeft;
}
// getEltPosLeft

/////////////////////////////////////////////////////////////////////////

function setEltTop(elt, y){
    if(cD.nav4) elt.top=y;
    else if(cD.ie4up) elt.style.pixelTop=y;
    else if(cD.nav6up) elt.style.top=y+"px";
    else if(cD.opera) elt.style.top=y;
}
// End setEltTop

/////////////////////////////////////////////////////////////////////////

function setEltLeft(elt, x){
    if(cD.nav4) elt.left=x;
    else if(cD.ie4up) elt.style.pixelLeft=x;
    else if(cD.nav6up) elt.style.left=x + "px";
    else if(cD.opera) elt.style.left=x;
}
// End setEltLeft

/////////////////////////////////////////////////////////////////////////

function moveElementToReferenceElement(ElementToMove, ReferenceElement)
{
   if (typeof ElementToMove != 'object')
       ElementToMove = document.getElementById(ElementToMove);

   if (typeof ReferenceElement != 'object')
       ReferenceElement = document.getElementById(ReferenceElement);

   if (ElementToMove.style.position != 'absolute' && ElementToMove.style.position !=  'relative')
       ElementToMove.style.position = 'absolute';

   setEltTop(ElementToMove, getEltPosTop(ReferenceElement));
   setEltLeft(ElementToMove, getEltPosLeft(ReferenceElement));
}
// End moveElementByReferenceElement

var formtosubmit = false;
var cmdtosubmit = false;
var messagetosubmit = false;
var permitSubmitOnReturn = false;
function submitOnReturn(MyEvent)
{
    if (!permitSubmitOnReturn)
    {
        if (!MyEvent)
        {
            MyEvent = window.event;
        }
        if (MyEvent.which)
        {
            Tastencode = MyEvent.which;
        }
        else if (MyEvent.keyCode)
        {
            Tastencode = MyEvent.keyCode;
        }
        if (Tastencode == 13)
        {
            if (formtosubmit)
            {
                if (cmdtosubmit)
                {
                    msg = "";
                    if (messagetosubmit)
                    {
                        msg = messagetosubmit;
                    }
                    setCmdAndSubmit(formtosubmit, cmdtosubmit, msg);
                }
                else
                {
                    myform = eval("document." + formtosubmit);
                    myform.submit();
                }
            }
        }
    }
}

/////////////////////////////////////////////////////////////////////////

// Diese beiden Funktionen gehören zusammen

var formSubmission;
function disableSubmitOnReturn(evt)
{
   evt = (evt)? evt : ((window.event)? window.event : "");

   if (evt && (evt.keyCode == 13 || evt.which == 13))
   {
       //alert( evt.keyCode); // IE and Safari
       //alert( evt.which); // FF

      formSubmission = false;
   }
}

function checkSubmitOnReturn()
{
   var returnValue = formSubmission;
   formSubmission = true;
   return returnValue;
}

/////////////////////////////////////////////////////////////////////////

function getTastencode(MyEvent)
{
    if (!MyEvent)
    {
        MyEvent = window.event;
    }
    if (MyEvent.which)
    {
        Tastencode = MyEvent.which;
    }
    else if (MyEvent.keyCode)
    {
        Tastencode = MyEvent.keyCode;
    }
    return Tastencode;
}

function setCSSClassById(eltId, cssclass)
{
    if (!eltId || !document.getElementById(eltId))
        alert("Could not set CSS-Class on id '" + eltId + "'");

    setCSSClass(document.getElementById(eltId), cssclass);
}
function setCSSClass(elt, cssclass)
{
    if (!elt)
        return;

    if (elt.className)
        elt.className = cssclass;
    else
    {
        for (var counter in elt.attributes)
        {
            if (elt.attributes[counter].nodeType == 2 &&
                (elt.attributes[counter].nodeName == "class" || elt.attributes[counter].nodeName == "CLASS")
               )
            {
                elt.attributes[counter].nodeValue = cssclass;
                break;
            }
        }
    }
}

function addCSSClassById(eltId, cssclass)
{
    if (!eltId || !document.getElementById(eltId))
        alert("Could not add CSS-Class on id '" + eltId + "'");

    addCSSClass(document.getElementById(eltId), cssclass);
}

function addCSSClass(elt, cssclass)
{
    if (!elt)
        return;

    if (elt.className.search(cssclass) == -1)
        elt.className += ' '+cssclass;
}

function removeCSSClassById(eltId, cssclass)
{
    if (!eltId || !document.getElementById(eltId))
        alert("Could not remove CSS-Class on id '" + eltId + "'");

    removeCSSClass(document.getElementById(eltId), cssclass);
}

function removeCSSClass(elt, cssclass)
{
    if (!elt)
        return;

    if (elt.className)
    {
        var regex = new RegExp('\s?'+cssclass, 'g');
        elt.className = elt.className.replace(regex, '');
    }
}

function loadDataExtended(keyname, id, appendUniqueId, specialargs, specialId, discardRequest, host)
{
    if (debug)
        alert("function loadDataExtended() - DEBUG: called!");

    if (host)
    {
       myHostname = host;
       myPort = '';
    }
    else
    {
       myHostname = window.location.hostname;
       myPort = window.location.port;
    }

    myPath = window.location.pathname;

    paramStr = window.location.search;
    keyValArr = new Array();
    if (paramStr)
    {
        paramArray = paramStr.substr(1, paramStr.length).split("&");

        for (var field in paramArray)
        {
            parts = paramArray[field].split("=");
            keyValArr[parts[0]] = parts[1];
        }
    }

    keyValArr[keyname] = id;

    if (!keyValArr["sid"] && blibsSid != "")
    {
        keyValArr["sid"] = blibsSid;
    }
    if (!keyValArr["id"] && blibsRequestId != "")
    {
        keyValArr["id"] = blibsRequestId;
    }
    if (specialId)
    {
        keyValArr["id"] = specialId;
    }

    paramStr = "?";

    for (fieldname in keyValArr)
    {
       if (discardRequest && (fieldname == "id" || fieldname == "sid" || fieldname == keyname))
          paramStr += fieldname + "=" + keyValArr[fieldname] + "&";

       if (!discardRequest)
          paramStr += fieldname + "=" + keyValArr[fieldname] + "&";
    }

    if (paramStr != "?")
    {
        if (specialargs)
        {
            paramStr += specialargs;
        }
        else
        {
            paramStr = paramStr.substr(0, paramStr.length - 1);
        }
    }
    else
    {
        if (specialargs)
        {
            paramStr += specialargs;
        }
        else
        {
            paramStr = "";
        }
    }

    if (myPort == '' || myPort == '80')
    {
       url = window.location.protocol + "//" +  myHostname + myPath + paramStr;
    }
    else
    {
       url = window.location.protocol + "//" +  myHostname + ":" + myPort + myPath + paramStr;
    }

    if (appendUniqueId)
    {
        timeobj = new Date();
        url += "&cmdid=" + timeobj.getTime();
    }
    window.location.href = url;
}

function copyNewItemToComboSelect(FormName, SelectBoxName, TextInputName)
{
    TextInput = eval("document." + FormName + "." + TextInputName);
    if (TextInput.value)
    {
        Selectbox = eval("document." + FormName + "." + SelectBoxName);
        NewOption = new Option(TextInput.value, TextInput.value, false, true);
        Selectbox.options[Selectbox.length] = NewOption;
        TextInput.value = "";
    }
}

/**
 * Liefert eine uniqueId
 */
function getUniqueId()
{
    if (!uniqueId || document.getElementById(uniqueId))
    {
        timeobj = new Date();
        var uniqueId = timeobj.getTime();
    }

    if (document.getElementById(uniqueId))
    {
        do {
            var uniqueId = getUniqueId();
        } while(document.getElementById(uniqueId));
    }
    return  uniqueId;
}
// End getUniqueId

//////////////////////////////////////
/**
 * Methoden die das OnClick-Event desjenigen Elternelements
 * solange entfernen wie der Mauszeiger über dem aufrufenden Element ist
 */
// Cache für die entfernten onclick-Events
var onClickEventCache = new Array();

//
// Cached das dem Link nächstgelegene onclick-Event
//
function removeParentOnClick(Elt)
{
    if (!Elt.id)
        Elt.setAttribute("id", getUniqueId());

    if (Elt.id)
    {
        ParentNode = findNextOnClick(Elt);
        if (ParentNode)
        {
            onClickEventCache[Elt.id] = ParentNode.getAttribute("onclick");
            if (debug)
                alert("function removeParentOnClick() - DEBUG: Caching '" + onClickEventCache[Elt.id] + "' for link with id '" + Elt.id + "'");

            ParentNode.setAttribute("onclick", ";");
        }
        else
        {
            if (debug)
                alert("function removeParentOnClick() - WARNING: No onclick-event found in parents of link with id '" + Elt.id + "'");

            Elt.removeAttribute("onmouseout");
            Elt.removeAttribute("onmouseover");
        }
    }
    else
    {
        if (debug)
            alert("function removeParentOnClick() - ERROR: Could not use function removeParentOnClick() on link without uniqueId");

        Elt.removeAttribute("onmouseout");
        Elt.removeAttribute("onmouseover");
    }
}
// End removeParentOnClick

//
// Stellt das von removeParentOnClick gecachete und entfernte
// onclick-Event wieder her.
//
function recoverParentOnClick(Elt)
{
    if (Elt.id)
    {
        if (onClickEventCache[Elt.id])
        {
            ParentNode = findNextOnClick(Elt);
            if (ParentNode)
            {
                if (debug)
                    alert("function recoverParentOnClick() - DEBUG: Recovering " + onClickEventCache[Elt.id] + " to parents onclick of link with id '" + Elt.id + "'");
                ParentNode.setAttribute("onclick", onClickEventCache[Elt.id]);
            }
            else
            {
                if (debug)
                    alert("function recoverParentOnClick() - WARNING: No onclick-event found in parents of link with id '" + Elt.id + "'");

                Elt.removeAttribute("onmouseout");
                Elt.removeAttribute("onmouseover");
            }
        }
        else
        {
            if (debug)
                alert("function recoverParentOnClick() - ERROR: Could not find cached onclick event for link with id " + Elt.id);

            Elt.removeAttribute("onmouseout");
            Elt.removeAttribute("onmouseover");
        }
    }
    else
    {
        if (debug)
            alert("function recoverParentOnClick() - ERROR: Could not use function recoverParentOnClick() on link without uniqueId");

        Elt.removeAttribute("onmouseout");
        Elt.removeAttribute("onmouseover");
    }
}
// recoverParentOnClick

//
// Findet nächstes übergeordnetes onclick-Event
//
function findNextOnClick(Elt)
{
    if (!Elt.parentNode)
        return false;

    if (Elt.parentNode.nodeType == 1 && Elt.parentNode.getAttribute("onclick"))
        return Elt.parentNode;

    return findNextOnClick(Elt.parentNode);
}
// End findNextOnClick

//////////////////////////////////////
// ENDE Methoden bzgl. onclicl-Event
//////////////////////////////////////

//
// Zeigt Objektstruktur in Alertfenstern
//
function showObjTree(Elt)
{
    myList = Array();
    var count = 0;
    var testStr = "";
    for (var key in Elt)
    {
        count++;
        testStr += "[" + key + "] " + Elt[key] + "\n";
        if (count > 15)
        {
            myList[myList.length] = testStr;
            testStr = '';
            count = 0;
        }
    }
    for (i = 0; i < myList.length; i++)
        alert(myList[i]);
}
// End showObjTree

//////////////////////////////////////
var optionTimeout = false;
var selectBoxId;
var openSelectBoxes = new Array();
function showSelectBoxOptions(selectBoxId)
{
    initBLibsSelectbox(selectBoxId);
    if (selectBoxId)
    {
        for (var openId in openSelectBoxes)
        {
            hideSelectBoxOptionsOnClick(openId);
        }

        showElement("selectboxoptions" + selectBoxId);
        showElement("selectBoxArrowLinkHide" + selectBoxId);
        hideElement("selectBoxArrowLinkShow" + selectBoxId);

        showElement("selectedTDHide" + selectBoxId);
        hideElement("selectedTDShow" + selectBoxId);

        openSelectBoxes = new Array();
        openSelectBoxes[selectBoxId] = true;
    }
}

function hideSelectBoxOptionsOnClick(selectBoxId)
{
    if (selectBoxId)
    {
        hideElement("selectboxoptions" + selectBoxId);
        hideElement("selectBoxArrowLinkHide" + selectBoxId);
        showElement("selectBoxArrowLinkShow" + selectBoxId);

        hideElement("selectedTDHide" + selectBoxId);
        showElement("selectedTDShow" + selectBoxId);
    }
    else
    {
        if (debug)
            alert("hideSelectBoxOptionsOnClick - no id");
    }
}
function hideSelectBoxOptions()
{
    if (selectBoxId)
    {
        hideElement("selectboxoptions" + selectBoxId);
        hideElement("selectBoxArrowLinkHide" + selectBoxId);
        showElement("selectBoxArrowLinkShow" + selectBoxId);

        hideElement("selectedTDHide" + selectBoxId);
        showElement("selectedTDShow" + selectBoxId);
    }
    else
    {
        if (debug)
            alert("hideSelectBoxOptions - no id");
    }
}
function startOptionTimeOut()
{
    optionTimeout = setTimeout("hideSelectBoxOptions()", 500);
}
function clearOptionTimeOut()
{
    window.clearTimeout(optionTimeout);
}

function selectBLibsSelectbox(ClickedDiv,selectBoxId,submitValue,submitFormOnClick,specialCmd)
{
    SelectedDiv = document.getElementById("selectedOptionDivShow" + selectBoxId);
    SelectedDiv.innerHTML = "";

    Clone = ClickedDiv.cloneNode(true);
    setCSSClass(Clone, "blibsIconSelectboxOption");
    Clone.style.padding = "0px;";
    Clone.style.width = "";
    if (cD.ie)
    {
        Clone.onmouseover = '';
        Clone.onmouseout = '';
    }
    else
    {
        Clone.removeAttribute("onmouseover");
        Clone.removeAttribute("onmouseout");
    }

    SelectedDiv.appendChild(Clone);

    SelectedDiv = document.getElementById("selectedOptionDivHide" + selectBoxId);
    SelectedDiv.innerHTML = "";
    Clone = Clone.cloneNode(true);
    SelectedDiv.appendChild(Clone);

    hideSelectBoxOptionsOnClick(selectBoxId);

    formular = findParentForm(ClickedDiv);

    Input = document.getElementById("selectedOptionHidden" + selectBoxId);

    Input.setAttribute("value", submitValue);
    formular.appendChild(Input);

    if (submitFormOnClick)
    {
	var cmd = (specialCmd)?(specialCmd):('filter');
        setCmdAndSubmit(formular.name,cmd,'');
    }
}
//////////////////////////////////////
function findParentForm(Elt)
{
    if (Elt && Elt.tagName == "FORM")
        return Elt;

    if (Elt.parentNode && Elt.parentNode != "BODY")
        return findParentForm(Elt.parentNode);

    return false;
}
// End findParentForm

function initBLibsSelectbox(selectBoxId)
{
    Positioner = document.getElementById('selectboxpositioner' + selectBoxId);
    posLeft = getEltPosLeft(Positioner);
    posTop = getEltPosTop(Positioner);

    posTop = (cD.ie)?(posTop + 4):(posTop);
    optionsDiv = document.getElementById('selectboxoptions' + selectBoxId);
    setEltLeft(optionsDiv, posLeft);
    setEltTop(optionsDiv, posTop);
}



////////////////////////////////////
// Methoden für die Mehrfachauswahl in Tabellen
////////////////////////////////////

function selectMultiselectItem(formName, tableIdent, ImageElt, modeToSet, currentSelectionCountElementName)
{
    blibstoggleimg(ImageElt, modeToSet);
    onclick = ImageElt.getAttribute("onclick");
    if (modeToSet == "hi")
    {
        onclick = onclick.replace(/\'hi\'/, "'lo'");
    }
    else
    {
        onclick = onclick.replace(/\'lo\'/, "'hi'");
    }
    ImageElt.setAttribute("onclick", onclick);


    FormularElt = eval("document." + formName);
    itemId = ImageElt.getAttribute('id').substr(ImageElt.getAttribute('id').lastIndexOf("_") + 1);

    HiddenElts = document.getElementsByName("multiselectedItem[" + itemId + "]");
    hiddenValue = (modeToSet == "hi")?(1):(0);
    updateCurrentSelectionCount(formName, currentSelectionCountElementName, hiddenValue);
    if (!HiddenElts[0])
    {
        var Input = document.createElement("input");
        Input.setAttribute("type", "hidden");
        Input.setAttribute("name", "multiselectedItems[" + itemId + "]");
        Input.setAttribute("value", hiddenValue);
        FormularElt.appendChild(Input);
        HiddenElts = document.getElementsByName("multiselectedItems[" + itemId + "]");
    }
    else
    {
        HiddenElt = HiddenElts[0];
        HiddenElt.setAttribute("value", hiddenValue);
    }
}

function selectAllMultiselectItems(formName, tableIdent, currentSelectionCountElementName)
{
    for (key in document.images)
    {
       if (typeof(document.images[key]) == "object")
       {
          if (document.images[key].getAttribute("class") == "multiselect_" + tableIdent)
             selectMultiselectItem(formName, tableIdent, document.images[key], "hi", currentSelectionCountElementName);
       }
    }
}

function clearAllMultiselectItems(formName, tableIdent, currentSelectionCountElementName)
{
    for (key in document.images)
    {
       if (typeof(document.images[key]) == "object")
        {
           if (document.images[key].getAttribute("class") == "multiselect_" + tableIdent)
              selectMultiselectItem(formName, tableIdent, document.images[key], "lo", currentSelectionCountElementName);
        }
    }
}

function invertMultiselectSelection(formName, tableIdent, currentSelectionCountElementName)
{
    for (key in document.images)
    {
        if (typeof(document.images[key]) == "object")
        {
            if (document.images[key].getAttribute("class") == "multiselect_" + tableIdent)
            {
                isHi = document.images[key].getAttribute("onclick").search(/\'hi\'/);
                modeToSet = (isHi == -1)?('lo'):('hi');
                selectMultiselectItem(formName, tableIdent, document.images[key], modeToSet, currentSelectionCountElementName);
            }
        }
    }
}

function updateCurrentSelectionCount(formName, currentSelectionCountElementName, incOrDec)
{
    CounterElt = document.getElementById(currentSelectionCountElementName);
    if (CounterElt)
    {
        if (CounterElt.tagName.toLowerCase() == "input")
        {
            HiddenConfirmedCounts = document.getElementsByName(currentSelectionCountElementName + "HiddenConfirmed");
            HiddenConfirmedCount = HiddenConfirmedCounts[0];

            HiddenCurrentCounts = document.getElementsByName(currentSelectionCountElementName + "HiddenCurrent");
            HiddenCurrentCount = HiddenCurrentCounts[0];

            currentValue = HiddenCurrentCount.getAttribute("value");
            if (incOrDec == 0)
            {
                currentValue--;
            }
            else
            {
                currentValue++;
            }
            HiddenCurrentCount.setAttribute("value", currentValue);
            CounterElt.setAttribute("value", "(" + HiddenConfirmedCount.getAttribute("value") + "/" + currentValue + ")");

            styleStr = CounterElt.getAttribute("style");
            if (!styleStr || !styleStr.search(/color\:red\;/))
            {
                styleStr += ";color:red;";
                CounterElt.setAttribute("style", styleStr);
            }
        }
        else
        {
            if (debug)
                alert("Feature to set current selectioncount in elements of typ " + CounterElt.tagName + " not implemented yet");
        }
    }
}

//////////////////////////////////////////////////////////////////////
// Methode zum Hide und Show für andere Elemente bei Selectboxauswahl
//////////////////////////////////////////////////////////////////////
function changeTargetField(Box,ident)
{
    value = Box.value;
    if(!ident) ident = '';
    for (element in elementList)
    {
        if (elementList[element] == (value+ident))
            removeCSSClass(document.getElementById(elementList[element]), 'hideRow');
        else if(elementList[element].slice(value.length) == ident)
            addCSSClass(document.getElementById(elementList[element]), 'hideRow');
    }
}


/**
 * Bringt den Spacer innerhalb eines Divs den FormatIcon baut auf die selben
 * Abmessungen
 */
function adjustIconSize(divId, iconId)
{
    div = document.getElementById(divId);
    icon = document.getElementById(iconId);
    icon.setAttribute('width', div.offsetWidth);
    icon.setAttribute('height', div.offsetHeight);
}


function copyNode(NodeToCopy,TargetNode)
{
    if (typeof NodeToCopy != 'object')
        NodeToCopy = document.getElementById(NodeToCopy);

    if (typeof TargetNode != 'object')
        TargetNode = document.getElementById(TargetNode);

    return TargetNode.appendChild(NodeToCopy.cloneNode(true));
}

var postProcessingJobs = new Array();
function postProcessing()
{
    for (var i in postProcessingJobs)
    {
        eval(postProcessingJobs[i]);
    }
}

function setTableCreatorColumn(formname, moduleId, colCount, value)
{
    /**
     * Absendewert ins Formular hängen
     */
    FormularElt = eval("document." + formname);
    InputElt = eval("document." + formname + ".colconfig_" + moduleId + "_" + colCount);
    if (!InputElt)
    {
        var InputElt = document.createElement("input");
        InputElt.setAttribute("type", "hidden");
        InputElt.setAttribute("name", "colconfig_" + moduleId + "_" + colCount);
        FormularElt.appendChild(InputElt);
    }
    InputElt.setAttribute("value", value);

    // MarkerTd bauen
    MarkerTd = document.getElementById('mark_' + moduleId + "_" + colCount);
    markerClass = (value == 1)?("columnConfigMarkerTdActive"):("columnConfigMarkerTd");
    setCSSClass(MarkerTd, markerClass);
    if (value == 1)
    {
        MarkerTd.setAttribute('onclick', "setTableCreatorColumn('" + formname + "','" + moduleId + "'," + colCount + ",0);");
    }
    else
    {
        MarkerTd.removeAttribute('onclick');
    }

    ClickTd = document.getElementById('click_' + moduleId + "_" + colCount);
    clickTdClass = (value == 1)?('columnConfigTdActive'):('columnConfigTd');
    setCSSClass(ClickTd, clickTdClass);
    if (value == 1)
    {
        ClickTd.removeAttribute('onmouseover');
        ClickTd.removeAttribute('onmouseout');
        ClickTd.setAttribute('onclick', "setTableCreatorColumn('" + formname + "','" + moduleId + "'," + colCount + ",0);");
    }
    else
    {
        ClickTd.setAttribute('onmouseover', "setCSSClassById('mark_" + moduleId + "_" + colCount + "','columnConfigMarkerTdActive');setCSSClassById('click_" + moduleId + "_" + colCount + "','columnConfigTdActive');");
        ClickTd.setAttribute('onmouseout', "setCSSClassById('mark_" + moduleId + "_" + colCount + "','columnConfigMarkerTd');setCSSClassById('click_" + moduleId + "_" + colCount + "','columnConfigTd');");

        ClickTd.setAttribute('onclick', "setTableCreatorColumn('" + formname + "','" + moduleId + "'," + colCount + ",1);");
    }

}



/** Drag and Drop gedönz **/
var startPos = new Array();
var MovingElt = false;

function setMovingElt(Elt)
{
    MovingElt = Elt;
}

function startMoving(Ereignis)
{
    if (MovingElt)
    {
        if (!MovingElt.id)
            MovingElt.setAttribute("id", getUniqueId());

        startPos[MovingElt.id] = new Array();
        startPos[MovingElt.id]["x"] = getEltPosLeft(MovingElt);
        startPos[MovingElt.id]["y"] = getEltPosTop(MovingElt);
        startPos[MovingElt.id]["offsetX"] = Ereignis.pageX - getEltPosLeft(MovingElt);
        startPos[MovingElt.id]["offsetY"] = Ereignis.pageY - getEltPosTop(MovingElt);

        MovingElt.style.left= startPos[MovingElt.id]["x"] + "px";
        MovingElt.style.top = startPos[MovingElt.id]["y"] + "px";
        MovingElt.style.position = 'absolute';
    }
}

function stopMoving(Elt)
{
    Elt.style.position = 'static';
    MovingElt = false;
}

function mouseMove(Ereignis)
{
    if (MovingElt)
    {
        xPos = Ereignis.pageX - startPos[MovingElt.id]["offsetX"];
        yPos = Ereignis.pageY - startPos[MovingElt.id]["offsetY"];

        MovingElt.style.left = xPos + "px";
        MovingElt.style.top  = yPos + "px";
        MovingElt.style.position = 'absolute';
    }
}


///////////////////////////////////////////
//Ein Formulartestgedönz
///////////////////////////////////////////

function ebobSubmit(cmd, args, isSecure)
{
    requestArgs = new Array();
    requestArgs['cmd'] = cmd;

    for (key in args)
    {
        helper = args[key].split('=');
        requestArgs[helper[0]] = helper[1];
    }

    EbobDefaultForm = getEbobDefaultForm(isSecure);

    if (!requestArgs['sid'])
        requestArgs['sid'] = blibsSid;

    if (!requestArgs['id'])
        requestArgs['id'] = blibsRequestId;

    if (!requestArgs['cmdid'])
        requestArgs['cmdid'] = getUniqueId();

    for (var key in requestArgs)
    {
        Input = document.createElement("input");
        Input.setAttribute("type", "hidden");
        Input.setAttribute("name", key);
        Input.setAttribute("value", requestArgs[key]);
        EbobDefaultForm.appendChild(Input);
    }

    EbobDefaultForm.submit();
}

////////////////////////////////////////////////////

function getEbobDefaultForm(isSecure)
{
    EbobDefaultForm = document.forms.ebobdefaultform;

    if (!EbobDefaultForm)
        EbobDefaultForm = createEbobDefaultForm(isSecure);

    return EbobDefaultForm;
}

////////////////////////////////////////////////////

function createEbobDefaultForm(isSecure)
{
    bodies = document.getElementsByTagName("body");

    var EbobDefaultFormular = document.createElement("form");

    var action= window.location.pathname;

    if(isSecure === true)
    {
        if(window.location.protocol != 'https:')
            action = 'https://' + window.location.hostname + window.location.pathname;
    }

    EbobDefaultFormular.setAttribute('action', action);
    EbobDefaultFormular.setAttribute("method", "POST");
    EbobDefaultFormular.setAttribute("name", "ebobdefaultform");

    return bodies[0].appendChild(EbobDefaultFormular);
}

////////////////////////////////////////////////////

function toggleDisplay(id, display)
{
   var Elt = document.getElementById(id);

   if (Elt.style.display != '' && Elt.style.display != 'none')
      Elt.style.display = 'none';
   else
      Elt.style.display = display;
}

////////////////////////////////////////////////////

function setDisplay(id, display)
{
   var Elt = document.getElementById(id);
   Elt.style.display = display;
}


////////////////////////////////////////////////////

function toggleDisplayAndIcon(id, display, ImgElt, modeNormal, modeHidden)
{
   toggleDisplay(id, display);

   var Elt = document.getElementById(id);
   imageSrc = ImgElt.getAttribute('src');
   if (Elt.style.display != 'none')
   {
      imageSrc = imageSrc.replace(modeHidden, modeNormal);
   }
   else
   {
      imageSrc = imageSrc.replace(modeNormal, modeHidden);
   }
   ImgElt.setAttribute('src', imageSrc);
}

////////////////////////////////////////////////////

function toggleDisplayAndClass(id, display, Elt, classNormal, classHidden)
{
   toggleDisplay(id, display);
   var ToggleElt = document.getElementById(id);

   if (ToggleElt.style.display != 'none')
      Elt.className = Elt.className.replace(classHidden, classNormal);
   else
      Elt.className = Elt.className.replace(classNormal, classHidden);
}

////////////////////////////////////////////////////

function removeAllChildNodes(DOMElt)
{
    if (typeof DOMElt == 'string')
        DOMElt = document.getElementById(DOMElt);

    if (typeof DOMElt != 'object')
        return;

    remove = new Array();
    for (var index in DOMElt.childNodes)
        remove.push(DOMElt.childNodes[index]);

    for (var index in remove)
    {
//         alert('remove child ' + index + ' type ' + (typeof remove[index]));
        if (typeof remove[index] == 'object')
            DOMElt.removeChild(remove[index]);
    }
}

////////////////////////////////////////////////////

function relocateDOMElement(ElementToMove, NewParentElement)
{
    if (typeof ElementToMove != 'object')
        ElementToMove = document.getElementById(ElementToMove);

    if (typeof NewParentElement != 'object')
        NewParentElement = document.getElementById(NewParentElement);

    NewParentElement.appendChild(ElementToMove.parentNode.removeChild(ElementToMove));
}

////////////////////////////////////////////////////

function moveElementToBody(elementId)
{
   var ElementToMove = document.getElementById(elementId);
   var BodyElt = document.getElementsByTagName('body')[0];

   var position = getPosition(ElementToMove);

   // rausholen und direkt an den Body hängen
   var MovedElement = BodyElt.appendChild(ElementToMove.parentNode.removeChild(ElementToMove));

   // absolut positionieren auf die alten Koordinaten
   setPosition(MovedElement, position);
}

////////////////////////////////////////////////////

function getPosition(element)
{
   var position = { x: 0, y: 0 };

   while(element)
   {
      position.x += element.offsetLeft;
      position.y += element.offsetTop;
      element = element.offsetParent;
   }

   return position;
}

////////////////////////////////////////////////////

function setPosition(element, position)
{
   var parentPosition = element.offsetParent? getPosition(element.offsetParent) : { x: 0, y: 0 };

   element.style.position = 'absolute';
   element.style.left = (position.x - parentPosition.x) + 'px';
   element.style.top = (position.y - parentPosition.y) + 'px';
}

////////////////////////////////////////////////////

function hideElementsByClassName(className,excludeEltId)
{
   var BodyElt = document.getElementsByTagName('body')[0];
   var Elementlist = document.getElementsByClassName(className,BodyElt);

   if(Elementlist.length)
   {
      for (var index in Elementlist)
      {
         if (!excludeEltId || Elementlist[index].getAttribute('id') != excludeEltId)
            Elementlist[index].style.display = 'none';
      }
   }
}

////////////////////////////////////////////////////

function setDisplayByClassName(className,displayValue,containerElt,excludeEltId)
{
   if(!className || !displayValue) return;
   var Elementlist = document.getElementsByClassName(className,containerElt);

   if(Elementlist.length)
   {
      for (var index in Elementlist)
      {
         if (!excludeEltId && Elementlist[index].id != excludeEltId)
            Elementlist[index].style.display = displayValue;
      }
   }
}

////////////////////////////////////////////////////


document.getElementsByClassName = function(searchClass,node,tag)
{
   var classElements = new Array();
   if ( node == null )
      node = document;
   if ( tag == null )
      tag = '*';
   var els = node.getElementsByTagName(tag);
   var elsLen = els.length;
   var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
   for (i = 0, j = 0; i < elsLen; i++) {
      if ( pattern.test(els[i].className) ) {
         classElements[j] = els[i];
         j++;
      }
   }

   return classElements;
}

/**
 * This enables assigning object methods to event handlers
 *
 * Usage (within object):
 *
 *       element.onclick = this.myMethod.bindEventListener(this, arg1, arg2,...);
 *
 */
function argsToArray(pseudoArray) {
    var result = new Array();
    for (var i = 0; i < pseudoArray.length; i++)
        result.push(pseudoArray[i]);
    return result;
};

Function.prototype.bind = function (object) {
    var method = this;
    var oldArguments = argsToArray(arguments).slice(1);
    return function () {
        var newArguments = argsToArray(arguments);
        return method.apply(object, oldArguments.concat(newArguments));
    };
};

Function.prototype.bindEventListener = function (object) {
    var method = this;
    var oldArguments = argsToArray(arguments).slice(1);
    return function (event) {
        var newArguments = argsToArray(arguments);
        return method.apply(object, newArguments.concat(oldArguments));
    };
};

////////////////////////////////////////////////////

var Page = function() {};

Page.load = function(arguments, isSecure)
{
    if(!arguments instanceof Object)
        throw 'Argument must be of type object';

    var protocol = '';

    if(isSecure === true)
    {
        protocol = 'https:';
    }
    else
    {
        if(isSecure === false)
            protocol = 'http:';
        else
            protocol = window.location.protocol;
    }

    var href = protocol + '//';
    href    += window.location.hostname;
    href    += window.location.port;
    href    += window.location.pathname;

    var search = new Array();

    for(var key in arguments)
        search.push(key + '=' + arguments[key]);

    if(search.length)
        href += '?' + search.join('&');

    if(window.location.hash)
        href += window.location.hash;

    window.location.href = href;

    return false;
};

////////////////////////////////////////////////////

/**
 * @class Importer
 */
var Importer = function(){};

/**
 * Loaded script hash
 */
Importer._Scripts = new Object();

/**
 * Imports a javascript file within javascript
 */
Importer.load = function(jsPath)
{
    if(Importer._Scripts[jsPath])
        return;

    document.write('<script type="text/javascript" src="'+ jsPath +'" />');
    Importer._Scripts[jsPath] = jsPath;
};
// End Importer.load

////////////////////////////////////////////////////

function html_entity_decode(string)
{
   var textarea = document.createElement('textarea');
   textarea.innerHTML = string;
   return textarea.value;
}
// End html_entity_decode

////////////////////////////////////////////////////

/**
 * Checks that a key event is a numeric key
 *
 * Example:
 * <input type="text"
 *        onkeypress="return isNumericKey(event);">
 */
function isNumericKey(e)
{
    var k = document.all ? e.keyCode : e.which;
    return ((k > 47 && k < 58) || k == 8 || k == 0);
}
// End isNumericKey

////////////////////////////////////////////////////

/**
 * Extracts numeric data from string
 *
 * Example:
 * <input type="text"
 *        onkeypress="return isNumericKey(event);"
 *        onchange="this.value = extractNumeric(this.value);">
 */
function extractNumeric(str)
{
    return str.replace(/\D/g,"");
}
// End extractNumeric

////////////////////////////////////////////////////

function trim(str)
{
   // Erst führende, dann Abschließende Whitespaces entfernen
   // und das Ergebnis dieser Operationen zurückliefern
   return str.replace (/^\s+/, '').replace (/\s+$/, '');
}

////////////////////////////////////////////////////

function ucfirst(str)
{
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1, str.length-1);
}

////////////////////////////////////////////////////

function insertAfter(parent, node, referenceNode)
{
    parent.insertBefore(node, referenceNode.nextSibling);
}

////////////////////////////////////////////////////
