var ueAcceptJs = function(){
var cookieName = '_uecookie';
var cookieNameAge = '_mayoriadeedad';
var cookies = [
{name:'analytics',id:'ga', removeCookies:['_ga','_gat','_gid','_gat_*', '__utma', '__utmb', '__utmc', '__utmt', '__utmz'], text: 'Cookies Analíticas'},
// {name:'alexa' ,id:'ale', removeCookies:['__asc','__auc'], text: 'Cookies Alexa'},
// {name:'newrelic' ,id:'nre', removeCookies:['JSESSIONID'], text: 'Cookies New Relic'},
{name:'tecnicas', id:'tec', text:'Cookies técnicas (obligatorias)', checked:true, disabled:true}
];
var enableCookies = ['ga', 'tec'];
var modifyText = "\
Configure sus preferencias:
\
";
var dialog = null;
var buttonAccept = null;
var buttonModify = null;
var buttonExit = null;
var buttonCookiepolicy = null;
var buttonBack = null;
var text = null;
var originalText = '';
var originalButtons = {};
var initialize = function(){
dialog = document.getElementsByClassName('ue-accept-bg')[0];
buttonAccept = document.getElementsByClassName('ue-accept-button-accept')[0];
// buttonModify = document.getElementsByClassName('ue-accept-button-modify')[0];
// buttonBack = document.getElementsByClassName('ue-accept-button-return')[0];
buttonExit = document.getElementsByClassName('ue-accept-button-exit')[0];
buttonCookiepolicy = document.getElementsByClassName('ue-accept-cookie-policy')[0];
text = document.getElementsByClassName('ue-accept-text')[0]
originalText = text.innerHTML;
originalButtons = {accept:buttonAccept.innerText,modify:buttonExit.innerText};
setEvents();
};
var showDialog = function(){
initialize();
setEnableCookiesFromCookie();
dialog.style.display = 'block';
};
var hideDialog = function(){
dialog.style.display = 'none';
};
var buttonAcceptClick = function(){
var oldConfig = getCookie();
if (oldConfig === false){
oldConfig = enableCookiesToString();
}
//var oldConfig = getCookie() || enableCookiesToString();
setEnableCookiesFromDialog();
saveCookie();
if (oldConfig !== getCookie()){
removeCookies();
location.reload();
return
}
hideDialog();
};
// var buttonModifyClick = function(){
// if (originalText == text.innerHTML) {
// text.innerHTML = setModifyText();
// buttonAccept.innerText = 'Guardar';
// buttonModify.innerText = 'Volver';
// buttonExit.style.display = 'none';
// buttonModify.style.display = 'none';
// buttonCookiepolicy.style.display = 'none';
// buttonBack.style.display = 'inline';
// } else {
// text.innerHTML = originalText;
// buttonAccept.innerText = originalButtons.accept;
// buttonModify.innerText = originalButtons.modify;
// buttonExit.style.display = 'inline';
// buttonModify.style.display = 'inline';
// buttonCookiepolicy.style.display = 'inline';
// buttonBack.style.display = 'none';
// }
// };
var buttonExitClick = function(){
window.location.href = "https://www.google.es";
};
var buttonCookiepolicyClick = function(){
window.open(url_cookie,'_blank');
};
// var setModifyText = function(){
// var text = modifyText;
// for(index in cookies){
// var item = cookies[index]
// if(!is_mobile){
// text = text + checkboxItem(item.id,item.text,item.disabled,item.checked) +'
';
// } else {
// text = text + checkboxItem(item.id,item.text,item.disabled,item.checked);
// }
// }
// // text = text + 'Más información';
// return ''+text+'
';
// };
// var checkboxItem = function(code,text,disabled,checked){
// checked = checked || false;
// var checked = (checked || enableCookies.indexOf(code) !== -1) ? 'checked' : '';
// var disabled = disabled ? 'disabled' : '';
// var input =
// "";
// return input;
// };
var setEvents = function(){
buttonAccept.addEventListener('click',buttonAcceptClick, false);
// buttonModify.addEventListener('click',buttonModifyClick, false);
// buttonBack.addEventListener('click',buttonModifyClick, false);
buttonExit.addEventListener('click',buttonExitClick, false);
buttonCookiepolicy.addEventListener('click',buttonCookiepolicyClick, false);
};
var getCookie = function(){
var value = "; " + document.cookie;
var parts = value.split("; " + cookieName + "=");
if(parts.length == 2){
return parts.pop().split(';').shift();
}
return false;
};
var setEnableCookiesFromDialog = function(){
var inputs = document.getElementsByClassName('ue-accept-chekbox');
if (inputs.length == 0){
return;
}
enableCookies = [];
for(index in inputs){
if(inputs[index].checked){
enableCookies.push(inputs[index].value);
}
}
};
var saveCookie = function(){
var date = new Date();
var value = enableCookiesToString();
date.setTime(date.getTime()+(1000*60*60*24*365*10));
var domain = 'mundoanuncioerotico.com';
document.cookie = cookieName + '=' + value + '; expires=' + date.toGMTString() + '; path=/; domain=' + domain;
document.cookie = cookieNameAge + '=1; expires=' + date.toGMTString() + '; path=/; domain=' + domain;
};
var enableCookiesToString = function(){
return JSON.stringify(enableCookies);
};
var setEnableCookiesFromCookie = function(){
var cookie = getCookie();
if (cookie == false){
return;
}
enableCookies = JSON.parse(cookie);
};
var removeCookies = function(){
for(index in cookies){
var item = cookies[index];
if (enableCookies.indexOf(item.id) == -1 ){
for(index2 in item.removeCookies){
removeCookie(item.removeCookies[index2]);
}
}
}
};
var removeCookie = function(cookieName){
if (/\*$/.test(cookieName)){
var regExp = new RegExp(cookieName.replace('*','.*?='));
newCookieName = document.cookie.match(regExp);
if(newCookieName !== null){
cookieName = newCookieName[0].replace('=','');
}
}
var domain = window.location.hostname;
var current_domain = 'mundoanuncioerotico.com';
document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;domain='+domain+';';
document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;domain='+current_domain+';';
document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;domain='+domain.replace('www.','')+';';
document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;';
};
var checkCookies = function(cookieCode){
cookieCode = cookieCode || false;
if(!cookieCode){
return true;
}
setEnableCookiesFromCookie();
return enableCookies.indexOf(cookieCode) != -1;
};
var url_cookie;
var current_country;
var is_mobile;
return {
init: function($urlCookie){
url_cookie = $urlCookie;
//current_country = $currentCountry;
//is_mobile = $isMobile;
console.log(window.location.pathname);
if(getCookie() == false){
if(url_cookie != window.location.pathname) {
showDialog();
}
}
},
showDialog: function(){
showDialog();
},
checkCookies: function(cookieCode){
return checkCookies(cookieCode);
},
addExternalScript: function(cookieCode,src){
if(checkCookies(cookieCode)){
var s = document.createElement('script');
s.setAttribute('src',src);
s.setAttribute('async','');
document.getElementsByTagName('body')[0].appendChild(s);
}
}
};
}();