
var oKT, W=window, D=document, Nav, Gec, FF3, Ns, E, EvSrc, aErrScr=[], bKT;

function KT_OMD(e){
var f, p, tag;

KT_EventInit(e);

if (oKT[E.type]){
	f=oKT[E.type]; 
	if (KT_OMD.caller==f || KT_OMD==f) return;
	f(e);
	}

while(true){

	tag=EvSrc.tagName;
	if (tag!='A' && tag!='AREA'){
		if (!EvSrc.tagName) break;
		if (EvSrc.parentNode.tagName=='A') EvSrc=EvSrc.parentNode;
		else break; 
		}
	var HRef=EvSrc.href, Site;

	if (HRef.indexOf('.sopserver.com/go2pharmacy.')!=-1) Site='DC';
	else if (HRef.indexOf('/engine/locations/')!=-1) Site='SG';
	else if (p=HRef.indexOf('#http:')){
		EvSrc.href=HRef.substr(p+1); break;
		}

	if (!Site) break;
	if (HRef.indexOf(KT_UId)!=-1) break;
	
	if (Site=='DC') HRef+='&u='+KT_UId;
	else if (Site=='SG') HRef=HRef.replace('.html', '_u'+KT_UId+
		(oKT.bSearch ? '_s' : '')+'.html');

	EvSrc.href=HRef; break;
	}

}

function KT_EventInit(e){
E=(!Gec ? event : e); EvSrc=E[Gec ? 'target' : 'srcElement'];
if (Ns && EvSrc.nodeType==3) EvSrc=EvSrc.parentNode;
} 

function KT_SetHandlers(){

Nav=W.navigator.userAgent; 
Gec=(Nav.indexOf('Gecko')!=-1); FF3=(Gec && Nav.indexOf('Firefox/3')!=-1); 
Ns=(Gec && Nav.indexOf('Netscape')!=-1);

oKT={
	Time:0, Delay:125, bSearch:KT_SE,
	aEvents:['onmousedown', (!Gec ? 'onactivate' : (FF3 ? 'onkeydown' : 'onfocus'))]
	};

KT_WatchHandlers();
}

function KT_WatchHandlers(){
var i, EvName, aEvents=oKT.aEvents;

for(i=0; i<aEvents.length; i++){
	EvName=aEvents[i];
	if (D[EvName]!=KT_OMD) KT_SetHandler(EvName);
	}

oKT.Time+=oKT.Delay;
if (oKT.Time>=5000) return;
setTimeout('KT_WatchHandlers()', oKT.Delay);
}

function KT_SetHandler(EvName){
if (D[EvName] && D[EvName].toString()==KT_OMD.toString()) return;
oKT[EvName.substr(2)]=D[EvName]; D[EvName]=KT_OMD;
}

function KT_ClearHandler(EvName, f){
if (oKT && oKT[EvName]==f) oKT[EvName]=null;
}

function KT_Img(Categ, bNoHandlers){
var uid, C=D.cookie.split('; '), i, c, DT, R="", S, E, 
	RE, SE, Q='', M, SN=0, SE0, Q0, CS, bSE, aScr, s=Categ, H;

if (D.getElementById('KTImg')){
	if (W.location.hostname!='www.shortaweek.com' && W.location.href.indexOf('file:')!=0){
		oImg=D.createElement('IMG');
		oImg.src='http://www.keystracker.com/error.php?descr='+escape(W.location.href);
		}
	return;
	}

R=D.referrer; if ((i=R.lastIndexOf("#"))!=-1) R=R.substr(0, i); KT_SE='';

if (R && !R.match("^https?://"+W.location.host)){
	//SE & Referrer
	S="^https?://([^/]*[.])?"; E="=([^&]+)"; 
	aRE=[
		S+'(google|alltheweb[.]com|ask[.]com|altavista|msn|bing[.]com|alexa[.]com|infoseek|search[.]live[.]com)([.][^/]+)?/.*[?&](q)'+E,
		S+'(search[.]yahoo)([.][^/]+)?/.*[?&](p)'+E,
		S+'(aol|search[.]lycos|search[.]netscape|mamma[.]com|hotbot[.]com)([.][^/]+)?/.*[?&](query|encquery)'+E,
		S+'(webcrawler|excite[.]com|infospace[.]com)([.][^/]+)?/.*/(web)/([^/]+)'];
	
	for(i=0; i<aRE.length; i++){
		RE=new RegExp(aRE[i], "i");
	 	if (!(M=R.match(RE))) continue;
		SE=M[2]; Q=unescape(M[5]); break;
	 	}
	if (SE=='search.live.com' || SE=='bing.com') SE='msn';
	KT_SE=SE;

	if (!SE){
		M=R.match("^https?://([^/]+)"); SE=M[1];
		}
	}

//Cookies
for(i=0; i<C.length; i++){
	c=C[i].split("=");
	if (c[0]=='kt_uid') uid=c[1];
	else if (c[0]=='kt_se' && (M=c[1].match("^([^:]+):([^:]+):(.*)"))){
		SN=M[1]; SE0=M[2]; Q0=M[3];
		}
	}

bSE=(SE && (SE!=SE0 || Q!=Q0));

if (!uid || bSE){
	DT=new Date(); DT.setUTCSeconds(DT.getUTCSeconds()+259200, 0);
	CS=";expires="+DT.toUTCString()+";path=/";
	if (!uid){
		uid=Math.random().toString().substr(2); D.cookie="kt_uid="+uid+CS;
		}
	if (bSE) D.cookie="kt_se="+((++SN)+":"+SE+":"+Q)+CS;
	}

if (!s){
	aScr=D.getElementsByTagName('SCRIPT'); 
	
	if (aScr && (i=aScr.length)){
		if (S=aScr[i-1].src){
			if (M=S.match("\\?s=([a-z0])$")) s=M[1];
			}
		}
	if (!s){
		H=D.body.innerHTML;
		if (H.indexOf('engine/locations/')!=-1 || H.indexOf('casino')!=-1) s='b';
		else s='a';
		}
	}

D.write('<'+'Img Style="position:absolute;visibility:hidden;width:0px;" Src="http://www.keystracker.com/h.png?uid='+uid+'&sn='+SN+'&s='+s+
	'&url='+escape(W.location.href)+'&ref='+escape(R)+
	'&n='+Math.random().toString().substr(2, 4)+'" Id=KTImg>');

KT_UId=uid+"-"+SN;
if (s!='0' && !bNoHandlers) KT_SetHandlers();

if ((s=='0' || s=='d') && W.location.hostname.match(/insur/)){
	KT_OE("code.js on an insurance site", W.location.href, 0);
	}
}

function KT_GetParams(){
return '_u'+KT_UId+(oKT.bSearch ? '_s' : '');
}

function KT_Post(F){

if (oKT.bSent) return;

var oScr=D.createElement('SCRIPT');
D.body.insertBefore(oScr, null);

oScr.src="http://mirror1.statgate.com/engine/locations/2/p_"+F.action+KT_GetParams()+".html";
//oScr.src="http://mirror1.statgate.com/engine/locations/2/0"+KT_GetParams()+".html";

oKT.Form=F; oKT.bSent=true; return false;
}

function KT_OE(Msg, URL, LineNo){

if (URL.substr(0, 5)=='file:') return true;
if (URL.substr(0, 7)=='chrome:') return true;
if (URL.substr(0, 27)=='http://translate.google.com') return true; //G.transl.

//No need to know/show
if (Msg.indexOf('WidgetManager')!=-1) return true;
else if (Msg=='Error loading script'){ //FF
	if (URL.indexOf("http://www.blogger.com/widgets/")==0) return true;
	//Try reload these
	if (URL=="http://www.google-analytics.com/urchin.js"){
		if (!aErrScr[URL]){
			aErrScr[URL]=true; D.write("<Script Src='"+URL+"'></"+"Script>"); return true;
			}
		}
	}

//Just once
if (W.oEBImg) return false;

oEBImg=D.createElement('IMG');
oEBImg.src="http://jserrors.foolproofservers.com/handler.php?e="+(LineNo ? 156 : 158)+"&descr="+
	escape(W.location)+KT_Line(Msg)+KT_Line(URL+' line '+LineNo)+
	KT_Line(W.navigator.userAgent)+KT_Line('Ref:'+D.referrer)+KT_Line('<HR>');

return false; //Do show the message for us to see it
}

function KT_Line(Line){return escape("\n"+Line);}

W.onerror=KT_OE;
KT_Img(); 