function Util() {
    /* Speichere eine Referenz auf das aktuelle Objekt in der privaten Eigenschaft self */
    var self = this;

    this.getBrowser = function() {
        var browserShortName = '????';
        if (document.ids) browserShortName = 'nc4';
        else if (document.all && ! document.getElementById) browserShortName = 'ie4';
        else if (window.opera && ! document.createElement) browserShortName = 'op5';
        else if (window.opera && window.getComputedStyle)  {
            if (document.createRange) browserShortName = 'op8';
            else if (window.navigate) browserShortName = 'op7.5';
            else browserShortName = 'op7.2';
        }
        else if (window.opera && document.compatMode) browserShortName = 'op7';
        else if (window.opera && document.releaseEvents) browserShortName = 'op6';
        else if (document.contains && !window.opera) browserShortName = 'kq3';
        else if (window.pkcs11&&window.XML) browserShortName = 'ff15';
        else if (window.getSelection && window.atob) browserShortName = 'nn7';
        else if (window.getSelection && !document.compatMode) browserShortName = 'nn6';
        else if (window.clipboardData && document.compatMode) browserShortName = 'ie6';
        else if (window.clipboardData) {
            browserShortName = 'ie5';
            if (! document.createDocumentFragment) browserShortName += '.5';
            if (document.doctype && ! window.print) browserShortName += 'm';
        }
        else if (document.getElementById && ! document.all ) browserShortName = 'op4';
        else if (document.images && ! document.all ) browserShortName = 'nn3';
        else if (document.clientWidth && ! window.RegExp) browserShortName = 'kq2';
        else browserShortName = '????';
        return browserShortName;
    }
    
    this.getBrowserVersion = function() {
        return self.getBrowser().substring(2, self.getBrowser().length);
    }
    
    this.getBrowserShortname = function() {
        return self.getBrowser().substring(0, 2);
    }
    
    this.getViewportWidth = function() {
        var availWidth;
        
        if (self.innerWidth) {
            // all except Explorer
            availWidth = self.innerWidth;
        } else if (document.documentElement && document.documentElement.clientWidth) {
            // Explorer 6 Strict Mode
            availWidth = document.documentElement.clientWidth;
        } else if (document.body) {
            // other Explorers
            availWidth = document.body.clientWidth;
        }
        return availWidth;
    }
    
    this.getViewportHeight = function() {
        var availHeight;
        
        if (self.innerHeight) {
            // all except Explorer
            availHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            // Explorer 6 Strict Mode
            availHeight = document.documentElement.clientHeight;
        } else if (document.body) {
            // other Explorers
            availHeight = document.body.clientHeight;
        }
        return availHeight;
    }
    
    this.getPageWidth = function() {
        var pageWidth;
        
        pageWidth = document.getElementById('centerContainer').offsetWidth;
        return pageWidth;
    }
    
    this.getPageHeight = function() {
        var pageHeight;
        
        if (document.body.scrollHeight > document.body.offsetHeight) {
            // all but Explorer Mac
            pageHeight = document.body.scrollHeight;
        } else {
            // Explorer Mac, would also work in Explorer 6 Strict, Mozilla and Safari
            pageHeight = document.body.offsetHeight;
        }
        
        return pageHeight;
    }
    
    this.getScrollPosX = function() {
        if (window.pageXOffset) {
            return window.pageXOffset;
        } else if (document.body && document.body.scrollLeft) {
            return document.body.scrollLeft;
        }
        return 0;
    }
    
    this.getScrollPosY = function() {
        if (window.pageYOffset) {
            return window.pageYOffset;
        } else if (document.body && document.body.scrollTop) {
            return document.body.scrollTop;
        }
        return 0;
    }
    
    this.getLeftPos = function(viewportWidth, popupWidth, scrollPosX) {
        if (self.getBrowserShortname() == 'ff') {
            return Math.round(viewportWidth / 2 - popupWidth / 2);
        }
        return Math.round(viewportWidth / 2 - popupWidth / 2) + scrollPosX;
    }
    
    this.getTopPos = function(viewportHeight, popupHeight, scrollPosY) {
        if (self.getBrowserShortname() == 'ff') {
            return Math.round(viewportHeight / 2 - popupHeight / 2);
        }
        return Math.round(viewportHeight / 2 - popupHeight / 2) + scrollPosY;
    }
    
    /* private */
    this.pngfix = function(divId, imgUrl, imgWidth, imgHeight) {
        var arVersion = navigator.appVersion.split("MSIE")
        var version = parseFloat(arVersion[1])
        var divContainer = document.getElementById(divId);
        
        if ((version >= 5.5) && (document.body.filters)) {
            var imgDiv = null;
            if (divContainer.hasChildNodes()) {
                imgDiv = divContainer.firstChild;
            } else {
                imgDiv = document.createElement('div');
                imgDiv.id = 'avatarImgDiv';
                divContainer.appendChild(imgDiv);
            }
            
            imgDiv.style.width = imgWidth + 'px';
            imgDiv.style.height = imgHeight + 'px';
            imgDiv.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + imgUrl + '", sizingMethod="scale")';

        } else {
        
            var img = null;
            if (divContainer.hasChildNodes()) {
                img = divContainer.firstChild;
            } else {
                // should be an image because of resize abilities
                var img = new Image(imgWidth, imgHeight);
                img.id = 'avatarImg';
                divContainer.appendChild(img);
            }
            
            img.src = imgUrl;
            
            // fix for firefox
            divContainer.style.height = imgHeight + 'px';
        }
    }

}

/**
 * Id des aktuell angezeigten Popups muss global gespeichert werden, damit Positionierung in Funktionen,
 * die durch Events aufgerufen werden vorgenommen werden kann.
 */
var activePopup = null;

/**
 * Wird nur vom IE6 genutzt, der css-eigenschaft position:fixed nicht interpretiert und derzeit kein
 * workaround mit expressions bekannt. Die Funktion zentriert das angezeigte Popup bzw. das div mit
 * der in activePopup gespeicherten id im viewport des browsers.
 */
function centerPopup() {
    var util = new Util();
    var popup;
    var popupWidth;
    var popupHeight;
    var popupLeftPos;
    var popupTopPos;
    var viewportWidth;
    var viewportHeight;
    var pageWidth;
    var pageHeight;
    var scrollPosX = 0;
    var scrollPosY = 0;
    
    if (activePopup == null) {
        return;
    }
    
    viewportWidth = util.getViewportWidth();
    viewportHeight = util.getViewportHeight();
    
    scrollPosX = util.getScrollPosX();
    scrollPosY = util.getScrollPosY();
    
    popup = document.getElementById(activePopup);
    popupHeight = popup.offsetHeight;
    popupWidth = popup.offsetWidth;
    
    popupLeftPos = util.getLeftPos(viewportWidth, popupWidth, scrollPosX);
    popupTopPos = util.getTopPos(viewportHeight, popupHeight, scrollPosY);
    
    popup.style.left = popupLeftPos + "px";
    popup.style.top = popupTopPos + "px";
}    

/**
 * Verbirgt alle Seitenelemente hinter einem iframe+?bergelagertem div und blendet ein divpopup mit der
 * ?bergebenen id ein. Das iframe ist f?r den ie6 n?tig, da dieser Auswahllisten grunds?tzlich als oberste
 * Elemente in z-Richtung anzeigt und sich diese somit nicht durch divs verdecken lassen. Das Iframe und
 * das div werden der ben?tigten Seitengr??e angepasst und ggf weiter vergr??ert, falls das Browserfenster
 * sehr gro? ist. Breite und H?he des iframes+div sind also min so gro?, wie der von den HTML-Elementen
 * ben?tigte Platz und max so gro?, wie der viewport des browserfensters.
 * Das Divpopup wird gemessen am viewport (nicht seitengr??e) zentriert angezeigt.
 * Alle verwendeten HTML-Elemente in der Seite m?ssen einen z-index < 100 haben.
 * iframe z-index 100
 * div z-index 101
 * divpopup z-index 102
 */
function showPopup(id) {
    var util = new Util();
    var popup;
    var popupWidth;
    var popupHeight;
    var popupLeftPos;
    var popupTopPos;
    var viewportWidth;
    var viewportHeight;
    var pageWidth;
    var pageHeight;
    var dialogBgWidth;
    var dialogBgHeight;
    var scrollPosX = 0;
    var scrollPosY = 0;
    
    if (id == null) {
        id = activePopup;
    } else {
        activePopup = id;
    }
    
    viewportWidth = util.getViewportWidth();
    pageWidth = util.getPageWidth();
    /* Falls Browserfenster gr??er als ben?tigte Seitenbreite, muss das ?berdeckende div
     * auf die Browserbreite augezogen werden. Das div nimmt also min die Gr??e an, die
     * von der HTML-Seite ben?tigt wird. */
    if (viewportWidth > pageWidth) {
        dialogBgWidth = viewportWidth;
    } else {
        dialogBgWidth = pageWidth;
    }
    
    viewportHeight = util.getViewportHeight();
    pageHeight = util.getPageHeight();
    // Falls Browserfenster gr??er als ben?tigte Seitenh?he, muss das ?berdeckende div auf die Browserh?he augezogen werden.
    if (viewportHeight > pageHeight) {
        dialogBgHeight = viewportHeight;
    } else {
        dialogBgHeight = pageHeight;
    }
    
    scrollPosX = util.getScrollPosX();
    scrollPosY = util.getScrollPosY();
    
    document.getElementById("hideWindowedControlsBg").style.width = dialogBgWidth + "px";
    document.getElementById("hideWindowedControlsBg").style.height = dialogBgHeight + "px";
    document.getElementById("hideWindowedControls").style.width = dialogBgWidth + "px";
    document.getElementById("hideWindowedControls").style.height = dialogBgHeight + "px";
    
    popup = document.getElementById(id);
    // Im IE6 muss der display-Style von none auf block gesetzt werden, damit das popup angezeigt wird. css eigenschaft visible ist ie6 unbekannt!?
    popup.style.display = 'block';
    document.getElementById("hideWindowedControlsBg").style.display = "block";
    document.getElementById("hideWindowedControls").style.display = "block";

    popupHeight = popup.offsetHeight;
    popupWidth = popup.offsetWidth;
    
    popupLeftPos = util.getLeftPos(viewportWidth, popupWidth, scrollPosX);
    popupTopPos = util.getTopPos(viewportHeight, popupHeight, scrollPosY);
    
    popup.style.left = popupLeftPos + "px";
    popup.style.top = popupTopPos + "px";
    
    window.onresize = resizePage;
    
    // Im IE6 muss das Popup per Javascript beim Scrollen neu zentriert werden.
    if (util.getBrowser() == 'ie6') {
        window.onscroll = centerPopup;
    }
}

function hidePopup(id) {
    if (id == null) {
        id = activePopup;
    }
    
    document.getElementById(id).style.display = "none";
    document.getElementById("hideWindowedControlsBg").style.display = "none";
    document.getElementById("hideWindowedControls").style.display = "none";
    
    window.onresize = null;
    window.onscroll = null;
    activePopup = null;
}

function resizePage() {
    if (document.getElementById("hideWindowedControlsBg").style.display == "block") {
        showPopup();
    }
}

function setPageInactive() {
    var util = new Util();
    var viewportWidth;
    var viewportHeight;
    var pageWidth;
    var pageHeight;
    var dialogBgWidth;
    var dialogBgHeight;
    
    viewportWidth = util.getViewportWidth();
    pageWidth = util.getPageWidth();
    /* Falls Browserfenster gr??er als ben?tigte Seitenbreite, muss das ?berdeckende div
     * auf die Browserbreite augezogen werden. Das div nimmt also min die Gr??e an, die
     * von der HTML-Seite ben?tigt wird. */
    if (viewportWidth > pageWidth) {
        dialogBgWidth = viewportWidth;
    } else {
        dialogBgWidth = pageWidth;
    }
    
    viewportHeight = util.getViewportHeight();
    pageHeight = util.getPageHeight();
    // Falls Browserfenster gr??er als ben?tigte Seitenh?he, muss das ?berdeckende div auf die Browserh?he augezogen werden.
    if (viewportHeight > pageHeight) {
        dialogBgHeight = viewportHeight;
    } else {
        dialogBgHeight = pageHeight;
    }
    
    document.getElementById("hideWindowedControlsBg").style.width = dialogBgWidth + "px";
    document.getElementById("hideWindowedControlsBg").style.height = dialogBgHeight + "px";
    document.getElementById("hideWindowedControls").style.width = dialogBgWidth + "px";
    document.getElementById("hideWindowedControls").style.height = dialogBgHeight + "px";
    
    document.getElementById("hideWindowedControlsBg").style.display = "block";
    document.getElementById("hideWindowedControls").style.display = "block";
    
    window.onresize = resizeBg;
}

function setPageActive() {
    document.getElementById("hideWindowedControlsBg").style.display = "none";
    document.getElementById("hideWindowedControls").style.display = "none";
}

function resizeBg() {
    if (document.getElementById("hideWindowedControlsBg").style.display == "block") {
        setPageInactive();
    }
}

function showPasswordField(act, show) {	
	if (act.value == '') {
		act.style.display = 'none';
		document.getElementsByName(show)[0].style.display = 'block';
	}
}

function hidePasswordField(hide, show) {
	hide.style.display = 'none';
	show = document.getElementsByName(show)[0];
	show.style.display = 'block';
	show.focus();
}

function toggleDiv(id) {alert(id);
    element = document.getElementById(id);
    alert(element);
    if (element.style.display == 'none') {
        element.style.display = 'block';
    } else {
        element.style.display = 'block';
    }
}

function checkAll() {
	var msgSelect = document.messages;
	var checkAll = msgSelect.elements['selectAll'];
	var state = false;
	
	if (checkAll.checked) {
		state = true;
	}
	
	for (i=0; i < msgSelect.length; i++) {
		if (msgSelect.elements[i].type == 'checkbox' && msgSelect.elements[i].name != 'selectAll') {
			msgSelect.elements[i].checked = state;			
		}
	}	
}

function elementFadeIn(element) {
    Effect.Appear(element);
}

function elementFadeOut(element) {
    Effect.Fade(element);
}

function elementBlindIn(element) {
    Effect.BlindDown(element);
}

function elementBlindOut(element) {
    Effect.BlindUp(element);
}

var buttons = Array();
buttons['buttonHotline'] = new Image();
buttons['buttonHotline'].src = 'images/banner/hotline_over.png';
buttons['buttonEmailkontakt'] = new Image();
buttons['buttonEmailkontakt'].src = 'images/banner/emailkontakt_over.png';
buttons['buttonBroschueren'] = new Image();
buttons['buttonBroschueren'].src = 'images/banner/broschueren_over.png';
buttons['buttonFoerderrechner'] = new Image();
buttons['buttonFoerderrechner'].src = 'images/banner/foerderrechner_over.png';
buttons['buttonAnsicht'] = new Image();
buttons['buttonAnsicht'].src = 'images/banner/ansicht_over.png';
buttons['buttonAnsichtVerkleinern'] = new Image();
buttons['buttonAnsichtVerkleinern'].src = 'images/banner/ansicht_verkleinern_over.png';
buttons['monatsgrafikImg'] = new Image();
buttons['monatsgrafikImg'].src = 'images/banner/ieu_grafik_des_monats_over.jpg';

var helpImage = new Image();

function changeImage(id) {
    helpImage.src = document.getElementById(id).src;
    document.getElementById(id).src = buttons[id].src;
    buttons[id].src = helpImage.src;
}