/*-- spam protection --*/

    function getAdr(prefix, postfix, text) {
        document.write('<a href="mailto:' + prefix + '@' + postfix + '">' + (text ? text.replace(/&quot;/g, '"').replace(/%EMAIL%/, prefix + '@' + postfix) : prefix + '@' + postfix) + '</a>');
    }

/*-- hover --*/

    function init_hover() {
        var tags = new Array('tr');
        for(t=0; t<tags.length; t++) {
            var eles = document.getElementsByTagName(tags[t]);
            for(var i = 0; i < eles.length; i++) {
                eles[i].onmouseover = function() { addClass(this, 'hover'); }
                eles[i].onmouseout = function() { removeClass(this, 'hover'); }            
            }
        }
    }

/*-- focus --*/

    function init_focus() {
        var tags = new Array('input','button','textarea');
        for(t=0; t<tags.length; t++) {
            var eles = document.getElementsByTagName(tags[t]);
            for(i=0; i<eles.length; i++) {
                eles[i].oldonfocus = eles[i].onfocus;
                eles[i].oldonblur = eles[i].onblur;
                eles[i].onfocus = function() { addClass(this, 'focus'); if(this.oldonfocus) this.oldonfocus(); }
                eles[i].onblur = function() { removeClass(this, 'focus'); if(this.oldonblur) this.oldonblur(); }
            }
        }
    }

/*-- add/remove class --*/

    function addClass(obj, newclass) {
        if(obj.className.indexOf(newclass) == -1)
            obj.className += " " + newclass;
    }
    
    function removeClass(obj, oldclass) {
        var classes = obj.className.split(' ');
        for(i=0; i<classes.length; i++) {
            if(classes[i].indexOf(oldclass) > -1)
                classes[i] = "";
        }
        obj.className = classes.join(' ');
    }

/*-- getElementsByClassName --*/

    function getElementsByClassName(strClass, strTag, objContElm) {
        strTag = strTag || "*";
        objContElm = objContElm || document;
        var objColl = objContElm.getElementsByTagName(strTag);
        if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
        var arr = new Array();
        var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
        var arrClass = strClass.split(delim);
        for (var i = 0, j = objColl.length; i < j; i++) {
            var arrObjClass = objColl[i].className.split(' ');
            if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
            var c = 0;
            comparisonLoop:
            for (var k = 0, l = arrObjClass.length; k < l; k++) {
                for (var m = 0, n = arrClass.length; m < n; m++) {
                    if (arrClass[m] == arrObjClass[k]) c++;
                    if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
                        arr.push(objColl[i]);
                        break comparisonLoop;
                    }
                }
            }
        }
        return arr;
    }

/*-- validform --*/

    var custom_required_text = new Object();
    function init_forms() {
        var content = document.getElementById('content');
        if(content) {
            var forms = content.getElementsByTagName('form');
            for(f=0; f<forms.length; f++) {
                init_form(forms[f]);
            }
        }
        var email_empfaenger = document.getElementById('email_empfaenger');
        if(email_empfaenger)
            email_empfaenger.value = email_empfaenger.value.replace('+at+', '@');
    }

    function init_form(form) {
        var required = getElementsByClassName('required', '*', form);
        for(i=0; i<required.length; i++) {
            required[i].onblur = function() {
                validate(this);
            }
        }
        form.onsubmit = function() {
            var doSubmit = true;
            var list = new Array();
            var required = getElementsByClassName('required', '*', this);
            for(v=0; v<required.length; v++) {
                if(! validate(required[v])) {
                    doSubmit = false;
                    list.push(required[v]);
                }
            }
            var checkboxeles = getElementsByClassName('required_checkbox', '*', this);
            for(i=0; i<checkboxeles.length; i++) {
                valid = false;
                checkboxes = checkboxeles[i].getElementsByTagName('input');
                for(c=0; c<checkboxes.length; c++) {
                    if(checkboxes[c].type == 'checkbox') {
                        checkboxeles[i].name = checkboxes[c].name; // we need the name to check for custom_required_texts
                        if(checkboxes[c].checked)
                            valid = true;
                    }
                }
    
                if(valid == false) {
                    doSubmit = false;
                    set_msg(checkboxeles[i], label_valid_checkbox);
                    list.push(checkboxeles[i]);
                } 
                else {
                    clear_msg(checkboxeles[i]);
                }
            }
            var radioeles = getElementsByClassName('required_radio', '*', this);
            for(i=0; i<radioeles.length; i++) {
                valid = false;
                radios = radioeles[i].getElementsByTagName('input');
                for(c=0; c<radios.length; c++) {
                    if(radios[c].type == 'radio') {
                        radioeles[i].name = radios[c].name; // we need the name to check for custom_required_texts
                        if(radios[c].checked)
                            valid = true;
                    }
                }
    
                if(valid == false) {
                    doSubmit = false;
                    set_msg(radioeles[i], label_valid_radio);
                    list.push(radioeles[i]);
                } 
                else {
                    clear_msg(radioeles[i]);
                }
            }

        if(doSubmit == false)
            show_error(list);
            return doSubmit;
        }
    }

    function validate(el) {
        var valid = true;
        clear_msg(el);
        switch(el.type) {
            case 'text':
            case 'textarea':
            case 'select-one':
                if(el.value != '') {
                    if(el.className.indexOf('email') > -1) {
                        var regEmail = /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;
                        if(el.value.toUpperCase().match(regEmail)){
                            valid = true;
                        }
                        else {
                            valid = false;
                            set_msg(el, label_valid_email);
                        }
                    }
                    if(el.className.indexOf('number') > -1) {
                        if(el.value == Math.round(el.value)) {
                            valid = true;
                        }
                        else {
                            valid = false;
                            set_msg(el, label_valid_postal_code);
                        }
                    }
                }
                else {
                    valid = false;
                    set_msg(el);
                }
                break;
        }
    
        return valid;
    }

    function set_msg(el, msg) {
        if(msg == undefined) {
            msg = el.parentNode.getElementsByTagName('span')[0].innerHTML.replace(' *', '') + ' ' + label_valid_required;
        }

        if(custom_required_text[el.name])
            msg = custom_required_text[el.name];

        el.errorMessage = msg;
        if(el.parentNode.className.indexOf('error') == -1)
            el.parentNode.className += ' error';
    }

    function clear_msg(el) {
        var classes = el.parentNode.className.split(' ');
        for(i=0; i<classes.length; i++) {
            if(classes[i].indexOf('error') > -1)
                classes[i] = "";
        }
        el.parentNode.className = classes.join(' ');
        el.errorMessage = "";
    }

    function show_error(list) {
        errorlist = '<ul>';
        for(i=0; i<list.length; i++) {
            el = list[i];
            if(el.errorMessage != undefined)
                errorMessage = el.errorMessage;
            else
                var errorMessage = el.parentNode.getElementsByTagName('span')[0].innerHTML.replace(' *', '') + ' ' + label_valid_required;
    
            errorlist += '<li>' + errorMessage + '</li>';
        };
        errorlist += '</ul>';
    
        var validationMessage = document.getElementById('validationMessage');
        validationMessage.innerHTML = '<h2 title="' + label_valid_error + '">' + label_valid_error + '</h2>' + errorlist;
        document.location.href = '#validationMessage';
    }

// BO Onlinetool Mootools
function popup(url, typ, para1, width, height) {
    attrib = "";
    Y = (screen.height - width) / 2;
    X = (screen.width - height) / 2;
    X = Math.round(X);
    Y = Math.round(Y);
    if (para1 == 'CENTER') attrib += 'height=' + height + ',width=' + width + ',top=' + Y + ',left=' + X;
    if (typ == 'TYP1') attrib += ",scrollbars=no";
    if (typ == 'TYP2') attrib += ",scrollbars=yes";
    if (typ == 'TYP3') attrib += ",scrollbars=yes,menubar=yes";
    fenster = window.open(url, 'win', attrib);
    //alert(width + " x " + height);
  return false;
    
}

function popupOnlineToolMoo(obj, toollink) {
    if(navigator.appVersion.indexOf('IE 6') > -1)
    {
        popup(toollink.replace('&noresize=1', ''), 'TYP2', 'CENTER', 800, 560);
    }
    else
    {
        var objTemp = document.getElementById('popupcontainer');
        objTemp.innerHTML = '<iframe src="' + toollink.replace('&noresize=1', '') + '" id="popupcalc" frameborder="0"></iframe>';
        objTemp.style.display='none';
        showPopup('popupcontainer', 800, 560);
    }
    return false;
}
// EO Onlinetool Mootools


// BO Popup
function hideSelectBoxes(){
    selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) { selects[i].style.visibility = "hidden";}

    if(!window.ie)
        document.getElementById('content').style.overflow='hidden';
}

function showSelectBoxes(){
    selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) { selects[i].style.visibility = "visible";}

    if(!window.ie)
        document.getElementById('content').style.overflow='auto';
}

var popupOldOnResize = window.onresize;
var popupOldOnLoad = window.onload;
function showPopup(id, width, height)
{
    hideSelectBoxes();
    if(document.getElementById('popup_background')) {
        var objTemp = document.getElementById('popup_background');
    }
    else
    {
        var objTemp = document.createElement("div");
        objTemp.id = 'popup_background';
        objTemp.style.visibility='hidden';
        objTemp.onclick=function() { }
    }

    if(objTemp.style.display != 'block')
    {
        objTemp.style.display='block';

        popupBackground = document.body.appendChild(objTemp);
        $(popupBackground).setStyle('opacity', 0);
        new Fx.Morph($(popupBackground), {
            duration:400,
            onComplete:function() {
                showPopupContent(id, width, height);
            }
        }).start({ 'opacity': 0.5 });
    }
    else
    {
        showPopupContent(id, width, height);
    }
}

function showPopupContent(id, width, height)
{
    if(document.getElementById('popup_content')) {
        objTemp = document.getElementById('popup_content');
    }
    else
    {
        objTemp = document.createElement("div");
        objTemp.id = 'popup_content';
    }

    $('popup_background').onclick=function() { popupClose(); }

    objTemp.innerHTML= '<div id="popup_close"><a href="javascript:popupClose()"><span>X</span></a></div><div id="popup_text">' + document.getElementById(id).innerHTML + '</div>';

    if(width > 0 && height > 0) {
        objTemp.style.width=width+'px';
        objTemp.style.height=height+'px';
        objTemp.style.marginLeft='-' + Math.round(width/2)-4 +'px';
        objTemp.style.marginTop='-' + Math.round(height/2) +'px';
    }

    objTemp.style.display='block';

    popupContent = document.body.appendChild(objTemp);
}

function popupClose()
{
    popupContent = document.getElementById('popup_content');
    popupContent.style.display='none';

    popupBackground = $('popup_background');
    popupBackground.onclick=function() { }

    new Fx.Morph($(popupBackground), {
        duration: 400,
        onComplete: function() {
            popupBackground.style.display = 'none';
            showSelectBoxes();
        }
    }).start({'opacity': 0});
}
// EO Popup


/*
             \|/
            .-*-
           / /|\
          _L_
        ,"   ".
    (\ /  O O  \ /)
     \|    _    |/
       \  (_)  /
       _/.___,\_
     (_/ doom  \_)
         ready, the end is near
*/

/* DOOMREADY - Based on Mootools */
var doomready = new Object();
doomready = {
    add: function(fn) {
        if (doomready.loaded) return fn();
        var observers = doomready.observers;
        if (!observers) observers = doomready.observers = [];
        observers[observers.length] = fn; // Arraypush is not supported by Mac IE 5
        if (doomready.callback) return;
        doomready.callback = function() {
            if (doomready.loaded) return;
            doomready.loaded = true;
            if (doomready.timer) {
                clearInterval(doomready.timer);
                doomready.timer = null;
            }
            var observers = doomready.observers;
            for (var i = 0, length = observers.length; i < length; i++) {
                var fn = observers[i];
                observers[i] = null;
                fn(); // make 'this' as window
            }
            doomready.callback = doomready.observers = null;
        };

        var ie = !!(window.attachEvent && !window.opera);
        var webkit = navigator.userAgent.indexOf('AppleWebKit/') > -1;
        if (document.readyState && webkit) { // Apple WebKit (Safari, OmniWeb, ...)
            doomready.timer = setInterval(function() {
                var state = document.readyState;
                if (state == 'loaded' || state == 'complete') {
                    doomready.callback();
                }
            }, 50);
        }
        else if (document.readyState && ie) { // Windows IE
            var src = (window.location.protocol == 'https:') ? '://0' : 'javascript:void(0)';
            document.write(
                '<script type="text/javascript" defer="defer" src="' + src + '" ' +
                'onreadystatechange="if (this.readyState == \'complete\') doomready.callback();"' +
                '><\/script>');
        }
        else {
            if (window.addEventListener) { // for Mozilla browsers, Opera 9
                document.addEventListener("DOMContentLoaded", doomready.callback, false);
                window.addEventListener("load", doomready.callback, false); // Fail safe
            }
            else if (window.attachEvent) {
            window.attachEvent('onload', doomready.callback);
            }
            else { // Legacy browsers (e.g. Mac IE 5)
                var fn = window.onload;
                window.onload = function() {
                    doomready.callback();
                    if (fn) fn();
                }
            }
        }
    }
}

doomready.add(function() {
    init_hover();
    init_focus();
    init_forms();
});
