
var undefined;
var istmenu = 0;
var warmenu = 0;





var menu = new Array;
var menu2 = new Array;

for (var i=1; i<10; i++){
  menu[i] = new Image();
  menu2[i] = new Image();
  menu[i].src = "/kiosk/grafik/hauptmenu_" + i + ".gif";
  menu2[i].src = "/kiosk/grafik/hauptmenu_" + i + "_.gif";
}

function over(x) {

  document.images["hauptmenu-" + x].src = menu2[x].src;

}


function out(x) {

  warmenu = istmenu;

  if (warmenu != x) {
    document.images["hauptmenu-" + x].src = menu[x].src;
  }

}


function untermenu(index) {

  warmenu = istmenu;

  if (warmenu != 0) {

    var currentUntermenuID = 'menu-unter-' + warmenu;
    var element = document.getElementById(currentUntermenuID);

    document.images["hauptmenu-" + warmenu].src = menu[warmenu].src;

    if (element) {
      element.style.display = 'none';
    }

    istmenu = 0;

  }

  if (index != 0 && index != warmenu) {

    var currentUntermenuID = 'menu-unter-' + index;
    var element = document.getElementById(currentUntermenuID);

    document.images["hauptmenu-" + index].src = menu2[index].src;

    if (element) {
      element.style.display = 'block';
    }

    istmenu = index;

  }

}

var undefined;

var popupSettings = {};

popupSettings['default'] = {};
popupSettings['default'].windowName = 'Default';
popupSettings['default'].settings = 'width=500,height=580';


function openPopup(url,settingsName) {

  var settings = popupSettings[settingsName];
  var newPopup;

  if (!settings) {
    settings = popupSettings['default'];
  }

  newPopup = window.open(url,settings.windowName,settings.settings);
  newPopup.focus();

}


function popup_oeffnen(x) {
  window.open(x,"Fenster1","width=530,height=600,directories=0,location=0,toolbar=0,scrollbars=1,status=0,resizable=1,menubar=0");
}


function mov_oeffnen(x) {
  window.open(x,"Fenster2","width=530,height=521,directories=0,location=0,toolbar=0,scrollbars=0,status=0,resizable=0,menubar=0");
}



function deleteDefaultValue(id,value) {

  var element = document.getElementById(id);

  if (element) {

    if (element.value == value) {
      element.value = '';
    }

  }

  return true;

}

var undefined;





function Navigation(id) {
  if (arguments.length>1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  this._id = undefined;
  this._setID(id);
  this._navigationAllowedStatus = undefined;
  this._direction = 'horizontal';
  this._dependVertical = 'top';
  this._dependHorizontal = 'right';
  this._highlightActiveRoot = 'no';
  this._highlightActiveClassPostfix = undefined;
  this._rootLeft = 0;
  this._rootTop = 0;
  this._differenceVertical = 0;
  this._differenceHorizontal = 0;
  this._navigationStructure = {};
  this._registerStructureItem = {};
  this._chacheRoot = '';
  this._chacheRootHTMLString = undefined;
  this._activeMenu = {};
  this._menuInUse = false;
  this._containerIDPrefix = this.id() + '_Nav';
  this._itemIDPrefix = this.id() + '_Item';
  this._timeout = undefined;
  this._delay = undefined;
  this._getNavigationStructureHTMLRoot = true;
  
  this.setDelay(1000);
}

Navigation.prototype.toString = function() {
  return "\n[Navigation - id: " + this + "]\n";
}


Navigation.prototype.id = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._id = str;
  }
  return this._id;
}

Navigation.prototype.navigationStructure = function(obj) {
  if (arguments.length) {
    if (typeof obj != "object") {
      focus();
      throw new Error("Argument ist nicht vom Typ Object!");
    }
    this._navigationStructure = obj;
  }
  return this._navigationStructure;
}

Navigation.prototype.registerStructureItem = function(obj) {
  if (arguments.length) {
    if (typeof obj != "object") {
      focus();
      throw new Error("Argument ist nicht vom Typ Object!");
    }
    this._registerStructureItem = obj;
  }
  return this._registerStructureItem;
}

Navigation.prototype._direction = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._direction = str;
  return this._direction;
}


Navigation.prototype._setID = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.id(str);
}

Navigation.prototype._setRegisterStructureItem = function(obj) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof obj != "object") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.registerStructureItem(obj);
}

Navigation.prototype._setRootPosition = function() {
  var id = this._containerIDPrefix + 'root';
  if (document.getElementById(id)){
    var elem = document.getElementById(id);
    if (elem.offsetParent){
      elem = elem.offsetParent;
    }
    this._rootLeft = elem.offsetLeft;
    this._rootTop = elem.offsetTop;
  }
}

Navigation.prototype._getNavigationStructureHTML = function(structure, html, id, loopPosition) {
  var containerClassName = '';
  var first = undefined;
  if (loopPosition == 1){
    first = true;
  }
  var containerStyle = 'display: none;';
  if (this._getNavigationStructureHTMLRoot){
    containerStyle = 'display: block;';    
  }
  if (NavigationItem.hasInstance(id) && NavigationItem.getInstance(id).style()){
    containerStyle += NavigationItem.getInstance(id).style();
  }
  if (NavigationItem.hasInstance(id) && NavigationItem.getInstance(id).className()){
    containerClassName = 'class="'+ NavigationItem.getInstance(id).className() +'"';
  }
  this._getNavigationStructureHTMLRoot = false;
  if (this._direction == 'vertical'){
    if (loopPosition > 1 &&  loopPosition <= 2){
      html += '<div id="'+ id +'"  '+ containerClassName +' style="'+ containerStyle +' position: absolute;">';
    } else  if (loopPosition > 2){
      html += '<div id="'+ id +'"  '+ containerClassName +' style="'+ containerStyle +' position: static;">';
    } else {
      html += '<div id="'+ id +'" '+ containerClassName +' style="'+ containerStyle +' position: absolute;">';
    }
    for (var i in structure){
      var id = this._containerIDPrefix + i;
      var cssStyle = '';
      var cssClassName = '';
      var href = 'href="javascript:void(0);"';
      var target = '';
      var onclick = '';
      var label = this.registerStructureItem()[id].label();
      var title = '';
      if (this.registerStructureItem()[id].style()){
        cssStyle = 'style="' + this.registerStructureItem()[id].style() + '" ';
      }
      if (this.registerStructureItem()[id].className()){
        cssClassName = 'class="' + this.registerStructureItem()[id].className() + '" ';
      }
      if (this.registerStructureItem()[id].href()){
        href = 'href="' + this.registerStructureItem()[id].href() + '" ';
      }
      if (this.registerStructureItem()[id].target()){
        target = 'target="' + this.registerStructureItem()[id].target() + '" ';
      }
      if (this.registerStructureItem()[id].onclick()){
        onclick = 'onclick="' + this.registerStructureItem()[id].onclick();
      } else {
      }
      if (this.registerStructureItem()[id].title()){
        title = 'title="' + this.registerStructureItem()[id].title() + '" ';
      }
      if (first){
        html += '<div id="'+ this._itemIDPrefix + this.registerStructureItem()[id].id() +'" style="position: static; float: left;">\n';
      } else {
        html += '<div id="'+ this._itemIDPrefix + this.registerStructureItem()[id].id() +'" style="position: static;">\n';
      }
      if (this._dependVertical == 'top'){
        if (typeof structure[i] == 'object'){
          html += this._getNavigationStructureHTML(structure[i], '', id, loopPosition+1);
        } 
      }
      if (this.registerStructureItem()[id].type() == 0){
        if (this.registerStructureItem()[id].subClassName()){
          cssClassName = 'class="' + this.registerStructureItem()[id].subClassName() + '" ';
        }
        if (this.registerStructureItem()[id].subStyle()){
          cssStyle = 'style="' + this.registerStructureItem()[id].subStyle() + ' display: block;" ';
        }
        if (first){
          html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ href +' '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' onmouseout="Navigation.getInstance(\''+ this.id() +'\').collapseMenu();" onmouseover="Navigation.getInstance(\''+ this.id() +'\').displaySubmenu(\''+ this.registerStructureItem()[id].id() +'\');" '+ title +'>' + label +'</a>\n';
        } else {
          html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' onmouseout="Navigation.getInstance(\''+ this.id() +'\').collapseMenu();" '+ title +'>' + label +'</a>\n';
        }
      } else {
        html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ href +' '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' onmouseout="Navigation.getInstance(\''+ this.id() +'\').collapseMenu();" onmouseover="Navigation.getInstance(\''+ this.id() +'\').displaySubmenu(\''+ this.registerStructureItem()[id].id() +'\');" '+ title +'>' + label +'</a>\n';
      }
      if (this._dependVertical != 'top'){
        if (typeof structure[i] == 'object'){
          html += this._getNavigationStructureHTML(structure[i], '', id, loopPosition+1);
        } 
      } 
      html += '</div>\n'; 
    }
    html += '</div>';
  } else {
    html += '<div id="'+ id +'"  '+ containerClassName +' style="'+ containerStyle +' position: absolute;">\n';
    for (var i in structure){
      var id = this._containerIDPrefix + i;
      var cssStyle = '';
      var cssClassName = '';
      var href = 'href="javascript:void(0);"';
      var target = '';
      var onclick = '';
      var label = this.registerStructureItem()[id].label();
      var title = '';
      if (this.registerStructureItem()[id].style()){
        cssStyle = 'style="' + this.registerStructureItem()[id].style() + '" ';
      }
      if (this.registerStructureItem()[id].className()){
        cssClassName = 'class="' + this.registerStructureItem()[id].className() + '" ';
      }
      if (this.registerStructureItem()[id].href()){
        href = 'href="' + this.registerStructureItem()[id].href() + '" ';
      }
      if (this.registerStructureItem()[id].target()){
        target = 'target="' + this.registerStructureItem()[id].target() + '" ';
      }
      if (this.registerStructureItem()[id].onclick()){
        onclick = 'onclick="' + this.registerStructureItem()[id].onclick() + '; Navigation.getInstance(\''+ this.id() +'\').displaySubmenu(\''+ this.registerStructureItem()[id].id() +'\');"';
      } else {
        onclick = 'onclick="Navigation.getInstance(\''+ this.id() +'\').displaySubmenu(\''+ this.registerStructureItem()[id].id() +'\');"';
      }
      if (this.registerStructureItem()[id].title()){
        title = 'title="' + this.registerStructureItem()[id].title() + '" ';
      }
      if (first){
        html += '<div id="'+ this._itemIDPrefix + this.registerStructureItem()[id].id() +'" style="position: static; float: left;">\n';
      } else {
        html += '<div id="'+ this._itemIDPrefix + this.registerStructureItem()[id].id() +'" style="position: static;">\n';
      }
      if (this.registerStructureItem()[id].type() == 0){
        if (this.registerStructureItem()[id].subClassName()){
          cssClassName = 'class="' + this.registerStructureItem()[id].subClassName() + '" ';
        }
        if (this.registerStructureItem()[id].subStyle()){
          cssStyle = 'style="display: block; ' + this.registerStructureItem()[id].subStyle() + '" ';
        }
        html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ href +' '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' '+ title +'>' + label +'</a>\n';
      } else {
        html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ href +' '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' '+ title +'>' + label +'</a>\n';
      }
      html += '</div>\n';
    } 
    if (first){
      html += '<div class="float-aufheben"><br /></div>\n';
    }
    html += '</div>\n';
    loopPosition++;
    for (var i in structure){
      var id = this._containerIDPrefix + '' + i;
      if (typeof structure[i] == 'object'){
        html += this._getNavigationStructureHTML(structure[i], '', id, loopPosition);
      } 
    }
  }
  return html;
}

Navigation.prototype._setHighlightedItems = function(id) {
  var items = [];
  var activeItem = NavigationItem.getInstance(id);
  items.push(activeItem);
  for (var i=0; i<items.length; i++){
    var elem = document.getElementById('button_' + items[i].id());
    if (elem){
      var className = items[i].subClassName() + this._highlightActiveClassPostfix;
      elem.className = className;
    }  
  }
}

Navigation.prototype._setOffHighlightedItems = function(id) {
  var items = [];
  var activeItem = NavigationItem.getInstance(id);
  items.push(activeItem);
  for (var i=0; i<items.length; i++){
    var elem = document.getElementById('button_' + items[i].id());
    if (elem){
      var className = items[i].subClassName();
      elem.className = className;
    }  
  }
}



Navigation.prototype.setDirection = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._direction = str;
}

Navigation.prototype.setChacheRoot = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._chacheRoot = str;
}

Navigation.prototype.setChacheRootHTMLString = function(obj) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof obj != "object") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._chacheRootHTMLString = obj;
}

Navigation.prototype.getNavigationAllowedStatus = function() {
  if (document.getElementById){
    this._navigationAllowedStatus = true;
  }
  return this._navigationAllowedStatus;
}

Navigation.prototype.setDelay = function(n) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (!NavigationTools.checkNumber(n)) {
    focus();
    throw new Error("Argument ist nicht vom Typ Number!");
  }
  if (document.all){
    if (n < 1200){
      n = n + (n/5);
    }
  }
  this._delay = n;
}

Navigation.prototype.setHighlightActiveRoot = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._highlightActiveRoot = str;
}

Navigation.prototype.setHighlightActiveClassPostfix = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._highlightActiveClassPostfix = str;
}

Navigation.prototype.setDependHorizontal = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._dependHorizontal = str;
}

Navigation.prototype.setDependVertical = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._dependVertical = str;
}

Navigation.prototype.setDifferenceVertical = function(n) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (!NavigationTools.checkNumber(n)) {
    focus();
    throw new Error("Argument ist nicht vom Typ Number!");
  }
  this._differenceVertical = n;
}

Navigation.prototype.setDifferenceHorizontal = function(n) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (!NavigationTools.checkNumber(n)) {
    focus();
    throw new Error("Argument ist nicht vom Typ Number!");
  }
  this._differenceHorizontal = n;
}

Navigation.prototype.setNavigationStructure = function(obj) {
  if(!this.getNavigationAllowedStatus()){
    return;
  }
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof obj != "object") {
    focus();
    throw new Error("Argument ist nicht vom Typ HMTL-Object!");
  }
  var structure = {};
  structure = Navigation._getNavigationStructureByNode(obj, structure, '', 0, this._containerIDPrefix);
  this.navigationStructure(structure);
  this._setRegisterStructureItem(NavigationItem._registerInstance);
}

Navigation.prototype.drawNavigationStructure = function(html) {
  if(!this.getNavigationAllowedStatus()){
    return;
  }
  if(!document.getElementById(this.id())){
    return;
  }
  var html = '';
  html += this._getNavigationStructureHTML(Navigation._getFirstItem(this.navigationStructure()), '', this._containerIDPrefix + 'root', 1);
  /*
  var win = window.open('','test');
  var doc = win.document;
  doc.open();
  doc.write(html);
  doc.close();
  */
  document.getElementById(this.id()).innerHTML = html;
  this._setRootPosition();
}

Navigation.prototype.hideVisitedNavigation = function(id) {
  var item = NavigationItem.getInstance(id);
  for (var i in this._activeMenu){
    var rootPos = i.split(this._containerIDPrefix)[1];
    if (item.rootObj()[rootPos] == undefined){
      if (this._activeMenu[i]['elem']){
        this._activeMenu[i]['elem'].style.display = 'none';
        this._setOffHighlightedItems(this._activeMenu[i]['item'].id());
      }
      delete this._activeMenu[i];
    }
  }
}

Navigation.prototype.showActiveNavigation = function(id) {
  var elem = document.getElementById(id);
  if (elem){
    this.setElementPosition(id);
    if (elem.style.display == 'block'){
      elem.display = 'none';
    } else {
      elem.style.display = 'block';
    } 
    if (this._highlightActiveRoot == 'yes'){
      if (this._highlightActiveClassPostfix){
        this._setHighlightedItems(id);
      }
    }
  }
}

Navigation.prototype.setElementPosition = function(id) {
  var item = NavigationItem.getInstance(id);
  var rootPos = id.split(this._containerIDPrefix)[1];
  var activeItem = NavigationItem.createInstance(this._itemIDPrefix +''+ id, '');
  if (this._direction == 'vertical'){
    if (document.getElementById(id)){
      if (this._dependHorizontal=='left'){
        document.getElementById(id).style.marginRight =  this._differenceHorizontal + 'px';
      } else {
        document.getElementById(id).style.marginLeft =  this._differenceHorizontal + 'px';
      }
      document.getElementById(id).style.marginTop = this._differenceVertical + 'px';
    }
  } else {  
    var _top;
    var _left;
    if (item.rootObj()[rootPos]){
      var idxR = parseFloat(item.rootObj()[rootPos] -1);
      if (item.rootArr()[idxR]){
        var rootItem = NavigationItem.getInstance(this._containerIDPrefix +''+ item.rootArr()[idxR]);
        if (this._dependHorizontal == 'left'){
          if (rootItem.properties().getLeft() != undefined){
            _left = parseFloat(rootItem.properties().getLeft() - item.properties().getWidth());
          } else {
            if (document.getElementById(this._itemIDPrefix +''+ id)){
            _left = parseFloat(activeItem.properties().getLeft() - item.properties().getWidth());
            }
          }
        } else {
          if (rootItem.properties().getRight() != undefined){
            _left = rootItem.properties().getRight();
          } else {
            if (document.getElementById(this._itemIDPrefix +''+ id)){
            _left = activeItem.properties().getRight();
            }
          }
        }
        if (this._dependVertical=='middle'){
          if (document.getElementById(this._itemIDPrefix +''+ id)){
            _top = parseFloat(activeItem.properties().getTop() + parseFloat(activeItem.properties().getHeight() / 2));
          }
        } else if (this._dependVertical=='bottom'){
          if (document.getElementById(this._itemIDPrefix +''+ id)){
            _top = activeItem.properties().getBottom();
          } 
        } else {
          if (document.getElementById(this._itemIDPrefix +''+ id)){
            _top = activeItem.properties().getTop();
          } 
        }
      }
    }
    if (document.getElementById(id)){
      if (_top != undefined){
        if (idxR > 0){
          document.getElementById(id).style.top = parseFloat(parseFloat(_top + this._differenceVertical) - this._rootTop) + 'px';
        } else {
          document.getElementById(id).style.top = parseFloat(parseFloat(_top + 55) - this._rootTop) + 'px';
        }  
      }
      if (navigator.userAgent.match(/Opera/)){
        document.getElementById(id).style.position = 'absolute';
      }
      if (_left != undefined){   
        if (idxR > 0){  
          document.getElementById(id).style.left = parseFloat(parseFloat(_left + this._differenceHorizontal) - this._rootLeft) + 'px';
        } else {  
          document.getElementById(id).style.left = parseFloat(parseFloat(_left - activeItem.properties().getWidth()) - this._rootLeft) + 'px';
        }
      }
      if (navigator.userAgent.match(/Opera/)){
        document.getElementById(id).style.position = 'absolute';
      }
    }
  }
}

Navigation.prototype.displaySubmenu = function(id) {
  this._menuInUse = true;
  var item = NavigationItem.getInstance(id);
  var elem = undefined;
  if (document.getElementById(id)){
    elem = document.getElementById(id);
  }
  this.hideVisitedNavigation(id);
  this.showActiveNavigation(id);
  if (this._direction == 'vertical'){
    if (this._activeMenu[id] || item.type() == 1){
      this._menuInUse = false;
      this.hideAll();
      return;
    }
  }
  this._activeMenu[id] = {};
  if (document.getElementById(id)){
    this._activeMenu[id]['elem'] = document.getElementById(id);
  }
  this._activeMenu[id]['item'] = item;
}

Navigation.prototype.collapseMenu = function() {
  this._menuInUse = false;
  if (this._timeout){
    window.clearTimeout(this._timeout);
  }
  var funcStr = 'Navigation.getInstance(\''+ this.id() +'\').hideAll()';
  this._timeout = window.setTimeout(funcStr, this._delay);
}

Navigation.prototype.hideAll = function() {
  if (this._timeout){
    window.clearTimeout(this._timeout);
  }
  if (!this._menuInUse){
    for (var i in this._activeMenu){
      if (this._activeMenu[i]['elem']){
        this._activeMenu[i]['elem'].style.display = 'none';
        this._setOffHighlightedItems(this._activeMenu[i]['item'].id());
      }
      delete this._activeMenu[i];
    }
  }
}


Navigation._defaultID = [];

Navigation._registerInstance = {};

Navigation._getNavigationStructureHTMLRoot = true;

Navigation._attributesToIE = {};
Navigation._attributesToIE['src'] = 'src';
Navigation._attributesToIE['style'] = 'style';
Navigation._attributesToIE['align'] = 'align';
Navigation._attributesToIE['title'] = 'title';
Navigation._attributesToIE['alt'] = 'alt';
Navigation._attributesToIE['valign'] = 'valign';
Navigation._attributesToIE['vspace'] = 'vspace';
Navigation._attributesToIE['hspace'] = 'hspace';
Navigation._attributesToIE['class'] = 'className';
Navigation._attributesToIE['border'] = 'border';
Navigation._attributesToIE['cellspacing'] = 'cellspacing';
Navigation._attributesToIE['cellpadding'] = 'cellpadding';
Navigation._attributesToIE['data'] = 'data';
Navigation._attributesToIE['marginwidth'] = 'marginwidth';
Navigation._attributesToIE['marginheight'] = 'marginheight';
Navigation._attributesToIE['margintop'] = 'margintop';
Navigation._attributesToIE['marginleft'] = 'marginleft';
Navigation._attributesToIE['frameborder'] = 'frameborder';
Navigation._attributesToIE['dataformatas'] = 'dataformatas';
Navigation._attributesToIE['type'] = 'type';
Navigation._attributesToIE['width'] = 'width';
Navigation._attributesToIE['height'] = 'height';
Navigation._attributesToIE['onmouseover'] = 'onMouseover';
Navigation._attributesToIE['onmouseout'] = 'onMouseout';
Navigation._attributesToIE['onclick'] = 'onClick';
Navigation._attributesToIE['onfocus'] = 'onFocus';
Navigation._attributesToIE['onblur'] = 'onBlur';
Navigation._attributesToIE['onload'] = 'onLoad';
Navigation._attributesToIE['onchange'] = 'onChange';
Navigation._attributesToIE['onsubmit'] = 'onSubmit';
Navigation._attributesToIE['name'] = 'name';
Navigation._attributesToIE['value'] = 'value';
Navigation._attributesToIE['id'] = 'id';
Navigation._attributesToIE['href'] = 'href';
Navigation._attributesToIE['target'] = 'target';


Navigation._attributesIE = {};
Navigation._attributesIE['src'] = 'src';
Navigation._attributesIE['style'] = 'style';
Navigation._attributesIE['align'] = 'align';
Navigation._attributesIE['title'] = 'title';
Navigation._attributesIE['alt'] = 'alt';
Navigation._attributesIE['valign'] = 'valign';
Navigation._attributesIE['vspace'] = 'vspace';
Navigation._attributesIE['hspace'] = 'hspace';
Navigation._attributesIE['className'] = 'class';
Navigation._attributesIE['border'] = 'border';
Navigation._attributesIE['cellspacing'] = 'cellspacing';
Navigation._attributesIE['cellpadding'] = 'cellpadding';
Navigation._attributesIE['data'] = 'data';
Navigation._attributesIE['marginwidth'] = 'marginwidth';
Navigation._attributesIE['marginheight'] = 'marginheight';
Navigation._attributesIE['margintop'] = 'margintop';
Navigation._attributesIE['marginleft'] = 'marginleft';
Navigation._attributesIE['frameborder'] = 'frameborder';
Navigation._attributesIE['dataformatas'] = 'dataformatas';
Navigation._attributesIE['type'] = 'type';
Navigation._attributesIE['width'] = 'width';
Navigation._attributesIE['height'] = 'height';
Navigation._attributesIE['onMouseover'] = 'onmouseover';
Navigation._attributesIE['onMouseout'] = 'onmouseout';
Navigation._attributesIE['onClick'] = 'onclick';
Navigation._attributesIE['onFocus'] = 'onfocus';
Navigation._attributesIE['onBlur'] = 'onblur';
Navigation._attributesIE['onLoad'] = 'onload';
Navigation._attributesIE['onChange'] = 'onchange';
Navigation._attributesIE['onSubmit'] = 'onsubmit';
Navigation._attributesIE['name'] = 'name';
Navigation._attributesIE['value'] = 'value';
Navigation._attributesIE['id'] = 'id';
Navigation._attributesIE['href'] = 'href';
Navigation._attributesIE['target'] = 'target';

Navigation._styleAttributesIE = {};
Navigation._styleAttributesIE['width'] = 'width';
Navigation._styleAttributesIE['height'] = 'height';
Navigation._styleAttributesIE['top'] = 'top';
Navigation._styleAttributesIE['left'] = 'left';
Navigation._styleAttributesIE['display'] = 'display';
Navigation._styleAttributesIE['position'] = 'position';
Navigation._styleAttributesIE['textAlign'] = 'text-align';
Navigation._styleAttributesIE['textDecoration'] = 'text-decoration';
Navigation._styleAttributesIE['padding'] = 'padding';
Navigation._styleAttributesIE['paddingTop'] = 'padding-top';
Navigation._styleAttributesIE['paddingRight'] = 'padding-right';
Navigation._styleAttributesIE['paddingBottom'] = 'padding-bottom';
Navigation._styleAttributesIE['paddingLeft'] = 'padding-left';
Navigation._styleAttributesIE['margin'] = 'margin';
Navigation._styleAttributesIE['marginTop'] = 'margin-top';
Navigation._styleAttributesIE['marginRight'] = 'margin-right';
Navigation._styleAttributesIE['marginBottom'] = 'margin-bottom';
Navigation._styleAttributesIE['marginLeft'] = 'margin-left';
Navigation._styleAttributesIE['border'] = 'border';
Navigation._styleAttributesIE['borderLeft'] = 'border-left';
Navigation._styleAttributesIE['borderRight'] = 'border-right';
Navigation._styleAttributesIE['borderTop'] = 'border-top';
Navigation._styleAttributesIE['borderBottom'] = 'border-bottom';
Navigation._styleAttributesIE['borderColor'] = 'border-color';
Navigation._styleAttributesIE['borderStyle'] = 'border-style';
Navigation._styleAttributesIE['borderWidth'] = 'border-width';
Navigation._styleAttributesIE['borderCollapse'] = 'border-collapse';
Navigation._styleAttributesIE['fontSize'] = 'font-size';
Navigation._styleAttributesIE['fontWeight'] = 'font-weight';
Navigation._styleAttributesIE['fontStyle'] = 'font-style';
Navigation._styleAttributesIE['fontFace'] = 'font-face';
Navigation._styleAttributesIE['color'] = 'color';
Navigation._styleAttributesIE['backgroundColor'] = 'background-color';
Navigation._styleAttributesIE['backgroundImage'] = 'background-image';
Navigation._styleAttributesIE['backgroundPosition'] = 'background-position';
Navigation._styleAttributesIE['backgroundRepeat'] = 'background-repeat';
Navigation._styleAttributesIE['zIndex'] = 'z-index'; 


Navigation._getNavigationStructureByNode = function(node, structure, path, countx, containerPrefix) {
  if (arguments.length!=5) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (!node){
    return structure;
  }
  var arr = structure;
  for (var i=0; i<node.childNodes.length; i++){
    var child = node.childNodes[i];
    if (child.nodeType == 1){
      if (child.nodeName.toLowerCase() == 'a'){
        if (path.length){
          path += '-';
        }
        arr[path +''+ countx] = 1;
        var item = NavigationItem.createInstance(containerPrefix + path +''+ countx);
        item.setType('1');
        item.setRoot(path +''+ countx);
        if (Navigation.hasAttributes(child, 'class')){
          item.setClassName(Navigation.getAttributesFromElement(child, 'class'));
        }
        if (Navigation.hasAttributes(child, 'style')){
          item.setStyle(Navigation.getAttributesFromElement(child, 'style'));
        }
        if (Navigation.hasAttributes(child, 'href')){
          item.setHref(Navigation.getAttributesFromElement(child, 'href'));
        }
        if (Navigation.hasAttributes(child, 'target')){
          item.setTarget(Navigation.getAttributesFromElement(child, 'target'));
        }
        if (Navigation.hasAttributes(child, 'onclick')){
          item.setOnClick(Navigation.getAttributesFromElement(child, 'onclick'));
        }
        if (Navigation.hasAttributes(child, 'title')){
          item.setTitle(Navigation.getAttributesFromElement(child, 'title'));
        }
        var label = Navigation.getTextNodeValue(child);
        item.setLabel(label);
      }
      if (child.nodeName.toLowerCase() == 'li'){
        countx++;
      }
      if (child.nodeName.toLowerCase() == 'ul'){
        path += countx;
        countx = 0;
        structure[path] = {};
        arr = structure[path];
        var item = NavigationItem.createInstance(containerPrefix + path);
        item.setType('0');
        item.setRoot(path);
        if (Navigation.hasAttributes(child, 'class')){
          item.setClassName(Navigation.getAttributesFromElement(child, 'class'));
        }
        if (Navigation.hasAttributes(child, 'style')){
          item.setStyle(Navigation.getAttributesFromElement(child, 'style'));
        }
        var subChild = undefined;
        if(child.previousSibling){
          if (child.previousSibling && child.previousSibling.nodeName.toLowerCase() == 'a'){
            subChild = child.previousSibling;
          } else if (child.previousSibling.previousSibling && child.previousSibling.previousSibling.nodeName.toLowerCase() == 'a'){
            subChild = child.previousSibling.previousSibling;
          }
        }
        if (subChild){
          if (Navigation.hasAttributes(subChild, 'class')){
            item.setSubClassName(Navigation.getAttributesFromElement(subChild, 'class'));
          }
          if (Navigation.hasAttributes(subChild, 'style')){
            item.setSubStyle(Navigation.getAttributesFromElement(subChild, 'style'));
          }
          if (Navigation.hasAttributes(subChild, 'href')){
            item.setHref(Navigation.getAttributesFromElement(subChild, 'href'));
          }
          if (Navigation.hasAttributes(subChild, 'target')){
            item.setTarget(Navigation.getAttributesFromElement(subChild, 'target'));
          }
          if (Navigation.hasAttributes(subChild, 'onclick')){
            item.setOnClick(Navigation.getAttributesFromElement(subChild, 'onclick'));
          }
          if (Navigation.hasAttributes(subChild, 'title')){
            item.setTitle(Navigation.getAttributesFromElement(subChild, 'title'));
          }
          var label = Navigation.getTextNodeValue(subChild);
          item.setLabel(label);
        }
      }
      Navigation._getNavigationStructureByNode(child, arr, path, countx, containerPrefix);
    }
  }
  return structure;
}

Navigation._getNavigationStructuretoString = function(nodeList, str, x) {
  if (arguments.length!=3) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  for (var i in nodeList){
    var count = x;
    while (count > 0){
      str += '. .';
      count--;
    }
    str += i + ' = ' + nodeList[i] + '\n';
    if (typeof nodeList[i] == 'object'){
      str += Navigation._getNavigationStructuretoString(nodeList[i], '', x+1);
    }
  }
  return str;
}


Navigation._getFirstItem = function(obj) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  var count = 0;
  for (var i in obj){
    if (count == 0){
      return obj[i];
    }
  }
  return obj;
}



Navigation.getTextNodeValue = function(node) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  var str = '';
  for (var i=0; i<node.childNodes.length; i++){
    var child = node.childNodes[i];
    if (child.nodeType == 3){
      str += child.nodeValue;
    }
  }  
  return str;
}

Navigation.hasAttributes = function(elem, attrName) {
  var str = '';
  if (document.all){
    if (Navigation._attributesToIE[attrName]){
      attrName = Navigation._attributesToIE[attrName];
    }
    if (attrName == 'className'){
      if (elem.getAttribute('class')){
        attrName = 'class';
      }
    }
  }
  if (elem.getAttribute(attrName)){
    return true;
  }
  return false;
}

Navigation.getAttributesFromElement = function(elem, attrName) {
  var str = '';
  if (document.all){
    str = Navigation._getAttributesFromElementIE(elem, attrName);
  } else {
    str = Navigation._getAttributesFromElementDOM(elem, attrName);
  }
  return str;
}

Navigation._getAttributesFromElementIE = function(elem, attrName) { 
  var str = '';
  if (Navigation._attributesToIE[attrName]){
    var attr = Navigation._attributesToIE[attrName];
    if (attr == 'className'){
      if (elem.getAttribute('class')){
        attr = 'class';
      }
    }
    var attrValue = elem.getAttribute(attr);
    if (attrValue){
      if (typeof attrValue == 'object'){
        for (var a in Navigation._styleAttributesIE){
          if (attrValue[a] && attrValue[a].length){
            str += Navigation._styleAttributesIE[a]+': '+attrValue[a]+'; ';
          }
        }
      } else {
        str += attrValue;
      }
    }
  }
  return str;
}

Navigation._getAttributesFromElementIELoop = function(elem, attrName) { 
  var str = '';
  for (var i in Navigation._attributesIE){
    var attr = i;
    if (attr == 'className'){
      if (elem.getAttribute('class')){
        attr = 'class';
      }
    }
    if (elem.getAttribute(attr)){
      var name = Navigation._attributesIE[i];
      if (name == attrName){
        var attrValue = elem.getAttribute(attr);
        if (attrValue){
          if (typeof attrValue == 'object'){
            for (var a in Navigation._styleAttributesIE){
              if (attrValue[a] && attrValue[a].length){
                str += Navigation._styleAttributesIE[a]+': '+attrValue[a]+'; ';
              }
            }
          } else {
            str += attrValue;
          }
        }
      } 
    }  
  }
  return str;
}

Navigation._getAttributesFromElementDOM = function(elem, attrName) {
  var attributes = elem.attributes;
  var str = '';
  if (attributes.length){
    if (elem.getAttribute(attrName)){
      str += elem.getAttribute(attrName);
    }
  }
  return str;
}


Navigation._getAttributesFromElementDOMLoop = function(elem, attrName) {
  var attributes = elem.attributes;
  var str = '';
  var output = '';
  if (attributes.length){
    for (var i=0; i<attributes.length; i++){
      var attr = attributes.item(i);
      if (attr && attr.value && attr.value.length){
        var name = attr.name;
        if (attrName == name){
          var attrValue = attr.value;
          str += attrValue;
        }  
      }
    }
  }
  return str;
}

Navigation.getInstance = function(id) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (! (Navigation._registerInstance[id])){
    focus();
    throw new Error("Es ist keine Navigation.Instance mit id=" + id + " registriert!");
  } 
  return Navigation._registerInstance[id];
}

Navigation.createInstance = function(id) {
  if (!arguments.length) {
    id = 'navigation' + Navigation._defaultID.length;
    Navigation._defaultID.push(1);
  }
  if (! (Navigation._registerInstance[id])){
    Navigation._registerInstance[id] = new Navigation(id);
  } 
  return Navigation.getInstance(id);
}





function NavigationItem(id) {
  if (arguments.length>1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  this._id = undefined;
  this._rootArr = [];
  this._rootObj = {};
  this._type = undefined;
  this._href = undefined;
  this._label = undefined;
  this._style = undefined;
  this._target = undefined;
  this._onclick = undefined;
  this._className = undefined;
  this._title = undefined;
  this._subStyle = undefined;
  this._subClassName = undefined;
  this._setID(id);
  this._properties = NavigationItemProperties.createNavigationItemProperties(this.id(), this._getParentElement());
}

NavigationItem.prototype.toString = function() {
  return "\n[Navigation - id: " + this.id + "]\n";
}


NavigationItem.prototype.id = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._id = str;
  }
  return this._id;
}

NavigationItem.prototype.type = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._type = str;
  }
  return this._type;
}

NavigationItem.prototype.label = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._label = str;
  }
  return this._label;
}

NavigationItem.prototype.href = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._href = str;
  }
  return this._href;
}

NavigationItem.prototype.title = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._title = str;
  }
  return this._title;
}

NavigationItem.prototype.target = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._target = str;
  }
  return this._target;
}

NavigationItem.prototype.onclick = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._onclick = str;
  }
  return this._onclick;
}

NavigationItem.prototype.style = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._style = str;
  }
  return this._style;
}

NavigationItem.prototype.className = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._className = str;
  }
  return this._className;
}

NavigationItem.prototype.subStyle = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._subStyle = str;
  }
  return this._subStyle;
}

NavigationItem.prototype.subClassName = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._subClassName = str;
  }
  return this._subClassName;
}

NavigationItem.prototype.rootArr = function(arr) {
  if (arguments.length) {
    if (typeof arr != "object") {
      focus();
      throw new Error("Argument ist nicht vom Typ Object!");
    }
    this._rootArr = arr;
  }
  return this._rootArr;
}

NavigationItem.prototype.rootObj = function(obj) {
  if (arguments.length) {
    if (typeof obj != "object") {
      focus();
      throw new Error("Argument ist nicht vom Typ Object!");
    }
    this._rootObj = obj;
  }
  return this._rootObj;
}

NavigationItem.prototype.properties = function(obj) {
  if (arguments.length) {
    if (typeof obj != "object") {
      focus();
      throw new Error("Argument ist nicht vom Typ Object!");
    }
    this._properties = obj;
  }
  return this._properties;
}


NavigationItem.prototype._setID = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.id(str);
}

NavigationItem.prototype._getParentElement = function() {
  var elem = document.getElementById(this.id());
  var parentElem = '';
  if (elem){
    if (document.all){
      parentElem = elem.parentElement.id;
    } else {
      parentElem = elem.parentNode.id;
    }  
  }  
  return parentElem;
}




NavigationItem.prototype.setType = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.type(str);
}

NavigationItem.prototype.setLabel = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.label(str);
}

NavigationItem.prototype.setHref = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.href(str);
}

NavigationItem.prototype.setTitle = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.title(str);
}

NavigationItem.prototype.setTarget = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.target(str);
}

NavigationItem.prototype.setOnClick = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.onclick(str);
}

NavigationItem.prototype.setStyle = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.style(str);
}

NavigationItem.prototype.setClassName = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.className(str);
}

NavigationItem.prototype.setSubStyle = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.subStyle(str);
}

NavigationItem.prototype.setSubClassName = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.subClassName(str);
}

NavigationItem.prototype.setRoot = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  var arr = str.split(/-/);
  var _str = '';
  var rootListArr = [];
  var rootListObj = {};
  for (var i=0; i<arr.length; i++){
    if (i>0){
      _str += '-';
    }
    _str += arr[i];
    rootListObj[_str] = i;
    rootListArr[i] = _str;
  }
  this.rootArr(rootListArr);
  this.rootObj(rootListObj);
}


NavigationItem._defaultID = [];

NavigationItem._registerInstance = {};

NavigationItem._isRoot = false;




NavigationItem.getInstance = function(id) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (! (NavigationItem._registerInstance[id])){
    focus();
    throw new Error("Es ist keine NavigationItem.Instance mit id=" + id + " registriert!");
  } 
  return NavigationItem._registerInstance[id];
}

NavigationItem.hasInstance = function(id) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (! (NavigationItem._registerInstance[id])){
    return false;
  } 
  return true;
}

NavigationItem.createInstance = function(id) {
  if (!arguments.length) {
    id = 'navigation' + NavigationItem._defaultID.length;
    NavigationItem._defaultID.push(1);
  }
  if (! (NavigationItem._registerInstance[id])){
    NavigationItem._registerInstance[id] = new NavigationItem(id);
  } 
  return NavigationItem.getInstance(id);
}






function NavigationItemProperties(id, idParentElement) {  
  this._id = undefined;
  this._idParentElement = 'body';
  this.id(id);
  this.idParentElement(idParentElement);
}



NavigationItemProperties.prototype.id = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("ArgumentError:noString!");
    }
    this._id = str;
  }
  return this._id;
}


NavigationItemProperties.prototype.idParentElement = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("ArgumentError:noString!");
    }  
    this._idParentElement = str.toLowerCase();
  }
  return this._idParentElement;
}



NavigationItemProperties.prototype.getTop = function() {  
  if (this._existsElement(this.id())){
    var parentDiv = document.getElementById(this.id());
    var topPosition = 0;
    if (this._existsElement(this.idParentElement())){
      while (parentDiv && parentDiv.id != this.idParentElement()){
        if (parentDiv.nodeType == 1){
          topPosition += parseFloat(parentDiv.offsetTop);
        }
        parentDiv = parentDiv.offsetParent;
      }
    }
    else{
      while (parentDiv){
        if (parentDiv.nodeType == 1){
          topPosition += parseFloat(parentDiv.offsetTop);
        }
        parentDiv = parentDiv.offsetParent;
      }
    }
    return parseFloat(topPosition);
  }
  return undefined;
}


NavigationItemProperties.prototype.getLeft = function() {  
  if (this._existsElement(this.id())){
    var parentDiv = document.getElementById(this.id());
    var leftPosition = 0;
    if (this._existsElement(this.idParentElement())){
      while (parentDiv && parentDiv.id != this.idParentElement()){
        if (parentDiv.nodeType == 1){
          leftPosition += parseFloat(parentDiv.offsetLeft);
        }
        parentDiv = parentDiv.offsetParent;
      }
    }
    else{
      while (parentDiv){
        if (parentDiv.nodeType == 1){
          leftPosition += parseFloat(parentDiv.offsetLeft);
        }
        parentDiv = parentDiv.offsetParent;
      }
    }
    return parseFloat(leftPosition);
  }
  return undefined;
}


NavigationItemProperties.prototype.getBottom = function() {
  if (this._existsElement(this.id())){
    var bottomPosition = parseFloat(this.getTop() +  this.getHeight());
    return parseFloat(bottomPosition);
  }
  return undefined;
}


NavigationItemProperties.prototype.getRight = function() {  
  if (this._existsElement(this.id())){
    var rightPosition = parseFloat(this.getLeft() + this.getWidth());
    return parseFloat(rightPosition);
  }
  return undefined;
}


NavigationItemProperties.prototype.getWidth = function() {
  if (this._existsElement(this.id())){
    var width = parseFloat(document.getElementById(this.id()).offsetWidth);
    return parseFloat(width);
  }
  return undefined;
}


NavigationItemProperties.prototype.getHeight = function() {
  if (this._existsElement(this.id())){
    var height = parseFloat(document.getElementById(this.id()).offsetHeight);
    return parseFloat(height);
  }
  return undefined;
}


NavigationItemProperties.prototype._existsElement = function(id) {
  if (document.getElementById(id) != undefined){
    return true;
  }
  return false;
}



NavigationItemProperties.createNavigationItemProperties = function(id, idParentElement) { 
  return new NavigationItemProperties(id, idParentElement);
}


NavigationItemProperties.prototype.toString = function() {
  return Object.prototype.toString.apply(this);
}





function NavigationTools() {
}








NavigationTools.checkNumber = function(n){
  if (!arguments.length){
    return false;
  }
  if (n == undefined){
    return false;
  }
  n = n.toString();
  if (n == '0'){
    return n;
  }
  if (!n.length){
    return false;
  }
  n = n.replace(/,/g,'.');
  if (isNaN(n)){
    return false;
  }
  if (!isFinite(n)) {
    return false;
  }
  n = parseFloat(n);
  return n;
}


NavigationTools.checkWertInArrayVorhanden = function(){
  var str = arguments[0];
  var arr = new Array();
  arr = arguments[1];
  for (var i in arr){
    if (arr[i] == str){
      return true;
    } 
  }
  return false;
}



NavigationTools.prototype.toString = function() {
  return Object.prototype.toString.apply(this);
}

var suggestionText = "Abendmensa, Absolventenball, Aktionswochen, Ansprechpartner, Arendt, Armean, Ausbildung im SWT, Ausweis, BAföG, Bargeldlos bezahlen, Behinderung, Beitragshöhe, Beratungsangebote, Beschallungsanlage, Billen, Birkenfeld, Bühne, Busverkehr, Cafeteria, Casser, Catering, Co-Cooking, CROUS, Darlehen, Deutsche Bahn AG, Dinner for two, Eiden, Essen, Examensabschlussdarlehen, Fachhochschule, Fahrausweis, Fahrrad, Fahrradmitnahme, Feiern, Finanzierung, Fotogalerien, Frank, Freie Stellen, Freitische, Freiwilliges Soziales Jahr, Freunde, Gästewohnung, Gästezimmer, Geltungsbereich, Geo-Mensa Petrisberg, Geschirr, Getränkekarte, Gültigkeitsdauer, Hamel Leones, Häufige Fragen, Hausmeistersprechstunden, Heidrich, Herbst, Hilfe, Individuelle Wohnangebote, Internet, ISIC, Jobbörse, Kalender, Kartenvorverkauf, Keil, Kettelhack, KfW-Darlehen, Kids for free, Kleine Karte Cafeteria Forum/Bistro AB, Kleine Karte Cafeteria Schneidershof, Krauß, Kulturförderung, Lageplan, Lay, Lebensmittelinfo, Longen, Lorenz, Löpki, Melchisedech, Mensa, Mensa Backstagetour, Mensa Irminenfreihof, Mensa Petrisberg, Mensa Schneidershof, Mensa Tarforst, Merlot, Metz, Nancy, Notunterkünfte, Öffnungszeiten, Opole, Papa-Mama-Knete, Partnerschaften, Privatzimmer, Psychosoziale Beratung, Raumvermietung, Rechtsberatung, Rezepte, Riemann, Rodermund, Rohr, Samstagmensa, Schappo, Soziale Unterstützung, Sparen, Speisepläne, Standorte, Strempel, Struktur, Stürmer, Studierendenaustausch, Studieren mit Behinderung, Studieren mit Kind, Theologische Fakultät, Total Lokal, Treinen, Trier, Trösch, Tutoren, Tutorenprogramm, Universität, Umzugswagen, über uns, Überbrückungsdarlehen, Unterstützungsdarlehen, Veranstaltungen, Vergünstigungen, Wagner, Web-Tipps, Wochenendnotdienst, Wohnanlagen, Wohnen, Wohngemeinschaft, Wohnheim Allianz, Wohnheim Kleeburger Weg, Wohnheim Olewig, Wohnheim Petrisberg, Wohnheim Tarforst, Wohnheimfeten, Zangl, Zawadzka, Zivildienst"; 
/* 

	SearchField 
	written by Alen Grakalic, provided by Css Globe (cssglobe.com)
	please visit http://cssglobe.com/post/1202/style-your-websites-search-field-with-jscss/ for more info
	
*/

this.stichwort = function(){
	
	
	var id = "stichwort";
	
	var defaultText = "Stichwort";	
	
	var suggestion = true;
	
  
	

	var field = document.getElementById(id);	
	var classInactive = "sf_inactive";
	var classActive = "sf_active";
	var classText = "sf_text";
	var classSuggestion = "sf_suggestion";
	this.safari = ((parseInt(navigator.productSub)>=20020000)&&(navigator.vendor.indexOf("Apple Computer")!=-1));
	if(field && !safari){
		field.value = defaultText;
		field.c = field.className;		
		field.className = field.c + " " + classInactive;
		field.onfocus = function(){
			this.className = this.c + " "  + classActive;
			this.value = (this.value == "" || this.value == defaultText) ?  "" : this.value;
		};
		field.onblur = function(){
			this.className = (this.value != "" && this.value != defaultText) ? this.c + " " +  classText : this.c + " " +  classInactive;
			this.value = (this.value != "" && this.value != defaultText) ?  this.value : defaultText;
			clearList();
		};
		if (suggestion){
			
			var selectedIndex = 0;
						
			field.setAttribute("autocomplete", "off");
			var div = document.createElement("div");
			var list = document.createElement("ul");
			list.style.display = "none";
			div.className = classSuggestion;
			list.style.width = "204px";
			div.appendChild(list);
			field.parentNode.appendChild(div);	

			field.onkeypress = function(e){
				
				var key = getKeyCode(e);
		
				if(key == 13){ // enter
					selectList();
					selectedIndex = 0;
					return false;
				};	
			};
				
			field.onkeyup = function(e){
			
				var key = getKeyCode(e);
		
				switch(key){
				case 13:
					return false;
					break;			
				case 27:  // esc
					field.value = "";
					selectedIndex = 0;
					clearList();
					break;				
				case 38: // up
					navList("up");
					break;
				case 40: // down
					navList("down");		
					break;
				default:
					startList();			
					break;
				};
			};
			
			this.startList = function(){
				var arr = getListItems(field.value);
				if(field.value.length > 0){
					createList(arr);
				} else {
					clearList();
				};	
			};
			
			this.getListItems = function(value){
				var arr = new Array();
				var src = suggestionText;
				var src = src.replace(/, /g, ",");
				var arrSrc = src.split(",");
				for(i=0;i<arrSrc.length;i++){
					if(arrSrc[i].substring(0,value.length).toLowerCase() == value.toLowerCase()){
						arr.push(arrSrc[i]);
					};
				};				
				return arr;
			};
			
			this.createList = function(arr){				
				resetList();			
				if(arr.length > 0) {
					for(i=0;i<arr.length;i++){				
						li = document.createElement("li");
						a = document.createElement("a");
						a.href = "javascript:void(0);";
						a.i = i+1;
						a.innerHTML = arr[i];
						li.i = i+1;
						li.onmouseover = function(){
							navListItem(this.i);
						};
						a.onmousedown = function(){
							selectedIndex = this.i;
							selectList(this.i);		
							return false;
						};					
						li.appendChild(a);
						list.setAttribute("tabindex", "-1");
						list.appendChild(li);	
					};	
					list.style.display = "block";				
				} else {
					clearList();
				};
			};	
			
			this.resetList = function(){
				var li = list.getElementsByTagName("li");
				var len = li.length;
				for(var i=0;i<len;i++){
					list.removeChild(li[0]);
				};
			};
			
			this.navList = function(dir){			
				selectedIndex += (dir == "down") ? 1 : -1;
				li = list.getElementsByTagName("li");
				if (selectedIndex < 1) selectedIndex =  li.length;
				if (selectedIndex > li.length) selectedIndex =  1;
				navListItem(selectedIndex);
			};
			
			this.navListItem = function(index){	
				selectedIndex = index;
				li = list.getElementsByTagName("li");
				for(var i=0;i<li.length;i++){
					li[i].className = (i==(selectedIndex-1)) ? "selected" : "";
				};
			};
			
			this.selectList = function(){
				li = list.getElementsByTagName("li");	
				a = li[selectedIndex-1].getElementsByTagName("a")[0];
				field.value = a.innerHTML;
				clearList();
			};			
			
		};
	};
	
	this.clearList = function(){
		if(list){
			list.style.display = "none";
			selectedIndex = 0;
		};
	};		
	this.getKeyCode = function(e){
		var code;
		if (!e) var e = window.event;
		if (e.keyCode) code = e.keyCode;
		return code;
	};
	
};


this.addEvent = function(obj,type,fn){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} else {
		obj.addEventListener(type,fn,false);
	};
};
addEvent(window,"load",stichwort);




function Tools() {
}







Tools.randomize = function(n) {
  if (arguments.length!=1) {
    return false;
  }
  var sum = n * Math.random();
  var randomNumber = Math.floor(sum)+1;
  return randomNumber;
}

Tools.openMicrosite = function(htmlElement, properties) {
  if (!arguments.length) {
    return false;
  }
  var url = '';
  var docSource = '';
  var tagName = htmlElement['tagName'];
  tagName = tagName.toLowerCase();
  if (tagName == 'form'){
    var nameValuePeer = [];
    for (var i=0; i<htmlElement.elements.length; i++){
      nameValuePeer[i] = {};
      if (htmlElement.elements[i].name.length){
        if (htmlElement.elements[i].type == 'select-one'){
            nameValuePeer[i]['name'] = htmlElement.elements[i].name;
            nameValuePeer[i]['value'] = htmlElement.elements[i].options[htmlElement.elements[i].selectedIndex].value;
        } else if (htmlElement.elements[i].type == 'select-multiple'){
          nameValuePeer[i]['name'] = htmlElement.elements[i].name;
          nameValuePeer[i]['value'] = [];
          for (var ii=0; ii<htmlElement.elements[i].options.length; ii++){
            if (htmlElement.elements[i].options[ii].selected){
              nameValuePeer[i]['value'][ii] = htmlElement.elements[i].options[ii].value;
            }
          }
        } else if (htmlElement.elements[i].type == 'radio'){
          nameValuePeer[i]['name'] = htmlElement.elements[i].name;
          if (htmlElement.elements[i].length){
            nameValuePeer[i]['value'] = [];
            for (var ii=0; ii<htmlElement.elements[i].length; ii++){
              if (htmlElement.elements[i][ii].checked){
                nameValuePeer[i]['value'][ii] = htmlElement.elements[i][ii].value;
              }
            }
          } else {
            if (htmlElement.elements[i].checked){
              nameValuePeer[i]['value'] = htmlElement.elements[i].value;
            }
          }
        } else if (htmlElement.elements[i].type == 'checkbox'){
          nameValuePeer[i]['name'] = htmlElement.elements[i].name;
          if (htmlElement.elements[i].length){
            nameValuePeer[i]['value'] = [];
            for (var ii=0; ii<htmlElement.elements[i].length; ii++){
              if (htmlElement.elements[i][ii].checked){
                nameValuePeer[i]['value'][ii] = htmlElement.elements[i][ii].value;
              }
            }
          } else {
            if (htmlElement.elements[i].checked){
              nameValuePeer[i]['value'] = htmlElement.elements[i].value;
            }
          }
        } else {
          nameValuePeer[i]['name'] = htmlElement.elements[i].name;
          nameValuePeer[i]['value'] = htmlElement.elements[i].value;
        }
      }
    }
    if (!htmlElement.method || htmlElement.method.toLowerCase() != 'post'){
      url += htmlElement.action + '?';
      for (var f=0; f<nameValuePeer.length; f++){
        if (typeof nameValuePeer[f]['value'] == 'object'){
          for (var ff=0; ff<nameValuePeer[f]['value'].length; ff++){
            if (nameValuePeer[f]['value'][ff]){
              url += '&' + encodeURIComponent(nameValuePeer[f]['name']);
              url += '=' + encodeURIComponent(nameValuePeer[f]['value'][ff]);
            }
          }
        } else {
          if (nameValuePeer[f]['value']){
            url += '&' + encodeURIComponent(nameValuePeer[f]['name']);
            url += '=' + encodeURIComponent(nameValuePeer[f]['value']);
          }
        }
      }
    } else {
      var charsetting = 'ISO-8859-1';
      if (document.charset){
        if (document.charset != charsetting){
          charsetting = document.charset;
        }
      } else if (document.characterSet){
        if (document.characterSet != charsetting){
          charsetting = document.characterSet;
        }
      }
      docSource += '<html>\n<head><title></title><meta http-equiv="content-type" content="text/html; charset='+ charsetting +'"/></head>\n<body background-color="#ffffff" onload="document.forms[\'myform\'].submit();"><div style="display: none;">\n';
      docSource += '<form name="myform" action="'+ htmlElement.action +'" method="post">\n';
      for (var f=0; f<nameValuePeer.length; f++){
        if (typeof nameValuePeer[f]['value'] == 'object'){
          for (var ff=0; ff<nameValuePeer[f]['value'].length; ff++){
            if (nameValuePeer[f]['value'][ff]){
              docSource += '<input type="checkbox" name="'+ nameValuePeer[f]['name'] +'" value="'+ nameValuePeer[f]['value'][ff] +'" checked="checked"/>\n';
            }
          }
        } else {
          if (nameValuePeer[f]['value']){
            docSource += '<input type="checkbox" name="'+ nameValuePeer[f]['name'] +'" value="'+ nameValuePeer[f]['value'] +'" checked="checked"/>\n';
          }
        }
      }
      docSource += '</form>\n</div></body>\n</html>';
    }
    try {
      htmlElement.reset();
    } catch(e){
    }
  } else if (tagName == 'a' || tagName == 'area'){
    url += htmlElement.href;
  }
  var windowProps = '';
  if (arguments[1]){
    windowProps = properties;
  } else {
    windowProps = 'width=800,height=600,scrollbars=yes,locationbar=no,menubar=no';
  }
  var fenster = window.open(url, 'Micorsite', windowProps);
  if (docSource.length){
    var doc = fenster.document;
    doc.open();
    doc.write(docSource);
    doc.close();
  }
  fenster.focus();
  return false;
}

Tools.getCookieValue = function(cookieName){
  var cookieValue = '';
  if (! navigator.cookieEnabled){
    alert('Ihr Browser erlaubt keine Cookies!');
    return cookieValue;
  }
  if (! cookieName){
    return cookieValue;
  }
  var allCookies = document.cookie;
  var allCookiesArr = allCookies.split(/\;/);
  var regExp = new RegExp('^' + cookieName + '=');
  for (var i=0; i<allCookiesArr.length; i++){
    var _val = Tools.stripSpace(allCookiesArr[i]);
    if (! _val.match(regExp)){
      continue;
    }
    cookieValue = _val.replace(regExp,'');
  }
  if (cookieValue.match(/^"/) && cookieValue.match(/"$/)){
    cookieValue = cookieValue.replace(/^"/,'');
    cookieValue = cookieValue.replace(/"$/,'');
  }
  cookieValue = cookieValue.replace(/###/,';');
  return cookieValue;
}

Tools.setCookieValue = function(cookieValue, cookieName, expiresDate, path, version, valueType){
  if (! navigator.cookieEnabled){
    alert('Ihr Browser erlaubt keine Cookies!');
    return false;
  }
  if (! cookieValue.length){
  }
  if(! cookieName){
    cookieName = 'myCookie';
  }
  var expDate = Tools.DateToGMTStringCookie(expiresDate);
  if (cookieValue.length >= 4000){
    alert('Das Cookie kann nicht gespeichert werden.\nDie Datenmenge übersteigt die maximal zu speichernde Datenmenge eines Cookies.\nBitte überprüfen Sie Ihre Daten.');
    return false;
  }
  cookieValue = cookieValue.replace(/;/,'###');
  var cookieStr = '';
  if (valueType == 'int'){
    cookieStr = cookieName +'=' + cookieValue +';';
  } else {
    cookieStr = cookieName +'="' + cookieValue +'";';
  }
  if (expDate){
    cookieStr += ' expires='+ expDate +';';
  }
  if (path){
    cookieStr += ' path='+ path + ';';
  }
  version = 3;
  if (version && version.toString().length){
    cookieStr += ' version="'+ version + '";';
  }
  document.cookie = cookieStr;
}

Tools.DateToGMTStringCookie = function(date){
  if (! date){
    return false;
  }
  var str = '';
  var gtm = '';
  var gtmJS = date.toGMTString();
  var gtmArr = gtmJS.split(/ /);
  for (var i=0; i<gtmArr.length; i++){
    if (i>1 && i<4){
      gtm += '-';
    } else if (i > 0){
      gtm += ' ';
    }
    gtm += gtmArr[i];
  }
  return gtm;
}

Tools.confirmURL = function(url){
  if (! url){
    return false;
  }
  var conf = confirm('Möchten Sie den Datensatz wirklich löschen?');
  if (conf) {
    return url;
  }
}

Tools.checkRequiredData = function(htmlElement) {
  if (!arguments.length) {
    return false;
  }
  var _dataType = new RegExp(' \\[datatype\\=');
  var _required = new RegExp(' \\[required');
  var _requiredOn = new RegExp(' \\[requiredOn\\]');
  var _requiredOr = new RegExp(' \\[requiredOr\\]');
  var tagName = htmlElement['tagName'];
  tagName = tagName.toLowerCase();
  if (tagName == 'form'){
    for (var i=0; i<htmlElement.elements.length; i++){
      var idRequiredOn = undefined;
      var elemRequiredOn = undefined;
      var idRequiredOr = undefined;
      var elemRequiredOr = undefined;
      if(htmlElement.elements[i].nodeName.toLowerCase() == 'fieldset'){
        continue;
      }
      if (!htmlElement.elements[i].name.length || (!htmlElement.elements[i].className.length || (!htmlElement.elements[i].className.toString().match(_required) && !htmlElement.elements[i].className.toString().match(_dataType))) ){
        continue;
      }
      var requiredElemHasValue = false;
      var dataTypeElemHasDataTypeValue = true;
      if (htmlElement.elements[i].className.toString().match(_dataType)){
        if (! Tools.checkDataTypeElement(htmlElement.elements[i])) {
          dataTypeElemHasDataTypeValue = false;
        }
      }
      if (htmlElement.elements[i].className.toString().match(_requiredOn)){
        var idRequiredOn = htmlElement.elements[i].className.toString().split(_requiredOn)[1].toString().replace(/[\[\]]/gi,'');
        var elemRequiredOn = document.getElementById(idRequiredOn);
        if (Tools.checkRequiredElement(elemRequiredOn)){
          requiredElemHasValue = Tools.checkRequiredElement(htmlElement.elements[i]);
        } else {
          requiredElemHasValue = true;
        }
      } else if (htmlElement.elements[i].className.toString().match(_requiredOr)){
        var idRequiredOr = htmlElement.elements[i].className.toString().split(_requiredOr)[1].toString().replace(/[\[\]]/gi,'');
        var elemRequiredOr = document.getElementById(idRequiredOr);
        if (Tools.checkRequiredElement(elemRequiredOr)){
          requiredElemHasValue = true;
        } else {
          requiredElemHasValue = Tools.checkRequiredElement(htmlElement.elements[i]);
        }
      } else {
        requiredElemHasValue = Tools.checkRequiredElement(htmlElement.elements[i]);
      }
      if (!requiredElemHasValue){
        var shownElemName = htmlElement.elements[i].name;
        if (htmlElement.elements[i].title){
          shownElemName = htmlElement.elements[i].title;
        }
        if (elemRequiredOr != undefined){
          var shownElemNameOr = elemRequiredOr.name;
          if (elemRequiredOr.title){
            shownElemNameOr = elemRequiredOr.title;
          }
          alert('Bitte füllen Sie das Feld >>'+ shownElemName +'<< oder >>'+ shownElemNameOr +'<< aus!');
        } else {
          alert('Bitte füllen Sie das Feld >>'+ shownElemName +'<< aus!');
        }
        if (htmlElement.elements[i].type != 'hidden') {
          htmlElement.elements[i].focus();
        }
        return false;
      }
      if (!dataTypeElemHasDataTypeValue){
        var shownElemName = htmlElement.elements[i].name;
        if (htmlElement.elements[i].title){
          shownElemName = htmlElement.elements[i].title;
        }
        if (htmlElement.elements[i].type != 'hidden') {
          htmlElement.elements[i].focus();
        }
        return false;
      }
    }
    return true;
  }
}

Tools.checkRequiredDataFormFragment = function(htmlElement, elem) {
  if (arguments.length != 2) {
    return false;
  }
  var _dataType = new RegExp(' \\[datatype\\=');
  var _required = new RegExp(' \\[required');
  var _requiredOn = new RegExp(' \\[requiredOn\\]');
  var _requiredOr = new RegExp(' \\[requiredOr\\]');
  var tagName = htmlElement['tagName'];
  tagName = tagName.toLowerCase();
  if (tagName == 'form'){
    for (var i=0; i<htmlElement.elements.length; i++){
      if(htmlElement.elements[i].nodeName.toLowerCase() == 'fieldset'){
        continue;
      }
      if (!htmlElement.elements[i].name.length || (!htmlElement.elements[i].className.length || (!htmlElement.elements[i].className.toString().match(_required) && !htmlElement.elements[i].className.toString().match(_dataType))) ){
        continue;
      }
      if (! Tools.isChildOfElement(elem, htmlElement.elements[i])) {
        continue;
      }
      var requiredElemHasValue = false;
      var dataTypeElemHasDataTypeValue = true;
      if (htmlElement.elements[i].className.toString().match(_dataType)){
        if (! Tools.checkDataTypeElement(htmlElement.elements[i])) {
          dataTypeElemHasDataTypeValue = false;
        }
      }
      if (htmlElement.elements[i].className.toString().match(_requiredOn)){
        var idRequiredOn = htmlElement.elements[i].className.toString().split(_requiredOn)[1].toString().replace(/[\[\]]/gi,'');
        var elemRequiredOn = document.getElementById(idRequiredOn);
        if (Tools.checkRequiredElement(elemRequiredOn)){
          requiredElemHasValue = Tools.checkRequiredElement(htmlElement.elements[i]);
        } else {
          requiredElemHasValue = true;
        }
      } else if (htmlElement.elements[i].className.toString().match(_requiredOr)){
        var idRequiredOr = htmlElement.elements[i].className.toString().split(_requiredOr)[1].toString().replace(/[\[\]]/gi,'');
        var elemRequiredOr = document.getElementById(idRequiredOr);
        if (Tools.checkRequiredElement(elemRequiredOr)){
          requiredElemHasValue = true;
        } else {
          requiredElemHasValue = Tools.checkRequiredElement(htmlElement.elements[i]);
        }
      } else {
        requiredElemHasValue = Tools.checkRequiredElement(htmlElement.elements[i]);
      }
      if (!requiredElemHasValue){
        var shownElemName = htmlElement.elements[i].name;
        if (htmlElement.elements[i].title){
          shownElemName = htmlElement.elements[i].title;
        }
        if (elemRequiredOr != undefined){
          var shownElemNameOr = elemRequiredOr.name;
          if (elemRequiredOr.title){
            shownElemNameOr = elemRequiredOr.title;
          }
          alert('Bitte füllen Sie das Feld >>'+ shownElemName +'<< oder >>'+ shownElemNameOr +'<< aus!');
        } else {
          alert('Bitte füllen Sie das Feld >>'+ shownElemName +'<< aus!');
        }
        if (htmlElement.elements[i].type != 'hidden') {
          htmlElement.elements[i].focus();
        }
        return false;
      }
      if (!dataTypeElemHasDataTypeValue){
        var shownElemName = htmlElement.elements[i].name;
        if (htmlElement.elements[i].title){
          shownElemName = htmlElement.elements[i].title;
        }
        if (htmlElement.elements[i].type != 'hidden') {
          htmlElement.elements[i].focus();
        }
        return false;
      }
    }
    return true;
  }
}

Tools.isChildOfElement = function(parentElem, childElem) {
  if (arguments.length != 2) {
    return false;
  }
  var nextElem = childElem;
  while (nextElem && nextElem.nodeName.toLowerCase() != 'body'){
    if (nextElem == parentElem){
      return true;
    }
    nextElem = nextElem.parentNode;
  }
  return false;
}

Tools.checkDataTypeElement = function(elem) {
  if (!arguments.length) {
    return false;
  }
  if (elem == undefined){
    return false;
  }
  var _dateTypeDE = new RegExp(' \\[datatype\\=Date\\_DE\\]');
  var _dateTypeCMS = new RegExp(' \\[datatype\\=Date\\_CMS\\]');
  var _dateTypeMail = new RegExp(' \\[datatype\\=Mail\\]');
  var _dateTypeLedgerNr = new RegExp(' \\[datatype\\=LedgerNr\\]');
  var _datePLZDE = new RegExp(' \\[datatype\\=PLZ_DE\\]');
  var _dateInt = new RegExp(' \\[datatype\\=INT\\]');
  var _dateSZ = new RegExp(' \\[datatype\\=SZ\\]');
  var _value = '';
  if (elem.type == 'select-one'){
    if (elem.selectedIndex < 0){
      return false;
    }
    _value = Tools.stripSpace(elem.options[elem.selectedIndex].value);
  } else if (elem.type == 'select-multiple'){
    for (var ii=0; ii<elem.options.length; ii++){
      if (elem.options[ii].selected){
        _value += Tools.stripSpace(elem.options[ii].value);
      }
    }
  } else if (elem.type == 'radio'){
    if (elem.length){
      for (var ii=0; ii<elem.length; ii++){
        if (elem[ii].checked){
          _value += Tools.stripSpace(elem[ii].value);
        }
      }
    } else {
      if (elem.checked){
        _value = Tools.stripSpace(elem.value);
      }
    }
  } else if (elem.type == 'checkbox'){
    if (elem.length){
      for (var ii=0; ii<elem.length; ii++){
        if (elem[ii].checked){
          _value += Tools.stripSpace(elem[ii].value);
        }
      }
    } else {
      if (elem.checked){
        _value = Tools.stripSpace(elem.value);
      }
    }
  } else {
    _value = Tools.stripSpace(elem.value);
  }
  if (! _value.length){
    return true;
  }
  if (elem.className.toString().match(_dateTypeDE)){
    return Tools.validateDateFormat(_value, 'DE');
  }
  if (elem.className.toString().match(_dateTypeCMS)){
    return Tools.validateDateFormat(_value, 'CMS');
  }
  if (elem.className.toString().match(_dateTypeMail)){
    return Tools.validateMailFormat(_value);
  }
  if (elem.className.toString().match(_dateTypeLedgerNr)){
    return Tools.validateLedgerNumber(_value);
  }
  if (elem.className.toString().match(_datePLZDE)){
    return Tools.validatePLZ(_value, 'DE');
  }        
  if (elem.className.toString().match(_dateInt)){
    return Tools.validateINT(_value);
  }   
  if (elem.className.toString().match(_dateSZ)){
    return Tools.validateSZ(_value);
  }
  return true;
}

Tools.validateSZ = function(value) {
  if (! arguments.length) {
    return;
  }
  if (value.match(/[^0-9-\/]/)) {
      alert('Bitte geben Sie nur Zahlen, "/", oder "-" ein!\n');
      return false;
  }
  return true;
}

Tools.validateINT = function(value) {
  if (! arguments.length) {
    return;
  }
  if (value.match(/\D/)) {
      alert('Bitte geben Sie nur Zahlen ein!\n');
      return false;
  }
  return true;
}

Tools.validatePLZ = function(value, lang) {
  if (! arguments.length) {
    return;
  }
  if (! lang){
    lang = 'DE';
  }
  if (lang == 'DE'){
    if (! value.match(/^(\D\-)?(\d\d\d\d\d)$/)) {
      alert('Bitte geben Sie eine fünfstellige Zahl ein!\n');
      return false;
    }
  } else if (! value.match(/^(\d\d\d\d\d)$/)) {
    alert('Bitte geben Sie eine fünfstellige Zahl ein!\n');
    return false;
  }
  return true;
}

Tools.validateLedgerNumber = function(value) {
  if (! arguments.length) {
    return;
  }
  if (! value.match(/^(\d\d?\d?\d?\d?\d?\d?\d?\d?\d?)$/)) {
    alert('Bitte geben Sie eine Zahl mit 1 - 10 Stellen ein!');
    return false;
  }
  return true;
}

Tools.validateDateFormat = function(value, variant) {
  if (! arguments.length) {
    return;
  }
  if (variant == 'CMS'){
    if (! value.match(/^(\d\d\d\d)\-(\d\d)\-(\d\d)$/)) {
      alert('Bitte geben Sie das Datum im Format jjjj-mm-dd an!');
      return false;
    }
  } else {
    if (! value.match(/^(\d\d?)\.(\d\d?)\.(\d\d\d\d)$/)) {
      alert('Bitte geben Sie das Datum im Format tt.mm.jjjj an!');
      return false;
    }
  }
  return true;
}

Tools.validateMailFormat = function(value) {
  if (!arguments.length) {
    return false;
  }
  var regEx = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)(\\@)([a-zA-Z0-9\\-\\.]+)(\\.)([a-zA-Z]{2,4})$');
  if (! value.match(regEx)){
    alert('Bitte geben Sie eine gültige E-Mail-Adresse an!');
    return false;
  }
  return true;
}

Tools.checkRequiredElement = function(elem) {
  if (!arguments.length) {
    return false;
  }
  if (elem == undefined){
    return false;
  }
  var _multipleRegEx = new RegExp(' \\[multiple\\]');
  var _multiple = false;
  if(elem.className.toString().match(_multipleRegEx)){
    _multiple = true;
  }
  if (_multiple){
    return Tools.checkRequiredElementMultiple(elem);
  }
  return Tools.checkRequiredElementSingle(elem);
}

Tools.checkRequiredElementMultiple = function(elem) {
  if (!arguments.length) {
    return false;
  }
  if (elem == undefined){
    return false;
  }
  var requiredValue = '';
  var arr = document.getElementsByName(elem.name);
  for (var i=0; i<arr.length; i++) {
    var multipleElem = arr[i];
    if (! Tools.checkRequiredElementSingle(multipleElem)){
      continue;
    }
    return true;
  }
  return false;
}

Tools.checkRequiredElementSingle = function(elem) {
  if (!arguments.length) {
    return false;
  }
  if (elem == undefined){
    return false;
  }
  var requiredValue = '';
  if (elem.type == 'select-one'){
    if (elem.selectedIndex < 0){
      return false;
    }
    requiredValue = Tools.stripSpace(elem.options[elem.selectedIndex].value);
  } else if (elem.type == 'select-multiple'){
    for (var ii=0; ii<elem.options.length; ii++){
      if (elem.options[ii].selected){
        requiredValue += Tools.stripSpace(elem.options[ii].value);
      }
    }
  } else if (elem.type == 'radio'){
    if (elem.length){
      for (var ii=0; ii<elem.length; ii++){
        if (elem[ii].checked){
          requiredValue += Tools.stripSpace(elem[ii].value);
        }
      }
    } else {
      if (elem.checked){
        requiredValue = Tools.stripSpace(elem.value);
      }
    }
  } else if (elem.type == 'checkbox'){
    if (elem.length){
      for (var ii=0; ii<elem.length; ii++){
        if (elem[ii].checked){
          requiredValue += Tools.stripSpace(elem[ii].value);
        }
      }
    } else {
      if (elem.checked){
        requiredValue = Tools.stripSpace(elem.value);
      }
    }
  } else {
    requiredValue = Tools.stripSpace(elem.value);
  }
  if (!requiredValue.length){
    return false;
  }
  return true;
}

Tools.resetFormElement = function(elem) {
  if (!arguments.length) {
    return false;
  }
  if (elem == undefined){
    return false;
  }
  var requiredValue = '';
  if (elem.type == 'select-one'){
    elem.options[0].selected = 'selected';
  } else if (elem.type == 'select-multiple'){
    elem.options[0].selected = 'selected';
  } else if (elem.type == 'radio'){
    if (elem.length){
      for (var ii=0; ii<elem.length; ii++){
        elem[ii].checked = false;
      }
    } else {
      elem.checked = false;
    }
  } else if (elem.type == 'checkbox'){
    if (elem.length){
      for (var ii=0; ii<elem.length; ii++){
        elem[ii].checked = false;
      }
    } else {
      elem.checked = false;
    }
  } else {
    elem.value = '';
  }
  return true;
}

Tools.stripSpace = function(attr){
  var result = '';
  if (attr){
    attr = new String(attr);
    result = attr.replace(/^\s+/,'');
    result = result.replace(/\s+$/,'');
  }
  return result;
}

Tools.checkDataSize = function(elem, size) {
  if (!arguments.length) {
    return false;
  }
  var _type = elem.type.toLowerCase();
  var _value = Tools.stripSpace(elem.value);
  if (_type == 'textarea'){
    if (_value.length >= size){
      elem.value = _value.substring(0, size);
    }
  }
}

Tools.validateEmail = function(elem) {
  if (!arguments.length) {
    return false;
  }
  var _value = Tools.stripSpace(elem.value);
  var regEx = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)(\\@)([a-zA-Z0-9\\-\\.]+)(\\.)([a-zA-Z]{2,4})$');
  if (! _value.match(regEx)){
    alert('Bitte geben Sie eine gültige E-Mail-Adresse an!');
    elem.focus();
  }
}

Tools.validateURL = function(elem) {
  if (!arguments.length) {
    return false;
  }
  var _value = Tools.stripSpace(elem.value);
  var regEx = new RegExp('^(http:\/\/|https:\/\/|mailto:\/\/|ftp:\/\/|\/)');
  if (! _value.match(regEx)){
    alert('Bitte geben Sie eine gültige URL an!\nEine gültige URL muß mit http://, https://, etc. anfangen');
    elem.focus();
  }
}

Tools.openLinkinOpener = function(url) {
  if (!arguments.length) {
    return false;
  }
  var root;
  if (window.opener){
    root = window.opener;
  }
  if (parent.opener){
    root = parent.opener;
  }
  if (parent.top.opener){
    root = parent.top.opener;
  }
  if (! root){
    return true;
  }
  root.location = url;
  root.focus();
  return false;
}

Tools.submitQuichsearch = function(htmlElement) {
  if (!arguments.length) {
    return false;
  }
  var tagName = htmlElement['tagName'];
  tagName = tagName.toLowerCase();
  if (tagName == 'form'){
    var regExp = new RegExp('Stichwort|Stichwort eingeben|Suchwort|Suchwort eingeben|Suchbegriff|Suchbegriff eingeben');
    for (var i=0; i<htmlElement.elements.length; i++){
      var _value = Tools.stripSpace(htmlElement.elements[i].value);
      if(! _value.match(regExp)){
        continue;
      }
      htmlElement.elements[i].value = '';
    }
    return true;
  }
}

Tools.formatCashFloat = function(n){
  cash_float = parseFloat(new String(n).replace(/\,/,'.'));
  cash_float = parseFloat(cash_float * 100);
  cash_float = parseFloat(Math.round(cash_float) / 100);
  cash_float = new String(cash_float);
  if (!cash_float.match(/\./)){
    cash_float = cash_float + '.00';
  }
  if (cash_float.split(/\./)[1].length == 1){
    cash_float = cash_float + '0';
  }
  cash_float = cash_float.replace(/\./,',');
  return cash_float;
}


Tools.addEvent = function(oneEvent, obj, handler, bol, ieWindow){
  if (arguments.length < 3) {
    focus();
    throw new Error('Tools.addEvent: Falsche Anzahl von Argumenten!');
  }
  if(window.addEventListener){
    obj.addEventListener(oneEvent, handler, bol);
  } else if(obj.attachEvent){
    var win = window;
    if (ieWindow) {
      win = ieWindow;
    }
    obj['e' + oneEvent + handler] = handler;
    obj[oneEvent + handler] = function() { obj['e' + oneEvent + handler] ( win.event ); win.event.cancelBubble = true;};
    obj.attachEvent('on' + oneEvent, obj[oneEvent + handler]);
  }
  return true;
}


Tools.removeEvent = function(oneEvent, obj, handler, bol){
  if (arguments.length < 3) {
    focus();
    throw new Error('Tools.removeEvent: Falsche Anzahl von Argumenten!');
  }
  if(window.removeEventListener){
    obj.removeEventListener(oneEvent, handler, bol);
  } else if(obj.detachEvent){
    obj.detachEvent( "on"+ oneEvent, obj[oneEvent + handler] );
    obj[oneEvent + handler] = undefined;
    obj["e" + oneEvent + handler] = undefined;
  }
  return true;
}


Tools.bookmark = function(url, title){
  if (! url.length) {
    return true;
  }
  if (! title.length) {
      title = 'Mein Bookmark';
  }
  if (window.opera && window.print) {
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
    return false;
  } else if (document.all) {
    window.external.AddFavorite(url,title);
    return false;
  } else if (window.sidebar) {
    window.sidebar.addPanel(title,url,"");
    return false;
  }
  return true;
}





var undefined;

function Captcha(idx) {
  this.id = undefined;
  this.token = undefined;
  this.captchaString = undefined;
  this.numberImageRequest = 0;
  this.numberCaptchaTest = 0;
  this.form = undefined;
  this.ajax = undefined;
  this.mode = 'standard' // standard, ajax
  this.lang = 'de';
  
  this._setID(idx);
  this._init();
}


Captcha.prototype._init = function () {
  this.ajax = Ajax.createInstance(this.id);
  this.ajax.setAsynchron(false);
  this.ajax.setMethod('GET');
  if (this.mode == 'Ajax') {
    return;
  }
  var idx = new String(this.id);
  var func = function () {
    Captcha._documentHasLoad = true;
    Captcha.getInstance(idx).drawCaptchaImage();
  }
  Captcha.addEvent('load',window,func);
}


Captcha.prototype._setID = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Captcha->_setID: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Captcha->_setID: Argument str ist nicht vom Typ String!");
  }
  this.id = str;
}


Captcha.prototype._setToken = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Captcha->_setToken: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Captcha->_setToken: Argument str ist nicht vom Typ String!");
  }
  this.token = str;
  this.setTokenInput();
}          


Captcha.prototype._setMode = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Captcha->_setMode: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Captcha->_setMode: Argument str ist nicht vom Typ String!");
  }
  this.mode = str;
}     


Captcha.prototype._setCaptchaString = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Captcha->_setCaptchaString: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Captcha->_setCaptchaString: Argument str ist nicht vom Typ String!");
  }
  this.captchaString = str;
}


Captcha.prototype._setFormOnSubmit = function () {
  if (! this.form) {
    focus();
    throw new Error("Captcha->_setFormOnSubmit: HTML-Form-Element wurde nicht definiert!");
    return;
  }
  var _funcOldSubmit = this.form.onsubmit;
  var funcOldSubmit = function (event) { 
    if (_funcOldSubmit) {
      return _funcOldSubmit(); 
    }
     return true;
  }
  var idx = new String(this.id);
  var func = function (event) {
    var captchaStringElem = document.getElementById('_CAPTCHA_STRING_');
    if (! captchaStringElem){
        focus();
        throw new Error("Captcha->_setFormOnSubmit: HTML-Input-Element _CAPTCHA_STRING_ existiert nicht!");
        return false;
    }
    if (! funcOldSubmit() ) {
      return false;
    }
    if (! Captcha.getInstance(idx).validateCaptcha(captchaStringElem.value) ) {
      captchaStringElem.focus();
      return false;
    }
    return true;
  }
   this.form.onsubmit = func;
}               


Captcha.prototype.setLang = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Captcha->_setLang: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Captcha->_setLang: Argument str ist nicht vom Typ String!");
  }
  this.lang = str;
}            


Captcha.prototype.validateCaptcha = function (str) {
  if (arguments.length != 1) {
    throw new Error("Captcha->validateCaptcha: Falsche Anzahl von Argumenten!");
    return false;
  }
  if (this.numberCaptchaTest >= Captcha._numberRequest) {
    var alertStr = 'Bitte versuchen Sie es erneut mit dem nächsten Code.';
    if (this.lang == 'uk') {
        alertStr = 'Please try with another code.';
    } else if (this.lang == 'fr') {
        alertStr = 'Veuillez l\'essayer avec un autre code.';
    } 
    alert(alertStr);
    this.refreshCaptcha();
    return false;
  }
  if (this.mode=='ajax') {
    return this.validateCaptchaAjax(str);
  }
   return this.validateCaptchaStandard(str);
}  


Captcha.prototype.validateCaptchaStandard = function (str) {
  if (arguments.length != 1) {
    throw new Error("Captcha->validateCaptcha: Falsche Anzahl von Argumenten!");
    return false;
  }
  var url = Captcha._baseGenMailURL + '&ACTION=TEST_CAPTCHA';
   url += '&_TOKEN_=' + this.token;
   url += '&_CAPTCHA_STRING_=' + str;
   url += '&_NOCACHE_=' +new Date().getTime();
   var script = document.getElementById('__CAPTCHA_TOKEN_SCRIPT__');
   if (script) {
     document.getElementsByTagName('body')[0].removeChild(script);
   }
   script = document.createElement('script');
   script.id = '__CAPTCHA_TOKEN_SCRIPT__';
   document['body'].appendChild(script);
   var idx = new String(this.id);
   var func = function () {
      if (Captcha.test_result == 'false'){
        var alertStr = 'Der Code ist fehlerhaft.';
        if (Captcha.getInstance(idx).lang == 'uk') {
            alertStr = 'The code is invalid.';
        } else if (Captcha.getInstance(idx).lang == 'fr') {
            alertStr = 'Le code est défectueux.';
        } 
        alert(alertStr);
        
        return false;
      }
      if (Captcha._error){
        focus();
        var force = 1;
        Captcha.getInstance(idx).refreshCaptcha(force);
        var alertStr = 'Es ist ein Fehler aufgetreten.\nVersuchen Sie es bitte mit diesem Code.';
        if (Captcha.getInstance(idx).lang == 'uk') {
            alertStr = 'An error is occurred.\nPlease try with another code';
        } else if (Captcha.getInstance(idx).lang == 'fr') {
            alertStr = 'Une erreur est apparue .\nVeuillez l\'essayer avec un autre code.';
        } 
        alert(alertStr);
        return false;
      }
      Captcha.getInstance(idx).form.submit();
   }
   this.numberCaptchaTest++;
   Captcha.callback = func;
   script.src = url;
   return false;
}  


Captcha.prototype.validateCaptchaAjax = function (str) {
  if (arguments.length != 1) {
    throw new Error("Captcha->validateCaptcha: Falsche Anzahl von Argumenten!");
    return false;
  }
  var url = Captcha._baseGenMailURL + '&ACTION=TEST_CAPTCHA';
   url += '&_TOKEN_=' + this.token;
   url += '&_CAPTCHA_STRING_=' + str;
   url += '&_NOCACHE_=' +new Date().getTime();
   this.ajax.setURL(url);
   this.ajax.open();                                      
   this.ajax.sendNull();
   Ajax.cursorWait();
  this.numberCaptchaTest++;
   if (this.ajax.getReadyState() != 4){
      Ajax.cursorWait();
  }
  var xml = this.ajax.getReadableXMLNode();   
  var result = this.ajax.getSingleNodeValue('test-result');
  var error = this.ajax.getSingleNodeValue('error');
  var msg = this.ajax.getSingleNodeValue('msg');
  Ajax.cursorFinished();
  if (result == 'false'){
    var alertStr = 'Der Code ist fehlerhaft.';
    if (this.lang == 'uk') {
        alertStr = 'The code is invalid.';
    } else if (this.lang == 'fr') {
        alertStr = 'Le code est défectueux.';
    } 
    alert(alertStr);
    this.refreshCaptcha();
    return false;
  }
  if (error){
    focus();
    throw new Error("Captcha->validateCaptcha: " + msg + "!");
    var alertStr = 'Es ist ein Fehler aufgetreten.\nVersuchen Sie es bitte mit diesem Code.';
    if (this.lang == 'uk') {
        alertStr = 'An error is occurred.\nPlease try with another code';
    } else if (this.lang == 'fr') {
        alertStr = 'Une erreur est apparue .\nVeuillez l\'essayer avec un autre code.';
    } 
    alert(alertStr);
    this.refreshCaptcha();
    return false;
  }
  return true;
}  


Captcha.prototype.refreshCaptcha = function (force) {
  if ( this.numberCaptchaTest < Captcha._numberRequest && (! force)){
     return;
  }
  this.numberCaptchaTest = 0;
  this.numberImageRequest = 0;
  this.setFreshToken();
  if (this.mode == 'ajax'){
    this.drawCaptchaImage();
  }
}


Captcha.prototype.setFormIdx = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Captcha->setFormIdx: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Captcha->setFormIdx: Argument str ist nicht vom Typ String!");
  }
  var elem = document.getElementById(str);
  if (! elem) {
    focus();
    throw new Error("Captcha->setFormIdx: HTML-Element mit ID = " + str + " ist nicht vorhanden!");
  }
  this.form = elem;
  this._setFormOnSubmit();
}


Captcha.prototype.setFreshToken = function () {
  var url = Captcha._baseGenMailURL + '&ACTION=NEW_CAPTCHA';
 url += '&_NOCACHE_=' +new Date().getTime();
  var token = undefined;
  if (this.mode == 'ajax') {
      this.getFreshTokenAjax(url);
  } else {
      this.getFreshTokenStandard(url);
  }
}


Captcha.prototype.getFreshTokenStandard = function (url) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Captcha->getFreshTokenStandard: Falsche Anzahl von Argumenten!");
  }
  if (typeof url != "string") {
    focus();
    throw new Error("Captcha->getFreshTokenStandard: Argument "+ url +" ist nicht vom Typ String!");
  }
   var script = document.getElementById('__CAPTCHA_TOKEN_SCRIPT__');
   if (script) {
     document.getElementsByTagName('body')[0].removeChild(script);
   }
   script = document.createElement('script');
   script.id = '__CAPTCHA_TOKEN_SCRIPT__';
   document['body'].appendChild(script);
   var idx = new String(this.id);
   var func = function () {
      Captcha.getInstance(idx)._setToken(Captcha.token);
      Captcha.getInstance(idx).drawCaptchaImage();
   }
   Captcha.callback = func;
   script.src = url;
}


Captcha.prototype.getFreshTokenAjax = function (url) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Captcha->getFreshTokenAjax: Falsche Anzahl von Argumenten!");
  }
  if (typeof url != "string") {
    focus();
    throw new Error("Captcha->getFreshTokenAjax: Argument "+ url +" ist nicht vom Typ String!");
  }
  if (! this.ajax) {
    focus();
    throw new Error("Captcha->getFreshTokenAjax: Instance.ajax ist undefiniert!");
  }
  if (this.mode == 'ajax') {
  }
   this.ajax.setURL(url);
   this.ajax.open();                                      
   this.ajax.sendNull();
   Ajax.cursorWait();
   if (this.ajax.getReadyState() != 4){
      Ajax.cursorWait();
  }
  var xml = this.ajax.getReadableXMLNode();   
  var token = this.ajax.getSingleNodeValue('token');
  var error = this.ajax.getSingleNodeValue('error');
  var msg = this.ajax.getSingleNodeValue('msg');
  Ajax.cursorFinished();
  if (error){
    focus();
    throw new Error("Captcha->getFreshTokenAjax: Error!\n" + msg );
    return;
  }
   this._setToken(token);
   return this.token;
}


Captcha.prototype.drawCaptchaImage = function () {
  var imgID = '_CAPTCHA_IMAGE_' + this.id;
  if (! Captcha._documentHasLoad) {
    document.write('<img id="' + imgID + '" src="http://www.rdts-ag.de/grafik/trans.gif" title="Sicherheitscode" alt="Sicherheitscode" style="height: 80px; width: 180px; visibility: hidden; border: none; "/><br />');
    return;
  }
  if (! this.token || this.numberImageRequest > Captcha._numberRequest) {
    this.setFreshToken();
  }
   this.numberImageRequest++;
   if (! this.token){
      return;
   }
   var imgSrc = Captcha._baseImageURL + this.token;
   var img = document.getElementById(imgID);
   if (! img){ 
     return;
   } 
   var func = function() {
      document.getElementById(imgID).style.visibility = 'visible';
      document.getElementById(imgID).style.height = 'auto';
      document.getElementById(imgID).style.width = 'auto';
   }
   Captcha.addEvent('load',img,func);
   img.src = imgSrc;   
   return;
}


Captcha.prototype.setTokenInput = function () {
   var inputID = '_CAPTCHA_TOKEN_' + this.id;
   var elem = document.getElementById(inputID);
   if (elem){
     elem.value = this.token;
     return;
   }
   if (! this.form){
      focus();
      throw new Error("Captcha->setTokenInput: HTML-Form-Element wurde nicht definiert!");
      return;
   }
   var inp = document.createElement('input');
   inp.type = 'hidden';
   inp.id = inputID;
   inp.name = '_TOKEN_';   
   inp.value = this.token;
   this.form.appendChild(inp);
}


Captcha._baseGenMailURL = 'http://www.studiwerk.de/cgi-bin/captcha?';
Captcha._baseImageURL = Captcha._baseGenMailURL + '&ACTION=GET_CAPTCHA_PICTURE&amp;_TOKEN_=';
Captcha._numberRequest = 5;
Captcha._increment = [];
Captcha._registerInstance = {};
Captcha._registerInstanceLength = [];
Captcha._documentHasLoad = false;


Captcha.callback = function () {
}


Captcha.getInstance = function(id) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (! (Captcha._registerInstance[id])){
    focus();
    throw new Error("Es ist keine Captcha.Instance mit id=" + id + " registriert!");
  }
  return Captcha._registerInstance[id];
}


Captcha.createInstance = function(id) {
  if (!arguments.length) {
    id = 'Captcha' + Captcha._increment.length;
    Captcha._increment.push(1);
  }
  if (! (Captcha._registerInstance[id])){
    Captcha._registerInstance[id] = new Captcha(id);
    Captcha._registerInstanceLength.push(id);
  } else {
    focus();
    throw new Error("Captcha.createInstance: id schon vorhanden!");
  }
  return Captcha.getInstance(id);
}


Captcha.addEvent = function(oneEvent, obj, handler, bol, ieWindow){
  if (arguments.length < 3) {
    focus();
    throw new Error('Captcha.addEvent: Falsche Anzahl von Argumenten!');
  }
  if(window.addEventListener){
    obj.addEventListener(oneEvent, handler, bol);
  } else if(obj.attachEvent){
    var win = window;
    if (ieWindow) {
      win = ieWindow;
    }
    obj['e' + oneEvent + handler] = handler;
    obj[oneEvent + handler] = function() { obj['e' + oneEvent + handler] ( win.event ); win.event.cancelBubble = true;};
    obj.attachEvent('on' + oneEvent, obj[oneEvent + handler]);
  }
  return true;
}


Captcha.removeEvent = function(oneEvent, obj, handler, bol){
  if (arguments.length < 3) {
    focus();
    throw new Error('Captcha.removeEvent: Falsche Anzahl von Argumenten!');
  }
  if(window.removeEventListener){
    obj.removeEventListener(oneEvent, handler, bol);
  } else if(obj.detachEvent){
    obj.detachEvent( "on"+ oneEvent, obj[oneEvent + handler] );
    obj[oneEvent + handler] = undefined;
    obj["e" + oneEvent + handler] = undefined;
  }
  return true;
}



function Ajax(id) {
  this.id;
  this.req = undefined;
  this.url = '';
  this.asynchron = true;
  this.parameter = {};
  this.parameterLength = [];
  this.mimeType = 'text/xml';
  this.requestHeader = 'application/x-www-form-urlencoded';
  this.callBackFunction = undefined;
  this.method = 'GET';

  this._setID(id);
}


Ajax.prototype._setID = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Ajax->_setID: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Ajax->_setID: Argument str ist nicht vom Typ String!");
  }
  this.id = str;
}


Ajax.prototype.createRequest = function () {
  var req;
  if (window.ActiveXObject) {
    try {
      req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    }
  } else if (typeof XMLHttpRequest != undefined) {
    req = new XMLHttpRequest();
    /*
    if (this.mimeType){
      req.overrideMimeType(this.mimeType);
    }*/
  } else {
    focus();
    throw new Error("Ajax->createRequest: Der Browser unterstützt die Methode nicht!");
  }
  return req;
}


Ajax.prototype.addParameter = function (strKey, strValue) {
  if (arguments.length != 2) {
    focus();
    throw new Error("Ajax->addParameter: Falsche Anzahl von Argumenten!");
  }
  if (typeof strKey != "string") {
    focus();
    throw new Error("Ajax->addParameter: Argument strKey ist nicht vom Typ String!");
  }
  if (typeof strValue != "string") {
    focus();
    throw new Error("Ajax->addParameter: Argument strValue ist nicht vom Typ String!");
  }
  this.parameter[strKey] = strValue;
  this.parameterLength.push(strKey);
}


Ajax.prototype.setRequestHeader = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Ajax->setRequestHeader: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Ajax->setRequestHeader: Argument str ist nicht vom Typ String!");
  }
  this.requestHeader = str;
}


Ajax.prototype.setAsynchron = function (b) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Ajax->setAsynchron: Falsche Anzahl von Argumenten!");
  }
  if (typeof b != "boolean") {
    focus();
    throw new Error("Ajax->setAsynchron: Argument str ist nicht vom Typ Boolean!");
  }
  this.asynchron = b;
}


Ajax.prototype.setMethod = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Ajax->setMethod: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Ajax->setMethod: Argument str ist nicht vom Typ String!");
  }
  if (str!='GET' && str!='POST' && str!='HEAD'){
    focus();
    throw new Error("Ajax->setMethod: Argument str muss Wert GET oder POST oder HEAD haben!");
  }
  this.method = str;
}


Ajax.prototype.setURL = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Ajax->setURL: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Ajax->setURL: Argument str ist nicht vom Typ String!");
  }
  this.url = str;
}


Ajax.prototype.setCallBackFunction = function (func) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Ajax->setCallBackFunction: Falsche Anzahl von Argumenten!");
  }
  if (typeof func != "function") {
    focus();
    throw new Error("Ajax->setCallBackFunction: Argument func ist nicht vom Typ Function!");
  }
  this.callBackFunction = func;
}


Ajax.prototype.open = function () {
  this.req = this.createRequest();
  if (this.method == 'POST'){
    if (! this.requestHeader){
      focus();
      throw new Error("Ajax->open: Mehtod=POST requires requestHeader !");
    }
  }
  try {
    this.req.open(this.method, this.url, this.asynchron);
    if (this.callBackFunction){
      this.req.onreadystatechange = this.callBackFunction;
    }
  } catch(e){
    alert(e);
    Ajax._getNavigatorPrivilege(this);
  }
}


Ajax.prototype.sendAll = function () {
  var _req = '';
  for (var i in this.parameter){
    if (Ajax.getCharset() == 'utf-8' || Ajax.getCharset() == 'utf-16'){
      _req += '&' + i + '=' + encodeURIComponent(this.parameter[i]);
    } else {
      _req += '&' + i + '=' + escape(this.parameter[i]);
    }
  }
  _req = _req.replace(/^\&/,'');
  this.req.send(_req);
}


Ajax.prototype.sendNull = function () {
  this.req.send(null);
}


Ajax.prototype.send = function (strKey, strValue) {
  if (arguments.length != 2) {
    focus();
    throw new Error("Ajax->send: Falsche Anzahl von Argumenten!");
  }
  if (typeof strKey != "string") {
    focus();
    throw new Error("Ajax->send: Argument strKey ist nicht vom Typ String!");
  }
  if (typeof strValue != "string") {
    focus();
    throw new Error("Ajax->send: Argument strValue ist nicht vom Typ String!");
  }
  if (Ajax.getCharset() == 'utf-8' || Ajax.getCharset() == 'utf-16'){
    this.req.send(strKey + '=' + encodeURIComponent(strValue));
  } else {
    this.req.send(strKey + '=' + escape(strValue));
  }
}


Ajax.prototype.getReadyState = function () {
  if (this.req.readyState == undefined){
    return undefined;
  }
  return this.req.readyState;
}


Ajax.prototype.getStatus = function () {
  if (this.req.status == undefined){
    return undefined;
  }
  return this.req.status;
}


Ajax.prototype.getResponseXML = function () {
  return this.req.responseXML;
}


Ajax.prototype.getResponseText = function () {
  return this.req.responseText;
}


Ajax.prototype.getXML = function (str) {
  str = Ajax.stripSpace(str);
  if (arguments.length != 1) {
    focus();
    throw new Error("Ajax->getXML: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Ajax->send: Argument str ist nicht vom Typ String!");
  }
  var xml = '';
  if (window.DOMParser){
    var parser = new DOMParser();
    xml = parser.parseFromString(str, "text/xml");
  } else {
    xml = new ActiveXObject("Microsoft.XMLDOM");
    xml.async="false";
    xml.loadXML(str);
  }
  return xml;
}


Ajax.prototype.getReadableXMLNode = function () {
  if (! this.req.responseXML){
    return undefined;
  }
  return this.req.responseXML.documentElement;
}


Ajax.prototype.getSingleNodeValue = function (name) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Ajax->getSingleNodeValue: Falsche Anzahl von Argumenten!");
  }
  if (typeof name != "string") {
    focus();
    throw new Error("Ajax->getSingleNodeValue: Argument name ist nicht vom Typ String!");
  }
  var xml = this.getReadableXMLNode();
  if (! xml){
    return undefined;
  }
  for (var i=0; i<xml.childNodes.length; i++) {
    var node = xml.childNodes[i];
    if (node.nodeType != 1){
      continue;
    }
    if (node.nodeName.toLowerCase() != name){
      continue;
    }
    return this.getValueFromXMLNode(node);
  }
  return undefined;
}


Ajax.prototype.getValueFromXMLNode = function (node) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Ajax->getValueFromXMLNode: Falsche Anzahl von Argumenten!");
  }
  return node.firstChild.nodeValue;
}


Ajax.prototype.getIdenticalNodeArray = function (name) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Ajax->getIdenticalNodeArray: Falsche Anzahl von Argumenten!");
  }
  if (typeof name != "string") {
    focus();
    throw new Error("Ajax->getIdenticalNodeArray: Argument name ist nicht vom Typ String!");
  }
  var xml = this.getReadableXMLNode();
  if (! xml){
    return undefined;
  }
  return xml.getElementsByTagName(name);
}


Ajax._increment = [];
Ajax._registerInstance = {};
Ajax._registerInstanceLength = [];


Ajax._getNavigatorPrivilege = function (obj) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Ajax._getNavigatorPrivilege: Falsche Anzahl von Argumenten!");
  }
  if (! (obj instanceof Ajax)) {
    focus();
    throw new Error("Ajax._getNavigatorPrivilege: Argument obj ist keine Instance von Ajax!");
  }
  if (obj.req) {
    if (typeof netscape != 'undefined' && typeof netscape.security != 'undefined' && typeof netscape.security.PrivilegeManager != 'undefined') {
      netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
      obj.open();
    } else {
      focus();
      throw new Error("Ajax._getNavigatorPrivilege: Das Ajax-Progamm läuft in diesem Kontext nicht. bitte wenden Sie sich an Ihren Administrator!");
    }
  }
}


Ajax.stripSpace = function(attr){
  var result = '';
  if (attr){
    attr = new String(attr);
    result = attr.replace(/^\s+/,'');
    result = result.replace(/\s+$/,'');
  }
  if (result.match(/^\s+/) || result.match(/\s+$/)){
    return Ajax.stripSpace(result);
  }
  return result;
}


Ajax.getInstance = function(id) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (! (Ajax._registerInstance[id])){
    focus();
    throw new Error("Es ist keine Ajax.Instance mit id=" + id + " registriert!");
  }
  return Ajax._registerInstance[id];
}


Ajax.createInstance = function(id) {
  if (!arguments.length) {
    id = 'Ajax' + Ajax._increment.length;
    Ajax._increment.push(1);
  }
  if (! (Ajax._registerInstance[id])){
    Ajax._registerInstance[id] = new Ajax(id);
    Ajax._registerInstanceLength.push(id);
  } else {
    focus();
    throw new Error("Ajax.createInstance: id schon vorhanden!");
  }
  return Ajax.getInstance(id);
}


Ajax.cursorWait = function () {
  if (! document.getElementsByTagName('body').length){
    return;
  }
  document.getElementsByTagName('body')[0].style.cursor = 'wait';
}


Ajax.cursorFinished = function () {
  if (! document.getElementsByTagName('body').length){
    return;
  }
  document.getElementsByTagName('body')[0].style.cursor = 'auto';
}


Ajax.getCharset = function () {
  if (document.charset){
    return document.charset.toLowerCase();
  } else if (document.characterSet) {
    return document.characterSet.toLowerCase();
  } else {
    return undefined;
  }
}



