function CCT_startTimer() {
    var timerRemainingSeconds = localStorage.getItem("timerRemainingSeconds551131");
    if (timerRemainingSeconds === null) {
        timerRemainingSeconds = '900';
    }

    if ('1' === '2') {
        if (jQuery('#effectiveAppsCDT').length > 0) {
            FlipClock.Lang.Custom = {hours: window.EFFECTIVE_APPS_CCT_TERMINOLOGY_HOURS, minutes: window.EFFECTIVE_APPS_CCT_TERMINOLOGY_MINUTES, seconds: window.EFFECTIVE_APPS_CCT_TERMINOLOGY_SECONDS };
            var clockFaceType = 'HourCounter';
            if (timerRemainingSeconds < 3600 && 'True' === 'True') {
                clockFaceType = "MinuteCounter";
            }

            window.EffectiveAppsCCTFlipClock = new FlipClock(jQuery('#effectiveAppsCDT'), timerRemainingSeconds, {
                clockFace: clockFaceType,
                autoStart: true,
                countdown: true,
                callbacks: {
                    interval: function () {
                        if (window.EffectiveAppsCCTFlipClock !== undefined) {
                            localStorage.setItem("timerRemainingSeconds551131", window.EffectiveAppsCCTFlipClock.getTime().time);
                        }
                    },
                    stop: function() {
                        if ('3' === '1') {
                            localStorage.removeItem("timerRemainingSeconds551131");
                        }
                        else if ('3' === '2') {
                            localStorage.removeItem("timerRemainingSeconds551131");
                            window.EFFECTIVE_APPS_CCT_TIMER_STARTED = false;
                            CCT_startTimer();
                        }
                        else if ('3' === '3') {
                            localStorage.removeItem("timerRemainingSeconds551131");
                            if (location.pathname.indexOf('/cart') > -1) {
                                document.location = '/cart/clear';
                            }
                            else {
                                jQuery.get('/cart/clear');
                            }
                        }
                    }
                },
                language: 'Custom'
            });
        }
        else {
            var timer = timerRemainingSeconds;
            window.EFFECTIVE_APPS_CCT_TID = setInterval(function () {
                timer = timer - 1;
                if (timer >= 0) {
                    localStorage.setItem("timerRemainingSeconds551131", timer);
                }
                if (timer < 0) {
                    if ('3' === '1') {
                        localStorage.removeItem("timerRemainingSeconds551131");
                        clearInterval(window.EFFECTIVE_APPS_CCT_TID);
                    }
                    else if ('3' === '2') {
                        timer = '900';
                        localStorage.removeItem("timerRemainingSeconds551131");
                    }
                    else if ('3' === '3') {
                        clearInterval(window.EFFECTIVE_APPS_CCT_TID);
                        localStorage.removeItem("timerRemainingSeconds551131");
                        if (location.pathname.indexOf('/cart') > -1) {
                            document.location = '/cart/clear';
                        }
                        else {
                            jQuery.get('/cart/clear');
                        }
                    }
                }
            }, 1000);
        }
    }
    else if ('1' === '1') {
        var timer = timerRemainingSeconds, hours, minutes, seconds, suffix;
        window.EFFECTIVE_APPS_CCT_TID = setInterval(function () {
            var display = document.getElementById('effectiveAppsCDT');
            seconds = parseInt((timer) % 60, 10);
            minutes = parseInt((timer/60) % 60, 10);
            hours = parseInt((timer/(60*60)), 10);

            hours = hours < 10 ? "0" + hours : hours;
            minutes = minutes < 10 ? "0" + minutes : minutes;
            seconds = seconds < 10 ? "0" + seconds : seconds;

            if (timer >= 3600)
            {
                suffix = window.EFFECTIVE_APPS_CCT_TERMINOLOGY_HOURS;
            }
            else if (timer >= 60)
            {
                suffix = window.EFFECTIVE_APPS_CCT_TERMINOLOGY_MINUTES;
            }
            else if (timer < 60) {
                suffix = window.EFFECTIVE_APPS_CCT_TERMINOLOGY_SECONDS
            }

            if ('True' === 'False') {
                suffix = "";
            }
            else {
                suffix = " " + suffix;
            }

            if (display !== null && display !== undefined && timer >= 0) {
                if (hours === "00" && 'True' === 'True') {
                    display.textContent = minutes + ":" + seconds + suffix;
                }
                else {
                    display.textContent = hours + ":" + minutes + ":" + seconds + suffix;
                }
            }

            if (timer >= 0) {
                timer = timer - 1;
                localStorage.setItem("timerRemainingSeconds551131", timer);
            }
            if (timer < 0) {
                if ('3' === '1') {
                    localStorage.removeItem("timerRemainingSeconds551131");
                    clearInterval(window.EFFECTIVE_APPS_CCT_TID);
                }
                else if ('3' === '2') {
                    timer = '900';
                    localStorage.removeItem("timerRemainingSeconds551131");
                }
                else if ('3' === '3') {
                    clearInterval(window.EFFECTIVE_APPS_CCT_TID);
                    localStorage.removeItem("timerRemainingSeconds551131");
                    if (location.pathname.indexOf('/cart') > -1) {
                        document.location = '/cart/clear';
                    }
                    else {
                        jQuery.get('/cart/clear');
                    }
                }
            }
        }, 1000);
    }
}

function CCT_attachToATC(atcElementToAttachTo) {
    if (document.getElementById('effectiveAppsCDTATCContainer') !== null) {
        return;
    }

	if (null === atcElementToAttachTo) {
		return;
	}

	var elementContainer = atcElementToAttachTo.parentElement;
    var timerElement = document.createElement('div');
    timerElement.id = 'effectiveAppsCDTATCContainer';
    if ('center' !== '') {
        timerElement.style.textAlign = 'center';
    }

    if ('' !== '') {
        timerElement.style.borderColor = '#';
        timerElement.style.borderStyle = 'unset';
        timerElement.style.marginBottom = "5px";
        timerElement.style.backgroundClip = "content-box";
    }

    if ('' !== '') {
        timerElement.style.backgroundColor = '#';
        timerElement.style.marginBottom = "5px";
        timerElement.style.backgroundClip = "content-box";
    }

    if ('0' !== '0') {
        timerElement.style.paddingTop = "0px";
    }

    if ('0' !== '0') {
        timerElement.style.paddingBottom = "0px";
    }

    if ('0' !== '0') {
        timerElement.style.marginTop = "0px";
    }

    if ('0' !== '0') {
        timerElement.style.marginBottom = "0px";
    }

    timerElement.innerHTML = window.EFFECTIVE_APPS_CCT_TEXT;

	if (window.CCT_THEME_NAME.indexOf("brooklyn") > -1 || window.CCT_THEME_NAME.indexOf("minimal") > -1 || window.CCT_THEME_NAME.indexOf("simple") > -1) {
        elementContainer = atcElementToAttachTo.parentElement.parentElement;
    }

    if (window.CCT_THEME_NAME.indexOf("flex") > -1 || window.CCT_THEME_NAME.indexOf("palo alto") > -1 || window.CCT_THEME_NAME.indexOf("broadcast") > -1) {
        elementContainer = atcElementToAttachTo.parentElement.parentElement.parentElement;
    }
    var timerWrapper = document.createElement('div');
    timerWrapper.appendChild(timerElement);
	elementContainer.insertAdjacentHTML('afterbegin', timerWrapper.innerHTML);
	window.effectiveAppsCCTSuccessfullyAttachedToATC = true;
}

function CCT_getLsWithExpiry(key) {
	const itemStr = localStorage.getItem(key)
	if (!itemStr) {
		return null
	}

	const item = JSON.parse(itemStr)
	const now = new Date()
	if (now.getTime() > item.expiry) {
		localStorage.removeItem(key)
		return null
	}

	return item.value.toString();
}

function CCT_setLsWithExpiry(key, value, ttl) {
    value = value.toString();
	const now = new Date()
	const item = {
		value: value,
		expiry: now.getTime() + ttl,
	}
	localStorage.setItem(key, JSON.stringify(item))
}

function CCT_attachToCart() {
    if ('True' !== 'True') {
        return;
    }

	var timerElement = document.createElement('div');
    timerElement.id = 'effectiveAppsCDTContainer';
    if ('center' !== '') {
        timerElement.style.textAlign = 'center';
    }

    if ('' !== '') {
        timerElement.style.borderColor = '#';
        timerElement.style.borderStyle = 'unset';
        timerElement.style.marginBottom = "5px";
        timerElement.style.backgroundClip = "content-box";
    }

    if ('' !== '') {
        timerElement.style.backgroundColor = '#';
        timerElement.style.marginBottom = "5px";
        timerElement.style.backgroundClip = "content-box";
    }

    if ('0' !== '0') {
        timerElement.style.paddingTop = "0px";
    }

    if ('0' !== '0') {
        timerElement.style.paddingBottom = "0px";
    }

    if ('0' !== '0') {
        timerElement.style.marginTop = "0px";
    }

    if ('0' !== '0') {
        timerElement.style.marginBottom = "0px";
    }

    timerElement.innerHTML = window.EFFECTIVE_APPS_CCT_TEXT;

    var timerWrapper = document.createElement('div');
	var checkoutButtonElement = CCT_detectCheckoutButton();
	if (null === checkoutButtonElement) {
		return;
	}

	let elementContainer = checkoutButtonElement.parentElement;
	if (document.querySelector('[class*="upcart-cart-body"]') !== null) {
	    timerWrapper.appendChild(timerElement);
        document.querySelector('[class*="upcart-cart-body"]').insertAdjacentElement('afterbegin', timerWrapper.cloneNode(true));
	}
	else if (window.CCT_THEME_NAME.indexOf('debut') > -1 && window.CCT_THEME_NAME.indexOf('debutify') === -1) {
        elementContainer = checkoutButtonElement.parentElement.parentElement;
        timerWrapper.appendChild(timerElement);
        elementContainer.innerHTML = timerWrapper.innerHTML + elementContainer.innerHTML;
	}
	else if (window.CCT_THEME_NAME.indexOf('atlantic') > -1 && document.querySelector('[class="sidebar-drawer__content"]') !== null && location.href.indexOf('/cart') === -1) {
	    let cartDrawerHeader = document.querySelector('[class="sidebar-drawer__content"]');
	    timerWrapper.style.marginRight = "20px";
	    timerWrapper.appendChild(timerElement);
        cartDrawerHeader.insertAdjacentElement('afterbegin', timerWrapper.cloneNode(true));
    }
    else if (window.CCT_THEME_NAME.indexOf('impact') > -1 && document.querySelector('[class="cart-drawer__top"]') !== null && location.href.indexOf('/cart') === -1) {
	    let cartDrawerHeader = document.querySelector('[class="cart-drawer__top"]');
	    timerWrapper.appendChild(timerElement);
        cartDrawerHeader.insertAdjacentElement('beforeend', timerWrapper.cloneNode(true));
    }
    else if (window.CCT_THEME_NAME.indexOf('speedfly') > -1 && document.querySelector('[class="mini-cart__items"]') !== null && location.href.indexOf('/cart') === -1) {
	    let cartDrawerHeader = document.querySelector('[class="mini-cart__items"]');
	    timerWrapper.appendChild(timerElement);
        cartDrawerHeader.insertAdjacentElement('beforebegin', timerWrapper.cloneNode(true));
    }
    else if (window.CCT_THEME_NAME.indexOf('speedfly') > -1 && document.querySelector('[class="cart-row-item"]') !== null && location.href.indexOf('/cart') === -1) {
	    let cartDrawerHeader = document.querySelector('[class="cart-row-item"]');
	    timerWrapper.appendChild(timerElement);
        cartDrawerHeader.insertAdjacentElement('beforebegin', timerWrapper.cloneNode(true));
    }
	else if (window.CCT_THEME_NAME.indexOf('brooklyn') > -1) {
        timerElement.style.position = 'relative';
        if ('1' === '1') {
            timerElement.style.marginBottom = '-25%';
            timerElement.style.top = '-50%';
        }
        else if ('1' === '2') {
            timerElement.style.marginTop = '-40%';
            timerElement.style.top = '-20%';
        }

        timerWrapper.appendChild(timerElement);
        elementContainer.innerHTML = timerWrapper.innerHTML + elementContainer.innerHTML;
	}
	else if (window.CCT_THEME_NAME.indexOf('boundless') > -1) {
        if ('1' === '1') {
            timerElement.style.position = 'relative';
            timerElement.style.marginBottom = '-25%';
            timerElement.style.top = '-35%';
        }
        else if ('1' === '2') {
            timerElement.style.marginTop = '-60%';
            timerElement.style.top = '-20%';
        }

        timerWrapper.appendChild(timerElement);
        elementContainer.innerHTML = timerWrapper.innerHTML + elementContainer.innerHTML;
	}
	else if (window.CCT_THEME_NAME.indexOf('debutify') > -1) {
	    let cartDrawerHeader = document.getElementById('CartDrawer').querySelector('[class*="drawer__inner"]');
	    if (cartDrawerHeader !== null) {
            timerWrapper.appendChild(timerElement);
            cartDrawerHeader.insertAdjacentElement('beforebegin', timerWrapper.cloneNode(true));
	    }
	    else {
            timerElement.style.position = 'relative';
            timerElement.style.marginBottom = '-13%';
            timerElement.style.top = '-50%';
        }
    }
    else if (window.CCT_THEME_NAME.indexOf('dawn') > -1 || window.CCT_THEME_NAME.indexOf('shopiweb') > -1 || window.CCT_THEME_NAME.indexOf('shrine') > -1 || window.CCT_THEME_NAME.indexOf('spotlight') > -1 || window.CCT_THEME_NAME.indexOf('kenzy1') > -1 || window.CCT_THEME_NAME.indexOf('sense') > -1) {
	    let cartDrawerHeader = document.querySelector('[class*="drawer__header"]');
	    if (cartDrawerHeader !== null) {
            timerWrapper.appendChild(timerElement);
            cartDrawerHeader.insertAdjacentElement('afterend', timerWrapper.cloneNode(true));
	    }
	    else {
	        elementContainer = checkoutButtonElement.parentElement.parentElement;
	        timerWrapper.appendChild(timerElement);
            elementContainer.insertAdjacentElement('beforebegin', timerWrapper.cloneNode(true));
	    }
    }
    else if (window.CCT_THEME_NAME.indexOf('blockshop') > -1) {
        elementContainer = checkoutButtonElement.parentElement.parentElement;
        timerWrapper.appendChild(timerElement);
        elementContainer.insertAdjacentElement('beforebegin', timerWrapper.cloneNode(true));
    }
    else if (window.CCT_THEME_NAME.indexOf('warehouse') > -1) {
        elementContainer = checkoutButtonElement.parentElement.parentElement;
        timerWrapper.appendChild(timerElement);
        elementContainer.insertAdjacentElement('beforebegin', timerWrapper.cloneNode(true));
    }
    else if (window.CCT_THEME_NAME.indexOf('sense') > -1) {
        timerWrapper.appendChild(timerElement);
        elementContainer.insertAdjacentElement('beforebegin', timerWrapper.cloneNode(true));
    }
    else if (window.CCT_THEME_NAME.indexOf('refresh') > -1) {
        timerWrapper.appendChild(timerElement);
        elementContainer.insertAdjacentElement('beforebegin', timerWrapper.cloneNode(true));
    }
    else if (window.CCT_THEME_NAME.indexOf('craft') > -1) {
        timerWrapper.appendChild(timerElement);
        elementContainer.insertAdjacentElement('beforebegin', timerWrapper.cloneNode(true));
    }
    else if (window.CCT_THEME_NAME.indexOf('be yours') > -1) {
        timerWrapper.appendChild(timerElement);
        elementContainer.insertAdjacentElement('beforebegin', timerWrapper.cloneNode(true));
    }
	else {
        timerWrapper.appendChild(timerElement);
        elementContainer.innerHTML = timerWrapper.innerHTML + elementContainer.innerHTML;
	}

	if (window.ON_ATTACHED_TO_CART_CALLBACK !== undefined) {
	    window.ON_ATTACHED_TO_CART_CALLBACK();
	}
}

function CCT_detectCartHeader() {
	var resultElement = null;
	var cartFormSelectors = [
	    '*[cct-ch-override="true"]:not([disabled])',
	    '*[class="cart-order"]',
	    'div[class="cart-wrapper"]',
		'form[action="/cart"]',
		'form[action="/checkout"]',
	];

	var broadCartFormSelector = [
	    'form[action*="/cart"]'
	];

	for (var selector of cartFormSelectors) {
		var elementSearchResult = document.querySelectorAll(selector);
		if (elementSearchResult.length > 1 && window.CCT_THEME_NAME.indexOf('optimal') === -1) {
		    if (elementSearchResult[1].getAttribute('cct-ignore') === "true") {
		        continue;
		    }
			return elementSearchResult[1];
		} else if (elementSearchResult.length > 0) {
		    if (elementSearchResult[0].getAttribute('cct-ignore') === "true") {
		        continue;
		    }
			return elementSearchResult[0];
		}
	}

	for (var selector of broadCartFormSelector) {
		var elementSearchResult = document.querySelector(selector);
		if (elementSearchResult !== null) {
		    return elementSearchResult;
		}
	}

	return null;
}

function CCT_appendToCart() {
    try {
        if ('True' !== 'True') {
            return;
        }

        var insertionType = "beforeelement";
        var timerElement = document.createElement('div');
        timerElement.id = 'effectiveAppsCDTContainer';
        if ('center' !== '') {
            timerElement.style.textAlign = 'center';
        }
        if ('' !== '') {
            timerElement.style.borderColor = '#';
            timerElement.style.borderStyle = 'unset';
            timerElement.style.marginBottom = "5px";
            timerElement.style.backgroundClip = "content-box";
        }
        if ('' !== '') {
            timerElement.style.backgroundColor = '#';
            timerElement.style.marginBottom = "5px";
            timerElement.style.backgroundClip = "content-box";
        }

        if ('0' !== '0') {
            timerElement.style.paddingTop = "0px";
        }

        if ('0' !== '0') {
            timerElement.style.paddingBottom = "0px";
        }

        if ('0' !== '0') {
            timerElement.style.marginTop = "0px";
        }

        if ('0' !== '0') {
            timerElement.style.marginBottom = "0px";
        }

        timerElement.innerHTML = window.EFFECTIVE_APPS_CCT_TEXT;
        var element = null;
        if ('2' === '2') {
            element = CCT_detectCartHeader();
            if (window.CCT_THEME_NAME.indexOf('capital') > -1 || window.CCT_THEME_NAME.indexOf('ella') > -1 || window.CCT_THEME_NAME.indexOf('impact') > -1) {
                jQuery(element).before(timerElement);
            }
            else {
                jQuery(element).prepend(timerElement);
            }
        }

        if ('2' === '1' || element === null) {
            element = CCT_detectCheckoutButton();
            let coContainer = element.parentElement;
            if (window.CCT_THEME_NAME.indexOf('debut') > -1 || window.CCT_THEME_NAME.indexOf('express') > -1) {
                coContainer = element.parentElement.parentElement;
            }

            if (window.CCT_THEME_NAME.indexOf('dawn') > -1) {
                insertionType = "beforebegin";
            }

            if (window.CCT_THEME_NAME.indexOf('sense') > -1) {
                insertionType = "beforebegin";
            }

            if (insertionType === "beforebegin") {
                coContainer.insertAdjacentElement('beforebegin', timerElement.cloneNode(true));
            }
            else {
                coContainer.insertBefore(timerElement.cloneNode(true), coContainer.firstChild);
            }
        }
        return true;
    }
    catch {
        return false;
    }
}

function CCT_loadStylesheet(url, success) {
    var cssFile = document.createElement("link");
    cssFile.setAttribute("rel", "stylesheet");
    cssFile.setAttribute("type", "text/css");
    cssFile.onload = function() {
        success();
    };
    cssFile.setAttribute("href", url);
    document.getElementsByTagName("head")[0].appendChild(cssFile);
}


function CCT_loadScript(url, success) {
     var script = document.createElement('script');
     script.src = url;
     var head = document.getElementsByTagName('head')[0],
     done = false;
     head.appendChild(script);
     script.onload = script.onreadystatechange = function() {
        if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
             done = true;
             success();
             script.onload = script.onreadystatechange = null;
             head.removeChild(script);
        }
    };
}

function CCT_detectATCButton() {
    var atcButtonSelectors = [
        '*[cct-atc-override="true"]:not([disabled])',
        '*[class*="os__add_to_cart"]:not([disabled])',
        '*[id="new-form-atc"]:not([disabled])',
        '*[class*="product__add-to-cart"]:not([disabled])',
        'input[name="add"]:not([disabled]):not([class*="quick-action-button"])',
        'button[name="add"]:not([disabled]):not([class*="quick-action-button"])',
        'button[id="add"]:not([disabled]):not([class*="quick-action-button"])',
        'input[id="add"]:not([disabled]):not([class*="quick-action-button"])',
        'button[id="addToCart"]:not([disabled])',
        'input[id="addToCart"]:not([disabled])',
        'input[name="AddToCart"]:not([disabled])',
        'button[name="AddToCart"]:not([disabled])',
        'input[id="AddToCart"]:not([disabled])',
        'button[id="AddToCart"]:not([disabled])',
        '*[class*="product-form--atc-button"]:not([disabled])',
        '*[id="shopify_add_to_cart"]:not([disabled])',
        '*[class*="product-form--add-to-cart"]:not([disabled])',
        '*[class*="ProductForm__AddToCart"]:not([disabled])',
        '*[class*="add-to-cart"]:not([disabled])',
        '*[class*="addtocart"]:not([disabled])',
        '*[class*="AddToCart"]:not([disabled])',
        '*[data-action="add-to-cart"]:not([disabled])',
        '*[data-add-to-cart]:not([disabled]):not([class*="quick-action-button"])',
        '*[name="add"]:not([disabled]):not([class*="quick-action-button"])',
        '*[id="add-to-cart"]:not([disabled])',
        '*[data-lhi="trans_buynow"]:not([disabled])',
        '*[class*="add_to_cart_button"]:not([disabled])',
        '*[data-add-to-cart-text]:not([disabled])',
        '*[class*="btn-cart"]:not([disabled])',
        '*[data-add-cart]:not([disabled])',
        '*[class*="product-buy-buttons--cta"]:not([disabled])',
        '*[data-aid="product-form-submit-button"]:not([disabled])',
        '*[class*="lh-add_to_cart"]:not([disabled])',
        '*[data-text-add-to-cart]:not([disabled])',
        '*[data-pf-type="ProductATC"]:not([disabled])',
        '*[class*="single_add_to_cart_button"]:not([disabled])',
        '*[data-text*="Add To Cart"]:not([disabled])',
        '*[id="adbtn"]:not([disabled])',
        '*[class*="addToCart"]:not([disabled])',
        '*[data-add-button]:not([disabled])',
        '*[data-buy-button]:not([disabled])',
        '*[class*="es-popup-button-product"]:not([disabled])',
    ];

    for (var selector of atcButtonSelectors) {
        var elementSearchResult = document.querySelector(selector);
        if ((elementSearchResult !== null) && (elementSearchResult.getAttribute('cct-ignore') === "true")) {
            continue;
        }

        if (elementSearchResult !== null) {
            return elementSearchResult;
        }
    }

    return null;
}

function CCT_detectCheckoutButton() {
    CCT_ignoreCheckoutElements();
	var resultElement = null;
	var checkoutButtonSelectors = [
	    '*[cct-checkout-override="true"]',
	    '*[class*="upcart-checkout-button"]',
		'*[class*="rebuy-cart__checkout-button"]',
		'*[name="checkout"]:not([disabled])',
		'*[name="goto_pp"]:not([disabled])',
		'*[name="goto_gc"]:not([disabled])',
		'*[value*="Checkout"]',
		'*[value*="Check out"]',
		'*[href*="/checkout"]:not([href*="front_end/login"]):not([href*="/manage/subscription/"]):not([href*="/admin/settings/checkout"]):not([href*="checkout-sandbox"]):not([href*="asset"]):not([data-mce-href])',
		'*[onclick*="/checkout"]',
		'*[name="qbk-checkout"]',
		'*[class*=satcb-cs-checkout-btn]',
        '*[class*="evm_upsell_checkout"]',
        '*[class*="ymq-fake-checkout-btn"]:not([disabled])',
        '*[name="checkout-exemptify"]:not([disabled])',
        '*[id="checkout"]:not([disabled])',
        '*[data-cart-checkout-button]',
        '*[class*="cart-button-checkout"]',
        '*[class*="Cart__Checkout"]',
        '*[class*="checkout__fbtn"]',
        '*[name="ddcheckout"]:not([disabled])',
        '*[class*="btnCheckout"]:not([disabled])',
        '*[id="mu-checkout-button"]:not([disabled])',
	];
	var cartFormSelectors = [
		'input[type="submit"]:not([disabled])',
		'input[type="button"]:not([disabled])'
	];

	for (var selector of checkoutButtonSelectors) {
        if (selector.indexOf('href*="/checkout"') > -1 && window.CCT_THEME_NAME.indexOf('providence') > -1) {
            continue;
        }

		var elementSearchResult = document.querySelectorAll(selector);
		if (elementSearchResult.length > 1) {

		    if (elementSearchResult[1].getAttribute('cct-ignore') === "true") {
		        continue;
		    }

			return elementSearchResult[1];
		} else if (elementSearchResult.length > 0) {
		    if (elementSearchResult[0].getAttribute('cct-ignore') === "true") {
		        continue;
		    }

			return elementSearchResult[0];
		}
	}

	var cartFormElement = document.querySelector('form[action="/cart"]');
	if (cartFormElement !== null) {
		for (var selector of cartFormSelectors) {
			var element = cartFormElement.querySelector(selector);
			if (element !== null) {
				return element;
			}
		}
	}

	return null;
}

function CCT_isElementVisible(element) {
    if (element.getAttribute('cct-override') === 'true' || window.CCT_THEME_NAME.indexOf('impact') > -1) {
        return true;
    }

	if (element.offsetWidth === 0 || element.offsetHeight === 0) {
	    return false;
	}

	var height = document.documentElement.clientHeight,
		rects = element.getClientRects(),
		on_top = function (r) {
			var x = (r.left + r.right) / 2,
				y = (r.top + r.bottom) / 2;
			var pointElement = document.elementFromPoint(x, y);
			var isParentVisible = (pointElement !== null && (pointElement.parentElement === element))
			return ((pointElement === element) || (isParentVisible));
		};
	for (var i = 0, l = rects.length; i < l; i++) {
		var r = rects[i],
			in_viewport = r.top > 0 ? r.top <= height : (r.bottom > 0 && r.bottom <= height);
		if (in_viewport && on_top(r)) return true;
	}
	return false;
}

function CCT_waitForCartDrawer() {
	if (document.getElementById('effectiveAppsCDTContainer') !== null) {
		return;
	}

	var atcButtonElement = null;
    if ('False' === 'True' && location.pathname.indexOf('/products') > -1) {
        atcButtonElement = CCT_detectATCButton();
    }

    if (atcButtonElement !== null) {
        if (window.effectiveAppsTimerSp.length > 0) {
            if (window.effectiveAppsCctAllowedProducts.indexOf(ShopifyAnalytics.meta.product.id.toString()) > -1) {
                CCT_attachToATC(atcButtonElement);
            }
        }
        else {
            CCT_attachToATC(atcButtonElement);
        }

        CCT_startTimer();
        clearInterval(window.EFFECTIVE_APPS_CCT_CART_LISTENER);
        return;
    }

	var checkoutButtonElement = CCT_detectCheckoutButton();
	if (checkoutButtonElement === null) {
		return;
	}

	if (CCT_isElementVisible(checkoutButtonElement) === true) {
	    if (window.effectiveAppsTimerSp.length > 0) {
            jQuery.getJSON('/cart.js').done(function(data) {
                for (var item of data['items']) {
                    if (window.effectiveAppsCctAllowedProducts.indexOf(item["product_id"].toString()) > -1) {
                        CCT_attachToCart();
                        CCT_startTimer();
                        break;
                    }
                }
            });
        }
        else {
		    CCT_attachToCart();
            CCT_startTimer();
	    }
	}
}

function loadFlipClock(callback) {
    CCT_loadScript('https://cdnjs.cloudflare.com/ajax/libs/flipclock/0.7.8/flipclock.js', function() {
        CCT_loadStylesheet('https://cdnjs.cloudflare.com/ajax/libs/flipclock/0.7.8/flipclock.css', callback);
    });
}

function CCT_getShopifyThemeName() {
    try {
        if (window.CCT_THEME_NAME_OVERRIDE !== undefined) {
            return window.CCT_THEME_NAME_OVERRIDE;
        }

        if (window.BOOMR !== undefined && window.BOOMR.themeName !== undefined) {
            return window.BOOMR.themeName.toLowerCase();
        }
        else {
            return Shopify.theme.name.toLowerCase();
        }
    }
    catch (err) {
        return "";
    }
}

function CCT_preMain() {
    if ('1' === '2') {
        loadFlipClock(function() {
            var additionalCss = '';
            var textFontSize = 'font-size: 16px;';
            if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
                additionalCss = 'font-size: 0.4em;';
                textFontSize = 'font-size: 0.75em;';
            }

            jQuery('head').append('<style>.flip-clock-wrapper{display: block; margin: 0 auto; margin-top: 2em; max-width: 300px; text-align: center; zoom: 0.55; -moz-transform: scale(0.55); padding-bottom: 10px; padding-top: 0; pointer-events: none; }.flip-clock{display: inline-block; width: auto; zoom: 0.55; -moz-transform: scale(0.55);}.flip-clock-label { ' + textFontSize + ' !important; margin-right: -7px !important; color: #000000 !important;  }.flip-clock-wrapper ul li a div div.inn{color: #CCCCCC !important; background-color: #333333 !important; ' + additionalCss + '} .flip-clock-dot{background: #323434 !important;}</style>');
            CCT_main();
        });
    }
    else {
        CCT_main();
    }
}

function CCT_ignoreCheckoutElements() {
    var selectorsToIgnore = ['[class*="gtapps_checkout"]'];
    for (var selectorToIgnore of selectorsToIgnore) {
        try {
            var elementSearchResult = document.querySelector(selectorToIgnore);
            if (elementSearchResult !== null) {
                elementSearchResult.setAttribute('cct-ignore', 'true');
            }
        }
        catch(err) {

        }
    }
}

function applyCssCustomizations() {
    if (window.CCT_THEME_NAME.indexOf("motion") > -1) {
        jQuery('head').append('<style>#effectiveAppsCDTContainer p { margin: 0 0 0 0 !important; }</style>');
    }
}

function CCT_main() {
    console.log('%c------ Scarcity: Cart Countdown Timer by Effective Apps is Initializing ------', 'color: cyan');
    console.log('%c------ Contact us at support@effectify.co for help and questions about the app ------', 'color: cyan');
    window.CCT_THEME_NAME = CCT_getShopifyThemeName();
    window.EFFECTIVE_APPS_CCT_TEXT = `<p style="text-align: center;"><strong style="font-size: 20px; color: #000000;">Get it NOW or FOVEVER hold your peace! Your cart expires in --&gt; <span style="color: #e03e2d;"><span id="effectiveAppsCDT"></span></span></strong></p>`;
    window.EFFECTIVE_APPS_CCT_TERMINOLOGY_HOURS = `hours`;
    window.EFFECTIVE_APPS_CCT_TERMINOLOGY_MINUTES = `minutes`;
    window.EFFECTIVE_APPS_CCT_TERMINOLOGY_SECONDS = `seconds`;
    window.effectiveAppsTimerSp = '';
    window.effectiveAppsCctAllowedProducts = window.effectiveAppsTimerSp.split(',');
    if (window.CCT_SCRIPT_INJECTED === undefined) {
        window.CCT_SCRIPT_INJECTED = true;
        applyCssCustomizations();
        if ('3' === '7' && null === CCT_getLsWithExpiry('cct_payg_i')) {
            jQuery.get('https://app.rushyapp.com/ri/a4caef4605a011efa486067cdd643fd6.js');
            CCT_setLsWithExpiry('cct_payg_i', 'true', 604800000);
        }

        if ('1' === '2' && localStorage.getItem("timerRemainingSeconds551131") !== null) {
            CCT_startTimer();
        }

        if (document.location.pathname.indexOf("/cart") === -1) {
            window.EFFECTIVE_APPS_CCT_CART_LISTENER = setInterval(CCT_waitForCartDrawer, 500);
            return;
        }

        if (window.effectiveAppsTimerSp.length > 0) {
            jQuery.getJSON('/cart.js').done(function(data) {
                for (var item of data['items']) {
                    if (window.effectiveAppsCctAllowedProducts.indexOf(item["product_id"].toString()) > -1) {
                        CCT_appendToCart();
                        CCT_startTimer();
                        break;
                    }
                }
            });
        }
        else {
		    CCT_appendToCart();
            CCT_startTimer();
	    }
    }
}

if (typeof jQuery === 'undefined'){
    CCT_loadScript('https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js', CCT_preMain);
} else {
    CCT_preMain();
}