
/*
#####
#	module: WT8_dcs.js
#
#	portions copyright ©2007 Verizon
#
#	purpose:  WebTrends DCS TAG script 
#		customized by Verizon
#
#	created: 16-jan-2007
#
#	version 1.54
#
#	usage:
#
#	update: 02-feb-2007 - Steve Novakovich
#		-updated from WT 7.5 to WT 8.0
#
#	update: 19-feb-2007 - Ian Dacek
#		-added pass-through of SmartView WT.svl to dcsExit function
#
#	update: 14-mar-2007 - Ian Dacek
#		-added dcsHit function as a helper for virtual pages
#		-this includes AJAX and FLASH pages
#
#	update: 16-mar-2007 - Ian Dacek
#		-added optional Window name and features args to dcsExit.
#			this allows dcsExit to direct into a new window.
#		
#	update: 30-mar-2007 - Ian Dacek
#		-modified scrpt to merge URL parameters into the global WebTrends parameters
#
#	update: 13-apr-2007 - Ian Dacek
#		-consolidated smartview exiting
#		-added dcsClick
#
#	update 30-apr-2007 - Ian Dacek
#		-changed the WebTrends dcsTag function to use the dcsID value if its been set
#		-modified dcsuri handling	
#####

*/



//<!-- START OF SDC Advanced Tracking Code -->
//<!-- Copyright (c) 1996-2005 WebTrends Inc.  All rights reserved. -->
//<!-- V8.0 -->
//<!-- $DateTime: 2006/04/07 16:45:14 $ -->

var gService = true;
var gTimeZone = -8;
// Code section for Enable First-Party Cookie Tracking
function dcsCookie(){
	if (typeof(dcsOther)=="function"){
		dcsOther();
	}
	else if (typeof(dcsPlugin)=="function"){
		dcsPlugin();
	}
	else if (typeof(dcsFPC)=="function"){
		dcsFPC(gTimeZone);
	}
}
function dcsGetCookie(name){
	var pos=document.cookie.indexOf(name+"=");
	if (pos!=-1){
		var start=pos+name.length+1;
		var end=document.cookie.indexOf(";",start);
		if (end==-1){
			end=document.cookie.length;
		}
		return unescape(document.cookie.substring(start,end));
	}
	return null;
}
function dcsGetCrumb(name,crumb){
	var aCookie=dcsGetCookie(name).split(":");
	for (var i=0;i<aCookie.length;i++){
		var aCrumb=aCookie[i].split("=");
		if (crumb==aCrumb[0]){
			return aCrumb[1];
		}
	}
	return null;
}
function dcsGetIdCrumb(name,crumb){
	var cookie=dcsGetCookie(name);
	var id=cookie.substring(0,cookie.indexOf(":lv="));
	var aCrumb=id.split("=");
	for (var i=0;i<aCrumb.length;i++){
		if (crumb==aCrumb[0]){
			return aCrumb[1];
		}
	}
	return null;
}
function dcsFPC(offset){
	if (typeof(offset)=="undefined"){
		return;
	}
	if (document.cookie.indexOf("WTLOPTOUT=")!=-1){
		return;
	}
	var name=gFpc;
	var dCur=new Date();
	var adj=(dCur.getTimezoneOffset()*60000)+(offset*3600000);
	dCur.setTime(dCur.getTime()+adj);
	var dExp=new Date(dCur.getTime()+315360000000);
	var dSes=new Date(dCur.getTime());
	WT.co_f=WT.vt_sid=WT.vt_f=WT.vt_f_a=WT.vt_f_s=WT.vt_f_d=WT.vt_f_tlh=WT.vt_f_tlv="";
	if (document.cookie.indexOf(name+"=")==-1){
		if ((typeof(gWtId)!="undefined")&&(gWtId!="")){
			WT.co_f=gWtId;
		}
		else if ((typeof(gTempWtId)!="undefined")&&(gTempWtId!="")){
			WT.co_f=gTempWtId;
			WT.vt_f="1";
		}
		else{
			WT.co_f="2";
			var cur=dCur.getTime().toString();
			for (var i=2;i<=(32-cur.length);i++){
				WT.co_f+=Math.floor(Math.random()*16.0).toString(16);
			}
			WT.co_f+=cur;
			WT.vt_f="1";
		}
		if (typeof(gWtAccountRollup)=="undefined"){
			WT.vt_f_a="1";
		}
		WT.vt_f_s=WT.vt_f_d="1";
		WT.vt_f_tlh=WT.vt_f_tlv="0";
	}
	else{
		var id=dcsGetIdCrumb(name,"id");
		var lv=parseInt(dcsGetCrumb(name,"lv"));
		var ss=parseInt(dcsGetCrumb(name,"ss"));
		if ((id==null)||(id=="null")||isNaN(lv)||isNaN(ss)){
			return;
		}
		WT.co_f=id;
		var dLst=new Date(lv);
		WT.vt_f_tlh=Math.floor((dLst.getTime()-adj)/1000);
		dSes.setTime(ss);
		if ((dCur.getTime()>(dLst.getTime()+1800000))||(dCur.getTime()>(dSes.getTime()+28800000))){
			WT.vt_f_tlv=Math.floor((dSes.getTime()-adj)/1000);
			dSes.setTime(dCur.getTime());
			WT.vt_f_s="1";
		}
		if ((dCur.getDay()!=dLst.getDay())||(dCur.getMonth()!=dLst.getMonth())||(dCur.getYear()!=dLst.getYear())){
			WT.vt_f_d="1";
		}
	}
	WT.co_f=escape(WT.co_f);
	WT.vt_sid=WT.co_f+"."+(dSes.getTime()-adj);
	var expiry="; expires="+dExp.toGMTString();
	document.cookie=name+"="+"id="+WT.co_f+":lv="+dCur.getTime().toString()+":ss="+dSes.getTime().toString()+expiry+"; path=/"+(((typeof(gFpcDom)!="undefined")&&(gFpcDom!=""))?("; domain="+gFpcDom):(""));
	if (document.cookie.indexOf(name+"=")==-1){
		WT.co_f=WT.vt_sid=WT.vt_f_s=WT.vt_f_d=WT.vt_f_tlh=WT.vt_f_tlv="";
		WT.vt_f=WT.vt_f_a="2";
	}
}

// Code section for Use the new first-party cookie generated with this tag.
var gFpc="WT_FPC";
var gConvert=true;

function dcsAdv(){
	dcsFunc("dcsET");
	dcsFunc("dcsCookie");
	dcsFunc("dcsAdSearch");
	dcsFunc("dcsTP");
}

//-->

//********
//ian-

var gDomain = dcsMetaValue('wtdomain',"dcshm.verizon.net");

/*SET A DEFAULT DCSID IF NONE WAS PROVIDED!*/
var gDcsId = dcsMetaValue('dcsid','dcsjcxdpzghjg5e6ym5wj21gv_1r5z');

/*SET A DEFAULT 'EXITS' DCSID IF NONE WAS PROVIDED*/
var gExitsDcsId = dcsMetaValue('exits_dcsid', gDcsId );

/* DETERMINE IF THIS IS A SMARTVIEW PAGE*/
var gIsSmartView =  dcsMetaValue('SmartView_Page',null);

//-ian
//********

if ((typeof(gConvert)!="undefined")&&gConvert&&(document.cookie.indexOf(gFpc+"=")==-1)&&(document.cookie.indexOf("WTLOPTOUT=")==-1)){
	document.write("<SCR"+"IPT TYPE='text/javascript' SRC='"+"http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+gDomain+"/"+gDcsId+"/wtid.js"+"'><\/SCR"+"IPT>");
}

var gImages=new Array;
var gIndex=0;
var DCS=new Object();
var WT=new Object();
var DCSext=new Object();
var gQP=new Array();
var gI18n=false;
if (window.RegExp){
	var RE={"%09":/\t/g,"%20":/ /g,"%23":/\#/g,"%26":/\&/g,"%2B":/\+/g,"%3F":/\?/g,"%5C":/\\/g,"%22":/\"/g,"%7F":/\x7F/g,"%A0":/\xA0/g};
	var I18NRE={"%25":/\%/g};
}

// Add customizations here

function dcsVar(){
	var dCurrent=new Date();
	WT.tz=dCurrent.getTimezoneOffset()/60*-1;
	if (WT.tz==0){
		WT.tz="0";
	}
	WT.bh=dCurrent.getHours();
	WT.ul=navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
	if (typeof(screen)=="object"){
		WT.cd=navigator.appName=="Netscape"?screen.pixelDepth:screen.colorDepth;
		WT.sr=screen.width+"x"+screen.height;
	}
	if (typeof(navigator.javaEnabled())=="boolean"){
		WT.jo=navigator.javaEnabled()?"Yes":"No";
	}
	
	if (document.title){
		if(!WT.ti){
			WT.ti=gI18n?dcsEscape(dcsEncode(document.title),I18NRE):document.title;
		}
	}
	
	WT.js="Yes";
	WT.jv=dcsJV();
	if (document.body&&document.body.addBehavior){
		document.body.addBehavior("#default#clientCaps");
		if (document.body.connectionType){
			WT.ct=document.body.connectionType;
		}
		document.body.addBehavior("#default#homePage");
		WT.hp=document.body.isHomePage(location.href)?"1":"0";
	}
	if (parseInt(navigator.appVersion)>3){
		if ((navigator.appName=="Microsoft Internet Explorer")&&document.body){
			WT.bs=document.body.offsetWidth+"x"+document.body.offsetHeight;
		}
		else if (navigator.appName=="Netscape"){
			WT.bs=window.innerWidth+"x"+window.innerHeight;
		}
	}
	WT.fi="No";
	if (window.ActiveXObject){
		for(var i=10;i>0;i--){
			try{
				var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
				WT.fi="Yes";
				WT.fv=i+".0";
				break;
			}
			catch(e){
			}
		}
	}
	else if (navigator.plugins&&navigator.plugins.length){
		for (var i=0;i<navigator.plugins.length;i++){
			if (navigator.plugins[i].name.indexOf('Shockwave Flash')!=-1){
				WT.fi="Yes";
				WT.fv=navigator.plugins[i].description.split(" ")[2];
				break;
			}
		}
	}
	if (gI18n){
		WT.em=(typeof(encodeURIComponent)=="function")?"uri":"esc";
		if (typeof(document.defaultCharset)=="string"){
			WT.le=document.defaultCharset;
		} 
		else if (typeof(document.characterSet)=="string"){
			WT.le=document.characterSet;
		}
	}
	WT.tv="8.0.0";
	DCS.dcsdat=dCurrent.getTime();

//********
//ian-

	DCS.dcssip = dcsMetaValue('dcssip',window.location.hostname);
		 
	DCS.dcsuri =  dcsMetaValue('dcsuri', window.location.pathname);
	
//-ian
//********

	if (window.location.search){
		DCS.dcsqry=window.location.search;
		if (gQP.length>0){
			for (var i=0;i<gQP.length;i++){
				var pos=DCS.dcsqry.indexOf(gQP[i]);
				if (pos!=-1){
					var front=DCS.dcsqry.substring(0,pos);
					var end=DCS.dcsqry.substring(pos+gQP[i].length,DCS.dcsqry.length);
					DCS.dcsqry=front+end;
				}
			}
		}
	}
	if ((window.document.referrer!="")&&(window.document.referrer!="-")){
		if (!(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)<4)){
			DCS.dcsref=gI18n?dcsEscape(window.document.referrer, I18NRE):window.document.referrer;
		}
	}
}

function dcsA(N,V){
	return "&"+N+"="+dcsEscape(V, RE);
}

function dcsEscape(S, REL){
	if (typeof(REL)!="undefined"){
		var retStr = new String(S);
		for (R in REL){
			retStr = retStr.replace(REL[R],R);
		}
		return retStr;
	}
	else{
		return escape(S);
	}
}

function dcsEncode(S){
	return (typeof(encodeURIComponent)=="function")?encodeURIComponent(S):escape(S);
}

var gRequestReps = 0;

function dcsCreateImage(dcsSrc){
	
	
	gRequestReps += 1;
	
	lURL = dcsSrc + "&xyzzy=" + gRequestReps;
	
	if (document.images){
		gImages[gIndex]=new Image;
		if ((typeof(gHref)!="undefined")&&(gHref.length>0)){
			gImages[gIndex].onload=gImages[gIndex].onerror=dcsLoadHref;
		}
		gImages[gIndex].src=lURL;
		gIndex++;
	}
	else{
		document.write('<IMG ALT="" BORDER="0" NAME="DCSIMG" WIDTH="1" HEIGHT="1" SRC="'+lURL+'">');
	}
}

function dcsMeta(){
	var elems;
	if (document.all){
		elems=document.all.tags("meta");
	}
	else if (document.documentElement){
		elems=document.getElementsByTagName("meta");
	}
	if (typeof(elems)!="undefined"){
		for (var i=1;i<=elems.length;i++){
			var meta=elems.item(i-1);
			if (meta.name){
				if (meta.name.indexOf('WT.')==0){
					WT[meta.name.substring(3)]=dcsEscape(dcsEncode(meta.content),I18NRE);
				}
				else if (meta.name.indexOf('DCSext.')==0){
					DCSext[meta.name.substring(7)]=meta.content;
				}
				else if (meta.name.indexOf('DCS.')==0){
					DCS[meta.name.substring(4)]=(gI18n&&(meta.name.indexOf('DCS.dcsref')==0))?dcsEscape(meta.content,I18NRE):meta.content;
				}
			}
		}
	}
}

//********
//ian-

//search the META values for a named value (parameter).
//if not found, the function will also search the WebTrends namespaces.

function dcsMetaValue(aname,adefault){
	
	var elems;
	
	if (document.all){
		elems=document.all.tags("meta");
	}
	else if (document.documentElement){
		elems=document.getElementsByTagName("meta");
	}
	
	if (typeof(elems) != "undefined") {
		
		
		if ( typeof(elems[aname]) != "undefined" &&  typeof(elems[aname].content) != "undefined" && elems[aname] != ''){
			
			return escape(elems[aname].content);
		}
		
		//try searching the WebTrends namespaces, so long as the name is not already explicitly a member of one.
		if (-1 == (aname.indexOf('.'))){
		
			var lname = 'DCS.'+aname;
		
			if ( typeof(elems[lname]) != "undefined" &&  typeof(elems[lname].content) != "undefined" && elems[lname] != ''){
				return escape(elems[lname].content);
			}
		
			lname = 'WT.'+aname;
		
			if ( typeof(elems[lname]) != "undefined" &&  typeof(elems[lname].content) != "undefined" && elems[lname] != ''){
				return escape(elems[lname].content);
			}
		
			lname = 'DCSext.'+aname;
		
			if ( typeof(elems[lname]) != "undefined" &&  typeof(elems[lname].content) != "undefined" && elems[lname] != ''){
				return escape(elems[lname].content);
			}
		}
		
		
	}
	
	return escape(adefault);
	
}



/* 
	
	dcsHit registers activity from any page.
	
	Its most useful for dynamic/virtual pages such as flash, ajax, etc.
	
	call dcsHit with an optional 'virtual' URL and optional Title to the 'virtual' page to be tracked.
	
*/
function dcsHit(aURL, aTitle ){
	
	clearEventData();
	
	dcsMergeURLQuery(aURL);
	
	if (typeof aTitle != 'undefined' ){ 
		WT['ti'] = dcsEscape(dcsEncode(aTitle));
	}
	
	//DCSext['tval'] = new Date().getTime();
	
	dcsTag();
	
	return false;
	
}


function clearEventData(){

	delete DCSext['click_item'];
	delete DCSext['click_data'];
	
}


/* 
	
	dcsClick records interaction activity from the CURRENT page.
	
	Its most useful for dynamic/virtual pages such as flash, ajax, etc.
	
	call dcsClick with the name or id of the item clicked, 
	the data (if any) for the Click,
	and the 'event'... which defaults to 'click'
		
*/

function dcsClick(aItem, aData){
	
	if (typeof aItem != 'undefined' ){ 
		DCSext['click_item'] = aItem;
	}
	else{
		DCSext['click_item'] = '-';
	}
	
	if (typeof aData != 'undefined' ){ 
		DCSext['click_data'] = dcsEscape(dcsEncode(aData));
	}
	else{
		DCSext['click_data'] = '-';
	}
	
	dcsTag();
	
}




//-ian
//********

function dcsTag(){

	if (document.cookie.indexOf("WTLOPTOUT=")!=-1){
		return;
	}
	
	var lDCSID = DCS['dcsid'];
	lDCSID = (typeof(lDCSID) == "undefined" || lDCSID == '' ) ? gDcsId : lDCSID;
	
	var P="http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+gDomain+(lDCSID==""?'':'/'+lDCSID)+"/dcs.gif?";
	for (N in DCS){
		if (DCS[N]) {
		
			if(N != 'dcsid'){
				P+=dcsA(N,DCS[N]);
			}

		}
	}
	for (N in WT){
		if (WT[N]) {
			P+=dcsA("WT."+N,WT[N]);
		}
	}
	for (N in DCSext){
		if (DCSext[N]) {
			P+=dcsA(N,DCSext[N]);
		}
	}
	if (P.length>2048&&navigator.userAgent.indexOf('MSIE')>=0){
		P=P.substring(0,2040)+"&WT.tu=1";
	}
	dcsCreateImage(P);
}

function dcsJV(){
	var agt=navigator.userAgent.toLowerCase();
	var major=parseInt(navigator.appVersion);
	var mac=(agt.indexOf("mac")!=-1);
	var nn=((agt.indexOf("mozilla")!=-1)&&(agt.indexOf("compatible")==-1));
	var nn4=(nn&&(major==4));
	var nn6up=(nn&&(major>=5));
	var ie=((agt.indexOf("msie")!=-1)&&(agt.indexOf("opera")==-1));
	var ie4=(ie&&(major==4)&&(agt.indexOf("msie 4")!=-1));
	var ie5up=(ie&&!ie4);
	var op=(agt.indexOf("opera")!=-1);
	var op5=(agt.indexOf("opera 5")!=-1||agt.indexOf("opera/5")!=-1);
	var op6=(agt.indexOf("opera 6")!=-1||agt.indexOf("opera/6")!=-1);
	var op7up=(op&&!op5&&!op6);
	var jv="1.1";
	if (nn6up||op7up){
		jv="1.5";
	}
	else if ((mac&&ie5up)||op6){
		jv="1.4";
	}
	else if (ie5up||nn4||op5){
		jv="1.3";
	}
	else if (ie4){
		jv="1.2";
	}
	return jv;
}

//********

//used internally. -ian
//mod 28 march 07 to not return a value.
function dcsMergeURLQuery(aURL){
	
	if( typeof(aURL) =="undefined"){
		return;
	}
	
	DCS['dcsref'] = DCS['dcsuri'];
	
	if(0 > aURL.indexOf('?')){
		DCS['dcsuri'] = aURL; 
		return;
	}
	
	var ltokens = aURL.split('?',2);
		
	var elems = ltokens[1].split('&');
	
	var ldcsuri = ltokens[0];
	
	for(var elem in elems){
		
		ltokens = elems[elem].split('=',2);
		
		if (ltokens[0]){
								
				if (ltokens[0].indexOf('WT.')==0){
					WT[ltokens[0].substring(3)]=dcsEscape(dcsEncode(ltokens[1]),I18NRE);
					ldcsuri = ldcsuri.replace('&'+elem,'');
					ldcsuri = ldcsuri.replace('?'+elem,'?');
				}
				else if (ltokens[0].indexOf('DCSext.')==0){
					DCSext[ltokens[0].substring(7)]=ltokens[1];
					ldcsuri = ldcsuri.replace('&'+elem,'');
					ldcsuri = ldcsuri.replace('?'+elem,'?');
				}
				else if (ltokens[0].indexOf('DCS.')==0){
					DCS[ltokens[0].substring(4)]=(gI18n&&(ltokens[0].indexOf('DCS.dcsref')==0))?dcsEscape(ltokens[1],I18NRE):ltokens[1];
					ldcsuri = ldcsuri.replace('&'+elem,'');
					ldcsuri = ldcsuri.replace('?'+elem,'?');
				}
			}
		}

	DCS['dcsuri'] = ldcsuri;
	
}


//used internally. -ian
//mod 28 march 07 to not return a value.
function dcsGo(aExitURL, aOptionalWindowName, aOptionalWindowFeatures){
	
	if ( typeof aOptionalWindowName == 'undefined' ){
		//open the requested link in the current window
		document.location.href = aExitURL;		
	}else if(typeof aOptionalWindowFeatures == 'undefined'){
		//open the requested link in a new window
		window.open(aExitURL,aOptionalWindowName);
	}else{	
		//open the requested link in a new window with a specific set of features
		window.open(aExitURL,aOptionalWindowName,aOptionalWindowFeatures);
	}
	
	return false;
	
}


//-ian
//the user has clicked on an external link,
//so trigger a hit collection
//
function dcsExit( aExitURL, aOptionalWindowName, aOptionalWindowFeatures ){
	
	
	
	clearEventData();
	
	//merge args from exit URL into the hit collection
	dcsMergeURLQuery(aExitURL);
	
	if( !gExitsDcsId ){
		return;
	}
	
	//document.images[ img_id ].src = "http://dcshm.verizon.net/" + dcs_host_key + "/dcs.gif?" + qs;
	var P="http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+gDomain+(gExitsDcsId==""?'':'/'+gExitsDcsId)+"/dcs.gif?";
	for (N in DCS){
		if (DCS[N]) {
			P+=dcsA(N,DCS[N]);
		}
	}
	for (N in WT){
		if (WT[N]) {
			P+=dcsA("WT."+N,WT[N]);
		}
	}
	//insert the exit url
	DCSext['exiturl'] = escape(aExitURL);
	for (N in DCSext){
		if (DCSext[N]) {
			P+=dcsA(N,DCSext[N]);
		}
	}
	if (P.length>2048&&navigator.userAgent.indexOf('MSIE')>=0){
		P=P.substring(0,2040)+"&WT.tu=1";
	}
	//collect the exit info
	
	dcsCreateImage(P);
	
	return dcsGo(aExitURL, aOptionalWindowName, aOptionalWindowFeatures);
	
	
}


//-ian
//********



// Code section for Enable SmartView Transition Page tracking
function dcsTP(){
	if (document.cookie.indexOf("WTLOPTOUT=")!=-1){
		return;
	}
	var name="WT_DC";
	var expiry="; expires=Thu, 31-Dec-2020 08:00:00 GMT";
	var path="; path=/";
	var domain="";
	if ((document.cookie.indexOf(name+"=")!=-1)&&(dcsGetCrumb(name,"tsp")=="1")){
		WT.ttp="1";
	}
	if (dcsGetMeta("SmartView_Page")=="1"){
		WT.tsp="1";
		document.cookie=name+"=tsp=1"+expiry+path+domain;
	}
	else{
		document.cookie=name+"=; expires=Sun, 1-Jan-1995 00:00:00 GMT;"+path+domain;
	}
}
function dcsGetMeta(name){
	var elems;
	if (document.all){
		elems=document.all.tags("meta");
	}
	else if (document.documentElement){
		elems=document.getElementsByTagName("meta");
	}
	if (typeof(elems)!="undefined"){
		for (var i=1;i<=elems.length;i++){
			var meta=elems.item(i-1);
			if (meta.name&&(meta.name.indexOf(name)==0)){
				return meta.content;
				break;
			}
		}
	}
	return null;
}




function dcsFunc(func){
	if (typeof(window[func])=="function"){
		window[func]();
	}
}

dcsVar();
dcsMeta();
dcsFunc("dcsAdv");
dcsTag();

//<!-- END OF SmartSource Data Collector  TAG -->	
