var overlayRedirect = (function () { var navigatorLanguage = navigator.language; var cookieName = 'ovrlRedirect'; var bannerShowed = false; var availableLanguages = [ { lang: /^el$/gm, title: 'Ψάχνετε για έναν Διεθνή Τραπεζικό Λογαριασμό;', options: { yes: 'Αίτηση για Citigold International', yesExpat: 'Αίτηση για Citigold Expat', no: 'Συνεχίστε στον ιστότοπο' }, redirectUrl: 'https://www.ipb.citibank.co.uk/citigold/greek/apply.htm?icid=UKCPOPUKIPB02' }, { lang: /^ru$/gm, title: 'Хотите открыть счет в международном банке?', options: { yes: 'Подать заявку на Citigold International', yesExpat: 'Подать заявку на Citigold Expat', no: 'Продолжить работу на сайте' }, redirectUrl: 'https://www.ipb.citibank.co.uk/citigold/russian/apply.htm?icid=UKCPOPUKIPB02' }, { lang: /^ar[-]?/gm, title: 'هل ترغب في فتح حسب مصرفي دولي؟', options: { yes: 'كن عميلاً لدى Citigold International', yesExpat: 'كن عميلاً لدى Citigold Expat', no: 'تواصل إلى الموقع' }, redirectUrl: 'https://www.ipb.citibank.co.uk/citigold/arabic/apply.htm?icid=UKCPOPUKIPB02' } ]; var coordsConfig = { uk: { longitude: { min: -7.57, max: 1.68 }, latitude: { min: 49.96, max: 58.64 } }, ru: { longitude: { min: -180, max: 180 }, latitude: { min: 41.15, max: 81.25 } }, gr: { longitude: { min: 20.15, max: 26.6 }, latitude: { min: 34.92, max: 41.83 } }, uae: { longitude: { min: 51.58, max: 56.4 }, latitude: { min: 22.5, max: 26.06 } } } var cookies = { set: function (name, value, years) { document.cookie = name + "=" + escape(value) + "; expires=" + new Date((new Date()).getTime() + years * 365 * 24 * 60 * 60 * 1000) + "; path=/;"; }, get: function (name) { var dc = document.cookie; var prefix = name + "="; var begin = dc.indexOf("; " + prefix); if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return ""; } else begin += 2; var end = document.cookie.indexOf(";", begin); if (end == -1) end = dc.length; return unescape(dc.substring(begin + prefix.length, end)); }, delete: function (name) { if (cookies.get(name)) { document.cookie = name + "=null;path=/;" + ";expires=Thu, 01 Jan 1970 00:00:01 GMT"; } } }; function __init () { var cookieSettings = cookies.get(cookieName); var bannerOption; var redirectLang; if (cookieSettings.length && cookieSettings.split(';')[0] === 'No' || !getConfigBasedOnUserSettings().length) { return; } getLocation(); // showBanner(); // if (cookieSettings.length && cookieSettings.split(';')[0] === 'Yes') { // showBanner(); // bannerOption = cookieSettings.split(';')[0] // redirectLang = cookieSettings.split(';')[1] // if (bannerOption === 'No' && redirectLang.match(navigatorLanguage)) { // redirect(); // } // } else { // showBanner(); // } } function showBanner (title, optionNo, optionYes, redirectUrl, isExpat) { if (bannerShowed) return; bannerShowed = true; var bannerSelector = '.overlayRedirect'; var bannerHtml = ''; bannerHtml += '
' $('body').append(bannerHtml); setTimeout(function() { $(bannerSelector).addClass('open'); }, 500) $('.overlay-redirect__box-button').on('click', function (e) { e.preventDefault(); var selectedOption = $(this).data('select'); if (selectedOption === 'Yes') { cookies.set(cookieName, selectedOption + ";" + navigatorLanguage, 1); window.location.replace($(this).data('url')); } else { cookies.set(cookieName, selectedOption + ";null", 1); $(bannerSelector).removeClass('open'); setTimeout(function() { $('.overlayRedirect').remove(); }, 500) } }) } function getConfigBasedOnUserSettings() { return availableLanguages.filter(function(elem) { return navigatorLanguage.match(elem.lang) }); } function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(checkPostion, function() { // position not available var config = getConfigBasedOnUserSettings(); if (config.length) { showBanner(config[0].title, config[0].options.no, config[0].options.yes, config[0].redirectUrl, false) } }, { timeout: 5000 }); } else { } } function checkPostion(position) { var lon = position.coords.longitude; var lat = position.coords.latitude; var config = getConfigBasedOnUserSettings(); if ( lon > coordsConfig.uk.longitude.min && lon < coordsConfig.uk.longitude.max && lat > coordsConfig.uk.latitude.min && lat < coordsConfig.uk.latitude.max ) { // UK // if user lang is ru, gr, uae if (config.length) { showBanner(config[0].title, config[0].options.no, config[0].options.yesExpat, 'https://www.ipb.citibank.co.uk/citigold-expat/applynow/index.htm?icid=UKCPOPUKEXP01', true) } } else if ( ( lon > coordsConfig.ru.longitude.min && lon < coordsConfig.ru.longitude.max && lat > coordsConfig.ru.latitude.min && lat < coordsConfig.ru.latitude.max ) || ( lon > coordsConfig.gr.longitude.min && lon < coordsConfig.gr.longitude.max && lat > coordsConfig.gr.latitude.min && lat < coordsConfig.gr.latitude.max ) || ( lon > coordsConfig.uae.longitude.min && lon < coordsConfig.uae.longitude.max && lat > coordsConfig.uae.latitude.min && lat < coordsConfig.uae.latitude.max ) ) { // RU, GR, UAE if (config.length) { showBanner(config[0].title, config[0].options.no, config[0].options.yes, config[0].redirectUrl, false) } } } return { init: __init } })(); overlayRedirect.init();