/* Popup-Fenster. */

function popup(target, title, winWidth, winHeight) {
    var winLeft = ((screen.width - winWidth) / 2);
    var winTop = ((screen.height - winHeight) / 2);
    var features = "status=0,scrollBars=0,resizable=1,toolbar=0,menubar=0,location=0,directories=0;statusbar=no";
    var props = "width=" + winWidth + ",height=" + winHeight + ",top=" + winTop
            + ",left=" + winLeft + features;
    var popup = window.open(target, title, props);
    popup.opener = self;
    popup.focus();
}

/* Neues Fenster. */
function nw(target) {
    var winWidth  = (screen.width / 2);
    var winHeight = (screen.height / 2);
    var winLeft = 10;
    var winTop = 10;
    var features = "status=1,scrollBars=1,resizable=1,toolbar=1,menubar=1,location=1,directories=1;statusbar=1";
    var props = "width=" + winWidth + ",height=" + winHeight + ",top=" + winTop
            + ",left=" + winLeft + features;
    var win = window.open(target, '', props);
    win.opener = self;
    win.focus();
}

/* Popup auf dem Bildschirm zentrieren. */
function centerOnScreen(target) {
    var x = target;
    var myW = 0;
    var myH = 0;
    var d = x.document.documentElement;
    var b = x.document.body;
    if (x.innerWidth) {
        myW = x.innerWidth;
        myH = x.innerHeight;
    } else if (d && d.clientWidth) {
        myW = d.clientWidth;
        myH = d.clientHeight;
    } else if (b && b.clientWidth) {
        myW = b.clientWidth;
        myH = b.clientHeight;
    }
    if (myW > 0 && myH > 0) {
        var winLeft = ((screen.width - myW) / 2);
        var winTop = ((screen.height - myH) / 2);
        target.moveTo(winLeft, winTop);
    }
    target.focus();
}

/* Dynamische Größenanpassung für Popup-Fenster. */
function getRefToDivMod(divID, oDoc) {
    if (!oDoc) {
        oDoc = document;
    }
    if (document.layers) {
        if (oDoc.layers[divID]) {
            return oDoc.layers[divID];
        } else {
            for ( var x = 0, y; !y && x < oDoc.layers.length; x++) {
                y = getRefToDivMod(divID, oDoc.layers[x].document);
            }
            return y;
        }
    }
    if (document.getElementById) {
        return oDoc.getElementById(divID);
    }
    if (document.all) {
        return oDoc.all[divID];
    }
    return document[divID];
}

function resizeWinTo(idOfDiv) {
    var oH = getRefToDivMod(idOfDiv);
    if (!oH) {
        return false;
    }
    var oW = oH.clip ? oH.clip.width : oH.offsetWidth;
    oH = oH.clip ? oH.clip.height : oH.offsetHeight;
    if (!oH) {
        return false;
    }
    var x = window;
    x.resizeTo(oW + 0, oH + 0);
    var myW = 0;
    var myH = 0;
    var d = x.document.documentElement;
    var b = x.document.body;
    if (x.innerWidth) {
        myW = x.innerWidth;
        myH = x.innerHeight;
    } else if (d && d.clientWidth) {
        myW = d.clientWidth;
        myH = d.clientHeight;
    } else if (b && b.clientWidth) {
        myW = b.clientWidth;
        myH = b.clientHeight;
    }
    if (window.opera && !document.childNodes) {
        myW += 16;
    }
    x.resizeTo(oW + ((oW + 0) - myW), oH + ((oH + 0) - myH));
    centerOnScreen(x);
}

function refreshParent() {
    opener.location.reload();
}

function setupFields() {
    $(".dateField").datepicker({
        duration: 200,
        showOn: "button",
        buttonImage: "${images}/calendar/calendar.gif",
        buttonImageOnly: true
    });
}
