// begin init vars
var sStem = 'http://tracking.webeventseurope.com/Track.aspx?a=6';
//var sStem = 'http://SessionTracker.WebAnalytics.com/Track.aspx?a=17';
var sUD = "undefined"; 
var sQS = ""; 
var sOLT = false; 
var oImg = new Image(); 
var bNet = (navigator.appName == "Netscape");

var guid = ""; 
var u;
var s;
var st = "False"; // session start


if(typeof oACTION != sUD)
{
	sQS += "&x=" + escape(oACTION);
	oACTION = '';
}
else 
	var oACTION = '';

if(typeof oAMOUNT != sUD)
{
	sQS += "&xa=" + escape(oAMOUNT);
	oAMOUNT = '';
}
else 
	var oAMOUNT = '';
	
if(typeof oORDERID != sUD)
{
	sQS += "&oc=" + escape(oORDERID);
	oORDERID = '';
}
else 
	var oORDERID = '';
	
if(typeof oMEMBERID != sUD)
	sStem += "&m=" + escape(oMEMBERID);
	
if(typeof oDOCUMENTGROUP != sUD)
	sStem += "&c=" + escape(oDOCUMENTGROUP);
	
if(typeof oDOCUMENTNAME != sUD)
	sStem += "&b=" + escape(oDOCUMENTNAME);
else 
	if(document.title.length > 0)
		sStem+="&b="+escape(document.title);
		
var dDate = new Date();

sQS += "&d=" + escape(dDate.toGMTString());
sQS += "&n=" + escape(parseInt(dDate.getTimezoneOffset() / 60));

var oExcl = '';

if(typeof EXCL != sUD)
	oExcl = EXCL;

bMS = (navigator.appName.substring(0,9) == "Microsoft");

// end init vars

// begin root

if (cookies_Enabled()) {
	// only do track if cookies enabled. avoid bogus data
	if(((window.screen) || ((new Array()).toSource) || ((new Array()).shift && bMS)) && (navigator.userAgent.indexOf('Mac') < 0))
	{
		if(window.onload)
		{
			onLd = window.onload;
			sOLT = true;
		}
		
		window.onload = handleOnLoad;
	}

	//mjg 20060615 don't track page. this script only handles exits
	//handleReferrer(true);
}

// end root
	
// begin functions

function keyVal(x)
{
	var z = location.search;
	var i = z.indexOf("?" + x + "=");
	var j = z.indexOf("&" + x + "=");
	if((i == 0) || (j > -1))
	{
		var k = (i == 0) ? 0 : j;
		var l = z.indexOf('&', k + 1);
		
		return z.substring(k + 2 + x.length, (l > -1) ? l : z.length);
	}
	
	return '';
}

function fileNamePart(x)
{
	return (x.substring(x.lastIndexOf("/") + 1, x.length));
}

function filePathPart(x) // x = document.location
{
	var h = hostNamePart(x);
	var p = x.href.substring(x.href.indexOf(h) + h.length, x.href.length);
	if (p.substring(0, 1) != "/") 
		p = "/" + p;
	return p;
}

function hostNamePart(x)
{
	var i = x.host.indexOf(":");
	
	return (i >= 0) ? x.host.substring(0,i) : x.host;
}

function protocolPart(x)
{
	var y = x.protocol;
	var i = y.indexOf(":");
	
	return (i >= 0) ? y : y + ":";
}

function pathNamePart(x)
{
	var y = x.pathname;
	var i = y.indexOf("/");
	
	return (i == 0) ? y : "/" + y;
}

function domainRegEx(v)
{
	return new RegExp(regExString(v), "i");
}

function replaceSubstring(e, _x, _y, _z)
{
	i = 0;
	while(e.indexOf(_x) >= 0)
	{
		i++;
		e = e.replace(_y, _z);
		
		if(i > 50)
			break;
	}
	
	return e;
}

function regExString(e)
{
	e = replaceSubstring(e, " ", " ", "");
	e = replaceSubstring(e, "\*\.", "\\*\\.", "\*");
	e = replaceSubstring(e, ",\*", ",\\*", "|");
	e = replaceSubstring(e, "*", "*", "");
	e = replaceSubstring(e, ",", ",", "|^");
	e = replaceSubstring(e, ".", "\\.", ";");
	e = replaceSubstring(e, ";", ";", "\\.");
	
	return e;
}

function handleExitLinks(x)
{
	if(hostNamePart(location) == hostNamePart(x))
		return true;
	
	var pt =(typeof oDOMAINS != sUD) ? domainRegEx(oDOMAINS) : domainRegEx(hostNamePart(location));
	a = (oACTION == '') ? "" : "&x=" + escape(oACTION);
	xa = (oAMOUNT == '') ? "" : "&xa=" + escape(oAMOUNT);
	ln = escape(x.href);
	
	if(pt.test(hostNamePart(x)))
		return true;

	setSessionIDs()
		
	if(bNet)
		setTimeout("oImg.src=sStem+xa+a+\"&el=\"+ln+\"&u=\"+u+\"&s=\"+s+\"&st=\"+st;", 1);
	else 
		oImg.src = sStem + xa + a + '&el=' + ln + '&u=' + u + '&s=' + s + '&st=' + st;
		
	return true;
}

function handleOnClick(x) // exit links
{
	var rv = true;
	if(x.onCk)
		rv = x.onCk();
		
	fn = fileNamePart(x.pathname);
	
	if(fn != "")
	{
		var pt = new RegExp("\\..?html?|\\.asp|\\.cfm|\\.jsp|\\.cgi|\\.php[3-4]?|\\.pl|\\.taf|\\.tml|\\.dll|\\.vm|\\.mv|jsessionid","i");
		
		if((!pt.test(fn)) && (fn.indexOf(".") != -1))
		{
			if(((oExcl.length > 0) && (!domainRegEx(oExcl).test(x.pathname))) || (oExcl.length == 0))
			{
				a = (oACTION == '') ? "" : "&x=" + escape(oACTION);
				xa = (oAMOUNT == '') ? "" : "&xa=" + escape(oAMOUNT);
				fn = protocolPart(x) + "//" + hostNamePart(x) + pathNamePart(x);
				
				setSessionIDs()
				
				if(bNet)
					setTimeout("oImg.src=sStem+xa+a+\"&fn=\"+escape(fn)+\"&u=\"+escape(u)+\"&s=\"+escape(s)+\"&st=\"+escape(st);", 1);
				
				else 
					oImg.src = sStem + xa + a + "&fn=" + escape(fn) + "&u=" + escape(u) + "&s=" + escape(s) + "&st=" + escape(st);
			}
		}
		else 
			handleExitLinks(x);
			
	}
	else 
		handleExitLinks(x);
	
	return rv;
}

function handleOnLoad()
{
	if(sOLT)
		onLd();
	
	var ln = document.links.length;
	
	for(var i = 0; i < ln; i++)
	{
		if(document.links[i].onclick)
			document.links[i].onCk = document.links[i].onclick;
			eval("document.links[i].onclick=function(){return handleOnClick(this);}");
	}
}

function handleError()
{
	handleReferrer(false);
	
	return true;
}

function handleReferrer(_d)
{
	if (cookies_Enabled()) { // only track if cookies are enabled
		t = "";
		r = document.referrer;
		p = filePathPart(document.location);
		q = document.location.search;
		
		if (q.length > 0)
		{
			p += q;
		}
		
		bc = navigator.cookieEnabled; 
		nua = navigator.userAgent; 

		
		if((navigator.userAgent.indexOf('Mac') >= 0) && (navigator.userAgent.indexOf('MSIE 4') >= 0))
			r = document.referrer;
		else if(_d)
		{
			window.e = window.onerror;
			window.onerror = handleError;
			
			if(document.location != top.location)
			{
				r = top.document.referrer;
				t = top.location.href;
			}
		}
		else 
			sQS += "&nr=t";
		
		window.onerror = window.e;
		
		if(r.length > 0)
			sQS += "&e=" + escape(r);
			
		if(t.length > 0)
			sQS += "&t=" + escape(t);
			
		if(p.length > 0)
			sQS += "&p=" + escape(p);
			
		if(q.length > 0)
			sQS += "&q=" + escape(q);
			
		if(bc.length > 0)
			sQS += "&bc=" + escape(bc);
			
		if(nua.length > 0)
			sQS += "&nua=" + escape(nua);
			
			
		sStem += "&f=" + escape(document.location);
		document.cookie = "itc=t";
		sQS += "&g=" + escape(bNet ? navigator.language : navigator.userLanguage);
		sQS += "&h=" + escape((navigator.javaEnabled() ? 'Y' : 'N'));
		sQS += "&j=" + escape(screen.width + 'x' + screen.height);
		sQS += "&k=" + escape((bMS) ? screen.colorDepth : screen.pixelDepth);
		sQS += "&l=" + ((document.cookie.indexOf("itc=") >= 0) ? "true" : "false");
			
		setSessionIDs()
		
		sQS += "&u=" + escape(u);
		sQS += "&s=" + escape(s);
		sQS += "&st=" + escape(st);
		
		
		oImg.src = sStem + sQS;
		
		//alert("test | " + oImg.src)
			
		if(!bNet || (parseInt(navigator.appVersion) < 5))
			document.write("<\!--");
	}
}

function setSessionIDs()
{
	if(get_Cookie("webanalytics-unique") != null)
	{
		if (unescape(get_Cookie("webanalytics-unique")) != "") // ensure unique IS a value
		{
			u = unescape(get_Cookie("webanalytics-unique"));
			
			if(get_Cookie("webanalytics-session") != null)
			{
				if(unescape(get_Cookie("webanalytics-session")) != "")
				{
					s = unescape(get_Cookie("webanalytics-session"));
				}
				else // session is an empty string 
				{
					// create new guid
					guid = "{"; 
					for (var i = 1; i <= 32; i++) 
					{ 
						var n = Math.floor(Math.random() * 16.0).toString(16); 
						guid += n; 
						if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) 
							guid += "-"; 
					} 
					guid += "}"; 
					
					//set_Cookie(name, value, expires, path, domain, secure)
					set_Cookie("webanalytics-session", guid, "", "/");
					
					s = guid;
				}
				st = "True";
			}
			else // if session cookie is null
			{
				// create new guid
				guid = "{"; 
				for (var i = 1; i <= 32; i++) 
				{ 
					var n = Math.floor(Math.random() * 16.0).toString(16); 
					guid += n; 
					if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) 
						guid += "-"; 
				} 
				guid += "}"; 
				
				//set_Cookie(name, value, expires, path, domain, secure)
				set_Cookie("webanalytics-session", guid, "", "/");
				
				s = guid;
			}
		}
		else // if unique is an empty string
		{
			// treat as a brand new unique - create new guid and use for both unique and session
			guid = "{"; 
			for (var i = 1; i <= 32; i++) 
			{ 
				var n = Math.floor(Math.random() * 16.0).toString(16); 
				guid += n; 
				if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) 
					guid += "-"; 
			} 
			guid += "}"; 
			
			var exDate = new Date();
			var year = exDate.getFullYear();
			exDate.setUTCFullYear(year + 1);
			
			//set_Cookie(name, value, expires, path, domain, secure)
			set_Cookie ('webanalytics-unique', escape(guid), exDate, "/");
			set_Cookie ('webanalytics-session', escape(guid), "", "/");
			
			u = guid;
			s = guid;
		}
	}
	else // if unique cookie is null
	{
		// create new guid and use for both unique and session
		guid = "{"; 
		for (var i = 1; i <= 32; i++) 
		{ 
			var n = Math.floor(Math.random() * 16.0).toString(16); 
			guid += n; 
			if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) 
				guid += "-"; 
		} 
		guid += "}"; 
		
		var exDate = new Date();
		var year = exDate.getFullYear();
		exDate.setUTCFullYear(year + 1);
		
		//set_Cookie(name, value, expires, path, domain, secure)
		set_Cookie ('webanalytics-unique', escape(guid), exDate, "/");
		set_Cookie ('webanalytics-session', escape(guid), "", "/");
		
		u = guid;
		s = guid;
	}
}
		
function cookies_Enabled () 
{		
	set_Cookie('webevents-cookietest', '1', "", "/");
	if(get_Cookie('webevents-cookietest') != null)
	{
		return true;
	} 
	return false;				
}

function get_Cookie(cookieName) 
{
	var theCookie = "" + document.cookie;
	var ind = theCookie.indexOf(cookieName);
	if (ind == -1 || cookieName == "") 
		return null;
		
	var ind1 = theCookie.indexOf(';',ind);
	if (ind1 == -1) 
		ind1 = theCookie.length;
		
	return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
}
	
function set_Cookie(name, value, expires, path, domain, secure) 
{
	var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");

	document.cookie = curCookie;
}

// end functions