var validNavigation = false;
var survey_showed = false;
var disabledConfirm_exit = false;
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
var ca = document.cookie.split(';');
var nameEQ = name + "=";
for(var i=0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1, c.length); /*delete spaces*/
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
var display_type = '
Warning: Undefined array key "display_type" in /var/www/conversietools/application/views/survey/jsEmbed.php on line 24
Warning: Trying to access array offset on value of type null in /var/www/conversietools/application/views/survey/jsEmbed.php on line 24
popup';
var isActive = '1';
var isPopup = readCookie('conversiepopup173');
if( isPopup != '1' && isActive == '1') {
var head = document.getElementsByTagName('head')[0];
if( typeof(jQuery) != 'undefined') {
callback();
} else {
var url = 'https://conversietools.be//js/jquery.js';
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
/*script.onreadystatechange = callback;*/
script.onload = callback;
head.appendChild(script);
}
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'https://conversietools.be//css/style_embed.css';
link.media = 'all';
head.appendChild(link);
}
function embedValidNavigation() {
/*Attach the event keypress to exclude the F5 refresh*/
jQuery('document').bind('keypress', function(e) {
if (e.keyCode == 116){
validNavigation = true;
}
});
/* Attach the event click for all links in the page */
jQuery("a").bind("click", function() {
validNavigation = true;
});
/* Attach the event submit for all forms in the page */
jQuery("form").bind("submit", function() {
validNavigation = true;
});
/* Attach the event click for all inputs in the page */
jQuery("input[type=submit]").bind("click", function() {
validNavigation = true;
});
}
function callback() {
embedValidNavigation();
var timeframe = 30 * 24 * 60 * 60 * 1000;
var count_visited = readCookie('conversie73_counter');
if( count_visited == 'null' || count_visited == null) {
count_visited = 1;
}
window.onbeforeunload = function(e) {
if( validNavigation == false) {
count_visited++;
}
createCookie('conversie73_counter', count_visited ,365);
}
var conversie_lasttime = readCookie('conversie73_lasttime');
var visitor_type = 'new';
if( visitor_type == 'anyone') {
//opensurvey_lightbox();
//return;
}
var visitor_from = 'all';
var when_appear = 'timer';
var where_appear = 'all';
var current_page = window.location.href.toLowerCase();
var time_fromlast = 0;
if( conversie_lasttime == 'null' || conversie_lasttime == null || count_visited < 2) {
createCookie('conversie73_lasttime', new Date().getTime() ,365);
createCookie('conversie73_counter', 1 ,365);
if( visitor_type == 'return')
return;
}
time_fromlast = new Date().getTime() - conversie_lasttime;
var current_visitor_type = 'new';
if( time_fromlast < timeframe)
current_visitor_type = 'return';
createCookie('conversie73_lasttime', new Date().getTime() ,365);
if( visitor_type != 'anyone' && current_visitor_type != visitor_type) {
return;
}
var referer = document.referrer;
var current_visitor_from = '';
if( referer.indexOf('facebook') > -1)
current_visitor_from = 'facebook';
if( referer.indexOf('twitter') > -1)
current_visitor_from = 'twitter';
if( referer.indexOf('utm') > -1)
current_visitor_from = 'google_organic';
if( referer.indexOf('adword') > -1)
current_visitor_from = 'adword';
if( current_visitor_from != visitor_from && visitor_from != 'all')
return;
var open_survey = true;
switch(where_appear) {
case 'home':
var location = window.location.href;
if( location.lastIndexOf('/') < 10) {
open_survey = true;
}
break;
case 'specific':
if( where_appear.toLowerCase().indexOf(current_page) > 0) {
open_survey = true;
}
break;
case 'all':
open_survey = true;
break;
}
if( open_survey) {
switch(when_appear) {
case 'enter':
opensurvey_lightbox();
break;
case 'leave':
var isLeave = 0;
if( isLeave == 1) {
var addEvent = function(obj, evt, fn) {
if (obj.addEventListener) {
obj.addEventListener(evt, fn, false);
}
else if (obj.attachEvent) {
obj.attachEvent("on" + evt, fn);
}
};
addEvent(document, "mouseout", function(event) {
event = event ? event : window.event;
console.log(event.clientY + '-' + event.clientX);
var from = event.relatedTarget || event.toElement;
if ( (!from || from.nodeName == "HTML") && event.clientY < 0 ) {
//hover to topbar
opensurvey_lightbox();
}
});
break;
window.addEventListener("beforeunload", function(e) {
if (e.keyCode == 116)
disabledConfirm_exit = true;
if(disabledConfirm_exit) return;
if(!e) e = window.event;
disabledConfirm_exit = true;
e.cancelBubble = true;
e.returnValue = 'Would you like fill the survey before leave. Click "Stay on Page" or "Don\'t reload" to enter survey information';
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
window.setTimeout(function() {
opensurvey_lightbox();
}, 3000);
return 'Please fill the survey before leave. Click "Stay on Page" or "Don\'t reload" to enter survey information';
});
break;
window.onbeforeunload = function(e)
{
if (e.keyCode == 116)
disabledConfirm_exit = true;
if(disabledConfirm_exit) return;
if(!e) e = window.event;
disabledConfirm_exit = true;
e.cancelBubble = true;
e.returnValue = 'Would you like fill the survey before leave. Click "Stay on Page" or "Don\'t reload" to enter survey information';
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
window.setTimeout(function() {
opensurvey_lightbox();
}, 1000);
return 'Please fill the survey before leave. Click "Stay on Page" or "Don\'t reload" to enter survey information';
}
}
break;
case 'timer':
var timeout = 0;
timeout *= 1000;
window.setTimeout(opensurvey_lightbox, timeout);
break;
case 'pages':
var totalPageVisited = readCookie('conversiepopup73_totalvisited');
if( totalPageVisited == null) totalPageVisited = 0;
totalPageVisited++;
createCookie('conversiepopup73_totalvisited', totalPageVisited ,365);
var countPages = 0;
if( totalPageVisited == countPages) {
opensurvey_lightbox();
}
break;
default:
opensurvey_lightbox();
break;
}
}
};
function opensurvey_lightbox() {
if( !survey_showed) {
var lightbox_url = 'https://conversietools.be//survey/jsEmbedContent/73&callback=?';
if( display_type == 'popup') {
jQuery.ajax({
url: lightbox_url,
dataType: 'jsonp',
crossDomain: true,
success: function(data) {
jQuery('#conversieToolInfo').remove();
jQuery('body').append(data[0]);
jQuery.getScript('https://conversietools.be//js/embed.js', function() {
survey_showed = true;
});
}
});
survey_showed = true;
} else if( display_type == 'static') {
jQuery.ajax({
url: lightbox_url,
dataType: 'jsonp',
crossDomain: true,
success: function(data) {
jQuery('#conversieToolInfo').after('