
/*
*	Config: start
*/

var _customuTrackDownloadLinks=true;
var _customuTrackExternalLinks=true;
var _customuTrackMailtoLinks=true;
var _customuLinkDownloadFileTypes="pdf,xls,doc";
var _customuLinkInternalFilters=document.location.href;

/*
*	Config: end
*/


/*
*	Utility functions: start
*/
function _customuTrimString(_customuString) 
{
  _customuString = _customuString.replace( /^\s+/g, "" );
  return _customuString.replace( /\s+$/g, "" );
}
/*
*	Utility functions: end
*/



/*
*	Download, Exit and mailto links handler: start
*/
function _customuClickHandler(_customuE)
{
	/* source: http://www.quirksmode.org */
	var rightclick;
	if(!_customuE) var _customuE=window.event;
	if(_customuE.which) rightclick=(_customuE.which == 3);
	else if(_customuE.button) rightclick=(_customuE.button == 2);
	/* source: http://www.quirksmode.org */
	
	if(rightclick) return;
	
	var _customuLinkName=_customuLinkHandler(_customuE);
	if(typeof(_customuLinkName)!="undefined") pageTracker._trackPageview(_customuLinkName);
}

function _customuLinkHandler(_customuE) 
{
	var _customuTarg,_customuHref,_customuExtension,_customuDomain,_customuReg;
	
	/* source: http://www.quirksmode.org */
	if(_customuE.target) _customuTarg=_customuE.target;
	else if(_customuE.srcElement) _customuTarg=_customuE.srcElement;
	if(_customuTarg.nodeType==3) _customuTarg=_customuTarg.parentNode; // defeat Safari bug
	/* source: http://www.quirksmode.org */

	while(!(_customuTarg.nodeName=="A" || _customuTarg.nodeName=="AREA"))
	{
		if(typeof(_customuTarg.nodeName)=="undefined"||_customuTarg.nodeName=="HTML") return;
		_customuTarg=_customuTarg.parentNode;
	} 
	
	if(!_customuTrackDownloadLinks && !_customuTrackExternalLinks && !_customuTrackMailtoLinks) return;
	
	if(_customuTrackDownloadLinks) _customuExtension=_customuTrimString(_customuLinkDownloadFileTypes).split(",");
	if(_customuTrackExternalLinks) _customuDomain=_customuTrimString(_customuLinkInternalFilters).split(",");
	
	if(typeof(_customuTarg.href)!="undefined") _customuHref=_customuTarg.href;
	
	_customuReg=/trackPageview/i;
	if(typeof(_customuTarg.onclick)!="undefined" && _customuReg.test(_customuTarg.onclick)) return;

	if(typeof(_customuHref)!="undefined")
	{					
		// 1. download
		if(_customuTrackDownloadLinks)
		{
			for(var ii=0;ii<_customuExtension.length;ii++)
			{
				_customuReg=eval("/\\."+_customuExtension[ii]+"$/i");				
				if (_customuReg.test(_customuHref)) 
				{
					var _customuFileName=_customuHref.substring(_customuHref.lastIndexOf("/")<0?0:_customuHref.lastIndexOf("/"));
					return "/custom/download"+_customuFileName;
				}
			}
		}
		
		// 2. mailto
		if(_customuTrackMailtoLinks)
		{
			_customuReg=/^mailto:/i;
			if (_customuReg.test(_customuHref)) 
			{
				return "/custom/mailto/"+_customuHref.substring(_customuHref.indexOf(":")+1,_customuHref.indexOf("?")<0?_customuHref.length:_customuHref.indexOf("?"));				
			}
		}
		
		//3. exit
		if(_customuTrackExternalLinks)
		{
			for(var ii=0;ii<_customuDomain.length;ii++)
			{
				_customuReg=new RegExp(_customuDomain[ii], "i");
				if (_customuReg.test(_customuHref)) 
				{
					return;
				}
			}
			var _customuDest=_customuHref.substring(_customuHref.indexOf("://")<0?0:_customuHref.indexOf("://")+"://".length);
			return "/custom/exit/"+_customuDest;
		}
	}
}

/*
*	Download and Exit links handler: end
*/

function _customuInit()
{
	try
	{
		document.onclick=_customuClickHandler
	}
	catch(e){}
}