// Standard Overlay - Jquery version
// (C) 2004-2011 Join the Dots

var pageProt = location.protocol;
if (location.protocol == "file:") pageProt = "http:";

var vslgSurveyName = 'nsandi_survey_3342';  //E.g. name+survey, used in cookie
//var vslgSurveyTitle = 'Join the Dots Survey'; // Use in title of popover

overlayImageSrc = pageProt + "/sites/all/themes/nsi_main/images/bg/logo.gif";
overlayImageAlt = "NSandI";
surveyTitleText = "Take Our<br/> Survey!";
var surveyIntroText = "Please tell us what you think of the <strong style='font-size: 120%'>online account area</strong> of our website at the <strong style='font-size: 120%'>end of your visit</strong> by clicking the 'Yes, later' button. The survey will be completely confidential and secure, will only take about 5 minutes to complete and your feedback will help us improve our website";
var vslgSurveyURL = pageProt + '//' + 'survey.euro.confirmit.com/wix/p806464405.aspx';
var surveyLaterText = "Yes, Later";
var closeSurveyText = "No Thanks";
var closeOverlayTitle = "Close Overlay";
var surveyLinkContainerTitle = "Opens survey in a new window";
var jobNumber = "9999"; //For tracker

var triggerLocation = new Array();
var vslgDefaultLocationNumber = 1;  //Default

//Do not include http:// in shost - do include 'www'
var i=0;

//triggerLocation[i++] = { shost: "survey.euro.confirmit.com", spath: "/isa/HMCYGPGAHXJXBHABPDEBCDDRJDMAGPBF/TEMP/index.htm", 	locNumber: 1 };
//
//  for (var i in triggerLocation){
//
//    if ( (triggerLocation[i].shost && triggerLocation[i].spath && location.host.toLowerCase() == triggerLocation[i].shost.toLowerCase() && location.pathname.toLowerCase() == triggerLocation[i].spath.toLowerCase()) || (triggerLocation[i].stitle && document.title.toLowerCase() == triggerLocation[i].stitle.toLowerCase()) ) vslgDefaultLocationNumber = triggerLocation[i].locNumber;
//
//  }

var vslgLang = 9; //English

var vslgPopupHeight = 540;
var vslgPopupWidth = 650;

var overlay_position = "centered"; // "specified" or "centered"
var persist_position = "absolute"; // use "fixed" or "absolute"
var opaque_container = "opaque";  // use "hidden" or "opaque"

var vslgIntervalURL = pageProt + '//' + 'survey.euro.confirmit.com/isa/HMCYGPGAHXJXBHABPDEBCDDRJDMAGPBF/3342_NSandI/job3342interval.js'; // use job number in name, note different domain to client

var vslgCookiePersistence = 30*24*60*60*1000; //set to 30*24*60*60*1000 if 30 day cookie required. 10 milliseconds
var vslgBodyFontSize = 1 / 0.8; // as 1/(font-size of containing document, 0.7 is font-size of 70%)

var vslgBorderCol = '#C0C0C0'; // colour name (blue) or hex value (#00f)
var vslgIntervalRetry = 2000; // 2000 milliseconds - time allowed for loading external interval script
var vslgIntervalTimeout = 5000; // 5 seconds
var time_before_appearing = 2000; //Time before overlay appears

//IMPORTANT don't change anything below this line------------------------------------------------

var vslgObjHeight, vslgObjWidth, vslgTopPos, vslgLeftPos;

var sizeArray = getPageSize();

vslgObjHeight = 350;
vslgObjWidth = 400;

vslgTopPos = 50; //in px - absolute only.
vslgLeftPos = 50; //in px - absolute only

if (!window.XMLHttpRequest) persist_position = "absolute"; //IE6 and lower override as can't do fixed

var vslgInterval = 0;     //default 0, will be changed by external file
var vslgDebug = false;
var vslgIntervalID;
var vslgIntervalAttempts = 0; // DO NOT CHANGE

var vslgCook = 3;

cookiesEnabled();

var vslgrandomnum = (new Date()).getTime();
vslgrandomnum = Math.round(Math.abs(Math.sin(vslgrandomnum) * 1000000)) % 1000;
var vslgHitSample = false;

if (vslgInterval != 0) vslgHitSample = ((vslgrandomnum + 1) * vslgInterval /1000 <= 1) && vslgCook != "2" && vslfGetCookie(vslgSurveyName) != 1;

function vslfGetCookieVal (offset) {

  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1){
    endstr = document.cookie.length;
  }
  return unescape(document.cookie.substring(offset, endstr));
}

function vslfGetCookie (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 vslfGetCookieVal (j);
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0){
      break;
    }
  }
  return null;
}

function vslfSetCookie (name, value) {

  var argv = vslfSetCookie.arguments;
  var argc = vslfSetCookie.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 vslfCheckIntervalFile() {

  try {

    setSampleIntervalRemote();

    if (vslgInterval != 0) vslgHitSample = ((vslgrandomnum + 1) * vslgInterval /1000 <= 1) && vslgCook != "2" && vslfGetCookie(vslgSurveyName) != 1;


    clearInterval(vslgIntervalID);

    if (vslgHitSample){

      $('input').filter(function(index){
        return $(this).attr("value") == "Secure log in"; 
      }).removeAttr("onclick").click(function(){
        vslfDoPopOver();
      })
      $('a.bluetxt').filter(function(index){
        return $(this).attr("href") == "/secure-login"; 
      }).removeAttr("href").css({"cursor":"pointer"}).click(function(){
        vslfDoPopOver();
      })

    }
	   
  } catch (e) {

    vslgIntervalAttempts++;

    if ((vslgIntervalAttempts * vslgIntervalRetry) >  vslgIntervalTimeout) clearInterval(vslgIntervalID);

  }
}

function setSampleInterval(remoteInterval) {

  vslgInterval = remoteInterval;

}

function vslfLoadwork() {

  $.getScript(vslgIntervalURL, function() { });
  vslgIntervalID = setInterval("vslfCheckIntervalFile()",vslgIntervalRetry);

}

function getPageSize(){
  
  var xScroll = $(window).scrollTop();
  var yScroll = $(window).scrollLeft();
  
  var windowWidth = $(window).width(); 
  var windowHeight = $(window).height();

  var windowWidth2 = $(document).width(); 
  var windowHeight2 = $(document).height();

  arrayPageSize = new Array(windowWidth,windowHeight,windowWidth2) 
  return arrayPageSize;

}


function vslfDoPopOver() {

  if (vslgHitSample) {

    var expdate = new Date();
    expdate.setTime(expdate.getTime() + (vslgCookiePersistence));
    vslfSetCookie(vslgSurveyName,"1",expdate,"/");

    var surveyWidth, surveyWidth2, surveyTop, surveyHeight;

    surveyLeft = vslgBodyFontSize*vslgLeftPos/16 + 'em';

    if (overlay_position == "centered" && persist_position == "absolute"){

      surveyWidth = vslgObjWidth + 'px';
      surveyWidth2 = vslgObjWidth + 'px';
      surveyHeight = vslgObjHeight + 'px';

      surveyTop =  ((sizeArray[1]/2) - (vslgObjHeight/2) + $(window).scrollTop()) + 'px';
      surveyLeft = ((sizeArray[0]/2) - (vslgObjWidth/2) + $(window).scrollLeft()) + 'px';

    }

    if (overlay_position == "centered" && persist_position == "fixed"){

      surveyWidth2 = "100%";
    
      surveyHeightPercentage = 30;
      surveyWidthPercentage = 50;

      surveyWidth = surveyWidthPercentage + '%';
      surveyHeight = surveyHeightPercentage + '%';

      surveyLeft = (100 - surveyWidthPercentage)/2 + '%';
      surveyTop = (100 - surveyHeightPercentage)/2 + '%';

    }

    if (overlay_position == "specified" && persist_position == "fixed"){

      surveyHeight = "50%";
      surveyWidth = "50%";
      surveyWidth2 = "100%";
      surveyTop = vslgTopPos + "px";
      surveyLeft = vslgLeftPos + "px";

    }
  
    var vslgObjURL2 = "?c="+vslgDefaultLocationNumber+"&w="+screen.width+"&h="+screen.height+"&si="+vslgInterval+"&l="+vslgLang;
    var oTracker = "";
    oTracker = "<img src='" + pageProt + "//www.vsdiscuss.com/overlay-tracker/?r=" + jobNumber + "'/>";

   vfontsize = vslgBodyFontSize*0.75;
   vfontsize = vfontsize + 'em';
   var maincontent = $("<div id='surveyouter'><div id='surveyinner'><div id='outerImageDiv'><img id='overlayImage' src='" + overlayImageSrc + "' alt='" + overlayImageAlt + "'><a style='height:1px;' id='skiptarget' name='skiptarget' class='skip' tabindex='-1'/><div id='overlayTitleWrapper'><h1 id='overlayTitle'>" + surveyTitleText + "</h1></div></div><div id='surveyInnerDiv'>" + surveyIntroText + "<div id='navsection'><span class='genericBlueButton' style='margin-right: 2em;'><input type='button' id='buttonno' title='" + closeOverlayTitle + "' href='#' value='" + closeSurveyText + "'></input></span><span class='genericBlueButton'><input type='button' id='buttonyes' href='#' title='" + surveyLinkContainerTitle + "' value='" + surveyLaterText + "'></input></span></div></div>" + oTracker + "</div></div>").hide();
		   
   var surveyInnerHeightMargin = ((vslgObjHeight / 100) * 2.5);
   var surveyInnerWidthMargin = ((vslgObjWidth / 100) * 2.5);
   innerMargin = surveyInnerHeightMargin;
   if (surveyInnerWidthMargin > surveyInnerHeightMargin) innerMargin = surveyInnerWidthMargin;
   surveyInnerHeight = vslgObjHeight - (innerMargin*2) + 'px';
   surveyInnerWidth = vslgObjWidth - (innerMargin*2) + 'px';
   surveyInnerHeightMargin = surveyInnerHeightMargin + 'px'
   surveyInnerWidthMargin = surveyInnerWidthMargin + 'px'
   
   if (opaque_container == "opaque") $("body:first").append("<div id='opaqueouteroverlay'>&nbsp;</div>");
   $("body:first").append($(maincontent).fadeIn("slow"));

   if (opaque_container == "opaque") $("#opaqueouteroverlay").css({"z-index":"9998","width":$(document).width(),"height":$(document).height(),"position":"absolute","left":"0","top":"0","background-color":"black","opacity":"0"});
   $('#surveyouter').css({"z-index": "9999","width": surveyWidth, "position" : persist_position, "top":surveyTop, "left":surveyLeft, "font-family": "Verdana, sans-serif", "text-align":"left","background":"#C0C0C0","font-size":vfontsize,"-webkit-border-radius": "10px","-moz-border-radius": "10px","border-radius": "10px"});
   $('#surveyinner').css({"background":"white","-webkit-border-radius": "10px","-moz-border-radius": "10px","border-radius": "10px", "height": surveyInnerHeight,"width": surveyInnerWidth ,"margin-left":innerMargin,"margin-top":innerMargin});

   if (!$.browser.msie) $('#surveyouter').css({"background":"rgba(192,192,192,0.5)"}); //Non-IE Browsers
   
   $('#surveyInnerDiv').css({"padding":"2em","clear":"both"})
   $("#overlayImage").css({"padding-left":"2em","padding-top":"2em","float":"left"});
   
   $("#overlayTitle").css({"font-size":"2em","padding-top":"0.75em","color":"#1B7AB6"});
   $("#overlayTitleWrapper").css({"float":"left","padding-left":"4em","padding-right":"1em","margin-top":"3.5em"})
   $("#outerImageDiv").css({"text-align":"center","width":"100%"});
   if (opaque_container == "opaque") $("#opaqueouteroverlay").fadeTo("slow",0.5);
   
   $('#navsection').css({"padding-left":"4em","padding-top":"2em"});
   if (surveyHeight) $('#surveyouter').css({"height":surveyHeight});


   $('#skiptarget').focus();

   $(".overlayButton").css({"padding":"0.25em 1em","width":"7em","margin":"0 0 1em 0","text-align":"center","background-color":"#0077B1","text-decoration":"none","font-size":"120%","color":"white","display":"block","background-position":"left top","background-repeat":"repeat-x","-moz-border-radius": "5px", "-webkit-border-radius": "5px", "border-radius": "5px","font-weight":"bold"});
   
   $('#buttonyes').click(function(e){

     e.preventDefault() 
     vslgPu = window.open(vslgSurveyURL + vslgObjURL2,vslgSurveyName+Math.floor(Math.random()*10e20),"height="+vslgPopupHeight+",width="+vslgPopupWidth+",resizable=yes,scrollbars=yes,toolbar=no,menubar=no");
     $('#surveyouter').fadeOut("slow");
     $('#opaqueouteroverlay').fadeOut("slow");
     self.focus(); // Hides modal window in firefox only
     window.location.href="http://www.nsandi.com/secure-login";
   })

   $('#buttonno,#opaqueouteroverlay').click(function(e){
     e.preventDefault() 
     $('#surveyouter').fadeOut("slow");
     $('#opaqueouteroverlay').fadeOut("slow");
     window.location.href="http://www.nsandi.com/secure-login";
   });

  }
}

function cookiesEnabled(){

  vslfSetCookie("cookieenabledcheck","1");
  if (vslfGetCookie("cookieenabledcheck") == 1){

    vslgCook = 1;

  } else {

    vslgCook = 2;

  }
}

$(document).ready(function(){

  vslfLoadwork();

})

