
// WebTrends SmartSource Data Collector Tag
// Version: 8.6.2     
// Tag Builder Version: 3.0
// Created: 4/23/2009 10:24:04 AM

function WebTrends(){
	var that=this;
	// begin: user modifiable
	this.domain="statse.webtrendslive.com";
	this.dcsid="";//this will be set by the base tag
	this.timezone=0;
	this.fpcdom=".ingrammicro.com";
	this.enabled=true;
	this.i18n=false;
	this.fpc="WT_FPC";
	this.paidsearchparams="gclid";
	// end: user modifiable
	this.DCS={};
	this.WT={};
	this.DCSext={};
	this.images=[];
	this.index=0;
	this.exre=(function(){return(window.RegExp?new RegExp("dcs(uri)|(ref)|(aut)|(met)|(sta)|(sip)|(pro)|(byt)|(dat)|(p3p)|(cfg)|(redirect)|(cip)","i"):"");})();
	this.re=(function(){return(window.RegExp?(that.i18n?{"%25":/\%/g}:{"%09":/\t/g,"%20":/ /g,"%23":/\#/g,"%26":/\&/g,"%2B":/\+/g,"%3F":/\?/g,"%5C":/\\/g,"%22":/\"/g,"%7F":/\x7F/g,"%A0":/\xA0/g}):"");})();
}
WebTrends.prototype.dcsGetId=function(){
	if (this.enabled&&(document.cookie.indexOf(this.fpc+"=")==-1)&&(document.cookie.indexOf("WTLOPTOUT=")==-1)){
		document.write("<scr"+"ipt type='text/javascript' src='"+"http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+this.domain+"/"+this.dcsid+"/wtid.js"+"'><\/scr"+"ipt>");
	}
}
WebTrends.prototype.dcsGetCookie=function(name){
	var cookies=document.cookie.split("; ");
	var cmatch=[];
	var idx=0;
	var i=0;
	var namelen=name.length;
	var clen=cookies.length;
	for (i=0;i<clen;i++){
		var c=cookies[i];
		if ((c.substring(0,namelen+1))==(name+"=")){
			cmatch[idx++]=c;
		}
	}
	var cmatchCount=cmatch.length;
	if (cmatchCount>0){
		idx=0;
		if ((cmatchCount>1)&&(name==this.fpc)){
			var dLatest=new Date(0);
			for (i=0;i<cmatchCount;i++){
				var lv=parseInt(this.dcsGetCrumb(cmatch[i],"lv"));
				var dLst=new Date(lv);
				if (dLst>dLatest){
					dLatest.setTime(dLst.getTime());
					idx=i;
				}
			}
		}
		return unescape(cmatch[idx].substring(namelen+1));
	}
	else{
		return null;
	}
}
WebTrends.prototype.dcsGetCrumb=function(cval,crumb,sep){
	var aCookie=cval.split(sep||":");
	for (var i=0;i<aCookie.length;i++){
		var aCrumb=aCookie[i].split("=");
		if (crumb==aCrumb[0]){
			return aCrumb[1];
		}
	}
	return null;
}
WebTrends.prototype.dcsGetIdCrumb=function(cval,crumb){
	var id=cval.substring(0,cval.indexOf(":lv="));
	var aCrumb=id.split("=");
	for (var i=0;i<aCrumb.length;i++){
		if (crumb==aCrumb[0]){
			return aCrumb[1];
		}
	}
	return null;
}
WebTrends.prototype.dcsIsFpcSet=function(name,id,lv,ss){
	var c=this.dcsGetCookie(name);
	if (c){
		return ((id==this.dcsGetIdCrumb(c,"id"))&&(lv==this.dcsGetCrumb(c,"lv"))&&(ss==this.dcsGetCrumb(c,"ss")))?0:3;
	}
	return 2;
}
WebTrends.prototype.dcsFPC=function(){
	if (document.cookie.indexOf("WTLOPTOUT=")!=-1){
		return;
	}
	var WT=this.WT;
	var name=this.fpc;
	var dCur=new Date();
	var adj=(dCur.getTimezoneOffset()*60000)+(this.timezone*3600000);
	dCur.setTime(dCur.getTime()+adj);
	var dExp=new Date(dCur.getTime()+315360000000);
	var dSes=new Date(dCur.getTime());
	WT.co_f=WT.vtid=WT.vtvs=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 curt=dCur.getTime().toString();
			for (var i=2;i<=(32-curt.length);i++){
				WT.co_f+=Math.floor(Math.random()*16.0).toString(16);
			}
			WT.co_f+=curt;
			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 c=this.dcsGetCookie(name);
		var id=this.dcsGetIdCrumb(c,"id");
		var lv=parseInt(this.dcsGetCrumb(c,"lv"));
		var ss=parseInt(this.dcsGetCrumb(c,"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.vtid=(typeof(this.vtid)=="undefined")?WT.co_f:(this.vtid||"");
	WT.vtvs=(dSes.getTime()-adj).toString();
	var expiry="; expires="+dExp.toGMTString();
	var cur=dCur.getTime().toString();
	var ses=dSes.getTime().toString();
	document.cookie=name+"="+"id="+WT.co_f+":lv="+cur+":ss="+ses+expiry+"; path=/"+(((this.fpcdom!=""))?("; domain="+this.fpcdom):(""));
	var rc=this.dcsIsFpcSet(name,WT.co_f,cur,ses);
	if (rc!=0){
		WT.co_f=WT.vtvs=WT.vt_f_s=WT.vt_f_d=WT.vt_f_tlh=WT.vt_f_tlv="";
		if (typeof(this.vtid)=="undefined"){
			WT.vtid="";
		}
		WT.vt_f=WT.vt_f_a=rc;
    }
}
WebTrends.prototype.dcsMultiTrack=function(){
	var args=dcsMultiTrack.arguments?dcsMultiTrack.arguments:arguments;
	if (args.length%2==0){
		this.dcsSetProps(args);
		var dCurrent=new Date();
		this.DCS.dcsdat=dCurrent.getTime();
		this.dcsFPC();
		this.dcsTag();
	}
}
WebTrends.prototype.dcsCleanUp=function(){
	this.DCS={};
	this.WT={};
	this.DCSext={};
	if (arguments.length%2==0){
		this.dcsSetProps(arguments);
	}
}
WebTrends.prototype.dcsSetProps=function(args){
	for (var i=0;i<args.length;i+=2){
		if (args[i].indexOf('WT.')==0){	
			this.WT[args[i].substring(3)]=args[i+1];
		}
		else if (args[i].indexOf('DCS.')==0){
			this.DCS[args[i].substring(4)]=args[i+1];
		}
		else if (args[i].indexOf('DCSext.')==0){
			this.DCSext[args[i].substring(7)]=args[i+1];
		}
	}
}
WebTrends.prototype.dcsAdv=function(){
	this.dcsFPC();
}
WebTrends.prototype.dcsVar=function(){
	var dCurrent=new Date();
	var WT=this.WT;
	var DCS=this.DCS;
	WT.tz=parseInt(dCurrent.getTimezoneOffset()/60*-1)||"0";
	WT.bh=dCurrent.getHours()||"0";
	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";
	}
	//this is IM custom code to allow the JS to override the page title
	if(WT.ti == ''){
		if (document.title){
			if (window.RegExp){
				var tire=new RegExp("^"+window.location.protocol+"//"+window.location.hostname+"\\s-\\s");
				WT.ti=document.title.replace(tire,"");
			}
			else{
				WT.ti=document.title;
			}
		}
	}
	WT.js="Yes";
	WT.jv=(function(){
		var agt=navigator.userAgent.toLowerCase();
		var major=parseInt(navigator.appVersion);
		var mac=(agt.indexOf("mac")!=-1);
		var ff=(agt.indexOf("firefox")!=-1);
		var ff0=(agt.indexOf("firefox/0.")!=-1);
		var ff10=(agt.indexOf("firefox/1.0")!=-1);
		var ff15=(agt.indexOf("firefox/1.5")!=-1);
		var ff20=(agt.indexOf("firefox/2.0")!=-1);
		var ff3up=(ff&&!ff0&&!ff10&!ff15&!ff20);
		var nn=(!ff&&(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 (ff3up){
			jv="1.8";
		}
		else if (ff20){
			jv="1.7";
		}
		else if (ff15){
			jv="1.6";
		}
		else if (ff0||ff10||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;
	})();
	WT.ct="unknown";
	if (document.body&&document.body.addBehavior){
		try{
			document.body.addBehavior("#default#clientCaps");
			WT.ct=document.body.connectionType||"unknown";
			document.body.addBehavior("#default#homePage");
			WT.hp=document.body.isHomePage(location.href)?"1":"0";
		}
		catch(e){
		}
	}
	if (document.all){
		WT.bs=document.body?document.body.offsetWidth+"x"+document.body.offsetHeight:"unknown";
	}
	else{
		WT.bs=window.innerWidth+"x"+window.innerHeight;
	}
	WT.fv=(function(){
		var i,flash;
		if (window.ActiveXObject){
			for(i=10;i>0;i--){
				try{
					flash=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
					return i+".0";
				}
				catch(e){
				}
			}
		}
		else if (navigator.plugins&&navigator.plugins.length){
			for (i=0;i<navigator.plugins.length;i++){
				if (navigator.plugins[i].name.indexOf('Shockwave Flash')!=-1){
					return navigator.plugins[i].description.split(" ")[2];
				}
			}
		}
		return "Not enabled";
	})();
	WT.slv=(function(){
		var slv="Not enabled";
		try{     
			if (navigator.userAgent.indexOf('MSIE')!=-1){
				var sli = new ActiveXObject('AgControl.AgControl');
				if (sli){
					slv="Unknown";
				}
			}
			else if (navigator.plugins["Silverlight Plug-In"]){
				slv="Unknown";
			}
		}
		catch(e){
		}
		if (slv!="Not enabled"){
			var i,j,v;
			if ((typeof(Silverlight)=="object")&&(typeof(Silverlight.isInstalled)=="function")){
				for(i=3;i>0;i--){
					for (j=9;j>=0;j--){
						v=i+"."+j;
						if (Silverlight.isInstalled(v)){
							slv=v;
							break;
						}
					}
					if (slv==v){
						break;
					}
				}
			}
		}
		return slv;
	})();
	if (this.i18n){
		if (typeof(document.defaultCharset)=="string"){
			WT.le=document.defaultCharset;
		} 
		else if (typeof(document.characterSet)=="string"){
			WT.le=document.characterSet;
		}
		else{
			WT.le="unknown";
		}
	}
	WT.tv="8.6.2";
//	WT.sp="@@SPLITVALUE@@";
	WT.dl="0";
	WT.ssl=(window.location.protocol.indexOf('https:')==0)?"1":"0";
	DCS.dcsdat=dCurrent.getTime();
	DCS.dcssip=window.location.hostname;
	DCS.dcsuri=window.location.pathname;
	WT.es=DCS.dcssip+DCS.dcsuri;
	if (window.location.search){
		DCS.dcsqry=window.location.search;
	}
	if (DCS.dcsqry){
		var dcsqry=DCS.dcsqry.toLowerCase();
		var params=this.paidsearchparams.length?this.paidsearchparams.toLowerCase().split(","):[];
		for (var i=0;i<params.length;i++){
			if (dcsqry.indexOf(params[i]+"=")!=-1){
				WT.srch="1";
				break;
			}
		}
	}
	if ((window.document.referrer!="")&&(window.document.referrer!="-")){
		if (!(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)<4)){
			DCS.dcsref=window.document.referrer;
		}
	}
}
WebTrends.prototype.dcsEscape=function(S, REL){
	if (REL!=""){
		S=S.toString();
		for (var R in REL){
 			if (REL[R] instanceof RegExp){
				S=S.replace(REL[R],R);
 			}
		}
		return S;
	}
	else{
		return escape(S);
	}
}
WebTrends.prototype.dcsA=function(N,V){
	if (this.i18n&&(this.exre!="")&&!this.exre.test(N)){
		if (N=="dcsqry"){
			var newV="";
			var params=V.substring(1).split("&");
			for (var i=0;i<params.length;i++){
				var pair=params[i];
				var pos=pair.indexOf("=");
				if (pos!=-1){
					var key=pair.substring(0,pos);
					var val=pair.substring(pos+1);
					if (i!=0){
						newV+="&";
					}
					newV+=key+"="+this.dcsEncode(val);
				}
			}
			V=V.substring(0,1)+newV;
		}
		else{
			V=this.dcsEncode(V);
		}
	}
	return "&"+N+"="+this.dcsEscape(V, this.re);
}
WebTrends.prototype.dcsEncode=function(S){
	return (typeof(encodeURIComponent)=="function")?encodeURIComponent(S):escape(S);
}
WebTrends.prototype.dcsCreateImage=function(dcsSrc){
	if (document.images){
		this.images[this.index]=new Image();
		this.images[this.index].src=dcsSrc;
		this.index++;
	}
	else{
		document.write('<IMG ALT="" BORDER="0" NAME="DCSIMG" WIDTH="1" HEIGHT="1" SRC="'+dcsSrc+'">');
	}
}
WebTrends.prototype.dcsMeta=function(){
	var elems;
	if (document.all){
		elems=document.all.tags("meta");
	}
	else if (document.documentElement){
		elems=document.getElementsByTagName("meta");
	}
	if (typeof(elems)!="undefined"){
		var length=elems.length;
		for (var i=0;i<length;i++){
			var name=elems.item(i).name;
			var content=elems.item(i).content;
			var equiv=elems.item(i).httpEquiv;
			if (name.length>0){
				if (name.toUpperCase().indexOf("WT.")==0){
					this.WT[name.substring(3)]=content;
				}
				else if (name.toUpperCase().indexOf("DCSEXT.")==0){
					this.DCSext[name.substring(7)]=content;
				}
				else if (name.toUpperCase().indexOf("DCS.")==0){
					this.DCS[name.substring(4)]=content;
				}
			}
		}
	}
}
WebTrends.prototype.dcsTag=function(){
	if (document.cookie.indexOf("WTLOPTOUT=")!=-1){
		return;
	}
	var WT=this.WT;
	var DCS=this.DCS;
	var DCSext=this.DCSext;
	var i18n=this.i18n;
	var P="http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+this.domain+(this.dcsid==""?'':'/'+this.dcsid)+"/dcs.gif?";
	if (i18n){
		WT.dep="";
	}
	for (var N in DCS){
 		if (DCS[N]&&(typeof DCS[N]!="function")){
			P+=this.dcsA(N,DCS[N]);
		}
	}
	var keys=["co_f","vtid","vtvs","vt_f_tlv"];
	for (var i=0;i<keys.length;i++){
		var key=keys[i];
		if (WT[key]){
			P+=this.dcsA("WT."+key,WT[key]);
			delete WT[key];
		}
	}
	for (N in WT){
		if (WT[N]&&(typeof WT[N]!="function")){
			P+=this.dcsA("WT."+N,WT[N]);
		}
	}
	for (N in DCSext){
		if (DCSext[N]&&(typeof DCSext[N]!="function")){
			if (i18n){
				WT.dep=(WT.dep.length==0)?N:(WT.dep+";"+N);
			}
			P+=this.dcsA(N,DCSext[N]);
		}
	}
	if (i18n&&(WT.dep.length>0)){
		P+=this.dcsA("WT.dep",WT.dep);
	}
	if (P.length>2048&&navigator.userAgent.indexOf('MSIE')>=0){
		P=P.substring(0,2040)+"&WT.tu=1";
	}
	this.dcsCreateImage(P);
	this.WT.ad="";
}
WebTrends.prototype.dcsDebug=function(){
	var t=this;
	var i=t.images[0].src;
	var q=i.indexOf("?");
	var r=i.substring(0,q).split("/");
	var m="<b>Protocol</b><br><code>"+r[0]+"<br></code>";
	m+="<b>Domain</b><br><code>"+r[2]+"<br></code>";
	m+="<b>Path</b><br><code>/"+r[3]+"/"+r[4]+"<br></code>";
	m+="<b>Query Params</b><code>"+i.substring(q+1).replace(/\&/g,"<br>")+"</code>";
	m+="<br><b>Cookies</b><br><code>"+document.cookie.replace(/\;/g,"<br>")+"</code>";
	if (t.w&&!t.w.closed){
		t.w.close();
	}
	t.w=window.open("","dcsDebug","width=500,height=650,scrollbars=yes,resizable=yes");
	t.w.document.write(m);
	t.w.focus();
}
WebTrends.prototype.dcsCollect=function(){
    if (this.enabled){
        this.dcsVar();
        this.dcsMeta();
        this.dcsAdv();
        this.dcsTag();
    }
}

function dcsMultiTrack(){
	if (typeof(_tag)!="undefined"){
		return(_tag.dcsMultiTrack());
	}
}

function dcsDebug(){
	if (typeof(_tag)!="undefined"){
		return(_tag.dcsDebug());
	}
}

Function.prototype.wtbind = function(obj){
	var method=this;
	var temp=function(){
		return method.apply(obj,arguments);
	};
	return temp;
}

//ingram specific tracking helper functions

//This object holds all the required tracking variables
//you can add to these, just ensure you follow the naming rules
function IMTrackingBean()
{
	this.IM_PSKU=''; //productSKU
	this.IM_PST=''; //productSubTotal (Add from basket action)
	this.IM_PU=''; //productUnits 
	this.IM_PL=''; //productLines
	this.IM_SN=''; //scenarioName
	this.IM_SS=''; //scenarioStep
	this.IM_SK=''; //searchKeyword
	this.IM_SPN=''; //searchPartNumber
	this.IM_SRR=''; //searchResults returned
	this.IM_TE=''; //transactionEvent
	this.IM_TI=''; //title
	this.IM_URI=''; //page URI
	this.IM_MPC=''; //marketing placement click
	this.IM_MPT=''; //marketing placement type
	this.IM_MPD=''; //marketing placement Display
	this.IM_WT_ARGS={};//this will be a array of extra webtrends specific elements, e.g. 'WT.mc_id','test'
}

//call this function if you want to create an IMTrackingBean on the fly
function createIMTrackingBean(){
	var iMTB = new IMTrackingBean();
	if("TRUE"=="TRUE")
	{
		if(arguments.length%2==0)
		{
			for (var i=0;i<arguments.length;i+=2){
				try{
					if ( !(arguments[i+1] instanceof Array) )
					{
						eval('iMTB.'+arguments[i]+'=\''+arguments[i+1]+'\'');
					}else{
						var arr ='';
						for (var j=0;j<arguments[i+1].length;j++){
							if(arr!=''){arr+=',';}
							arr +='\''+arguments[i+1][j]+'\'';
						}
						eval('iMTB.'+arguments[i]+'=new Array('+arr+')');
					}
				}
				catch(e)
				{
					imTrackingError(e);
				}
			}
		}
	}
	return iMTB;
}

//Allow things to be debuged if we are having problems
function imTrackingError(e)
{
	//only if debug
	if("FALSE"=="TRUE")
	{
		txt="Tracking Error.\n\n";
	  	txt+="Error Name: " + e.name + "\n\n";
	  	txt+="Message."+ e.message + "\n\n";
	  	showAlertDialog(txt)
	}
}

function imTracking(iMTB)//IMTrackingBean
{
	if("TRUE"=="TRUE")
	{
		try{
			if(iMTB)
			{
				if(iMTB.IM_URI !='')
				{
					//set all the specific WT args
					if (iMTB.IM_WT_ARGS &&
						iMTB.IM_WT_ARGS.length%2==0)
					{
						if (typeof(_tag)!="undefined")
						{
							_tag.dcsSetProps(iMTB.IM_WT_ARGS);
						}					
					}					
					dcsMultiTrack('DCS.dcsuri',(iMTB.IM_URI?iMTB.IM_URI:'undefined'),
									'WT.ti',(iMTB.IM_TI?iMTB.IM_TI:''),
									'WT.pn_sku',(iMTB.IM_PSKU?iMTB.IM_PSKU:''),
									'WT.z_value',(iMTB.IM_PST?iMTB.IM_PST:''),
									'WT.z_units',(iMTB.IM_PU?iMTB.IM_PU:''),
									'WT.z_lines',(iMTB.IM_PL?iMTB.IM_PL:''),
									'WT.si_n',(iMTB.IM_SN?iMTB.IM_SN:''),
									'WT.si_x',(iMTB.IM_SS?iMTB.IM_SS:''),
									'WT.z_oss_kw',(iMTB.IM_SK?iMTB.IM_SK:''),
									'WT.z_oss_pn',(iMTB.IM_SPN?iMTB.IM_SPN:''),
									'WT.oss_r',(iMTB.IM_SRR?iMTB.IM_SRR:''),
									'WT.tx_e',(iMTB.IM_TE?iMTB.IM_TE:''),
									'WT.z_ad_t',(iMTB.IM_MPT?iMTB.IM_MPT:''),
									'WT.ad',(iMTB.IM_MPD?iMTB.IM_MPD:''),
									'WT.ac',(iMTB.IM_MPC?iMTB.IM_MPC:''));				
				}
			}		
		}
		catch(e)
		{
			//do nothing, it's only tacking
			imTrackingError(e);
			if("FALSE"=="TRUE")
			{
				dcsDebug();
			}
		}
	}
}

//---------------------------------
//---------------------------------
//---- CURRENCY WEBTRENDS CODE ----
//---------------------------------
//15MAY09 : WebTrends : Added custom exchange rate conversions

// This is where we include the exchange rates file and standard WebTrends tag
function imInclude(filename) {
	document.write('<script src="' + filename + '" type="text/javascript"></script>');
}

// This effectively extends the standard WebTrends object, taking in currency info
function IMWebTrends(imExRates, imCurrDefaults) {
	// Create the standard tag in here
	this.wtTag = new WebTrends();
	
	// Add escaping of other chars to WebTrends' own escaping RegExp
	// UNCOMMENT IF = SIGN IN DATA PROVES A PROBLEM
	/*if (typeof(this.wtTag.re) == 'object') {
		this.wtTag.re['%3D'] = new RegExp(/=/g);
	}*/

	// Reference all tag properties/methods into this custom object so they can all be used as normal. 
	// (Although be aware simple data types are passed by value, so will not reflect any changes made inside wtTag)
	for (var n in this.wtTag) {
		this[n] = this.wtTag[n];
	}

	// Add in the currency info
	this.exRates = imExRates;
	this.currDefaults = imCurrDefaults;
	
	// This overrides the standard dcsTag to pre-process all transaction currency conversions (works on load and dcsMultiTrack()
	this.dcsTag = function() {
    	this.populateCurrencies();
    	this.wtTag.dcsTag(arguments);
    	this.clearZValues();
	}

	// This overrides the standard dcsCollect to extract WT params from URL (don't want to happen with dcsMultiTrack()
	this.dcsCollect = function () {
	    if (this.enabled){
	        this.dcsVar();
	        this.dcsMeta();
	        this.dcsAdv();
			this.setParamsFromUrl();
	        this.dcsTag();
	    }
	}
	
	// This overrides the standard dcsCleanUp to ensure references are maintained
	this.dcsCleanUp = function() {
    	this.wtTag.dcsCleanUp(arguments);
    	this.DCS = this.wtTag.DCS;
    	this.DCSext = this.wtTag.DCSext;
    	this.WT = this.wtTag.WT;
	}
}

// Adds in a method to our custom object for formatting currency figures
IMWebTrends.prototype.formatMoney = function(amount) {
	// Round to 2 decimal places
	amount = Math.round(amount * 100) / 100;
	// Format as a string, padding zeros
	var aAmounts = amount.toString().split('.');
	if (aAmounts.length == 1) {
		aAmounts[1] = '00';
	}
	else {
		aAmounts[1] += '00';
		aAmounts[1] = aAmounts[1].substr(0,2);
	}
	return aAmounts.join('.');
}

// Adds in a method to our custom object for converting between currencies
IMWebTrends.prototype.convert = function(amount, sourceCurrency, targetCurrency) {
	var rate = this.exRates[sourceCurrency + '-' + targetCurrency];
	// If no rate is specified, will use zero, so amount will come out to zero
	if (typeof(rate) == 'undefined') {
		rate = 0;
	}
	return this.formatMoney(amount * rate);
}

//Adds in a method to our custom object for populating all multi-currency transaction details
IMWebTrends.prototype.populateCurrencies = function () {
	try {
		// We only care about all this is there is a WT.tx_e and it isn't blank or a view
		if (typeof(this.WT.tx_e) != 'undefined' && this.WT.tx_e != '' && this.WT.tx_e != 'v') {
			// Want to make sure this is lowercase
			this.WT.tx_e = this.WT.tx_e.toLowerCase();
			
			// If no sitecode, set to UNKNOWN 
			if (typeof(this.WT.z_sitecode) == 'undefined') this.WT.z_sitecode = 'UNKNOWN';
	    	this.WT.z_sitecode = this.WT.z_sitecode.toUpperCase();
			
	    	// Find the site currency (default to UNKNOWN)
	    	var siteCurr = 'UNKNOWN';
			if (typeof(this.currDefaults[this.WT.z_sitecode]) != 'undefined') siteCurr = this.currDefaults[this.WT.z_sitecode].toUpperCase();
	
			// If no transaction currency, then set to UNKNOWN
			if (typeof(this.WT.z_tx_cur) == 'undefined') this.WT.z_tx_cur = 'UNKNOWN';
	    	this.WT.z_tx_cur = this.WT.z_tx_cur.toUpperCase();
	
	    	// If no z_value, set to zero
	    	if (typeof(this.WT.z_value) == 'undefined') this.WT.z_value = '0.00';

	    	// If no z_units, set to zero
	    	if (typeof(this.WT.z_units) == 'undefined') this.WT.z_units = '0';
	    		    	
	    	// Now we have everything we need
    		var aValueTrans = this.WT.z_value.split(';');
    		var aValueSite = new Array(aValueTrans.length);
    		var aValueUsd = new Array(aValueTrans.length);
    		
    		// First, make sure passed transaction values are properly formatted
    		for (var i=0; i<aValueTrans.length; i++) {
    			aValueTrans[i] = this.formatMoney(aValueTrans[i]);
    		}
    		
    		// If site currency is same as transaction, then no conversion needed
    		if (this.WT.z_tx_cur == siteCurr && siteCurr != 'UNKNOWN') {
    			aValueSite = aValueTrans;
    		}
    		else {
    			// Convert transaction values to site currency
	    		for (i=0; i<aValueTrans.length; i++) {
	    			aValueSite[i] = this.convert(aValueTrans[i], this.WT.z_tx_cur, siteCurr);
	    		}
    		}

    		// If transaction currency is USD then no conversion needed
    		if (this.WT.z_tx_cur == 'USD') {
    			aValueUsd = aValueTrans;
    		}
    		else {
    			// Or if site currency is USD, then no conversion needed
    			if (siteCurr == 'USD') {
    				aValueUsd = aValueSite;
    			}
    			else {
    				// Convert transaction values to USD
    	    		for (i=0; i<aValueTrans.length; i++) {
    	    			aValueUsd[i] = this.convert(aValueTrans[i], this.WT.z_tx_cur, 'USD');
    	    		}
    			}
    		}
    		
    		// Now put the values into WebTrends tags
    		if (this.WT.tx_e == 'p') {
    			this.WT.tx_s = aValueSite.join(';');
    			this.WT.z_tx_usd = aValueUsd.join(';');
    			this.WT.z_tx_txn = aValueTrans.join(';');
    			this.WT.tx_u = this.WT.z_units;
    		}
    		else {
    			var txe = this.WT.tx_e;
    			if (txe == 'i') txe = 'a'; 
    			this.WT['z_tx_' + txe] = aValueSite.join(';');
    			this.WT['z_tx_us' + txe] = aValueUsd.join(';');
    			this.WT['z_tx_tx' + txe] = aValueTrans.join(';');
    			this.WT['z_tx_u' + txe] = this.WT.z_units;
    			this.WT.tx_u = this.WT.z_units;
    		}
		}
		// Don't want to log these
		this.WT.z_value = null;
		//units can be in view datasheet
		if (typeof(this.WT.z_units) != 'undefined' && this.WT.z_units != '') this.WT.tx_u = this.WT.z_units;
		this.WT.z_units = null;
		}
	catch (e) {
		// Do nothing so we can still log whatever we have
	}
}

//Adds in a method to our custom object for setting parameters extracted from URL
IMWebTrends.prototype.setParamsFromUrl = function () {
	var qry = location.search.substring(1);
	if (qry != '') {
		var pair = new Array();
		var params = new Array();
		qry = qry.split('&');
		for (var i=0; i<qry.length; i++) {
			pair = qry[i].split('=');
			if (pair[0] != '') {
				params.push(pair[0]);
				if (pair.length == 1) {
					params.push('');
				}
				else {
					params.push(pair[1]);
				}
			}
		}
		this.dcsSetProps(params);
	}
}

//Adds in function to clear out unwanted WT.z_tx_* params and others
IMWebTrends.prototype.clearZValues = function() {
	for (var n in this.WT) {
		if ((n.substr(0, 5) == 'z_tx_' || n == 'z_load_basket') && n != 'z_tx_cur') this.WT[n] = null;
	}
}
