function get_href() {

    var login_pattern = /login.phtml/;

    var my_href = window.location.href;

    var maid_pattern = /MAID=(\d+)/i;
    var maid_result = my_href.match(maid_pattern);
    var maid = 1660;

    if (maid_result) {
        maid = maid_result[1];
    }

    var user_pattern = /USER=([^&]+)/i;
    var user_result = my_href.match(user_pattern);
    var user = '';
    if (user_result) {
        user = user_result[1];
    }

    var password_pattern = /PASSWORD=([^&]+)/i;
    var password_result = my_href.match(password_pattern);
    var password = '';
    if (password_result) {
      password = password_result[1];
    }

    var redirect_pattern = /RedirectForenBeitrag=([0-9]+)/;
    var redirect_result = my_href.match(redirect_pattern);
    var redirect = '';
    if (redirect_result) {
        redirect = redirect_result[1];
    }

    var token_pattern = /TOKEN=([^&]+)/;
    var token_result = my_href.match(token_pattern);
    var token = '';
    if (token_result) {
        token = token_result[1];
    }

    var url = '../login.phtml?PHPINI_CHECK=1&MAID='+maid+'&HTTP_USER_SCREEN='+screen.width+'x'+screen.height;
    if (user != '' && password != '') {
        url += '&USER='+user
            +  '&PASSWORD='+password
            +  '&PHPINI_CHECK=1&GoOn=1';
    }
    if (redirect != '') {
        url += '&RedirectForenBeitrag='+redirect;
    }
    if (token) {
        url += '&TOKEN='+token;
    }

    return url;
}



function stopBusy() {
    window.document.getElementById('loading').style.display='none';
}

function startBusy() {
    window.document.getElementById('loading').style.display='';
}

function setSecondsBusy(sec) {
    startBusy();
    setTimeout('stopBusy()',sec*1000);
}

function DlsBase() {
    return window.mainframe;
}

function openWindow(url,referer) {
    var win = window.document.createElement('div');
    win.setAttribute('id','popup');
    
    var head = window.document.createElement('div');
    head.setAttribute('id','head');
    win.appendChild(head);

    var body = window.document.createElement('div');
    body.setAttribute('id','body');
    win.appendChild(body);

    window.document.getElementById('loading-mask').appendChild(win);

    setSecondsBusy(3);

    head.innerHTML='<img id="close" src="images/buttons/16x16/grau/x-hell.gif" onclick="window.document.getElementById(\'popup\').remove()" />';

    body.innerHTML='<iframe name="iwin" id="iwin" src="'+url+'"></iframe>';
    window.iwin.referer=referer;
        
    win.remove=function() {
        this.parentNode.removeChild(this);
    }

    window.iwin.remove=function() {
        top.document.getElementById('popup').remove();
    }

}

function login() {
    var b = window.document.getElementById('loading-mask');
    b.style.height="100%";
    b.innerHTML = '<iframe name="mainframe" id="mainframe" src="'
                + get_href()
                + '"></iframe>';
    setSecondsBusy(2);
    
}
