// header-documentation-links.js

// Identify Products
var IsAuthoring     = window.location.href.indexOf("/Authoring/") != -1;
var IsDefaultData   = window.location.href.indexOf("/DefaultData/") != -1;
var IsDGS           = window.location.href.indexOf("/DGS/") != -1;
var IsDocViewer     = window.location.href.indexOf("/DocViewer/") != -1;
var IsEDP           = window.location.href.indexOf("/DocumentPortal/") != -1;
var IsEDS           = window.location.href.indexOf("/WK-Hosted-Expere/") != -1;
var IsEForms        = window.location.href.indexOf("/EForms/") != -1;
var IsEngine        = window.location.href.indexOf("wolterskluwerfs.com/Expere/Engine/") != -1;
var IseOriginal     = window.location.href.indexOf("/eOriginal/") != -1;
var IsESign         = window.location.href.indexOf("/WoltersKluwer_E-Sign/") != -1;
var IsEZGateway     = window.location.href.indexOf("/ExpereEZConfig/EZGateway/") != -1;
var IsI32           = window.location.href.indexOf("/I-32/") != -1;
var IsPnP           = window.location.href.indexOf("/ExpereEZConfig/PackagesAndPackets/") != -1;
var IsWKIS          = window.location.href.indexOf("/WK-IntegratedSolutions/") != -1;
var IsHosted        = window.location.href.indexOf("audience=hosted") != -1;
var IsInstalled     = window.location.href.indexOf("audience=installed") != -1;

// Generic variables
var ProductLandingPage = "";
var ProductName = "";
var IsRN = "";
var IncRNLink = '';
var ChangelogLink = "";
var RemoveSearch = "";

if (IsAuthoring){   //if Expere Authoring then
    ProductName             = "Expere Authoring";
    ProductLandingPage      = "/Expere/Authoring/index.html";
    IncRNLink               = "yes";
    ChangelogLink           = "/Expere/Authoring/ReleaseNotes/webhelp/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
    ProductName             = "Default Data";
    var AudienceValue = sessionStorage.getItem('audience');
    if(AudienceValue === "hosted"){
        ProductLandingPage  = "/WK-Hosted-Expere/";
    }
    if(AudienceValue === "installed"){
        ProductLandingPage  = "/DGS/";
    }
    IncRNLink               = "yes";
    ChangelogLink           = "/ExpereEZConfig/DefaultData/Changelogs/index.html";
    IsRN                    = window.location.href.indexOf("/DefaultData/Changelogs") != -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/PackagesAndPackets/Changelog/index.html";
    IsRN                    = window.location.href.indexOf("/PackagesAndPackets/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
    // console.log(IsDGS);
    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/EZGateway/Changelogs/index.html";
    IsRN                    = window.location.href.indexOf("/EZGateway/Changelogs") != -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 (IsOPPSA){       //if OPPSA 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;
// }

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");
$('#searchForm').before('<div class="ChangelogLink"><a href="' + ProductLandingPage + '" index.html" target="_blank">View ' + ProductName + ' Documentation Page</a>');

// // if(!(IsAuthoring)){
    $('.ChangelogLink').css({
        'display':'inline-block',
        'position':'absolute',
        'text-align':'end',
        'right':'-25px',
        'top':'40px !important',
        'font-size':'1.5rem'
    });
// // }

if (IncRNLink == "yes" && !(IsRN) ){
    $('.ChangelogLink').append(' <span style="color: black">   |   </span> '  +
        '<a href="' + ChangelogLink + '" target="_blank">View Changelog</a></div>');
}

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


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

// function getCookie(name) {
//     var nameEQ = name + "=";
//     var ca = document.cookie.split(';');
//     for (var i = 0; i < ca.length; i++) {
//         var c = ca[i];
//         while (c.charAt(0) == ' ') c = c.substring(1, c.length);
//         if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
//     }
//     return null;
// }
