// WebTrends Ad Director
// Copyright (c) 1996-2007 WebTrends Inc. All rights reserved.
// $DateTime: 2007/01/31 12:23:58 $

// First party cookie implementation for use on a site using WebTrends Analytics JS Tag
// configured to use commerce parameters wt.pn_sku, wt.tx_s, wt.tx_u, and wt.tx_i.
// Apply this javascript to all page on the site (will work on just landing pages).
// Change @@CUSTID@@ in the last line to reflect the correct account number.
// BMC 08I31610 Oct 29, 2008

function DcsDynamicSearch(cid){
	// private members
	var cname="WT_DSAI";
	var wt=(typeof(WT)=="object")?WT:{};

	// private methods
	function setAdInfo(){
		var value=getQueryParam("cshift_ck");
		if (value.length>0){
			var cur=new Date();
			var exp=new Date(cur.getTime()+315360000000);
			document.cookie=cname+"="+value+"; expires="+exp.toGMTString()+"; path=/";
		}
	}
	function getQueryParam(key){
		var qry=window.location.search.substring(1);
		if (qry.length>0){
			var params=qry.split("&");
			var count=params.length;
			for (var i=0;i<count;i++){
				var p=params[i].split("=");
				if (p[0]==key){
					return p[1];
				}
			}
		}
		return "";
	}

	// privileged methods
	this.getClientId=function(){
		return cid;
	};
	this.getProductInfo=function(){
		var info="";
		try{
			var id=wt.pn_sku.split(";");
			var price=wt.tx_s.split(";");
			var qty=wt.tx_u.split(";");
			for (var i=0;i<id.length;i++){
				info+=(i?",":"")+id[i]+"#"+parseInt((parseFloat(price[i])*100)/parseInt(qty[i]))+"*"+qty[i];
			}
		}
		catch(e){
		}
		return info;
	};
	this.getOrderInfo=function(){
		return wt.tx_i||"";
	};
	this.getIsNew=function(){
		return 1;
	};
	this.getAdInfo=function(){
		return dcsGetCookie(cname)||"";
	};
	this.getAttribution=function(){
		return "";
	};
	this.isConvPage=function(){
		return ((typeof(wt)=="object")&&(wt.tx_e=="p"))?true:false;
	};

	// read query parameter, set cookie
	setAdInfo();
}

var dcsDS=new DcsDynamicSearch(5135);
if (dcsDS.isConvPage()){
	f2convert(dcsDS.getClientId(),dcsDS.getProductInfo(),dcsDS.getOrderInfo(),dcsDS.getIsNew(),dcsDS.getAdInfo());
}

