var _webTrendsExtender=new ALCSWebTrendsExtender();
_tag.WT.cg_n=_webTrendsExtender.GetContentGroup();
_tag.WT.cg_s=_webTrendsExtender.GetSubContentGroup();
_tag.dcsCollect();

//Bind the TrackRedirectLink function to the onclick event
if (document.body.addEventListener){
	document.body.addEventListener("click",_TrackRedirectLinkClicks, true);		
}
else if(document.body.attachEvent){
	document.body.attachEvent("onclick", _TrackRedirectLinkClicks);		
}

function _TrackRedirectLinkClicks(evt){
	try {
		if (WebTrends){//Verify that the WebTrends object exists, if it does not, we cannot continue
			if (WebTrends&&(typeof(_tag)=="undefined")){ 
				//If the WebTrends object exists, but an instance does not, instantiate a new object
				var _tag=new WebTrends();
				var _webTrendsExtender=new ALCSWebTrendsExtender();					
			}
			//Track Redirect based on WebTrends.dcsOffsite() method
			var e=_tag.dcsEvt(evt,"A"); //Retrieve the anchor element			
			if (e.href){//Only continue if the source element has an href property									
				//Setup variables for dcsMultiTrack
				var url="";
				var uri="";
				var host="";
				var qry="";
				var title="";
				var dlType="";
				//RegEx for Parsing URL
				var urlRegEx = new RegExp(/^((https?):\/\/)?([^:\/\?\#\s]+)([^\?]+)?([\?]+.*)?$/);
				var contentGroup = _webTrendsExtender.GetContentGroup();
				var subContentGroup = _webTrendsExtender.GetSubContentGroup();
				//Get the source element
				var srcEl = evt.target||window.event.srcElement;				
				
				if ((e.protocol.toLowerCase()=="javascript:")||(e.protocol.toLowerCase()=="mailto:")){return;}//This is a JavaScript function call and will be handled by the WebTrends click tracker			
				if (e.href.toLowerCase().indexOf("redirect.ashx?url=")!=-1){//If the redirect handler is used, extract the URL
					//Extract the URL from the redirect handler's query parameter
					url = unescape(e.href.substring(e.href.indexOf("=")+1)); //CHANGED 1/8/09
					//Parse the URL using a reg. expression, we cannot use JavaScript's e.hostname, e.pathname...etc
					var m = urlRegEx.exec(url);	
					if (m!=null){
						host=m[3];
						uri=m[4];
						qry=m[5]||"";
					} else {
						uri=url;
					}
					//Sanity check...if the redirect handler was used, but this is an Onsite link, WebTrends will track automatically
					if (_tag.dcsIsOnsite(host)) {return;}
					title="Offsite: " + ((srcEl.tagName.toLowerCase()=="a")?srcEl.innerHTML:host+uri+qry);  //CHANGED 1/8/09
					dlType="24";
				} else {
					host = e.hostname?(e.hostname.split(":")[0]):"";
					uri = e.pathname?((e.pathname.indexOf("/")!=0)?"/"+e.pathname:e.pathname):"/";
					qry = e.search||"";
					url = e.href;
					//Sanity Check...If this is an offsite link and the redirect handler was not used, WebTrends will track the click automatically
					if (!_tag.dcsIsOnsite(host)){return;}
					var type=uri.substring(uri.lastIndexOf(".")+1,uri.length);					
					var path=(type.toLowerCase().indexOf("aspx")!=-1)?uri.substring(0,uri.lastIndexOf(".")):uri;
					title="Download: " + ((srcEl.tagName.toLowerCase()=="a")?srcEl.innerHTML:host+uri+qry); //CHANGED 1/8/09
					if (_tag.dcsTypeMatch(path,_tag.downloadtypes)){//Determine if the file type is in the list of downloads					
						//We only want to use the innerHTML if the event source was an anchor tag
						title="Download: " + ((srcEl.tagName.toLowerCase()=="a")?srcEl.innerHTML:uri);
						dlType="20";
					} else { 
						//This is a normal, non-download onsite link...ignore it
						return; 
					}
				}						
				//Finally...Call MultiTrack to track the link click
				_tag.dcsMultiTrack("DCS.dcssip",host,"DCS.dcsuri",uri,"DCS.dcsqry",qry,"WT.ti",title,"WT.dl",dlType,"WT.cg_n",contentGroup,"WT.cg_s",subContentGroup);
			}			
		}
	} catch (ex) {
		//Suppress error messages
	}
}

// Uncomment the line below to display the WebTrends Debug popup window
//_tag.dcsDebug();
//_webTrendsExtender.ShowDebugWindow();