

    /*** Chat Bot Settings ***/

    var globalStaticResourcePath = '/liveagent/resource/1616204122000/RH_Chatbot_Resource';

    var userClickedReadMore         = false;
    var resumeWasSubmitted          = false;
    var isCommunity                 = false;
    var showButton                  = true;
    var autoOpen                    = true;
    var proactiveTimeout            = null;
    var observer                    = null;
    var buttonObserver              = null;
    var chatButtonClass             = 'button.uiButton';
    var chatWindowClass             = '.dockableContainer';
    var chatMessageClass            = '.chatMessage';
    var clickdone                   = false;

    var isLiveAgent                 = sessionStorage.getItem('isLiveAgent') == 'true' ? true : false;
    var isBotInitialized            = sessionStorage.getItem('isBotInitialized') == 'true' ? true : false;
    var isMessageToAgentSent        = sessionStorage.getItem('isMessageToAgentSent') == 'true' ? true : false;
    var isSubmitResumeOpenedFromBot = sessionStorage.getItem('isSubmitResumeOpenedFromBot') == 'true' ? true : false;
    var isJobAlertsOpenedFromBot    = sessionStorage.getItem('isJobAlertsOpenedFromBot') == 'true' ? true : false;
    var isJobFoundByBot             = sessionStorage.getItem('isJobFoundByBot') == 'true' ? true : false;
    var askAnythingElse             = sessionStorage.getItem('askAnythingElse') == 'true' ? true : false;
    var proactive                   = sessionStorage.getItem('proactive');
    var chatKey                     = sessionStorage.getItem('chatKey');
    var isChatBtnVisibleOnPage      = false;
       
    const observeConfig = {
        attributes: true,
        childList: true,
        subtree: true
    };

    const url_domain = function() {
        var anchor = document.createElement('a');
        anchor.href = window.location;
        return anchor.hostname;
    };

    var settings = {
        displayHelpButton            : 'true',
        defaultMinimizedText         : 'Chat',
        language                     : 'en',
        storageDomain                : url_domain(),
        enabledFeatures : [
            'LiveAgent'
        ],
        entryFeature : 'LiveAgent',
        extraPrechatFormDetails : [{
                label : 'URL Location',
                value : window.location.pathname,
                transcriptFields : ['URL_Location__c'],
                displayToAgent: true
            },{
                label : 'URL Origin',
                value : window.location.origin,
                transcriptFields : ['URL_Origin__c'],
                displayToAgent: true
            }]
    };

    const autoMessagesMap = {
        resumeNotSubmitted     : '#Bot_resumeNotSubmitted',
        resumeSubmitted        : '#Bot_resumeSubmitted',
        anythingElse           : '#Bot_anythingElse',
        thanksForApplication   : '#Bot_thanksForApplication',
        jobAlerts              : '#Bot_jobAlerts',
        redirectToSubmitResume : '#Bot_redirectToSubmitResume',
        userInitiated          : '#Bot_User-Initiated',
        proactive              : '#Bot_Proactive',
        allowPopups            : '#Bot_allowPopups'
    };
    
    var visitorEngagementType = autoMessagesMap.userInitiated;

    /*** Onload Methods ***/

    const preventPageTitleChange = function() {
        window.originalTitle = document.title;
        Object.defineProperty(document, 'title', {
            get: function() {return originalTitle},
            set: function(e) {}
        });
    }

    const clearRedundantSessionStorage = function() {
        if (window.performance.navigation.type == 1) {
            sessionStorage.removeItem('proactive');
            proactive = null;
        }
        if (!location.pathname.includes('/submit-resume')) {
            sessionStorage.removeItem('isSubmitResumeOpenedFromBot');
            isSubmitResumeOpenedFromBot = false;
        }
        if (!location.pathname.includes('/job') && !location.pathname.includes('submit-resume/thank-you/')) {
            sessionStorage.removeItem('isJobFoundByBot');
            sessionStorage.removeItem('isJobAlertsOpenedFromBot');
            isJobFoundByBot = false;
            isJobAlertsOpenedFromBot = false;
        }
    }

    const sendMessageAfterResumeSubmitted = function() {
        if (location.pathname.includes('submit-resume/thank-you/') && !isLiveAgent) {
            if (isSubmitResumeOpenedFromBot) {
                embedded_svc.postMessage("chasitor.sendMessage", autoMessagesMap.resumeSubmitted);
                sessionStorage.removeItem("isSubmitResumeOpenedFromBot");
            }
            if (isJobFoundByBot) {
                embedded_svc.postMessage("chasitor.sendMessage", autoMessagesMap.thanksForApplication);
                sessionStorage.removeItem("isJobFoundByBot");
                isJobFoundByBot = false;
            }
        }
    }

    const sendJobAlertsQuestion = function() {
        if (location.pathname.includes('/jobs/') && !isLiveAgent) {
            if (window.performance.navigation.type != 1 && isJobFoundByBot) {
                embedded_svc.postMessage("chasitor.sendMessage", autoMessagesMap.resumeSubmitted);
            }
        }
    };

    const sendAnythingElseQuestion = function() {
        if (askAnythingElse && !isLiveAgent) {
            embedded_svc.postMessage("chasitor.sendMessage", autoMessagesMap.anythingElse);
            sessionStorage.removeItem("askAnythingElse");
            askAnythingElse = false;
        }
    };

    preventPageTitleChange();
    clearRedundantSessionStorage();

    /*** Drupal Windows Methods ***/

    window.chatBotInteraction = function(actionType) {
        switch(actionType) {
            case '#JOB_ALERTS':
                if (isJobAlertsOpenedFromBot || isJobFoundByBot) {
                    embedded_svc.postMessage("chasitor.sendMessage", autoMessagesMap.jobAlerts);
                    sessionStorage.removeItem("isJobAlertsOpenedFromBot");
                    isJobAlertsOpenedFromBot = false;
                }
                break;
            default:
                return false;
        }
        return true;
    };

    /*** Standard Bot Events ***/

    const addBotEventHandlers = function() {
        embedded_svc.addEventHandler("onAgentMessage", function(data) {
            if (!isBotInitialized && jQuery('.messageArea').length) {
                isBotInitialized = true;
                sessionStorage.setItem('isBotInitialized', isBotInitialized);

                chatKey = data.liveAgentSessionKey;
                sessionStorage.setItem('chatKey', chatKey);

                embedded_svc.postMessage("chasitor.sendMessage", visitorEngagementType);
            }
        });

        embedded_svc.addEventHandler("onHelpButtonClick", function() {
            onHelpButtonClickHandler();
        });

        embedded_svc.addEventHandler("onChatEndedByChasitor", function(data) {
            removeBotInitSessionData();
        });

        embedded_svc.addEventHandler("onChatEndedByAgent", function(data) {
            removeBotInitSessionData();
        });

        embedded_svc.addEventHandler("onConnectionError", function(data) {
            removeBotInitSessionData();
        });

        embedded_svc.addEventHandler("onIdleTimeoutOccurred", function(data) {
            removeBotInitSessionData();
        });

        embedded_svc.addEventHandler("onChatTransferSuccessful", function(data) {
            if (sessionStorage.getItem('proactive') == "true") {
                proactiveLiveAgent_Tealium();
            }
            sessionStorage.setItem('isLiveAgent', true);
            isLiveAgent = true;
        });
    };

    const onHelpButtonClickHandler = function() {
        addBotListener();
        addTextAreaListener();
        if (!isCommunity) addHelpButtonListener();
        autoOpen = false;

        if (proactive == "false") chatButtonClicked_Tealium();
        sessionStorage.setItem('proactive', proactive);

        if (!isCommunity) {
            var contactId = window.userFormFields ? window.userFormFields.contactId : '';
            settings.extraPrechatFormDetails.push({
                label               : 'Visitor Id',
                value               : contactId,
                transcriptFields    : ['Visitor_Id__c'],
                displayToAgent      : true
            });
        }
    };

    const removeBotInitSessionData = function() {
        sessionStorage.removeItem('isBotInitialized');
        sessionStorage.removeItem('chatKey');
        sessionStorage.removeItem('isLiveAgent');
        sessionStorage.removeItem('isMessageToAgentSent');
        sessionStorage.setItem('proactive', false);

        isMessageToAgentSent = false;
        isBotInitialized = false;
        isLiveAgent = false;
        sessionStorage.setItem('proactive', false);
        proactive = 'false';
    };

    const showHelpButton = function(showOrHide) {
        showButton = showOrHide;
        if (showOrHide) {
            embedded_svc.showHelpButton()
        } else {
            embedded_svc.hideHelpButton();
        }
    };

    /*** User Action Listeners ***/

    window.inactiveUserTime = null;

    const inactiveUser = function() {
    	clearTime(window.inactiveUserTime);
        window.inactiveUserTime = setTimeout(
        	makeActionWhenUserIsInactive,
            '120000'
        );
    };

    const clearTime = function(timeToClear) {
    	if (timeToClear) {
        	clearTimeout(timeToClear); 
        }
    };

    const makeActionWhenUserIsInactive = function() {
        if (isBotInitialized && !isLiveAgent) {
            if (location.pathname == '/submit-resume' && !resumeWasSubmitted) {
                embedded_svc.postMessage("chasitor.sendMessage", autoMessagesMap.resumeNotSubmitted);
            } else {
                embedded_svc.postMessage("chasitor.sendMessage", autoMessagesMap.anythingElse);
            }
        }
    };

    window.addEventListener('click', inactiveUser);
    window.addEventListener('keypress', inactiveUser);

    /*** Chat Action Listeners ***/

    const openChatAutomaticallyAfterTime = function () {
        var currentHour = 11;
        var currentDay = 'Thu';
        if (currentDay != 'Sat' && currentDay != 'Sun' && currentHour >= 5 && currentHour < 17) {
            proactiveTimeout = setTimeout(
                function() {
                    if (autoOpen && showButton && !jQuery(chatWindowClass).length) {
                        visitorEngagementType = autoMessagesMap.proactive;
                        proactive = 'true';
                        proactiveBot_Tealium();
                        jQuery(chatButtonClass).click();
                    }
                }, '30000'
            );
        }
        proactive = 'false';
    };

    const addTextAreaListener = function () {
        waitForElementRender(chatMessageClass, textAreaListener, 500);
    };

    const addBotListener = function () {
        waitForElementRender(chatWindowClass, initBotListener, 100);
    };

    const addHelpButtonListener = function() {
        waitForElementRender(chatButtonClass, helpButtonAvailabilityListener, 50);
    };

    const waitForElementRender = function(selector, callback, time) {
        if (!jQuery(selector).length) {
            setTimeout(function() {
                waitForElementRender(selector, callback);
            }, time);
        } else {
            callback();
        }
    };

    const initBotListener = function() {
        observer = new MutationObserver(makeActionBasedOnBotChange);
        observer.observe(jQuery(chatWindowClass)[0], observeConfig);
    };

    const textAreaListener = function() {
        jQuery(".chasitorText")[0].onkeydown = function(e) {
            if (e.code == 'Enter') {
                textAreaSubmitted_Tealium();
                if (!isMessageToAgentSent && isLiveAgent) {
                    sessionStorage.setItem('isMessageToAgentSent', true);
                    isMessageToAgentSent = true;
                    liveAgentEngagement_Tealium();
                }
            }
        }
        sendMessageAfterResumeSubmitted();
        sendJobAlertsQuestion();
        sendAnythingElseQuestion();
    };

    const helpButtonAvailabilityListener = function() {
        jQuery('.helpButton').on("DOMSubtreeModified", function() {
            if ((!embedded_svc.liveAgentAPI && !embedded_svc.liveAgentAPI.connection.running) ||
                 !embedded_svc.settings.agentAvailableOnButtonClick) {

                showHelpButton(false);

            } else {
                if (!showButton) {
                    showHelpButton(true);
                    openChatAutomaticallyAfterTime();
                }
            }
        });
    };

    const makeActionBasedOnBotChange = function(mutations, observer) {
        mutations.forEach(function(mutation) {
            if (mutation.target.className && mutation.target.className.includes('messageWrapper') && mutation.addedNodes.length) {
                var newMessageContainer = jQuery(mutation.addedNodes[0]);
                var newMessage = newMessageContainer.children('.chatContent');
                if (!newMessage.length) {
                    newMessage = newMessageContainer.children('.embeddedServiceLiveAgentStateChatEventMessage');
                }

                var messageValue = newMessage[0].textContent;
                if (messageValue.includes('#Bot') || messageValue.includes('#HTTP')) {
                    newMessageContainer.remove();
                }

                var splitMessage = messageValue.split(';');
                if (splitMessage.length && splitMessage[0].includes("#HTTP")) {
                    redirectToPage(splitMessage);
                }

                sendTealiumEventOnUtterance(messageValue);

                if ((messageValue == "Bot-No-Agents-Available") || (messageValue == "No agents are available.")) {
                    showNoAgentsAvailable();
                }

                var elements = jQuery(chatMessageClass);
                if (elements.length > 4) {
                    scrollChatToBottom();
                }
            }
        });
    };

    const redirectToPage = function(splitMessage) {
        var newPath = splitMessage[1];
        var timeout = 2000;
        var redirectTarget = "_self";

        switch (splitMessage[2]) {
            case "#SUBMIT_RESUME":
                sessionStorage.setItem("isSubmitResumeOpenedFromBot", true);
                isSubmitResumeOpenedFromBot = true;
                break;
            case "#JOB_ALERTS":
                sessionStorage.setItem("isJobAlertsOpenedFromBot", true);
                isJobAlertsOpenedFromBot = true;
                break;
            case "#JOB_SEARCH":
                sessionStorage.setItem("isJobFoundByBot", true);
                isJobFoundByBot = true;
                break;
            case "#ANYTHING_ELSE":
                if (splitMessage[1].includes(location.pathname + '#')) {
                    embedded_svc.postMessage("chasitor.sendMessage", autoMessagesMap.anythingElse);
                } else {
                    sessionStorage.setItem("askAnythingElse", true);
                    askAnythingElse = true;
                }
                break;
            case "#LUX_COMMUNITY":
                timeout = 4000;
                redirectTarget = "_blank";
            default:
                break;
        }

        setTimeout(function() {
            let newWindow = window.open(newPath, redirectTarget);
            if (!newWindow || newWindow.closed || typeof newWindow.closed=='undefined') {
                embedded_svc.postMessage("chasitor.sendMessage", autoMessagesMap.allowPopups);
            } else if (redirectTarget == '_blank') {
                embedded_svc.postMessage("chasitor.sendMessage", autoMessagesMap.anythingElse);
            }
        }, timeout);
    };

    const sendTealiumEventOnUtterance = function(message) {
        if (message == "#Bot_Hire") {
            lookingToHire_Tealium();
        } else if (message == "#Bot_Look_for_a_job") {
            lookingForAJobs_Tealium();
        } else if (message == "#Bot_Transfer_To_Live_Agent") {
            anAgentIsOnItsWay_Tealium();
        }
    };

    const showNoAgentsAvailable = function() {
        var element = jQuery('.stateBody');
        var buttons = jQuery('.endChatContainer');

        var iFrameSrc = 'src="https://rh.secure.force.com/liveagent/RHCB_OfflineChatForm?chatKey=' + chatKey + '"';
        var iFrameHtml = '<iframe  allow="geolocation *; microphone *; camera *" frameborder="0" height="100%" id="j_id24" name="j_id24" scrolling="no" src="" title="Content" width="100%"></iframe>';
        iFrameHtml = iFrameHtml.replace('src=""', iFrameSrc + ' class="offline-form"');
        element.html(iFrameHtml);

        jQuery('.embeddedServiceSidebarExtendedHeader .content').remove();
        embedded_svc.liveAgentAPI.ping();
        addIFrameEventHandler(buttons);
        removeBotInitSessionData();
    };

    const addIFrameEventHandler = function(buttons) {
        window.addEventListener('message', function (e) {
            if (e.data === "formSubmittedEvent" || e.message === "formSubmittedEvent") {
                buttons.css('position', 'absolute');
                buttons.css('bottom', '0');
                jQuery('.stateBody').append(buttons);
            }
        });
    };
    
    const scrollChatToBottom = function() {
    	var elements = document.getElementsByClassName('messageArea');
        elements[0].scrollTop = elements[0].scrollHeight;
    };

    /*** Tealium Events ***/

    const chatButtonClicked_Tealium = function() {
        sendTealiumEvent("chat_live_agent_initiate_click");
    };

    const textAreaSubmitted_Tealium = function() {
        sendTealiumEvent("chat_engagement");
    };

    const proactiveBot_Tealium = function() {
        sendTealiumEvent("chat_proactive_bot_load");
    };

    const proactiveLiveAgent_Tealium = function() {
        sendTealiumEvent("chat_proactive_agent_load");
    };

    const lookingForAJobs_Tealium = function() {
        sendTealiumEvent("chat_bot_response_candidate");
    };

    const lookingToHire_Tealium = function() {
        sendTealiumEvent("chat_bot_response_client");
    };

    const anAgentIsOnItsWay_Tealium = function() {
        sendTealiumEvent("chat_bot_live_agent_transfer");
    };

    const liveAgentEngagement_Tealium = function() {
        sendTealiumEvent("chat_live_agent_engagement");
    };

    const sendTealiumEvent = function(eventValue) {
        utag.link({
            "tealium_event": eventValue
        });
    };

    /*** Chat main methods ***/
    const initEinsteinBot = function() { 

    console.log('@@@initEinsteinBot'+ '@@@isbotini=' + isBotInitialized+'@@@isChatBtnVisibleOnPage='+isChatBtnVisibleOnPage);
        isChatBtnVisibleOnPage = false;
        if (!isBotInitialized) {
            var i = 0;
            const time = setInterval(
                function() {
                    i++;
                    if (((window.clientId && window.drupalSettings) || i == 20) && window.clientId != 'not set') {
                        clearInterval(time);
                        initEmbedded_svc();
                        if (!proactive) openChatAutomaticallyAfterTime();
                    }
                }, 500
            );
        } else {
            initEmbedded_svc();
        }
    };
    
    const checkLiveagentAvail = async function() {
        isChatBtnVisibleOnPage = true;

        if(isBotInitialized){
            initEmbedded_svc();
        } else {
            const pathname = window.location.pathname.toLowerCase();
            const hostname = window.location.hostname.toLowerCase();
            const agentAvailability = await getButtonIdBySource(pathname,hostname);
            var t = JSON.parse(agentAvailability); 
            var results = t.messages[0].message.results;

            results.every(element => {
                if(element.isAvailable == true){
                    sessionStorage.setItem("chatButtonId", element.id);
                    return;
                }
            });
        }
    };

    const getButtonIdBySource = async function(pathname, hostname){
        const myHeaders = new Headers()
        myHeaders.append("Content-Type", "application/json")
        const requestOptions = {
            method: 'GET',
            headers: myHeaders,
            redirect: 'follow'
        }
        
        const response = await fetch("https://rh.secure.force.com/liveagent" + "/services/apexrest/Button?path=" + encodeURI(pathname) + "&host=" + encodeURI(hostname), requestOptions)
        const availabilty = await response.json();

        return availabilty;
    }
    
    const initEmbedded_svc = function() {
        var clientId =  window.clientId ? window.clientId.split('.')[0] : '';
        var visitorType = window.drupalSettings ? window.drupalSettings.rh_datalayer.ContentUserFocusCD : null;
        var buttonId;
        if(sessionStorage.getItem("chatButtonId") != undefined && !isChatBtnVisibleOnPage) {
            buttonId = sessionStorage.getItem("chatButtonId");
        } else {
            buttonId = getButtonId();
        }

        settings.extraPrechatFormDetails.push({
            label               : 'Client Id',
            value               : clientId,
            transcriptFields    : ['Client_Id__c'],
            displayToAgent      : true
        });
        settings.extraPrechatFormDetails.push({
            label               : 'beforeThankyou',
            value               : isChatBtnVisibleOnPage,
            transcriptFields    : ['beforeThankyou__c'],
            displayToAgent      : false
        });
        if(window.drupalSettings.form_user_input != undefined) {
            var vendorId = JSON.parse(window.drupalSettings.form_user_input).leadId;
            settings.extraPrechatFormDetails.push({
                label               : 'Vendor Id',
                value               : vendorId,
                transcriptFields    : ['Vendor_Id__c'],
                displayToAgent      : true
            });
        }
        
        if (visitorType == 'Client' || visitorType == 'Candidate') {
            settings.extraPrechatFormDetails.push({
                label               : 'Visitor Type',
                value               : visitorType,
                transcriptFields    : ['Visitor_Type__c'],
                displayToAgent      : true
            });
        }

        embedded_svc.settings.targetElement = jQuery('body')[0]
        Object.assign(embedded_svc.settings, settings);
        embedded_svc.init(
            'https://rh.my.salesforce.com',
            'https://rh.secure.force.com/liveagent',
            'https://service.force.com',
            '00Dd0000000iMUB',
            'RH_North_America_Proactive_Bot_Snap_In',
            {
                baseLiveAgentContentURL : 'https://c.la1-c1-ia5.salesforceliveagent.com/content',
                deploymentId            : '5720V000001UJCp',
                buttonId                :  buttonId,
                baseLiveAgentURL        : 'https://d.la1-c1-ia5.salesforceliveagent.com/chat',
                eswLiveAgentDevName     : 'EmbeddedServiceLiveAgent_Parent04I0V000000CaS0UAK_16c55a7030c',
                isOfflineSupportEnabled : false
            }
        );
        addBotEventHandlers();
        addTextAreaListener();
        addHelpButtonListener();
        if(isBotInitialized) addBotListener();
        if(!isChatBtnVisibleOnPage && !clickdone && sessionStorage.getItem("chatButtonId") != undefined) {
            const ctime = setInterval(
                function() {
                    var chtButtonClass = 'button.uiButton';
                    var chtButtonText = jQuery(chtButtonClass).length > 0  ? jQuery(chtButtonClass)[0].innerText : undefined;
                    if(jQuery(chtButtonClass).length > 0 && chtButtonText!= undefined && !chtButtonText.includes('Offline') && !jQuery(chtButtonClass).hasClass("helpButtonDisabled")) {
                        clearInterval(ctime);
                        jQuery(chtButtonClass).click();
                        clickdone=true;
                    }
            },200);
        }
       
        
    };

    const getButtonId = function() {
        var locationsMap = JSON.parse('{"/locations/la-baton-rouge/4000-s-sherwood-forest-boulevard":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/sc-north-charleston/4105-faber-place-drive":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ri-providence/275-promenade-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ca-los-angeles":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ma-springfield/one-monarch-pl":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/technology":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/tx-midland/300-north-marienfeld":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/il-chicago":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/tx-san-antonio/8000-ih-10-west":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/officeteam":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/sc-greenville":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/en/find-the-right-service":{"Button_Name__c":null,"Button_Name_CAN__c":"5733w000000oLp1AAE"},"/locations/ny-buffalo/726-exchange-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/pa-pittsburgh":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ky-louisville/9300-shelbyville-rd":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/legal":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/nc-charlotte":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/oh-columbus":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/long-term-project-consultants":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/in-fort-wayne/9921-dupont-circle-dr-w":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ia-davenport/5405-utica-ridge-road":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/me-portland/100-middle-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/oh-cincinnati":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/mn-minneapolis-st-paul":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ga-savannah/2-east-bryan-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/nm-albuquerque/6501-americas-pkwy-ne":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/looking-for-a-job/direct-apply":{"Button_Name__c":"5730V000000oLogQAE","Button_Name_CAN__c":null},"/locations/hi-honolulu/737-bishop-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ne-omaha/1125-s-103rd-st":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/wi-middleton/1600-aspen-commons":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ca-sacramento-stockton-modesto":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ga-atlanta":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/tn-chattanooga/537-market-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/az-tucson/5255-east-williams-circle":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/mo-st-louis/622-emerson-road":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/md-baltimore":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ny-new-york":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/wa-spokane/601-w-riverside-avenue":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ia-cedar-rapids/1120-depot-lane-se":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/en/new-job-order":{"Button_Name__c":null,"Button_Name_CAN__c":"5733w000000oLp1AAE"},"/locations/ut-salt-lake-city":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/az-phoenix":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ar-little-rock/10801-executive-center-drive":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ny-albany/20-corporate-woods-blvd":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ga-macon/3920-arkwright-road":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ca-san-diego":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/oh-cleveland-akron":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/creativegroup":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/va-norfolk/150-west-main-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/mi-grand-rapids-kalamazoo":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/find-the-right-service":{"Button_Name__c":"5733w000000oLp0AAE","Button_Name_CAN__c":null},"/locations/ny-syracuse/300-s-state-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/mi-east-lansing/2900-west-road":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/management-resources":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ny-rochester/255-east-avenue":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/tx-houston":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/fl-ft-myers/9530-marketplace-road":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/candidate-search":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/tn-memphis":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/nv-las-vegas/3993-howard-hughes-pkwy":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/finance":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ca-santa-barbara/1525-state-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/in-indianapolis":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/time-reports/unavailable":{"Button_Name__c":"5733w000000oLpLAAU","Button_Name_CAN__c":null},"/employers/full-time-staffing":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/dc-washington":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/sc-columbia/1441-main-st":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/accountemps":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ca-orange-county":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/va-richmond/1051-east-cary-st":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ca-monterey/4-lower-ragsdale-drive":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/fl-tampa":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/en/time-reports/unavailable":{"Button_Name__c":null,"Button_Name_CAN__c":"5733w000000oLpLAAU"},"/locations/oh-youngstown":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ok-tulsa/8801-s-yale-ave":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/nv-reno":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/default":{"Button_Name__c":"5733w0000019KZmAAM","Button_Name_CAN__c":"5733w0000019KZmAAM"},"/apex/EinsteinBot":{"Button_Name__c":null,"Button_Name_CAN__c":null},"/locations/al-birmingham/3535-grandview-pkwy":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ca-indian-wells/74760-us-highway-111":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/pa-philadelphia":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/direct-candidate-match":{"Button_Name__c":"5730V000000oLogQAE","Button_Name_CAN__c":null},"/locations/co-colorado-springs/5575-tech-center-drive":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/tn-knoxville/1111-northshore-drive-nw":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/nc-raleigh":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/or-portland/10220-sw-greenburg-road":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/fl-west-palm-beach":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/mi-detroit":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/oh-perrysburg/2210-levis-common-blvd":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ar-fayetteville/438-east-millsap-rd":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ia-des-moines/801-grand-ave":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/hiring-request-form":{"Button_Name__c":null,"Button_Name_CAN__c":null},"/locations/id-boise/720-park-blvd":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ca-san-francisco-bay-area":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/fl-orlando":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/fl-miami-ft-lauderdale":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/tn-nashville":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/executive-search":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/fl-jacksonville/10751-deerwood-park-blvd-south":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/mo-kansas-city/2345-grand-blvd":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/tx-el-paso/4100-rio-bravo-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/wa-seattle-tacoma":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"www.robert-half.com/unitTestLocation":{"Button_Name__c":null,"Button_Name_CAN__c":null},"/locations/ca-bakersfield/5001-east-commercenter-drive":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/la-new-orleans/909-poydras-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ma-boston-manchester":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/oh-dayton/one-south-main-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/employers/flexible-staffing":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ca-fresno":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ok-oklahoma-city/3817-nw-expressway":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ky-lexington/2343-alexandria-drive":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/or-eugene/800-willamette-street":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/ct-hartford":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/wi-appleton/100-w-lawrence-street-3rd-floor":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/wi-milwaukee":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/tx-dallas-ft-worth":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/nc-greensboro/101-centreport-drive":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/tx-austin/10801-2-n-mopac-expressway":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/staffing-services-request-form":{"Button_Name__c":null,"Button_Name_CAN__c":null},"/employers/managed-solutions":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null},"/locations/co-denver":{"Button_Name__c":"5733w0000019KZhAAM","Button_Name_CAN__c":null}}');
        var pathname = window.location.pathname.toLowerCase();
        //PRCBT-353_VJ - identifying if the domain is CANADA or US
        let isThisCanadaDomain = window.location.hostname.toLowerCase().endsWith('.ca');

        if(pathname.includes('hiring') || pathname.includes('find-the-right') || pathname.includes('new-job-order')) {
            console.log('@@@setting pathname');
            pathname = pathname+'xx';
        }

        //PRCBT-353_VJ - modified below variable name
        let botLocationDetails = ((pathname in locationsMap) ? locationsMap[pathname] : locationsMap['/default']);
        isChatBtnVisibleOnPage = true;

        //PRCBT-353_VJ - conditionally return CANADA chat button Id or US chat button Id.
        return isThisCanadaDomain ? botLocationDetails.Button_Name_CAN__c.substring(0,15) : botLocationDetails.Button_Name__c.substring(0,15);
    }