// browser sniffer
function Browser(){
  this.iE = navigator.appName.toLowerCase().indexOf('microsoft') != -1 ? 1 : 0;
  this.mac =  navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 1 : 0;
  this.win = navigator.userAgent.toLowerCase().indexOf('windows') != -1 ? 1 : 0;
  this.safari =  navigator.userAgent.toLowerCase().indexOf('safari') != -1 ? 1 : 0;
  this.opera =  navigator.userAgent.toLowerCase().indexOf('opera') != -1 ? 1 : 0;    
  this.mozilla = navigator.appName.toLowerCase().indexOf('netscape') != -1 && !this.safari ? 1 : 0;
  this.winMozilla = this.mozilla && this.win ? 1 : 0;
  this.winIE = this.iE && this.win && !this.opera ? 1 : 0;
  this.macIE = this.iE && this.mac ? 1 : 0;
}
var browser = new Browser();

	function popup(sUrl, nWidth, nHeight)  {
		popupWindow = window.open(
			sUrl
			, "popup"
			, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,dependent=yes,width=" + nWidth + ",height=" + nHeight + ",left=40,top=40"
		);
		if (popupWindow.opener == null)
			popupWindow.opener = self;
		popupWindow.focus();
	}
   
// addStyle
function addStyle(selector,properties){
  if (document.styleSheets) {
    var s = document.getElementsByTagName('STYLE');
    if (s.length == 0){
      var sheet = document.createElement('style');
      sheet.setAttribute('type','text/css');
      document.getElementsByTagName('HEAD')[0].appendChild(sheet);}
    if (browser.winIE){
      var lastSheet = document.styleSheets[document.styleSheets.length - 1];
      lastSheet.addRule(selector, properties);}
    else {var lastSheet = s[0];
      lastSheet.appendChild(document.createTextNode(selector + ' { ' + properties + ' }'));}
  	}
};
addStyle('.drempel','display:none;');

// getElementById
function getEl(id){
  return document.getElementById(id);
}

//top nav
var activeMenu;
 active = function(id) {
 var nav = document.getElementById(id);
 if (!nav){return;}
var e = nav.getElementsByTagName("LI");
for (var i=0; i<e.length; i++) {
	e[i].onmouseover=function() {
     if (activeMenu){activeMenu.onmouseout();}
     activeMenu = this;
		this.className+=" active";
	}
	e[i].onmouseout=function() {
		this.className=this.className.replace(/active/g, '');
		}
	}
	navFocus(id,true);
};

navFocus = function(id,mouseOverMenu){
   var subnav = document.getElementById(id);
   if (!subnav){return;}  
   var list = subnav.getElementsByTagName("A");
   for (var i = 0; i < list.length; i++){
     var e = list[i];
     if (e.parentNode.parentNode.id == id){
	  if (mouseOverMenu){
	    e.onfocus = function(){this.parentNode.onmouseover();}
	  }
	  else {
	    e.onfocus = function(){this.parentNode.onclick();}
	  }
     }
   }
 if (list.length == 0){return;}
   var lastSub = list[list.length-1];
   if (lastSub.parentNode.parentNode.id == id){return;}
   lastSub.onblur = function(){
     this.parentNode.parentNode.parentNode.onmouseout();
   }
 };
 

//zebra stripe tables
  var setZebra = function() {
  var tables = document.getElementsByTagName('table');  
  for(var x = 0; x != tables.length; x++){
    var table = tables[x];
    if (! table) { return; }
    if (tables[x].className=='data'){
    var tbodies = table.getElementsByTagName('tbody');
    for (var h = 0; h < tbodies.length; h++) {
      var even = true;
      var trs = tbodies[h].getElementsByTagName('tr');
      for (var i = 0; i < trs.length; i++) {
        trs[i].onmouseover=function(){
          this.className += ' ruled'; return false
        }
        trs[i].onmouseout=function(){
          this.className = this.className.replace('ruled', ''); return false
        }  
        if(even)
          trs[i].className += ' even';
        even = !even;
        }
      }
    }
  }
};

//remove borders
var setBorder = function(){
var rbg = document.getElementsByTagName('input');
for (var i = 0; i < rbg.length; i++) {
if(rbg[i].getAttribute('type')=='radio' || rbg[i].getAttribute('type')=='checkbox'){
		  rbg[i].style.border='none';
		  rbg[i].style.width='auto';
		  rbg[i].style.position='relative';
		  rbg[i].style.top='-2px';
  		}
	}
};

//hover form buttons
var setHover = function(){
var hbg = document.getElementsByTagName('input');
	for (var i = 0; i < hbg.length; i++) {    
	  if(hbg[i].getAttribute('type')=='submit' || hbg[i].getAttribute('type')=='reset' || hbg[i].getAttribute('type')=='button' || hbg[i].getAttribute('type')=='file') {
	    hbg[i].onmouseover=function(){
	      this.className = 'buttonhover';
	    }
	    hbg[i].onmouseout=function(){
	      this.className = 'button';
	    }
	  }
	}
};

function setSearch() { 
  var e = document.getElementById('search').style;
  var el = document.getElementById('toggle').style;
  if (e.display == "none") { 
    e.display = "block"; 
    el.color = "#F1F2F5";
    el.background = "#003082";
  } 
    else if (e.display == "block") { 
    e.display = "none"; 
    el.color = "#003082";
    el.background = "#F1F2F5";
  } 
};

function Finder(n) {
  var root = n;
  if (!root) return false;
  var id = root.id;
  
  function getOffsetLeft(n) {
    for (var i = 0; n; n = n.offsetParent)
      i += n.offsetLeft;
    return i;
  }
  function getOffsetTop(n) {
    for (var i = 0; n; n = n.offsetParent)
      i += n.offsetTop;
    return i;
  }
  
  function getChildElements(n, name) {
    var list = [];
    for (var n = n.firstChild; n; n = n.nextSibling)
      if (n.nodeType == 1 && (!name || name.toLowerCase() == n.tagName.toLowerCase()))
        list[list.length] = n;
    return list;
  }
  
  function getListHeight(n) {
    return getOffsetTop(n.lastItem) + n.lastItem.offsetHeight - getOffsetTop(n.firstItem);
  }
  
  function activate(e) {
    if (!e) var e = window.event;
    var item = this.parentNode;
    if (active != null) {
      var descendant = false;
      for (var n = item.parentNode.parentItem; n; n = n.parentNode.parentItem) {
        if (n == active) {
          descendant = true;
          break;
        }
      }
      if (descendant) {
        active.className = "activated";
        active.parentNode.parentNode.className = "list activated";
      }
      else {
        for (var n = active; n; n = n.parentNode.parentItem) {
          n.className = "";
          n.parentNode.parentNode.className = "list";
          if (n.childList) n.childList.parentNode.className = "list";
          var sibling = false;
          for (var n2 = n.parentNode.firstChild; n2; n2 = n2.nextSibling) {
            if (n2 == item) {
              sibling = true;
              break;
            }
          }
          if (sibling) break;
        }
      }
    }
    active = item;
    item.className = "activated";
    item.parentNode.parentNode.className = "list activated";
    var list = item.childList;
    if (list) {
      list.parentNode.className = "list active";
      rootCont.shiftTo(Math.max(0, item.parentNode.level - columnCount + 2) * -listWidth);
      return false;
    }
  }
  
  function shiftTo(i) {
    this.shiftTarget = i;
    root.scrollLeft = 0;
    if (!this.shifting) {
      this.shifting = true;
      this.shift();
    }
  }
  function shiftFrame() {
    var i = (this.style.left != "") ? parseInt(this.style.left) : 0;
    if (i != this.shiftTarget) {
      if (i > this.shiftTarget)
        i = Math.max(this.shiftTarget, i - Math.max(1, (i - this.shiftTarget) / 2));
      else
        i = Math.min(this.shiftTarget, i + Math.max(1, (this.shiftTarget - i) / 2));
      this.style.left = i + "px";
      setTimeout(function() {
        rootCont.shift();
      }, 50);
    }
    else {
      this.shifting = false;
      // paint bug in mozilla; force redraw:
      if (navigator.userAgent.toLowerCase().indexOf("gecko") > -1) {
        root.style.overflow = "visible";
        setTimeout(function() {
          root.style.overflow = "hidden";
        }, 1);
      }
    }
  }
  
  function countColumns() {
    root.style.width = "";
    columnCount = Math.floor(root.offsetWidth / listWidth);
    root.style.width = columnCount * listWidth + "px";
  }
  
  function toggleHeading() {
    if (heading.className.indexOf("collapsed") > -1)
      heading.className = "finder-heading finder-heading-ui";
    else
      heading.className = "finder-heading finder-heading-ui finder-heading-collapsed";
    return false;
  }
  
  // init heading
  var heading = document.getElementById(id + "-heading");
  if (heading) {
    heading.className = "finder-heading finder-heading-ui";
    var trigger = document.createElement("a");
    trigger.setAttribute("href", "#" + id);
    trigger.appendChild(heading.firstChild.cloneNode(false));
    heading.insertBefore(trigger, heading.firstChild);
    var visual = document.createElement("div");
    visual.className = "visual";
    visual.style.backgroundImage = heading.style.backgroundImage;
    heading.style.backgroundImage = "";
    heading.insertBefore(visual, heading.firstChild);
    visual.appendChild(trigger);
    trigger.onclick = heading.onmousedown = toggleHeading;
  }
  
  root.className = "finder finder-ui";
  var active = null;
  var preset = [];
  var columnCount = 3;
  var listWidth = null;
  var rootList = null;
  var rootCont = root.appendChild(document.createElement("div"));
  rootCont.className = "lists";
  rootCont.shiftTo = shiftTo;
  rootCont.shift = shiftFrame;
  var links = root.getElementsByTagName("a");
  for (var i = 0, l = links.length; i < l; i++)
    links[i].onclick = activate;
  var lists = root.getElementsByTagName("ul");
  for (var i = 0, l = lists.length; i < l; i++) {
    var list = lists[i];
    list.id = id + "-list-" + i;
    if (i == 0) {
      rootList = list;
      list.level = 0;
    }
    else {
      var item = list.parentItem = list.parentNode;
      list.parentItem.childList = list;
      var trigger = document.createElement("a");
      trigger.setAttribute("href", "#"+ id + "-list-" + i);
      item.appendChild(trigger).appendChild(item.firstChild);
      trigger.tabIndex = i;
      trigger.onclick = activate;
      trigger.onmousedown = function() {
        return false;
      };
      if (list.className == "active")
        for (var n = list.parentItem; n; n = n.parentNode.parentItem)
          preset[preset.length] = getChildElements(n, "a")[0];
      list.level = 1;
      for (var n = item.parentNode; n != root; n = n.parentNode)
        if (n.tagName == "LI") list.level++;
    }
    list.childItems = getChildElements(list, "li");
    list.firstItem = list.childItems[0];
    list.lastItem = list.childItems[list.childItems.length - 1];
  }
  
  function initList(list) {
    var cont = rootCont.appendChild(document.createElement("div"));
    cont.className = (list == rootList) ? "list active" : "list";
    cont.appendChild(list);
    if (list == rootList) listWidth = cont.offsetWidth;
    cont.style.left = list.level * listWidth + "px";
    for (var i = 0, l = list.childItems.length; i < l; i++) {
      var lists = getChildElements(list.childItems[i], "ul");
      if (lists.length > 0) initList(lists[0]);
    }
  }
  if (rootList != null) initList(rootList);
  countColumns();
  
  if (preset.length > 0)
    for (var i = preset.length - 1; i >= 0; i--) preset[i].onclick();
  if (document.onmousemove == null) document.onmousemove = Finder.readMousePos;
  var oldResize = window.onresize;
  window.onresize = function() {
    if (oldResize != null) oldResize();
    countColumns();
  };
}
Finder.mouseLeft = 0;
Finder.mouseTop = 0;
Finder.readMousePos = function(e) {
  if (!e) var e = window.event;
  if (e.pageX) {
    Finder.mouseLeft = e.pageX;
    Finder.mouseTop = e.pageY;
  }
  else if (e.clientX) {
    Finder.mouseLeft = e.clientX + document.body.scrollLeft;
    Finder.mouseTop = e.clientY + document.body.scrollTop;
  }
  return false;
}
Finder.setup = function() {
  var list = document.body.getElementsByTagName("div");
  var finders = [];
  for (var i = 0, l = list.length; i < l; i++)
    if (list[i].className == "finder") finders[finders.length] = list[i];
  for (var i = 0, l = finders.length; i < l; i++)
    new Finder(finders[i]);
};

var queryElements = [];
function queryElementById(id, f) {
  var n = document.getElementById(id);
  if (!n && !window.loaded) setTimeout(function() { queryElementById(id, f); }, 200);
  else if (n && !n.queried && f) {
    n.queried = true;
    f();
  }
}

//DOM loader
function init() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	if(document.getElementsByTagName('table'))setZebra();
  	if(document.getElementsByTagName('input')){setBorder();setHover();}
  	if (getEl('navigation'))active('nav');
	queryElementById("footer", Finder.setup);
	try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}
	};
if (document.addEventListener) {	document.addEventListener("DOMContentLoaded", init, null);}
if (/WebKit/i.test(navigator.userAgent)) { var _timer = setInterval(function() { if (/loaded|complete/.test(document.readyState)) { clearInterval(_timer); init();}}, 10);};
/*@cc_on @*/
	/*@if (@_win32)document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");var script = document.getElementById("__ie_onload");script.onreadystatechange = function() {	if (this.readyState == "complete") { init(); }};
/*@end @*/
window.onload = init


/*
window.loaded = false;
window.onload = window.onstop = function(){
  if(document.getElementsByTagName('table'))setZebra();
  if(document.getElementsByTagName('input')){setBorder();setHover();}
  if(getEl('navbar'))initNavbar();
  this.loaded = true;
  queryElementById("footer", Finder.setup);
}
queryElementById("footer", Finder.setup);
*/