//CustomJS Cole Haan LIVE
//Apr 04 2024

if(!(IMI.CustomJS && IMI.CustomJS.customJSisLoaded)){
    (function(){
        IMI.Classes.Trigger.UserPercentageTriggerType.prototype.evaluateTriggerRule = function(triggerRule) {
            var triggered = false;
            var tid = "im_throttleInclude_" + triggerRule.id;
            
            if(window.sessionStorage && window.sessionStorage.getItem(tid)){
                triggered=window.sessionStorage.getItem(tid);
                triggered = (triggered === "true");
            }
            else{
                var current_percent = Math.floor(Math.random() * 100);
                triggered = IMI.TriggerUtil.evaluateTriggerRuleLogic(current_percent, triggerRule.operator, triggerRule.value);
                if(window.sessionStorage){
                    window.sessionStorage.setItem(tid, triggered);
                }
            }
            if(!triggered && document.location.href.indexOf("im_throttle=true") > -1){
                triggered=true;
                if(window.sessionStorage){
                    window.sessionStorage.setItem(tid, triggered);
                }
            }
            console.log("IMc->userPercentage triggered=" + triggered);
            return triggered;
        };

         IMI.CustomJS = {
            feedback_iframe_id:3535,
            timed_iframe_id:3529,
            customJSisLoaded:true,
            afterInterceptsLoaded : function(){
                var imm = IMI.CustomJS.mods;
                if(this.mods.setFeedbackWidth){
                    this.mods.setFeedbackWidth(372);
                    
                }
                if(this.mods.addCustomStyles){
                    this.mods.addCustomStyles();
                }
                if(this.mods.messageListener){
                    this.mods.messageListener();
                }
                window.IMI.siteTimeSpent = IM_SiteTimeSpent;
                /*
                
                IMI.siteTimeSpent.start();
                */

            },
            triggeredIntercepts:function(){
                if(this.mods.modifyCloseButton){
                    this.mods.modifyCloseButton(IMI.CustomJS.timed_iframe_id);
                    //this.mods.modifyCloseButton(3530);
                    //this.mods.modifyCloseButton(3533);
                    
                }
            },
            afterInterceptsInDom:function(){
                if(this.afterInterceptsInDom_called){
                    return;
                }
                this.afterInterceptsInDom_called=true;
                
                if(this.mods.modifyCloseButton){
                    this.mods.modifyCloseButton(IMI.CustomJS.timed_iframe_id);
                    //this.mods.modifyCloseButton(3530);
                    //this.mods.modifyCloseButton(3533);
                    
                }
               
                if(this.mods.addFeedbackCloseButon){
                    this.mods.addFeedbackCloseButon(3530);
                }
                if(this.mods.addEvents){
                    this.mods.addEvents();
                }
                this.mods.hideIntercept('_im_iframe_overlay__' + IMI.CustomJS.timed_iframe_id);
            },
            trigger:{},
            'mods':{
                showIntercept:function(id){
                    id=id || IMI.CustomJS.lastIntercept;
                    var elem = document.getElementById(id);
                    var isNotFatigued=true;
                    if(window.inmData && window.inmData.userId && IMI.CustomJS.mods.fatigue){
                        
                        isNotFatigued=IMI.CustomJS.mods.fatigue.accountWithinLimit(window.inmData.userId);
                       
                    }
    
                    if(elem && isNotFatigued){
                        //console.log("IM->show intercept");
                        elem.classList.remove("im_hide");
                    }
                    else{
                        //console.log("IM->hide intercept");
                    }
                },
                hideIntercept:function(id){
                    IMI.CustomJS.lastIntercept = id;
                    var elem = document.getElementById(id);
                    
                    if(elem){
                        elem.classList.add("im_hide");
                    }
                },
                hideIntercepts:function(ids){
                    
                    var elem;
                    for(var c=0; c<ids.length; ++c){
                        elem = document.getElementById(ids[c]);

                        if(elem){
                            elem.classList.add("im_hide");
                        }
                    }
                },
                addEvents:function(){
                    var elem = document.querySelector("#_im_feedbackTab_tab__3530");
                    if(elem){
                        elem.addEventListener("mousedown", ()=>{
                        //console.log("IMt->feedback append data");
                            for(var c=0; c<IMI.Intercepts.length; ++c){
                                IMI.InterceptUtil.appendAdditionalDataToURL(IMI.Intercepts[c]);
                            }
                            
                            if(!window.IMI.timerCloseBtn && !document.getElementById("im_int_close_" + IMI.CustomJS.feedback_iframe_id)){
                                window.IMI.timerCloseBtn = setInterval(()=>{
                                    if(document.getElementById("intercept_close__"+ IMI.CustomJS.feedback_iframe_id) && IMI.CustomJS.mods.modifyCloseButton){
                                        IMI.CustomJS.mods.modifyCloseButton( IMI.CustomJS.feedback_iframe_id);
                                        clearInterval(window.IMI.timerCloseBtn);
                                        window.IMI.timerCloseBtn=null;
                                    }
                                },100);
                            }
                        });

                       
                    }
                },
                findIntercept:function(id){
                    var intercept,searchType;
                    
                    if(typeof(id) == 'object'){
                        if(id.id){
                            intercept = id;
                        }
                    }
                    else if(typeof(id) == 'number'){
                        searchType="intercept";
                    }
                    else if(typeof(id) == 'string'){
                        if(Number.isNaN(parseInt(id))){
                            searchType="trigger";
                        }
                        else if(typeof(parseInt(id)) == 'number'){
                            searchType = "intercept";
                            id=parseInt(id);
                        }
                    }
    
                    if(!intercept && id && searchType){
                        for(var z=0; z<IMI.Intercepts.length; ++z){
                            if(searchType == "intercept"){
                                if(IMI.Intercepts[z].id == id){
                                    intercept = IMI.Intercepts[z];
                                    break;
                                }
                            }
                            else if(searchType == "trigger"){
                                if(IMI.Intercepts[z].trigger && IMI.Intercepts[z].trigger.name.toLowerCase() === id.toLowerCase()){
                                    intercept = IMI.Intercepts[z];
                                    break;
                                }
                            }
                        }
                    }
                    return intercept;
                },
                addPageExitTrigger:function(intercept_id, config, callback){
                    console.log("IMc->addPageExitTrigger");
                    console.log(config);
                    config = config || {};
                    IMI.InterceptInfo = IMI.InterceptInfo || {};
    
                    function isInterceptTriggered(interceptId){
                        var isTriggered=false;
                        if(IMI.InterceptInfo[interceptId] && IMI.InterceptInfo[interceptId].intercept_triggered){
                            isTriggered=true;
                        }
                        return isTriggered;
                    }
    
                    function triggerIntercept(intercept){
                        if(isInterceptTriggered(intercept.id)){
                            return;
                        }
                        
                        IMI.InterceptInfo[intercept.id].intercept_triggered=true;
                        
                        window.inmData = window.inmData || {};
                        window.inmData.triggerPoint = config.trigger;
                        IMI.InterceptUtil.appendAdditionalDataToURL(intercept);
                        IMI.InterceptUtil.triggerIntercept.call(IMI.InterceptUtil.triggerIntercept, intercept, new Map);
                        if(typeof(callback)=="function"){
                            callback();
                        }
                        if(IMI.CustomJS.mods.showIntercept){
                            setTimeout(function(){
                                IMI.CustomJS.mods.showIntercept();
                            },5000);
                        }
                        
                    }
                    function mouseOutWindowCheck(intercept,delay){
                        return function(evt){
                           
                            if(isInterceptTriggered(intercept.id)){
                                return;
                            }
                            
                            if(evt && typeof(evt.clientY) !== 'undefined' && intercept){
                                if(evt.clientY < 0){
                                    config.trigger="pageExit";
                                    document.removeEventListener('mouseout', evtMouseOut);
                                    if(delay){
                                        setTimeout(function(){
                                            triggerIntercept(intercept);
                                        },delay)
                                    }
                                    else{
                                        triggerIntercept(intercept);
                                    }
                                }
                            }
                        }
                    }
                    function addMouseOutEvent(intr, skipMouseout){
                        return function(){
                            if(!skipMouseout){
                                document.addEventListener('mouseout', evtMouseOut);
                                //document.addEventListener('mouseout', mouseOutWindowCheck(intr, delay));
                            }
                            else{
                                triggerIntercept(intr);
                            }
                        }
                    }
    
    
                    var page_delay = config.page_delay || .01;
                    page_delay = page_delay * 1000;
                    var trigger_delay = config.trigger_delay || 0;
                    trigger_delay = trigger_delay * 1000;
                    
                    var intercept=IMI.CustomJS.mods.findIntercept(intercept_id);
                    
                    if(intercept){
                        var evtMouseOut = mouseOutWindowCheck(intercept,trigger_delay);
    
                        if(!IMI.InterceptInfo[intercept.id]){
                            IMI.InterceptInfo[intercept.id]={};
                        }
    
                        setTimeout(addMouseOutEvent(intercept, config.skipMouseout, trigger_delay), page_delay);
                    }
                   
                    if(config.addSroll){
                        IMI.CustomJS.mods.addScrollTrigger(intercept_id, config, callback)
                    }
                },
                addScrollTrigger:function(intId, config, callback){
                
                    config = config || {};
                    var pageLoadDelay=config.page_delay||10;
                    var delay = config.delay;
                    
                    IMI.InterceptInfo = IMI.InterceptInfo || {};
    
                    function isInterceptTriggered(interceptId){
                        var isTriggered=false;
                        if(IMI.InterceptInfo[interceptId] && IMI.InterceptInfo[interceptId].intercept_triggered){
                            isTriggered=true;
                        }
                        return isTriggered;
                    }
    
                    function triggerIntercept(intercept){
                        if(isInterceptTriggered(intercept.id)){
                            return;
                        }
                        
                        IMI.InterceptInfo[intercept.id].intercept_triggered=true;
                        
                        
                        IMI.InterceptUtil.appendAdditionalDataToURL(intercept);
                        IMI.InterceptUtil.triggerIntercept.call(IMI.InterceptUtil.triggerIntercept, intercept, new Map);
                        if(typeof(callback)=="function"){
                            callback();
                        }
                        if(IMI.CustomJS.mods.showIntercept){
                            setTimeout(function(){
                                IMI.CustomJS.mods.showIntercept();
                            },5000);
                        }
                        
                    }
                    var skipCookie=false;
                    var scrollSpeed = config.speed || 160;

                    var intercept = IMI.CustomJS.mods.findIntercept(intId);

                    if(!intercept){
                        return;
                    }
                    setTimeout(function() {
                        document.addEventListener("scroll", calcScrollSpeed);
                    }, pageLoadDelay*1000);
                     
                    var direction="top";

                    var lastPosition,newPosition=0;
                    function calcScrollSpeed() {
                    lastPosition = window.scrollY;
                    setTimeout(function() {
                        newPosition = window.scrollY;
                    }, 100);
                    currentSpeed = newPosition - lastPosition;
                        if ((direction == "top" && currentSpeed > scrollSpeed)  || (direction=="bottom" && currentSpeed < scrollSpeed)) {

                            if(!delay){
                                triggerIntercept(intercept);
                            }
                            else{
                                setTimeout(()=>{
                                    triggerIntercept(intercept)
                                },delay);
                            }

                            document.removeEventListener("scroll", calcScrollSpeed);
                        }
                    };
                    
                },
                interceptAction:function(action, int_id){
                    function dispatchEvent(elm, evtType) { if(elm){var evt = null;evtType = evtType || 'click';if(document.createEvent) { evt = document.createEvent('MouseEvents'); if(elm && elm.dispatchEvent && evt && evt.initMouseEvent) { evt.initMouseEvent(evtType,true,true,document.defaultView,1, 0, 0,0,0,false,false,false,false,0,null); elm.dispatchEvent(evt); }} else if (elm[evtType]){elm[evtType]();}}};
                    var feedbackArea, elem, elemAction;
                    var sections = document.getElementsByTagName("section");
                    var visId=0,subVisId=0;
                    if(int_id){
                        for(var c=0; c<IMI.Intercepts.length; ++c){
                            if(IMI.Intercepts[c].id == int_id){
                                if(IMI.Intercepts[c].visual){
                                    visId = IMI.Intercepts[c].visual.id
                                }
                                if(IMI.Intercepts[c].visual.subVisual){
                                    subVisId = IMI.Intercepts[c].visual.subVisual.id
                                }
								break;
                            }
                        }
                    }
                    for(var z=0; z<sections.length; ++z){
                        elemAction=null;
                        if(sections[z].id.indexOf("_im_feedbackTab__") > -1){
                            feedbackArea = sections[z];
                            elem = feedbackArea.getElementsByTagName("sidebar")[0];
                            if(elem && feedbackArea &&  feedbackArea.style.visibility && feedbackArea.style.visibility.toLowerCase().indexOf("visible") > -1 && (!int_id || (int_id && visId && feedbackArea.id.indexOf(visId) > -1))){
                                if(action == "close"){
                                    //embed feedback is open
                                    if(elem.style.right && elem.style.right != "0px"){
                                        elemAction=elem;
                                    }
                                    else if(elem.style.left && elem.style.left != "0px"){
                                        elemAction=elem;
                                    }
                                }
                                else if(action == "open"){
                                    //embed feedback is closed
                                    if(elem.style.right && elem.style.right == "0px"){
                                        elemAction=elem;
                                    }
                                    else if(elem.style.left && elem.style.left == "0px"){
                                        elemAction=elem;
                                    }
                                    else if(!elem.style.right && !elem.style.left){
                                        elemAction=elem;
                                    }
                                }
                            }
                            
                        }
                        else if(sections[z].id.indexOf("_im_iframe_overlay__") > -1){
                            feedbackArea = sections[z];
                            if(feedbackArea){
                                //iframe feedback is open
                                if(action == "close" && feedbackArea.style.visibility && feedbackArea.style.visibility.toLowerCase().indexOf("visible") > -1 && (!int_id || (int_id && subVisId && feedbackArea.id.indexOf(subVisId) > -1))){
                                    elemAction = feedbackArea.querySelector("button.intercept-close");
                                }
                            }
                        }
                        if(elemAction){
                            dispatchEvent(elemAction);
                            break;
                        }
                    }
                },
                messageListener:function(seconds){
                    seconds = seconds || 10;
                    function receivePostMessage(event){
                        var payload;

                        var originIsGood=false;
                        if(event.origin && event.origin.indexOf("inmoment") > -1){
                            originIsGood=true;
                        }
                        if (originIsGood){
                            IMI.CustomJS.log('messengerParent: receivePostMessage');    
                            if(event.data && typeof(event.data)==="string"){
                                try{
                                    payload=JSON.parse(event.data);
                                }
                                catch(e){
    
                                }
                                //console.log(payload);
                                if(payload){
                                    if(payload.message){
                                        //IMI.CustomJS.mods.showIntercept();
                                        if(payload.message=="renderedPage" && IMI.CustomJS.mods.showIntercept){
                                            //setTimeout(function(){
                                                IMI.CustomJS.mods.showIntercept();
                                           // },2000);
                                        }
                                    }
                                    if(payload.messageType == "Survey Close"){
                                        if(IMI.CustomJS.mods.interceptAction){
                                            IMI.CustomJS.mods.interceptAction("close");
                                        }
                                    }
                                    
                                    return true;
                                }
                            }
                        }
                        return false;		
                    }   
                    window.addEventListener("message", receivePostMessage, false);
                },
                trigger:function(triggerName){
                    var intercept;
                    for(var c=0; c<IMI.Intercepts.length; ++c){
                        if(IMI.Intercepts[c].trigger.name == triggerName){
                            intercept=IMI.Intercepts[c];break;
                        }
                    }
                    if(intercept){
                      IMI.InterceptUtil.appendAdditionalDataToURL(intercept);
                      IMI.InterceptUtil.triggerIntercept.call(IMI.InterceptUtil.triggerIntercept, intercept, new Map);

                      setTimeout(function(){
                        IMI.CustomJS.mods.showIntercept();
                      },6000);
                    }
                },
                setFeedbackWidth:function(newFeedbackWidth){
                    var imm = IMI.CustomJS.mods;
                    if(imm.addStyle && IMI.AnimationUtil){
                      //  imm.addStyle("#_im_feedbackTab__1526 section{width:500px !important;}");
                        IMI.AnimationUtil.slideOutReverse = function(obj, displaceLeftBy) {
                            //increase width of feedback tab, default witdh is 319
                            var oldWidth=319,newWidth=newFeedbackWidth,elemSection;
                            if(screen.width < newFeedbackWidth+35){
                                newWidth = oldWidth;
                                newWidth = screen.width-35;
                            }
                            var neutralPos = '0px';
                            var extPos = newWidth + displaceLeftBy +'px';
                            
                            if (obj) {
                                var elem = obj;
                                if (obj.target) {
                                    elem = obj.target;
                                }
    
                                if(elem && elem.parentNode){
                                    elemSection = elem.parentNode.querySelector("section");
                                }
                                //opening
                                if (IMI.AnimationUtil.slideOutStatusReverse === 0) {
                                    elem.style.transition = '0.5s';
                                    elem.style.right = extPos;
                                    IMI.AnimationUtil.slideOutStatusReverse = 1;
                                    if(elemSection){
                                        elemSection.style.width=newWidth + "px";
                                    }
                                    
                                }
                                //closing
                                else {
                                    elem.style.transition = '0.5s';
                                    elem.style.right = neutralPos;
                                    IMI.AnimationUtil.slideOutStatusReverse = 0;
                                    IMI.JSUtil.setInterceptClosedCookie();
                                    if(elemSection){
                                        elemSection.style.width=oldWidth + "px";
                                    }
                                }
                            }
                        }
                    }
                },
                fatigue:{
                    name:"IMI_Fatigue",
                    days:30,
                    type:"cookie",
                    isFatigued:function(interceptId){
                        var ckVal = this.get();
                        var fatigued=false;
                        if(interceptId && ckVal && ckVal.indexOf(interceptId + ";") > -1){
                            fatigued=true;
                        }
                        return fatigued;
                    },
                    set:function(interceptId){
                        var ckVal = this.get();
                        var newVal = "";
                        if(ckVal){
                            if(ckVal.indexOf(interceptId) == -1){
                                newVal = ckVal+=interceptId + ";";
                            }
                        }
                        else{
                            newVal = interceptId + ";";
                            
                        }
                        if(newVal){
                            if(this.type == "cookie"){
                                var days = (this.days) ? this.days * 86400 : null;
                                IMI.CustomJS.mods.setCookie(this.name, newVal, null, days);
                            }
                            else{
                                if(window[this.type]){
                                    window[this.type].setItem(this.name, newVal);
                                }
                            }
                        }
                    },
                    get:function(){
                        var val="";
                        if(this.type == "cookie"){
                            val= IMI.JSUtil.getCookie(this.name);
                        }
                        else{
                            if(window[this.type]){
                                val= window[this.type].getItem(this.name);
                            }
                        }
                        return val;
                    },
                    remove:function(interceptId){
                        var ckVal = this.get();
                        if(ckVal){
                            if(interceptId !== "all" && ckVal.indexOf(interceptId + ";") > -1){
                                ckVal = ckVal.replace(interceptId + ";", "");
                            }
                            if(ckVal){
                                IMI.CustomJS.mods.setCookie(this.name, ckVal, null, this.days * 86400);
                            }
                            else if(interceptId == "all" || !ckVal){
                                IMI.CustomJS.mods.setCookie(this.name, "", null, -1);
                            }
                        }
                    }
                },
                modifyIframe:function(frameIds){
                    var width = window.innerWidth;
                    var height = window.innerHeight;
                    //var iframeWidth = 928;
                   // var iframeHeight = 580;//668
                    var leftPos, topPos;
                    var styles=[];
                    if(width < 720){
                        return;
                    }
                    /*
                    if(iframeWidth < width){
                        leftPos = (width - iframeWidth) / 2;
                        styles.push([
                            "width:" + iframeWidth + "px !important;",
                            "left:" + leftPos + "px !important;"
                        ].join(""));
                    }
                    if(iframeHeight < height){
                        topPos = (height - iframeHeight) / 2;		
                        styles.push([
                            "height:" + iframeHeight + "px !important;",
                            "top:" + topPos + "px !important;"
                        ].join(""));
                    }
                    
                    if(styles.length){
                        var st=[];
                        for(var c=0; c<frameIds.length; ++c){
                            st.push("#_im_iframe_overlay__" + frameIds[c] + " #intercept_section{" + styles.join("") + "}");
                        }
                        IMI.CustomJS.mods.addStyle(st.join(""));
                    }
                    */

                    var st=[],frid;
                    var iframeWidth = 928;
                    var iframeHeight = 702;
                    for(var c=0; c<frameIds.length; ++c){
                        
                        frid = frameIds[c];
                        styles=[];
                        
                        if(iframeWidth < width){
                            leftPos = (width - iframeWidth) / 2;
                            styles.push([
                                "width:" + iframeWidth + "px !important;",
                                "left:" + leftPos + "px !important;"
                            ].join(""));
                        }
                        if(iframeHeight < height){
                            topPos = (height - iframeHeight) / 2;		
                            styles.push([
                                "height:" + iframeHeight + "px !important;",
                                "top:" + topPos + "px !important;"
                            ].join(""));
                        }
                        if(styles.length){
                            st.push("#_im_iframe_overlay__" + frid + " #intercept_section{" + styles.join("") + "}");
                            
                        }
                    }
                    if(st.length){
                        //console.log(st);
                        var css = st.join("");
                        css = css.replace(/#intercept_section/g, ".intercept-section")
                        IMI.CustomJS.mods.addStyle(css);
                    }
                    
                },
                addCustomStyles:function(){
                    var css = `#_im_iframe_overlay__${IMI.CustomJS.timed_iframe_id}.im_iframe_overlay{z-index:2147483647;}
                        #intercept_section__${IMI.CustomJS.timed_iframe_id}{transform:translate(-50%, -50%); top:50% !important; left:50% !important;}
                        #intercept_section__${IMI.CustomJS.timed_iframe_id}{width:90% !important;}
                        
                        
                        @media (min-width:720px){#intercept_section__${IMI.CustomJS.timed_iframe_id}{width:68% !important;}}
                        @media (min-width:1024px){#intercept_section__${IMI.CustomJS.timed_iframe_id}{width:650px !important;}}
                        
                        
                        @media (min-height:800px){#intercept_section__${IMI.CustomJS.timed_iframe_id}{height:528px !important;}}
                        @media (max-width:480px){#intercept_section__${IMI.CustomJS.timed_iframe_id}{height:68% !important;}}
                        #_im_iframe_overlay__${IMI.CustomJS.feedback_iframe_id}.im_iframe_overlay{z-index:2147483647;}
                        #intercept_section__${IMI.CustomJS.feedback_iframe_id}{transform:translate(-50%, -50%); top:50% !important; left:50% !important;}
                        #intercept_section__${IMI.CustomJS.feedback_iframe_id}{width:580px !important; height:692px !important;}
                        @media (max-width:624px){#intercept_section__${IMI.CustomJS.feedback_iframe_id}{width:90% !important;}}
                        @media (max-height:720px){#intercept_section__${IMI.CustomJS.feedback_iframe_id}{height:90% !important;}}

                        #_im_feedbackTab_tab__3530{top:auto !important; bottom:225px !important; z-index: 9999999 !important;}
                        #_im_feedbackTab__3530 section{ height:658px !important; xxheight:60% !important; box-shadow:2px 2px 20px rgb(0 0 0 / 20%);}
                        X.im_hide{display:none !important;}
                        
                        .im_iframe_overlay .iframe-tab-spinner{background:white !important; opacity:1 !Important;}
                        .im_hide .iframe-tab-spinner{display:block !important;}
                    `;

                    IMI.CustomJS.mods.addStyle(css);
                },
                addFeedbackCloseButon:function(){
                
                    function _getCloseStyle(vis_id){
                        var styles=[
                            '#im_int_close_' + vis_id + '{',
                                'top: 10px;',
                                'right: 30px;',
                                'position: absolute;',
                                'cursor:pointer;',
                                'z-index:100001;',
                            '}',
                            '#im_int_close_' + vis_id + ':after {',
                               "content: url(\"data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg'  viewBox='0 0 37 37'%3E%3Cpath fill='%23000' d='M36.533 3.533L33 0 18.267 14.733 3.533 0 0 3.533l14.733 14.734L0 33l3.533 3.533L18.267 21.8 33 36.533 36.533 33 21.8 18.267z' /%3E%3C/svg%3E\");",
                                'width: .875rem;',
                                'height: .875rem;',
                                'display: inline-block',
                            '}',
                        ''].join("");
                        return styles;
                    }
                    function _addCloseElem(vis_id){
                        var sp = document.getElementById("im_int_close_" + vis_id);
                        if(sp){
                            return;
                        }
                        sp=document.createElement('div');
                        sp.id = "im_int_close_" + vis_id;
                        sp.className="im_closeLink";
                        sp.title="Close Survey";
    
                        var sec = document.querySelector('#_im_feedbackTab__' + vis_id + ' section');
                        if(sec){
                            sec.insertBefore(sp,sec.firstChild);
                            ///sec.appendChild(sp);
                        }
                        else{
                            sec = document.querySelector("#_im_iframe_overlay__" + vis_id + ' section');
                            if(sec){
                                sec.insertBefore(sp,sec.firstChild);
                                var btn = sec.querySelector("#intercept_close");
                                if(!btn){
                                    btn = sec.querySelector(".intercept-close");
                                }
                                if(btn){
                                    btn.style.display="none";
                                }
                            }
                        }
                    }
                    var id;
                    var arStyles=[];
                    var arSections = document.querySelectorAll("section");
                    for(var h=0; h<arSections.length; ++h){
                        if(arSections[h].id && arSections[h].id.indexOf("_im") == 0){
                            id = arSections[h].id.substring(arSections[h].id.indexOf("__")+2, arSections[h].id.length);
                            if(id){
                                arStyles.push(_getCloseStyle(id));
                                _addCloseElem(id);
                            }
                        }
                    }
                    
                    if(arStyles.length){
                        IMI.CustomJS.mods.addStyle(arStyles.join(""));
                    }
                    
                },

                modifyCloseButton:function(visId){
                    function dispatchEvent(elm, evtType) { if(elm){var evt = null;evtType = evtType || 'click';if(document.createEvent) { evt = document.createEvent('MouseEvents'); if(elm && elm.dispatchEvent && evt && evt.initMouseEvent) { evt.initMouseEvent(evtType,true,true,document.defaultView,1, 0, 0,0,0,false,false,false,false,0,null); elm.dispatchEvent(evt); }} else if (elm[evtType]){elm[evtType]();}}};
                    //console.log("IMc->modifyCloseButton")
                    var existingBtn = document.getElementById("im_int_close_" + visId);
                    if(existingBtn){
                        return;
                    }
                    var styles=[
                    '#im_int_close_' + visId + '{',
                        'top: 10px;',
                        'right: 30px;',
                        'position: absolute;',
                        'cursor:pointer;',
                        'z-index:100001;',
                    '}',
                    '#im_int_close_' + visId + ':after {',
                       "content: url(\"data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg'  viewBox='0 0 37 37'%3E%3Cpath fill='%23000' d='M36.533 3.533L33 0 18.267 14.733 3.533 0 0 3.533l14.733 14.734L0 33l3.533 3.533L18.267 21.8 33 36.533 36.533 33 21.8 18.267z' /%3E%3C/svg%3E\");",
                        'width: .875rem;',
                        'height: .875rem;',
                        'display: inline-block',
                    '}',
                    '#im_int_close_' + visId + ':focus {outline:none !important;}',
                    ''].join("");
                    
                    var btnClose = document.querySelector("#_im_iframe_overlay__" + visId + " #intercept_close");
                    if(!btnClose){
                        btnClose =  document.querySelector("#_im_iframe_overlay__" + visId + " .intercept-close");
                    }

                   // console.log(btnClose);
                    if(btnClose){
                        IMI.CustomJS.mods.addStyle(styles);
                        btnClose.style.display="none";
                        var newBtn = document.createElement("a");
                        newBtn.id="im_int_close_" + visId;
                        newBtn.title="Close Survey";
                        newBtn.href="javascript:void(0);"
                        btnClose.parentNode.insertBefore(newBtn,btnClose);
                        newBtn.addEventListener("click", ()=>{
                            dispatchEvent(btnClose);
                        });
                    }
                },

                setCookie : function(n, v, d, e) {
                    var de = new Date;
                    de.setTime(de.getTime() + e * 1000);
                    document.cookie = n + "=" + escape(v) + ((e == null) ? "" : ("; expires=" + de.toGMTString())) + "; path=/" + ((d == null) ? "" : (";domain=" + d));
                },
                
                addCustomTrigger:function(){
                    //client calls IMI.triggerSurvey when they want to manually trigger a survey.  
                    window.IMI.triggerSurvey = function(surveyType){
                        var intId,intercept;
                        //window.IMI.customIntercepts is an object set within the trigger
                        if(window.IMI.customIntercepts && window.IMI.customIntercepts[surveyType] && window.IMI.customIntercepts[surveyType].intercept_id){
                            intId = window.IMI.customIntercepts[surveyType].intercept_id;
                        }
                        if(intId){
                            for(var c=0; c<IMI.Intercepts.length; ++c){
                                if(IMI.Intercepts[c].id == intId){
                                    intercept = IMI.Intercepts[c];break;
                                }
                            }
                        }
                        if(intercept){
                            IMI.InterceptUtil.appendAdditionalDataToURL(intercept);
                            IMI.InterceptUtil.triggerIntercept.call(IMI.InterceptUtil.triggerIntercept, intercept, new Map);
                            if(IMI.CustomJS.trigger && IMI.CustomJS.trigger[intercept.id]){
                                IMI.CustomJS.trigger[intercept.id]();
                            }
                        }
                    }
                },
                browserType:(function(){
                    var ua=navigator.userAgent, orient=(typeof window.orientation !== "undefined");
                    if(!!ua.match(/Pixel(.*)Chrome\/[.0-9].*Mobile/i)) return 'ChromePixel';
                    else if(!!ua.match(/Android(.*)SamsungBrowser\/[.0-9].*Mobile/i)) return 'SamsungAndroid';
                    else if(!!ua.match(/Android(.*)UCBrowser\/[.0-9].*Mobile/i)) return 'UCBrowserAndroid';
                    else if(!!ua.match(/Android(.*)Chrome\/[.0-9].*Mobile/i)) return 'ChromeAndroid';
                    else if(!!ua.match(/Android(.*)Firefox\/[.0-9]/i)) return 'FirefoxAndroid';
                    else if(!!ua.match(/Android(.*)Chrome\/[.0-9]/i)) return 'ChromeAndroidTablet';
                    else if(!!ua.match(/\(iPad(.*)CriOS/i)) return 'Chrome_iPad';
                    else if(!!ua.match(/\(iPhone(.*)CriOS/i)) return 'Chrome_iPhone';
                    else if(!!ua.match(/\(iPad(.*)Safari/i)) return 'Safari_iPad';
                    else if(!!ua.match(/\(iPhone(.*)Safari/i)) return 'Safari_iPhone';
                    else if(!!ua.match(/\(iPad(.*)FxiOS/i)) return 'Firefox_iPad';
                    else if(!!ua.match(/\(iPhone(.*)FxiOS/i)) return 'Firefox_iPhone';
                    else if(!!ua.match(/\(Macintosh(.*)FxiOS/i)) return 'Firefox_iPad';
                    else if(!!ua.match(/FxiOS\//i)) return 'Firefox_iPad';             
                    else if(!!ua.match(/\(Macintosh(.*)FxiOS/i)) return 'Chrome_iPad';             
                    else if(!!ua.match(/edg\//i)) return 'ChrEdge';             
                    else if(!!ua.match(/edge/i)) return 'Edge';             
                    else if(!!ua.match(/opr/i)) return 'Opera';                    
                    else if(!!ua.match(/Chrome/i)) return 'Chrome';
                    else if(!!ua.match(/Safari/i)&&orient) return 'Safari_iPad';
                    else if(!!ua.match(/Safari/i)) return 'Safari';
                    else if(!!ua.match(/Firefox/i)) return 'Firefox';             
                    else if(!!ua.match(/MSIE|rv\:/i)) return 'IE';             
                    else if(!!ua.match(/OP/)) return 'Opera';             
                    else return 'unknown';             
                })(), 
                addStyle:function(css){
                    var head = document.getElementsByTagName("head")[0];
                    var style = document.createElement("style");
                    style.type = 'text/css';
                    style.appendChild(document.createTextNode(css));
                    if(head){
                        head.appendChild(style);
                    }
                }
            },
            log:function(str, xtra, showLog){
                if(IMI.CustomJS.debug || showLog){
                    if(xtra){console.log('%c'+str, xtra);}
                    else{
                        if(typeof(str)=="string"){console.log('%c'+str,'color: #E0E0B6; background: #0137A3;');}
                        else {console.log('Object value of:',str);}
                    }
                } 
            }            	
        }
       
    })();
}


/* BEGIN IM_SiteTimeSpent */
//ver 2.75
var IM_SiteTimeSpent = (function(){
    var data;
    var VARS={
        started:false,
        timing_info:[],
        timer_count:0,
        setTimeout_handle:null,
        time_elapsed:0,
        stop_timer:false,
        time_triggers:[],
        events:[]
    }
    var OPTIONS={
        name:"IM_SiteTimeSpent",
        storage_type:'sessionStorage',
        storage_name:'IMI_SiteTimeSpent',
        reevaluate:false,
        interval:2000
    }
    function on(arg1, arg2){
        var id, callback;
        if(arg1 && arg2){
            id = arg1;
            callback = arg2;
        }
        else if(arg1){
            callback = arg1;
            id = OPTIONS.event_name;
        }
        if(id && callback){
            VARS.events.push({
                'id':id,
                'callback':callback
            });
        }
    }
    function emit(id, info){
        if(window.IMI && IMI.events && OPTIONS.event_name){
            IMI.events.emit(OPTIONS.event_name, info);
        }
        for(var c=0; c<VARS.events.length; ++c){
            if(id && VARS.events[c].id == id && typeof(VARS.events[c].callback)=='function'){
                VARS.events[c].callback.call(this,info);
            }
            if(VARS.events[c].id == OPTIONS.event_name){
                VARS.events[c].callback.call(this,info);
            }
        }
        
    }


    //get local/session storage value
    function getSavedData(){
        var mydata=null;
        if(window[OPTIONS.storage_type]){
            mydata = window[OPTIONS.storage_type].getItem(OPTIONS.storage_name);
        }
        if(mydata){
            mydata = JSON.parse(mydata);
        }
        if(!mydata){
            mydata={};
        }
        return mydata;
    }
    function clear(){
        if(window[OPTIONS.storage_type]){
            window[OPTIONS.storage_type].removeItem(OPTIONS.storage_name);
            data={};
        }
    }
    //save local/sesssion storage value
    function saveData(mydata){
        if(mydata){
            try{
                if(VARS.time_triggers.length){console.log(`IM->Time on Site->${mydata.time_elapsed} seconds have elapsed, triggering after [${VARS.time_triggers.join(",")}] seconds`);}
                if(window[OPTIONS.storage_type]){
                    mydata = JSON.stringify(mydata);
                    window[OPTIONS.storage_type].setItem(OPTIONS.storage_name, mydata);
                }
            }
            catch(err){
                //console.log(err);
            }
            
        }
    }

    function calculate_time_elapsed(){
        if(VARS.stop_timer){
            clearTimeout(VARS.setTimeout_handle);
            return;
        }
        var timePassed=((OPTIONS.interval) / 1000);
        //data = getSavedData();
        if(typeof data.time_elapsed == "undefined"){
            data.time_elapsed = 0;
            
        }
        
        VARS.time_elapsed = data.time_elapsed += timePassed;
        //saveData(data);     
          
        var time_triggered = checkIfTimeTriggered();
        if(time_triggered){
            emit("time_elapsed",{elapsed:VARS.time_elapsed, trigger:time_triggered});
            if(OPTIONS.reevaluate && window.IMI){
                IMI.InterceptUtil.reevaluateIntercepts(!1,!0);
            }
        }
        timer();
    }
    function timer(){
        if(document.location.search.indexOf(OPTIONS.name +"_erase") > -1){
            VARS.stop_timer=true;
            saveData({});
            data={};
        }
        if(VARS.setTimeout_handle != null){
            clearTimeout(VARS.setTimeout_handle);
        }
        if(!VARS.stop_timer){
            VARS.setTimeout_handle = setTimeout(calculate_time_elapsed, OPTIONS.interval);
        }
    }
    function stop(){
        VARS.stop_timer=true;
    }
    function checkIfTimeTriggered(){
        var isTriggered=false;
        for(var c=0; c<VARS.time_triggers.length; ++c){
            if(VARS.time_elapsed >= VARS.time_triggers[c]){
                isTriggered=VARS.time_triggers[c];
                break;
            }
        }
        
        return isTriggered;
    }

    function changeDefaultOptions(config){
        if(config){
            for(var name in config){
                if(typeof(OPTIONS[name]) != 'undefined'){
                    OPTIONS[name] = config[name];
                }
            }
        }
    }
    function remove(time){
        VARS.time_triggers = VARS.time_triggers.filter((ttrig)=>{
            return time !== ttrig;
        });
    }
    function getTimeElapsed(){
        return VARS.time_elapsed;
    }
    function start(triggerTime){
        if(triggerTime){
            VARS.time_triggers.push(triggerTime);
        }
        if(VARS.started){
            return VARS.time_elapsed;
        }
        data = getSavedData();
       
        if(!data){
            data={};
        }
        if(typeof data.time_elapsed == "undefined"){
            data.time_elapsed=0;
        }
        
        saveData(data);
        VARS.time_elapsed = parseInt(data.time_elapsed);

        if(!VARS.started){
            VARS.started=true;
            timer();


            VARS.interval = setInterval(()=>{
                if(VARS.stop_timer){
                    clearInterval(VARS.interval);
                    VARS.interval = null;
                    return;
                }
                saveData(data);
            },10000);
            window.addEventListener("beforeunload", ()=>{
                saveData(data);
                if(VARS.interval){
                    clearInterval(VARS.interval);
                }
            });
            
            
        }


        return VARS.time_elapsed;
    }
    return {
        on:on,
        emit:emit,
        getSavedData:getSavedData,
        saveData:saveData,
        changeDefaultOptions:changeDefaultOptions,
        start:start,
        stop:stop,
        clear:clear,
        timer:timer,
        remove:remove,
        getTimeElapsed:getTimeElapsed,
        checkIfTimeTriggered:checkIfTimeTriggered
    };
}());


/* END IM_SiteTimeSpent */