﻿function showPopup(popupClientId, popupBackgroundClientId) {
    //Center popup - use jQueryExtensions
    $('#' + popupClientId).centerOnScreen();

    //only need force for IE6
    $("#" + popupBackgroundClientId).css({
        "height": $(window).height()
    });


    $("#" + popupBackgroundClientId).css({
        "opacity": "0.4"
    });
    $("#" + popupBackgroundClientId).fadeIn("slow");
    $("#" + popupClientId).fadeIn("slow");

    //Subscibe to the click event on the background so we can close the 
    //window if the user clicks anywhere on the background
    $("#" + popupBackgroundClientId).click(function () {
        hidePopup(popupClientId, popupBackgroundClientId);
    });

    //Raise a custom event so handlers can be attached
    $("#" + popupClientId).trigger('popupOpened');
}

function hidePopup(popupClientId, popupBackgroundClientId) {
    $("#" + popupBackgroundClientId).fadeOut("slow");
    $("#" + popupClientId).fadeOut("slow");

    //This could cause potential problems if other controls are bound to the click event
    $("#" + popupBackgroundClientId).unbind('click');

    //Raise a custom event so handlers can be attached.
    $("#" + popupClientId).trigger('popupClosed');
}
