// BEHAVIOR LAYER
// create print page link on the fly if key items are supported
var hasPrintFeature = (window.print) ? true : false;
var supportsW3CDOM = ((document.createElementNS || document.createElement) && document.createTextNode && document.insertBefore && document.appendChild);
if (hasPrintFeature && supportsW3CDOM) {
    if (typeof PRINT_PAGE_TEXT == 'string') {
        var li = (document.createElementNS) ? document.createElementNS(XHTML_NS_URI, 'li') : document.createElement('li');
        li.setAttribute('id', 'navFunctionsPrint');
        var a = (document.createElementNS) ? document.createElementNS(XHTML_NS_URI, 'a') : document.createElement('a');
        a.setAttribute('href', '#');
        a.onclick = function() {
            window.print();
            return false;
        }
        a.appendChild(document.createTextNode(PRINT_PAGE_TEXT));
        li.appendChild(a);
        var refNode = document.getElementById('navFunctionsRecommend');
        if (refNode) {
            refNode.parentNode.insertBefore(li, refNode);
        } else {
            var parentRefNode = document.getElementById('siteInfo');
            if (parentRefNode) {
                var ul = (document.createElementNS) ? document.createElementNS(XHTML_NS_URI, 'ul') : document.createElement('ul');
                ul.appendChild(li);
                refNode = (parentRefNode.getElementsByTagName('p').length > 0) ? parentRefNode.getElementsByTagName('p')[0] : null;
                if (refNode) {
                    refNode.parentNode.insertBefore(ul, refNode);
                }
            }
        }
    }
}
// attach events to search form input
var searchInputEl = document.getElementById('searchInput');
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);
    }
    addEventHandler(searchInputEl, 'focus', listener);
    addEventHandler(searchInputEl, 'blur', listener);
}
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 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 openImageGallery(link) {
    openPopup (link.href, "ImageGallerye", 560, 700, "psu");
}

(function(jQuery){
jQuery.fn.attachToField = function (id, defaultValue){
    var field = jQuery('#'+id);
    var input_text = field.attr('value');
    return jQuery(field).bind('focus',function(){
       if( input_text == defaultValue ) {
          field.attr('value','');
        }
      }).bind('blur',function(){
        if(field.attr('value')==''){ 
          field.attr('value',input_text);
        }
        input_text = field.attr('value');
      });
};
jQuery.init_clearfields = function(){
// attach events to search form input
//ServicebereichSuche f2025194d14618 searchExpert f6916d6920

      jQuery('#searchExpert').attachToField('f14812d14830','recherche');
      jQuery('#searchExpert').attachToField('f6916d6920','Suchwort eingeben');
      jQuery('#searchExpert').attachToField('f13818d13820','search');
      jQuery('#ServicebereichSuche').attachToField('f2025194d14618','Suchwort eingeben');
      jQuery('#ServicebereichSuche').attachToField('f11812d11820','search');
      jQuery('#ServicebereichSuche').attachToField('f13078d13082','recherche');

return;
};
})(jQuery);
jQuery(document).ready(function (){

   jQuery.init_clearfields();
});
