var LinksLimit = 4;
LinksLimit = parseInt(LinksLimit);

// Specify cookie name.
//var CookieName = "ABCRegion";
var CookieName = "ABCGuestID";

var DaysToLive = 0;
DaysToLive = parseInt(DaysToLive);

// No other customizations required.
var HistoryLink = new Array();
var HistoryTitle = new Array();
var HistoryContent = new String();

//if a cookie for this site exists, read its values
function GetCookie() 
{
var cookiecontent = '';
if(document.cookie.length > 0) 
{
   var cookiename = CookieName + '=';
   var cookiebegin = document.cookie.indexOf(cookiename);
   if(cookiebegin > -1) 
      {
      cookiebegin += cookiename.length;
      var cookieend = document.cookie.indexOf(";",cookiebegin);
      if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
      //cookiecontent = document.cookie.substr(cookiebegin,cookieend);
	  //cookiecontent = document.cookie.substr(cookiebegin,document.cookie.length);
	  if (document.cookie.indexOf("smtp.abc.net.au")>-1)
	  	{
	  	cookiecontent = document.cookie.substr(44,document.cookie.length);
		}
	 else {
	  	cookiecontent = document.cookie.substr(cookiebegin,document.cookie.length);	
		}		  
	  //alert("cookiecontent: " + cookiecontent);
      }
   }
//alert("cookiecontent: " + cookiecontent); 
if( cookiecontent.length < 3 ) { return; } 	//see if cookie contains any values
cookiecontent = unescape(cookiecontent); 	//decode the extracted value
var historyList = cookiecontent.split('&'); 	//add the cookiecontent into historylist and split it at & char occurance
for( var i = 0; i < historyList.length; i++ ) 	//loop through the array to extract its values
   {
   var link = historyList[i].split('=',2);
   HistoryLink.push(link[0]);
   HistoryTitle.push(link[1]);
   var temparray = link[0].split('amp;');
   link[0] = temparray.join('&');
   temparray = link[1].split('amp;');
   link[1] = temparray.join('&');   
   }
}

function PutCookie() 
{
if( HistoryLink.length < 1 ) { return; }
var len = HistoryLink.length;
var pairs = new Array();
for( var i = 0; i < HistoryLink.length; i++ ) 
	{ 
	pairs.push(HistoryLink[i]+'='+HistoryTitle[i]); 
	} //end for
var value = pairs.join('&');
var exp = new String();

if(DaysToLive > 0) {
   var now = new Date();
   now.setTime( now.getTime() + (DaysToLive * 24 * 60 * 60 * 1000) );
   exp = '; expires=' + now.toGMTString();
   }
   document.cookie = CookieName + "=" + escape(value) + '; path=/' + exp;
}

function SaveCurrentPage() 
{
//extract the page link/url
var link = document.URL;
var title = document.title.length > 1 ? document.title : 'Irrelevant page';
var temparray = link.split('&');
link = temparray.join('amp;');
var temparray = title.split('&');
title = temparray.join('amp;');
HistoryLink.push(link); //add the link to the array
HistoryTitle.push(title); //add page title to the array
}

GetCookie();
SaveCurrentPage();
PutCookie();
