function getCookie(name) {
    name += "="; // append '=' to name string
    var i = 0; // index of first 'name=value' pair
    while (i < cook.length) {
       var offset = i + name.length; // end of section to compare with name string
        if (cook.substring(i, offset) == name) { // if string matches
           var endstr = cook.indexOf(";", offset); // locate end of 'name=value' pair
            if (endstr == -1) endstr = cook.length;
               return unescape(cook.substring(offset, endstr)); // return cookie value section
       }
       i = cook.indexOf(" ", i) + 1; // move i to next name=value pair
       if (i == 0) break; // no more values in cookie string
   }
   return null; // cookie not found
}

var cook = document.cookie;
var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000 * 3);
var userID = getCookie("WestpacID")
if (userID == null || userID == "") {
   var randomNum = (Math.random() * 1000000);
   CurrentYear = today.getYear();
   if (CurrentYear < 1000)
       CurrentYear = CurrentYear + 1900;
   userID= "d"+ CurrentYear + (today.getMonth()+1) +  today.getDate() + "t" +  today.getHours() + today.getMinutes() + today.getSeconds() + today.getTime() + "r" + Math.floor(randomNum);
   document.cookie = "WestpacID=" + escape(userID) + "; expires=" + expiry.toGMTString() + "; domain=.westpac.com.au" + ";path=/";
}