// header-documentation-links.js

// TODO
// Include: EDS MAin variables section
// Add Documentation link to WK Hosted Expere Changelog


//region Changelog hrefs pulled dynamically
// var myHref = $('#EzConfigChangeLogLink').attr('href');

// https://stackoverflow.com/questions/7567181/jquery-get-different-page-elements
// $('#result').load('/WK-Hosted-Expere/index.html #EzConfigChangeLogLink').attr('href');

// console.log("MyHref = " + myHref);
//endregion

IsHosted = sessionStorage.getItem("audience");

if (IsAuthoring){   //if Expere Authoring then
    ProductName             = "Expere Authoring";
    ProductLandingPage      = "/Expere/Authoring/index.html";
    IncRNLink               = "yes";
    ChangelogLink           = "/Expere/Authoring/ReleaseNotes/index.html";
    // Changelogs
    IsRN                    = ChangelogLink;
    // User Guides
    var IsReUG 	            = window.location.href.indexOf("Authoring/RequirementsEditor") != -1;
    var IsAdminUG 			= window.location.href.indexOf("Authoring/AdministrationTool/webhelp") != -1;
    var IsDdvUG 	   		= window.location.href.indexOf("Authoring/DDV") != -1;
    var IsAuthInstallUG     = window.location.href.indexOf("Authoring/EngineInstallation") != -1;
}

if (IsDefaultData){ //if Default Data then
    // console.log(IsDefaultData);
    ProductName             = "Default Data";
    if(IsHosted){
        console.log("IsHosted = " + IsHosted);
        ProductLandingPage  = "/WK-Hosted-Expere/";
    }
    if(IsInstalled){
        console.log("IsInstalled = " + IsInstalled);
        ProductLandingPage  = "/DGS/";
    }
    IncRNLink               = "yes";
    // ChangelogLink           = DDChangelogLink;
    // alert ("ChangelogLink is " + DDChangelogLink);
    IsRN                    = window.location.href.indexOf("/ExpereEZConfig/Changelog") != -1;
    // User Guides
    var IsDD_InstallGuide   = window.location.href.indexOf("/DefaultData/InstallationGuide") != -1;
    var IsDD_UpgradeGuide   = window.location.href.indexOf("/DefaultData/UpgradeGuide") != -1;
    var IsDD_USerGuide      = window.location.href.indexOf("/DefaultData/UserGuide") != -1;
    var IsDD_WebServGuide   = window.location.href.indexOf("/DefaultData/WebServicesGuide") != -1;
}

if (IsPnP){ //if Packages and Packets then
    ProductName             = "Packages and Packets";
    if(IsHosted){
        console.log("IsHosted = " + IsHosted);
        ProductLandingPage  = "/WK-Hosted-Expere/";
    }
    if(IsInstalled){
        console.log("IsInstalled = " + IsInstalled);
        ProductLandingPage  = "/DGS/";
    }
    IncRNLink               = "yes";
    // ChangelogLink           = "/ExpereEZConfig/Changelog/index.html";
    IsRN                    = window.location.href.indexOf("/ExpereEZConfig/Changelog") != -1;
    // User Guides
    var IsPnP_InstallGuide   = window.location.href.indexOf("/ExpereEZConfig/InstallGuide") != -1;
    var IsPnP_UpgradeGuide   = window.location.href.indexOf("/PackagesAndPackets/UpgradeGuide") != -1;
    var IsPnP_USerGuide      = window.location.href.indexOf("/PackagesAndPackets/UserGuide") != -1;
    var IsPnP_WebServGuide   = window.location.href.indexOf("/ExpereEZConfig//WebservicesGuide") != -1;
}

if (IsDGS){         //if DGS then
    ProductName             = "Document Generation Services";
    ProductLandingPage      = "/DGS/";
    IncRNLink               = "yes";
    ChangelogLink           = "/DGS/Change-Log/index.html";
    // Changelogs
    IsRN                    = window.location.href.indexOf("/DGS/Change-Log") != -1;
    // User Guides
    var IsDGS_Changelog     = window.location.href.indexOf("/DGS/Change-Log/") != -1;
}

if (IsDocViewer){   //if DocViewer then
    ProductName             = "DocViewer";
    if(IsHosted){
        ProductLandingPage  = "/WK-Hosted-Expere/";
    }
    if(IsInstalled){
        ProductLandingPage  = "/DGS/";
    }
    IncRNLink               = "yes";
    ChangelogLink           = "/DocViewer/ReleaseNotes/index.html";
    // Changelogs
    IsRN                    = window.location.href.indexOf("/DocViewer/ReleaseNotes") != -1;
    // User Guides
    
}

// if (IsEDP){         //if EDP then
//     ProductName             = "Document Portal";
//     if(IsHosted){
//         ProductLandingPage  = "/WK-Hosted-Expere/";
//     }
//     if(IsInstalled){
//         ProductLandingPage  = "/DGS/";
//     }
//     IncRNLink               = "yes";
//     ChangelogLink           = "/DocumentPortal/UserGuide/index.html";
//     // Changelogs
//     IsRN                    = window.location.href.indexOf("/DocumentPortal/UserGuide/topics/edp_Change-Log-Overview.html") != -1;
//     // User Guides
//     var IsUserGuide         = window.location.href.indexOf("DocumentPortal/UserGuide") != -1;

// }

if (IsEngine){      //if Expere Engine then
    ProductName             = "Expere Engine";
    ProductLandingPage      = "/Expere/Engine/";
    IncRNLink               = "yes";
    ChangelogLink           = "/Expere/Engine/Change-Log";
    // Changelogs
    IsRN                    = window.location.href.indexOf("Engine/Change-Log") != -1;
    // User Guides
    // Install and Upgrade Guides
    // OD-Related Install Guides
}

if (IseOriginal){   //if eOriginal then
    console.log("IseOriginal = " + IseOriginal);
    ProductName             = "eOriginal";
    if(IsHosted){
        ProductLandingPage  = "/WK-Hosted-Expere/";
    }
    if(IsInstalled){
        ProductLandingPage  = "/DGS/";
    }
    IncRNLink               = "yes";
    ChangelogLink           = "/WK-Hosted-Expere/Change-Log/index.html";
    // Changelogs
    IsRN                    = window.location.href.indexOf("/WK-Hosted-Expere/Change-Log") != -1;
    // User Guides
    var IsQuickGuide     = window.location.href.indexOf("eOriginal/QuickGuide") != -1;

}

if (IsEZGateway){   //if EZGateway then
    ProductName             = "EZGateway";
    ChangelogLink           = "/ExpereEZConfig/Changelog/index.html";
    IsRN                    = window.location.href.indexOf("/ExpereEZConfig/Changelog") != -1;
    if (IsRN){
        IncRNLink = "no";
    }
    else{
        IncRNLink = "yes";
    }
    if(IsHosted){
        // console.log("IsHosted = " + IsHosted);
        ProductLandingPage  = "/WK-Hosted-Expere/";
    }
    if(IsInstalled){
        // console.log("IsInstalled = " + IsInstalled);
        ProductLandingPage  = "/DGS/";
    }
}

if (IsI32){         //if I-32 then
    ProductName             = "I-32";
    ProductLandingPage      = "/I-32/";
    IncRNLink               = "yes";
    ChangelogLink           = "/I-32/Changelog/index.html";
    // Changelogs
    IsRN                    = window.location.href.indexOf("I-32/Changelog") != -1;
    // User Guides
    var IsFormsDesignUG     = window.location.href.indexOf("I-32/FormsDesignUserGuide") != -1;
    var IsImageUpdateUG     = window.location.href.indexOf("I-32/ImageUpdate") != -1;
    // Install and Upgrade Guides
    // OD-Related Install Guides
}

if (IsWKES){       //if WKIS  then
    ProductName             = "ESign";
    ProductLandingPage      = "/WoltersKluwer_E-Sign/index.html";
    IncRNLink               = "yes";
    ChangelogLink           = "/WoltersKluwer_E-Sign/ReleaseNotes/index.html";
    // Changelogs
    IsRN                    = window.location.href.indexOf("/WoltersKluwer_E-Sign/ReleaseNotes") != -1;
    // User Guides
    var IsWKES_UserGuide   = window.location.href.indexOf("//WoltersKluwer_E-Sign/UserGuide/") != -1;
}

// if (IsWKIS){       //if WKIS  then
//     ProductName             = "OPPSA";
//     ProductLandingPage      = "/DGS/";
//     IncRNLink               = "yes";
//     ChangelogLink           = "/OPPSA/ChangeLog/index.html";
//     // Changelogs
//     IsRN                    = window.location.href.indexOf("/OPPSA/ChangeLog") != -1;
//     // User Guides
//     var IsOPPSA_UserGuide   = window.location.href.indexOf("/OPPSA/UserGuide/") != -1;
// }


// console.log("ProductName = " + ProductName + "\n" +
//             "ProductLandingPage = " + ProductLandingPage + "\n" +
//             "ChangelogLink = " + ChangelogLink  + "\n" +
//             "isRN " + IsRN + "\n");

// if (IsAuthoring || IsDefaultData || IsPnP || IsDGS || IsDocViewer ||  
//     IsEngine || IseOriginal || IsEZGateway || IsI32 || IsWKES){
//     $('.wh_content_area > .row:nth-child(1)').before('<div class="row DocLinks">' + 
//     '<span class="glyphicon glyphicon-arrow-right landing-page-arrow"></span>' +
//     '<div class="div-landing-page-btn">' +
//     '<button type="button" class="btn btn-outline-primary link-landing-page">' +
//     '<a id="LandingPageLink" class="link-primary" href="' + ProductLandingPage + '" index.html" target="_blank">View ' + ProductName + ' Documentation Page</a></button>' +
//      '</div>'
//      );

//     }

if (IsAuthoring || IsDefaultData || IsPnP || IsDGS || IsDocViewer ||  
    IsEngine || IseOriginal || IsEZGateway || IsI32 || IsWKES){
    $('.wh_right_tools').prepend('<div class="row DocLinks">' + 
    '<span class="glyphicon glyphicon-arrow-right landing-page-arrow"></span>' +
    '<div class="div-landing-page-btn">' +
    '<button type="button" class="btn btn-outline-primary link-landing-page">' +
    '<a id="LandingPageLink" class="link-primary" href="' + ProductLandingPage + '" index.html" target="_blank">View ' + ProductName + ' Documentation Page</a></button>' +
        '</div>'
        );

    }
    
        // Create View Changelog button for all products except Default Data and PnP
if ((!(IsDefaultData) && !(IsPnP)) && (IncRNLink == "yes" && !(IsChangelogPage) )) {
    $('.DocLinks').append(
        '<div class="div-changelog-btn">' +
        '<button type="button" class="btn btn-outline-primary link-landing-page">' +
        '<a class="link-primary" href="' + ChangelogLink + '" index.html" target="_blank">View Changelog</a></button></div>'
    );
}

// Change Landing Page href for DefaultData and PnP
if (IsDefaultData || IsPnP) {
    // modify landing Page link href
    $('#LandingPageLink').attr('href', ProductLandingPage + 'index.html');
}



// Create View Changelog button for Default Data
if (IsDefaultData || IsPnP) {
    // Load Landing Page file to access elements
    var NewChangelogLink;
    $.get('/WK-Hosted-Expere/index.html', function (data) {
        data = $(data).find('#EzConfigChangeLogLink');
        var id = $(data).attr('href');
        NewChangelogLink = id;
        // alert ("ChangelogLink is " + DDChangelogLink);

        if (IncRNLink == "yes" && !(IsChangelogPage) ) {
            $('.DocLinks').append(
                '<div class="div-changelog-btn">' +
                '<button type="button" class="btn btn-outline-primary link-landing-page">' +
                '<a class="link-primary" href="' + NewChangelogLink + '" index.html" target="_blank">View Changelog</a></button></div>'
            );
        }
    });
}

if (IsRN && (!(IsAuthoring))){
    $('#searchForm').remove();
}


if (IsEForms){
    console.log(IsEForms);
    $('.ChangelogLink').remove();
}
