// Vouchers
$(document).ready(function () {
    // Update Month & Year
    const rh_month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], rh_d = new Date();
    $('#voucherMonthShown').text(rh_month[rh_d.getMonth()]);
    $('#voucheYearShown').text(rh_d.getFullYear());
    // Active tooltip
    $(function () {
        $('[data-toggle="tooltip"]').tooltip();
    });
    // Reset tooltip message
    $('.voucherCodeCopy').mouseout(function () {
        $(this).tooltip('hide').attr('data-original-title', 'Copy code');
    });
    // Copy code and update tooltip message
    $('.voucherCodeCopy').click(function () {
        navigator.clipboard.writeText($(this).attr('value'));
        $(this).tooltip('hide').attr('data-original-title', 'Copied to clipboard').tooltip('show');
    });
    // Fallback check for active vouchers
    if ($('.activeVoucherCampaign').length === 0) {
        $('.noVouchersFallBack').removeClass('d-none');
    };
});
// competitions
$(document).ready(function () {
    // Fallback check for competitions
    if ($('.activeCompetitionsCampaign').length === 0) {
        $('.noCompetitionsFallBack').removeClass('d-none');
    };
});
// Adestra Forms

$(document).ready(function () {

    setTimeout(function () {
$(function() {
    if ( document.location.href.indexOf('?formSubmit=Success') > -1 ) {
        $('#adFormSuccessMessage').show();
    } else  if ( document.location.href.indexOf('?formSubmit=CompetitionSuccess') > -1 ) {
        $('#adFormCompetitionSuccessMessage').show();
    }
});

}, 1000);

});

// END - Adestra Forms
// Focus Campaign product recommendations
$(document).ready(function () {
    if ($("div[class*='bannerX-'].cms-component").length) {
        $("div[class*='bannerX-'].cms-component").each(function (index) {
            var cbp_cid = $(this).attr('class');
            cbp_cid = '.' + cbp_cid.substring(cbp_cid.lastIndexOf(" ") + 1) + '-products';
            $(cbp_cid + ' .product-container').each(function (index) {
              //  console.log( $(this).find('a') );
                var cbp_ql = $(this).data('ql'),
                    cbp_inject = '<div class="col pl-0 m-0 p-0 fullArticleClickZone mr-3"><div class="row p-0 m-0 rounded py-4 text-center"><img src="/images/product/uni2/' + cbp_ql.substring(0, 2).toLowerCase() + '/' + cbp_ql.toLowerCase() + '_large.jpg" class="w-75 rounded"></div><div class="row p-0 m-0"><p class="h4 btfont-regular"><a class="color-white" href="/' + cbp_ql + '">' + $(this).find('a.btfont-regular').attr('title') + '</a></p></div><div class="row m-0 p-0"><p class="btfont-regular color-white">' + $(this).find('.lprice').text() + '</p></div></div>';
                $('.bannerX-product-row').append(cbp_inject);
            });
        });
    }
});
// Custom content based upon a ReferrerId 
$(document).ready(function () {
    function customBlockShow() {
        var refid = $.cookie("ReferrerID");
        if (refid !== "CL01" && refid !== "M100" && refid !== "VR00" && refid !== "F4LC" && refid !== "BT04") {
            $('.custom140620191435').removeClass('custom140620191435');
        }
        if (refid === "CI02") {
            $('.custom180320201556').removeClass('custom180320201556');
        };
    };
    setTimeout(function () {
        customBlockShow();
    }, 5000);
});