
function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function popup(popupUrl, popupName, x, y, w, h, extras)
{
    switch (x) {
        case 'left':
            var x = 0;
            break;
        case 'center':
            var x = (screen.width) ? (screen.width-w)/2 : 0;
            break;
        case 'right':
            var x = (screen.width) ? (screen.width-w) : 0;
            break;
    }
    switch (y) {
        case 'top':
            var y = 0;
            break;
        case 'middle':
            var y = (screen.height) ? (screen.height-h)/2 : 0;
            break;
        case 'bottom':
            var y = (screen.height) ? (screen.height-h) : 0;
            break;
    }

    //TopPos-=25; // Taskbar
    var settings = 'left=' + x + ',top=' + y + ',height=' + h + ',width=' + w + ',resizable=yes,scrollbars=yes';
    if (extras != '') settings += ',' + extras
    var win = window.open(popupUrl, popupName, settings);
    if (win) {
        if (win.window.focus) win.window.focus();
        return win;
    } else {
        alert('Bitte deaktivieren Sie Ihren Popup-Blocker!');
        return null;
    }
}

function parsePopupLinks()
{
    var links = document.getElementsByTagName('a');
    for (var i=0, link; link = links[i]; i++) {
        if (link.href && link.rel == 'popup') {
            link.onclick = function() {
                popup(this.href, 'popup', 'center', 'middle');
                return false;
            };
        }
    }
}

addLoadEvent(function() { parsePopupLinks(); });

