(function(){
if(typeof jQuery!='undefined'){
return startScript();
}
function getScript(url,success){
var script=document.createElement('script');
script.src=url;
var head=document.getElementsByTagName('head')[0],done=false;
script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){done=true;success();}};
head.appendChild(script);
}
getScript('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js',function(){return startScript();});
function startScript(){
(function ($) {
var time = setTimeout(function () {setTimeout("startTrack()",1050);}, 0),
lastelm = null;
$.readyOrDone = function (fn) {
var s = document.readyState,
getLast = function () {
var elms = document.getElementsByTagName('*');
return elms[elms.length - 1];
};
//alert("s"+s);
if (s === 'complete') {
$.ready(function () {setTimeout("startTrack()",1050);});
} else if (typeof s === 'undefined') {
lastelm = getLast();
clearTimeout(time);
time = setTimeout(function () {
if (getLast() === lastelm && typeof document.readyState === 'undefined') {
$.ready(function () {setTimeout("startTrack()",1050);});
}
}, 1000);
}
$(fn);
};
})($);
}
})();
var popBox = {
width : 720,
height : 500,
featuredImage : "http://surveytool71.3s.se/popup/images/16632.png"
};
var w3c=(document.getElementById)? true: false;
var ns4=(document.layers)?true:false;
var ie5=(w3c && document.all && !window.opera)? true : false;
var ie6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var ie7 = (typeof document.body.style.maxHeight != "undefined" && document.all);
var strictMode = ((document.documentElement.clientWidth || document.documentElement.clientHeight) && (ie6 || ie7) && !window.opera) ? true : false;
var ns6=(w3c && !document.all)? true: false;
var windowWidth = ns6 ? window.innerWidth : document.body.clientWidth;
var windowHeight = ns6 ? window.innerHeight : document.body.clientHeight;
if (windowWidth == 0 || strictMode) windowWidth = document.documentElement.clientWidth;
if (windowHeight == 0 || strictMode) windowHeight = document.documentElement.clientHeight;
var maximum_duration_in_days = 44640;
var minimum_number_of_visits = 1;
var delay_in_seconds = 1;
var interval_in_hours = 1;
var maximum_number_of_responses = 10000;
var visitorInterval = 1;
var sUrl = "http://surveytool.3s.se/?s=tetrapakpopup201004";
var pageviews = 200;
var micp = 16199;
var sid = 0;
var trackerName = "3stracker16199";
var rightNow = new Date();
if(window.console){
console.log(trackerName);
}
/* cookie function */
function createCookie(name,value,minutes) {
if (minutes) {
var date = new Date();
//date.setTime(date.getTime()+(days*24*60*60*1000));
date.setTime(date.getTime()+(minutes*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/;"
}
function readCookie(name) {
var nameCookie = name + "=";
var cookieArray = document.cookie.split(';');
for(var i=0;i < cookieArray.length;i++) {
var cookie = cookieArray[i];
while (cookie.charAt(0)==' ') cookie = cookie.substring(1,cookie.length);
if (cookie.indexOf(nameCookie) == 0) return cookie.substring(nameCookie.length,cookie.length);
}
return null;
}
function makeKey (id,visit,view,time,flag,status) {
var key = [id.toString(16),visit.toString(16),view.toString(16),time.toString(16),flag,status];
return key.join(".");
}
function drawPopContainer() { //show the popup
var isMSIE = /*@cc_on!@*/false;
$("html").css("overflow","hidden").css("position","fixed");
$("body").css("overflow","hidden");
var popupTop = ($(window).height() > popBox.height)?($(window).height()-popBox.height)/2:$(window).height()/3;
var popupLeft = ($(window).width() > popBox.width)?($(window).width()-popBox.width)/2:$(window).width()/3;
var popupTop = (windowHeight > popBox.height)?(windowHeight-popBox.height)/2:windowHeight/3;
var popupLeft = (windowWidth > popBox.width)?(windowWidth-popBox.width)/2:windowWidth/3;
$("body").prepend('
');
if(window.console){
console.log("window height:"+$(window).height());
console.log("document height:"+$(document.body).height());
console.log("popbox height:"+popBox.height);
console.log("window width:"+$(window).width());
console.log("document width:"+$(document.body).width());
console.log("popbox width:"+popBox.width);
}
$("#cover").height($(window).height()).width($(window).width()+20);
$(window).resize(function(){
$("#cover").height($(window).height()).width($(window).width()+20);
$("#3spop").css("top",($(window).height()-$("#3spop").height())/2+"px").css("left",($(window).width()-$("#3spop").width())/2+"px");
});
}
function popClose(hasAccepted) { //restore orginal page layout and remove popup
var cookieStr = readCookie(trackerName);
var value = cookieStr.split(".");
sid = parseInt(value[0],16);
var returns = parseInt(value[1],16);
//var pageviews = parseInt(value[2],16);
var lastTimeStamp = parseInt(value[3],16);
var newKey = makeKey(sid,returns,pageviews,lastTimeStamp,1,(hasAccepted) ? 1:0);
createCookie(trackerName,newKey,maximum_duration_in_days);
if (hasAccepted) {
$.getJSON("http://surveytool.3s.se/popup/setResponseCount.php?micp="+micp+"&sid="+sid+"&domain="+location.hostname+"&status=Y&jsoncallback=?",function (data) {
//save response
});
window.open(sUrl+"&pop="+sid,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, width=800, height=600");
} else {
$.getJSON("http://surveytool.3s.se/popup/setResponseCount.php?micp="+micp+"&sid="+sid+"&domain="+location.hostname+"&status=N&jsoncallback=?",function (data) {
//save response
});
}
$("#3spop").remove();
$("#cover").remove();
$("html").css("overflow","auto").css("position","relative");
$("body").css("overflow","auto");
}
function startTrack() {
if (readCookie(trackerName) == null) { //new visitor
//alert("New visitor (no cookie found)\nNew cookie added.");
$.getJSON("http://surveytool.3s.se/popup/getNewSID.php?micp="+micp+"&domain="+location.hostname+"&now="+rightNow.getTime()+"&jsoncallback=?",function(data){
sid = parseInt(data.sid); //getting a ungiue ID from surveytool
if (sid > 0) { //if ID is valid i.e
var newKey = makeKey(sid,1,1,parseInt(rightNow.getTime()),0,0); //create a key for the cookie string
createCookie(trackerName,newKey,maximum_duration_in_days); //create cookie
//alert(minimum_number_of_visits);
if (minimum_number_of_visits==0) {//check for criteria to serve survey, in this case no minimum requirement of previous visit
$.getJSON("http://surveytool.3s.se/popup/getPopCount.php?micp="+micp+"&sid="+sid+"&view="+pageviews+"&visit=0&domain="+location.hostname+"&now="+rightNow.getTime()+"&jsoncallback=?",function (data) {
var popCount = parseInt(data.response); //get the total number of response so far
var visitorCount = parseInt(data.count); //get the total number of visitor so far
var toShow = (visitorCount > 0 && ((visitorCount % visitorInterval) == 0)) ? true : false;
//alert(toShow+":"+popCount+":"+visitorCount+":"+visitorInterval);
if (popCount >= 0 && popCount <= maximum_number_of_responses && toShow) { //show Popup
setTimeout(function () {
drawPopContainer();
//var newKey = makeKey(sid,returns,pageviews,lastTimeStamp,1,0);
createCookie(trackerName,newKey,maximum_duration_in_days);
},delay_in_seconds*1000);
}
});
}
}
});
} else { // returning visitor
var cookieStr = readCookie(trackerName);
var value = cookieStr.split(".");
sid = parseInt(value[0],16);
var returns = parseInt(value[1],16);
//var pageviews = parseInt(value[2],16);
var lastTimeStamp = parseInt(value[3],16);
var hasShown = (parseInt(value[4],16)) ? true : false;
//seconds for testing
var interval = interval_in_hours * 1000;
// if visitor return within a determined interval do not count as new visit
if (lastTimeStamp + interval < rightNow.getTime()) {
returns++;
lastTimeStamp = parseInt(rightNow.getTime());
}
if(window.console){
console.log("lastTimeStamp:"+lastTimeStamp);
console.log("interval:"+interval);
console.log("rightNow:"+rightNow.getTime());
}
pageviews++;
var newKey = makeKey(sid,returns,pageviews,lastTimeStamp,parseInt(value[4]),parseInt(value[5])); //update Key
createCookie(trackerName,newKey,maximum_duration_in_days);//update cookie
//check for criteria to serve survey
//if (!hasShown && returns > minimum_number_of_visits) {
$.getJSON("http://surveytool.3s.se/popup/getPopCount.php?micp="+micp+"&sid="+sid+"&view="+pageviews+"&visit="+returns+"&domain="+location.hostname+"&now="+rightNow.getTime()+"&jsoncallback=?",function (data) {
var popCount = parseInt(data.response); //get total number of responses so far
var visitorCount = parseInt(data.count); //get total number of visitor
var toShow = (visitorCount > 0 && ((visitorCount % visitorInterval) == 0)) ? true : false;
//alert(toShow+":"+popCount+":"+visitorCount+":"+visitorInterval);
if(window.console){
console.log("returning visitor-hasshown:"+hasShown+"-returns:"+returns+"-minvisits:"+minimum_number_of_visits+"-popcount:"+popCount+"-toShow:"+toShow+"-maxresponse:"+maximum_number_of_responses+"-visitorCount:"+visitorCount+"-visitorInterval:"+visitorInterval);
}
//alert("Returns: "+returns+"\nMin visits: "+minimum_number_of_visits+"\nHas shown survey?: "+hasShown+"\nTotal Responses: "+popCount+"\nPage visits: "+visitorCount);
if (returns >= minimum_number_of_visits && !hasShown && popCount > 0 && popCount <= maximum_number_of_responses && toShow) { //show popup
setTimeout(function () {
drawPopContainer();
//update cookie that user has seen popup (kenneth 2june10)
var newKey = makeKey(sid,returns,pageviews,lastTimeStamp,1,0); //update Key
createCookie(trackerName,newKey,maximum_duration_in_days);//update cookie
},delay_in_seconds*1000);
}
});
//console.log("returning visitor-hasshown:"+hasShown+"-returns:"+returns+"-minvisits:"+minimum_number_of_visits);
}
}