// Creare's 'Implied Consent' EU Cookie Law Banner v:2.4
// Conceived by Robert Kent, James Bavington & Tom Foyster
// Modified by Simon Freytag for syntax, namespace, jQuery and Bootstrap

C = {
    // Number of days before the cookie expires, and the banner reappears
    cookieDuration : 14,

    // Name of our cookie
    cookieName: 'complianceCookie',

    // Value of cookie
    cookieValue: 'on',

    // Message banner title
    bannerTitle: "<p class="+'"cookie-js-title"'+">Pravidlá ochrany osobných údajov:</p>",

    // Message banner message
    bannerMessage: "<p class="+'"cookie-js-content"'+">"+('V našom najnovšom vyhlásení o ochrane osobných údajov sa dozviete, ako zaručujeme ochranu vašich údajov. Pre zlepšovanie vášho zážitku na našich stránkach používame cookies. Tieto súbory nám poskytujú informácie o navštevovaní našich stránok používateľmi, avšak neuchovávajú osobné údaje. Kliknutím na Pokračovať súhlasíte, aby naša stránka používala cookies.  Vaše rozhodnutie a nastavenia súborov cookie môžete kedykoľvek zmeniť vo vašom prehliadači.').replace(/"/g, '\\"')+"</p>",

    // Message banner dismiss button
    bannerButton: "<p class="+'"cookie-js-button"'+">Pokračovať</p>",

    // Link to your cookie policy.
    bannerLinkURL: "/ochrana-osobnych-udajov-impressum/",

    // Link text
    bannerLinkText: "Viac informácií",

    // Text alignment
    alertAlign: "center",
    
    // Link text
    buttonClass: "btn-success btn-xs",    

    createDiv: function () {
        var banner = $(
            '<div class="TCCookieConsetDiv alert alert-success alert-dismissible text-'+
             this.alertAlign +' fade in" ' +
            'role="alert" style="position: fixed; bottom: 0; width: 100%; ' +
            'margin-bottom: 0"><strong>' + this.bannerTitle + '</strong> ' +
            this.bannerMessage + '<p class="cookie-js-utltext"> <a href="' + this.bannerLinkURL + '">' +
            this.bannerLinkText + '</a></p> <button type="button" class="btn ' +
             this.buttonClass + '" onclick="C.createCookie(C.cookieName, C.cookieValue' +
            ', C.cookieDuration)" data-dismiss="alert" aria-label="Close">' +
            this.bannerButton + '</button></div>'
        )
        $("body").append(banner)
    },

    createCookie: function(name, value, days) {
        //console.log("Create cookie")
        var expires = ""
        if (days) {
            var date = new Date()
            date.setTime(date.getTime() + (days*24*60*60*1000))
            expires = "; expires=" + date.toGMTString()
        }
        document.cookie = name + "=" + value + expires + "; path=/";

        console.log('setcookie');

        gtag('consent', 'update', {
          'ad_user_data': 'granted',
          'ad_personalization': 'granted'
        });
    },

    checkCookie: function(name) {
        var nameEQ = name + "="
        var ca = document.cookie.split(';')
        for(var i = 0; i < ca.length; i++) {
            var c = ca[i]
            while (c.charAt(0)==' ')
                c = c.substring(1, c.length)
            if (c.indexOf(nameEQ) == 0) 
                return c.substring(nameEQ.length, c.length)
        }
        return null
    },

    init: function() {
        if (this.checkCookie(this.cookieName) != this.cookieValue)
            this.createDiv()
    }
}

$(document).ready(function() {
    C.init()
})