// JAVASCRIPT LIBRARY
// constants
var XHTML_NS_URI = 'http://www.w3.org/1999/xhtml';
/*EventCache Version 1.0
Copyright 2005 Mark Wubben
Provides a way for automagically removing events from nodes and thus preventing memory leakage.
See <http://novemberborn.net/javascript/event-cache> for more information.
This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/
/*Event Cache uses an anonymous function to create a hidden scope chain.
This is to prevent scoping issues. */
var EventCache = function(){
var listEvents = [];
return {
listEvents : listEvents,
add : function(node, sEventName, fHandler, bCapture){
listEvents.push(arguments);
},
flush : function(){
var i, item;
for(i = listEvents.length - 1; i >= 0; i = i - 1){
 item = listEvents[i];
 
 if(item[0].removeEventListener){
 item[0].removeEventListener(item[1], item[2], item[3]);
 };
 
 /* From this point on we need the event names to be prefixed with 'on" */
 if(item[1].substring(0, 2) != "on"){
 item[1] = "on" + item[1];
 };
 
 if(item[0].detachEvent){
 item[0].detachEvent(item[1], item[2]);
 };
 
 item[0][item[1]] = null;
};
}
};
}();
// destroy events on unload to prevent memory leakage in IE-Win
addEventHandler(window, 'unload', EventCache.flush);
/**
 * Implements <code>getElementById<code> method for W3C DOM-incapable browsers.
 * For these browsers it returns always <code>null</code>. You do not have
 * to detect the <code>getElementById<code> elsewhere in a script anymore.
 * <p>
 * You should always check, if the returned value is not <code>null</code> to 
 * prevent script errors; <code>getElementById</code> returns null in
 * W3C DOM-capable browsers as well, if there is no match for the given id in
 * the document tree.
 * <p>
 * Usage:
 * <p>
 * <code>var elem = document.getElementById(id);<br>
 * if (elem) {<br>
 *     // process elem<br>
 * }</code>
 *
 * @author klaus.hartl (30.03.2005)
 */
if (!document.getElementById) {
    document.getElementById = function() {
        return null;
    };
}
/**
 * Implement <code>Array.push</code> for browsers which don't support it natively.
 *
 * @author klaus.hartl (30.03.2005)
 */
if (!Array.prototype.push) {
    Array.prototype.push = function() {
        for(var i = 0; i < arguments.length; i++) {
            this[this.length] = arguments[i];
        }
        return this.length;
    }
}
/**
 * Binds an event handler function to a given node, so that the function executes
 * when an event of the particular, given type arrives at the node either as event
 * target or during event propagation. Existing events, either defined as a tag
 * attribute or binded dynamically, are not affected.
 * <p>
 * Note: If this has to work in IE/Mac with existing events as tag attributes
 * the call to bind a new event has to follow the target node in the source 
 * code.
 *
 * @param target           the node to which the event will be binded
 * @param eventType        a string of one event type (without the "on" prefix)
 *                         known to the browser's object model
 * @param listenerFunction a reference to the function to execute, when the node
 *                         hears the event type
 * @param useCapture       a Boolean value. If <code>true</code>, the node listens
 *                         for the event type only while the event propagates
 *                         toward the target node. If <code>false</code>, the 
 *                         node listens only when the event bubbles outward from
 *                         the event target. The typical setting of this parameter
 *                         is <code>false</code> and if omitted, it falls back to 
 *                         that value.
 * @author                 klaus.hartl (24.03.2005)
 */
function addEventHandler(target, eventType, listenerFunction, useCapture) {
    var result;
    if (target.addEventListener) {
        // W3C DOM approach
        useCapture = (typeof useCapture == 'boolean') ? useCapture : false;
        target.addEventListener(eventType, listenerFunction, useCapture);
        result = true;
    } else if (target.attachEvent) {
        // IE/Win DOM approach
        var r = target.attachEvent('on' + eventType, listenerFunction);
        result = r;
    } else {
        // fallback approach (IE/Mac and anything else that gets this far)
        var onEv = 'on' + eventType;
    // if there's an existing event handler function
        if(typeof target[onEv] == 'function') {
            // store it
            var existing = target[onEv];
            // attach new onload handler
            target[onEv] = function() {
                // call existing function
                existing();
                // call given function
                listenerFunction();
            };
        } else {
            target[onEv] = listenerFunction;
        }
        return true; // do not use EventCash
    }
    EventCache.add(target, eventType, listenerFunction, useCapture);
    return result;
}
/**
 *
 */
function toggleValue(evt, defaultValue) {
    evt = (evt) ? evt : ((event) ? event : null);
    if (evt) {
        var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        if (elem) {
            if (elem.value == defaultValue) {
                elem.value = '';
            } else if (elem.value == '') {
                elem.value = defaultValue;
            }
        }
    }
}
/**
 *
 */
function attachToField(id) {
  var searchInputEl = document.getElementById(id);
  if (searchInputEl) {
    // searchInputEl.setAttribute('autocomplete', 'off'); // prevents exception occuring with mozilla's autocomplete feature
    // this exception though does not break/impact the script but maybe we want to avoid an error at the console...
    var s = searchInputEl.value;
    var listener = function(evt) {
        toggleValue(evt, s);
    }
    addEventHandler(searchInputEl, 'focus', listener);
    addEventHandler(searchInputEl, 'blur', listener);
  }
  return searchInputEl
}
function glossaryClose(link){
window.close();
}
function glossaryGoto(link){
opener.location.href=link;
window.close();
}
//Ergaenzung fuer Glossar Popup
var isStretcherActive = false;
var testString = "";
var testObj = null;
function init() {
    if ((!is.netscape7 && !is.safari) && isStretcherActive && (document.createElementNS || document.createElement) && document.createTextNode && document.appendChild && document.insertBefore) {
      var stretchers = document.getElementsByClassName('stretcher'); // ul that stretches
      var stretchers = new Array();
        var toggles = new Array(); // links where I click on
        var p, a;
        for (var i = 0; i < stretchers.length; i++) {
            p = (document.createElementNS) ? document.createElementNS(XHTML_NS_URI, 'p') : document.createElement('p');
            p.className = 'infoswitch';
            a = (document.createElementNS) ? document.createElementNS(XHTML_NS_URI, 'a') : document.createElement('a');
            a.setAttribute('href', '#');
            a.className = 'close';
            a.appendChild(document.createTextNode(CONTENT_SWITCH_OPEN_TEXT));
            p.appendChild(a);
            toggles[i] = a;
            stretchers[i].parentNode.insertBefore(p, stretchers[i]);
        }
        // enhance default accordion effect object located in moo.fx.pack
        fx.Accordion.prototype.hideThis = function(toHide){
            if (toHide.offsetHeight == 0) setTimeout(function(){this.clearAndToggle(toHide);}.bind(this), this.options.delay);
            this.elements.each(function(el, i){
                if (el.offsetHeight > 0) {
                    if (el != toHide) {
                        switchBarValue(el.previousSibling.getElementsByTagName("a")[0]);
                    }
                    this.clearAndToggle(el);
                }
            }.bind(this));
        }
        // accordion effect
        var myAccordion = new fx.Accordion(toggles, stretchers, {opacity: true, duration: 500});
        toggles.each(function(a, i) {
            a.onclick = function() {
                var srcEl;
                if (this == window && event) { // IE/Win does not understand "this", if event is attached other than "a.onclick = '...'"
                    srcEl = event.srcElement
                    while (srcEl.nodeName.toLowerCase() != 'a') { // Source element might be a nested node inside the desired a-node
                        srcEl = elem.parentNode;
                    }
                } else {
                    srcEl = this;
                }
                switchBarValue(srcEl);
                var ul = Element.find(a.parentNode, 'nextSibling'); // element.find is located in prototype.lite
                myAccordion.hideThis(ul);
                return false;
            };
        });
        var showAllElement = document.getElementById("showAllLink");
/*
       if (showAllElement != null) {
            var p = (document.createElementNS) ? document.createElementNS(XHTML_NS_URI, 'p') : document.createElement('p');
            p.className = 'infoswitch';
            var a = (document.createElementNS) ? document.createElementNS(XHTML_NS_URI, 'a') : document.createElement('a');
            a.setAttribute('href', CONTENT_SWITCH_ALL_LINK);
            if (isStretcherActive) {
                a.className = 'close';
                a.appendChild(document.createTextNode(CONTENT_SWITCH_ALL_OPEN_TEXT));
            } else {
                a.className = 'open';
                a.appendChild(document.createTextNode(CONTENT_SWITCH_ALL_CLOSE_TEXT));
            }
            p.appendChild(a);
            showAllElement.appendChild(p);
            p.style.marginLeft = "0px";
            showAllElement.style.marginTop = "1em";
        }
*/
    }
}
function switchBarValue(elem) {
    elem.className = (elem.className == 'close') ? 'open' : 'close';
    elem.firstChild.nodeValue = (elem.className == 'close') ? CONTENT_SWITCH_OPEN_TEXT : CONTENT_SWITCH_CLOSE_TEXT;
}
addEventHandler(window, 'load', function() { init(); });
var is = new function() {
    this.agent = navigator.userAgent.toLowerCase();
    this.appVersion = navigator.appVersion;
    this.opera = (this.agent.indexOf("opera") != -1 ? true : false);
    this.staroffice = (this.agent.indexOf("staroffice") != -1 ? true : false);
    this.beonex = (this.agent.indexOf("beonex") != -1 ? true : false);
    this.chimera = (this.agent.indexOf("chimera") != -1 ? true : false);
    this.netpositive = (this.agent.indexOf("netpositive") != -1 ? true : false);
    this.phoenix = (this.agent.indexOf("phoenix") != -1 ? true : false);
    this.firefox = (this.agent.indexOf("firefox") != -1 ? true : false);
    this.safari = (this.agent.indexOf("safari") != -1 ? true : false);
    this.skipstone = (this.agent.indexOf("skipstone") != -1 ? true : false);
    this.ie = (this.agent.indexOf("msie") != -1 ? true : false);
    this.netscape = (this.agent.indexOf("netscape") != -1 ? true : false);
    this.netscape7 = (this.agent.indexOf("netscape\/7") != -1 ? true : false);
    this.mozilla = (this.agent.indexOf("mozilla/5.0") != -1 ? true : false);
    this.mac = (this.agent.indexOf('mac') != -1 ? true : false);
    this.version = (1 * navigator.appVersion.substring(0,1));
}
var ie = 0;
var agent = navigator.userAgent.toLowerCase();
var isMac = (agent.indexOf('mac')) ? true : false;
if (navigator.appName.indexOf("Explorer") > -1) {
if (navigator.appVersion.indexOf("MSIE 5") > -1) { ie = 5 }
else { ie = navigator.appVersion.substring(0,1) }
}
var openedPopups = new Array();
var defaults = new Array();
defaults['url'] = ""; defaults['name'] = "popup"; defaults['width'] = 600; defaults['height'] = 400;
function openPopup (url,name,w,h,switches,x,y) {
if (!url) { url = defaults['url'] }
if (!name) { name = defaults['name'] }
if (!w) { w = defaults['width'] }
else { w = parseInt(w) }
    if (ie && isMac){ w -= 10 }
    if (ie == 5) { w += 20 }
if (!h) { h = defaults['height'] }
else { h = parseInt(h) }
    if (ie && ie < 5) { h -= 20; }
if (switches && switches.indexOf("f") > -1 && window.screen) {
        /*w = "outerWidth=" + window.screen.availWidth;
          h = ",outerHeight=" + window.screen.availHeight; */
w = window.screen.availWidth;
h = window.screen.availHeight;
}
var xpos; var ypos;
if (x > -1 && y > -1) {
        xpos = x;
ypos = y;
} else {
if (switches && window.screen) {
            if (switches.indexOf("c") > -1) {
                xpos = parseInt((window.screen.availWidth - w)/2);
ypos = parseInt((window.screen.availHeight - h)/2);
}
if (switches.indexOf("f") > -1) {
                xpos = 0;
ypos = 0;
}
}
}
var params = popupParams(w,h,switches,xpos,ypos);
var newwin;
if (openedPopups[name] && openedPopups[name].close && !openedPopups[name].closed) {
        openedPopups[name].close();
        openedPopups[name] = "";
    }
    newwin = window.open(url, name, params);
    if (switches && switches.indexOf('b') > -1 && window.moveTo && window.resizeTo && window.focus) {
        newwin.blur();
        newwin.opener.focus();
        newwin.resizeTo(w,h);
        newwin.moveTo(xpos,ypos);
}
if (window.focus) { newwin.focus() }
openedPopups[name] = newwin;
    return false;
}
function popupParams (w,h,switches,xpos,ypos) {
var width = "width=" + w;
var height = ",height=" + h;
var parent = ",dependent=no";
    var dirbar = ",directories=no";
var fullscreen = ",fullscreen=0";
    var hotkeys = ",hotkeys=yes";
    var locbar = ",location=no";
var menubar = ",menubar=no";
var resizable = ",resizable=no";
var scrollbars = ",scrollbars=no";
var statusbar = ",status=no";
var toolbar = ",toolbar=no";
if (switches) {
if (switches.indexOf("p") > -1 ) { parent = ",dependent=yes"}
if (switches.indexOf("d") > -1 ) { dirbar = ",directories=yes"}
if (switches.indexOf("h") > -1 ) { hotkeys = ",hotkeys=no"}
if (switches.indexOf("l") > -1 ) { locbar = ",location=yes"}
if (switches.indexOf("m") > -1 ) { menubar = ",menubar=yes"}
if (switches.indexOf("r") > -1 ) { resizable = ",resizable=yes"}
if (switches.indexOf("s") > -1 ) { scrollbars = ",scrollbars=yes" }
if (switches.indexOf("u") > -1 ) { statusbar = ",status=yes"}
if (switches.indexOf("t") > -1 ) { toolbar = ",toolbar=yes"}
if (switches.indexOf("k") > -1 || switches.indexOf("b") > -1 ) { fullscreen = ",fullscreen=1" }
}
var pos = "";
if (xpos > -1 && ypos > -1) { pos = ",left=" + xpos + ",top=" + ypos }
return width + height + parent + dirbar + hotkeys + locbar + menubar + resizable + scrollbars + statusbar + toolbar + pos + fullscreen;
}
function openGlossaryPopUp(link) {
    openPopup(link.href, "ImageGallerye", 560, 700, "psu");
}
