function open_help(url) {
    void(window.open(url, 'helpwindow', 'width=450,height=330,toolbar=no,menubar=no,directories=no,location=no,scrollbars=yes,resizable=yes'));
    return false;
}

function open_large_help(url) {
    void(window.open(url, 'helpwindow', 'width=800,height=600,toolbar=no,menubar=no,directories=no,location=no,scrollbars=yes'));
    return false;
}

function resize_help_window () {
    if (self.innerWidth) {
        frameWidth = self.innerWidth;
        frameHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientWidth) {
        frameWidth = document.documentElement.clientWidth;
        frameHeight = document.documentElement.clientHeight;
    }
    else if (document.body) {
        frameWidth = document.body.clientWidth;
        frameHeight = document.body.clientHeight;
    }
    else return;
    
    var images = document.images;
    var length = document.images.length;
    var width = 0;
    
    for (var i = 0; i < length; i++) {
        if (images[i].width > width) {
            width = images[i].width;
        }
    }
    var embeds = document.embeds;
    length = document.embeds.length;
    for (var i = 0; i < length; i++) {
        if (embeds[i].width > width) {
            width = embeds[i].width;
        }
    }
    if (width > frameWidth) {
        if (width+55 > 800) {
            frameWidth = 800;
        }
        else {
            frameWidth = width+55;
        }
    }

    var height = document.getElementById('help-page').clientHeight;
    height = height-140;
    if (height > frameHeight) {
        if (height > 600) {
            frameHeight = 600;
        }
        else {
            frameHeight = height;
        }
    }
    if (frameHeight > frameWidth) {
        if (frameHeight*1.33 >800) {
            frameWidth = 800;
        }
        else {
            frameWidth = 1.33*frameHeight
        }
    }
    top.resizeTo(frameWidth, frameHeight);
}

if (self['$']) {
    // Only define this function is Prototype is available
    function activate_help_popups() {
        md_popups = $$('a.help-popup');
        lg_popups = $$('a.help-popup-large');

        md_popups.each(function(link) {
            link.observe('click', function(event) { open_help(link.href); Event.stop(event); });
        });
        lg_popups.each(function(link) {
            link.observe('click', function(event) { open_large_help(link.href); Event.stop(event); });
        });
    }
}
else {
    // We won't define the function.  If you want to use activate_help_popups you MUST load Prototype!
}

