/*
 * DO NOT REMOVE THIS NOTICE
 *
 * PROJECT:   mygosuMenu
 * VERSION:   1.4.2
 * COPYRIGHT: (c) 2003,2004 Cezary Tomczak
 * LINK:      http://gosu.pl/dhtml/mygosumenu.html
 * LICENSE:   BSD (revised)
 */

function XulMenu(id) {
    
    this.type = "horizontal";
    this.position = {
        "level1": { "top": 0, "left": 0},
        "levelX": { "top": 0, "left": 0}
    }
    this.zIndex = {
        "visible": 1,
        "hidden": -1
    }
    this.arrow1 = null;
    this.arrow2 = null;

    // Browser detection
    this.browser = {
        "ie": Boolean(document.body.currentStyle),
        "ie5": (navigator.appVersion.indexOf("MSIE 5.5") != -1 || navigator.appVersion.indexOf("MSIE 5.0") != -1)
    };
    if (!this.browser.ie) { this.browser.ie5 = false; }

    /* Initialize the menu */
    this.init = function() {
        if (!document.getElementById(this.id)) alert("Element '"+ this.id +"' does not exist in this document. XulMenu cannot be initialized.");
        if (this.type != "horizontal" && this.type != "vertical") { return alert("XulMenu.init() failed. Unknown menu type: '"+this.type+"'"); }
        document.onmousedown = click;
        if (this.browser.ie && this.browser.ie5) { this.fixWrap(); }
        this.fixSections();
        this.parse(document.getElementById(this.id).childNodes, this.tree, this.id);
    }

    /* Search for .section elements and set width for them */
    this.fixSections = function() {
        var arr = document.getElementById(this.id).getElementsByTagName("div");
        var sections = new Array();
        var widths = new Array();

        for (var i = 0; i < arr.length; i++) {
            //reisacher software start

            if (arr[i].className.substring(0,"Xulsection".length) == "Xulsection") 
            {
                sections.push(arr[i]);
            }
            /*
            if (arr[i].className == "Xulsection") {
                sections.push(arr[i]);
            }
            */
            //reisacher software ende
        }
        for (var i = 0; i < sections.length; i++) {
            widths.push(this.getMaxWidth(sections[i].childNodes));
        }
        for (var i = 0; i < sections.length; i++) {
            sections[i].style.width = (widths[i]) + "px";
        }
        if (self.browser.ie) {
            for (var i = 0; i < sections.length; i++) {
                this.setMaxWidth(sections[i].childNodes, widths[i]);
            }
        }
    }

    this.fixWrap = function() {
        var elements = document.getElementById(this.id).getElementsByTagName("a");
        for (var i = 0; i < elements.length; i++) {
            if (/item/.test(elements[i].className)) {
                elements[i].innerHTML = '<div nowrap="nowrap">'+elements[i].innerHTML+'</div>';
            }
        }
    }

    /* Search for an element with highest width, return that width */
    this.getMaxWidth = function(nodes) {
        var maxWidth = 0;
        for (var i = 0; i < nodes.length; i++) {
            //reisacher software start
            if (nodes[i].nodeType != 1 || nodes[i].className.substring(0,"Xulsection".length) == "Xulsection") { continue; }
            //if (nodes[i].nodeType != 1 || nodes[i].className == "Xulsection") { continue; }
            //reisacher software ende
            if (nodes[i].offsetWidth > maxWidth) maxWidth = nodes[i].offsetWidth;
        }
        return maxWidth;
    }

    /* Set width for item elements */
    this.setMaxWidth = function(nodes, maxWidth) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType == 1 && /item/.test(nodes[i].className) && nodes[i].currentStyle) {
                if (this.browser.ie5) {
                    nodes[i].style.width = (maxWidth) + "px";
                } else {
                    nodes[i].style.width = (maxWidth - parseInt(nodes[i].currentStyle.paddingLeft) - parseInt(nodes[i].currentStyle.paddingRight)) + "px";
                }
            }
        }
    }

    /* Parse menu structure, create events, position elements */
    this.parse = function(nodes, tree, id) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType != 1) { continue };
            
            //reisacher software start
            
            classname=nodes[i].className;

            if(classname.substring(0,"Xulbutton".length)=="Xulbutton") 
            {
              nodes[i].id = id + "-" + tree.length;
              tree.push(new Array());
              nodes[i].onmouseover = buttonOver;
              nodes[i].onclick = buttonClick;
            }
            else if(classname.substring(0,"Xulitem".length)=="Xulitem") 
            {
              nodes[i].id = id + "-" + tree.length;
              tree.push(new Array());
              nodes[i].onmouseover = itemOver;
              nodes[i].onmouseout = itemOut;
              nodes[i].onclick = itemClick;
            }
            else if(classname.substring(0,"Xulsection".length)=="Xulsection") 
            {
              nodes[i].id = id + "-" + (tree.length - 1) + "-section";
              var box1 = document.getElementById(id + "-" + (tree.length - 1));
              var box2 = document.getElementById(nodes[i].id);
              var el = new Element(box1.id);
              if (el.level == 1) {
                  if (this.type == "horizontal") {
                      box2.style.top = (box1.offsetTop + box1.offsetHeight + this.position.level1.top) + "px";
                      if (this.browser.ie5) {
                          box2.style.left = (this.position.level1.left) + "px";
                      } else {
                          box2.style.left = (box1.offsetLeft + this.position.level1.left) + "px";
                      }
                  } else if (this.type == "vertical") {
                      box2.style.top = (box1.offsetTop + this.position.level1.top) + "px";
                      if (this.browser.ie5) {
                          box2.style.left = (box1.offsetWidth + this.position.level1.left) + "px";
                      } else {
                          box2.style.left = (box1.offsetLeft + box1.offsetWidth + this.position.level1.left) + "px";
                      }
                  }
              } 
              else 
              {
                  box2.style.top = (box1.offsetTop + this.position.levelX.top) + "px";
                  box2.style.left = (box1.offsetLeft + box1.offsetWidth + this.position.levelX.left) + "px";
              }
            }
            else if(classname.substring(0,"arrow".length)=="arrow")
            {
              nodes[i].id = id + "-" + (tree.length - 1) + "-arrow";
            }
            
            /*
            switch (nodes[i].className) {
                case "Xulbutton":
                    nodes[i].id = id + "-" + tree.length;
                    tree.push(new Array());
                    nodes[i].onmouseover = buttonOver;
                    nodes[i].onclick = buttonClick;
                    break;
                case "Xulitem":
                    nodes[i].id = id + "-" + tree.length;
                    tree.push(new Array());
                    nodes[i].onmouseover = itemOver;
                    nodes[i].onmouseout = itemOut;
                    nodes[i].onclick = itemClick;
                    break;
                case "Xulsection":
                    nodes[i].id = id + "-" + (tree.length - 1) + "-section";
                    var box1 = document.getElementById(id + "-" + (tree.length - 1));
                    var box2 = document.getElementById(nodes[i].id);
                    var el = new Element(box1.id);
                    if (el.level == 1) {
                        if (this.type == "horizontal") {
                            box2.style.top = (box1.offsetTop + box1.offsetHeight + this.position.level1.top) + "px";
                            if (this.browser.ie5) {
                                box2.style.left = (this.position.level1.left) + "px";
                            } else {
                                box2.style.left = (box1.offsetLeft + this.position.level1.left) + "px";
                            }
                        } else if (this.type == "vertical") {
                            box2.style.top = (box1.offsetTop + this.position.level1.top) + "px";
                            if (this.browser.ie5) {
                                box2.style.left = (box1.offsetWidth + this.position.level1.left) + "px";
                            } else {
                                box2.style.left = (box1.offsetLeft + box1.offsetWidth + this.position.level1.left) + "px";
                            }
                        }
                    } else {
                        box2.style.top = (box1.offsetTop + this.position.levelX.top) + "px";
                        box2.style.left = (box1.offsetLeft + box1.offsetWidth + this.position.levelX.left) + "px";
                    }
                    break;
                case "arrow":
                    nodes[i].id = id + "-" + (tree.length - 1) + "-arrow";
                    break;
            }
            */
            //reisacher software ende
 
            if (nodes[i].childNodes) {
                //reisacher software start
                //if (nodes[i].className == "Xulsection") {
                if (nodes[i].className.substring(0,"Xulsection".length) == "Xulsection") {
                //reisacher software ende
                    this.parse(nodes[i].childNodes, tree[tree.length - 1], id + "-" + (tree.length - 1));
                } else {
                    this.parse(nodes[i].childNodes, tree, id);
                }
            }
        }
    }

    /* Hide all sections */
    this.hideAll = function() {
        for (var i = this.visible.length - 1; i >= 0; i--) {
            this.hide(this.visible[i]);
        }
    }

    /* Hide higher or equal levels */
    this.hideHigherOrEqualLevels = function(n) {
        for (var i = this.visible.length - 1; i >= 0; i--) {
            var el = new Element(this.visible[i]);
            if (el.level >= n) {
                this.hide(el.id);
            } else {
                return;
            }
        }
    }

    /* Hide a section */
    this.hide = function(id) {
        var el = new Element(id);
        //document.getElementById(id).className = (el.level == 1 ? "Xulbutton" : "Xulitem");
        //if (el.level > 1 && this.arrow2) {
        //    document.getElementById(id + "-arrow").src = this.arrow1;
        //}
        document.getElementById(id + "-section").style.visibility = "hidden";
        document.getElementById(id + "-section").style.zIndex = this.zIndex.hidden;
        if (this.visible.contains(id)) {
            if (this.visible.getLast() == id) {
                this.visible.pop();
            } else {
                throw "XulMenu.hide("+id+") failed, trying to hide element that is not deepest visible element";
            }
        } else {
            throw "XulMenu.hide("+id+") failed, cannot hide element that is not visible";
        }
    }

    /* Show a section */
    this.show = function(id) {
        var el = new Element(id);
        //document.getElementById(id).className = (el.level == 1 ? "Xulbutton-active" : "Xulitem-active");
        //if (el.level > 1 && this.arrow2) {
        //    document.getElementById(id + "-arrow").src = this.arrow2;
        //}
        document.getElementById(id + "-section").style.visibility = "visible";
        document.getElementById(id + "-section").style.zIndex = this.zIndex.visible;
        this.visible.push(id);
    }

    /* event, document.onmousedown */
    function click(e) {
        var el;
        if (e) {
            el = e.target.tagName ? e.target : e.target.parentNode;
        } else {
            el = window.event.srcElement;
            if (el.parentNode && /item/.test(el.parentNode.className)) {
                el = el.parentNode;
            }
        }
        if (!self.visible.length) { return };
        if (!el.onclick) { self.hideAll(); }
    }

    /* event, button.onmouseover */
    function buttonOver() {
        if (!self.visible.length) { return; }
        if (self.visible.contains(this.id)) { return };
        self.hideAll();
        var el = new Element(this.id);
        if (el.hasChilds()) {
            self.show(this.id);
        }
    }

    /* event, button.onclick */
    function buttonClick() {
        //this.blur();
        if (self.visible.length) 
        {
          //alert("unsichtbar machen");
          self.hideAll();
        } 
        else 
        {
          //alert("sichtbar machen");
          var el = new Element(this.id);
          if (el.hasChilds()) 
          {
              self.show(this.id);
          }
        }
    }

    /* event, item.onmouseover */
    function itemOver() {
        var el = new Element(this.id);
        self.hideHigherOrEqualLevels(el.level);
        if (el.hasChilds()) {
            self.show(this.id);
        }
    }

    /* event, item.onmouseout */
    function itemOut() {
        var el = new Element(this.id);
        if (!el.hasChilds()) {
            //document.getElementById(this.id).className = "Xulitem";
        }
    }

    /* event, item.onclick */
    function itemClick() {
        //this.blur();
        var el = new Element(this.id);
        self.hideHigherOrEqualLevels(el.level);
        if (el.hasChilds()) {
            self.show(this.id);
        }
    }

    function Element(id) {

        /* Get Level of given id
         * Examples: menu-1 (1 level), menu-1-4 (2 level) */
        this.getLevel = function() {
            var s = this.id.substr(this.menu.id.length);
            return s.substrCount("-");
        }

        /* Check whether an element has a sub-section */
        this.hasChilds = function() {
            return Boolean(document.getElementById(this.id + "-section"));
        }

        if (!id) { throw "XulMenu.Element(id) failed, id cannot be empty"; }
        this.menu = self;
        this.id = id;
        this.level = this.getLevel();
    }

    this.id = id;
    var self = this;

    this.tree = new Array(); /* Multidimensional array, structure of the menu */
    this.visible = new Array(); /* Example: Array("menu-0", "menu-0-4", ...), succession is important ! */
}

/* Check whether array contains given string */
if (typeof Array.prototype.contains == "undefined") {
    Array.prototype.contains = function(s) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === s) { return true; }
        }
        return false;
    }
}

/* Get the last element from the array */
if (typeof Array.prototype.getLast == "undefined") {
    Array.prototype.getLast = function() {
        return this[this.length-1];
    }
}

/* Counts the number of substring occurrences */
if (typeof String.prototype.substrCount == "undefined") {
    String.prototype.substrCount = function(s) {
        return this.split(s).length - 1;
    }
}





// +----------------------------------------------------------------+
// | Array functions that are missing in IE 5.0                     |
// | Author: Cezary Tomczak [www.gosu.pl]                           |
// | Free for any use as long as all copyright messages are intact. |
// +----------------------------------------------------------------+

// Removes the last element from an array and returns that element.
if (!Array.prototype.pop) {
    Array.prototype.pop = function() {
        var last;
        if (this.length) {
            last = this[this.length - 1];
            this.length -= 1;
        }
        return last;
    };
}

// Adds one or more elements to the end of an array and returns the new length of the array.
if (!Array.prototype.push) {
    Array.prototype.push = function() {
        for (var i = 0; i < arguments.length; ++i) {
            this[this.length] = arguments[i];
        }
        return this.length;
    };
}

// Removes the first element from an array and returns that element.
if (!Array.prototype.shift) {
    Array.prototype.shift = function() {
        var first;
        if (this.length) {
            first = this[0];
            for (var i = 0; i < this.length - 1; ++i) {
                this[i] = this[i + 1];
            }
            this.length -= 1;
        }
        return first;
    };
}

// Adds one or more elements to the front of an array and returns the new length of the array.
if (!Array.prototype.unshift) {
    Array.prototype.unshift = function() {
        if (arguments.length) {
            var i, len = arguments.length;
            for (i = this.length + len - 1; i >= len; --i) {
                this[i] = this[i - len];
            }
            for (i = 0; i < len; ++i) {
                this[i] = arguments[i];
            }
        }
        return this.length;
    };
}

// Adds and/or removes elements from an array.
if (!Array.prototype.splice) {
    Array.prototype.splice = function(index, howMany) {
        var elements = [], removed = [], i;
        for (i = 2; i < arguments.length; ++i) {
            elements.push(arguments[i]);
        }
        for (i = index; (i < index + howMany) && (i < this.length); ++i) {
            removed.push(this[i]);
        }
        for (i = index + howMany; i < this.length; ++i) {
            this[i - howMany] = this[i];
        }
        this.length -= removed.length;
        for (i = this.length + elements.length - 1; i >= index + elements.length; --i) {
            this[i] = this[i - elements.length];
        }
        for (i = 0; i < elements.length; ++i) {
            this[index + i] = elements[i];
        }
        return removed;
    };
}

/* Strip whitespace from the beginning and end of a string */
if (!String.prototype.trim) {
    String.prototype.trim = function() {
        return this.replace(/^\s*|\s*$/g, "");
    };
}





//reisacher software
//reisacher software
//reisacher software
//reisacher software
//reisacher software
//reisacher software
//reisacher software
//reisacher software
//reisacher software


//navigationsleiste standard
//navigationsleiste standard
//navigationsleiste standard
//navigationsleiste standard
//navigationsleiste standard
function none(){}


function Cookie() {
    this.get = function(name) {
        var cookies = document.cookie.split(";");
        for (var i = 0; i < cookies.length; ++i) {
            var a = cookies[i].split("=");
            if (a.length == 2) {
                a[0] = a[0].trim();
                a[1] = a[1].trim();
                if (a[0] == name) {
                    return unescape(a[1]);
                }
            }
        }
        return "";
    };
    this.set = function(name, value, seconds, path, domain, secure) {
        var cookie = (name + "=" + escape(value));
        if (seconds) {
            var date = new Date(new Date().getTime()+seconds*1000);
            cookie += ("; expires="+date.toGMTString());
        }
        cookie += (path    ? "; path="+path : "");
        cookie += (domain  ? "; domain="+domain : "");
        cookie += (secure  ? "; secure" : "");
        document.cookie = cookie;
    };
    this.del = function(name) {
        document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
    };
}




function rs_div_aufklappen(aelement)
{
  //alert(document.getElementById(aelement).style.display);
  if(document.getElementById(aelement))
  {
    var cookie = new Cookie();
    var tmp = cookie.get("rsmenu");
    cookie.del("rsmenu");
    
    if(document.getElementById(aelement).style.display=="block")
    {
      document.getElementById(aelement).style.display="none";
      tmp = tmp.replace(aelement+"|","");
    }
    else
    {
      document.getElementById(aelement).style.display="block";
      tmp = tmp+aelement+"|";
    }
    cookie.set("rsmenu",tmp);
  }
}










//navigationsleiste standard2
//navigationsleiste standard2
//navigationsleiste standard2
//navigationsleiste standard2
//navigationsleiste standard2
//navigationsleiste standard2
function rs_div_aufklappen2(boxid,itemid)
{
  var cookie = new Cookie();
  var tmp = cookie.get("rsmenu");
  cookie.del("rsmenu");
    
  if(document.getElementById(boxid))
  {
    
    if(document.getElementById(boxid).style.display=="block")
    {
      document.getElementById(boxid).style.display="none";
      tmp = tmp.replace(boxid+"|","");
    }
    else
    {
      //alle anderen zumachen die nicht in dem element liegen
      var rootid = rs_find_rootelement(itemid);
      rs_div_close(document.getElementById(rootid),itemid);
      document.getElementById(boxid).style.display="block";
      tmp=get_open_boxes_string(document.getElementById(rootid));
    }
  }
  else
  {
    //ist ein element auf level 0 ohne unterpunkte, alle zumachen
    var rootid = rs_find_rootelement(itemid);
    rs_div_close(document.getElementById(rootid),itemid);
    tmp=get_open_boxes_string(document.getElementById(rootid));
    //var cookie = new Cookie();
    //cookie.del("rsmenu");
  }
  cookie.set("rsmenu",tmp);
}

function rs_find_rootelement(aelement)
{
  //suche parent table
  var tmpnode = document.getElementById(aelement);
  for(i=0;i<20;i++)
  {
    tmpnode = tmpnode.parentNode;
    if(tmpnode.tagName.toLowerCase()=="table")
      break;
  }
  if(tmpnode)
  {
    return tmpnode.id;
  }
}

function get_open_boxes_string(prootelement)
{
  var i;
  var rootelement = prootelement;
  var fertig;
  fertig="";
  
  for(i=0;i<rootelement.childNodes.length;i++)
  {
    if(rootelement.childNodes[i].tagName)
    {
      if(rootelement.childNodes[i].tagName.toLowerCase()=="tbody" || rootelement.childNodes[i].tagName.toLowerCase()=="td" || rootelement.childNodes[i].tagName.toLowerCase()=="tr")
      {
        var tmp="";
        tmp = get_open_boxes_string(rootelement.childNodes[i]);
        if(tmp!="")
        {
          if(fertig=="")
            fertig=tmp;
          else
            fertig=fertig+"|"+tmp;
        }
      }
      else if(rootelement.childNodes[i].id)
      {
        if(rootelement.childNodes[i].id.substring(0,3)=="box" && rootelement.childNodes[i].style.display=="block")
        {
          if(fertig=="")
            fertig=rootelement.childNodes[i].id;
          else
            fertig=fertig+"|"+rootelement.childNodes[i].id;
            
          //ein offenes gefunden, ist darunter noch eins offen?
          var tmp="";
          tmp = get_open_boxes_string(rootelement.childNodes[i]);
          if(tmp!="")
          {
            if(fertig=="")
              fertig=tmp;
            else
              fertig=fertig+"|"+tmp;
          }
        }
      }
    }
  }
  return fertig;
}

function rs_is_inbox(pboxid,pitemid)
{
  //nachschauen ob item in der box liegt 
  //oder in einer darüberliegenden box....
  //dann true
  //sonst false
  var boxelement=document.getElementById(pboxid);
  var itemid=pitemid;
  var i;
  
  for(i=0;i<boxelement.childNodes.length;i++)
  {
    //alert("2");
    if(boxelement.childNodes[i].tagName)
    {
      if(boxelement.childNodes[i].id)
      {
        if(boxelement.childNodes[i].id==itemid)
        {
          return true;
          break;
        }
        if(boxelement.childNodes[i].id.substring(0,3)=="box")
        {
          //eine box gefunden, diese auch noch durchsuchen
          if(rs_is_inbox(boxelement.childNodes[i].id,itemid)==true)
          {
            return true;
            break;
          }
        }
      }
    }
  }
  return false;
}

function rs_div_close(prootelement,pitemid)
{
  var i;
  var rootelement = prootelement;
  var itemid = pitemid;
  
  for(i=0;i<rootelement.childNodes.length;i++)
  {
    if(rootelement.childNodes[i].tagName)
    {
      if(rootelement.childNodes[i].tagName.toLowerCase()=="tbody" || rootelement.childNodes[i].tagName.toLowerCase()=="td" || rootelement.childNodes[i].tagName.toLowerCase()=="tr")
      {
        rs_div_close(rootelement.childNodes[i],itemid);
      }
      else if(rootelement.childNodes[i].id)
      {
        if(rootelement.childNodes[i].id.substring(0,3)=="box" && rootelement.childNodes[i].style.display=="block")
        {
          //ein offenes gefunden, prüfen ob es zu dem guten gehört oder ob geschlossen werden muss
          if(rs_is_inbox(rootelement.childNodes[i].id,itemid)==false)
            rootelement.childNodes[i].style.display="none";
      
          rs_div_close(rootelement.childNodes[i],itemid);
        }
      }
    }
  }
}

//standardleiste und standardleiste2
//standardleiste und standardleiste2
//standardleiste und standardleiste2
//standardleiste und standardleiste2
function rs_init()
{
  var cookie = new Cookie();
  var tmp = cookie.get("rsmenu");
  tmp = tmp.trim();
  if(tmp!="")
  {
    var a = tmp.split("|");
    for(x=0;x<a.length;x++)
    {
      a[x]=a[x].trim();
      if(a[x]!="")
      {
        if(document.getElementById(a[x]))
        {
          document.getElementById(a[x]).style.display="block";
        }
      }
    }
  }
}










function rs_div_aufklappen3(hintergrundtemplateid,boxid,itemid)
{
  var cookie = new Cookie();
  //var tmp = cookie.get(hintergrundtemplateid);
  cookie.del(hintergrundtemplateid);
    
  if(document.getElementById(boxid))
  {
    
    if(document.getElementById(boxid).style.display=="block")
    {
      document.getElementById(boxid).style.display="none";
      tmp = tmp.replace(boxid+"|","");
    }
    else
    {
      //alle anderen zumachen die nicht in dem element liegen
      var rootid = rs_find_rootelement(itemid);
      rs_div_close(document.getElementById(rootid),itemid);
      document.getElementById(boxid).style.display="block";
      tmp=get_open_boxes_string(document.getElementById(rootid));
    }
  }
  else
  {
    //ist ein element auf level 0 ohne unterpunkte, alle zumachen
    var rootid = rs_find_rootelement(itemid);
    rs_div_close(document.getElementById(rootid),itemid);
    tmp=get_open_boxes_string(document.getElementById(rootid));
    //var cookie = new Cookie();
    //cookie.del("rsmenu");
  }
  cookie.set(hintergrundtemplateid,tmp);
}


function rs_init3(hintergrundtemplateid)
{
  var cookie = new Cookie();
  var tmp = cookie.get(hintergrundtemplateid);
  tmp = tmp.trim();
  //alert(tmp);
  if(tmp!="")
  {
    var a = tmp.split("|");
    for(x=0;x<a.length;x++)
    {
      a[x]=a[x].trim();
      if(a[x]!="")
      {
        if(document.getElementById(a[x]))
        {
          document.getElementById(a[x]).style.display="block";
        }
      }
    }
  }
}







