




    window.rzdApp = window.rzdApp || {};

    rzdApp.FeatureDetector = function() {};

    rzdApp.FeatureDetector.isSafari = (window.navigator.userAgent.indexOf('Safari') !== -1 && window.navigator.userAgent.indexOf('Chrome') === -1 && window.navigator.userAgent.indexOf('Firefox') === -1);
    rzdApp.FeatureDetector.supportedFeatures = ['iframe-resize', 'embedded-cart', 'unified-modal'];

    rzdApp.FeatureDetector.detectFeature = function _detectFeature(feature) {
        var existingScript = null;
        var script = null;

        var scriptId = 'rzd-'+ feature;
        script = document.createElement('script');
        script.id = scriptId;
        script.defer = true;

        existingScript = document.querySelector('#' + scriptId);
        if (existingScript) {
            return true;
        }

        var rzdIframes =  [].filter.call(document.querySelectorAll('iframe'), function(iframe) {
            return iframe.className.indexOf('rezdy') !== -1 || iframe.src.indexOf('rezdy.com') !== -1;
        });
        /* Check for features to activate */
        switch(feature) {
            case 'iframe-resize':
                script.innerText = "        var rzdResizeIframe = function _rzdResizeIframe(iframe) {"+
"          var rzdFindPos = function _findPos(obj) {"+
"            var curleft = 0;"+
"            var curtop = 0;"+
"            if (obj.offsetParent) {"+
"                do {"+
"                    curleft += obj.offsetLeft;"+
"                    curtop += obj.offsetTop;"+
"                } while (obj = obj.offsetParent);"+
"            }"+
"            return {x: curleft, y: curtop};"+
"          };"+
""+
"           try {"+
"                iFrameResize({"+
"                    checkOrigin: false,"+
"                    log: false,"+
"                    enablePublicMethods: false,"+
"                    heightCalculationMethod: 'lowestElement',"+
"                    messageCallback: function(data) {"+
"                        if (data.message.type === 'scrollToTop') {"+
""+
"                            /*See https://github.com/jquery/jquery/blob/master/src/offset.js#L74*/"+
"                            var getOffset = function _offset(elem) {"+
"                                if ( !elem.getClientRects().length ) {"+
"                                    return { top: 0, left: 0 };"+
"                                }"+
""+
"                                var rect = elem.getBoundingClientRect();"+
"                                var win = elem.ownerDocument.defaultView;"+
"                                return {"+
"                                    top: rect.top + win.pageYOffset,"+
"                                    left: rect.left + win.pageXOffset"+
"                                };"+
"                            };"+
"                            window.scrollTo(0, getOffset(data.iframe).top);"+
"                        }"+
"                    },"+
"                    resizedCallback: function(messageData){  /* Callback fn when resize is received*/"+
"                        var iframePosition = rzdFindPos(document.getElementById(messageData.id));"+
""+
"                        if (typeof iframePosition !== 'undefined') {"+
"                            var iframeBottomPosition = iframePosition.y + parseFloat(messageData.height);"+
""+
"                            if(window.pageYOffset > iframeBottomPosition) {"+
"                                window.scrollTo(0, iframePosition.y);"+
"                            }"+
"                        }"+
"                    },"+
"                }, iframe);"+
"            } catch (error) {"+
"              /** iFrameResize throwing an error might be because existing outdated resizer is on the page */"+
"              rzdApp.hasError = true;"+
"              console.error(error);"+
"            }"+
"        };"+
""+
"        /**"+
"        * use event delegation to resize async loaded iframes"+
"        */"+
"        var iframeResizeHandler = function _iframeResizeHandler(event) {"+
"            if (event.target && event.target.matches('iframe.rezdy') || event.target.src.indexOf('rezdy.com') !== -1) {"+
"              rzdResizeIframe(event.target);"+
"            }"+
"        };"+
"        document.removeEventListener('load', iframeResizeHandler);"+
"        document.addEventListener('load', iframeResizeHandler);"+
""+
"        if (!document.querySelector('#rzd-iframe-resizer')) {"+
""+
"            var rzdIframeResizer = document.createElement('script');"+
"            rzdIframeResizer.id = 'rzd-iframe-resizer';"+
"            rzdIframeResizer.defer = true;"+
"            rzdIframeResizer.addEventListener('load',function() {"+
"                rzdApp.iFrameResize = function(){};"+
"                rzdApp.iFrameResize.prototype = window.iFrameResize.prototype;"+
"                /*Resize any existing Iframes*/"+
"                [].forEach.call(document.querySelectorAll('iframe'), function(iframe) {"+
"                  if (iframe.src.indexOf('rezdy.com') !== -1 || iframe.className.indexOf('rezdy') !== -1) {"+
"                    rzdResizeIframe(iframe);"+
"                    iframe.addEventListener('load', function(event) {"+
"                        /*If the error has been triggered before iframe is done loading... don't send health check*/"+
"                        if (!rzdApp.hasError) {"+
"                          event.target.contentWindow.postMessage('rzd_plugin_js_loaded', '*');"+
"                        }"+
"                        event.target.contentWindow.postMessage('CUSTOMER_URL=' + window.location.href, '*');"+
"                    });"+
"                  }"+
"                });"+
"            });"+
"            rzdIframeResizer.src = 'https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.6.2/iframeResizer.min.js';"+
""+
"            document.body.append(rzdIframeResizer);"+
"        }"+
"";
            break;
            case 'embedded-cart':
                if (document.querySelector('#rezdy-embedded-cart')) {
                    script.innerText = "    window.rzdApp = window.rzdApp || {};"+
"    rzdApp.embeddedCart = rzdApp.embeddedCart || {};"+
""+
"    rzdApp.embeddedCart.open = function _openCart(event) {"+
"       window.postMessage({url: window.rezdyCartLink + '?iframe=1', data: '', type: 'rezdy_open_in_modal'}, '*');"+
"    };"+
""+
"    rzdApp.embeddedCart.update = function _updateCartQty() {"+
"        var ajaxUrl = 'https://tanganyikacoastalcampsite95.rezdy.com/ajax';"+
"        var cart = document.querySelector('#rezdy-embedded-cart');"+
"        var cartCount = cart.querySelector('.rezdy-cart-count');"+
"        var cartLabel= cart.querySelector('.rezdy-cart');"+
"        var cartLoading = cart.querySelector('.rezdy-cart-loading');"+
"        var cartEmpty = cart.querySelector('.rezdy-cart-empty');"+
""+
"        var numberOfItems = 0;"+
""+
"        fetchJsonp(ajaxUrl + '?method=cartsize&callback=callback')"+
"        .then(function(json) { return json.json(); })"+
"        .then(function (response) {"+
"          if (response.length) {"+
"            numberOfItems = parseInt(response[0], 10);"+
"          }"+
""+
"          if(numberOfItems >= 1) {"+
""+
"            cartCount.innerText = numberOfItems;"+
"            if (cartCount.classList.contains('hidden')) {"+
"              cartCount.classList.remove('hidden');"+
"            }"+
""+
"            if(cartLabel.classList.contains('hidden')) {"+
"              cartLabel.classList.remove('hidden');"+
"            }"+
""+
"            if (!cartLoading.classList.contains('hidden')) {"+
"              cartLoading.classList.add('hidden');"+
"            }"+
""+
"            if (!cartEmpty.classList.contains('hidden')) {"+
"              cartEmpty.classList.add('hidden');"+
"            }"+
""+
"          } else {"+
"            if (!cartCount.classList.contains('hidden')) {"+
"              cartCount.classList.add('hidden');"+
"            }"+
""+
"            if(!cartLabel.classList.contains('hidden')) {"+
"              cartLabel.classList.add('hidden');"+
"            }"+
""+
"            if (!cartLoading.classList.contains('hidden')) {"+
"              cartLoading.classList.add('hidden');"+
"            }"+
""+
"            if (cartEmpty.classList.contains('hidden')) {"+
"              cartEmpty.classList.remove('hidden');"+
"            }"+
"          }"+
"        })"+
"        .catch(function(){"+
"          if (!cartCount.classList.contains('hidden')) {"+
"              cartCount.classList.add('hidden');"+
"            }"+
""+
"          if(!cartLabel.classList.contains('hidden')) {"+
"              cartLabel.classList.add('hidden');"+
"            }"+
""+
"            if (cartLoading.classList.contains('hidden')) {"+
"              cartLoading.classList.remove('hidden');"+
"            }"+
""+
"            if (!cartEmpty.classList.contains('hidden')) {"+
"              cartEmpty.classList.add('hidden');"+
"            }"+
"        });"+
"    };"+
""+
"    rzdApp.embeddedCart.init = function _embeddedCart() {"+
"      var cart = document.querySelector('#rezdy-embedded-cart');"+
""+
"      if (!cart) { return; }"+
"      cart.removeEventListener('click', rzdApp.embeddedCart.open);"+
"      cart.addEventListener('click', rzdApp.embeddedCart.open);"+
""+
"      rzdApp.embeddedCart.update();"+
"      [].forEach.call(document.querySelectorAll('iframe.rezdy'), function (iframe) {"+
"        iframe.addEventListener('load', rzdApp.embeddedCart.update);"+
"      });"+
"    };"+
""+
"    rzdApp.embeddedCart.shutdown = function _shutdown() {"+
"      document.removeEventListener('click', rzdApp.embeddedCart.open);"+
""+
"      [].forEach.call(document.querySelectorAll('iframe'), function (iframe) {"+
""+
"        if (iframe.src.indexOf('rezdy.com') !== -1 || iframe.className.indexOf('rezdy') !== -1) {"+
"            iframe.removeEventListener('load', rzdApp.embeddedCart.update);"+
"        }"+
"      });"+
""+
"      document.querySelector('#rezdy-embedded-cart').onclick = function() {"+
"        window.location.href = window.rezdyCartLink;"+
"      };"+
"    };"+
""+
"    if(!document.querySelector('#rzd-fetch-jsonp')) {"+
"      var script = document.createElement('script');"+
"      script.id = 'rzd-fetch-jsonp';"+
"      script.defer = true;"+
"      script.addEventListener('load', rzdApp.embeddedCart.init);"+
""+
"      script.src = 'https://cdnjs.cloudflare.com/ajax/libs/fetch-jsonp/1.1.3/fetch-jsonp.min.js';"+
""+
"      document.body.append(script);"+
"    } else {"+
"      rzdApp.embeddedCart.init();"+
"    }";
                }

            break;
            case 'unified-modal':

                if (!document.querySelector('#rzd-modal-css')) {
                  var rzdModalCss = document.createElement('link');
                  rzdModalCss.id = 'rzd-modal-css';
                  rzdModalCss.rel ='stylesheet';
                  rzdModalCss.type = 'text/css';
                  rzdModalCss.href = 'data:text/css;base64,LnJ6ZC1tb2RhbHsKICAgIHBvc2l0aW9uOmZpeGVkOwogICAgdG9wOjA7CiAgICByaWdodDowOwogICAgYm90dG9tOjA7CiAgICBsZWZ0OjA7CiAgICB0ZXh0LWFsaWduOmxlZnQ7CiAgICBiYWNrZ3JvdW5kOnJnYmEoMCwwLDAsLjgpOwogICAgdHJhbnNpdGlvbjpvcGFjaXR5IC4yNXMgZWFzZTsKICAgIG92ZXJmbG93LXk6YXV0bwp9Ci5yemQtbW9kYWxfX2JnewogICAgcG9zaXRpb246YWJzb2x1dGU7CiAgICB0b3A6MDsKICAgIHJpZ2h0OjA7CiAgICBib3R0b206MDsKICAgIGxlZnQ6MDsKICAgIGN1cnNvcjpwb2ludGVyCn0KLnJ6ZC1tb2RhbHsKICAgIHotaW5kZXg6OTk5OTk5OTk5OTsKICAgIG9wYWNpdHk6MTsKICAgIHZpc2liaWxpdHk6dmlzaWJsZQp9Ci5yemQtbW9kYWxfX2lubmVyewogICAgdHJhbnNpdGlvbjp0b3AgLjI1cyBlYXNlOwogICAgcG9zaXRpb246YWJzb2x1dGU7CiAgICB0b3A6NDBweDsKICAgIHJpZ2h0OjA7CiAgICBsZWZ0OjA7CiAgICBtYXJnaW46YXV0bzsKICAgIGJhY2tncm91bmQtY29sb3I6I2ZmZjsKICAgIGJvcmRlci1yYWRpdXM6NXB4OwogICAgbWF4LXdpZHRoOjEwMjBweDsKICAgIHdpZHRoOjEwMCU7CiAgICBoZWlnaHQ6Y2FsYygxMDB2aCAtIDEwMHB4KTsKfQoucnpkLW1vZGFsX19jbG9zZXsKICAgIHBvc2l0aW9uOmFic29sdXRlOwogICAgdG9wOjA7CiAgICByaWdodDowOwogICAgZGlzcGxheTpibG9jazsKICAgICBoZWlnaHQ6MjRweDsKICAgIHdpZHRoOjQwcHg7CiAgICBsaW5lLWhlaWdodDoyNHB4OwogICAgdGV4dC1hbGlnbjpjZW50ZXI7CiAgICBmb250LXNpemU6MjBweDsKICAgIG1hcmdpbjowOwogICAgYmFja2dyb3VuZDpyZ2JhKDAsMCwwLC43NSk7CiAgICBjb2xvcjojZmZmIWltcG9ydGFudDsKICAgIHBhZGRpbmc6MDsKICAgIGJvcmRlci1yYWRpdXM6MCAwIDAgM3B4OwogICAgYm9yZGVyOm5vbmU7CiAgICBjdXJzb3I6cG9pbnRlcjsKICAgIHotaW5kZXg6MTA2MAp9Ci5yemQtbW9kYWxfX2Nsb3NlIHNwYW57CiAgICBjb2xvcjojZmZmIWltcG9ydGFudAp9Ci5yemQtbW9kYWxfX2xvYWRlcnsKICAgIGRpc3BsYXk6aW5saW5lLWJsb2NrOwogICAgcG9zaXRpb246cmVsYXRpdmU7CiAgICB0b3A6NTAlOwogICAgbGVmdDo1MCU7CiAgICB3aWR0aDo2NHB4OwogICAgaGVpZ2h0OjY0cHgKfQoucnpkLW1vZGFsX19sb2FkZXIgZGl2ewogICAgYm94LXNpemluZzpib3JkZXItYm94OwogICAgZGlzcGxheTpibG9jazsKICAgIHBvc2l0aW9uOmFic29sdXRlOwogICAgd2lkdGg6NTFweDsKICAgIGhlaWdodDo1MXB4OwogICAgbWFyZ2luOjZweDsKICAgIGJvcmRlcjo2cHggc29saWQgI2ZmZjsKICAgIGJvcmRlci1yYWRpdXM6NTAlOwogICAgYW5pbWF0aW9uOnJ6ZC1sb2FkZXIgMS4ycyBjdWJpYy1iZXppZXIoLjUsMCwuNSwxKSBpbmZpbml0ZTsKICAgIGJvcmRlci1jb2xvcjojZmZmIHRyYW5zcGFyZW50IHRyYW5zcGFyZW50Cn0KLnJ6ZC1tb2RhbF9fbG9hZGVyIGRpdjpudGgtY2hpbGQoMSl7CiAgICBhbmltYXRpb24tZGVsYXk6LS40NXMKfQoucnpkLW1vZGFsX19sb2FkZXIgZGl2Om50aC1jaGlsZCgyKXsKICAgIGFuaW1hdGlvbi1kZWxheTotLjNzCn0KLnJ6ZC1tb2RhbF9fbG9hZGVyIGRpdjpudGgtY2hpbGQoMyl7CiAgICBhbmltYXRpb24tZGVsYXk6LS4xNXMKfQpAa2V5ZnJhbWVzIHJ6ZC1sb2FkZXJ7CiAgICAwJXsKICAgICAgICB0cmFuc2Zvcm06cm90YXRlKDApCiAgICB9CiAgICAxMDAlewogICAgICAgIHRyYW5zZm9ybTpyb3RhdGUoMzYwZGVnKQogICAgfQp9CkBtZWRpYSBzY3JlZW4gYW5kIChtYXgtd2lkdGg6NzY4cHgpewogICAgLnJ6ZC1tb2RhbF9faW5uZXJ7CiAgICAgICAgd2lkdGg6OTAlOwogICAgICAgIGhlaWdodDo5MCU7CiAgICAgICAgYm94LXNpemluZzpib3JkZXItYm94OwogICAgfQp9';
                  document.head.append(rzdModalCss);
                }

                script.innerText = "    window.rzdApp = window.rzdApp || {};"+
"    rzdApp.unifiedModal = rzdApp.unifiedModal || {};"+
"    rzdApp.unifiedModal.currentBodyStyle = document.body.style;"+
"    rzdApp.unifiedModal.currentHtmlStyle = document.documentElement.style;"+
""+
"    rzdApp.unifiedModal.init = function _init() {"+
""+
"        window.removeEventListener('message', rzdApp.unifiedModal.slickCloseHandler);"+
"        window.addEventListener('message', rzdApp.unifiedModal.slickCloseHandler);"+
""+
"        window.removeEventListener('keydown', rzdApp.unifiedModal.escapeHandler);"+
"        window.addEventListener('keydown', rzdApp.unifiedModal.escapeHandler);"+
""+
"        document.removeEventListener('click', rzdApp.unifiedModal.simpleModalHandler);"+
"        document.addEventListener('click', rzdApp.unifiedModal.simpleModalHandler);"+
""+
"        var mobileRegEx = new RegExp('mobi', 'i');"+
"        var userAgent = window.navigator.userAgent;"+
"        if (mobileRegEx.test(userAgent) ||  rzdApp.FeatureDetector.isSafari) {"+
"          document.removeEventListener('click', rzdApp.unifiedModal.simpleModalHandler);"+
"        }"+
""+
"        /*ensure the previous message handler is replaced*/"+
"        window.removeEventListener('message', rzdApp.unifiedModal.openOnMessage);"+
"        window.addEventListener('message', rzdApp.unifiedModal.openOnMessage);"+
"        if (window.top !== window) {"+
"            rzdApp.hasError = true;"+
"            throw new Error('This script should not be embedded inside an iframe.');"+
"        }"+
"    };"+
""+
"    rzdApp.unifiedModal.releaseTheLock = function _releaseTheLock() {"+
"      var iframes = [].filter.call(document.querySelectorAll('iframe'), function(iframe) {"+
"          return iframe.className.indexOf('rezdy') !== -1 || iframe.src.indexOf('rezdy.com');"+
"      });"+
"      if (iframes.length) {"+
"         [].forEach.call(iframes, function(iframe){"+
"           iframe.contentWindow.postMessage('rezdy_release_the_lock', '*');"+
"         });"+
"      }"+
"    };"+
""+
"    rzdApp.unifiedModal.cleanupHandler = function cleanupHandler(event) {"+
"      if (typeof event !== 'undefined') {"+
"          event.stopPropagation();"+
"          event.preventDefault();"+
"      }"+
""+
"      var existingModal = document.querySelector('#rzd-modal');"+
"      if (existingModal && existingModal.parentNode) {"+
"        var existingIFrame = existingModal.querySelector('iframe');"+
"         if (existingIFrame && existingIFrame.iFrameResizer) {"+
"           existingIFrame.iFrameResizer.close();"+
"         }"+
"         existingModal.remove();"+
"      }"+
""+
"      document.body.style = rzdApp.unifiedModal.currentBodyStyle;"+
"      document.documentElement.style = rzdApp.unifiedModal.currentHtmlStyle;"+
""+
"      /** Ugly workaround for IE11 … Couldn't find a better way*/"+
"      try {"+
"        if (document.body.style instanceof MSStyleCSSProperties) {"+
"          document.body.setAttribute('style', document.body.getAttribute('style').replace('-ms-overflow-y: hidden;'));"+
"          document.documentElement.setAttribute('style', document.documentElement.getAttribute('style').replace('-ms-overflow-y: hidden;'));"+
"        }"+
"      } catch (e) { /* Not IE */ }"+
""+
"      rzdApp.unifiedModal.releaseTheLock();"+
"    };"+
""+
"  rzdApp.unifiedModal._generateModal = function _generateModal() {"+
"    if (window.top !== window){"+
"      rzdApp.hasError = true;"+
"      throw new Error('This script should not be embedded inside an iframe.');"+
"    }"+
""+
"    var modalContainer = document.createElement('div');"+
"    modalContainer.className = 'rzd-modal';"+
"    modalContainer.id = 'rzd-modal';"+
""+
"    var modalBackground = document.createElement('label');"+
"    modalBackground.className = 'rzd-modal__bg';"+
""+
"    var loader = document.createElement('div');"+
"    loader.className = 'rzd-modal__loader';"+
"    loader.innerHTML = '<div></div><div></div><div></div><div></div>';"+
"    modalBackground.append(loader);"+
""+
"    var modalInnerWrapper = document.createElement('div');"+
"    modalInnerWrapper.className = 'rzd-modal__inner';"+
"    modalInnerWrapper.style.visibility = 'hidden';"+
""+
"    var modalClose = document.createElement('label');"+
"    modalClose.className = 'rzd-modal__close';"+
"    modalClose.onclick = function(event) {"+
"      event.preventDefault();"+
"      rzdApp.unifiedModal.cleanupHandler(event);"+
"    };"+
"    modalClose.innerText = 'x';"+
""+
"    var modalContentWrapper = document.createElement('div');"+
"    modalContentWrapper.className = 'rzd-modal__content';"+
""+
"    modalInnerWrapper.append(modalClose);"+
"    modalInnerWrapper.append(modalContentWrapper);"+
"    modalContainer.append(modalBackground);"+
"    modalContainer.append(modalInnerWrapper);"+
""+
"    document.body.append(modalContainer);"+
""+
"    document.body.style.overflowY = 'hidden';"+
"    document.documentElement.style.overflowY = 'hidden';"+
"  };"+
""+
"function allocateGA4Notifier() {"+
"    let dataObj;"+
"    let pendingRecvs = [];"+
""+
"    function addReceiver(recvWindow) {"+
"        if (dataObj) {"+
"            console.debug('Sending GA4 message on addReceiver', recvWindow, dataObj);"+
"            recvWindow.postMessage(dataObj, '*');"+
"        } else {"+
"            console.debug('Adding GA4 receiver to pendingRecvs', recvWindow);"+
"            pendingRecvs.push(recvWindow);"+
"        }"+
"    }"+
""+
"    function prepareData(cid,sid, measurementID) {"+
"        console.debug('Sending GAINIT event', cid == null ? 'to signal no connected GA4 property' : 'for ' + measurementID);"+
"        let connectedGA4 = sessionStorage.getItem('connectedGA4');"+
"        dataObj = {gaInit: {cid,sid, measurementID, connectedGA4}};"+
"        console.debug('pendingRecvs: ', pendingRecvs);"+
"        for(const pender of pendingRecvs) {"+
"            console.debug(pender);"+
"            pender.postMessage(dataObj, '*');"+
"        }"+
"    }"+
""+
"    return {"+
"        prepareData: prepareData,"+
"        addReceiver: addReceiver"+
"    }"+
"};"+
""+
"function allocateUANotifier() {"+
"    let dataObj;"+
"    let pendingRecvs = [];"+
""+
"    function addReceiver(recvWindow) {"+
"        if (dataObj) {"+
"            console.debug('Sending UA message on addReceiver', recvWindow, dataObj);"+
"            recvWindow.postMessage(dataObj, '*');"+
"        } else {"+
"            console.debug('Adding UA receiver to pendingRecvs', recvWindow);"+
"            pendingRecvs.push(recvWindow);"+
"        }"+
"    }"+
""+
"    function prepareData(cid,trackingID) {"+
"        let connectedGA4 = sessionStorage.getItem('connectedGA4');"+
"        dataObj = {uaInit: {cid,trackingID,connectedGA4}};"+
"        console.debug('pendingRecvs: ', pendingRecvs);"+
"        for(const pender of pendingRecvs) {"+
"            console.debug(pender);"+
"            pender.postMessage(dataObj, '*');"+
"        }"+
"    }"+
""+
"    return {"+
"        prepareData: prepareData,"+
"        addReceiver: addReceiver"+
"    }"+
"};"+
""+
"    const gaCommObj = allocateGA4Notifier();"+
"    window.prepareGA4Data = gaCommObj.prepareData;"+
"    window.addGA4Receiver = gaCommObj.addReceiver;"+
""+
"    const uaCommObj = allocateUANotifier();"+
"    window.prepareUAData = uaCommObj.prepareData;"+
"    window.addUAReceiver = uaCommObj.addReceiver;"+
""+
"    rzdApp.unifiedModal.openOnMessage = function _modalHandler(event) {"+
"        /*Empty data object*/"+
"        var data = {type: '', data: ''};"+
""+
"        /*window emitting the message*/"+
"        var iframeWindow = null;"+
""+
"        /*If current event is holding data*/"+
"        if (event.data) {"+
"          data = event.data;"+
"        }"+
""+
"        /*Or if the original one is holding data*/"+
"        if (event.originalEvent && event.originalEvent.data) {"+
"          data = event.originalEvent.data;"+
"        }"+
""+
"        /*Only listen to message emitted by the click on _booking_booknow*/"+
"        if (typeof data === 'undefined' || typeof data.type === 'undefined') {"+
"          return;"+
"        }"+
""+
"        if (data.type === 'readyToStartGA') {"+
"            console.debug('Handling readyToStartGA event', event);"+
"            window.addGA4Receiver(event.source);"+
"            window.addUAReceiver(event.source);"+
"        }"+
""+
"        if (data.type === 'storeConnectedGA4') {"+
"            console.debug('Setting connected GA4 in session storage to ' + data.value);"+
"            sessionStorage.setItem('connectedGA4', data.value);"+
"        }"+
""+
"        if (['rezdy_open_in_modal', 'rezdy_loading', 'RezdyScrollToTop', 'rezdy_cleanup_modal'].indexOf(data.type) === -1) {"+
"          return;"+
"        }"+
""+
"        if (data.type === 'rezdy_cleanup_modal') {"+
"          rzdApp.unifiedModal.cleanupHandler();"+
"        }"+
""+
""+
"        if (data.type === 'rezdy_loading'|| data.type === 'rezdy_open_in_modal') {"+
"          if (!document.querySelector('#rzd-modal')) {"+
"            rzdApp.unifiedModal._generateModal();"+
"          }"+
"        }"+
""+
"        if (data && typeof data.data !== 'undefined' && ((typeof data.data === 'string' && data.data.length) || (typeof data.data === 'object' && Object.keys(data.data).length) || data.url.length)) {"+
"            /*Load the iframe on the checkout page.*/"+
"            var iframe = document.createElement('iframe');"+
"            iframe.className = 'external_rezdy rezdy';"+
"            /*Resize the iframe once loaded*/"+
"            iframe.onload = function () {"+
"              /*trigger scrolling to top whenever the iframe inside the modal is loaded*/"+
"              document.querySelector('.rzd-modal').scrollTop = 0;"+
"              try {"+
"                  iFrameResize("+
"                        {"+
"                            checkOrigin: false,"+
"                            log: false,"+
"                            enablePublicMethods: false,"+
"                            resizedCallback: function(iframe) {"+
"                                var modalLoader = document.querySelector('.rzd-modal__loader');"+
"                                if (modalLoader) {"+
"                                  modalLoader.remove();"+
"                                }"+
"                                iframe.iframe.contentWindow.postMessage('MODAL_OPENED', '*');"+
"                            }"+
"                        },"+
"                        iframe"+
"                  );"+
"              } catch (e) {"+
"                /** iFrameResize throwing an error might be because existing outdated resizer is on the page */"+
"                rzdApp.shutdown();"+
"                window.location.href = data.url;"+
"              }"+
"              document.querySelector('.rzd-modal__inner').style.visibility = 'visible';"+
"            };"+
""+
"            iframe.style.width = '100%';"+
"            iframe.style.border = 'none';"+
"            iframe.style.height = document.body.getBoundingClientRect().height / 1.7 + 'px';"+
""+
"            var modalContent = document.querySelector('.rzd-modal__content');"+
"            modalContent.append(iframe);"+
"            iframe.src = data.url;"+
""+
"            /*Release the lock when the content is shown to the user.*/"+
"            rzdApp.unifiedModal.releaseTheLock();"+
"        }"+
"    };"+
""+
"    rzdApp.unifiedModal.simpleModalHandler = function _simpleModalHandler(event) {"+
"      if (event.target && event.target.matches('.rezdy-modal')) {"+
"        var url = event.target.href;"+
"        url += url.indexOf('?') !== -1 ? '&iframe=true' : '?iframe=true';"+
""+
"        event.preventDefault();"+
"        event.stopPropagation();"+
"        event.data = {url: url, data: '', type: 'rezdy_open_in_modal'};"+
"        rzdApp.unifiedModal.openOnMessage(event);"+
"      }"+
"    };"+
""+
"    rzdApp.unifiedModal.escapeHandler = function _escapeHandler (event) {"+
"      if (event.defaultPrevented) {"+
"        return;"+
"      }"+
""+
"      var handled = false;"+
"      if (event.key !== undefined) {"+
"        if (event.key === 'Escape') {"+
"          rzdApp.unifiedModal.cleanupHandler();"+
"          handled = true;"+
"        }"+
""+
"      } else if (event.keyCode !== undefined) {"+
"        if (event.keyCode === 27) {"+
"          rzdApp.unifiedModal.cleanupHandler();"+
"          handled = true;"+
"        }"+
"      }"+
""+
"      if (handled) {"+
"        event.preventDefault();"+
"      }"+
"    };"+
""+
"    rzdApp.unifiedModal.slickCloseHandler = function _slickCloseHandler(event) {"+
"      var closeButtonSelector = '.rzd-modal__close';"+
"      if (typeof event.data === 'string' && event.data === 'SHOW_MODAL_CLOSE') {"+
"        /*need to show for those who arent using the new rezdy header*/"+
"        if (document.querySelector(closeButtonSelector)) {"+
"          document.querySelector(closeButtonSelector).style.display = 'block';"+
"        }"+
"      } else if (typeof event.data === 'string' && event.data === 'HIDE_MODAL_CLOSE') {"+
"        /*need to hide for those who arent using the new rezdy header and are having"+
"        the slick box modal close button overlapping issue*/"+
"        if (document.querySelector(closeButtonSelector)) {"+
"          document.querySelector(closeButtonSelector).style.display = 'none';"+
"        }"+
"      }"+
"    };"+
""+
"    rzdApp.unifiedModal.shutdown = function _shutdown() {"+
"      rzdApp.unifiedModal.cleanupHandler();"+
"      rzdApp.unifiedModal.releaseTheLock();"+
"      window.removeEventListener('message', rzdApp.unifiedModal.slickCloseHandler);"+
"      window.removeEventListener('keydown', rzdApp.unifiedModal.escapeHandler);"+
"      document.removeEventListener('click', rzdApp.unifiedModal.simpleModalHandler);"+
"      window.removeEventListener('message', rzdApp.unifiedModal.openOnMessage);"+
"    };"+
""+
"    rzdApp.unifiedModal.init();";
            break;
        }

        if (script.innerText.length) {
            document.body.append(script);
            return true;
        }

        return false;
    };

    rzdApp.FeatureDetector.init = function _init() {
      rzdApp.FeatureDetector.supportedFeatures.filter(function(feature) {
        return rzdApp.FeatureDetector.detectFeature(feature);
      });
    };

   //Dedicated endpoint to deal with async loaded booking button (monthly calendar)
   rzdApp.healthCheck = function _healthCheck(event) {
     if (event.data && event.data === 'rzd_health_check' && !document.querySelector('.rzd-modal') && window.location.protocol === 'https:' && !rzdApp.hasError) {
      rzdApp.notifyIframes('rzd_plugin_js_loaded');
     }
   };

   rzdApp.initPluginJS = function _initPluginJs() {
     if (document.querySelector('#rzd-polyfill')) {
       return;
     }
      var polyfillScript = document.createElement('script');

      polyfillScript.id = 'rzd-polyfill';
      polyfillScript.defer = true;
      polyfillScript.addEventListener('load', function(){
          rzdApp.FeatureDetector.init();
      });
      polyfillScript.src = 'https://cdn.polyfills.io/v2/polyfill.min.js';

      //BAD DOM
      if (document.readyState === 'complete' && !document.body) {
        var body = document.createElement("body");
        document.documentElement.appendChild(body);
      }
      document.body.appendChild(polyfillScript);

      window.addEventListener('message', rzdApp.healthCheck);
      window.addEventListener('message', function(event) {
        if (event && event.data && event.data === 'rzd_app_shutdown') {
           rzdApp.hasError = true;
         }
      });
      window.iFrameResize = rzdApp.iFrameResize;
      window.addEventListener('error', function() {
        rzdApp.hasError = true;
      });

      //hasError is reactive, it will trigger the shutdown has soon has it's set to true.
      var internalValue = false;
      Object.defineProperty(rzdApp, 'hasError', {
        configurable: true,
        enumerable: true,
        writeable: true,
        get: function() {
          return internalValue;
        },
        set: function (value) {
          internalValue = value;
          if (value) {
            rzdApp.shutdown();
          }
        }
      });
      rzdApp.hasError = false;

      //Disable the modal for safari (until we find a reliable way to check 3rd party cookies being allowed).
      if ( rzdApp.FeatureDetector.isSafari) {
        rzdApp.hasError = true;
      }
  };

  rzdApp.notifyIframes = function _notifyIframes(message) {
    var rzdIframes = document.querySelectorAll('iframe.rezdy, iframe[src*="rezdy.com"]');
    if (!rzdIframes.length) { return; }
     [].forEach.call(rzdIframes, function(iframe) {
       iframe.contentWindow.postMessage(message, '*');
     });
  };

   //If something goes wrong, try to provide the feature
  //Without using modal
  rzdApp.shutdown = function _gracefullyFail(event) {
    rzdApp.notifyIframes({type: 'rzd_js_errors'});

    if (typeof rzdApp.healthCheck === 'function') {
      window.removeEventListener('message', rzdApp.healthCheck);
    }

    if (typeof rzdApp.unifiedModal !== 'undefined') {
      rzdApp.unifiedModal.shutdown();
    }

    if (typeof rzdApp.embeddedCart !== 'undefined') {
      rzdApp.embeddedCart.shutdown();
    }
  };

  if (!document.querySelector('#rzd-polyfill')) {
    if (document.readyState === 'loading') {
      document.removeEventListener('DOMContentLoaded', rzdApp.initPluginJS);
      document.addEventListener('DOMContentLoaded', rzdApp.initPluginJS);
    } else {
      rzdApp.initPluginJS();
    }
  }
    // check if gtag() exists in data layer
    function allocateDataLayer() {
        window.dataLayer = window.dataLayer || [];
        if(window.gtag) {
            return window.gtag;
        }
        return function gtag() {
            window.dataLayer.push(arguments);
        }
    }
    (function() {

        const rezdyIFrames = document.querySelectorAll('iframe.rezdy, iframe[src*="rezdy.com"]');

        const extractGaObj = () => {
            const ga = window.GoogleAnalyticsObject;
            if(!ga) {
              return;
            }
            return window[ga];
        }

        const prepareForGA4 = (ga4gTag) => {
            const gtag = allocateDataLayer();
            const measurementID = (new URL(ga4gTag.src)).searchParams.get('id');
            console.debug("GA4 measurement ID: " + measurementID);
            rezdyIFrames.forEach(rezdyIframe => {
                console.debug("Adding iframe receiver for GA4", rezdyIframe);
                window.addGA4Receiver && window.addGA4Receiver(rezdyIframe.contentWindow);
            });
            const setupGA4Gtag = () => {
                gtag('get', measurementID, 'client_id', (cid) => {
                    gtag('get', measurementID, 'session_id', (sid) => {
                        console.debug("GA4 cid & sid: " + cid + ", " + sid);
                        console.debug(window.prepareGA4Data);
                        window.prepareGA4Data(cid,sid,measurementID);
                    })
                });
            }

            if(gtag) {
                setTimeout(setupGA4Gtag,100)
            }
            else{
                ga4gTag.addEventListener('load',() => setTimeout(setupGA4Gtag,100));
            }
        }

        const setupUAGtag = (cid, trackingID) => {
            console.debug("UA cid: " + cid + ", trackingID: " + trackingID);
            if (!window.prepareUAData) {
                console.debug("window.prepareUAData has not been defined yet - skip & retry");
                setTimeout(() => setupUAGtag(cid, trackingID),100)
                return;
            }
            window.prepareUAData(cid,trackingID);

            // Handle connected GA4 property (if any)
            console.debug("Looking for connected GA4 tag");
            const ga4gTag = document.querySelector('script[src^="https://www.googletagmanager.com/gtag/js?id=G-"]');
            if (ga4gTag !== null) {
                console.debug("Connected GA4 tag found");
                sessionStorage.setItem('connectedGA4', 'true');
                prepareForGA4(ga4gTag);
            } else {
                // signal there is no connected GA4 property
                window.prepareGA4Data(null, null, null);
            }
        }

        const prepareForUA = (uagTag) => {

            const gtag = allocateDataLayer();
            const trackingID = (new URL(uagTag.src)).searchParams.get('id');
            console.debug("UA tracking ID: " + trackingID);
            rezdyIFrames.forEach(rezdyIframe => {
                console.debug("Adding iframe receiver for UA", rezdyIframe);
                window.addUAReceiver && window.addUAReceiver(rezdyIframe.contentWindow);
            });
            const listenForUAClientId = () => {
                gtag('get', trackingID, 'client_id', (cid) => setupUAGtag(cid, trackingID));
            }

            if(gtag) {
                setTimeout(listenForUAClientId,100)
            }
            else{
                uagTag.addEventListener('load',() => setTimeout(listenForUAClientId,100));
            }
        }

        // GTM: either GA4 or UA (GA v3)
        const gtmTag = document.querySelector('script[src^="https://www.googletagmanager.com/gtm.js?id=GTM-"]');
        if (gtmTag !== null) {
            let waitCounter = 0;
            console.debug("### GTM tag detected - getting into waitForEitherUAorGA4");
            const waitForEitherUAorGA4 = () => {
                console.debug("### waiting for GTM TAG");

                // If a connected UA property tag is delivered via GTM, it should always be the first one to
                // be loaded! The connected GA4 property would follow, but that is taken care of within the
                // scope of "setupUAGtag"

                const gaObj = extractGaObj();
                if(gaObj && gaObj.getAll && Array.isArray(gaObj.getAll()) && gaObj.getAll().length > 0) {
                    console.debug("### UA TAG loaded from GTM tag!");
                    setupUAGtag(ga.getAll()[0].get('clientId'), ga.getAll()[0].get('trackingId'));
                    return;
                }

                // We would not expect to get to run this unless the GTM tag was directly deploying a GA4 tag
                // (no connected UA involved)
                const ga4gTag = document.querySelector('script[src^="https://www.googletagmanager.com/gtag/js?id=G-"]');
                if (ga4gTag !== null) {
                    console.debug("### GA4 TAG loaded from GTM tag!");
                    prepareForGA4(ga4gTag);
                    return;
                }

                if (++waitCounter > 50) return;

                setTimeout(() => waitForEitherUAorGA4(),300);
            }
            setTimeout(() => waitForEitherUAorGA4(),100)
            return;
        }

        // UA (GA v3) GTAG
        const uagTag = document.querySelector('script[src^="https://www.googletagmanager.com/gtag/js?id=UA-"]');
        if (uagTag !== null) {
            prepareForUA(uagTag);
            return;
        }

        // GA V4
        const ga4gTag = document.querySelector('script[src^="https://www.googletagmanager.com/gtag/js?id=G-"]');
        if (ga4gTag !== null) {
            prepareForGA4(ga4gTag);
            return;
        }

    })();