/*
***********************************************************************
*
*	Author: 		Alexandre D. Frantz	Teksteel: http://www.teksteel.ca
*	Version:		0.1 
*
***********************************************************************
*/

/*
*	Config: start
*/

var _customuTrackDownloadLinks=true;
var _customuTrackExternalLinks=true;
var _customuTrackMailtoLinks=true;
var _customuLinkDownloadFileTypes="pdf,xls,doc";
var _customuLinkInternalFilters=document.location.href;

/*
*	Config: end
*/



/*
*	Search Engines: start
*/

var _customuOsr = new Array();
var _customuOkw = new Array();

// Google  Image 
_customuOsr[_customuOsr.length]="images.google.co.uk";				_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.es";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.pt";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.it";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.fr";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.nl";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.be";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.de";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.no";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.se";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.dk";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.fi";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.ch";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.at";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.ie";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.ru";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.pl";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.com";				_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.ca";					_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google.com.au";				_customuOkw[_customuOkw.length]="prev";
_customuOsr[_customuOsr.length]="images.google";					_customuOkw[_customuOkw.length]="prev";

// Google 
_customuOsr[_customuOsr.length]="google.co.uk";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.es";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.pt";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.it";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.fr";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.nl";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.be";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.de";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.no";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.se";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.dk";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.fi";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.ch";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.at";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.ie";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.ru";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.pl";						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="google.ca"; 						_customuOkw[_customuOkw.length]="q";

// Yahoo
_customuOsr[_customuOsr.length]="qc.search.yahoo.com"; 				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="ca.search.yahoo.com"; 				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="uk.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="es.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="pt.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="it.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="fr.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="nl.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="be.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="de.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="no.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="se.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="dk.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="fi.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="ch.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="at.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="ie.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="ru.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";
_customuOsr[_customuOsr.length]="pl.search.yahoo.com";				_customuOkw[_customuOkw.length]="p";

// Canada
_customuOsr[_customuOsr.length]="toile.com"; 						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="msn.ca"; 							_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="mamma.ca"; 						_customuOkw[_customuOkw.length]="query";
_customuOsr[_customuOsr.length]="aol.ca"; 							_customuOkw[_customuOkw.length]="query";
_customuOsr[_customuOsr.length]="lycos.ca"; 						_customuOkw[_customuOkw.length]="q";
_customuOsr[_customuOsr.length]="ca.altavista.com"; 				_customuOkw[_customuOkw.length]="q";

// Extras
_customuOsr[_customuOsr.length]="hotbot";							_customuOkw[_customuOkw.length]="query";

_uOsr = _customuOsr.concat(_uOsr);
_uOkw = _customuOkw.concat(_uOkw);

/*
*	Search Engines: 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") urchinTracker(_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=/urchinTracker/i;
	if(typeof(_customuTarg.onclick)!="undefined" && _customuReg.test(_customuTarg.onclick)) return;

	if(typeof(urchinTracker)=="function" && 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){}
}
