var msET_o = new Object();
msET_o.ev = [];					// event storer
msET_o.siteCode = 0;			// code for this website
msET_o.cId = "00000000";		// default cookie id
msET_o.ol = window.onload;		// put my load event after any of their load events
msET_o.baseUrl = "http://www.sendlo.com/tracker.php";
/*		
b = user id
c = target url
d = referring url (error message)
e = link text
f = link id
g = site id
*/
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
msET_o.setCookie = function (name, value, expires, path, domain, secure)
{
	try {
		document.cookie= name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
	}
	catch(err)
	{
		msET_o.logError("setCookie",err);
	}
}
msET_o.getCookie = function (name) {
	try {
		var dc = document.cookie;
		var prefix = name + "=";
		var begin = dc.indexOf("; " + prefix);
		if (begin == -1) {
			begin = dc.indexOf(prefix);
			if (begin != 0) return null;
		} else {
			begin += 2;
		}
		var end = document.cookie.indexOf(";", begin);
		if (end == -1) {
			end = dc.length;
		}
		return unescape(dc.substring(begin + prefix.length, end));
	}
	catch(err)
	{
		msET_o.logError("getCookie",err);
	}		
	return null;
}
msET_o.loadtracker = function ()
{
	try {
		// GET THE SITE CODE
		switch (location.hostname)
		{
		case "www.discountpetmedication.net":
			msET_o.siteCode = 1;
			break;
		case "www.pet-health-plan.com":
			msET_o.siteCode = 2;
			break;
		case "www.express-ebay.com":
			msET_o.siteCode = 3;
			break;
		case "www.affordablecostumes.com":
			msET_o.siteCode = 4;
			break;
		}
		var isDebug = (location.href.substr(-4,4)=="debg")?true:false;
		// SET OR READ COOKIE ID
		msET_o.cId = msET_o.getCookie("msET_cId");
		if(isDebug)
		{
			msET_o.cId = "10000001"; // log it, but mark it as debugging.
			msET_o.setCookie("msET_cId", msET_o.cId);
		}
		if(!msET_o.cId)
		{
			msET_o.cId=Math.floor(Math.random()*10000000)
			var dat = new Date();
			dat.setFullYear(3000);
			msET_o.setCookie("msET_cId", msET_o.cId, dat)
			msET_o.cId = msET_o.getCookie("msET_cId");
			if(!msET_o.cId)
			{
				msET_o.cId = "10000002"  // log it, but let us know the cookie cannot be set.
			}
		}

		addEvent = function(o, n, f, l)
		{
			var d = 'addEventListener', h = 'on' + n, t, a;
			if (!o.aE) { o.aE = msET_o.ev.length || 1; msET_o.ev[o.aE] = { o:o } }
			t = msET_o.ev[o.aE][n] || (msET_o.ev[o.aE][n] = []);
			t[t.length] = o[h] ? [o[h], f] : [f];
			o[h] = new Function('e', 'var r = true, i = 0, o = msET_o.ev[' + o.aE + '].o,' + 'a = msET_o.ev[' + o.aE + ']["' + n + '"][' + (t.length - 1) + '];' + 'for (; i < a.length; i++) { ' + 'o._f = a[i]; r = o._f(e||window.event) != false && r; o._f = null;' + '}; return r');
		};
		
		// TRACK THIS PAGE
		if (msET_o.cId != "10000001")
		{
			msET_o.trackclick(document.URL,document.referrer);

			// put my tracker event before any of their events
			var l=document.links;
			var h = location.protocol+"//"+location.hostname;
			var hlen = h.length;
			for(i=0;i<l.length;i++) {
				if(l[i].href.substring(0,hlen) != h) 
				{
					var oc = l[i].onclick;
					l[i].onclick = null;
					addEvent(l[i],'click',msET_o.trackclick);
					if(oc)addEvent(l[i],'click',oc);
				}
			}
		}
	}
	catch(err)
	{
		msET_o.logError("loadtracker",err);
	}
}
msET_o.logError = function (eCode,eText)
{
	msET_o.trackit("&b="+msET_o.cId+"&c="+escape(document.URL)+"&d="+escape("Err-"+eCode+"-"+eText)+"&e=&f=&g="+escape(msET_o.siteCode));
}
msET_o.trackit = function (imgPath)
{
	var img = new Image();
	var dat = new Date();
	img.src = msET_o.baseUrl + "?a=" + dat.valueOf() + imgPath;
	dat = null;
	img = null;
//	prompt("",imgPath);
}
msET_o.trackclick = function ()
{
	try 
	{
		var c="",d="",e="",f="";
		if(arguments.length > 1)  // the event passes a single argument, so check for 2
		{
			if (arguments[0])c=arguments[0];
			if (arguments[1])d=arguments[1];
		}
		else
		{
			c=this.href;
			d=document.URL;
			e=this.innerHTML;
			f=this.id;
		}
		if(c.substring(0,5) != "file:")
		{
			msET_o.trackit("&b="+msET_o.cId+"&c="+escape(c)+"&d="+escape(d)+"&e="+escape(e)+"&f="+escape(f)+"&g="+escape(msET_o.siteCode));
		}
	}
	catch(err)
	{
		msET_o.logError("trackclick",err);
	}		
}
window.onload=function (){var b=true;if(msET_o.ol)b=msET_o.ol();msET_o.loadtracker();return b;}