function pullVar(k,str,delim) {
return ((idx=str.indexOf(k+'='))==-1)? '' : str.substring((idx+(k.length+1)),(((edx=str.indexOf(delim,idx))!=-1)?edx:str.length));
}
function cMgr() {
this.cdays=30;
this.exdt = function() { return new Date( new Date().valueOf() + ( this.cdays*86400000 ) ).toGMTString(); }
this.cset = function(k,v) {	document.cookie=k+'='+v+';path=/;expires='+this.exdt()+';';	return true; }
this.cget = function(k) {	return pullVar(k,document.cookie,';'); }
}
function tpng() {
var im="http://stats.swirlclient.com/tpx3/tpx3-1.php",
	dc = document,
	dr = dc.referrer,
	ud = 'undefined',
	hn = location.hostName,
	qs = location.search,
	ky = (typeof(campaignKey) != ud) ? campaignKey : '';
	rd = Math.random().toString().substring(2,10) + new Date().getTime().toString(),
	rf = ( (dr.length) && (typeof(dr) !=ud) && ( ( dr.indexOf(hn) == -1 ) || ( dr.indexOf(hn) > (hn.length) ) ) ) ? escape(dr) : '',
	sc = (typeof(tpxsc) != ud) ? tpxsc : pullVar('tpxsc',qs,'&'),
	ck = new cMgr();ck.cdays=90,
	ct = ((i = ck.cget('CT_'+ky)) ? ++i : 1),
	ck.cset('CT_'+ky,ct);
var pg,uq,iq,ev,sc1,sc2,sc3;
if ( !( uq=ck.cget('UQ') ) ) { uq='u'+rd;ck.cset('UQ',uq); }
pg = escape( location.pathname );
ev = ( arguments.length ) ? escape( arguments[0] ) : '';
	//pg  = ( arguments[0].substring(0,0) == '/' ) ? ev : pg + '/' + ev;

iq = '?pg=' + pg + '&rf=' + rf + '&uq=' + uq + '&ct=' + ct + '&rnd=' + rd;
if(ev) { iq+='&ev=' + ev; }
if(qs) { iq+='&qs=' + escape(qs); }
if( sc ) { 
	if(!(sc1=ck.cget('SC1'))) ck.cset('SC1',sc);
	if(ck.cget('SC2')!=sc) { ck.cset('SC2',sc); ck.cset('SC3',(ck.cget('SC3'))+'&'+sc); }
	iq+='&sc='+ escape(sc); 
}
iq+='&up='+ escape(ck.cget('SC3')); 
if (ky) { iq+='&c=' + ky; }

dc.tpngpx = new Image();
dc.tpngpx.src = im+iq;
}
function dump(s){
	//return();
}
(function() {
		try {
			var oldonload;
			if ( ( 'onload' in window ) && typeof window.onload == 'function' ) oldonload = window.onload;
			
			window.onload = function() 
			{
				try {
					tpng();
					if ( oldonload ) oldonload();
					//console.log('tpx3 loaded, tracking campaign ' + campaignKey );
				} 
				catch (ex) { //console.error
					dump('(tpx3.js) window.onload error: ' + ex.message); }
			}
			
		} catch (ex) { //console.error
			dump('(tpx3.js) could not hook onto window onload: ' + ex.message); }
})();
