//IMPORTANT - change these variables for each
var surveyName = "lloydswebsitesurvey";	//E.g. name+survey
var sampleInterval = 35;     //E.g. for every 10th person, sampleInterval = 10
var locationNumber = 1;    //E.g. trigger location number
var popupHeight = 440;
var popupWidth = 550;
var popupURL = 'http:\/\/survey.euro.confirmit.com/wix/p14886099.aspx';	//ensure that you escape http:// to http:\/\/
var cookiePersistence = 180*24*60*60*1000; //set to 30*24*60*60*1000 if 30 day cookie required. Currently set to 10 seconds for testing


//IMPORTANT don't change anything below this line------------------------------------------------

//variable for popup window is undefined
var pu;

var sWidth = 0;
var sHeight = 0;
var wWidth = 0;
var wHeight = 0;

// size of screen
if (window.screen)      {
    sWidth = window.screen.width;
    sHeight = window.screen.height;
  }
// size of browser window, excluding chrome.
if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    wWidth = window.innerWidth;
    wHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    wWidth = document.documentElement.clientWidth;
    wHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    wWidth = document.body.clientWidth;
    wHeight = document.body.clientHeight;
  }
  
  
if (navigator.appName=="Microsoft Internet Explorer") {
if (navigator.cookieEnabled==true) {
        var cook = 1;
}
else{
        var cook = 2;
}
    }
else {
        var cook = 3;
        }
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0)
break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie(name) {
var exp = new Date();
FixCookieDate (exp); // Correct for Mac bug
exp.setTime (exp.getTime() - 1); // This cookie is history
var cval = GetCookie (name);
if (cval != null)
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function vscheck(uC,pH,pW,pU) {
// Screen out those with cookies turned off (IE only check)
	if (cook != "2"){
		if (GetCookie(surveyName) != 1){
			var nth = sampleInterval;
			today = new Date();
			randomnum = today.getTime();
			randomnum = Math.round(Math.abs(Math.sin(randomnum) * 1000000)) % 1000;
			if ((randomnum + 1) * nth /1000 <= 1) {
				var expdate = new Date();
				expdate.setTime(expdate.getTime() + (cookiePersistence));
				SetCookie(surveyName,"1",expdate,"/");
				browserVer = parseInt(navigator.appVersion);

// Communis popmatic code
				var popH = 0;
				var popW = 0;
				var popUrl = "";
				var original = "";
		
				function fixPage(h,w,u){
					popH = h;
					popW = w;
					popUrl = u;
					fixLinks();
				}

				function doPop(){
				
					//pu = window.open(popUrl+"?c="+uC+"&w="+sWidth+"&h="+sHeight+"&wW="+wWidth+"&wH="+wHeight+"&k="+cook,"vswindow","height="+popH+",width="+popW+",resizable=yes,scrollbars=yes,toolbar=no,menubar=no");

					if(pu != undefined && !pu.closed && pu.location)
						 {pu.location.href = popUrl+"?c="+uC+"&w="+sWidth+"&h="+sHeight+"&wW="+wWidth+"&wH="+wHeight+"&k="+cook;}
					else
						{pu=window.open(popUrl+"?c="+uC+"&w="+sWidth+"&h="+sHeight+"&wW="+wWidth+"&wH="+wHeight+"&k="+cook,surveyName+Math.floor(Math.random()*10e20),"height="+popH+",width="+popW+",resizable=yes,scrollbars=yes,toolbar=no,menubar=no");
						if (!pu.opener) pu.opener = self;}
						if (self.focus && pu) {self.focus()}
				
				
				}

				function fixLinks(){
					docPs = document.getElementsByTagName("a");
					for(i=0;i<docPs.length;i++){

						//Excludes internet banking links from launching a pop-up
						//if (docPs[i].href && docPs[i].href != "http://www.lloydstsb.com/it/cmf/exturl.asp?asset=/assets/link/lloydstsb2004/external/log_on.xml" && docPs[i].href != "http://www.lloydstsb.com/it/cmf/exturl.asp?asset=/assets/link/lloydstsb2004/external/log_on_business.xml"){

						// check to see if the element has already got an onclick event handler
							
						if (!docPs[i].onclick){

							docPs[i].onclick = doPop;

						}

					}
				}

// IMPORTANT: next line sets height, width and location of survey respectively
				fixPage(pH,pW,pU);

			}
		}
	}
}




window.onload = function(){
  vscheck(locationNumber,popupHeight,popupWidth,popupURL);
}

