
$.ajaxSetup({
	async: false
});

function add_style_css(){
			var style = document.createElement('style');
			style.type = 'text/css';
			style.innerHTML='.accept_cookie_button:hover{opacity: 0.7;}';
		document.getElementsByTagName('head')[0].appendChild(style);
}

add_style_css();

var shop = 'le-toy-van.myshopify.com';
var referer = 'https://letoyvan.co.uk/';
var url_array = '["https:","","letoyvan.co.uk",""]';

var banner_enable = 'enable';
var banner_message = 'This website uses cookies to ensure you get the best experience on our website.';
var policy_url = 'https://letoyvan.co.uk/policies/privacy-policy';
var ok_button_text = 'Got it!';
var info_link_text = 'Read more';
var eu_countries = 'enable';
var banner_color = 'rgb(129, 129, 128)';
var button_color = 'rgba(0, 194, 255, 0.53)';
var button_text_color = 'rgb(129, 129, 129)';
var banner_link_color = 'rgba(0, 194, 255, 0.53)';
var banner_text_color = 'rgb(255, 255, 255)';

var eu_all_countries = ["Austria","Belgium","Bulgaria","Croatia","Cyprus","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Ireland","Italy","Latvia","Lithuania","Luxembourg","Malta","Netherlands","Poland","Portugal","Romania","Slovakia","Slovenia","Spain","Sweden","United Kingdom"];

var html ="";
		html+='<div style="display: none; bottom: 0px;background-color: '+banner_color+';padding: 10px; width : 100%;position: fixed; z-index: 999999999;" id="cookie_policy" class="cookie_policy">';
			html+= '<div style="padding-right: 21px;font-size:16px; display: flex; padding-left: 2rem; line-height: 1.5;">';
				html+= '<div style="width: 90%; float: left;">';
					html+='<span style="margin-bottom: 0;color: '+banner_text_color+'; text-transform: none;" class="policy_message"></span>';
					if(policy_url.match(/http/g)){
						html +='<a href="'+policy_url+'" style="text-decoration: underline; color: '+banner_link_color+'; padding-left: 15px;" target="_blank">'+info_link_text+'</a>';

					}else{
						html +='<a href="https://'+policy_url+'" style="text-decoration: underline; color: '+banner_link_color+'; padding-left: 15px;" target="_blank">'+info_link_text+'</a>';
					}
				html+='</div>';
				html+= '<button class="accept_cookie_button" style="width: auto !important; border-radius: 3px;right: 0px; float: right; white-space: nowrap; padding: 1px 12px; border: 0px solid #ccc; margin: auto; color: '+button_text_color+'; background-color: '+button_color+'; font-size:16px;" onclick="store_cookie();">'+ok_button_text+'</button>';
			html+= '</div>';
		html+='</div>';

var html2 ="";
		html2 +='<div style="display: none;background-color: '+banner_color+';padding: 10px; width : 100%;position: absolute; z-index: 999999999;" id="cookie_policy" class="cookie_policy">';
			html2 += '<div style="padding-right: 21px;font-size:16px; display: flex; padding-left: 2rem; line-height: 1.5;">';
				html2 += '<div style="width: 90%; float: left;">';
					html2 +='<span style="margin-bottom: 0;color: '+banner_text_color+'; text-transform: none;" class="policy_message"></span>';
					if(policy_url.match(/http/g)){
						html2 +='<a href="'+policy_url+'" style="text-decoration: underline; color: '+banner_link_color+'; padding-left: 15px;" target="_blank">'+info_link_text+'</a>';

					}else{
						html2 +='<a href="https://'+policy_url+'" style="text-decoration: underline; color: '+banner_link_color+'; padding-left: 15px;" target="_blank">'+info_link_text+'</a>';
					}
				html2 +='</div>';
				html2 += '<button class="accept_cookie_button" style="width: auto !important; border-radius: 3px;right: 0px; float: right; white-space: nowrap; padding: 1px 12px; border: 0px solid #ccc; margin: auto; color: '+button_text_color+'; background-color: '+button_color+'; font-size:16px;">'+ok_button_text+'</button>';
			html2 += '</div>';
		html2 +='</div>';

	if(banner_enable == 'enable'){
		if(eu_countries == 'enable'){
			$.getJSON('https://api.db-ip.com/v2/free/self', function(){}).done( function( location )
			{
				var eu_county_name = location['countryName'];
	       		if( eu_all_countries.indexOf(eu_county_name) >= 0 ) {
					if($(".cookie_bar_manually_install").length > 0 ){
						$(".cookie_bar_manually_install").append(html2);
						$('.policy_message')[0].innerHTML = banner_message;
						$("#cookie_policy").show();
					}else{
						$("body").append(html);
						$('.policy_message')[0].innerHTML = banner_message;
						var check_is_cookie_set = checkCookie();
						if (!check_is_cookie_set){
							$("#cookie_policy").show();
						}
					}
	       		}else{

	       		};
			});
		}else{
			if($(".cookie_bar_manually_install").length > 0 ){
				$(".cookie_bar_manually_install").append(html2);
				$('.policy_message')[0].innerHTML = banner_message;
				$("#cookie_policy").show();
			}else{
				$("body").append(html);
				$('.policy_message')[0].innerHTML = banner_message;
				var check_is_cookie_set = checkCookie();
				if (!check_is_cookie_set){
					$("#cookie_policy").show();
				}
			}
		}
	}

function store_cookie(){

	$("#cookie_policy").hide();
	$('.cookie_policy').remove();

	setCookie('eu_cookie');
}

function setCookie(eu_cookie) {
    document.cookie = eu_cookie + "=" + "enable";
}

function getCookie(eu_cookie) {
    var policy = eu_cookie + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(policy) == 0) {
            return c.substring(policy.length, c.length);
        }
    }
    return "";
}

function checkCookie() {
    var eu_cookie = getCookie("eu_cookie");

    if ( eu_cookie != "" ) {
        return true;
    } else {
       return false;
    }
}