// LATEST HISTORY 
// 2007-08-30 WT.ti for form - don't use innerText
// 2008-10-02 reset gDomain before sdcCollector.tagsSent( ) method returns

function dcsCreateImage(dcsSrc)
	{
	//-------------------
	//send the tags first
	//-------------------
	var failure = "";
	try	{
		if (document.images)
			{
			gImages[gIndex]=new Image;
			if ((typeof(gHref)!="undefined")&&(gHref.length>0))
				gImages[gIndex].onload	=
				gImages[gIndex].onerror	= dcsLoadHref;
			gImages[gIndex].src=dcsSrc;
			gIndex++;
			}
		else
			failure = "not attempting ";
		}
	catch (e)
		{
		failure = "couldn't send, got error #" + (e.number & 0xFFFF) + " - " + e.description;
		}

	//--------------------
	//then try the logging
	//--------------------
	if (document.cookie.indexOf("SDClog=1") > -1)	//only log to the cookie's set
	try	{
		var logWin = window.open("",sdcCreateLogWindowName(), sdcCreatLogWindowOptions());
		var curr = (logWin.document.body.innerHTML);	//save the current contents
		logWin.document.body.innerHTML = "";		//clear the slate
		if (curr != "")
			curr = curr.substr(curr.toUpperCase().indexOf("</DIV>")+6);	//remove old heading
		var now = new Date();
		var protocol = document.location.protocol;
		if (protocol.toUpperCase() == "HTTPS:")
			protocol = "<span style='color:red;'>" + protocol + "</span>";
		logWin.document.write("<div style='border:1px solid #ccc;background-color:#eee;padding:5px;font:bold 10pt Arial;margin-bottom:5px;'>SDC tagging log for \"" + protocol + "//" + document.location.hostname + "\"</div>");
		logWin.document.write("<div style='border:1px solid gray;padding:5px;font:8pt Arial;'>");
		logWin.document.write(now + "<br>");
		logWin.document.write(unescape(dcsSrc.replace(/&/g,"<br>")));
		logWin.document.write("</div>");
		logWin.document.write("<div style='font:6pt arial;' class='raw'>\n\n" + dcsSrc + "\n\n</div>");
		if (failure != "")logWin.document.write("<div style='font:bold 6pt arial;color:white;background-color:red;' class='raw'>\n\n" + failure + "\n\n</div>");
		logWin.document.write(curr);
		window.document.close(logWin);
		}
	catch(e){
		alert(unescape(dcsSrc.replace(/&/g,"\n")));
		}
	}
function sdcCreateLogWindowName()
	{
	var fullName = document.location.protocol + document.location.hostname + "sdclog";	//use the server's protocol and name
	fullName = fullName.toUpperCase();
	var windowName = "";
	for(var x = 0; x < fullName.length; x++)	//only preserve alphabetics and numerics
		{
		var oneChar = fullName.substr(x,1);
		if ((oneChar >= "A" && oneChar <= "Z")||(oneChar >= "0" && oneChar <= "9"))
			windowName += oneChar;
		}
	return windowName;
	}
function sdcCreatLogWindowOptions()
	{
	var width = 375;
	var options = "scrollbars=yes, resizable=yes, width=" + width + ", top=0";
	if (typeof(screen)=="object")
		{
		options += ", left=" + (screen.width - width - 25);
		options += ", height=" + (screen.height - 50);
		}
	return options;
	}

function sdcTagHarvester()
	{
	this.useFilterTagsOnly	= false;
	this.activationCode	= "!showtags!";
	this.gDomain		= "";
	this.gDcsId		= "";
	this.gFpc		= "";
	this.gTempWtId		= "";
	this.gConvert		= false;
	this.tags		= null;		//where the tags are stored as they're being collected
	this.pageTags		= null;		//the collection of page tags that were sent
	this.showImmediately	= false;	//display the report as soon as the page is loaded
	this.showAllOpened	= false;	//display the report with all the items already opened
	this.downloadExtensions	= {"csv":"1","doc":"1","exe":"1","jpg":"1","mp3":"1","pdf":"1","pps":"1","ppt":"1","sit":"1","swf":"1","txt":"1","xls":"1","zip":"1"};
	this.timerID		= 0;
	this.domains		= new Array();	//collection of gDomains and gDcsIds to be used for logging

	//define the collection modes
	this.collectionModes	= new Object;
	this.collectionModes.NONE	= 0;
	this.collectionModes.PAGE	= 1;
	this.collectionModes.FAIL	= 2;
	this.collectionModes.LINK	= 3;
	this.collectionModes.FORM	= 4;
	this.collectionModes.FRAME	= 5;

	//set the current collection mode
	this.collectionMode	= this.collectionModes.NONE;

	//=================
	// event processors
	//=================
	this.recordPageTags = function()
		{
		if (this.timerID)
			{
			window.clearTimeout(this.timerID);
			this.timerID = 0;
			}
		this.collectionMode = this.collectionModes.PAGE;
		var tag = document.getElementsByTagName("body")[0];
		if (!tag) return;
		if (this.alreadySent(tag)) return;
		this.extractTags(tag);
		this.augmentTags(tag);
		this.deriveTags(tag);
		this.addUserTags(tag);
		this.extractGlobalTags();
		this.lookforCampaignInfo();
		if (this.tagsToSend())
			{
			this.markAsSent(tag);
			this.sendTags();
			this.pageTags = this.tags;	//save the page tags
			}
		this.collectionMode = this.collectionModes.NONE;
		if (this.showImmediately == true)this.displayAllTags();
		}
	this.pageLoadFailed = function(tag)
		{
		this.collectionMode = this.collectionModes.PAGE;
		//can't seem to get "this" to work on the body tag, so we'll get it ourselves
		//tag is being sent in, but it's pointing to some other object
		tag = document.getElementsByTagName("body")[0];
		if (!tag) return;
		if (tag.sdcTagsSent == true) return;
		this.collectionMode = this.collectionModes.FAIL;
		this.extractTags(tag);
		this.augmentTags(tag);
		this.deriveTags(tag);
		this.addUserTags(tag);
		this.extractGlobalTags();
		this.lookforCampaignInfo();
		if (this.tagsToSend())
			{
			this.addTag("DCSext.abortedLoad","1");
			this.sendTags();
			}
		this.collectionMode = this.collectionModes.NONE;
		}
	this.recordLinkTags = function(evnt)
		{
		var tag = this.locateLinkTag(evnt);	//find the anchor tag parent of the tag that raised the click event
		if(!tag) return;			//if none found
		this.collectionMode = this.collectionModes.LINK;
		this.extractTags(tag);
		this.augmentTags(tag);
		this.deriveTags(tag);
		this.addUserTags(tag);
		this.extractGlobalTags();
		if (this.tagsToSend())
			{
			//2008-07-29 U001500025806
			//The following compensates for a difference with Safari.
			//When dcsSaveHref() was called, it altered Safari's behavior.
			//Links ignored their target attribute, replacing the main page instead.
			var callIt = true;			//make the call if there's no target at all
			if (typeof tag.target == "string")	//if the tag has a target
				switch (tag.target.toLowerCase())
					{
					case "_parent":
					case "_self":
					case "_top":
					case "":	callIt = true;	//this page is being replaced, so call the routine
							break;
					case "_blank":
					default:	callIt = false;	//this page is not being replaced, so skip it
					}
			if (callIt)
				dcsSaveHref(evnt);	//2007-11-27
			this.sendTags();
			}
		this.collectionMode = this.collectionModes.NONE;
		}
	this.recordFormTags = function(tag)
		{
		this.collectionMode = this.collectionModes.FORM;
		this.extractTags(tag);
		this.augmentTags(tag);
		this.deriveTags(tag);
		this.addUserTags(tag);
		this.extractGlobalTags();
		if (this.tagsToSend())
			this.sendTags();
		this.collectionMode = this.collectionModes.NONE;
		}
	this.recordFrameTags = function(tag)
		{
		this.collectionMode = this.collectionModes.FRAME;
		if (this.alreadySent(tag)) return;
		this.extractTags(tag);
		this.augmentTags(tag);
		this.deriveTags(tag);
		this.addUserTags(tag);
		this.extractGlobalTags();
		if (this.tagsToSend())
			{
			this.sendTags();
			this.markAsSent(tag);
			}
		this.collectionMode = this.collectionModes.NONE;
		}
	this.displayAllTags = function()
		{
		var info = "<body style='font:9pt arial;'>";
		info += "<div style='border:1px solid black;background-color:#f8f8f8;padding:10px;'>"
			+ "<button style='float:right;' onclick=\"window.close();\">Close</button>"
			+ "<button style='float:right;' onclick=\"setAll('');\">Show All</button>"
			+ "<button style='float:right;' onclick=\"setAll('none');\">Hide All</button>"
			+ "<b>Title:</b> " + document.title + "<br>"
			+ "<b>Host:</b> " + document.location.hostname + "<br>"
			+ "<b>Path:</b> " + unescape(document.location.pathname) + "<br>"
			+ "<b>URL:</b> " + document.location + "<br>"
			+ "<b>gDomain:</b> " + this.gDomain + "<br>"
			+ "<b>gDcsId:</b> " + this.gDcsId + "<br>"
			+ "<b>Time:</b> " + new Date
			+ "</div>";

		var win = window.open("","");
		win.document.write(info);
		info = "";

		var collectionMode	= this.emptyArray();
		collectionMode["body" ]	= this.collectionModes.PAGE;
		collectionMode["a"    ]	= this.collectionModes.LINK;
		collectionMode["form" ]	= this.collectionModes.FORM;
		collectionMode["frame"]	= this.collectionModes.FRAME;
		var itemCount = 1;
		for (var tagName in collectionMode)
			{
			var tags = document.getElementsByTagName(tagName);
			this.collectionMode = collectionMode[tagName];
			for(var y = 0; y < tags.length; y++)
				{
				tag = tags[y];
				this.extractTags(tag);
				this.augmentTags(tag);
				this.deriveTags(tag);
				this.addUserTags(tag);
				if (this.tagsToSend())
					{
					this.getWebTrendsTags();
					info += "<div style='margin:10px 0px 0px 0px;' onclick=\"return toggle('tagSet"+itemCount+"');\">"
						+ "<a style='text-decoration:none;' href=#>"
						+ itemCount + " ";
					if (tag.tagName == "A")
						info += " <b>" + this.innerText(tag) + "</b> (" + tag.href + ")";
					info +=  " &lt;" + tag.tagName + "&gt;</a></div>";

					//sort them by tag name
					var tagNames =  new Array();
					for (var name in this.tags)		//extract the names
						tagNames.push(name);
					tagNames.sort(function(a1,a2)		//sort the names
						{
						var a1u = a1.toUpperCase();
						var a2u = a2.toUpperCase();
						if(a1u<a2u)return -1;
						if(a1u>a2u)return  1;
						return 0;
						});
					info	+= "<div style='display:"
						+ ((this.showAllOpened == true)?"":"none")
						+ ";margin:0px 0px 5px 10px;' id=tagSet" + itemCount + ">";

if (tag.href) info += tag.href + "<br>";
					for (var t = 0; t < tagNames.length; t++)
						info += tagNames[t] + " = " + this.tags[tagNames[t]] + "<br>";
					info += "</div>";
					itemCount++;	
					}
				}
			}
		info += "</body>";
		info += "<script>";
		info += "function toggle(id)"
			+ "{"
			+ "var tag = document.getElementById(id);"
			+ "tag.style.display = (tag.style.display == 'none')?'':'none';"
			+ "return false;"
			+ "}"
		info += "function setAll(how)"
			+ "{"
			+ "var tag;"
			+ "for (var x = 1; tag = document.getElementById(\"tagSet\" + x); x++)"
			+ 	"tag.style.display = how;"
			+ "}"
		info += "</script>";

		win.document.write(info);
		win.document.close();
		}

	//=================
	// override methods
	//=================
	this.augmentTags = function(tag){}	//this routine is called just after the raw tags have been extracted
	this.addUserTags = function(tag){}	//this routine is called just prior to sending the tags
	this.tagsSent = function(){}		//this function is called immediately after sending the tags

	this.extractGlobalTags = function()
		{
		//-------------------------------------------------------
		//use the noscript image tag values as the default values
		//-------------------------------------------------------
		var tags = document.getElementsByTagName("noscript");		//look for any <noscript> tags
		if (tags.length > 0)						//hopefully there's at least one
			{
			var tag	= tags[0];					//and the 1st one's the one we're looking for
			var info = new sdcMerckParseURL(tag.innerHTML, true);
			if (info.matched)
				{
				this.gDomain	= info.server;			//get the image server's domain
				var loc		= info.uri.indexOf("/");	//there will always be a slash
				this.gDcsId	= info.uri.substr(0, loc);	//and the site's dcs Id
				}
			}
		//----------------------------------------------------
		//but if tags were overtly specified, use them instead
		//----------------------------------------------------
		if (this.tags["gDomain"])
			{
			this.gDomain = this.tags["gDomain"];
			delete this.tags["gDomain"];
			}
		if (this.tags["gDcsId"])
			{
			this.gDcsId = this.tags["gDcsId"];
			delete this.tags["gDcsId"];
			}
		var domainServers = this.gDomain.split(",");
		var appIdentifiers = this.gDcsId.split(",");
		if (domainServers.length == appIdentifiers.length)
			{
			this.domains = new Array();
			for (var x = 0; x < domainServers.length; x++)
				{
				var domain	= new Object();
				domain.server	= domainServers[x];
				domain.appID	= appIdentifiers[x];
				this.domains.push(domain);
				}
			}
		else
			alert("mismatched entries in gDomain and gDcsId");
		if (this.domains.length == 0)
			alert("no entries found for gDomain and gDcsId");
		}
	this.extractTags = function(tag)
		{
		//---------------------------------------------
		//get the tags stored in the "sdcTags" property
		//---------------------------------------------
		this.tags = this.emptyArray();	//remove any old tags
		this.elevateAttribute(tag, "sdcTags");
		if (tag.sdcTags != null)
			{
			try	{
				var theseTags = eval("({" + tag.sdcTags + "})");
				this.addTags(theseTags);
				}
			catch(e){}
			}
		}
	this.deriveTags = function(tag)
		{
		//----------------------------
		//if there weren't any - leave
		//----------------------------
		if (this.useFilterTagsOnly == true) return;

		var taggedByFilter	= this.tagsToSend();
		var offsite		= false;
		var download		= false;

		var url;
		switch (tag.tagName)
			{
			case "A"     :url = tag.href   ;break;
			case "FRAME" :url = tag.src    ;break;
			case "FORM"  :url = tag.action ;break;
			}
		if (url && typeof(url) == "string")
			{
			this.addTag("DCS.dcsref", window.location.pathname);	//2007-11-27
			var info = new sdcMerckParseURL(url);
			if (!info.matched && tag.tagName == "FORM" && document.all)	//if an unmatched FORM action in IE (2007-11-14)
				{
				url = document.location.protocol + "//" + document.location.host + url;	//try it again with more info
				info = new sdcMerckParseURL(url);
				}
			if (info.matched)
				{
				//------------------------------
				//create tags for url components
				//------------------------------
				this.addUndefinedTag("DCS.dcssip", info.server);		//dcssip is required (2007-11-16)
				this.addUndefinedTag("DCS.dcsuri", (info.uri)?info.uri:"/");	//dscuri is required (2007-11-16)
				if (info.query ) this.addUndefinedTag("DCS.dcsqry", info.query );
				//-------------------
				//look for an SVL tag
				//-------------------
				if (info.queryParms["WT.svl"])
					this.addUndefinedTag("WT.svl", info.queryParms["WT.svl"]);
				//------------------------
				//look for an offsite link
				//------------------------
				if (document.location.hostname.toUpperCase() != info.server.toUpperCase())
					{
					this.addUndefinedTag("WT.os", "1");
					offsite	= true;
					}
				//-------------------
				//look for a download
				//-------------------
				var extensionLoc = info.uri.lastIndexOf(".") + 1;
				if (extensionLoc > 0)
					{
					var extension = info.uri.substring(extensionLoc,info.uri.length);
					if (this.downloadExtensions[extension])
						{
						this.addUndefinedTag("WT.dl", "1");
						download = true;
						}
					}
				}
			else				//if we can't parse the url, just report it as is (2007-11-16)
				{
				this.addUndefinedTag("DCS.dcssip", document.location.hostname);
				this.addUndefinedTag("DCS.dcsuri", url);
				}
			//---------------------------------
			//use the url for the title (WT.ti)
			//---------------------------------
			var titleTagValue = url;

			//--------------------------------------
			//for links, try to use the clicked text
			//--------------------------------------
			if (tag.tagName == "A")
				{
				var title = this.innerText(tag).trim();
				if (title) titleTagValue = title;
				}

			//------------------------------
			// add any prefixes to the title
			//------------------------------
			//test if we set it, or if it was already set (written this way for efficiency)
			if (offsite  || this.tags["WT.os"] == "1") titleTagValue = "Offsite:"  + titleTagValue;
			if (download || this.tags["WT.dl"] == "1") titleTagValue = "Download:" + titleTagValue;

			this.addUndefinedTag("WT.ti",titleTagValue);
			}

		//----------------------------------------------------
		// check to see if there are tags that need to be sent
		//----------------------------------------------------
		if (taggedByFilter == false && offsite == false && download == false)
			{
			this.tags = this.emptyArray();	//if we shouldn't be sending tags, make sure we don't
			return;
			}

		//---------------------------------------
		//look for "special directive" tag values
		//---------------------------------------
		for(var tagname in this.tags)
			{
			var directive = this.tags[tagname];
			if (tag.tagName == "A" && tag.href)
				{
				if (directive == "$innerText$")
					this.tags[tagname] = this.innerText(tag);
				else if (directive.indexOf("$query$") == 0)
					this.tags[tagname] = this.extractQueryParameter(tag.href, directive.substr(7));
				else if (directive.indexOf("$bookmark$") > -1)
					this.tags[tagname] = this.substituteBookMark(directive, tag.href);
				}
			if (directive.indexOf("$id$") == 0)
				{
				var element = document.getElementById(directive.substr(4));
				if (element && element.value)
					this.tags[tagname] = element.value;
				}
			}

		}
	this.lookforCampaignInfo = function()
		{

		//==========================================================
		// This routine uses the function addUndefinedTag()
		// so that it will not overright any tags set by the Filter.
		// This was done so that this code could also be used by
		// sites like Speaker Services that don't use the Filter.
		//==========================================================

		var pageInfo = new sdcMerckParseURL(document.location.href);
		if (pageInfo.matched == false) return;
		var mcValue1 = pageInfo.queryParmsLower["tcode"];
		var mcValue2 = pageInfo.queryParmsLower["cmpgn_id"];
		var mcValue3 = pageInfo.queryParmsLower["offer_id"];
		if (!mcValue1) mcValue1 = pageInfo.queryParmsLower["wt.mc_id"];
		if (!mcValue1) mcValue1 = "";
		if (!mcValue2) mcValue2 = "";
		if (!mcValue3) mcValue3 = "";
		var mcTagValue = mcValue1 + "_" + mcValue2 + "_" + mcValue3;
		if (mcTagValue != "__")		this.addUndefinedTag("WT.mc_id", mcTagValue);
		if (this.tags["WT.mc_id"])	this.addUndefinedTag("WT.mc_ev", "click");	//add this no matter who set it

		//add page's svl code
		if (pageInfo.queryParmsLower["wt.svl"])
			this.addUndefinedTag("WT.svl", pageInfo.queryParmsLower["wt.svl"]);
		}
	this.locateLinkTag = function(event)
		{
		//-----------------------------------------------------
		//we got a click event ... but did it come from a link?
		//walk the tree backwards looking for an <a> tag
		//-----------------------------------------------------
		for	(
			var tag = (event.srcElement)?event.srcElement:event.target;
			tag && tag.tagName != "A";
			tag = tag.parentNode
			);
		return tag; //will return an <a> tag or null
		}
	this.sendTags = function()
		{
		this.getWebTrendsTags();
		this.addUndefinedTag("WT.ti",document.location);	//use url if no page title
		this.exportTags();	//send out our tags
		for (var x = 0; x < this.domains.length; x++)
			{
			var domain = this.domains[x];
			gDomain	= domain.server;
			gDcsId	= domain.appID;
			dcsTag();
			this.tagsSent();
			}
		}
	this.getWebTrendsTags = function()
		{
		this.clearWT();		//clear the WT arrays
		//---------------------
		//set up the WT globals
		//---------------------
		gFpc		= this.gFpc;
		gTempWtId	= this.gTempWtId;

		if (this.useFilterTagsOnly == true) return;

		//--------------------
		//call the WT routines
		//--------------------
		dcsVar();
		if (this.collectionMode != this.collectionModes.PAGE)	//removed unwanted page values
			DCS.dcssip	=
			DCS.dcsuri	=
			DCS.dcsqry	=
			DCS.dcsref	=
			WT.ti		=
			WT.svl		=
			WT.os		= "";
		//------------------
		//import the WT tags
		//------------------
		this.importWTArray(WT    , "WT."    );
		this.importWTArray(DCS   , "DCS."   );
		this.importWTArray(DCSext, "DCSext.");
		}
	this.clearWT = function()
		{
		//-----------------------
		//clear all the WT arrays
		//-----------------------
		WT		= this.emptyArray();
		DCS		= this.emptyArray();
		DCSext		= this.emptyArray();
		}
	this.importWTArray = function(array, tagPrefix)
		{
		for (var tagSuffix in array)
			{
			var incomingValue = array[tagSuffix];
			if(incomingValue)
				{
				var tagName = tagPrefix + tagSuffix;
				if(!this.tags[tagName])	//only take the WT tag if we don't already have it
					this.tags[tagName] = incomingValue;
				}
			}
		}
	this.exportTags = function()
		{
		this.clearWT();	//get rid of theirs
		for(var name in this.tags)		//give them ours
			{
			if (name.indexOf('WT.'    )==0)	    WT[name.substring(3)]=this.tags[name];
			if (name.indexOf('DCS.'   )==0)	   DCS[name.substring(4)]=this.tags[name];
			if (name.indexOf('DCSext.')==0)	DCSext[name.substring(7)]=this.tags[name];
			}
		}
	this.markAsSent = function(tag)
		{
		tag.sdcTagsSent = true;
		}
	this.alreadySent = function(tag)
		{
		return (tag.sdcTagsSent == true);
		}
	this.tagsToSend = function()
		{
		for(var v in this.tags) return true;
		return false;
		}
	//==========
	// utilities
	//==========
	this.addTags = function(tags)
		{
		for(var v in tags)
			this.addTag(v, tags[v]);
		}
	this.addTag = function(tagName, tagValue)
		{
		this.tags[tagName] = unescape(tagValue);
		}
	this.addUndefinedTags = function(tags)
		{
		for(var v in tags)
			this.addUndefinedTag(v, tags[v]);
		}
	this.addUndefinedTag = function(tagName, tagValue)
		{
		if (!this.tags[tagName])
			this.tags[tagName] = unescape(tagValue);
		}
	this.elevateAttribute = function(tag, attrName)
		{
		if (tag[attrName] || document.all) return;
		//extra code for FireFox
		var attr = tag.attributes.getNamedItem(attrName);
		if (attr) tag[attrName] = attr.nodeValue;
		}
	this.innerText = function(tag)
		{
		return (tag.innerText || tag.textContent || "");
		}
	this.extractQueryParameter = function (href, name)
		{
		var info = new sdcMerckParseURL(href);
		if (info)
			{
			var value = info.queryParms[name];
			if (value) return value;
			}
		return "";
		}
	this.emptyArray = function()
		{
		var array = {};			//changed from "= new Array()" to "{}" (2007-11-19)
		for (var item in array)		//in case the Array class has been "extended"
			delete array[item];
		return array;
		}
	this.substituteBookMark = function(directive, href)
		{
		var returnValue = directive;
		var info = new sdcMerckParseURL(href);
		if (info.matched)
			returnValue = returnValue.replace("$bookmark$",info.bookmark);
		return returnValue;
		}
	this.showAllAttributes = function(item)
		{
		var info = "";
		for (var attr in item)
			info += attr + " = " + item[attr] + "<br>";
		var win = window.open("","");
		win.document.write(info);
		win.document.close();
		}

	//===================================
	// stuff to process keyboard activity
	// to produce that tagging report
	//===================================

	this.ASCII		= " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'abcdefghijklmnopqrstuvwxyz{|}~";
	this.savedStrokes	= "";

	//------------------------------
	//the keyboard listener function
	//------------------------------
	this.keyboardMonitor = function(evnt)
		{
		var index = (evnt.charCode == null)?evnt.keyCode:evnt.charCode;
		if (index <  32) return;
		if (index > 128) return;
		index -= 32;
		var keyChar = this.ASCII.substring(index,index + 1);

		this.savedStrokes += keyChar;
		if (this.savedStrokes.length > this.activationCode.length)
			this.savedStrokes = this.savedStrokes.substring(1);
//window.status = this.savedStrokes;
		if (this.savedStrokes == this.activationCode)
			this.displayAllTags();
		}

	//-----------------------------
	//install the keyboard listener
	//-----------------------------
	this.connectKeyboardListener = function(tag)
		{
		}
		var me = this;
tag = document;
		if (tag.attachEvent)
			tag.attachEvent
				(
				"onkeypress",
				function(){me.keyboardMonitor.call(me, event);}
				);
		if (tag.addEventListener)
			{
			tag.addEventListener
				(
				"keypress",
				function(event){me.keyboardMonitor.call(me, event);},
				true
				);
			}
	}

//======================================
function sdcMerckParseURL(url, floating)
	{
	this.url	= url;
	this.matched	= false;
	this.protocol	= "";
	this.server	= "";
	this.uri	= "";
	this.query	= "";
	this.queryParms	= new Array();
	this.queryParmsLower	= new Array();
	this.bookmark	= "";

	if (typeof(floating)!="undefined" && floating == true)
		var re = /(https?):\/\/([^\/:]+)(:\d+)?(\/([^\?#]+)(\?[^#]+)?(#.+)?)?/gi;
	else
		var re = /^(https?):\/\/([^\/:]+)(:\d+)?(\/([^\?#]+)(\?[^#]+)?(#.+)?)?/gi;
	if (url.match(re))
		{
		this.matched = true;
		if (RegExp.$1) this.protocol	= RegExp.$1;
		if (RegExp.$2) this.server	= RegExp.$2;
		if (RegExp.$5) this.uri		= RegExp.$5;
		if (RegExp.$6) this.query	= RegExp.$6;
		if (RegExp.$7) this.bookmark	= RegExp.$7;
		if (this.query)
			{
			this.query = this.query.substr(1);
			parms = this.query.split("&");
			for (var x = 0; x < parms.length; x++)
				{
				var parm = parms[x].split("=");
				if (parm.length == 2)
					{
					this.queryParms[parm[0]] = parm[1];
					this.queryParmsLower[parm[0].toLowerCase()] = parm[1];
					}
				}
			}
		if (this.bookmark)
			this.bookmark = this.bookmark.substr(1);
		}
	}



//-----------------------
//extend the String class
//-----------------------
String.prototype.trimL = function() {return this.replace( /^\s+/g, ""  );}
String.prototype.trimR = function() {return this.replace( /\s+$/g, ""  );}
String.prototype.trim  = function() {tmp=this.trimR();return tmp.trimL();}

//------------------------------------
// Create in instance of the collector
// and set some default values
//------------------------------------
var sdcCollector	= new sdcTagHarvester();		//make an instance of the collector
sdcCollector.gDomain	= "sdc.merck.com";			//establish some defaults
sdcCollector.gDcsId	= "unknown";
sdcCollector.gFpc	= "WT_FPC";
sdcCollector.gConvert	= true;

//---------------------------------------------------------
// some post-load logic to make sure the page tags get sent
//---------------------------------------------------------
// some other JavaScript on the page may have interrupted
// the "normal" flow by overwriting the onload event for
// the window, document or body, thus preventing our tags
// from being sent.  The following will send the tags even
// if this occurs.
//---------------------------------------------------------
sdcCollector.checkForOnloadCount	= 0;		//number of times the timer has been executed
sdcCollector.checkForOnloadLimit	= 100;		//maximum number of timer runs
sdcCollector.timerInitiated		= false;	//flag to indicate that this run was initiated by the timer
sdcCollector.lastTimerRun		= false;	//flag to indicate that this is the last timer run
sdcCollector.timerID			= window.setTimeout("sdcCheckForOnload()", 1000);
function sdcCheckForOnload()
	{
	sdcCollector.timerID = 0;
	var tag = document.getElementsByTagName("body")[0];	//locate the <body> tag
	var runAgain = true;
	if (tag)						//if body found
		{
		runAgain = false;				//we probably won't need this any more
		if (sdcCollector.alreadySent(tag) == false)	//if the tags haven't been sent yet
			{
			sdcCollector.timerInitiated	= true;
			sdcCollector.lastTimerRun	= (sdcCollector.checkForOnloadCount == sdcCollector.checkForOnloadLimit);
			sdcCollector.recordPageTags();		//send them now
			sdcCollector.timerInitiated	= false;
			sdcCollector.lastTimerRun	= false;
			if (sdcCollector.alreadySent(tag) == false)	//if they still aren't sent (.addUserTags() may have stopped it)
				runAgain = true;			//try it again
			}
		}
	if (runAgain == true)						//try again later
		{
		if (sdcCollector.checkForOnloadCount++ < sdcCollector.checkForOnloadLimit)	//but only try a limited number of times
			sdcCollector.timerID = window.setTimeout("sdcCheckForOnload()", 100);
		}
	}


//=====================================
// extra code to impliment dual-logging
//=====================================
sdcCollector.tagsSent = function()
	{
	if (this.domains.length == 1)	//only if server only sent a single domain - 2008-08-01 (U001500026143)
		{
		var server = document.location.hostname;
		var re = /^(www\.)?[^.]+\.com$/gi;	// BoS, 1 optional "www.", 1-n chars (other than dot), ".com", EoS - 2008-08-01 (U001500026143)
		if (server.match(re))
			gDomain = "www.mercksdc.com";	//production
		else
			gDomain = "sdc-test.merck.com";	//test
		var temp = gDcsId;
		gDcsId = "dcspy7cf6wfd34f191mj9x44u_2g9y";
		dcsTag();
		gDcsId = temp;
		}
	}
