var cssSite = "https://ols.nab.com.au/jloan-web/wizard.ctl?wizardCode=MLC";
var cssCmaURL = "/Online_Services/0,,78099,00.html?";
var cssMaxWidth=screen.availWidth;
var cssMaxHeight=screen.availHeight;
var cssGoAheadflag="0";
var cssDHTML = (document.getElementById || document.all || document.layers);

var yes = 1;
var Y = 1;
var no = 0;
var N = 0;

function creatCookie(name, value, expires, path, domain, secure) {
 var expireDate = new Date;
 expireDate.setMonth(expireDate.getMonth()+expires);
 document.cookie = name + "=" + ( value ) + "; expires=" + expireDate.toGMTString() + "; path=/; domain=.mlc.com.au";
}

function custSurveyChk(){
 var lc = document.location.toString();
 var today = new Date(); 
 var curr_date = new Date(today.toGMTString());

// eligCookie - if customer meets requirements for survey
// cssCookie - initial visit cookie

//  if (lc.indexOf('=IDEok') != -1)
//  {
//   showPopUp();
//  } else {
   var cookieString = document.cookie;
   cookie2Valid = cookieString.indexOf('eligCookie');
   cookie1Valid = cookieString.indexOf('cssCookie');
   if (cookie2Valid!=-1)
   {
    eligCookie = getCookie('eligCookie');
    if ((eligCookie == 'qualified') && (cssGoAheadflag == '1'))
    {
     randomPopUp();
    } 
    
   } else if (cookie1Valid!=-1){
    cssCookie = getCookie('cssCookie');
    surveyDate = new Date();
    surveyDate = Date.parse(cssCookie);
    var lastVisit = checkCookie1(surveyDate);
    if (lastVisit > 6)
    {
     deleteCookie('cssCookie','/','.mlc.com.au');
     creatCookie('eligCookie', 'qualified', 3, '/', '.mlc.com.au', '');
    } 
   } else {
    creatCookie('cssCookie', curr_date, 3, '/', '.mlc.com.au', '')
   }
//  }
}


function checkCookie1(dateValue) {
 var oneDay = 1000 * 60 * 60 * 24;
 var getCurrentDate = new Date();
 getCurrentDate = getCurrentDate.getTime();
 dateDiff = Math.abs(dateValue - getCurrentDate);
 dateDiff = Math.round(dateDiff/oneDay);
 return (dateDiff);
}
  
function getCookie(name) {
 var cookValue = null;
 var myCookie =' ' + document.cookie+';';
 var searchCookie = ' '+name+'=';
 var cookieStart = myCookie.indexOf(searchCookie);
 var cookieEnd;
 if (cookieStart!=-1)
 {
  cookieStart+=searchCookie.length;
  cookieEnd=myCookie.indexOf(';',cookieStart);
  cookieValue=unescape(myCookie.substring(cookieStart,cookieEnd));
 }
 return cookieValue;
}

function showPopUp() {
 //  shows the popup survey window.
// surveyAccept(site,'CustomerSurvey',maxWidth,maxHeight,0,0,0,1,0,0,0,0,0);
	showme();
	document.getElementById('pop').focus();

// creatCookie('eligCookie','applied',6,'/','',''); 
}

function deleteCookie( name, path, domain ) { 
 document.cookie = name + "=" +
 ( ( path ) ? ";path=" + path : "") +
 ( ( domain ) ? ";domain=" + domain : "" ) +
 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function randomPopUp()  { 
 var highestChance = 50;
 var randomNum=Math.floor(Math.random()* highestChance);
 var ref = window.location;
//  this randomNum is arbitrarily chosen, may think of a better random function.
 if (randomNum==1)
 {
//  location.href = "http://www.national.com.au/cgi-bin/servStat.pl?ref="+ref+"&site="+cssSite;
//		location.href = ref+"?ide=IDEok";
		showPopUp();
 }
}

function surveyAccept (url,winName,winWidth,winHeight,sBars,menuBar,toolbar,resizable,status,dir,loc,lPix,tPix) {

 if (url=="") {url="http://www.national.com.au"};
 if (winName==null) {winName="extWin"};
 if (winWidth==null) {winWidth="100"};
 if (winHeight==null) {winHeight="500"};
 if (sBars==null) {sBars="1"};
 if (menuBar==null) {menuBar="1"};
 if (toolbar==null) {toolbar="1"};
 if (resizable==null) {resizable="1"};
 if (status==null) {status="1"};
 if (dir==null) {dir="1"};
 if (loc==null) {loc="1"};
 if (lPix==null) {lPix="1"};
 if (tPix==null) {tPix="1"};

    winWidth=screen.availWidth;
    winHeight=screen.availHeight;
    var winXPos = (winWidth-400)/2;
    var winYPos = (winHeight-400)/2;
 url= cssCmaURL+url+","+winName+","+winWidth+","+winHeight+","+sBars+","+menuBar+","+toolbar+","+resizable+","+status+","+dir+","+loc+","+lPix+","+tPix;

    globalWindowOpen(url,'winName',400,400,1,0,0,1,0,0,0,winXPos,winYPos);
}

function getObj(name)
{
  if (document.getElementById)
  {
   this.obj = document.getElementById(name);
 this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
 this.obj = document.all[name];
 this.style = document.all[name].style;
  }
  else if (document.layers)
  {
    this.obj = document.layers[name];
    this.style = document.layers[name];
  }
}

function invi(flag,name)
{
 if (!cssDHTML) return;
 var x = new getObj(name);
 x.style.visibility = (flag) ? 'hidden' : 'visible';
 x.style.display = (flag) ? 'none' : 'block'
}


function showme()
{

var winWidth=""; // screen.availWidth;
var winHeight="";//screen.availHeight;

if (parseInt(navigator.appVersion)>3){
 if ((navigator.appName=="Microsoft Internet Explorer")&&document.body){
  winWidth=document.body.offsetWidth;
  winHeight=document.body.offsetHeight;
 }
 else if (navigator.appName=="Netscape"){
  winWidth=window.innerWidth;
  winHeight=window.innerHeight;
 }
}

var winXPos = (winWidth-450)/2;
var winYPos = (winHeight-350)/3;
if (winXPos<0)
{
 winXPos = 0;
}
if (winYPos<0)
{
 winYPos = 0;
}
var inline="<div id='pop' tabindex='-1' style='z-index:500;border:#999 2px solid;font-size:1.1em;background-color:#fff;width:400px;height:340px;padding:5px;position:absolute;top:" + winYPos + ";left:" + winXPos + "'>";


sometext ="<script type=\"text/javascript\">dcsMultiTrack('DCS.dcsuri','CSS Displayed','WT.ti','CSS Displayed');</script><table><tr><td align='left' valign='top' height='40'><img src='/cms/dynamic/resources/images/webcontent/mlc_logo.gif' border='0' alt='mlc logo' /></td><td align='right' valign='top' height='40'><a tabindex='1' href='javascript:creatCookie(\"eligCookie\",\"applied\",6,\"/\",\"\",\"\");dcsMultiTrack(\"DCS.dcsuri\",\"CSS No Thankyou\",\"WT.ti\",\"CSS No Thankyou\");invi(1,\"pop\")'><img src='/cms/dynamic/resources/images/webcontent/nab_icon_close.gif' border='0' alt='close survey offer' /></a></td></tr>";
sometext +="<tr><td colspan='2' style='border-top:1px #ccc solid'>&nbsp;</td></tr>";
sometext +="<tr><td colspan='2'><p><h1>Improving our website</h1><br />Thank you for visiting our website today. </p><p>We are interested in knowing your thoughts about our website and would like to ask you a few questions using an online survey. </p> <p>The purpose of the survey is to help us refine our website so that it better meets your needs. </p><p>The survey is easy to complete and should take approximately 5 minutes. It is completely anonymous and your answers will not be disclosed to any third party. </p></td></tr>"
sometext +="<tr><td height='5' colspan='2'>&nbsp;</td></tr>";
sometext +="<tr><td colspan='2' align='right'><p><a href='javascript:creatCookie(\"eligCookie\",\"applied\",6,\"/\",\"\",\"\");dcsMultiTrack(\"DCS.dcsuri\",\"CSS No Thankyou\",\"WT.ti\",\"CSS No Thankyou\");invi(1,\"pop\")'><img tabindex='2' src='/cms/dynamic/resources/images/webcontent/btn_noThankYou.jpg' border='0' alt='cancel survey' /></a>&nbsp;<a tabindex='3' href=\"javascript:globalWindowOpenCSS(\'/cms/dynamic/Satisfaction_Survey/survey_unavailable.html\',\'cssSurvey\',780,560,Y,N,N,Y,N,N,N,0,0);\" onClick='javascript:invi(1,\"pop\");dcsMultiTrack(\"DCS.dcsuri\",\"CSS Start Survey\",\"WT.ti\",\"CSS Start Survey\");creatCookie(\"eligCookie\",\"applied\",6,\"/\",\"\",\"\");'><img src='/cms/dynamic/resources/images/webcontent/btn_startSurvey.jpg' border='0' alt='start survey' /></a></p></td></tr></table></div>";
message = inline+sometext;

document.write(message);

}



function globalWindowOpenCSS(targetURL, windowName, windowWidth, windowHeight, scrollBars,
 menuBar, toolbar, resizable, status, directories, location, leftPix, topPix)
{
 // Local Variables (if any)
 var strFeatures;
 var strCheckDefinition;

 // Validate the "windowName" variable. If the windowName has not been passed
 // then a date/time stamp will be assigned as the window name.
 strCheckDefinition = typeof windowName;
 if (strCheckDefinition == "undefined")
 {
  windowName = new Date();
  windowName = windowName.getTime();
  windowName = windowName.toString();
 }

 // Build strFeatures list depending on what variables have been passed into this
 // function.
 if ((isNaN(parseInt(windowWidth))) || (parseInt(windowWidth) == 0))
 {
  windowWidth = "700";
 }
 strFeatures = "width=" + parseInt(windowWidth);
 if ((isNaN(parseInt(windowHeight))) || (parseInt(windowHeight) == 0))
 {
  windowHeight = "500";
 }
 strFeatures += ",height=" + parseInt(windowHeight);
 if ((scrollBars == "no") || (scrollBars == "N") ||
  (scrollBars == "n") || (parseInt(scrollBars) == 0))
 {
  strFeatures += ",scrollbars=no";
 }
 else
 {
  strFeatures += ",scrollbars=yes";
 }
 if ((menuBar == "no") || (menuBar == "N") ||
  (menuBar == "n") || (parseInt(menuBar) == 0))
 {
  strFeatures += ",menubar=no";
 }
 else
 {
  strFeatures += ",menubar=yes";
 }
 if ((toolbar == "no") || (toolbar == "N") ||
  (toolbar == "n") || (parseInt(toolbar) == 0))
 {
  strFeatures += ",toolbar=no";
 }
 else
 {
  strFeatures += ",toolbar=yes";
 }
 if ((resizable == "no") || (resizable == "N") ||
  (resizable == "n") || (parseInt(resizable) == 0))
 {
  strFeatures += ",resizable=no";
 }
 else
 {
  strFeatures += ",resizable=yes";
 }
 if ((status == "no") || (status == "N") ||
  (status == "n") || (parseInt(status) == 0))
 {
  strFeatures += ",status=no";
 }
 else
 {
  strFeatures += ",status=yes";
 }
 if ((directories == "no") || (directories == "N") ||
  (directories == "n") || (parseInt(directories) == 0))
 {
  strFeatures += ",directories=no";
 }
 else
 {
  strFeatures += ",directories=yes";
 }
 if ((location == "no") || (location == "N") ||
  (location == "n") || (parseInt(location) == 0))
 {
  strFeatures += ",location=no";
 }
 else
 {
  strFeatures += ",location=yes";
 }
 if (isNaN(parseInt(leftPix)))
 {
  strFeatures += ",left=" + (screen.width/2 - parseInt(windowWidth)/2);
 }
 else
 {
  strFeatures += ",left=" + parseInt(leftPix);
 }
 if (isNaN(parseInt(topPix)))
 {
  strFeatures += ",top=" + (screen.height/2 - parseInt(windowHeight)/2);

 }
 else
 {
  strFeatures += ",top=" + parseInt(topPix);
 }
 strFeatures += ",channelmode=no";

 // Open the new window
 window.open(targetURL, windowName, strFeatures);

}