// 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 : 365,

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

    // Value of cookie
    cookieValue: 'on',

    // Message banner title
    bannerTitle: "Cookie-k:",

    // Message banner message
    bannerMessage: "A weboldal további használatával Ön hozzájárul a cookie-k használatához és elemzéséhez a felhasználói élmény tökéletesítése érdekében.",

    // Message banner dismiss button
    bannerButton: "Elfogadom",

    // Link to your cookie policy.
    bannerLinkURL: "/files/cookie_szabalyzat_nw360.pdf",

    // Link text
    bannerLinkText: "További információ.",

    createDiv: function () {
        var banner = $(
            '<div id="cookie_hasznalat" class="alert alert-danger alert-dismissible fade in" role="alert" style="position: fixed; left: 0; right: 0; bottom: 0; width: 100%; z-index: 99999; margin-bottom: 0;">'+
				'<div class="container">'+
					'<p>' + this.bannerMessage + '<br /><a href="' + this.bannerLinkURL + '" class="alert-link" target="_blank">' + this.bannerLinkText + '</a></p>'+
					'<button type="button" class="btn btn-xs btn-primary" onclick="C.createCookie(C.cookieName, C.cookieValue, C.cookieDuration)" data-dismiss="alert" aria-label="' + this.bannerButton + '">' + this.bannerButton + '</button>'+
				'</div>'+
			'</div>'
        );
        $("body").prepend(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=/";

		var bootstrap3_enabled = (typeof $().emulateTransitionEnd == 'function');
		if(!bootstrap3_enabled) {
			$('#cookie_hasznalat').fadeOut();
		}
    },

    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();
});