// December 2009, Mike Ryan

//This function includes additional js files.  -Silvester
//Parameter:  The File path. 
function include(file)
{

  var script  = document.createElement('script');
  script.src  = file;
  script.type = 'text/javascript';
  script.defer = true;

  document.getElementsByTagName('head').item(0).appendChild(script);

}

// Since it could take some time to load the files adding these as first activity. 
// it is also good practices to check whether the files loaded or not before using any function within these files
/* include any js files here */
include('/system/js/PageFrom.js');

function doLink(value) {

	 console.info ("doLink() called w/ value: " + value);
	
     var bannerName = "";
     var bannerID = "";
	 var linkTitle = "";
	 var segments1 = "";
	 var segments2 = "";
	 var segments3 = "";
	 var segments4 = "";
     var title = "";
	 var dcsuri = "";
	 var metricsTracking = "";

	 var nameValuePairs = new String(value);

	 /* TaggingMetaData:banner or TaggingMetaData:link */
	 /* If none specified, assume link. */

	 var linkType = matchTaggingName("TaggingMetaData",nameValuePairs, false);
	 if (linkType == "") {
		  linkType == "link";
	 }
    //if enabletracking Off tracking events will be disabled
	var enabletracking = "On";
	if (linkType == "flash") 
	{
		enabletracking = matchTaggingName("enabletracking",nameValuePairs, false);	
	}
	 /* If no url specified, then can't do link. */
	 var url = matchTaggingName("url",nameValuePairs, false);
	 if (url == "") {
		  return(0);
	 }

	 var urlType = matchTaggingName("urltype",nameValuePairs,false);
	 if (urlType == "") {
		  // assume internal if not specified.
		  urlType="internal";
	 }

	 var urlTarget = matchTaggingName("urltarget",nameValuePairs, false);
	 if (urlTarget == "") {
		  // assume _self (same window)
		  urlTarget = "_self";
	 }

	 // Determine popup parameters
	 // This one is special one-time regex w/ [] around popupParams
	 var popupParamsRegex=/popupParams:\[([^\]]+)\]/i;
	 var popupParamsMatch=nameValuePairs.match(popupParamsRegex);
	 if (popupParamsMatch != null) {
		  var popupParams=popupParamsMatch[1];
	 } else {
		  // assume none if not specified.
		  popupParams="";
	 }

	 var metricsPrefix = matchTaggingName("metricsPrefix",nameValuePairs, false);

	 /* Fix for tabs on the same page -- the event is an onclick event. */
	 /* If link is on same page and tab is value, then simulate click. */
	 /* If not found, then just continue. */
	 /* Only apply to relative links, not absolute links. */
	 /* Only apply to links on this same page. */
	 if ((url.indexOf("#") > 0) && 
		 (url.substr(0,1) == "/") &&
		 (url.length > location.pathname.length) &&
		 (url.substr(0,location.pathname.length) == location.pathname)) {
		  var urlIndex = url.indexOf("#");
		  var urlPathname = url.substr(0,urlIndex);
		  var urlHash = url.substr(urlIndex);

		  if (urlPathname == location.pathname) {
			   /* tab corresponding to Hash. */
			   /* this code adapted from globalJS.js:initTabMenu() */
			   var mainMenuObj = document.getElementById('mainMenu');
			   if(mainMenuObj != null ) {
					var menuItems = mainMenuObj.getElementsByTagName('A');
					for (var i=0; i<menuItems.length; i++) {
						 if (menuItems[i].hash == urlHash) {
							  /* Call the showHide() method with an argument. */
							  /* Defined in globalJS.js. */
							  if (typeof(showHide) == "function") {
								   showHide("",i);
								   return;
							  }
							  else {
								   console.log("GlobalJS.js file not loaded.");
							  }
						 }
					}
			   }
		  }
	 }

	 // Entire try-catch block is for metrics purposes -- all metrics calling as part of doLink()
	 //   should be in here.

	 try {
		 //if enabletracking Condition
		 if(enabletracking == "On")
		 {
		  if (linkType == "banner") {
			   // Determine Banner Name
			   bannerName = matchTaggingName("bannertitle",nameValuePairs, false);
			   if (bannerName == "") {
					bannerName = "UnknownBanner";
			   }

			   bannerID = matchTaggingName("bannerid",nameValuePairs, false);
			   if (bannerID == "") {
					bannerID = "UnknownBannerID";
			   }
		  }

		  if (linkType == "link") {
			   // Determine Link Title
			   linkTitle = matchTaggingName("linkTitle",nameValuePairs, false);
			   if (linkTitle == "") {
					linkTitle = "UnknownLinkTitle";
			   }
		  }

		  /* Permanent fix -- segments are now appearing in doLink() calls. */
		  segments1 = matchTaggingName("segments1",nameValuePairs, false);
		  segments2 = matchTaggingName("segments2",nameValuePairs, false);
		  segments3 = matchTaggingName("segments3",nameValuePairs, false);
		  segments4 = matchTaggingName("segments4",nameValuePairs, false);

		  /* If segments are separated by a comman (,) make it a semi-colon separator instead. */
		  segments1 = segments1.replace(/,/g, ";");
		  segments2 = segments2.replace(/,/g, ";");
		  segments3 = segments3.replace(/,/g, ";");
		  segments4 = segments4.replace(/,/g, ";");

		  // Get unique title for link.
		  if (linkType == "link") {
			   title = encodeURIComponent(linkTitle) + "_" + (typeof(tcmPageID) != "undefined" ? tcmPageID : "");
			   // metrics prefix is optional parameter -- purpose is to provide a prefix for the
			   //   link similar to the prefixes that apply for GAQ, FAO, etc.
			   if (metricsPrefix != "") {
					title = metricsPrefix + "_" + title;
			   }
		  }
		  else if (linkType == "banner") {
			   title = encodeURIComponent(bannerName) + "_" + encodeURIComponent(bannerID) + "_" + (typeof(tcmPageID) != "undefined" ? tcmPageID : "");
		  }

		  // if internal -- then add the appropriate wt_ac as a query string at the end of the URL
		  // if external or asset -- then group some variables and do the dcs_multiTrack call

		  if (urlType == "internal" && linkType == "banner") {
			   // assumes no query parameter already in URL (which is wrong for press releases).

			   // If this url has an anchor, insert the WT.ac before the anchor.
			   if (url.indexOf("#") >= 0) {
					var insertionPoint = url.indexOf("#");
					url = url.substring(0,insertionPoint) + "?WT.ac=" + title + "&oc_id=" + title 
						 + url.substr(insertionPoint);
			   }
			   else {
					//  No anchor -- just add at end.
					url = url + "?WT.ac=" + title + "&oc_id=" + title;
			   }
			   // alert ("Just set up url for internal or banner as " + url);
		  }
		  else if (urlType == "asset") {
  			   
			   clearMultiTrackMeta();

			   if (linkType == "banner") {
				   	dcsuri = 'DL_' + title + "_" + encodeURIComponent(url);
					dcsMultiTrack('DCS.dcsuri',dcsuri,
								  'WT.ti',title,
								  "WT.cg_n","Download",
								  "WT.cg_s","",
								  "WT.seg_1",segments1,
								  "WT.seg_2",segments2,
								  "WT.seg_3",segments3,
								  "WT.seg_4",segments4,
								  "WT.ac",title,
								  "DCSext.oc_id",title,
								  "DCS.dcsqry","");

					/* Google */
					if (typeof(pageTracker) != "undefined") {
						 pageTracker._trackPageview(dcsuri);
					}

					multiTrackPauseExecution(multiTrackPauseTime);

			   }
			   else {
   				    dcsuri = 'DL_' + title + "_" + encodeURIComponent(url);
					dcsMultiTrack('DCS.dcsuri', dcsuri,
								  'WT.ti',title,
								  "WT.cg_n","Download",
								  "WT.cg_s","",
								  "WT.seg_1",segments1,
								  "WT.seg_2",segments2,
								  "WT.seg_3",segments3,
								  "WT.seg_4",segments4,
								  "DCS.dcsqry","");

					/* Google */
					if (typeof(pageTracker) != "undefined") {
						 pageTracker._trackPageview(dcsuri);
					}

					multiTrackPauseExecution(multiTrackPauseTime);

			   }
			   // alert ("Just completed dcsMultiTrack call for asset for uri DL_" +encodeURIComponent(url));
		  }
		  else if (urlType == "external") {
			   clearMultiTrackMeta();
			   if (linkType == "banner") {
				   	dcsuri = 'EXT_' + title + "_" + encodeURIComponent(url);
					dcsMultiTrack('DCS.dcsuri', dcsuri,
								  'WT.ti',title,
								  "WT.cg_n","External",
								  "WT.cg_s","",
								  "WT.seg_1",segments1,
								  "WT.seg_2",segments2,
								  "WT.seg_3",segments3,
								  "WT.seg_4",segments4,
								  "WT.ac",title,
								  "DCSext.oc_id",title,
								  "DCS.dcsqry","");

					/* Google */
					if (typeof(pageTracker) != "undefined") {
						 pageTracker._trackPageview(dcsuri);
					}

					multiTrackPauseExecution(multiTrackPauseTime);
			   }
			   else {
				    dcsuri = 'EXT_' + title + "_" + +encodeURIComponent(url);
					dcsMultiTrack('DCS.dcsuri',dcsuri,
								  'WT.ti',title,
								  "WT.cg_n","External",
								  "WT.cg_s","",
								  "WT.seg_1",segments1,
								  "WT.seg_2",segments2,
								  "WT.seg_3",segments3,
								  "WT.seg_4",segments4,
								  "DCS.dcsqry","");

					/* Google */
					if (typeof(pageTracker) != "undefined") {
						 pageTracker._trackPageview(dcsuri);
					}
					multiTrackPauseExecution(multiTrackPauseTime);
			   }

			   // alert ("Just completed dcsMultiTrack call for external link for uri EXT_" +encodeURIComponent(url) + "with segment: " + segments);
		  }
		  else {
			   // alert("Unknown urltype of " + urlType);
		  }

		  /* The presence of a metricsPrefix on an internal link is a signal to do an extra dcsMultiTrack */
		  /*   that otherwise wouldn't be done on an internal link, because the destination page */
		  /*   page event would normally be sufficient. */

		  if (linkType == "link" && urlType == "internal" && metricsPrefix != "") 
		  {
			   clearMultiTrackMeta();
			   dcsuri = title + ".html";

			   dcsMultiTrack('DCS.dcsuri',dcsuri,
							 'WT.ti',title,
							 "WT.cg_n",metricsPrefix,
							 "WT.cg_s","",
							 "WT.seg_1",segments1,
							 "WT.seg_2",segments2,
							 "WT.seg_3",segments3,
							 "WT.seg_4",segments4,
							 "DCS.dcsqry","");

			   /* Google */
			   if (typeof(pageTracker) != "undefined") {
					pageTracker._trackPageview(dcsuri);
			   }
			   multiTrackPauseExecution(multiTrackPauseTime);

			   mikeRyTest = metricsPrefix;
		  }


		 }
	 } catch (ex) {
		  // alert(ex.description);
	 }

	//  Update QS with CS,SCG and Au for PageFrom
	//  Added by Silvester
	url = addParamToQSToPopulatePageForm(url,contentGroup,subContentGroup,audience);

	 // Set variable to indicate that screen is leaving because of doLink() call
	 // Used to cancel popups if relevant.
	 mcExitViaDoLink = true;

	 // Call the URL that was extracted above.
	 if (urlTarget=="self" || urlTarget=="_self" || urlTarget==null) {
		  location.href=url;
	 } else {
		  // alert ("About to open Window url: " + url + " / urlTarget: " + urlTarget + " / popupParams: *" + popupParams +"*");
		 window.open(url,urlTarget,popupParams);
	 }

	 return (1);
}

/* Returns the value of the name/value pairs passed in nameValuePairs */
/* Assumes that it's "name:value;name:value; . . . " format. */
/* This is format for all data passed from CMS. */
/* Parameters:  Name:  name of value being looked for. */
/*              nameValuePairs:  complete string to parse out value. */
/*              returnNull -- if true, then return the actual value "" if the value exists but has a */
/*                            blank value.  else return actual word null if not in keyvalue pair. */
/*                            if false, then always just return "" if value is set to clear, or if value */
/*                            doesn't exist. */
function matchTaggingName(name,nameValuePairs,returnNull)
{
	 var taggingRegExp = new RegExp(name+":([^;]*)","i");
	 var taggingMatch = taggingRegExp.exec(nameValuePairs);
	 if (taggingMatch != null) {
		  return(taggingMatch[1]);
	 }
	 else {
		  if (returnNull)
			   return("null");
		  else 
			   return("");
	 }
}

/* Returns an associative array of name-value pairs passed in. */
/* name value pairs are in name:value;(name:value;) format. */
/* name must be non-blank.  Value can be blank. */
/* Colons and semi-colons are not allowed in name-value pairs -- used as terminators. */
function taggingNameArray(nameValuePairs)
{
	 var taggingRegExp = new RegExp("([^;:]+):([^;]*);*","g");
	 var taggingMatch;
	 var resultArray = {};

	 while ((taggingMatch = taggingRegExp.exec(nameValuePairs)) != null) {
		  resultArray[taggingMatch[1]] = taggingMatch[2];
	 }

	 return (resultArray);
}

/* Function used to insert millisecond timeout periods, for non IE browers */
/* This is used to prevent the image retrieval from being cancelled when going to */
/*  a new page.  This only happens in Firefox based browsers. */
/* In Testing 500 was too short, so 1000 ms is current time.  M. Ryan, 19-Aug-09. */
var multiTrackPauseTime = 2000;

function multiTrackPauseExecution(millis)
{
	 if (navigator.appName == "Microsoft Internet Explorer") {
		  /* alert ("This is an IE browser, so don't pause."); */
		  return;
	 }

	 var date = new Date();
	 var curDate = null;

	 do { curDate = new Date(); }
	 while(curDate-date < millis);
}

function clearMultiTrackMeta()
{
	 // Right now, clear only wt.ad values,
	 // Which are values inserted by Portal Abstraction Layer for banners.
	 metaValues = document.getElementsByTagName("meta");

	 for (var i=0; i<metaValues.length; i++) {
         if (metaValues[i].name != null)
         {
             if (metaValues[i].name == "wt.ad" ||
				 metaValues[i].name == "wt.oss" ||
				 metaValues[i].name == "wt.oss_r") {
                 metaValues[i].name = "";
                 metaValues[i].content = "";
			 }
		 }
		 else {
			  // alert("iteration "+i+" of metavalues: " + metaValues[i]);
		 }
	 }

	 return 1;
}


function virtualUrlSuffixForWebTrends() 
{
	 var title = ((typeof(contentGroup) != "undefined" ? (contentGroup != "" ? contentGroup : "null") : "null") + "_" + 
		         (typeof(subContentGroup) != "undefined" ? (subContentGroup != "" ? subContentGroup : "null") : "null") + "_" + 
				  (typeof(tcmPageID) != "undefined" ? (tcmPageID != "" ? tcmPageID : "null") : "null"));

	 return(title);
}

function trackEvent(type, value)
{
	 /* The type determines what kind or processing we do. */
	 /* Since all of these are dcsmultiTrack call, we need to call clearMultiTrackMeta first. */

	 type = type.toLowerCase();

	 console.info ("trackEvent called with type: " + type + ", value: " + value);

	 /* do not do right rail expansions. */
	 if (type == "rr") {
		  return 1;
	 }

     var nameValuePairs = new String(value);
	 var webtrendsString = "";

	 /* These are required for webforms, optional for everything else. */
     var scenarioName = matchTaggingName("scenarioName",nameValuePairs, false);
     var scenarioStep = matchTaggingName("scenarioStep",nameValuePairs, false);
     var scenarioLead = matchTaggingName("scenarioLead",nameValuePairs, false);
	 var title = matchTaggingName("title",nameValuePairs, false);
	 var localContentGroup = matchTaggingName("cg",nameValuePairs, false);
	 var localSubContentGroup = matchTaggingName("scg",nameValuePairs, false);
	 var formName = matchTaggingName("formName",nameValuePairs, false);
	 var bannerName = matchTaggingName("bannertitle",nameValuePairs, false);
	 var bannerID = matchTaggingName("bannerid",nameValuePairs, false);
	 var eventSubType = matchTaggingName("type",nameValuePairs, false);
	 var localSegments1 = matchTaggingName("segments1",nameValuePairs, false);
	 var localSegments2 = matchTaggingName("segments2",nameValuePairs, false);
	 var localSegments3 = matchTaggingName("segments3",nameValuePairs, false);
	 var localSegments4 = matchTaggingName("segments4",nameValuePairs, false);
	 var prefix = matchTaggingName("prefix",nameValuePairs, false);

	 /* For compatibility w/ old calls, segments1 used to be known as segments */
	 if (localSegments1 == "") {
		  var localSegments1 = matchTaggingName("segments",nameValuePairs, false);
	 }

	 var completeBannerTitle = "";

	 /* These are optional for all value -- only include if they are actually set on the line. */
	 var url = matchTaggingName("url",nameValuePairs, false);

	 // alert ("title: " + title);
	 // alert ("url: " + url);

	 if (type=="webform") {
		  /* Parse out variables from nameValuepairs */
		  /* For webforms, expect there to be "scenarioName:value;scenarioStep:value;scenarioLead:value" */

		  /* Sample:  trackEvent("webform","scenarioName:SampleForm;scenarioStep:1;scenarioLead:1"); */

		  if (scenarioLead == 1 && scenarioName == "Lead") {
			   localContentGroup = "Lead";
			   localSegments1 = "";
			   title = "TY_" + encodeURIComponent(scenarioName) + "_" + virtualUrlSuffixForWebTrends();
			   url = title + ".html";
		  }
		  else if (scenarioLead == 0 && scenarioName == "ServiceLead") {
			   localContentGroup = "ServiceLead";
			   localSegments1 = "service";
			   title = "TY_" + encodeURIComponent(scenarioName) + "_" + virtualUrlSuffixForWebTrends();
			   url = title + ".html";
		  }
		  else if (formName != "") {
			   title = "TY_" + encodeURIComponent(formName) + "_" + virtualUrlSuffixForWebTrends();
			   url = title + ".html";
			   if (localContentGroup == "") {
					localContentGroup = "FormNonLead";
			   }
		  }

		  clearMultiTrackMeta();

		  // dcsuri should be set by existing thank you url -- hardcoding a dummy one here.

		  dcsMultiTrack("DCS.dcsuri",url,
						"WT.si_n",encodeURIComponent(scenarioName),
						"WT.si_x",scenarioStep,
						"WT.si_cs",scenarioLead,
			            "WT.cg_n",localContentGroup,
						"WT.cg_s",(typeof(subContentGroup) != "undefined" ? subContentGroup : ""),
			            "WT.seg_1",localSegments1,
			            "WT.seg_2",localSegments2,
			            "WT.seg_3",localSegments3,
			            "WT.seg_4",localSegments4,
						"WT.ti",title,
						"DCS.dcsqry","");

		  // Google would go here -- would use the same value for 'url' as above.
		  if (scenarioLead == 1 && scenarioName == "Lead") {
				if (typeof(pageTracker._trackPageview) != "undefined") {
					 pageTracker._trackPageview(url);
				}
				if (typeof(pageTracker._trackEvent) != "undefined") {
					 pageTracker._trackEvent('Form', 'Lead','');
				}
			   
		  }
		  else if (scenarioLead == 0 && scenarioName == "ServiceLead") {
			   if (typeof(pageTracker._trackPageview) != "undefined") {
					pageTracker._trackPageview(url);
			   }
			   if (typeof(pageTracker._trackEvent) != "undefined") {
					pageTracker._trackEvent('Form', 'ServiceLead','');
			   }
		  }

		  // End Google

	 }
	 else if (type == "tab") {
		  // Parse out variables -- only tab name and tab anchor are tracked. */
		  
		  /* Sample: trackEvent("tab","tabAnchor:value"); */

//		  var tabName = matchTaggingName("tabName",nameValuePairs);
//		  if (tabName == "") {
//			   tabName = "UnknownTabName";
//		  }

		  var tabAnchor = matchTaggingName("tabAnchor",nameValuePairs);
		  if (tabAnchor == "") {
			   tabAnchor = "UnknownTabAnchor";
		  }		  

		  var title = "Tab_" + encodeURIComponent(tabAnchor) + "_" + (typeof(tcmPageID) != "undefined" ? tcmPageID : "");

		  /* Ask Latha about tabs is title the anchor name also, or can they be different? */

		  /* Take the current url and strip off the # and ? if they are present. */
		  var newURL = window.location.pathname + "#" + encodeURIComponent(tabAnchor);

		  clearMultiTrackMeta();

		  // alert ("about to call dcsMultiTrack() called with DCS.dcsuri = " + newURL);

		  // alert ("Skipping the dcsMultitrack() call right now.");
		  // dcsMultiTrack("DSC.dcsuri",newURL,"WT.ti",title);

		  // alert ("dcsMultiTrack() called with DCS.dcsuri = " + newURL);
	 }
	 else if (type == "button") {
		  // Parse out variables -- only button name is tracked. */

		  /* Sample:  trackEvent("button","buttonName:value"); */

		  var buttonName = matchTaggingName("buttonName",nameValuePairs);
		  if (buttonName == "") {
			   buttonName = "UnknownButtonName";
		  }

		  var title = encodeURIComponent(title) + "_" + (typeof(tcmPageID) != "undefined" ? tcmPageID : "");

		  clearMultiTrackMeta();

		  // alert ("button title: " + title);

		  if (bannerID != "" && bannerName != "") {
			   completeBannerTitle = encodeURIComponent(bannerName) + "_" + encodeURIComponent(bannerID) + "_" + (typeof(tcmPageID) != "undefined" ? tcmPageID : "");
		  }
		  else {
			   completeBannerTitle = "";
		  }

		  /* A few special cases exist -- */
		  if (buttonName == "OfficeLocatorforScore.html") {
			   dcsMultiTrack("DCS.dcsuri",buttonName,
						 "WT.ti",title,
						 "WT.cg_n",localContentGroup,
						 "WT.cg_s",localSubContentGroup,
						 "WT.seg_1",localSegments1,
			             "WT.seg_2",localSegments2,
			             "WT.seg_3",localSegments3,
			             "WT.seg_4",localSegments4,
		                 "WT.si_n",encodeURIComponent(scenarioName),
						 "WT.si_x",scenarioStep,
						 "WT.si_cs",scenarioLead);

			   /* Google Code */
			   if (typeof(pageTracker) != "undefined") {
					pageTracker._trackPageview(buttonName);
			   }
		  }
		  else if (buttonName == "GetAQuote.html") {
			   
			   title = "GAQ_" +  virtualUrlSuffixForWebTrends();
			   url = title + ".html";

			   // alert ("Get a Quote title: " + title);

			   clearMultiTrackMeta();

			   dcsMultiTrack("DCS.dcsuri",url,
							 "WT.ti",title,
							 "WT.cg_n",localContentGroup,
							 "WT.cg_s",localSubContentGroup,
							 "WT.seg_1",localSegments1,
			                 "WT.seg_2",localSegments2,
			                 "WT.seg_3",localSegments3,
			                 "WT.seg_4",localSegments4,
							 "WT.si_n",encodeURIComponent(scenarioName),
							 "WT.si_x",scenarioStep,
							 "WT.si_cs",scenarioLead,
							 "DCS.dcsqry","");

			   /* Google Code */
				if (typeof(pageTracker) != "undefined") {
				//pageTracker is causing page flicker in IE6, asyncronously call it using setTimeout
				//pageTracker._trackPageview(url);
				setTimeout("pageTracker._trackPageview('" + url + "')", 0);
				}

		  }
		  else if ((buttonName == "findanoffice") || ((buttonName == "Locateanoffice"))) {
			   
			   if (buttonName == "findanoffice") {
			     title = "FAO_" +  virtualUrlSuffixForWebTrends();
			   } else if (buttonName == "Locateanoffice") {
			     title = "LAO_" +  virtualUrlSuffixForWebTrends();
			   }
			   url = title + ".html";

			   // alert ("Get a Quote title: " + title);

			   clearMultiTrackMeta();

			   dcsMultiTrack("DCS.dcsuri",url,
							 "WT.ti",title,
							 "WT.cg_n",localContentGroup,
							 "WT.cg_s",localSubContentGroup,
							 "WT.seg_1",localSegments1,
			                 "WT.seg_2",localSegments2,
			                 "WT.seg_3",localSegments3,
			                 "WT.seg_4",localSegments4,
							 "WT.si_n",encodeURIComponent(scenarioName),
							 "WT.si_x",scenarioStep,
							 "WT.si_cs",scenarioLead,
							 "DCS.dcsqry","");

			   /* Google Code */
			   if (typeof(pageTracker) != "undefined") {
			         
				 if (buttonName == "findanoffice") {
				       pageTracker._trackPageview(url);
			          } else if (buttonName == "Locateanoffice") {
			               setTimeout("pageTracker._trackPageview('" + url + "')", 0);
			          }
			   }
		  }
		  else if (buttonName == "signin.html") {

			   title = "SI_" +  virtualUrlSuffixForWebTrends();
			   url = title + ".html";

			   clearMultiTrackMeta();

			   dcsMultiTrack("DCS.dcsuri",url,
							 "WT.ti",title,
							 "WT.cg_n",localContentGroup,
							 "WT.cg_s",localSubContentGroup,
							 "WT.seg_1",localSegments1,
							 "WT.seg_2",localSegments2,
							 "WT.seg_3",localSegments3,
							 "WT.seg_4",localSegments4,
							 "WT.si_n",encodeURIComponent(scenarioName),
							 "WT.si_x",scenarioStep,
							 "WT.si_cs",scenarioLead,
							 "DCS.dcsqry","");

			   /* Google Code */
			   if (typeof(pageTracker) != "undefined") {
					pageTracker._trackPageview(url);
			   }

			   // alert ("signin button dcsMultiTrack() completed -- using title " + title);

			   }

		  else {
			   // All other buttons tracked using the following:
			   url = "EV_" + title + "_" + encodeURIComponent(url);

			   clearMultiTrackMeta();

			   dcsMultiTrack("DCS.dcsuri", url,
						 "WT.ti",title,
						 "WT.cg_n",localContentGroup,
						 "WT.cg_s",localSubContentGroup,
						 "WT.seg_1",localSegments1,
						 "WT.seg_2",localSegments2,
			             "WT.seg_3",localSegments3,
			             "WT.seg_4",localSegments4,
						 "WT.si_n",encodeURIComponent(scenarioName),
						 "WT.si_x",scenarioStep,
						 "WT.si_cs",scenarioLead,
						 "WT.ac", completeBannerTitle,
						 "DCSext.oc_id", completeBannerTitle,
						 "DCS.dcsqry","");

			   /* Google Code */
			   if (typeof(pageTracker) != "undefined") {
					pageTracker._trackPageview(url);
			   }
		  }

		  multiTrackPauseExecution(multiTrackPauseTime);

	 }
	 else if (type == "rr") {
		  // Note, right rail removed -- requirements change.

		  // Parse out variables -- only div name is tracked. */

  		  /* Sample:  trackEvent("rr","divTagName:value"); */


		  var divTagName = matchTaggingName("divTagName",nameValuePairs);
		  if (divTagName == "") {
		  	   divTagName = "UnknownRRComponentName";
		  }

		  var title = "RR_" + encodeURIComponent(divTagName) + "_" + (typeof(tcmPageID) != "undefined" ? tcmPageID : "");

		  clearMultiTrackMeta();

		  dcsMultiTrack("WT.ti",title);
	 }
	 else if (type == "flashevent") {

		  if (prefix == "")
			   prefix = "FLASH";
		  var clickTags = false;
		  var impressionTags = false;

		  switch(eventSubType.toLowerCase()) {
		  case "rotatingbannerload" :
			   prefix = "rload";
			   impressionTags = true;
			   break;
		  case "rotatingbannerrotation" :
			   prefix = "rrot";
			   impressionTags = true;
			   break;
		  case "rotatingbannerclick" :
			   prefix = "rac";
			   clickTags = true;
			   break;
		  case "rotatingbannertabclick" :
			   prefix = "rtab";
			   impressionTags = true;
		  }

		  if (bannerID != "" && bannerName != "") {
			   completeBannerTitle = encodeURIComponent(prefix) + "_" + encodeURIComponent(bannerName) + "_" + encodeURIComponent(bannerID) + "_" + (typeof(tcmPageID) != "undefined" ? tcmPageID : "");
		  }
		  else {
			   completeBannerTitle = encodeURIComponent(prefix) + "_" + (typeof(tcmPageID) != "undefined" ? tcmPageID : "");
		  }

		  var dcsuri = completeBannerTitle + ((url != "") ? ("_" + encodeURIComponent(url)) : "");

		  /* Load mappings for all vendors. */
		  var fieldMapping = loadFieldMappings();

		  /* create variable that will hold each vendor's mappings. */
		  var vendorMapping = {};
		  var vendor;

		  /* Parse the nameValuePairs that were passed in trackEvent(). */
		  var nameValueArray = taggingNameArray(nameValuePairs);

		  if ((typeof (fieldMapping) != "undefined") && 
			  (typeof (fieldMapping[type] != "undefined"))) {
		  
			   for (vendor in fieldMapping[type]) {
					if (fieldMapping[type][vendor] == "disabled") {
						 continue;
					}

					vendorMapping = fieldMapping[type][vendor];

					if (vendor == "webtrends") {
						 var multiTrackValues = [];

						 /* auto-values */
						 multiTrackValues.push("DCS.dcsuri",dcsuri);
						 multiTrackValues.push("WT.ti",encodeURIComponent(completeBannerTitle));
						 multiTrackValues.push("DCS.dcsqry","");
						 multiTrackValues.push("WT.ad", ((impressionTags == true) ? completeBannerTitle : ""));
						 multiTrackValues.push("WT.ac", ((clickTags == true) ? completeBannerTitle : ""));
						 multiTrackValues.push("DCSext.oc_id", ((clickTags == true) ? completeBannerTitle : ""));

						 /* the following were previously hard-coded -- not anymore */
						 //	"WT.cg_n",localContentGroup,
						 //	"WT.cg_s",localSubContentGroup,
						 //	"WT.seg_1",localSegments1,
						 //	"WT.seg_2",localSegments2,
						 //	"WT.seg_3",localSegments3,
						 //	"WT.seg_4",localSegments4,

						 /* for every value in target string */
						 /*   find this value in the associative array. */
						 /*   set add to the values array, both the field value, and the key */
						 var baseName;
						 for (baseName in nameValueArray) {
							  if (vendorMapping[baseName] != null) {
								   multiTrackValues.push(vendorMapping[baseName],encodeURIComponent(nameValueArray[baseName]));
							  }
						 }
						 dcsMultiTrack.apply(null, multiTrackValues);
					}
					else if (vendor == "google") {

						 /* Google Code */
						 if (typeof(pageTracker) != "undefined") {
							  pageTracker._trackPageview(dcsuri);
						 }
					}
			   }
		  }
	 }
	 else if (type == "taf") {
		  title = "TAF-" + eventSubType + "_" + virtualUrlSuffixForWebTrends();
		  url = title + ".html";

		  clearMultiTrackMeta();

		  dcsMultiTrack("DCS.dcsuri",url,
						"WT.ti",title,
						"WT.cg_n",localContentGroup,
						"WT.cg_s",localSubContentGroup,
						"WT.seg_1",localSegments1,
						"WT.seg_2",localSegments2,
						"WT.seg_3",localSegments3,
						"WT.seg_4",localSegments4,
						"WT.si_n",encodeURIComponent(scenarioName),
						"WT.si_x",scenarioStep,
						"WT.si_cs",scenarioLead,
						"DCS.dcsqry","");

		  /* Google Code */
		  if (typeof(pageTracker) != "undefined") {
			   pageTracker._trackPageview(url);
		  }


	 }
	 else if (type == "sr") {
		  /* called from search results. */
		  /* sample call:   trackEvent("sr","title:<link_title>;url:<pageID>;type<rec|sr>"); */
		  var linkTitle = title;
		  var pageID = url;

		  url =   "SR_" +  eventSubType + "_" + linkTitle + "_" + pageID;
		  title = "SR_" +  eventSubType + "_" + linkTitle + "_" + pageID;

		  clearMultiTrackMeta();

		  dcsMultiTrack("DCS.dcsuri",url,
						"WT.ti",title,
						"WT.cg_n",localContentGroup,
						"WT.cg_s",localSubContentGroup,
						"WT.seg_1",localSegments1,
						"WT.seg_2",localSegments2,
						"WT.seg_3",localSegments3,
						"WT.seg_4",localSegments4,
						"WT.si_n",encodeURIComponent(scenarioName),
						"WT.si_x",scenarioStep,
						"WT.si_cs",scenarioLead,
						"WT.oss","",
						"WT.oss_r","",
						"DCS.dcsqry","");

		  /* Google Code */
		  if (typeof(pageTracker) != "undefined") {
			   pageTracker._trackPageview(title);
		  }
		  
		  multiTrackPauseExecution(multiTrackPauseTime);
	 }
	 //Modified by sarumalla -- 10-Mar-10
	 else if (type == "overlay") {
	  title = "OVR_" + virtualUrlSuffixForWebTrends();	  
	 		  url = title + ".html";
	 
	 		  clearMultiTrackMeta();
	 
	 		  dcsMultiTrack("DCS.dcsuri",url,
	 						"WT.ti",title,
	 						"WT.cg_n",localContentGroup,
	 						"WT.cg_s",localSubContentGroup,
	 						"WT.seg_1",localSegments1,
	 						"WT.seg_2",localSegments2,
	 						"WT.seg_3",localSegments3,
	 						"WT.seg_4",localSegments4,
	 						"WT.si_n",encodeURIComponent(scenarioName),
	 						"WT.si_x",scenarioStep,
	 						"WT.si_cs",scenarioLead,
	 						"DCS.dcsqry","");
	 
	 		  /* Google Code */
	 		  if (typeof(pageTracker) != "undefined") {
	 			   pageTracker._trackPageview(url);
	 		  }
	 		  
	 
	 }

	 // alert ("trackEvent call finished");

	 return 1;
}


/* ********************************************************** */
/*             Starting of C2C EVENT Tracking Code                       */
/* ********************************************************** */

function trackC2CEvent(type, value)
{
        //alert('Inside trackC2CEvent')
        var nameValuePairs = new String(value);
        
        var eventName = matchTaggingName("eventName",nameValuePairs);
        var title = matchTaggingName("title",nameValuePairs, false);
        var localContentGroup = matchTaggingName("cg",nameValuePairs, false);
		var localSubContentGroup = matchTaggingName("scg",nameValuePairs, false);
		var scenarioLead = matchTaggingName("scenarioLead",nameValuePairs, false);
        var scenarioName = matchTaggingName("scenarioName",nameValuePairs, false);
        var scenarioStep = matchTaggingName("scenarioStep",nameValuePairs, false);
        var localz_age  = matchTaggingName("z_age",nameValuePairs, false);
		var localz_gnd  = matchTaggingName("z_gnd",nameValuePairs, false);
        var localz_small3  = matchTaggingName("z_small3",nameValuePairs, false);
        var localz_small4  = matchTaggingName("z_small4",nameValuePairs, false);
		var localz_tool  = matchTaggingName("z_tool",nameValuePairs, false);
		var local_ad  = matchTaggingName("ad",nameValuePairs, false);
		var local_ac  = matchTaggingName("ac",nameValuePairs, false);
		var local_oc_id  = matchTaggingName("oc_id",nameValuePairs, false);
		var localz_num3  = matchTaggingName("z_num3",nameValuePairs, false);
		var localz_num4  = matchTaggingName("z_num4",nameValuePairs, false);
		var localz_inc  = matchTaggingName("z_inc",nameValuePairs, false);
		var chart_type  = matchTaggingName("chartType",nameValuePairs, false);
	    var displayType = matchTaggingName("displayType",nameValuePairs, false);
	
		if(localz_small3 == "undefined"){
			localz_small3="";
			}
		if(localz_small4 == "undefined"){
			localz_small4="";
			}

        if (type == "c2cButton") {

			    if (eventName == "onC2CDisplayed") {
				    clearMultiTrackMeta();
				    dcsMultiTrack("DCS.dcsuri", "/"+title+"_"+displayType+"_"+tcmPageID+".html", "WT.ti", title+"_"+tcmPageID, "WT.cg_n", localContentGroup,"WT.cg_s",localSubContentGroup,"WT.si_cs", scenarioLead, "WT.si_n",scenarioName ,"WT.si_x", scenarioStep,"WT.z_age",localz_age,"WT.z_gnd",localz_gnd,"WT.z_small3",localz_small3,"WT.z_small4",localz_small4,"WT.z_tool",localz_tool,"WT.ad",local_ad,"WT.ac",local_ac,"DCSext.oc_id",local_oc_id,"WT.z_num3",localz_num3,"WT.z_num4",localz_num4 ,"WT.z_inc",localz_inc);
					 if (typeof(pageTracker) != "undefined") {
						   pageTracker._trackPageview("/"+title+"_"+displayType+"_"+tcmPageID+".html");
					  }

				}
			   
			   if (eventName == "onC2CClicked") {
				    clearMultiTrackMeta();
					dcsMultiTrack("DCS.dcsuri", "/"+title+"_"+tcmPageID+".html", "WT.ti", title+"_"+tcmPageID, "WT.cg_n", localContentGroup,"WT.cg_s",localSubContentGroup,"WT.si_cs", scenarioLead, "WT.si_n",scenarioName ,"WT.si_x", scenarioStep,"WT.z_age",localz_age,"WT.z_gnd",localz_gnd,"WT.z_small3",localz_small3,"WT.z_small4",localz_small4,"WT.z_tool",localz_tool,"WT.ad",local_ad,"WT.ac",local_ac,"DCSext.oc_id",local_oc_id,"WT.z_num3",localz_num3,"WT.z_num4",localz_num4 ,"WT.z_inc",localz_inc);
					if (typeof(pageTracker) != "undefined") {
						   pageTracker._trackPageview("/"+title+"_"+tcmPageID+".html");
					  }

				}

			   if(eventName == "onChatLaunched"){
				    clearMultiTrackMeta();
				    dcsMultiTrack("DCS.dcsuri", "/"+title+"_"+chart_type+"_"+tcmPageID+".html", "WT.ti", title+"_"+chart_type+"_"+tcmPageID, "WT.cg_n", localContentGroup,"WT.cg_s",localSubContentGroup,"WT.si_cs", scenarioLead, "WT.si_n",scenarioName ,"WT.si_x", scenarioStep,"WT.z_age",localz_age,"WT.z_gnd",localz_gnd,"WT.z_small3",localz_small3,"WT.z_small4",localz_small4,"WT.z_tool",localz_tool,"WT.ad",local_ad,"WT.ac",local_ac,"DCSext.oc_id",local_oc_id,"WT.z_num3",localz_num3,"WT.z_num4",localz_num4 ,"WT.z_inc",localz_inc);
     			    if (typeof(pageTracker) != "undefined") {
							pageTracker._trackPageview("/"+title+"_"+chart_type+"_"+tcmPageID+".html");
					}
				}

			   if(eventName == "onChatEngagedEvent"){
					clearMultiTrackMeta();
					dcsMultiTrack("DCS.dcsuri", "/"+title+"_"+tcmPageID+".html", "WT.ti", title+"_"+tcmPageID, "WT.cg_n", localContentGroup,"WT.cg_s",localSubContentGroup,"WT.si_cs", scenarioLead, "WT.si_n",scenarioName ,"WT.si_x", scenarioStep,"WT.z_age",localz_age,"WT.z_gnd",localz_gnd,"WT.z_small3",localz_small3,"WT.z_small4",localz_small4,"WT.z_tool",localz_tool,"WT.ad",local_ad,"WT.ac",local_ac,"DCSext.oc_id",local_oc_id,"WT.z_num3",localz_num3,"WT.z_num4",localz_num4 ,"WT.z_inc",localz_inc);
					if (typeof(pageTracker) != "undefined") {
						   pageTracker._trackPageview("/"+title+".html");
						}
				}

			   if(eventName == "onSaleQualifiedEvent"){
					clearMultiTrackMeta();
					dcsMultiTrack("DCS.dcsuri", "/"+title+"_"+tcmPageID+".html", "WT.ti", title+"_"+tcmPageID, "WT.cg_n", localContentGroup,"WT.cg_s",localSubContentGroup,"WT.si_cs", scenarioLead, "WT.si_n",scenarioName ,"WT.si_x", scenarioStep,"WT.z_age",localz_age,"WT.z_gnd",localz_gnd,"WT.z_small3",localz_small3,"WT.z_small4",localz_small4,"WT.z_tool",localz_tool,"WT.ad",local_ad,"WT.ac",local_ac,"DCSext.oc_id",local_oc_id,"WT.z_num3",localz_num3,"WT.z_num4",localz_num4 ,"WT.z_inc",localz_inc);
					if (typeof(pageTracker) != "undefined") {
						   pageTracker._trackPageview("/"+title+"_"+tcmPageID+".html");
						}
				}


	  
        }
}
function trackC2CDART(type,category) {


/* Start of DoubleClick Spotlight Tag: Please do not remove  */
/* Activity Name for this tag is:TLIIQStart  */
/* Web site URL where tag should be placed: https://www.metlife.com/campaign/search/term-life-quote  */
/* This tag must be placed within the opening <body> tag, as close to the beginning of it as possible  */
/* Creation Date:6/19/2009 */

var axel = Math.random()+"";
var a = axel * 10000000000000;

dartIframe = document.createElement("IFRAME");
var _protocol=window.location.protocol.indexOf('https:')==0?'https':'http';
dartIframe.setAttribute("src",_protocol+"://fls.doubleclick.net/activityi;src=1524815;type="+type+";cat="+category+";ord=1;num=" + a + "?");
dartIframe.setAttribute("width","1");
dartIframe.setAttribute("height","1");	
dartIframe.setAttribute("frameborder","0");
document.body.appendChild(dartIframe);

//End of DoubleClick Spotlight Tag: Please do not remove //

}


/* ********************************************************** */
/*             End of C2C EVENT Tracking Code                */
/* ********************************************************** */


function loadFieldMappings()
{

/* Test & Sample Mappings

	 var localMetricsMapping = {
		  "flashevent" : {
			   "webtrends" : {
					"cg"   : "WT.cg_n",
					"scg"  : "WT.cg_s",
					"scenarioName" : "WT.si_n",
					"scenarioStep" : "WT.si_x",
					"scenarioLoad" : "WT.si_cs",
					"segments1"    : "WT.seg_1",
					"segments2"    : "WT.seg_2",
					"segments3"    : "WT.seg_3",
					"segments4"    : "WT.seg_4"
			        },
			   "google" : "disabled"
		  }
	 };

// End Sample Mapping

*/

	 try {
     /* First look for mappings in variable "localMetricsMapping" */
		  if (typeof(localMetricsMapping) != "undefined")
			   return(localMetricsMapping);
	 }  catch (ex) {
		  console.info("metlifeJS.js:localFieldMappings():  Bypassing localMetricsMapping due to exception " + ex);
	 }


	 try {
     /* If not found, look for mappings in variable "globalMetricsMapping" */
		  if (typeof(globalMetricsMapping) != "undefined")
			   return(globalMetricsMapping);
	 }  catch (ex) {
		  console.info("metlifeJS.js:localFieldMappings():  Bypassing localMetricsMapping due to exception " + ex);
	 }

	 /* If not found, look for local json object w/ mappings. */
//	 dojo.xhrGet( {
//		  url: "./metricsMapping.txt",
//		  handleAs: "json",
//		  load: function(responseObject, ioArgs) {
//					/* This should only execute upon successful http load. */
//					console.dir(responseObject);  // Dump it to the console
//					return(responseObject);
//			   
//		  }
//		  error: function(responseObject, ioArts) {
//					/* This should only execute upon http failure code. */
//					console.info ("Cannot load local metricsMapping.txt -- looking globally.");
//		  }
//		  );
	 
	 /* If not found, look for global json object w/ mappings. */
//	 dojo.xhrGet( {
//		  url: "/system/js/metricsMapping.txt",
//		  handleAs: "json",
//		  load: function(responseObject, ioArgs) {
//					/* This should only execute upon successful http load. */
//					console.dir(responseObject);  // Dump it to the console
//					return(responseObject);
			   
//		  }
//		  error: function(responseObject, ioArts) {
//					/* This should only execute upon http failure code. */
//					console.info ("Cannot load local metricsMapping.txt -- looking globally.");
//		  }
//		  );

	 var defaultMetricsMapping = {
		  "flashevent" : {
			   "webtrends" : {
					"cg"   : "WT.cg_n",
					"scg"  : "WT.cg_s",
					"scenarioName" : "WT.si_n",
					"scenarioStep" : "WT.si_x",
					"scenarioLoad" : "WT.si_cs",
					"segments1"    : "WT.seg_1",
					"segments2"    : "WT.seg_2",
					"segments3"    : "WT.seg_3",
					"segments4"    : "WT.seg_4"
			        },
			   "google" : "disabled"
		  }
	 };

	 return (defaultMetricsMapping);
}

/* ********************************************************** */
/* Functions to control popups on timeout or close            */
/* ********************************************************** */

dojo.declare("Monitor", null ,{
	_events : [[window, 'scroll'], [window, 'resize'], [document, 'mousemove'], [document, 'keydown']],
	_timer : null,

	constructor: function(time){
		Monitor.prototype.time=time;
		this.initObservers();
		this.setTimer();
	},
	initObservers:function(){
		dojo.forEach(this._events, function(e){
			dojo.connect(e[0],e[1], function(event){
				Monitor.prototype.onInterrupt();
			});
		})
	},
	onInterrupt:function(){
		this.setTimer();
	},
	setTimer: function(){
		var oj = Monitor.prototype;
		clearTimeout(this._timer);
		this._timer = setTimeout(function(){
			dojo.publish("state:idle", null);
		},oj.time); 
	}
});

function debug(txt){
	 console.info(txt);
}

function RegisterHandler(type,value)
{
	 debug("RegisterHandler: " + type + "  values: " + value);

	 var nameValuePairs = new String(value);

	 var popupType = matchTaggingName("PopupType", nameValuePairs, false);
	 if (popupType == "") {
		  return(0);
	 }

	 var url = matchTaggingName("url",nameValuePairs, false);
	 if (url == "") {
		  return(0);
	 }
	 
	 var usersPercentage = matchTaggingName("UsersPercentage",nameValuePairs, false);
	 var cookieLifetime = matchTaggingName("CookieLifeTime",nameValuePairs, false);
	 var timeoutSeconds = matchTaggingName("timeout",nameValuePairs, false);

	 // Determine popup parameters
	 // This one is special one-time regex w/ [] around popupParams
	 var popupParams = "";
	 var popupParamsRegex=/popupParams:\[([^\]]+)\]/i;
	 var popupParamsMatch=nameValuePairs.match(popupParamsRegex);

	 if (popupParamsMatch != null) {
		  popupParams=popupParamsMatch[1];
	 } else {
		  // assume none if not specified.
	 }

	 /* Check to see if cookie already exists.  If so, then don't show popup. */
	 /* Cookie is lastPS -- last popup shown. */
	 var allcookies = document.cookie;
	 var entryFound = allcookies.indexOf("lastPpSh=");
	 if (entryFound != -1) {
		  debug("Cookie Found -- no registering new Popup.");
		  return;
	 }

	 /* If the arrays don't exist, create them. */
	 if (typeof(mcPopupType) == "undefined") {
		  mcPopupType = [];
		  mcPopupURL = [];
		  mcPopupTimeout = [];
		  mcPopupParams = [];
		  mcPopupCookieLifetime = [];
		  mcPopupUsersPercentage = [];
	 }

	 /* Now go through and assign values. */
	 mcPopupType.push(popupType.toLowerCase());
	 mcPopupURL.push(url);
	 mcPopupTimeout.push(timeoutSeconds);
	 mcPopupParams.push(popupParams);
	 mcPopupCookieLifetime.push(cookieLifetime);
	 mcPopupUsersPercentage.push(usersPercentage);

     if (popupType.toLowerCase() == "windowclose") {
		  debug("Registering a Windowclose.  url: " + url + ", params: " + popupParams);
		  mcCallCloseWindow = true;
     }
     else if (popupType.toLowerCase() == "idletimeout") {
		  debug("Registering an IdleTimeout.  url: " + url + ", params: " + popupParams);
          mcCallTimeout = true;
     }
}


function mcPopupSetCookie(cookieAge) {
	 /* Set a cookie to indicate popup has been shown. */
	 var lifetime_temp;

	 lifetime_temp = cookieAge*24*60*60;

	 debug("Registering a MC Popup cookie of " + lifetime_temp + " seconds");

	 document.cookie = "lastPpSh=true;max-age=" + lifetime_temp;

	 // + ";path=" 
	 //	  + document.URL.substr(document.URL.indexOf(document.domain)+document.domain.length);
}

function mcPopupPickPopup(popupType) 
{
	 /* Assume that total of user percentage for Popups is 100%. */
	 /* Behavior will be undefined if it not. */

	 var randomTest = Math.random() * 100.0;

	 /* After picking random #, iterate through popups in array to determine which one */
	 /*   gets thrown. */
	 var runningTotal = 0;

	 for (var i=0;i<mcPopupType.length;i++) {
		  if (mcPopupType[i].toLowerCase() == popupType.toLowerCase()) {
			   runningTotal = Number(runningTotal) + Number(mcPopupUsersPercentage[i]);
			   debug ("PickPopup: " + runningTotal + ", " + mcPopupUsersPercentage + ", " + randomTest + ", " + i);
			   if (randomTest <= runningTotal) {
					return(i);
			   }
		  }
	 }
	 return(-1);
}

function mcPopupRegisterClick(arguments)
{
	 mcPopupLastClick = new Date();
	 console.info("Register Click");
	 console.info(mcPopupLastClick);
}

function mcPopupCloseWindow()
{
	 /* If the screen is being left because we're going to another within metlife.com via doLink(), then don't do this handler. */
	 if (typeof(mcExitViaDoLink) != "undefined") {
		  return;
	 }

	 /* Some methods of leaving the screen don't go through doLink().  Instead trap on the last mouse click */
	 /*   if this mouseclick occured within 1/10th of a second of leaving, assume we're leaving via a link, so */
	 /*   no on close popup. */
	 if (typeof(mcPopupLastClick) != "undefined") {
		  var currentTime = new Date();
		  var interval = currentTime - mcPopupLastClick;

//		  alert("Times: " + currentTime + ", mcPopupLastClick, " + mcPopupLastClick + ", interval: " + interval);
		  if (interval < 100) {
			   return;
		  }
	 }

	 /* Popup Window on close, if the parameters have been passed. */
	 if ((typeof(mcCallCloseWindow) != "undefined" ) && 
		 (typeof(mcPopupCloseWindowURL) != "undefined") && (typeof(mcPopupCloseWindowParams) != "undefined")) {

		  if (typeof(mcPopupWindow) == "undefined") {
			   mcPopupWindow = window.open(mcPopupCloseWindowURL,"MetlifeComPopup",mcPopupCloseWindowParams);
			   mcPopupSetCookie(mcPopupWindowCloseCookieLifetime);
		  }
	 }
}

dojo.addOnLoad(function()
{
	 /* Determine which popup in array should be chosen. */
	 var popupChosen;

	 /* This variable set to true to indicate that any timeout popups have been chosen. */
	 if (typeof(mcCallTimeout) != "undefined") {
		  popupChosen = mcPopupPickPopup("idleTimeout");

		  if (popupChosen < 0) {
			   return;
		  }
		  
		  console.info ("Going to Register IdleTimeout function");
					
		  var timeoutMonitor = new Monitor(mcPopupTimeout[popupChosen] * 1000);

		  mcTimeoutSubscriber = dojo.subscribe("state:idle", null, onIdle);
		  mcPopupTimeoutURL = mcPopupURL[popupChosen];
		  mcPopupTimeoutWindowParams = mcPopupParams[popupChosen];
		  mcPopupTimeoutCookieLifetime = mcPopupCookieLifetime[popupChosen];
	 }

	 if (typeof(mcCallCloseWindow) != "undefined") {
		  popupChosen = mcPopupPickPopup("WindowClose");

		  if (popupChosen < 0) {
			   return;
		  }

		  /* Set function to register mouseclicks -- if time of close and mouseclick are the same */
		  /*  then, don't trigger show WindowClose popup. */
		  dojo.connect(document, "onclick", "mcPopupRegisterClick");

		  console.info ("Setting up window close Popup");

		  dojo.connect(window, "beforeunload", mcPopupCloseWindow);

		  mcPopupCloseWindowURL = mcPopupURL[popupChosen];
		  mcPopupCloseWindowParams = mcPopupParams[popupChosen];
		  mcPopupWindowCloseCookieLifetime = mcPopupCookieLifetime[popupChosen];
	 }

	 /* Used to trigger popup on timeout. */
	 function onIdle(){
		  debug("Popping Timeout Window");
		  if (typeof(mcPopupWindow) == "undefined") {
			   mcPopupWindow = window.open(mcPopupTimeoutURL,"MetlifeComPopup",mcPopupTimeoutWindowParams);
			   mcPopupSetCookie(mcPopupTimeoutCookieLifetime);
		  }
		  else {
			   if (typeof(mcTimeoutSubscriber) != "undefined") {
					dojo.unsubscribe(mcTimeoutSubscriber);
			   }
			   debug("Not calling Popup subsequent time -- unsubscribed event.");
		  }
	 };
});


/* **************************************************************************/
/* Specific Function added for tracking flash events   On 15th April 2010  */
/* **************************************************************************/

function trackFlashEvent(type,name,flashparams)
{

		type = type.toLowerCase();
		name = name.toLowerCase();

		console.info ("trackEvent called with type: " + type );

		var isTracking = document.getElementById('EnableTracking').value;
		if(isTracking == "off")
		{
					return 1;
		}
		var enabledStr; 
		var events = document.getElementById('trackingMeta').value;
		var webStr;
		var eventsArray = events.split("#");
		for(var i=0;i<eventsArray.length;i++)
		{
				
				var tempArr = eventsArray[i].split("@");
				var enabledArr = tempArr[0].split("$");
					
				/*var evtNameArr = enabledArr[0].split(":");
				

				if(evtNameArr[1] == type)
				{
					webStr = tempArr[1];
					enabledStr = enabledArr[1];
					break;
				}*/

				var tempEventName = matchTaggingName("eventname",enabledArr[0], false);
				var tempEventType = matchTaggingName("eventtype",enabledArr[0], false);
				if(tempEventType.toLowerCase() == type && tempEventName.toLowerCase() == name)
				{
					webStr = tempArr[1];
					enabledStr = enabledArr[1];
					break;
				}
		}

		var nameValuePairs = new String(webStr);


		var webtrendsString = "";


		if (type == "flashevent") {

			/* check event is enabled or not here */
			  if(matchTaggingName("webtrends",enabledStr, false) == "enabled")
			  {
				 
				 var multiTrackValues = [];
					 
					 /*multiTrackValues.push("DCS.dcsqry","");
					 multiTrackValues.push("WT.ad", ((impressionTags == true) ? completeBannerTitle : ""));
					 multiTrackValues.push("WT.ac", ((clickTags == true) ? completeBannerTitle : ""));
					 multiTrackValues.push("DCSext.oc_id", ((clickTags == true) ? completeBannerTitle : ""));

					 /* Adding params sent from flash 
					 
					 multiTrackValues.push("DCS.dcsuri", matchTaggingName("DCS.dcsuri",flashparams, false));	
					 multiTrackValues.push("WT.ti", matchTaggingName("WT.ti",flashparams, false));	
					 multiTrackValues.push("WT.si_cs", matchTaggingName("WT.si_cs",flashparams, false));	
					 multiTrackValues.push("WT.si_n", matchTaggingName("WT.si_n",flashparams, false));	
					 multiTrackValues.push("WT.si_x", matchTaggingName("WT.si_x",flashparams, false));
					 multiTrackValues.push("WT.z_age", matchTaggingName("WT.z_age",flashparams, false));
					 multiTrackValues.push("WT.z_num3", matchTaggingName("WT.z_num3",flashparams, false));
					 multiTrackValues.push("WT.z_num4", matchTaggingName("WT.z_num4",flashparams, false));
					 multiTrackValues.push("WT.z_small3", matchTaggingName("WT.z_small3",flashparams, false));
					 multiTrackValues.push("WT.z_small4", matchTaggingName("WT.z_small4",flashparams, false));
					 multiTrackValues.push("WT.z_gnd", matchTaggingName("WT.z_gnd",flashparams, false));
					 multiTrackValues.push("WT.z_inc", matchTaggingName("WT.z_inc",flashparams, false));
					 multiTrackValues.push("WT.z_tool", matchTaggingName("WT.z_tool",flashparams, false));
					 multiTrackValues.push("WT.z_time", matchTaggingName("WT.z_time",flashparams, false));
					*/

					flashparams = flashparams.replace(/['"]/g,'');
					var flashPairsArr = flashparams.split(","); 

					for (var i=0;i<flashPairsArr.length;i++ )
					{
						multiTrackValues.push(flashPairsArr[i], flashPairsArr[i+1]);
						i++;
					}

				    var pairsArr = nameValuePairs.split(","); 

					for (var i=0;i<pairsArr.length;i++ )
					{
						multiTrackValues.push(pairsArr[i], pairsArr[i+1]);
						i++;
					}
				
				 dcsMultiTrack.apply(null, multiTrackValues);		
			  }
			  else
			  {
					return 1;
			  }
				

		}

		else if (type == "dartevent") {
			/* check enabled or not here */
			 if(matchTaggingName("dart",enabledStr, false) == "enabled")
			  {

				  //fireDART(flashparams);
				   var darttype;
				   var category;
				   var pairsArr = nameValuePairs.split(","); 

					for (var i=0;i<pairsArr.length;i++ )
					{
						if(pairsArr[i] == "type")
						{
							darttype = pairsArr[i+1];
						}
						else if(pairsArr[i] == "category")
						{
							category = pairsArr[i+1];
						}
						i++;
					}
				  trackC2CDART(darttype,category)
			  }
			  else
			  {
					 return 1;
			  }
			
					 
		}

		else if (type == "gaevent") {
			/* check enabled or not here */
			 if(matchTaggingName("google",enabledStr, false) == "enabled")
			 {			 		 
				//var params:String = "url:"+strUrl+";event:"+strEvent+";tool:"+tool;
				var strurl = matchTaggingName("url",flashparams, false);
				var event = matchTaggingName("event",flashparams, false);
				var tool = matchTaggingName("tool",flashparams, false);
				pageTracker._trackPageview(strurl);
				pageTracker._trackEvent("Tool",event,tool);
			}
			else
			{
				 return 1;
			}
					 
		}
			

                 // alert ("trackEvent call finished");

                 return 1;
}
/* **************************************************************************/
/*							END                                             */
/* **************************************************************************/
