var is_lightbox;

function show_lightbox (url, width, height)
{
    document.getElementById('lightbox_content').className='lightbox_content_show';
    document.getElementById('lightbox_overlay').className='lightbox_overlay_show';
    frames['lightbox_frame'].location.href = url;

    is_lightbox = true;

    resize_lightbox(width, height);    
    position_lightbox();

//    document.getElementById('lightbox_overlay').style.width = document.body.scrollWidth + 'px';
    document.getElementById('lightbox_overlay').style.height = (document.body.scrollHeight + height) + 'px';

}

function hide_lightbox ()
{
    if (confirm('Are you sure you want to close this window? NOTE: ALL DATA WILL BE LOST!')) 
    {
        document.getElementById('lightbox_content').className = 'lightbox_content_hide';
        document.getElementById('lightbox_overlay').className = 'lightbox_overlay_hide'
        frames['lightbox_frame'].location.href = '';
        
        is_lightbox = false;
    }
}

function hide_lightbox_no_warn ()
{
    document.getElementById('lightbox_content').className = 'lightbox_content_hide';
    document.getElementById('lightbox_overlay').className = 'lightbox_overlay_hide'
    frames['lightbox_frame'].location.href = '';
    
    is_lightbox = false;
}

function position_lightbox ()
{
    if (is_lightbox) 
    {
        width = str_replace('px', '', document.getElementById('lightbox_content').style.width);
        width = parseInt(width);

        var left_shift = (document.body.clientWidth / 2) - (width / 2);
        
        document.getElementById('lightbox_content').style.left = left_shift;
//        document.getElementById('lightbox_content').style.top = 175;
        document.getElementById('lightbox_content').style.top = parent.document.body.scrollTop + 50
    }
}

function resize_lightbox(width, height)
{
    if (is_lightbox) 
    {
        document.getElementById('lightbox_frame').style.width = width;
        document.getElementById('lightbox_frame').style.height = height - 60;
        document.getElementById('lightbox_content').style.width = width;
        document.getElementById('lightbox_content').style.height = height;
    }
}

if (typeof window.addEventListener != 'undefined') 
{
    window.addEventListener('resize', position_lightbox, false);
//    window.addEventListener('scroll', position_lightbox, false);
}
else
{
    window.onresize = function()
    {
        position_lightbox(document.getElementById('lightbox_frame').style.width);
    }
    
    window.onscroll = function()
    {
//        position_lightbox(document.getElementById('lightbox_frame').style.width);
    }
}
