var PROD_account = "DM56053038NA;DM5604116MAD";
var DEV_account = "DM5611047BZF";

var theHost = window.location.hostname.toLowerCase();
var DEV_HOST = "whmm3662";
var SIT_HOST = "whmm3459";

var srvPrefix = "";

//ACCOUNT NUMBER(S)
var accountNumber = PROD_account;

if ((theHost.indexOf(DEV_HOST) != -1)) {
	srvPrefix = "/DEV";
	accountNumber = DEV_account;
} else if (theHost.indexOf(SIT_HOST) != -1) {
	srvPrefix = "/SIT";
	accountNumber = DEV_account;
}

var userName = "";
if (getCookie("JHSalesNetVisitor") != null)
	userName = getCookie("JHSalesNetVisitor");
else if (getCookie("JHServiceNetVisitor") != null)
	userName = getCookie("JHServiceNetVisitor");

if (userName == "" || userName == "null") {
	userName = "anonymous";
}


if (typeof(hbx_hc2) == 'undefined') {hbx_hc2="";}
if (typeof(hbx_hc3) == 'undefined') {hbx_hc3="";}
if (typeof(hbx_hc4) == 'undefined') {hbx_hc4="";}


var _hbEC=0,_hbE=new Array;function _hbEvent(a,b){b=_hbE[_hbEC++]=new Object();b._N=a;b._C=0;return b;}
var hbx=_hbEvent("pv");hbx.vpc="HBX0200u";hbx.gn="a.johnhancock.com";

var documentTitle = document.title.replace(/\//ig, "+");

//BEGIN EDITABLE SECTION
//CONFIGURATION VARIABLES
//hbx.acct="DM56053038NA;DM5604116MAD";//ACCOUNT NUMBER(S)
hbx.acct=accountNumber;

if (typeof(hbx_mlc) == 'undefined') {
   hbx.mlc="/CONTENT+CATEGORY";
} else {
   hbx.mlc=validateString(hbx_mlc);

   if (hbx_mlc.indexOf(documentTitle) == -1) { 
	hbx.mlc = hbx.mlc + "/" + validateString(documentTitle);
   }


   if (typeof(hbx_productInfo) != 'undefined')
	if (hbx_productInfo != "" && hbx_productInfo != null)
		hbx.mlc = hbx.mlc + "/" + validateString(hbx_productInfo);

}

hbx_mlc = hbx.mlc;
hbx.mlc = srvPrefix + hbx.mlc;

hbx.pndef="title";//DEFAULT PAGE NAME
hbx.ctdef="full";//DEFAULT CONTENT CATEGORY

//OPTIONAL PAGE VARIABLES
//ACTION SETTINGS
hbx.fv="";//FORM VALIDATION MINIMUM ELEMENTS OR SUBMIT FUNCTION NAME
hbx.dlf="n";//DOWNLOAD FILTER
hbx.dft="n";//DOWNLOAD FILE NAMING
hbx.elf="n";//EXIT LINK FILTER

//SEGMENTS AND FUNNELS
hbx.seg="";//VISITOR SEGMENTATION
hbx.fnl="";//FUNNELS

//CAMPAIGNS
hbx.cmp="";//CAMPAIGN ID
hbx.cmpn="";//CAMPAIGN ID IN QUERY
hbx.dcmp="";//DYNAMIC CAMPAIGN ID
hbx.dcmpn="";//DYNAMIC CAMPAIGN ID IN QUERY
hbx.dcmpe="";//DYNAMIC CAMPAIGN EXPIRATION
hbx.dcmpre="";//DYNAMIC CAMPAIGN RESPONSE EXPIRATION
hbx.hra="";//RESPONSE ATTRIBUTE
hbx.hqsr="";//RESPONSE ATTRIBUTE IN REFERRAL QUERY
hbx.hqsp="";//RESPONSE ATTRIBUTE IN QUERY
hbx.hlt="";//LEAD TRACKING
hbx.hla="";//LEAD ATTRIBUTE
hbx.gp="";//CAMPAIGN GOAL
hbx.gpn="";//CAMPAIGN GOAL IN QUERY
hbx.hcn="";//CONVERSION ATTRIBUTE
hbx.hcv="";//CONVERSION VALUE
hbx.cp="null";//LEGACY CAMPAIGN
hbx.cpd="";//CAMPAIGN DOMAIN

//CUSTOM VARIABLES
hbx.ci=userName;//CUSTOMER ID
hbx.hc1=validateString(userName)  + '|' + validateString(documentTitle.replace(/\//ig, "+"));	//CUSTOM 1
hbx.hc2=hbx_hc2;	//CUSTOM 2
if (hbx_hc3 != "") hbx.hc3=hbx_hc3 + '|' + validateString(userName);	//CUSTOM 3
hbx.hc4=hbx_hc4;	//CUSTOM 4
hbx.hrf="";//CUSTOM REFERRER
hbx.pec="";//ERROR CODES

//CUSTOM EVENTS
//hbx.pn="PUT+PAGE+NAME+HERE";//PAGE NAME(S)
hbx.pn = validateString(documentTitle); 
//hbx.lt="none";//LINK TRACKING
hbx.lt = "auto"; 


var oLink=document.getElementsByTagName("a");
for (var i=0; i < oLink.length; i++)
{	
	oLink[i].onmousedown=sa_onclick_prep;
}

 
function sa_onclick_prep()
{

	var msgText = "";
	var msgType = "";
	var srcText = "";
	var onclickText = "";
	var force = false;

	if (navigator.appName.indexOf("Netscape") != -1)
	{	
		var eS=arguments[0].target;
		var bNetsc=true;
	}
	else
	{
		var eS=window.event.srcElement;
		var bNetsc=false;
	}

	//remove internal format tags
	var cnt = 0;		
	while (eS.tagName.toLowerCase() != "a" && eS.tagName.toLowerCase() != "img" && cnt < 8 && eS.parentNode != null) 
	{
		eS = eS.parentNode;
		cnt++;
 	}

	if (eS.tagName.toLowerCase() == "a") 
	{
		if (typeof(eS.href) != "undefined") srcText=eS.href;
		if (typeof(eS.onclick) != "undefined" && eS.onclick != null) onclickText=eS.onclick.toString();
		msgText=eS.innerHTML;
		if (bNetsc)
			var oHT=eS.parentNode.innerHTML.toLowerCase();
		else
			var oHT=eS.outerHTML.toLowerCase();

		if (oHT.indexOf(".exe") > -1)		
			msgType="Executable";
		else if (oHT.indexOf(".pdf") > -1 || oHT.indexOf("pdffile") > -1)
			msgType="PDF";
		else if (oHT.indexOf("file") > -1)	
			msgType="File";	
	} 
	else if (eS.tagName.toLowerCase() == "img") 
	{
		if (bNetsc)
		{
			srcText=eS.parentNode.href;
			var mT=eS.parentNode.innerHTML;
		}
		else
		{
			if (typeof(eS.parentElement.href) == "undefined")
				srcText=eS.parentElement.innerText;
			else 
				srcText=eS.parentElement.href;
			
			var mT=eS.outerHTML;
		}
	
		var iA=mT.toLowerCase().indexOf("alt=");
		if (iA > -1)
		{
			if (mT.indexOf('"', iA+4) == iA+4)
				msgText=mT.substring(iA+5, mT.indexOf('"', iA+5));
			else
				msgText=mT.substring(iA+4, mT.indexOf(' ', iA+4));

			if (msgText == "null")
			{
				iA=mT.toLowerCase().indexOf("src=");
				if (iA > -1)
				{
					if (mT.indexOf('"', iA+4) == iA+4)
						msgText=mT.substring(iA+5, mT.indexOf('"', iA+5));
					else
						msgText=mT.substring(iA+4, mT.indexOf(' ', iA+4));
				}
			}
			
			if (msgText != "")
				msgType="Hyperlink";
		}
		else
		{ 
			var iC=iA=mT.toLowerCase().indexOf("_channel_");
			if (iC > -1)
				msgText="channel_"+mT.substring(iC+9, mT.indexOf("_", iC+9));
			else
			{ 
				var iN=mT.toLowerCase().indexOf("name=");
				if (iN > -1)
				{
					var iE=mT.indexOf(">", iN+5);
					if (iE == -1)
					{
						iE=mT.indexOf(" ", iN+5);
						if (iE > -1)
							msgText="button_"+mT.substring(iN+5, iE);		
						else
							msgText="channel";
					}
					else
						msgText="button_"+mT.substring(iN+5, iE);
				}
				else
					msgText="channel";
			}

			if (msgText != "")
			{
				if (msgText.indexOf("channel") > -1)
					msgType="Channel";
				else
					msgType="Button";
			}
		}
	} 


	
	SA_Message = document.title.substring(0,46);
	SA_Message = SA_Message.replace( /^\s*/, "" ).replace( /\s*$/, "" );
	SA_Message = "Page="+escape(SA_Message.replace(/\b \b/ig,'_'));
	

	if (srcText.toLowerCase().indexOf("javascript:") > -1) {
	   onclickText = onclickText.toLowerCase();
	   if (onclickText.indexOf("window.open(") > -1) {
		srcText = onclickText.substr(onclickText.indexOf("window.open(") + 12);
		if (srcText.indexOf(",") > -1) srcText = srcText.substring(0, srcText.indexOf(","));
		if (srcText.indexOf(")") > -1) srcText = srcText.substring(0, srcText.indexOf(")"));
		srcText = srcText.replace(/\'/ig,"").replace(/\"/ig,"");
	   } else {
		srcText=window.location.pathname;
		force = true;
	   }
	}

	if (msgText != "")
	{
		SA_Message=SA_Message+"&Link="+escape(msgText.replace(/\b \b/ig,'_'));
		if (msgType != "")
			SA_Message=SA_Message+"&Type="+msgType
	}
	
	if (getCookie("JHSalesNetVisitor") != null)
		SA_Message=SA_Message+"&JHSalesNetVisitor="+getCookie("JHSalesNetVisitor")
	else if (getCookie("JHServiceNetVisitor") != null)
		SA_Message=SA_Message+"&JHServiceNetVisitor="+getCookie("JHServiceNetVisitor")
	

	
	if (typeof(sa_onclick) == "function")
	{
		sa_onclick(srcText);
	}

//*** start HBX ***
	wrk = srcText.toLowerCase();
	if ( (wrk.indexOf("article_master") == -1 || force) && 
	    // wrk.indexOf("/jhportal/channel") == -1 && 
            // wrk.indexOf("/jhportal/dslchannel") == -1 &&
	    // wrk.indexOf("/jhportal/sslchannel") == -1 &&
	    // wrk.indexOf("/jhportal/front") == -1 &&
	     wrk.indexOf("file_master") == -1 )


	{ 

		srcText = validateString(srcText);
		var cName = hbx_mlc;
		if (hbx_mlc.lastIndexOf("/") != -1) { cName = hbx_mlc.substr(hbx_mlc.lastIndexOf("/") + 1); }

	
		var pName = srcText;
		if (srcText.lastIndexOf("/") != -1) { pName = srcText.substr(srcText.lastIndexOf("/") + 1); }

		var downloadMode = false;
		if (wrk.indexOf("/jhportal/channel") == -1 && 
            	    wrk.indexOf("/jhportal/dslchannel") == -1 &&
	    	    wrk.indexOf("/jhportal/sslchannel") == -1 &&
	    	    wrk.indexOf("/jhportal/front") == -1 ) downloadMode = true;

		if (typeof(_hbPageView) == "function")
		{
		   sendHBX(pName, hbx_mlc + "/Downloads/" + pName, cName, pName, true, downloadMode);
		}
	}									

//*** end HBX ***
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


function sendHBX(pName, mcl, channel, path, pageView, download) {

	if (download) { _hbDownload(validateString(path)); }
	if (pageView) { _hbPageView(validateString(pName), validateString(srvPrefix + mcl)); }
									
	_hbSet("c1",userName + "|" + validateString(channel.replace(/\//ig, "+")));
	_hbSet("c4",userName + "|" + validateString(path.replace(/\//ig, "+")));
	_hbSend();									
		
}	

function validateString(line) {
	var unacceptableSymbols = new Array(/\"/ig, /\'/ig, /\</ig, /\>/ig, /\?/ig,
					/\!/ig, /\#/ig, /\$/ig, /\%/ig, /\^/ig, /\*/ig, 
					/\:/ig, /\;/ig, /\\/ig, /\|/ig, /\~/ig);

    	line = line.replace(/\&/ig, "and");
	line = line.replace(/\,/ig, "+");
   	line = line.replace(/\ /ig, "+");

			
	for (i=0; i < unacceptableSymbols.length; i++) {
	   	line = line.replace(unacceptableSymbols[i], "");
	}
				
   	return line;
}		

function _hbOnPrePVR(){if (accountNumber == PROD_account) {_mlc += ';/LifeSales' + _mlc}}