  var nav_curr = null;
  function $(a) { return document.getElementById(a); }
  function menushow(t)
  {
      if(menuhide_element == t) {
          clearTimeout(menuhide_timeout);
          menuhide_timeout = null;
          menuhide_element = null;
          return;
      }
      else if(menuhide_element) {
          menuhide(menuhide_element, 'FORCE');
      }
      
      if(!(els = t.getElementsByTagName('ul'))) return;
      if(!(el = els[0])) return;
      el.style.display = "block";
  }
  function menuhide(t, flags)
  {
      if(t == menuhide_element) return;

      var el;
      if(!(els = t.getElementsByTagName('ul'))) return;
      if(!(el = els[0])) return;

      if(typeof(flags) != 'undefined' && flags == 'FORCE') {
          el.style.display = "none";
          menuhide_timeout = null;
          menuhide_element = null;
      }
      else {
          menuhide_element = t;
          menuhide_timeout = setTimeout(function() { el.style.display = "none"; menuhide_timeout = null; menuhide_element = null; }, 100);
      }
  }
  function navout()
  {
      if(nav_q.length == 0 || nav_q[nav_q.length - 1].type != "out") {
          nav_q[nav_q.length] = {set: 100, step: -50, pos_after: "430px", type: 'out'};
      }
  }
  
  function nav_int_func() {
      nav_int_lastcall = new Date();

      if(nav_curr == null && nav_q.length > 0) {
          if(nav_q.length > 2) nav_q = nav_q.slice(nav_q.length - (nav_q.length%2));
          nav_curr = nav_q[0];
          nav_q = nav_q.slice(1);

          if(!nav_element) {
              nav_element = document.getElementById('navhover');
          }
          if(nav_curr && typeof(nav_curr.pos_before) == "string") nav_element.style.top = nav_curr.pos_before;
          if(nav_curr && typeof(nav_curr.set) != "undefined") nav_opa = nav_curr.set;
      }
      
      if(nav_curr) {
          nav_opa += nav_curr.step;
          if(nav_opa < 0) nav_opa = 0;
          if(nav_opa > 100) nav_opa = 100;

          nav_element.style.opacity = (nav_opa/100);
          if(nav_element.filters) {
              try { nav_element.filters("DXImageTransform.Microsoft.Alpha").opacity = nav_opa; }
              catch(e) {}
          }
          if(nav_opa == 0 || nav_opa == 100) {
              if(typeof(nav_curr.pos_after) == "string") nav_element.style.top = nav_curr.pos_after;
              nav_curr = null;
          }
      }
  }
  function navhover(n)
  {
      if(nav_q.length == 0 || nav_q[nav_q.length - 1].type != "in") {
          nav_q[nav_q.length] = {set: 0, step: 34, pos_before: "" + (430 * -n) + 'px', type: 'in'};
      }
      
      if(((new Date()).getTime() - nav_int_lastcall.getTime()) > 100) {
          clearInterval(nav_int);
          nav_int = setInterval(nav_int_func, 50);
      }
  }

function form_check(f)
{
    var errors  = "";
    var tab = f.getElementsByTagName('table')[0];
    for(var i = 0; i < tab.rows.length - 1; i++) {
        if(tab.rows[i].className.indexOf("required") == -1) {
            continue;
        }
        
        var el = tab.rows[i].getElementsByTagName('select');
        if(!el[0]) el = tab.rows[i].getElementsByTagName('input');
        if(!el[0]) el = tab.rows[i].getElementsByTagName('textarea');
        if(!el[0]) continue;
        
        if(el[0].tagName == "SELECT") {
            if(el[0].value == "-1") {
                errors += tab.rows[i].title + "\n";
            }
            continue;
        }
        if(el[0].type == "radio") {
            var val = "";
            for(var k = 0; k < el.length; k++) {
                if(el[k].checked) {
                    val = el[k].value;
                    break;
                }
            }
            if(val == "") {
                errors += tab.rows[i].title + "\n";
            }
            continue;
        }
        if(el[0].value == "") {
            errors += tab.rows[i].title + "\n";
            continue;
        }
    }
    
    if(errors.length > 0) {
        alert("Bitte füllen Sie alle Felder, die mit einem * gekennzeichnet sind, aus:\n\n" + errors);
        return false;
    }
    return true;
}

function getStyle(el, prop) {
  if (document.defaultView && document.defaultView.getComputedStyle) {
    return document.defaultView.getComputedStyle(el, null)[prop];
  } else if (el.currentStyle) {
    return el.currentStyle[prop];
  } else {
    return el.style[prop];
  }
}
var scrollbars_active = new Array();
function scrollbars_move(e)
{
    if(!e) { e = window.event; }
    
    for(var i = 0; i < scrollbars_active.length; i++) {
        if(!scrollbars_active[i].drag_start) return;
        
        var ypos = (scrollbars_active[i].currentPos + e.screenY - scrollbars_active[i].drag_start.y);
        ypos = Math.max(ypos, 0);
        ypos = Math.min(ypos, scrollbars_active[i].barbar_container_height - scrollbars_active[i].barbar_height);
        scrollbars_active[i].style.borderTop = ypos + 'px solid #F0F0F0';
        
        scrollbars_active[i].scroll_element.scrollTop = (ypos * scrollbars_active[i].barbar_coefficient);
    }
}
function scrollbars_up()
{
    for(var i = 0; i < scrollbars_active.length; i++) {
        scrollbars_active[i].drag_start = null;
        scrollbars_active[i].currentPos = parseInt(scrollbars_active[i].style.borderTop.replace(/^.*(^| )([0-9]+)px.*$/, '$2'));
    }
    scrollbars_active.length = 0;
}

function getOffsetLeft(e)
{
    var sum = 0;
    while(e && e.id != "right") { sum += e.offsetLeft; e = e.offsetParent; }
    return sum;
}
function getOffsetTop(e)
{
    var sum = 0;
    while(e && e.id != "right") { sum += e.offsetTop; e = e.offsetParent; }
    return sum;
}
function scrollbars_init(id)
{
    var box = document.getElementById(id);
    //alert(box.offsetHeight +" "+ box.scrollHeight);
    if(box.offsetHeight >= box.scrollHeight) return;

    var barbar_container_height = (box.offsetHeight - 4 - 4 - 13 - 13);
    var tmp_height = Math.ceil((box.offsetHeight / box.scrollHeight) * barbar_container_height);
    var barbar_height = Math.max(15, tmp_height);
    var barbar_coefficient = (box.offsetHeight + barbar_height) / tmp_height;

    box.style.overflow = "hidden";
    box.style.paddingRight = "27px";
    box.style.width = "174px";

    var bar = document.createElement('div');
    bar.style.background = "#F0F0F0";
    bar.style.position = "absolute";
    bar.style.width = "13px";
    bar.style.height = (box.offsetHeight - 4) + 'px';
    bar.style.left = (196 + getOffsetLeft(box)) + "px";
    bar.style.top = (2 + getOffsetTop(box)) + "px";
    
    var up = document.createElement('div');
    up.style.background = "url('/graphics/scroll_up.png')";
    up.style.width = "13px";
    up.style.height = "13px";
    up.onmouseover = function() { up.style.backgroundPosition = "0px -13px"; }
    up.onmouseout = function() { up.style.backgroundPosition = "0px 0px"; }
    up.onmouseup = function() {
        ypos = barbar.currentPos - 10;
        ypos = Math.max(ypos, 0);
        barbar.style.borderTop = ypos + 'px solid #F0F0F0';
        box.scrollTop = (ypos * barbar_coefficient);
        barbar.currentPos = ypos;
    }
    
    var barbar_container = document.createElement('div');
    barbar_container.style.height = barbar_container_height + 'px';
    barbar_container.style.margin = "2px 0";
    
    var barbar = document.createElement('div');
    barbar.style.background = "#D6D6D6";
    barbar.style.height = barbar_height + "px";
    barbar.onmouseover = function() { barbar.style.backgroundColor = "#D0D0D0"; }
    barbar.onmouseout = function() { barbar.style.backgroundColor = "#D6D6D6"; }
    barbar.currentPos = 0;
    barbar.barbar_container_height = barbar_container_height;
    barbar.barbar_height = barbar_height;
    barbar.barbar_coefficient = barbar_coefficient;
    barbar.scroll_element = box;
    barbar.onmousedown = function(e) {
        if(!e) { e = window.event; }

        barbar.drag_start = {x: e.screenX, y: e.screenY};
        scrollbars_active[scrollbars_active.length] = barbar;
    }
    var down = document.createElement('div');
    down.style.background = "url('/graphics/scroll_down.png')";
    down.style.width = "13px";
    down.style.height = "13px";
    down.onmouseover = function() { down.style.backgroundPosition = "0px -13px"; }
    down.onmouseout = function() { down.style.backgroundPosition = "0px 0px"; }
    down.onmouseup = function() {
        ypos = barbar.currentPos + 10;
        ypos = Math.min(ypos, barbar_container_height - barbar_height);
        barbar.style.borderTop = ypos + 'px solid #F0F0F0';
        box.scrollTop = (ypos * barbar_coefficient);
        barbar.currentPos = ypos;
    }
    
    var a = new Array(bar, barbar, barbar_container, down, up);
    for(var i = 0; i < a.length; i++) {
        a[i].onselectstart = function() { return false; }
        a[i].oncontrolselect = function() { return false; }
        a[i].ondragstart = function() { return false; }
        a[i].ondragenter = function() { return false; }
        a[i].ondrag = function() { return false; }
    }

    barbar_container.appendChild(barbar);
    
    bar.appendChild(up);
    bar.appendChild(barbar_container);
    bar.appendChild(down);
    
    var right = document.getElementById('right');
    right.insertBefore(bar, right.firstChild);
    
    document.body.onmousemove = scrollbars_move;
    document.body.onmouseup = document.body.onmouseleave = scrollbars_up;
}
