  var nav_curr = null;
  function $ID(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() {
    var em = $('<div style="visibility: hidden; position: absolute; left: 0; top: 0; height: 1em">&nbsp;</div>').appendTo(document.body).height();
    var init_scrollbar = function() {
        var box = $(this).offset();
        box.width = $(this).outerWidth();
        box.height = $(this).outerHeight();

        var slider, slider_box, that = this, moving = null;
        var max = function() { return Math.max(that.scrollHeight - $(that).outerHeight(false), 0) };
        var scrollbar_area = box.height - 34, // 2*arrow + inner margin
            scrollbar_height = Math.max(10/*min height*/, Math.ceil(scrollbar_area / Math.max(1, (that.scrollHeight / $(that).outerHeight(false))))),
            scrollbar_max = scrollbar_area - scrollbar_height;
        var scrollbar_position = Math.round(scrollbar_max * (that.scrollTop / Math.max(1, max())));
        var set_slider = function(pos) {
            slider.css('top', 15 + (scrollbar_position = Math.round(scrollbar_max * (pos / Math.max(1, max())))))
        };
        var scroll = function(pos) {
            $(that).scrollTop(pos).scroll();
        }
        var arrow_interval = null;
        var arrow = function(n) {
            return function(e) {
                if(arrow_interval) { clearInterval(arrow_interval); arrow_interval = null; }
                var fn = function() { scroll($(that).scrollTop() + em * 1.5 * n); };
                fn();
                if(!jQuery.browser.opera) arrow_interval = setInterval(fn, 200);
            }
        };
        var arrow_stop = function() {
            clearInterval(arrow_interval);
            arrow_interval = null;
        };
        $(that).scroll(function() {
            set_slider(this.scrollTop);
        });
        slider_box = $('<div class="_x_scrollbar"></div>')
            .data('el', this)
            .css({
                background: 'white',
                width: 17,
                height: box.height,
                left: box.left + box.width - 17,
                top: box.top,
                position: 'absolute'
            })
            .append($('<div></div>')
                .css({
                    background: '#f0f0f0',
                    margin: 2,
                    width: 13,
                    height: box.height - 4,
                    position: 'relative'
                })
                .append($('<div></div>')
                    .css({
                        background: 'url(/graphics/scroll_up.png)',
                        width: 13,
                        height: 13,
                        position: 'absolute',
                        left: 0,
                        top: 0
                    })
                    .mousedown(arrow(-1))
                    .mouseup(arrow_stop)
                    .mouseleave(arrow_stop)
                )
                .append($('<div></div>')
                    .css({
                        background: 'url(/graphics/scroll_down.png)',
                        width: 13,
                        height: 13,
                        position: 'absolute',
                        left: 0,
                        bottom: 0
                    })
                    .mousedown(arrow(1))
                    .mouseup(arrow_stop)
                    .mouseleave(arrow_stop)
                )
                .append(slider = $('<div></div>')
                    .css({
                        background: '#d6d6d6',
                        position: 'absolute',
                        width: 13,
                        height: scrollbar_height,
                        top: 15 + scrollbar_position,
                        left: 0
                    })
                    .mousedown(function(e) {
                        //s=''; for(i in e) { if(e[i] && e[i].toString && e[i].toString().search(/^[0-9]+$/)==-1) continue; s+= i+" = " +e[i]+"\n"; } alert(s);
                        moving = {mouse: e.clientY, box: $(that).scrollTop(), bar: scrollbar_position};
                    })
                )
            )
            .mousemove(function(e) { // here for better behaviour - leaving the scrollbar can happen
                if(!moving) return;
                var now = {mouse: e.clientY, box: $(that).scrollTop(), bar: scrollbar_position};
                
                scroll(Math.max(0, Math.min(scrollbar_max, (now.mouse - moving.mouse) + moving.bar)) * max() / scrollbar_max);
            })
            .appendTo(document.body)
            .find('*').andSelf().bind('dragstart', function() { return false; });

        $(document.body).mouseup( // here for better behaviour - mousedown anywhere stops the scrollbar
            function() {
                moving = null;
            }
        );
    };
    $('div.scroll_box').each(init_scrollbar);
    var reinit = function() {
        $('div._x_scrollbar').remove();
        $('div.scroll_box').each(init_scrollbar);
    };
    $(window)
        .resize(reinit)
        .load(reinit);
});

/*
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;
}
*/
