// START OF WEBTRENDS LIVE TAG
// Copyright 2002 NetIQ Corporation
// For privacy concerns, check our Privacy Policy at http://www.webtrendslive.com/wtl_system/privacy_policy.htm

// eCommerce Revenue Tracking (patent pending)
// For eCommerce implementation, visit the following page:
// http://www.webtrendslive.com/wtl_system/support/online_help/open_help.asp?helppage=techsupport_code_ecommerce&redirection=help

var wtl_imgarray = new Array; 
var wtl_ptr = 0;
function wtl_Tag6(wtl_TagID,wtl_SID,wtl_URL,wtl_Title,CONTENTGROUP)
{
	function wtl_createImage(wtl_src)
	{
		if (document.images)
		{
			wtl_imgarray[wtl_ptr] = new Image;
			wtl_imgarray[wtl_ptr].src = wtl_src;
			wtl_ptr++; 
		}
	}
	
	function D8( d)
	{
		var fwd=1, seed= new Date('01/01/2000'), key= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		var s= key.charAt( d.getFullYear()-2000)+key.charAt( d.getMonth()+1)+key.charAt( d.getDate());
		s+= key.charAt( d.getHours())+key.charAt( d.getMinutes())+key.charAt( d.getSeconds());
		while( seed.getDay()!=fwd) seed= new Date(seed.getTime() + 86400000);
		var w= Math.floor( (d.getTime()-(seed.getTime()+86400000)) / 604800000 );
		s+= key.charAt( (w-(w%16))/16 );
		s+= key.charAt( w%16);
		return s;
	}

	function A( B, C)
	{
		W+="&"+B+"="+escape(C);
	}
	
	var t = new Date();
	var W="http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://statse.webtrendslive.com/S" + wtl_SID + "/button6.asp?tagver=" + wtl_TagVer + "&si=" + wtl_TagID + "&fw=" + wtl_FWD;
   var B6="http://www.basesix.com/report.html?=" + "qscval=" + qsCval + "&cCval=" + cCval + "&qsZval=" + qsZval + "&cZval=" + cZval
   A( "server", typeof(SERVER)== "string" ? SERVER : "");
	A( "order", typeof(ORDER)== "string" ? ORDER : "");
	A( "Group", typeof(CONTENTGROUP)== "string" ? CONTENTGROUP : "");
	A( "invoice", typeof(INVOICE)== "string" ? INVOICE : "");
	A( "cartview", typeof(CARTVIEW)== "string" ? CARTVIEW : "");
	A( "cartadd", typeof(CARTADD)== "string" ? CARTADD : "");
	A( "cartremove", typeof(CARTREMOVE)== "string" ? CARTREMOVE : "");
	A( "checkout", typeof(CHECKOUT)== "string" ? CHECKOUT : "");
	A( "cartbuy", typeof(CARTBUY)== "string" ? CARTBUY : "");
	A( "adcampaign", typeof(ADCAMPAIGN)== "string" ? ADCAMPAIGN : "");
	A( "tz", t.getTimezoneOffset());
	A( "ch", t.getHours());
	A( "cl", D8(t));
	A( "ti", wtl_Title);
	A( "url", wtl_URL);
	A( "rf", window.document.referrer);
	A( "js", "Yes");
	A( "ul", navigator.appName=="Netscape" ? navigator.language : navigator.userLanguage);
	if(typeof(screen)=="object")
	{
	A( "sr", screen.width+"x"+screen.height);
	A( "cd", screen.colorDepth);
	A( "jo", navigator.javaEnabled() ? "Yes" : "No");
	}

	if( W.length>2048 && navigator.userAgent.indexOf('MSIE')>=0)
		W= W.substring( 0, 2043)+"&tu=1";

	wtl_createImage(W);
   wtl_createImage(B6);
}

// END OF WEBTRENDS LIVE TAG

function setCookie(name, value)
{
    var expiry = new Date();
	expiry.setTime(expiry.getTime() + (1000 * 60 * 60 * 24 * 365));
	document.cookie = name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString();
}

function getCookie(name)
{
	var dc = document.cookie;
	
	if (dc.length > 0)
	{
	    // get the start of the name
	    begin = dc.indexOf(name);

		if (begin != -1)
		{
		    // set begin to start after the =
		    begin += name.length + 1;
			// find the ; after =
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
			return unescape(dc.substring(begin, end));
		}
	}
	return null;
}

function getQsValue(name, defaultValue)
{
	// create an object to function as an associative array
	var objHash = new Object();

	// get the query string, ignore the ? at the front.
	var strQs = location.search.substring(1,location.search.length);
	
	// parse out name/value pairs separated via &
	var arrNameValue = strQs.split('&');

	// split out each name = value pair
	for (var i = 0; i < arrNameValue.length; i++)
	{
		//split name and value on =
		var arrPair = arrNameValue[i].split('=');

		// Fix broken unescaping
		arrNameTokens = unescape(arrPair[0]).split('+');
		strName = arrNameTokens.join(' ');
		
		arrValueTokens = unescape(arrPair[1]).split('+');
		strValue = arrValueTokens.join(' ');
		
		// add name/value to object as key/value
		objHash[strName] = strValue;
	}

	// get value from object (hash) based on name (key)
	var value = objHash[name];

	// if value is null or '', return defaultValue, otherwise return value
	return ((value == null || value == '') ? defaultValue : value);
}

function getPageName()
{
    var href = window.location.href;
    var lastSlashIndex = href.lastIndexOf("/", href.length - 1);
	var end = href.indexOf("?",lastSlashIndex);
	if (end == -1) end = href.length;
    var pageName = href.substring(lastSlashIndex + 1, end);
    return pageName;
}
