function closePopupById(psIdWindow) 
{
    skPopup.closePopupById(psIdWindow);
}

function openPopup(popupId, popupMode, aExtraParam)
{
    skPopup.closePopupById(popupId);

    if (g_PopupSpec[popupId][3])
        skPopup.closeAllPopups();

    var newPopup = skPopup.initNewPopup(popupId, popupMode);

    newPopup.width  = g_PopupSpec[popupId][0];
    newPopup.height = g_PopupSpec[popupId][1];

    if (newPopup.width > window.screen.width - 5)
        newPopup.width = window.screen.width - 5;
    if (newPopup.height > window.screen.height - 25)
        newPopup.height = window.screen.height - 25;

    //Other parameters:
    //newPopup.{minWidth, minHeight, maxWidth, maxHeight}
    //newPopup.{title,titleBar,alwaysRaised,url,center}
    newPopup.alreadyRaised = "yes";
    newPopup.chrome = "yes";
    newPopup.depend = "yes";
    newPopup.modal = "no";
    newPopup.resize = g_PopupSpec[popupId][2];
    newPopup.titleBar = "yes";
    var popupUrl = g_PopupSpec[popupId][4];
    // absolute URL, don't add prefix
    if (popupUrl.match(/^\w+:\/\//))
        newPopup.url = popupUrl;
    // relative URL, add prefix
    else
        newPopup.url = "chrome://ocoll2e/content/popup/" + popupUrl;

    newPopup.extraArgs = aExtraParam;

    var newWindow = skPopup.openPopup();
    var mainWindow = window;
    newWindow.addEventListener("load", function()
    {
        var size = mainWindow.g_Pref.GetIntPref("skpref.fontsize");
        mainWindow.UpdateTextSize(size, newWindow);
    }, false);
    return newWindow;
}

function openExercisePopup(psExercise, psData) {
    openPopup(POPUP_EXERCISES, false, { exercise: psExercise, data: psData });
}
