
//\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\//
// Functions called at startup
//\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\//



function OnSmallAppMainMenu(event) {

    var menuitems = HarvestMainRibbonMenuItems();
    if (!menuitems)
        return;

    var menu = new ContextMenu(menuitems);
    menu.display(event);
}


function SmallAppShowStContent(ContentType, UniqueId, ValueString, title) {

    if (!ContentType || ContentType.length == 0)
        return;

    // Array of content for Back and Forward
    if (ContentType != "HOMEALLVIEWS" || GetContentArrayItemCount() == 0) {

        // TODO: P3 Load these from cookies (remember the last filter for each content type)
        var FilterJsonString = "";
        var SettingsJsonString = ""

        // Only add "Home" once. Do not add it repeatedly because it confuses user
        AddToContentArray(ContentType, UniqueId, ValueString, title, FilterJsonString, SettingsJsonString);
    }

    // Fill div with content
    RefreshSmallAppContentByValues(ContentType, ValueString, FilterJsonString, SettingsJsonString);

    // Enable buttons
    EnableBackForwardContent();
}

function SetCurrentContentFilterJsonString(FilterJsonString) {

    var ContentItem = GetCurrentContentItem();
    if (!ContentItem)
        return;

    ContentItem.FilterJsonString = FilterJsonString;
}

function SetCurrentContentSettingsJsonString(SettingsJsonString) {

    var ContentItem = GetCurrentContentItem();
    if (!ContentItem)
        return;

    ContentItem.SettingsJsonString = SettingsJsonString;
}


function RefreshSmallAppCurrentContent() {

    var ContentItem = GetCurrentContentItem();
    if (!ContentItem)
        return;

    // Fill div with content
    RefreshSmallAppContentByItem(ContentItem);
}


function HarvestMainRibbonMenuItems() {

    SetupReportFilesInReportFilesDiv();

    // Convert all the tabs and buttons into a context menu
    var HarvestRibbonMainMenuDiv = $("#HarvestRibbonMainMenuDiv");
    var MainRibbonTabsList = $("#MainRibbonTabsList");
    var menuitems = HarvestMenuItemsFromTabsInDiv(HarvestRibbonMainMenuDiv, MainRibbonTabsList);
    return menuitems;
}


function ClearSmallAppContentDiv() {

    var SmallAppContentDiv = $("#" + SmallAppContentDivId);
    SmallAppContentDiv.html("");
}

function AddLoginButtonToSmallAppContentDiv() {

    // Add a single button to log in
    var sHtml = "";
    sHtml += "</br></br>";
    sHtml += "&nbsp;&nbsp;&nbsp;";
    sHtml += "<button id=\"LoginUserButton\" onclick=\"OpenLoginDialogFromCookieValues()\">Login</button>";

    var SmallAppContentDiv = $("#" + SmallAppContentDivId);
    SmallAppContentDiv.html(sHtml);
}
