function ShowModal(modalUrl)
{
    $('#modalFrame').bind('load', HideLoadingMsg);
    ShowLoadingMsg();
    $('#modalFrame').attr('src', modalUrl);
}

function ShowModalResize(modalUrl, width, height, hideCloseButton)
{
    var ibHeight = width;
    var ibWidth = height;
    if ((window.innerHeight) && (window.innerWidth))
    {
        ibHeight = window.innerHeight;
        ibWidth = window.innerWidth;
        
        window.open(modalUrl, 'cgModalWindow', "\'menubar=0,status=0,toolbar=0,height=" + height + ",width=" + width + "\'");
        return;
    }
    else if ((document.documentElement.clientHeight) && (document.documentElement.clientWidth))
    {
        ibHeight = document.documentElement.clientHeight;
        ibWidth = document.documentElement.clientWidth;
    }

    if ((ibHeight < height) || (ibWidth < width))
    {
        window.open(modalUrl, 'cgModalWindow', "\'menubar=0,status=0,toolbar=0,height=" + height + ",width=" + width + "\'");
        return;
    }

    var blockPage = getCSSRule('.blockPage');
    if (blockPage != false)
    {
        blockPage.style.width = width;
        blockPage.style.height = height;
        blockPage.style.marginLeft = (width / 2) * (-1);
    }

    var dialog = getCSSRule('#dialog');
    if (dialog != false)
    {
        dialog.style.width = width;
        dialog.style.height = height + 3;
        if (hideCloseButton)
        {
            dialog.style.paddingTop = 0;
        }
    }

    var dialogClose = getCSSRule('#dialog #dialogClose');
    if (dialogClose != false)
    {
        if (hideCloseButton) 
            dialogClose.style.display = 'none'; 
        else
            dialogClose.style.display = 'block';
    }
    
    $('#modalFrame').bind('load', HideLoadingMsg);
    ShowLoadingMsg();
    $('#modalFrame').attr('src', modalUrl);
}

function ShowLoadingMsg()
{
    $.blockUI({ message: $('#dialog') });
    $('#loadingMsg').show();
    $('#modal').hide();
    $('html').addClass('killScroll');
}

function HideLoadingMsg()
{
    $('#loadingMsg').hide();
    $('#modal').show();
}

function CloseModal()
{
    $.unblockUI();
    $('html').removeClass('killScroll');
}

/*
Taken from http://www.hunlock.com/blogs/Totally_Pwn_CSS_with_Javascript
Gets a CSS rule on a page by class name
modified by remove the "delete" option
*/

function getCSSRule(ruleName)                             // Return requested style obejct
{                           
   ruleName=ruleName.toLowerCase();                       // Convert test string to lower case.
   if (document.styleSheets)                              // If browser can play with stylesheets
   {
      for (var i=0; i<document.styleSheets.length; i++)  // For each stylesheet
      {
         var styleSheet=document.styleSheets[i];          // Get the current Stylesheet
         var ii=0;                                        // Initialize subCounter.
         var cssRule=false;                               // Initialize cssRule. 
         do                                               // For each rule in stylesheet
         {
            if (styleSheet.cssRules)                      // Browser uses cssRules?
            {
               cssRule = styleSheet.cssRules[ii];         // Yes --Mozilla Style
            } else {                                      // Browser usses rules?
               cssRule = styleSheet.rules[ii];            // Yes IE style. 
            }                                             // End IE check.
            if (cssRule)                                  // If we found a rule...
            {
               if (cssRule.selectorText.toLowerCase()==ruleName)  //  match ruleName?
               {
                  return cssRule;                         // return the style object.
               }                                          // End found rule name
            }                                             // end found cssRule
            ii++;                                         // Increment sub-counter
         } while (cssRule)                                // end While loop
      }                                                   // end For loop
   }                                                      // end styleSheet ability check
   return false;                                          // we found NOTHING!
}                                                         // end getCSSRule 