function agegate_isMobileTablet(){ let check = false; (function(a){ if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))){ check = true; } })(navigator.userAgent||navigator.vendor||window.opera); return check;}
 class AVP { /*constructor(agegate_ldarule, agegate_tooYoungWebsite, agegate_force_minor_redirect, agegate_no_age_input) {*/ constructor(options) { this.debug = true; this.log('-- Age Gate launched'); const urlParams = new URLSearchParams(window.location.search); if (urlParams.has('agdebug')) { this.debug = true; this.log('Debug forced to true'); } else { this.debug = false; } this.log('Options:'); this.log(options); this.json_content = {}; this.agegate_content_json_loaded = false; this.user_country_json = {}; this.activeLanguage = ''; this.activeCountry = ''; this.getActiveUserInfo(); this.log('constructor setLda'); this.setLda(options['agegate_ldarule']); this.agegate_tooYoungWebsite = options['agegate_tooYoungWebsite']; this.agegate_force_minor_redirect = options['agegate_force_minor_redirect']; this.agegate_no_age_input = options['agegate_no_age_input']; this.agegate_cached_content_file = options['cached_content_file']; this.allow_switch_language = options['allow_switch_language']; this.dateOfBirth = { year: null, month: null, day: null, }; this.params = {}; this.show = false; this.fieldErrors = []; this.avpBody = null; this.today = new Date(); this.form = null; this.yearInput = null; this.monthInput = null; this.dayInput = null; this.monthInputWrapper = null; this.dayInputWrapper = null; this.rememberMeInput = null; this.fieldErrorMessage = null; this.fieldErrorMessageEl = null; this.submitButton = null; this.isLegalThisYear = false; this.isLegalThisMonth = false; this.initMutationObserver(); this.updateParams(); } log(message){ if(this.debug){ console.log(message); } } setLda(ldaRules){ this.log('-- setLda'); this.ldaRules = ldaRules; this.log(this.ldaRules); this.full = this.ldaRules.full; this.inputOrder = (typeof this.ldaRules.format === 'string' ? this.ldaRules.format.split('-'):''); this.inputOrder = this.inputOrder = (typeof this.inputOrder === 'array' ? this.inputOrder.map(input => { switch(input){ case 'yyyy': return 'year'; case 'mm': return 'month'; case 'dd': return 'day'; } }):[]); } updateParams(){ if(window.location.search !== ''){ this.params = (window.location.search.match( new RegExp("([^?=&]+)(=([^&]*))?", 'g' )) || []).reduce( function( result, each, n, every ){ let[ key, value ] = each.split( '=' ); result[ key ] = value; return( result ); }, {}); } } localStorageTest(){ var t = 't'; try { localStorage.setItem(t, t); localStorage.removeItem(t); return true; } catch(e) { return false; } } get show() { return this._show; } set show(value) { if(this.avpBody != null){ if(value == false){ document.body.classList.remove("avp-showing"); this.avpBody.style.display = 'none'; } else { if(typeof AVPActions !== 'undefined' && typeof AVPActions.beforeShow == 'function') AVPActions.beforeShow(); } } this._show = value; } getAvpUserID(){ return window.avpuid || window.localStorage.getItem('avpuid'); } isAlreadyPassed(){ let ageGateStorageData = this.localStorageTest() === true && window.sessionStorage.getItem('ageGatePassed') != null ? window.sessionStorage.getItem('ageGatePassed') : window.localStorage.getItem('ageGatePassed'); let ageGateCookieData = this.localStorageTest() === true ? ageGateStorageData : this.getCookie('ageGatePassed'); let passThrough = /[?&]?(AvpPassThrough=1|avp=0)[^&?]*/gi.test(window.location.href); return ageGateCookieData; } checkForPassedData(){ if(window.location.href.includes("/wp-admin/")) { this.show = true; return false; } let ageGateStorageData = this.localStorageTest() === true && window.sessionStorage.getItem('ageGatePassed') != null ? window.sessionStorage.getItem('ageGatePassed') : window.localStorage.getItem('ageGatePassed'); let ageGateCookieData = this.localStorageTest() === true ? ageGateStorageData : this.getCookie('ageGatePassed'); let passThrough = /[?&]?(AvpPassThrough=1|avp=0)[^&?]*/gi.test(window.location.href); this.removePassedThroughParam(); if (!ageGateCookieData) { if(passThrough){ if(typeof AVPActions !== 'undefined' && typeof AVPActions.passedThrough == 'function') AVPActions.passedThrough(); if(typeof AVPActions !== 'undefined' && typeof AVPActions.passed == 'function') AVPActions.passed(); window.localStorage.setItem('avpuid', window.avpuid); this.setAgeGateData({ age: null, dateOfBirth: null, dateOfBirthString: null, passed: this.today.getFullYear() + '-' + (this.today.getMonth() + 1) + '-' + this.today.getDate() }); this.show = false; return true; } else { this.show = true; return false; } } else { ageGateCookieData = JSON.parse(ageGateCookieData); if(ageGateCookieData.tooYoung !== undefined && ageGateCookieData.tooYoung === true){ if(this.agegate_force_minor_redirect) { this.redirectTooYoung(); } this.show = true; return false; } window.localStorage.setItem('avpuid', window.avpuid); if(typeof AVPActions !== 'undefined' && typeof AVPActions.passed == 'function') AVPActions.passed(); this.show = false; return true; } } removePassedThroughParam(){ if (!Object.keys(this.params).length) return; let baseUrl = window.location.href.split('?')[0]; let paramStrings = []; Object.entries(this.params).forEach(([key, value]) => { if (key && key.toLowerCase() === 'avppassthrough') return; let param = key; if (value !== undefined) { param += '=' + encodeURIComponent(value); } paramStrings.push(param); }); let newUrl = baseUrl; if (paramStrings.length > 0) { newUrl += '?' + paramStrings.join('&'); } window.history.replaceState({}, '', newUrl); } calcAge(dateString) { const today = new Date(); const birthDate = new Date(dateString); let age = today.getFullYear() - birthDate.getFullYear(); if (today.getMonth() < birthDate.getMonth() || (today.getMonth() === birthDate.getMonth() && today.getDate() < birthDate.getDate())) { age--; } return age; } switchToInvalidField(){ for (let i = 0; i < this.inputOrder.length; i++){ const inputName = this.inputOrder[i]; if(!this.isInputValid(inputName) && this.isInputVisible(inputName)) { if(document.activeElement != null && document.activeElement.name != null && !this.isInputValidForSwitch(document.activeElement.name.toLowerCase())) return; this.showErrorMessageIfErrorsElseRemove(); this[inputName+'Input'].focus(); return; } } } hasVisableFieldsAValue(){ if ( (this.dateOfBirth.year == null) || ( (getComputedStyle(this.monthInput).display === 'block' || getComputedStyle(this.monthInput).display === 'inline-block') && this.dateOfBirth.month == null) || ( (getComputedStyle(this.dayInput).display === 'block' || getComputedStyle(this.dayInput).display === 'inline-block') && this.dateOfBirth.day == null) ) { return false; } else { return true; } } hasVisableFieldsValidInput(){ if ( (!this.validateYear()) || (this.isMonthInputVisible() && !this.validateMonth()) || (this.isDayInputVisible() && !this.validateDay()) ) { this.switchToInvalidField(); return false; } else { return true; } } verifyAge(submitClicked) { if (!this.hasVisableFieldsValidInput()) { return; } let dateOfBirthString = this.dateOfBirth.year !== null ? this.dateOfBirth.year : ''; dateOfBirthString += this.dateOfBirth.month !== null ? '-'+('0' + this.dateOfBirth.month).slice(-2) : '-01'; dateOfBirthString += this.dateOfBirth.day !== null ? '-'+('0' + this.dateOfBirth.day).slice(-2) : '-01'; let birthDate = new Date(dateOfBirthString); let age = this.calcAge(dateOfBirthString); this.isLegalThisYear = age == this.ldaRules.age; this.isLegalThisMonth = (this.today.getMonth() - birthDate.getMonth()) === 0; if (this.isLegalThisYear && !this.isMonthInputVisible()) { this.showMonthInput(); this.monthInput.focus(); return; } if (this.isLegalThisYear && this.isLegalThisMonth && !this.validateDay()) { this.showDayInput(); this.dayInput.focus(); return; } if (age >= this.ldaRules.age) { this.dateOfBirth.month = this.dateOfBirth.month != null ? ('0' + this.dateOfBirth.month).slice(-2) : this.dateOfBirth.month; this.dateOfBirth.day = this.dateOfBirth.day != null ? ('0' + this.dateOfBirth.day).slice(-2) : this.dateOfBirth.day; let passedDateOfBirthString = this.dateOfBirth.year+'-'+this.dateOfBirth.month+'-'+this.dateOfBirth.day; this.setAgeGateData({ age: age, dateOfBirth: this.dateOfBirth, dateOfBirthString: passedDateOfBirthString, passed: this.today.getFullYear() + '-' + String("0" + (this.today.getMonth() + 1)).slice(-2) + '-' + this.today.getDate() }); if(typeof AVPActions !== 'undefined' && typeof AVPActions.passed == 'function') AVPActions.passed(); if(!!Array.from(this.avpBody.querySelectorAll('input')).filter(a => a === document.activeElement).length){ document.activeElement.blur(); } this.show = false; } else { if(true === submitClicked && this.agegate_force_minor_redirect){ this.setAgeGateData({ age: age, tooYoung: true, dateOfBirth: this.dateOfBirth }); } if(typeof AVPActions !== 'undefined' && typeof AVPActions.tooYoung == 'function') { AVPActions.tooYoung(); } if(this.submitButton != null && (getComputedStyle(this.submitButton).display === 'block' || getComputedStyle(this.submitButton).display === 'inline-block') && submitClicked){ this.removeShow(); this.avpBody.querySelector('.agegate_tooyoung-message').classList.add('agegate_show'); this.redirectTooYoung(); } else if(this.submitButton != null) { this.submitButton.style.display = 'inline-block'; this.submitButton.style.fontSize = 'inherit'; } else { this.removeShow(); this.avpBody.querySelector('.agegate_tooyoung-message').classList.add('agegate_show'); } } } noDateInputValidation(agegate){ this.form = agegate.querySelector('form.agegate_content'); this.noAgeInputCheckbox = agegate.querySelector('[name="noAgeInputCheckbox"]').checked; if(!this.noAgeInputCheckbox){ this.avpBody.querySelector('.agegate_tooyoung-message').classList.add('agegate_show'); } else { let birthDate = new Date('1980-07-31T22:30:30Z'); let age = this.calcAge(birthDate); this.dateOfBirth.year = birthDate.getFullYear(); this.dateOfBirth.month = birthDate.getMonth(); this.dateOfBirth.day = birthDate.getDate(); let passedDateOfBirthString = this.dateOfBirth.year+'-'+this.dateOfBirth.month+'-'+this.dateOfBirth.day; this.setAgeGateData({ age: age, dateOfBirth: this.dateOfBirth, dateOfBirthString: passedDateOfBirthString, passed: this.today.getFullYear() + '-' + String("0" + (this.today.getMonth() + 1)).slice(-2) + '-' + this.today.getDate() }); if(typeof AVPActions !== 'undefined' && typeof AVPActions.passed == 'function') AVPActions.passed(); this.show = false; } } redirectTooYoung(){ setTimeout(() => { if(this.agegate_tooYoungWebsite != null && this.agegate_tooYoungWebsite !== ''){ window.location.href = this.agegate_tooYoungWebsite; } }, 1337); } removeShow(){ this.avpBody.querySelector('.agegate_tooyoung-message').classList.remove('agegate_show'); this.avpBody.querySelector('.agegate_field-error-message').classList.remove('agegate_show'); } isInputValid(input){ switch(input){ case 'year': case 'yyyy': return this.validateYear(); case 'month': case 'mm': return this.validateMonth(); case 'day': case 'dd': return this.validateDay(); } } isInputValidForSwitch(input){ switch(input){ case 'year': case 'yyyy': this.validateYear(); return this.validateYearForAutoFocus(); case 'month': case 'mm': this.validateMonth(); return this.validateMonthForAutoFocus(); case 'day': case 'dd': this.validateDay(); return this.validateDayForAutoFocus(); } } isInputVisible(input){ switch(input){ case 'year': case 'yyyy': return this.isYearInputVisible(); case 'month': case 'mm': return this.isMonthInputVisible(); case 'day': case 'dd': return this.isDayInputVisible(); } } isYearInputVisible(){ if(this.yearInputWrapper != null){ return getComputedStyle(this.yearInputWrapper).display === 'none' ? false : true; } else if(this.yearInput !== null){ return getComputedStyle(this.yearInput).display === 'none' ? false : true; } return false; } isMonthInputVisible(){ if(this.monthInputWrapper != null){ return getComputedStyle(this.monthInputWrapper).display === 'none' ? false : true; } else if(this.monthInput !== null) { return getComputedStyle(this.monthInput).display === 'none' ? false : true; } return false; } showMonthInput(){ if(this.monthInputWrapper != null){ this.monthInputWrapper.style.display = 'inline-block'; } else { this.monthInput.style.display = 'inline-block'; } } isDayInputVisible(){ if(this.dayInputWrapper != null){ return getComputedStyle(this.dayInputWrapper).display === 'none' ? false : true; } else if(this.dayInput !== null){ return getComputedStyle(this.dayInput).display === 'none' ? false : true; } return false; } showDayInput(){ if(this.dayInputWrapper != null){ this.dayInputWrapper.style.display = 'inline-block'; } else { this.dayInput.style.display = 'inline-block'; } } validateYearForAutoFocus(){ let year = Number(this.dateOfBirth.year); if (year !== null && year.toString().length === 4) { return true; } return false; } validateMonthForAutoFocus(){ let month = Number(this.dateOfBirth.month); if (month !== null && month > 0 && month < 13 && ['0','1'].indexOf(this.dateOfBirth.month) === -1) return true; return false; } validateDayForAutoFocus(){ let day = Number(this.dateOfBirth.day); if(day > 0 && day <= 31 && ['0','1','2','3'].indexOf(this.dateOfBirth.day) === -1) return true; return false; } validateYear(){ let year = Number(this.dateOfBirth.year); let ix = this.fieldErrors.indexOf('year'); if (ix > -1) { this.fieldErrors.splice(ix, 1); } if ( year !== null && year.toString().length === 4 && (year > (new Date().getFullYear() - 124) ) ) { return true; } else { if(this.dateOfBirth.year != null) this.fieldErrors.push('year'); return false; } } validateMonth(){ let month = Number(this.dateOfBirth.month); let ix = this.fieldErrors.indexOf('month'); if (ix > -1) { this.fieldErrors.splice(ix, 1); } if (month !== null && this.dateOfBirth.month !== '1' && month > 0 && month < 13) { return true; } else { if(this.dateOfBirth.month != null) this.fieldErrors.push('month'); } return false; } validateDay(){ let day = Number(this.dateOfBirth.day); let year = Number(this.dateOfBirth.year); let month = Number(this.dateOfBirth.month) || 12; let ix = this.fieldErrors.indexOf('day'); if (ix > -1) { this.fieldErrors.splice(ix, 1); } if(this.dateOfBirth.day != null && ['0', '1', '2', '3'].indexOf(this.dateOfBirth.day) !== -1){ this.fieldErrors.push('day'); return false; } if((!Number(this.dateOfBirth.year) || !Number(this.dateOfBirth.month))){ if(day > 0 && day <= 31){ return true; } if(this.dateOfBirth.day != null) { this.fieldErrors.push('day'); } return false; } if((month > 12 || month <= 0) && day > 0 && day <= 31){ return true; } if(day > 0 && day <= this.daysInMonth(month - 1, year)){ return true; } else { if(this.dateOfBirth.day != null) { this.fieldErrors.push('day'); } return false; } } daysInMonth(m, y){ switch (m) { case 1 : return (y % 4 == 0 && y % 100) || y % 400 == 0 ? 29 : 28; case 8 : case 3 : case 5 : case 10 : return 30; default : return 31; } } setAgeGateData(data){ let JSONData = JSON.stringify(data); if(this.localStorageTest() === true){ if(this.rememberMeInput.checked){ window.localStorage.setItem('ageGatePassed', JSONData); } else { window.sessionStorage.setItem('ageGatePassed', JSONData); } } else { this.setCookie('ageGatePassed', JSONData, 30, this.rememberMeInput.checked); } } setCookie(name, value, exdays, rememberMe) { let d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); let expires = "expires=" + d.toUTCString(); if(rememberMe) { expires = 'expires=""'; } document.cookie = name + "=" + value + ";" + expires + ";path=/"; } getCookie(name) { name += "="; let decodedCookie = decodeURIComponent(document.cookie); let ca = decodedCookie.split(';'); for (let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return null; } showErrorMessageIfErrorsElseRemove(){ const allInputs = [...this.form.querySelectorAll('input[name="year"],input[name="month"],input[name="day"]')]; for (let i = 0; i < allInputs.length; i++){ const ageGateInput = allInputs[i]; const inputName = ageGateInput.name; if(this.fieldErrors.indexOf(inputName) !== -1){ ageGateInput.classList.add('agegate_error'); } else { ageGateInput.classList.remove('agegate_error'); } } this.updateErrorMessage(); } updateErrorMessage(){ this.removeShow(); if(this.fieldErrorMessageEl != null && this.fieldErrors.length > 0){ const fieldTitles = this.fieldErrors.map(inputName => this[inputName+'Input'].title); let errorMessage = this.fieldErrorMessage.replace('{fields}', fieldTitles.join(' & ')); if(fieldTitles.length === 3){ errorMessage = errorMessage.replace(' &', ', '); } this.fieldErrorMessageEl.innerHTML = errorMessage.charAt(0).toUpperCase() + errorMessage.slice(1); this.fieldErrorMessageEl.classList.add('agegate_show'); } else if(this.fieldErrorMessageEl != null && this.fieldErrors.length == 0) { this.fieldErrorMessageEl.classList.remove('agegate_show'); } } removeInputError(inputName, force = false){ if(this.fieldErrors.indexOf(inputName) === -1 || force == true){ this[inputName+'Input'].classList.remove('agegate_error'); this.updateErrorMessage(); } } onAgeGateExist(agegate){ this.form = agegate.querySelector('form.agegate_content'); this.noAgeInputContainer = agegate.querySelector('.agegate_noAgeInputCheckbox'); this.noAgeInputCheckbox = agegate.querySelector('[name="noAgeInputCheckbox"]'); this.yearInput = agegate.querySelector('[name="year"]'); this.monthInput = agegate.querySelector('[name="month"]'); this.dayInput = agegate.querySelector('[name="day"]'); this.yearInputWrapper = agegate.querySelector('.age-gate__year-input-wrapper'); this.monthInputWrapper = agegate.querySelector('.age-gate__month-input-wrapper'); this.dayInputWrapper = agegate.querySelector('.age-gate__day-input-wrapper'); this.rememberMeContainer = agegate.querySelector('.agegate_rememberMe'); this.rememberMeHelp = agegate.querySelector('.agegate_rememberMeHelp'); this.rememberMeInput = agegate.querySelector('input[name="rememberMe"]'); this.fieldErrorMessageEl = agegate.querySelector('.agegate_field-error-message'); if(this.fieldErrorMessageEl != null) { this.fieldErrorMessage = this.fieldErrorMessageEl.innerHTML; } this.submitButton = agegate.querySelector('.agegate_submit'); this.log('Display management'); if(this.agegate_no_age_input){ this.displayNoAgeInputFields(agegate); } else { this.displayAgeInputFields(agegate); } } displayNoAgeInputFields(agegate){ if(null!== this.noAgeInputContainer){ this.noAgeInputContainer.style.display = 'block'; } this.yearInput.style.display = 'none'; this.monthInput.style.display = 'none'; this.dayInput.style.display = 'none'; if(this.rememberMeContainer) this.rememberMeContainer.style.display = 'block'; if(this.rememberMeHelp) this.rememberMeHelp.style.display = 'block'; this.submitButton.style.display = 'inline-block'; this.submitButton.addEventListener('click', (e) => { e.preventDefault(); this.noDateInputValidation(agegate); }); } reorderInputs() { let format = this.ldaRules.format; this.log('ReorderInputs'); this.log('LDA format for reordering'); this.log(format); const container = document.querySelector('#pr_age_gate .agegate_inputs_container'); const inputDay = this.dayInput; const inputMonth = this.monthInput; const inputYear = this.yearInput; const order = format.split('-'); const inputs = { 'dd': inputDay, 'mm': inputMonth, 'yyyy': inputYear }; inputDay.remove(); inputMonth.remove(); inputYear.remove(); const fragment = document.createDocumentFragment(); order.forEach(part => { if (inputs[part]) { fragment.appendChild(inputs[part]); } }); container.insertBefore(fragment, container.firstChild); } displayAgeInputFields(agegate){ let allNumberInputs = [...agegate.querySelectorAll('input[name="year"],input[name="month"],input[name="day"]')]; /* Reorder fields list for tab management */ const order = this.ldaRules.format.split('-'); const inputsMap = { 'dd': document.querySelector('#pr_age_gate input[name="day"]'), 'mm': document.querySelector('#pr_age_gate input[name="month"]'), 'yyyy': document.querySelector('#pr_age_gate input[name="year"]') }; allNumberInputs = order.map(part => inputsMap[part]); if(null!== this.noAgeInputContainer){ this.noAgeInputContainer.style.display = 'none'; } this.yearInput.style.display = 'inline-block'; this.monthInput.style.display = 'inline-block'; this.dayInput.style.display = 'inline-block'; if(this.rememberMeContainer) this.rememberMeContainer.style.display = 'block'; if(this.rememberMeHelp) this.rememberMeHelp.style.display = 'block'; this.submitButton.style.display = 'inline-block'; this.submitButton.removeEventListener('click', (e) => { e.preventDefault(); this.noDateInputValidation(agegate); }); this.reorderInputs(); if(!this.full){ if(null!==this.monthInput){ this.monthInput.style.display = 'none'; } if(null!==this.dayInput){ this.dayInput.style.display = 'none'; } if(null!==this.submitButton){ this.submitButton.style.display = 'none'; } } this.log('Event listeners'); this.log(this.form); if (this.form != null){ this.form.addEventListener('submit', (e) => { e.preventDefault(); this.verifyAge(true); }); } let inputIx = 1; for (let i = 0; i < allNumberInputs.length; i++){ if(allNumberInputs[i] != null && ( getComputedStyle(allNumberInputs[i]).display == 'block' || getComputedStyle(allNumberInputs[i]).display == 'inline-block' ) && typeof allNumberInputs[i].focus == 'function' && !agegate_isMobileTablet()){ setTimeout(() => { allNumberInputs[i].focus(); }, 1); break; } } for (let i = 0; i < allNumberInputs.length; i++){ const ageGateInput = allNumberInputs[i]; const inputName = ageGateInput.name; ageGateInput.addEventListener('input', (e) => { this.dateOfBirth[inputName] = e.target.value == '' ? null : e.target.value; let fieldsAreValid = this.hasVisableFieldsValidInput(); this.removeInputError(inputName); if (e.target.value.length === e.target.maxLength) { const nextInput = allNumberInputs[i + 1]; if (nextInput) { nextInput.focus(); } } if(!fieldsAreValid || !this.hasVisableFieldsAValue()) this.submitButton.setAttribute('disabled', ''); if (fieldsAreValid){ this.submitButton.disabled = false; this.verifyAge(); } }); ageGateInput.addEventListener('focusout', (e) => { if(this.fieldErrors.indexOf(inputName) !== -1){ this.showErrorMessageIfErrorsElseRemove(); } }); ++inputIx; } } loadLang(e = null, thisObj = null){ var url = "$langfile_url"; var storage_name = "$storage_name"; if(e != null){ e.preventDefault(); e.stopPropagation(); url += '?l='+e.target.value; url += '&s='+storage_name; }else{ url += '?s='+storage_name; } var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.onload = function(){ if (xhr.status == 200) { var responseData = JSON.parse(xhr.responseText); if(thisObj != null){ thisObj.setLda(responseData.ldaRules); this.log(thisObj.full); thisObj.avpBody.querySelector('.agegate_tooyoung-message').classList.remove('agegate_show'); if(thisObj.full){ if(null!==thisObj.monthInput){ thisObj.monthInput.style.display = 'inline-block'; } if(null!==thisObj.dayInput){ thisObj.dayInput.style.display = 'inline-block'; } if(null!==thisObj.submitButton){ thisObj.submitButton.style.display = 'inline-block'; } } else { if(null!==thisObj.monthInput){ thisObj.monthInput.style.display = 'none'; } if(null!==thisObj.dayInput){ thisObj.dayInput.style.display = 'none'; } if(null!==thisObj.submitButton){ thisObj.submitButton.style.display = 'none'; } } thisObj.monthInput.value = ''; thisObj.dayInput.value = ''; thisObj.yearInput.value = ''; } var ageGateElement = document.getElementById('pr_age_gate'); if (ageGateElement) { ageGateElement.setAttribute('data-lang', responseData.lang); } if(null!==document.querySelector('.agegate_change_country')){ document.querySelector('.agegate_change_country').selectedIndex = responseData.lang; } for (var key in responseData.content) { if(key != 'rememberMe'){ var element = document.querySelector('#pr_age_gate .agegate_' + key); } else { var element = document.querySelector('#pr_age_gate .agegate_' + key +' span'); } if (element) { switch(contentType){ case 'innerHTML': element.innerHTML = responseData.content[key]; break; case 'value': element.value = responseData.content[key]; break; case 'placeholder': element.placeholder = responseData.content[key]; break; } } } } }; xhr.send(); } async getActiveUserInfo(){ this.log('-- getActiveUserInfo'); /*const urlParams = new URLSearchParams(window.location.search); if (urlParams.has('fakeVpn')) { this.log('Fake VPN detected'); this.user_country_json = []; this.user_country_json['cloudfront-viewer-country-code'] = urlParams.get('fakeVpn'); } else {*/ let url = 'https://age-gate-static.pernod-ricard.io/geolocation.json'; /*let url = '/geolocation.json';*/ this.log(url); var response = await fetch(this.addCacheBusterParam(url)); this.user_country_json = await response.json(); this.log('Response ok'); /*}*/ this.log(this.user_country_json); this.setActiveLangCountry(this.user_country_json["cloudfront-viewer-country-code"]); this.loadJson(); } addCacheBusterParam(url){ const cacheBuster = `cb=${Date.now()}`; const separator = url.includes('?') ? '&' : '?'; return `${url}${separator}${cacheBuster}`; } async loadJson(){ this.log('-- loadJson'); /*let url = 'https://age-gate-static.pernod-ricard.io/content_.json';*/ let url = this.agegate_cached_content_file; /*let url = 'https://nico-gcms-plugins-dev.pantheonsite.io/wp-content/uploads/agegate/agegate_content.json';*/ this.log(url); var response = await fetch(this.addCacheBusterParam(url), { mode: 'no-cors', headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0' } }); if(response.ok) { this.agegate_content_json_loaded = true; this.json_content = await response.json(); } /*this.json_content = await response.json();*/ if (!window.location.search.includes('force_age_gate_lang') && this.agegate_content_json_loaded) { this.checkUserLang(); } } getMyCountry(){ return this.user_country_json["cloudfront-viewer-country-code"].toLowerCase(); } getActiveLangCountry(){ if(this.getActiveLang() != this.getActiveCountry()){ return this.getActiveLang().toLowerCase() + '-' + this.getActiveCountry().toLowerCase(); } else { return this.getActiveCountry().toLowerCase(); } } getActiveCountry(){ return this.activeCountry; /*return this.json_content.country.toLowerCase();*/ } getActiveLang(){ return this.activeLanguage; /*return this.json_content.lang.toLowerCase();*/ } getCountry(){ return this.user_country_json["cloudfront-viewer-country-code"].toLowerCase(); /*return this.json_content.country;*/ } setActiveCountry(country){ this.log('-- setActiveCountry to :'); this.log(country); this.json_content.country = country; this.activeCountry = country; } setActiveLang(lang){ this.log('-- setActiveLang to :'); this.log(lang); this.json_content.lang = lang; this.activeLanguage = lang; } setActiveLangCountry(langCountry){ this.log('-- setActiveLangCountry :'); this.log('Param given : ' + langCountry); langCountry = langCountry.replace(/_/g, '-').toLowerCase().split('-'); this.log('After split : '); this.log(langCountry); if(langCountry.length > 1){ this.setActiveLang(langCountry[0]); this.setActiveCountry(langCountry[1]); } else { this.setActiveLang(langCountry[0]); this.setActiveCountry(langCountry[0]); } } getLdaRules(){ return this.json_content.ldaRules; } getNoAgeGateSlug(){ return this.json_content.noAgegateSlug; } getTranslations(){ return this.json_content.contents; } getMyLda(lang = null){ let myCountryHere = this.getCountry(); if(lang != null){ myCountryHere = lang; } return this.json_content.ldaRules[myCountryHere]; } checkIfBan(){ this.log('-- checkIfBan'); if(this.getMyLda().age >= 99){ this.log('You are banned'); return true; } else { this.log('You are not banned'); return false; } } checkIfLangChange(){ if(this.getMyLda().name != this.ldaRules.name){ this.log('Need to change LdaRules'); return true; } else { return false; } } replacePatterns(content){ return content.replace("{age}", this.getMyLda().age); } updateInterfaceWithNewLang(){ this.log('-- updateInterfaceWithNewLang'); let translationIndex = ''; let translationTempIndex = this.getActiveLangCountry(); let myTranslations = this.getTranslations(); this.log(myTranslations); this.log('check if ' + translationTempIndex); let forceShowCountrySelector = false; /* check translation lang-country */ if(myTranslations[translationTempIndex] == undefined){ this.log('No translation for lang-country'); /* check translation browser lang - country */ const browserLanguage = navigator.language || navigator.userLanguage; const languageOnly = browserLanguage.split('-')[0].toLowerCase(); this.log('check if '+languageOnly+'-'+this.getActiveCountry()); if(myTranslations[languageOnly+'-'+this.getActiveCountry()] != undefined){ translationIndex = languageOnly+'-'+this.getActiveCountry(); forceShowCountrySelector = true; } else { this.log('No translation for browserlang-country'); this.log('check if '+this.getActiveCountry()); /* check translation only country */ if(myTranslations[this.getActiveCountry()] == undefined){ this.log('No translation for country'); for (let key in myTranslations) { if(translationIndex == ''){ this.log('check if '+key+' contains '+this.getActiveCountry()); this.log(key.endsWith(this.getActiveCountry())); if(key.endsWith(this.getActiveCountry())) { this.log(key+' index is ok'); translationIndex = key; forceShowCountrySelector = true; } } } } else { this.log('Translation for country'); translationIndex = this.getActiveCountry(); forceShowCountrySelector = true; } } } else { translationIndex = translationTempIndex; } if(translationIndex == ''){ translationIndex = 'generic'; } this.log('translationIndex : ' + translationIndex); myTranslations = myTranslations[translationIndex]; this.log(myTranslations); this.avpBody.querySelector('.agegate_tooyoung-message').classList.remove('agegate_show'); if(this.full){ if(null!==this.monthInput){ this.monthInput.style.display = 'inline-block'; } if(null!==this.dayInput){ this.dayInput.style.display = 'inline-block'; } if(null!==this.submitButton){ this.submitButton.style.display = 'inline-block'; } } else { if(null!==this.monthInput){ this.monthInput.style.display = 'none'; } if(null!==this.dayInput){ this.dayInput.style.display = 'none'; } if(null!==this.submitButton){ this.submitButton.style.display = 'none'; } } this.monthInput.value = ''; this.dayInput.value = ''; this.yearInput.value = ''; var ageGateElement = document.getElementById('pr_age_gate'); if (ageGateElement) { ageGateElement.setAttribute('data-lang', translationIndex); } if(forceShowCountrySelector || this.allow_switch_language == true){ document.querySelector('.agegate_countrySelector').style.display = 'block'; this.log('country selector displayed'); } else { document.querySelector('.agegate_countrySelector').style.display = 'none'; this.log('country selector not displayed'); } if(null!==document.querySelector('#agegate_change_country')){ /*let newIndex = this.getActiveCountry(); if(this.getActiveCountry() != this.getActiveLang()){ newIndex = this.getActiveLang() + '-' + this.getActiveCountry(); } */ document.querySelector('#agegate_change_country').value = translationIndex; this.log('Selected index : '); this.log(translationIndex); } if(myTranslations['no-age-input'] != undefined && myTranslations['no-age-input'] == 'ok'){ this.displayNoAgeInputFields(ageGateElement); } else { this.displayAgeInputFields(ageGateElement); } for (var key in myTranslations) { if(key != 'no_age_input'){ var contentType = 'innerHTML'; switch(key){ case 'rememberMe': case 'countrySelector': var element = document.querySelector('#pr_age_gate .agegate_' + key +' span'); break; case 'submit': contentType = 'value'; var element = document.querySelector('#pr_age_gate .agegate_' + key); break; case 'inputYear': case 'inputMonth': case 'inputDay': contentType = 'placeholder'; var inputTypeName = key.replace('input', ''); inputTypeName = inputTypeName.charAt(0).toLowerCase() + inputTypeName.slice(1); var element = document.querySelector('#pr_age_gate input[name="' + inputTypeName + '"]'); break; default: var element = document.querySelector('#pr_age_gate .agegate_' + key +''); break; } if (element) { let thisFieldTranslation = this.replacePatterns(myTranslations[key]); if(key == 'noAgeInputCheckbox'){ let noAgeInputCheckboxChecked = ''; if(myTranslations['no-age-input-checked'] != null && myTranslations['no-age-input-checked'] == 'ok'){ noAgeInputCheckboxChecked = 'checked="checked"'; this.log('No age input checked'); } thisFieldTranslation = '<input type="checkbox" name="noAgeInputCheckbox" class="noAgeInputCheckbox" value="ok" '+noAgeInputCheckboxChecked+' />' + thisFieldTranslation; } thisFieldTranslation = thisFieldTranslation.replace(/<\/?pre>/g, ''); switch(contentType){ case 'innerHTML': element.innerHTML = thisFieldTranslation; break; case 'value': element.value = thisFieldTranslation; break; case 'placeholder': element.placeholder = thisFieldTranslation; break; } } } } } checkUserLang(){ this.log('-- checkUserLang'); this.log('getMyCountry : '); this.log(this.getMyCountry()); this.log('getNoAgeGateSlug : '); this.log(this.getNoAgeGateSlug()); this.log('getTranslations : '); this.log(this.getTranslations()); this.log('getLdaRules : '); this.log(this.getLdaRules()); this.log('getMyLda : '); this.log(this.getMyLda()); if(this.checkIfBan()){ this.showBanned(); } else { if(this.checkIfLangChange()){ this.setLda(this.getMyLda()); this.setActiveCountry(this.getMyCountry()); this.updateInterfaceWithNewLang(); } } } showBanned(){ document.querySelector('#pr_age_gate .agegate_top').style.display = 'none'; document.querySelector('#pr_age_gate .agegate_middle').style.display = 'none'; document.querySelector('#pr_age_gate .agegate_bottom').style.display = 'none'; document.querySelector('#pr_age_gate .agegate_banned').style.display = 'block'; document.querySelector('#pr_age_gate .agegate_countrySelector').remove(); } initMutationObserver(){ var ageGateObserver = new MutationObserver((mutations, me) => { var agegate = document.getElementById('pr_age_gate'); var agegateYear = document.querySelector('#pr_age_gate input[name="year"]'); if (agegate != null && agegateYear != null) { var thisObj = this; /* && document.querySelector('select#agegate_change_country')*/ if (!window.location.search.includes('force_age_gate_lang')) { /*thisObj.loadLang(null, thisObj);*/ /*thisObj.loadLang2(null, thisObj);*/ } if(document.querySelector("select[name='agegate_change_country']") != null){ const self = this; document.querySelector("select[name='agegate_change_country']").addEventListener("change", function(e){ self.log('-----------'); self.log('change country to :'); self.log(this.value); self.setActiveLangCountry(this.value); self.log('New LDA : '); self.log(self.getMyLda(self.json_content.country)); self.setLda(self.getMyLda(self.json_content.country)); self.updateInterfaceWithNewLang(); }); } this.avpBody = agegate; this.onAgeGateExist(agegate); this.checkForPassedData(); me.disconnect(); return; } }); ageGateObserver.observe(document, { childList: true, subtree: true }); } }

function injectAgeGate() {
    // generic
let agegate_tooYoungWebsite = 'https://www.wise-drinking.com';
let agegate_ldarule = JSON.parse('{"name":"Generic","countrycode":"generic","age":21,"langCodes":["generic"],"languages":["English"],"format":"yyyy-mm-dd","full":false}');
let agegate_force_minor_redirect = true;
let allow_switch_language = false;
let allowedSlugsWithoutAgeGate = [''];

let agegate_user_country = 'generic';
if (typeof gcms_user_country === 'undefined') {
    let gcms_user_country = agegate_user_country;
}
let agegate_user_country_language = navigator.language || navigator.userLanguage;
let agegate_no_age_input = false;

let cached_content_file = '/wp-content/uploads/agegate/agegate_content.json';
let cached_script_file = '/wp-content/uploads/agegate/agegate_script.js';

    // Launch age gate
    let agegateOptions = { agegate_ldarule: agegate_ldarule, agegate_tooYoungWebsite: agegate_tooYoungWebsite, agegate_force_minor_redirect: agegate_force_minor_redirect, agegate_no_age_input: agegate_no_age_input, cached_content_file: cached_content_file, allow_switch_language: allow_switch_language, allowedSlugsWithoutAgeGate: allowedSlugsWithoutAgeGate};let noAgeGateToDisplay = false; let currentPath = document.location.pathname;if(currentPath != '/' && allowedSlugsWithoutAgeGate.length > 0){ if (currentPath.startsWith('/')) { currentPath = currentPath.slice(1); } if (currentPath.endsWith('/')) { currentPath = currentPath.slice(0, -1); } for (let i = 0; i < allowedSlugsWithoutAgeGate.length; i++) { let testedUrl = allowedSlugsWithoutAgeGate[i]; if (testedUrl.startsWith('/')) { testedUrl = testedUrl.slice(1); } if (testedUrl.endsWith('/')) { testedUrl = testedUrl.slice(0, -1); } if (currentPath == testedUrl) { noAgeGateToDisplay = true; } }}if(!noAgeGateToDisplay){ window.AVP = new AVP(agegateOptions);}

    // Add styles
    const style = document.createElement('style');
    style.textContent = `#pr_age_gate, #pr_age_gate * {font-family: Arial, Helvetica, Sans-Serif;} #pr_age_gate * {color:#000000;} #pr_age_gate:target {display: block;} #pr_age_gate .agegate_overlay {background-color: rgba(0, 0, 0, 0.5);position: fixed;top: 0px;left: 0px;right: 0px;bottom: 0px;color: transparent;} #pr_age_gate .agegate_dialog {background-color: white;max-width: 900px;width:90%;overflow:hidden;} #pr_age_gate .agegate_dialog .agegate_content {padding: 20px;} #pr_age_gate .agegate_dialog.agegate_center-fix-xy {position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);}#pr_age_gate p {line-height: unset;margin: unset;} #pr_age_gate .agegate_relative{position:relative;} #pr_age_gate .agegate_inputs_container {} #pr_age_gate .agegate_inputs_container input {display:block; margin:0 auto} #pr_age_gate .agegate_top, #pr_age_gate .agegate_middle, #pr_age_gate .agegate_text {text-align: center;} #pr_age_gate .agegate_banned {text-align: center;display:none;} #pr_age_gate .agegate_bottom {text-align: center;margin-bottom:20px;} #pr_age_gate .age-gate_input {padding: 5px;border-radius: 2px;border-color: rgba(0,0,0,.15);color: #373737;height:40px;border-width:1px;} #pr_age_gate .agegate_field-error-message.agegate_show, #pr_age_gate .agegate_tooyoung-message.agegate_show{display:block;} #pr_age_gate .agegate_field-error-message{display:none;} #pr_age_gate .agegate_tooyoung-message{display:none;} #pr_age_gate .agegate_submit,#pr_age_gate .agegate_submit:hover,#pr_age_gate .agegate_submit:active,#pr_age_gate .agegate_submit:focus {border: none;outline:none;padding:8px;font-size:12px;display:inline-block;height:40px;cursor: pointer;} #pr_age_gate #avp-field-error-message, #pr_age_gate #tooyoung-message{display:none;width:auto;padding:5px 10px;margin:0 auto;z-index:2;background:#e15959;color:#fff;transition:all .28s ease;transform:translate3d(0,-10px,0) scale(.9)} #pr_age_gate #avp-field-error-message.agegate_show,#pr_age_gate #tooyoung-message.agegate_show{display:block;} #pr_age_gate #avp-field-error-message:before,#pr_age_gate #tooyoung-message:before{content:"";display:block;position:absolute;top:-4px;margin:0 auto;left:0;right:0;width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-bottom:5px solid #e15959} #pr_age_gate .agegate_change_country{position:absolute;right:10px;bottom:10px;} #pr_age_gate .agegate_change_country select {width:170px;margin:0 5px;} #pr_age_gate .agegate_banned_title {font-size: 24px;font-weight: bold;margin: 20px 0;} #pr_age_gate .agegate_banned_message {font-size: 18px;;margin: 20px 0;} #pr_age_gate .agegate_banned_terms-title {font-size: 16px;font-weight: bold;;margin: 20px 0;} #pr_age_gate .agegate_banned_term-content {font-size: 14px;width: 100%;height: 500px;overflow: auto;padding:15px;} @media only screen and (max-width: 400px) { #pr_age_gate .agegate_dialog .agegate_content{padding:5px !important;} #pr_age_gate .agegate_logo{max-width:40% !important;} #pr_age_gate .agegate_over18 {font-size:15px !important;line-height:15px !important;margin:20px 0 !important;} #pr_age_gate .agegate_subtitle {font-size:15px !important;line-height:15px !important;margin:20px 0 !important;} #pr_age_gate .agegate_rememberMeHelp {margin-bottom:5px !important;} #pr_age_gate .agegate_rememberMe {margin:5px 0 !important;} #pr_age_gate .agegate_generalConditionsTitle {font-size:12px !important;line-height:12px !important;} #pr_age_gate .agegate_generalConditions, #pr_age_gate .agegate_generalConditions p, #pr_age_gate .agegate_generalConditions p a {font-size:9px !important;line-height:9px !important;} } @media (min-width: 401px) and (max-width: 576px) { #pr_age_gate .agegate_dialog .agegate_content{padding:5px !important;} #pr_age_gate .agegate_logo{max-width:80% !important;} #pr_age_gate .agegate_over18 {font-size:18px !important;line-height:18px !important;margin:20px 0 !important;} #pr_age_gate .agegate_subtitle {font-size:18px !important;line-height:18px !important;margin:20px 0 !important;} #pr_age_gate .agegate_rememberMe {margin:20px 0 !important;} #pr_age_gate .agegate_generalConditions, #pr_age_gate .agegate_generalConditions p, #pr_age_gate .agegate_generalConditions p a {font-size:10px !important;line-height:10px !important;} } @media (min-width: 680px) { #pr_age_gate .agegate_inputs_container input {display:inline-block;} } #pr_age_gate .agegate_content div:empty, #pr_age_gate .agegate_content p:empty, #pr_age_gate .agegate_content span:empty {display: none;} #pr_age_gate {position:relative;z-index: 9999 !important;}#pr_age_gate, #pr_age_gate * {font-family: Trebuchet MS, Helvetica, Sans-Serif;}#pr_age_gate .agegate_overlay {background-color: rgba(255,255,255,1);}#pr_age_gate .agegate_dialog {max-width:860px;}#pr_age_gate .agegate_dialog {background-color: #ffffff;border: 5px solid #ffffff}#pr_age_gate .agegate_logo {width:260px;height:auto;}#pr_age_gate .agegate_rememberMe span {font-size:15px; color:#000000}#pr_age_gate .age-gate_input {border-style: solid;width:150px;height:40px;}#pr_age_gate .age-gate_input {background-color:#ffffff;}#pr_age_gate .age-gate_input {color:#000000;}#pr_age_gate .age-gate_input {::placeholder: ;::-ms-input-placeholder: ;}#pr_age_gate .age-gate_input {border-color:#000000;}#pr_age_gate .age-gate_input {border-width:1px;}#pr_age_gate .agegate_inputs_container input.noAgeInputCheckbox {margin-right:10px;}#pr_age_gate .agegate_submit,#pr_age_gate .agegate_submit:hover,#pr_age_gate .agegate_submit:active,#pr_age_gate .agegate_submit:focus {background-color:#000000;}#pr_age_gate .agegate_submit,#pr_age_gate .agegate_submit:hover,#pr_age_gate .agegate_submit:active,#pr_age_gate .agegate_submit:focus {border: 1px solid #000000;}#pr_age_gate .agegate_submit,#pr_age_gate .agegate_submit:hover,#pr_age_gate .agegate_submit:active,#pr_age_gate .agegate_submit:focus {color:#ffffff;}#pr_age_gate .agegate_submit,#pr_age_gate .agegate_submit:hover,#pr_age_gate .agegate_submit:active,#pr_age_gate .agegate_submit:focus {font-size:12px;}#pr_age_gate .agegate_change_country{position:absolute;right:10px;bottom:10px;}#pr_age_gate .agegate_change_country span {line-height:14px;font-size:14px;color:#000000;}#pr_age_gate .agegate_change_country select {height:40px;width:150px;border-width:1px;border-color:#000000;color:#000000;background-color:#ffffff;}#pr_age_gate .agegate_over18, #pr_age_gate .agegate_over18 p, #pr_age_gate .agegate_over18 p a {color: #000000;font-size: 23px;margin-top: 30px;margin-bottom: 30px;line-height: 23px;}#pr_age_gate .agegate_subtitle, #pr_age_gate .agegate_subtitle p, #pr_age_gate .agegate_subtitle p a {color: #000000;font-size: 23px;margin-top: 30px;margin-bottom: 40px;line-height: 23px;}#pr_age_gate .agegate_rememberMe, #pr_age_gate .agegate_rememberMe p, #pr_age_gate .agegate_rememberMe p a {color: #000000;font-size: 15px;margin-top: 40px;margin-bottom: 1px;line-height: 15px;}#pr_age_gate .agegate_rememberMeHelp, #pr_age_gate .agegate_rememberMeHelp p, #pr_age_gate .agegate_rememberMeHelp p a {color: #000000;font-size: 12px;margin-top: 10px;margin-bottom: 50px;line-height: 12px;}#pr_age_gate .agegate_noAgeInputCheckbox, #pr_age_gate .agegate_noAgeInputCheckbox p, #pr_age_gate .agegate_noAgeInputCheckbox p a {color: #000000;font-size: 23px;margin-top: 30px;margin-bottom: 30px;line-height: 23px;}#pr_age_gate .agegate_generalConditionsTitle, #pr_age_gate .agegate_generalConditionsTitle p, #pr_age_gate .agegate_generalConditionsTitle p a {color: #000000;font-size: 14px;margin-top: 17px;margin-bottom: 1px;line-height: 14px;}#pr_age_gate .agegate_generalConditions, #pr_age_gate .agegate_generalConditions p, #pr_age_gate .agegate_generalConditions p a {color: #000000;font-size: 12px;margin-top: 1px;margin-bottom: 1px;line-height: 20px;}`;
    document.head.appendChild(style);

    // Add html content
    const ageGateContainer = document.createElement('div');
    ageGateContainer.setAttribute('id', 'pr_age_gate');
    ageGateContainer.setAttribute('data-lang', 'generic');
    ageGateContainer.innerHTML = `
        
        <span class="agegate_overlay"></span>
        <div class="agegate_center-fix-xy agegate_dialog">
            <form method="post" class="agegate_content agegate_relative">
                <div class="agegate_content">
                    <div class="agegate_top"><span id="agegate_logo_container"><svg class="agegate_logo" viewBox="0 0 150 36" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(-113.000000, -96.000000)" fill="#004027"><g transform="translate(0.000000, 64.000000)"><g transform="translate(113.000000, 32.000000)"><path d="M5.64228887,14.3377921 C5.28815633,13.0114572 4.15566234,12.3299038 3.38642803,12.2811174 L3.36488801,12.2101222 C3.36488801,12.2101222 5.45025411,11.4419183 6.96061118,10.9274766 C8.52682627,10.3959232 10.7662583,9.65866592 10.7662583,9.65866592 L10.8005763,9.73111737 C10.2255673,10.2484717 9.97000768,11.3454378 10.2967588,12.6288115 C10.2967588,12.6288115 13.1677881,23.8646125 13.579239,25.3511416 C13.9877692,26.8354863 14.5543813,27.6670397 15.3298221,27.7708018 L15.355378,27.841797 C14.9556098,28.2317242 14.6332397,29.2034475 14.2247095,30.0958018 C13.8096077,30.9987145 12.9454513,33.7464086 9.59323985,35.0490785 C5.94019832,36.4678892 2.21194925,35.6115785 0.625289398,33.0364572 C-0.411552293,31.3602436 -0.180818508,29.0552679 1.48141396,28.1112145 C2.92459537,27.2942242 4.48788978,27.8141271 5.08370867,29.0057533 C5.6612733,30.1587873 5.27574343,31.3962873 4.80806942,31.8036902 C4.71241712,31.8903407 4.80697416,32.0519912 5.0289459,32.1979863 C6.00992957,32.862064 7.11905811,32.8187387 8.18766221,32.2471368 C9.55454083,31.5160688 10.0163735,30.344831 9.30628296,27.6288115 C8.73309935,25.4498067 6.04205706,15.8217727 5.64228887,14.3377921 L5.64228887,14.3377921 Z M34.2200554,27.4780834 C32.6753804,27.8723795 30.0445771,28.4589086 30.0445771,28.4589086 L30.0237673,28.3882776 C30.6385706,27.8246853 31.3037556,26.4925251 30.3450422,24.6597582 L28.9098926,21.77153 L22.854226,23.4062387 L22.6172858,26.8019912 C22.6081587,28.840462 23.6723817,29.7178892 24.4879819,29.8941028 L24.5040456,29.9680106 C24.5040456,29.9680106 22.5636183,30.5665543 21.052166,30.9968941 C19.5706506,31.4712873 17.6984942,32.027962 17.6984942,32.027962 L17.6736684,31.9558747 C18.25963,31.4563601 18.9003544,29.7579378 19.0226579,27.7806319 C19.3618219,22.5055106 19.8601631,14.6239572 20.3048368,11.0931319 C20.5209671,9.39725815 20.3121385,7.79021932 18.9978321,7.34167563 L18.9792128,7.25466106 C18.9792128,7.25466106 20.8221623,6.71691835 23.0648801,6.18536495 C24.9447033,5.73827757 27.1896116,5.15866592 27.1896116,5.15866592 L27.2188184,5.24458825 C26.3488206,6.39871446 27.015466,7.61364165 27.8398282,9.13475815 C28.6192849,10.582331 35.2543415,22.7021125 35.8132868,23.7047824 C36.7891593,25.3828164 37.4145501,26.0585446 38.4170738,26.5063601 L38.4262009,26.5795397 C38.4262009,26.5795397 35.7826197,27.1427679 34.2200554,27.4780834 L34.2200554,27.4780834 Z M23.6983028,11.2933747 L23.0937219,19.9711659 L27.4170596,18.7704378 L23.6983028,11.2933747 Z M53.7791247,0.876748442 L60.9179988,0.328811549 L60.9329673,0.400898928 C59.069938,1.28196689 59.2692745,2.87808339 59.4580235,5.35708825 L60.4087051,19.479297 C60.6379785,21.5461659 61.1512882,23.1437387 62.0691121,23.5438601 L62.0625406,23.6174038 C62.0625406,23.6174038 60.3984827,23.7171611 58.1013672,23.9002921 C55.8148392,24.0845154 54.1208444,24.2527193 54.1208444,24.2527193 L54.1047806,24.1806319 C54.9433811,23.6174038 55.6552971,21.8763844 55.4968501,19.7359717 C55.4968501,19.7359717 54.8802214,10.5499281 54.8163315,9.78208825 C54.7392985,8.91594747 54.8239983,8.3203164 54.8239983,8.3203164 C54.8239983,8.3203164 54.7115521,8.96400572 54.4895803,9.70708825 C54.265053,10.4508989 49.9063019,25.0161902 49.9063019,25.0161902 L49.7923954,25.0241999 C49.7923954,25.0241999 43.3135952,13.0569669 42.7312844,12.0958018 C42.2672613,11.3268698 42.0810679,10.5987145 42.0810679,10.5987145 C42.0810679,10.5987145 42.3085159,11.2795397 42.4582008,12.1973795 C42.609346,13.1115785 43.7560783,21.1791756 43.7560783,21.1791756 C44.1251793,23.295195 45.2445303,24.8093941 46.1930214,25.1519912 L46.1988627,25.2255349 L39.932542,26.2445882 L39.9113671,26.1768698 C40.7017763,25.5659475 40.8094764,23.890098 40.5247101,21.8286902 L38.6269977,7.82589893 C38.3316439,5.69568048 37.2436903,3.99944262 35.6636019,3.47881155 L35.6599511,3.4045397 L42.7743645,2.19252514 C42.7743645,2.19252514 48.7132038,12.9408261 49.756252,14.5751708 C50.3885794,12.5312387 53.7791247,0.876748442 53.7791247,0.876748442 L53.7791247,0.876748442 Z M80.8921698,0.163156209 L80.7161988,5.2893698 L80.6424516,5.29555912 C79.8228356,3.38706398 77.7491522,3.00041349 75.8912341,3.01788922 L71.8665359,3.05903 L71.7570104,9.2399766 L73.7967409,9.29713679 C76.5100534,9.35174844 77.3136057,9.12674844 78.3048117,7.41339893 L78.3774637,7.42504941 L78.1189834,14.7695882 L78.0466966,14.7768698 C77.1496825,12.8694669 75.1450002,12.7394912 73.2900028,12.7584232 L71.7632169,12.7518698 L71.6036747,19.5721368 L75.8076296,19.6558747 C78.5213072,19.7086659 79.8808841,18.9601222 80.7585487,17.3949523 L80.8308355,17.4106077 L80.0813158,23.4295397 C75.1154283,23.2642484 69.4168149,23.2336659 64.972999,23.435729 L64.9609512,23.3632776 C65.9649353,22.7021125 66.5132931,21.2097582 66.5235155,18.9659475 L66.6837878,4.33767077 C66.701677,2.25805912 66.5571033,0.927719316 65.1164775,0.207209607 L65.1266999,0.134394073 C69.9673632,-0.0450962179 76.1230631,-0.053834082 80.8921698,0.163156209 L80.8921698,0.163156209 Z M91.7169431,24.6441028 C88.7371185,24.5541756 88.4169389,23.7116999 86.7302457,23.3265057 C85.495893,23.0450737 84.6565623,23.5839086 84.2911121,24.0186174 L84.2184602,24.0098795 L84.5755134,15.785729 L84.6470701,15.7766271 C85.2560321,17.3723795 86.9858053,19.5805106 88.9912178,20.698229 C90.8140877,21.7125494 92.6610532,21.2909475 93.6037029,20.0960446 C94.4218586,19.0558747 94.6288619,17.1328164 93.3364606,15.8199523 C92.0455197,14.5067242 90.004694,13.6220154 88.2895242,12.3102436 C84.8274222,9.6557533 85.0519495,6.0703164 86.1347919,4.07662708 C87.6466093,1.29507368 90.8170083,0.162063976 93.6475131,0.435122229 C95.3696196,0.602962034 96.1454254,1.04276786 97.3480157,1.4268698 C98.5549871,1.80987951 99.6221308,1.57978242 99.8448328,1.45672417 L99.9174847,1.46946689 L99.369857,7.96315621 L99.2957448,7.96752514 C98.6761953,6.25162708 96.6251472,4.11121446 94.4678594,3.70963679 C92.5763535,3.36230669 91.5296545,4.03002514 91.064536,4.80805912 C90.3489692,6.00623873 90.6662282,7.33803485 91.9699471,8.23803485 C93.8588974,9.53961252 96.1516319,10.5127921 97.6608937,11.9301465 C99.8546901,13.9937387 100.554193,17.6505349 98.6024482,20.8850009 C97.0289314,23.4939815 93.9403114,24.7110931 91.7169431,24.6441028 L91.7169431,24.6441028 Z M122.379346,17.7157048 C120.758003,24.377598 115.804163,28.9930106 109.97704,27.7176465 C103.626749,26.3283261 101.673909,20.3432533 103.322999,13.5506562 C104.950913,6.83852029 109.551715,2.61121446 115.483983,3.60369019 C122.515157,4.78002514 123.961259,11.2110931 122.379346,17.7157048 L122.379346,17.7157048 Z M114.917006,6.94774359 C111.863069,6.27856883 109.826625,9.96667563 108.77664,14.7291756 C107.674448,19.7508989 108.187027,23.6381562 110.983214,24.2498067 C113.649066,24.832695 115.906387,21.5508989 117.008944,16.530996 C118.056373,11.7681319 117.973134,7.61619019 114.917006,6.94774359 L114.917006,6.94774359 Z M136.623871,23.1426465 C136.778302,23.7790543 136.789985,24.6138844 136.789985,24.6138844 C136.789985,24.6138844 136.765524,24.2177679 137.06891,23.2336659 L139.678173,15.5865785 C140.340437,13.615462 140.318532,12.1813601 139.436852,11.0578164 L139.470805,10.9944669 L145.797364,13.3402193 L145.77984,13.4133989 C144.462248,13.7971368 143.453518,14.8846368 142.790524,16.8703164 C142.419597,18.0597582 136.632268,35.0377921 136.632268,35.0377921 L133.440694,33.8348795 L130.294756,18.2996853 C130.135214,17.6658261 130.127912,16.8306319 130.127912,16.8306319 C130.127912,16.8306319 130.149817,17.2249281 129.849352,18.2115785 C129.579189,19.0984717 126.965545,26.8966514 126.965545,26.8966514 C126.382139,28.9646125 126.459172,30.3896125 127.292661,31.4811174 L127.264914,31.5502921 L120.502078,29.5682533 L120.5123,29.4961659 C121.888671,29.1116999 123.058039,28.0700737 123.698033,26.0891271 L127.980481,12.6794183 C128.638365,10.4847582 128.467505,8.48305912 127.271121,7.33330184 L127.297042,7.26339893 L133.530505,9.06776786 L136.623871,23.1426465 Z M148.427072,16.8102436 C149.567598,17.12153 150.237895,18.2931319 149.921731,19.4330591 C149.609948,20.5726222 148.435834,21.2414329 147.291658,20.9272339 C146.149306,20.6148552 145.47828,19.4428892 145.793714,18.3033261 C146.109512,17.163763 147.284356,16.4964086 148.427072,16.8102436 L148.427072,16.8102436 Z M148.291261,17.2922824 C147.403739,17.0479863 146.559297,17.5511416 146.310309,18.4449523 C146.064972,19.3391271 146.538487,20.2034475 147.426374,20.4455591 C148.313896,20.6905834 149.162354,20.1863358 149.407326,19.2928892 C149.654489,18.3998067 149.184989,17.5343941 148.291261,17.2922824 L148.291261,17.2922824 Z M146.596171,19.4581805 C146.848079,19.4978649 146.868889,19.4927679 146.924382,19.3074523 L147.289832,17.9763844 C147.340214,17.7903407 147.322325,17.773229 147.08575,17.679297 L147.134306,17.5063601 L148.366468,17.8416756 C148.716585,17.9363358 148.988573,18.1755349 148.882699,18.5600009 C148.808951,18.8294183 148.556678,19.0118213 148.252562,19.0231077 L148.485121,19.7771125 C148.538058,19.9438601 148.619472,20.013763 148.704902,20.0366999 L148.658536,20.2121853 L148.153259,20.0752921 C148.044463,20.0428892 147.984954,19.9522339 147.941874,19.7756562 L147.725379,18.9735931 L147.581535,18.9350009 L147.442438,19.4472582 C147.389135,19.6336659 147.407755,19.6518698 147.641044,19.7461659 L147.592123,19.919831 L146.54944,19.6336659 L146.596171,19.4581805 Z M147.794745,18.8039329 C147.958303,18.8476222 148.184656,18.7864572 148.278118,18.4362145 C148.364643,18.1271125 148.213863,17.9876708 148.037527,17.9388844 L147.867032,17.8930106 L147.630457,18.7595154 L147.794745,18.8039329 Z" id="Fill-1"></path></g></g></g></g></svg></span><p class="agegate_text agegate_over18" >You have to be over 21 to enter this site</p><p class="agegate_text agegate_subtitle" >Please enter your date of birth</p></div>
                    <div class="agegate_middle"><div class="agegate_inputs_container"><input type="tel" autocomplete="off" name="year" title="year" placeholder="YYYY" maxlength="4" onclick="this.select();" class="age-gate_input"><input type="tel" autocomplete="off" name="month" title="month" placeholder="MM" maxlength="2" onclick="this.select();" class="age-gate_input"><input type="tel" autocomplete="off" name="day" title="day" placeholder="DD" maxlength="2" onclick="this.select();" class="age-gate_input"><p class="agegate_text agegate_noAgeInputCheckbox" style="display:none;" ><input type="checkbox" name="noAgeInputCheckbox" class="noAgeInputCheckbox" value="ok"  />I am 21, let me in.</p><input type="submit" name="agegate_submit" class="agegate_submit" value="Submit" />
                                    <p id="avp-field-error-message" class="agegate_field-error-message">Please enter a valid value for the fields: {fields}</p>
                                    <p id="tooyoung-message" class="agegate_tooyoung-message">You must be of legal age to access the site</p>
                                </div><div class="agegate_rememberMe">
                                <input type="checkbox" name="rememberMe" value="ok"  /> <span>Remember me</span>
                                
                            </div><p class="agegate_text agegate_rememberMeHelp" >Don't tick this box if your computer can be accessed by people under legal drinking age</p></div>
                    <div class="agegate_bottom"><p class="agegate_text agegate_generalConditionsTitle" ></p><div class="agegate_text agegate_generalConditions" ><p>By entering this site, you are agreeing to our <a href="/en/terms-and-condititions/">TERMS &amp; CONDITIONS</a>, <a href="/en/privacy-policy/">PRIVACY STATEMENT</a>. Read our Privacy Policy to find out more. Read the <a href="/en/enjoy-responsibly/">ENJOY RESPONSIBLY</a>. Jameson Whiskey endorses responsible and moderate drinking.</p></div></div>
                    <div class="agegate_banned"><div class="agegate_banned_container">
    <div class="agegate_banned_title">We're sorry</div>
    <div class="agegate_banned_message">You are not allowed to visit our website from your country.</div>
    <div class="agegate_banned_terms-title"></div>
    <div class="agegate_banned_term-content"></div>
</div></div>
                </div>
                <div class="agegate_change_country agegate_countrySelector"><span>Change language</span><select id="agegate_change_country" name="agegate_change_country"><option value="generic" selected>Generic</option><option value="ar" >Arabic</option><option value="nl" >Dutch</option><option value="ee" >Ewe</option><option value="fr" >French</option><option value="de" >German</option><option value="it" >Italian</option><option value="jp" >Japanese (Japan)</option><option value="lv" >Latvian</option><option value="pl" >Polish</option><option value="pt" >Portuguese</option><option value="es" >Spanish</option></select></div>
            </form>

        </div>
    
    `;
    document.body.appendChild(ageGateContainer);
}

function checkIfAlreadyPassed() {
    try{
        if(window.sessionStorage.getItem('ageGatePassed') !== null || window.localStorage.getItem('ageGatePassed') !== null) {
            return true;
        }
        return false;
    } catch(e) {
        console.error(e);
        return false;
    }
}

document.addEventListener('DOMContentLoaded', function() {
    if(!checkIfAlreadyPassed()){
        injectAgeGate();
    }
});