/*
 * Show the options dialog
 */
function ShowInlinePopup(popupId, link, offsetX, offsetY) {    
    // If the popup is already visible (the user has clicked the link twice) then don't re-display it
    var popup = $(popupId);
    if (popup.style["display"] == "block") {
        return;
    }

    // Work out the x and y positions to show the popup. (The "FindPosition" function is in the Common.js file.)
    // Use default offsets for inline popups if not specified
    var mousePos = FindPosition(link);
    if (!offsetX) offsetX = 130;
    if (!offsetY) offsetY = 12;
    PositionPopup(popup, 100, 45, mousePos[0], mousePos[1], offsetX, offsetY);
        
    // Display after a timeout to allow the link.blur(); to occur
    if (link) link.blur();
    ShowInlinePopupByRef(popup, true);
}

function ShowInlinePopupByRef(popup, useDelay) {
    var showPopup = function() {
        // Attach a click event to the links inside the popup, to close the popup after the link is clicked
        var popupId = popup.id;
        AttachCloseEvents(popupId, popup);

        isDocumentClickRegistered = document["onclick"] != null;    
        AttachEvent(document, "onclick", function() { HideInlinePopup(popupId, false); });

        popup.style["display"] = "block";
        AttachEvent(popup, "onmouseover", function() { isMouseOverPopup = true; });
        AttachEvent(popup, "onmouseout", function() { isMouseOverPopup = false; });
        AttachSelectClickEventsFor(popup);
    }
    
    if (useDelay) setTimeout(showPopup, 100); else showPopup();
}