(function() {
    var name = '';
    var inventory = "S:lFTZr7pEczDhR1aab5jc4-vDLvfgSR1jABSFfWP-QFAMf5KEqQ7UOmDNYQC4WUTQzQARkXmhBbW8tCTweZaAejaqfmOVpqk0qI0yIu1Oq4icWK6GEiZiUZQ9kAUr43xwmWyCbCvtf50gQATBtNZBVjd9-LiVApqJ12FD";
    var logSampleRatePercent = -1;
    var logSampling = Math.random() * 100 <= logSampleRatePercent;
    var isIE = (function() {
        var ver = navigator.userAgent.match(/MSIE ([0-9]{1,}[\\.0-9]{0,})|Trident\/.*rv:([0-9]{1,}[\\.0-9]{0,})/);
        if (!ver) {
            return false;
        }
        ver.shift();
        return ver.filter(function(str) { return str != undefined; }).pop();
    });
    var logEvent = function (event) {
        if (!logSampling) {
            logger('log sampling disabled, event: ' + event);
            return;
        }
        var eventURL = new URL("https:\/\/ads.counciladvertising.net\/event\/log");
        eventURL.searchParams.set('inventory', inventory);
        eventURL.searchParams.set('event', event);
        var xhr = new XMLHttpRequest();
        xhr.open('GET', eventURL.toString());
        logger('sending audit event: ' + event);
        xhr.send();
    };
    var debuggingEnabled = function () {
        if (window.location && window.location.search.indexOf('can_debug') !== -1) {
            return true;
        }

        return window.localStorage && window.localStorage.getItem('can_debug') == 'true';
    }
    var logger = function () {
        if (debuggingEnabled()) {
            if (window._canStore && !window._canStore.debugLogsPrinted) {
                window._canStore.debugLogsPrinted = true;

                if (isIE()) {
                    console.debug(
                        "[CAN] If you can see this, CAN debug logs are turned ON"
                    );
                } else {
                    console.debug(
                        "%c[CAN] %cIf you can see this, CAN debug logs are turned ON",
                        "font-size: 3em; color: #267cae; font-weight: bolder; font",
                        "font-size: 3em; color: #f47401; font-weight: bold"
                    );
                }
            }
            for (var msgKey in arguments) {
                var msg = arguments[msgKey];
                console.debug("[can] [" + name + "]: "+msg);
            }
        }
    };
    logEvent('script_load');
    (function(currentScript) {
    if (!window._canStore) {
        window._canStore = {};
    }
    name = "div-gpt-ad-torfaencbc-ibar";
    var isRTBEnabled = false;
    var consentDecisionMade = false;
    var consentManagement = true;
    var segmentationCategories = [];

    if (consentManagement) {
        logger('waiting for IAB CMP to provide consent info');
        var cmpFrame = null;
        var cmpInterval = null;

        var checkConsent = function (tcData, success) {
                        if (consentDecisionMade) {
                return;
            }

            var shouldCheckConsent = tcData.gdprApplies !== false;

            var requiredPurposes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
            var purposesWithoutConsent = requiredPurposes
                .filter(function (key) {
                    return tcData.purpose.consents[key] !== true
                        && tcData.purpose.legitimateInterests[key] !== true;
                });

            var vendorsWithConsent = Object
                .keys(tcData.vendor.consents)
                .map(function (key) { return parseInt(key); })
                .filter(function (key) {
                    return tcData.vendor.consents[key] === true;
                });

            var consentGranted = !shouldCheckConsent ||
                (
                    vendorsWithConsent.length > 0
                    && purposesWithoutConsent.length === 0
                    && tcData.isServiceSpecific
                );

            if (consentGranted) {
                clearInterval(cmpInterval);
                consentDecisionMade = true;
                logEvent('consent_granted');
                logger('consent granted; continuing');
                if (cmpFrame) {
                    cmpFrame.postMessage(
                        {
                            __tcfapiCall: {
                                command: 'removeEventListener',
                                version: 2,
                                callId: Math.random()+'',
                                parameter: tcData.listenerId
                            }
                        },
                        '*'
                    );
                    window.removeEventListener('message', readPostMessage);
                } else {
                    window.__tcfapi('removeEventListener', 2, function () {}, tcData.listenerId);
                }
                beginInit();
            } else {
                logEvent('consent_denied');
                logger('consent not granted; exiting');
                window._canStore.consent = {
                    vendorsWithConsent: vendorsWithConsent,
                    purposesWithoutConsent: purposesWithoutConsent,
                };
            }
        }

        var getTCFLocatorFrame = function() {
            let frame = window;

            while (frame) {
                try {
                    if (frame.frames['__tcfapiLocator']) {
                        cmpFrame = frame;
                        break;
                    }
                } catch (ignore) {}

                if (frame === window.top) {
                    break;
                }
                frame = frame.parent;
            }

            return cmpFrame;
        }

        var readPostMessage = function (event) {
            var payload = event.data;
            try {
                if (typeof payload === 'string') {
                    payload = JSON.parse(payload);
                }
            } catch (ignore) { }
            if (!payload || !payload.__tcfapiReturn) {
                return;
            }
            var commandResult = payload.__tcfapiReturn.returnValue;
            if (! commandResult.tcString) {
                return;
            }

            checkConsent(payload.__tcfapiReturn.returnValue, payload.__tcfapiReturn.success);
        };

        var checkForCMP = function (delay) {
            if (window.__tcfapi) {
                logger('found TCF API via current window');
                cmpInterval = setInterval(function () {
                    window.__tcfapi('addEventListener', 2, checkConsent);
                }, 150);
                return;
            }
            var locatorFrame = getTCFLocatorFrame();
            var cmpFrame = locatorFrame;
            if (locatorFrame && locatorFrame != window.top) {
                cmpFrame = locatorFrame.parent;
            }

            if (cmpFrame) {
                logger('found TCF API via locator frame');
                window.addEventListener(
                    'message',
                    readPostMessage,
                    false
                );
                cmpInterval = setInterval(function () {
                    cmpFrame.postMessage(
                        {
                            __tcfapiCall: {
                                command: 'addEventListener',
                                version: 2,
                                callId: Math.random()+'',
                            }
                        },
                        '*'
                    );
                }, 150);
                return;
            }

            var nextDelay = delay + 100;
            setTimeout(checkForCMP, nextDelay, nextDelay);
            return;
        };
        setTimeout(checkForCMP, 0, 0);
    } else {
        setTimeout(function () { beginInit() }, 0);
    }

    var validateRTBResponse = function (xhr) {
        if (xhr.status != 200) {
            logger('RTB is disabled: a failure occurred resolving the RTB check for ' + window.location.href, xhr.status, xhr.statusText, xhr.responseText);
            isRTBEnabled = false;
            return;
        }
        var responseJson;
        try {
            responseJson = JSON.parse(xhr.responseText);
        } catch (err) {
            logger('RTB is disabled: a failure occurred parsing the RTB response', err);
            isRTBEnabled = false;
            return;
        }

        if (responseJson.blocked) {
            logger('RTB is disabled: endpoint blocked');
            isRTBEnabled = false;
        } else {
            logger('RTB is enabled');
            isRTBEnabled = true;
        }

        if (responseJson.categories) {
            logger('Received segmentation categories: ' + responseJson.categories.join(', '));
            segmentationCategories = responseJson.categories;
        }
    };

    var beginInit = function () {
        logger('checking RTB state');

        var windowURL = window.location.hostname + window.location.pathname;
        var xhr = new XMLHttpRequest();
        xhr.open('GET', "https:\/\/ads.counciladvertising.net\/tag\/config\/torfaencbc\/ibar" + "?url=" + encodeURIComponent(windowURL));
        xhr.setRequestHeader('Accept', 'application/json');

        xhr.onload = function() {
            validateRTBResponse(xhr);
            start();
        };
        xhr.onerror = function() {
            logger('a failure occurred resolving the RTB check for ' + window.location.href);
            start();
        };

        xhr.send();
    };
    var start = function() {
        var blacklist = ["@","%2540","%40","user=","email=","emailaddress=","password=","pw=","un=","username="];

var shouldAbortDueToPII = function () {
    var url = (window.location.search || window.location.href).toLowerCase();
    for (var i = 0; i < blacklist.length; i++) {
        var word = blacklist[i];
        if (url.indexOf(word) !== -1 || decodeURIComponent(url).indexOf(word) !== -1) {
            logger("aborted load after finding "+word);
            return true;
        };
    };

    return false;
}

if (shouldAbortDueToPII()) {
    return;
}

var gdpr = null;
var addScript = function(url) {
    var script = document.createElement("script");

    script.type = "text/javascript";
    script.src = url;

    var head = document.body || document.getElementsByTagName('body')[0];
    head.appendChild(script);
    return script;
};
var gpt_slot = null;

var load = function () {
    var div = document.createElement('div');
    div.id = "div-gpt-ad-torfaencbc-ibar";
    document.body.appendChild(div);
};

if (gdpr == null) {
    load();
} else {
    window._canStore = window._canStore || {};
    if (!window._canStore['gdpr']) {
        addScript(gdpr);
        window._canStore['gdpr'] = true;
    };
    window.addEventListener('canGdprConsent', function (e) {
        if (e.consent) {
            load();
        }
    });
}

if (isRTBEnabled) {
    var script = document.createElement('script');
            script.setAttribute('async', 'async');
            script.setAttribute('src', "\/\/assets.counciladvertising.net\/v3\/scripts\/33c5aa25c38970faae4c327b935edb7d.js");
    document.head.appendChild(script);
}
    };
})(document.currentScript);
})();
