var win;

window.onresize = handleResize;
window.onload = handleResize;

if (self.name == "") {
    self.name = "main";
}

function popup(url, width, height) {
    width += 40;
    height += 40;

    var features = 'width=' + width + ',height=' + height + ',left=10,top=10,' +
        'scrollbars=yes,resizable=yes,location=no,directories=no,status=no,menubar=no';

    win = open(url, 'popup', features);
    setTimeout('win.focus();', 250);
}

function picture(name, width, height) {
    var features = 'width=' + width + ',height=' + height + ',left=10,top=10';

    win = window.open('party.php', 'popup', features);

    win.document.open();
    win.document.write('<html><head><title>Popup</title></head>');
    win.document.write('<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
    win.document.write('<img src="pictures/' + name + '" width="' + width + '" height="' + height + '" onClick="self.close()">');
    win.document.write('</body>');
    win.document.write('</html>');
    win.document.close();

    win.focus();
    setTimeout('win.focus();', 250);
}

function handleResize() {
    var footer = document.getElementById('footer');

    if (footer) {
        var footerPos = getElemPos(footer);
        var footerSize = getElemSize(footer);
        var contentPos = getElemPos('content');
        var contentSize = getElemSize('content');
        var clientSize = getWindowClientSize();

        var heightUsed = contentPos.top + footerSize.height;

        if (clientSize.height < heightUsed) {
            footer.style.top = contentPos.top + 'px';
        } else {
            footer.style.top = 'auto';
            footer.style.bottom = '0px';
        }
    }
}

function getElemPos(elem) {
    if (typeof(elem) == "string") {
        elem = document.getElementById(elem);
    }

    var left = 0;
    var top = 0;

    while (elem) {
        left += elem.offsetLeft;
        top += elem.offsetTop;
        elem = elem.offsetParent;
    }

    if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") {
        left += document.body.leftMargin;
        Top += document.body.topMargin;
    }

    return { left: left, top: top };
}

function getElemSize(elem) {
    if (typeof(elem) == "string") {
        elem = document.getElementById(elem);
    }

    var width;
    var height;

    if (elem.offsetWidth) {
        width = elem.offsetWidth;
        height = elem.offsetHeight;
    } else if (elem.clip && elem.clip.width) {
        width = elem.clip.width;
        height = elem.clip.height;
    } else if (elem.style && elem.style.pixelWidth) {
        width = elem.style.pixelWidth;
        height = elem.style.pixelHeight;
    }

    return { width: width, height: height }
}

function getWindowClientSize() {
    var width;
    var height;

    if (window.innerWidth) {
        width = window.innerWidth;
        height = window.innerHeight;
    } else if (document.body.parentElement.clientWidth) {
        width = document.body.parentElement.clientWidth;
        height = document.body.parentElement.clientHeight;
    } else {
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }

    return { width: width, height: height };
}
