﻿/// <reference path="jquery-1.3.2.min.js" />
var timeoutId;

function ShowModal( pWidth, pHeight, pURL, pContainerId )
{
    var id;
    var sep;
    var maskHeight;
    var maskWidth;
    var Path;

    if (pURL != null)
    {
        sep = '?';

        if (pURL.indexOf('?') != -1)
        {
            sep = '&';
        }
    }
    
    id  = $('#dialog');

    if (pWidth != null)
    {
        $(id).css('width', pWidth);
    }

    if (pHeight != null)
    {
        $(id).css('height', pHeight);
    }

    maskHeight = $(document).height() + 100;
    maskWidth  = $(window).width() + 100;

    if ($.browser.msie)
    {
        maskHeight = maskHeight - 5;
    }

    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    $('#mask').fadeIn(100);
    $('#mask').fadeTo("slow", 0.5);

    var winH = $(window).height();
    var winW = $(window).width();

    $(id).css('top', (winH / 2) - ($(id).height() / 2) + $(document).scrollTop());
    $(id).css('left', (winW / 2) - ($(id).width() / 2) + $(document).scrollLeft());

    $(document.body).css('overflow', 'hidden');

    if ($.browser.msie)
    {
        $('#tblMain').css('margin-left', '-17px');
    }
    
    if (pURL != null)
    {
        Path = appPath + pURL + sep + 'rnd=' + GetRandomNumber();

        if (pContainerId != null)
        {
            Path = Path + ' ' + pContainerId;
        }

        $('#divMsg').load(Path);
        $('#divMsg').css('text-align', 'left');
        $('#divMsg').css('margin-top', '0px');
        
        if (pWidth != null)
        {
            $('#divMsg').css('width', pWidth);
            $(pContainerId).css('width', pWidth);
        }

        if (pHeight != null)
        {
            $('#divMsg').css('height', pHeight - 30);
            $(pContainerId).css('height', pWidth - 30);
        }        

    }
    else
    {
        $('#divMsg').css('text-align', 'center');
    }

    $(id).fadeIn(200);

    return false;
}

function CloseModal()
{
    clearTimeout(timeoutId);
    $('#mask').hide();
    $('.window').hide();
    $('#divMsg').text('In Progress');

    $(document.body).css('overflow', 'auto');

    if ($.browser.msie)
    {
        $('#tblMain').css('margin-left', '0px');
    }

    return false;
}   

