var NF = { parameters:{ lang: 'it' }, colori:{ color: '#fff', bg: '#9BBC19', border: '#809A14', buttonBg: '#49505A', buttonColor: '#fff' }, ic: null, id_portale: null, stato: null, view_element: true, cookie_hide_name: 'newsletter-popupHide', cookie_hide_duration: '30', // un mese cookie_sended_name: 'newsletter-popupSended', cookie_sended_duration: '365', // un anno, cookie_first_visit: 'newsletter-first', cookie_pages_visited: 'newsletter-pages', cookie_first_duration: '365', // un anno init: function(options) { NF.view_element = NF.isRequiredView(); if(! NF.view_element){ return; } var cf = NF.getCookie(NF.cookie_first_visit); if(!cf){ NF.setCookie(NF.cookie_first_visit, (Date.now() / 1000 | 0), NF.cookie_first_duration,'/'); NF.setCookie(NF.cookie_pages_visited, 1, NF.cookie_first_duration,'/'); return; }else{ var pages = (parseInt(NF.getCookie(NF.cookie_pages_visited)) + 1); NF.setCookie(NF.cookie_pages_visited, pages, NF.cookie_first_duration,'/'); } var now = Date.now() / 1000 | 0; if(((now - cf) > 90) || pages >= 3){ var random = Math.floor(Math.random() * 2000) + 2000; setTimeout(function(){ NF.parameters.lang = options.parameters.lang; if( !options.id_portale || !options.ic || !options.parameters.id_lista || !options.parameters.id_attivita ) return false; NF.ic = options.ic; NF.id_portale = options.id_portale; NF.parameters.id_lista = options.parameters.id_lista; NF.parameters.id_attivita = options.parameters.id_attivita; if(typeof options.stato != 'undefined'){ NF.stato = options.stato; } if(typeof options.parameters.lang != 'undefined'){ NF.parameters.lang = options.parameters.lang; } if(typeof options.parameters.email_notify != 'undefined'){ NF.parameters.email_notify = options.parameters.email_notify; } if(typeof options.parameters.name != 'undefined'){ NF.parameters.name = options.parameters.name; } if(typeof options.parameters.surname != 'undefined'){ NF.parameters.surname = options.parameters.surname; } if(typeof options.colori != 'undefined'){ NF.colori = options.colori; } NF.setCookie(NF.cookie_first_visit,1,-1); NF.setCookie(NF.cookie_pages_visited,1,-1); NF.viewNF(); }, random); } }, createHtmlPopup: function() { return '
' + '' + '
' + '×' + '
' + '
' + NF.testoCta + '
' + '
' + '
' + '
' + '
' + '' + '
' + '
' + '
' + '' + '
' + '
' + NF.testoRimozione + '
' + '
' + '
' + '' + '' + '' + '' + '' + '' + '' + '


' + NF.RISPARMI + '


' + NF.RICEVI + '


' + NF.SCOPRI + '
' + '
' + '
' + '
'; }, createCSSPopup: function() { return ''; }, isRequiredView: function(){ var ch = NF.getCookie(NF.cookie_hide_name); var cs = NF.getCookie(NF.cookie_sended_name); if(ch=='1' || cs=='1'){ return false; }else{ return true; } }, removePopup: function(){ var el = document.getElementById( 'newsletter-popup' ); if(el) el.parentNode.removeChild( el ); }, registration: function(data){ if(data.result == true){ document.getElementById('newsletterIscriviti').innerHTML = NF.testoIscrizioneAvvenuta; setTimeout(function(){ window.location.hash = '#'; NF.setCookie(NF.cookie_sended_name, '1', NF.cookie_sended_duration,'/'); },2000); }else{ document.getElementById('newsletterIscriviti').innerHTML = NF.testoErrore; } }, submitForm: function(email){ var qs = '&email=' + email + '&lang=' + NF.parameters.lang + '&list_id=' + NF.parameters.id_lista + '&id_attivita=' + NF.parameters.id_attivita; if(typeof options.parameters.email_notify != 'undefined'){ qs = qs + '&email_notify=' + NF.parameters.email_notify; } if(typeof options.parameters.name != 'undefined'){ qs = qs + '&name=' + NF.parameters.name; } if(typeof options.parameters.surname != 'undefined'){ qs = qs + '&surname=' + NF.parameters.surname; } $jsonp.send('https://admin.abc.sm/scripts/ajax/portali/newsletterIscrizione.php?callback=NF.registration' + qs, { callbackName: 'NF.registration', onSuccess: function(json){ }, onTimeout: function(){ NF.registration({ result: false, reason: 'timeout' }); }, timeout: 5 }); }, validateFormOnSubmit: function(contact){ if(NF.getCookie(NF.cookie_hide_name) == '1'){ NF.hideNF(); return null; } reason = ""; reason += NF.validateEmail(contact.email); reason += NF.validateDisclaimer(contact.disclaimer); if (reason.length > 0) { return false; } else { NF.submitForm(email.value.trim()); } }, validateDisclaimer: function(disclaimer) { var error = ""; if (document.getElementById("disclaimer").checked === false) { document.getElementById('disclaimer-error').innerHTML = NF.errori.emailDisclaimer; var error = "4"; } else { document.getElementById('disclaimer-error').innerHTML = ''; var disclaimer = document.getElementById("disclaimer").checked; } return error; }, validateEmail: function(email) { var error = ""; var temail = email.value.trim() // value of field with whitespace trimmed off var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/; var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/; if (email.value == "") { document.getElementById('email-error').innerHTML = NF.errori.emailRequired; var error = "2"; } else if (!emailFilter.test(temail)) { //test email for illegal characters document.getElementById('email-error').innerHTML = NF.errori.emailInvalid; var error = "3"; } else if (email.value.match(illegalChars)) { var error = "4"; document.getElementById('email-error').innerHTML = NF.errori.emailInvalidChar; } else { document.getElementById('email-error').innerHTML = ''; } if (error != "") { email.style.boxShadow = 'inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #ce8483'; email.style.borderColor = '#843534'; }else{ email.style.boxShadow = 'none'; email.style.borderColor = '#fff'; } return error; }, viewNF: function(){ NF.removePopup(); function create(htmlStr) { var frag = document.createDocumentFragment(), temp = document.createElement('div'); temp.innerHTML = htmlStr; while (temp.firstChild) { frag.appendChild(temp.firstChild); } return frag; } var fragment = create(NF.createHtmlPopup()); document.body.insertBefore(fragment, document.body.childNodes[0]); var fragment = create(NF.createCSSPopup()); document.head.insertBefore(fragment, document.head.childNodes[0]); NF.bindLinks(); window.location.hash = '#newsletter-popup'; }, bindLinks: function(){ document.getElementById('newsletter-popup-close').addEventListener('click', function(event) { NF.hideNF(); }, false); document.getElementById('newsletter-popup-inner-close').addEventListener('click', function() { NF.hideNF(); }, false); }, hideNF: function(){ var element = document.getElementById('newsletter-popup'); element.outerHTML = ''; delete element; window.history.go(-1); /*window.location.hash = '#';*/ NF.setCookie(NF.cookie_hide_name, '1', NF.cookie_hide_duration,'/'); }, getCookie: function(name){ var start = document.cookie.indexOf( name + "=" ); var len = start + name.length + 1; if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ){ return null; } if ( start == -1 ) return null; var end = document.cookie.indexOf( ";", len ); if ( end == -1 ) end = document.cookie.length; return unescape( document.cookie.substring( len, end ) ); }, setCookie: function(name, value, expires, path, domain, secure){ var today = new Date(); today.setTime( today.getTime() ); if ( expires ) { expires = expires * 1000 * 60 * 60 * 24; } var expires_date = new Date( today.getTime() + (expires) ); document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" ); } }; var $jsonp = (function(){ var that = {}; that.send = function(src, options) { var callback_name = options.callbackName || 'callback', on_success = options.onSuccess || function(){}, on_timeout = options.onTimeout || function(){}, timeout = options.timeout || 10; // sec var timeout_trigger = window.setTimeout(function(){ window[callback_name] = function(){}; on_timeout(); }, timeout * 1000); window[callback_name] = function(data){ window.clearTimeout(timeout_trigger); on_success(data); } var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true; script.src = src; document.getElementsByTagName('head')[0].appendChild(script); } return that; })(); NF.testoCta = 'ISCRIVITI ALLA NOSTRA NEWSLETTER!'; NF.testoRimozione = 'Potrai cancellarti in qualsiasi momento!'; NF.testoInvia = 'INVIA'; NF.testoIscrizioneAvvenuta = 'Iscrizione avvenuta'; NF.testoErrore = 'Si รจ verificato un errore. REINVIA'; NF.testoTrattamento = 'Trattamento dati personali ', NF.RICEVI = 'RICEVI
solo offerte
personalizzate', NF.SCOPRI = 'SCOPRI
hotel, campeggi e
villaggi da sogno', NF.RISPARMI = 'RISPARMI
con gli sconti a te
riservati', NF.errori = { emailRequired:'Inserisci un indirizzo email', emailInvalid:'Inserisci un indirizzo email valido', emailInvalidChar:'L\'indirizzo email contiene caratteri non validi', emailDisclaimer:'Occorre accettare il trattamento dati' }; var options = {"ic":168,"stato":"RSM","id_portale":609,"parameters":{"id_lista":"1014839","lang":"it","id_attivita":3257},"colori":{"color":"#fff","bg":"#1C6FAF","border":"#5995C4","buttonBg":"#FFC52D","buttonColor":"#fff","promoBg":"#19649D"}} NF.init(options);