function display_mask()
{
    var mask = document.getElementById("themask");
    mask.style.width = screen.availWidth  + "px";
    mask.style.height = ($(window).height()) * 2  + "px";
    $(mask).show().fadeTo("slow", 0.33);
    document.body.style.overflow = "hidden";

}
function disable_mask()
{
    var mask = document.getElementById("themask");
    $(mask).fadeOut("slow");
    document.body.style.overflow = "auto";
}
function close_mask(me)
{
    $(me).fadeOut('slow');
    disable_mask();
}
function display_form(me)
{
    display_mask();
    $('#' + me).fadeIn('slow');
}

function center_form(tableid)
{
    var scwidth  = screen.width;
    var scheight = screen.height;
    var tblwidth = $("#" + tableid).width();
    var tblheight = $("#" + tableid).height();

    var D_width = (scwidth - tblwidth);
    if(D_width > 0)
    {
        D_width /= 2;
    }
    else if(D_width < 0)
    {
        D_width *= -1;
        D_width /= 2;
    }
    $("#" + tableid).css('left', D_width + 'px');

    var D_height = (scheight - tblheight);
    if(D_height > 0)
    {
        D_height /= 2;
    }
    else if(D_height < 0)
    {
        D_height *= -1;
        D_height /= 2;
    }

    document.getElementById(tableid).style.top = '150px';
    window.open("#", "_self");
}

$(document).ready(function()
{
    //ready to use
    $("#themask").bind('click', function()
    {
        close_mask('.disable_masking');
    });
    $(".close").each(function()
    {
        var main = $(this).parent().parent().parent().parent().get(0);
        $(this).bind('click', function()
        {
            close_mask('#' + main.id);
        });
    }
    );
    $('.disable_masking').each(function()
    {
        center_form(this.id);
    });
}
);
