//<!-- Tracking Code v1.00 - All rights reserved -->

function hSetCookie(name,value,expires){var cookie_string=name+"="+escape(value);if(expires){expires=new Date(expires);cookie_string+=";expires="+expires.toGMTString();}document.cookie=cookie_string+";path=/";} 
function hGetCookie(cookie_name){var regexp=new RegExp(cookie_name +"=(.*?)(;|$)","i");var results=regexp.exec(document.cookie);if(results){return(unescape(results[1]));}else{return null;}} 
function hasSubKeys(cookieName){var ret=false;var cookie=unescape(hGetCookie(cookieName));var subKeys=cookie.split("&");if(subKeys.length>=2){ret=true;}else{var subKeys=cookie.split("=");if(subKeys.length>=1){ret=true;}}return ret;}

function DelCookie(cookie_name){var cookie_date=new Date();cookie_date.setTime(cookie_date.getTime()-1);document.cookie=cookie_name+="=;expires="+cookie_date.toGMTString()+";path=/";} 

function GetCookie(cookieName,keyName){
	var ret;
	var cookie=unescape(hGetCookie(cookieName));
	//alert(cookie);
	if(keyName && hasSubKeys(cookieName)==true){
		var cookieData=getCookieData(cookie);
		ret=cookieData[keyName];
	}else{
		ret=cookie;
	}
	return ret
}


function SetCookie(cookieName,keyName,value,expires){
	var thisCookie=unescape(hGetCookie(cookieName));
	if(thisCookie){
		if(keyName){
			//alert(keyName);
			var cookieData=getCookieData(thisCookie);
			cookieData[keyName]=value;
			value="";
			for (var cookie in cookieData){
				value +=cookie+"="+cookieData[cookie]+"&";
			}
			if(value.charAt(value.length-1)=="&"){value=value.substring(0,value.length-1)}
		}
	}
	//alert(cookieName+"\n"+value);
	hSetCookie(cookieName,value,expires);
}

function getCookieData(cookie){
	var ret=[];
	var subKeys=cookie.split("&");
	for (var i=0;i<subKeys.length;i++){
		//alert(subKeys[i]);
		var pos=subKeys[i].indexOf("=");
		if(pos!=0){
			//alert("cookieData["+subKeys[i].substring(0,pos)+']='+subKeys[i].substring(pos+1));
			ret[subKeys[i].substring(0,pos)]=subKeys[i].substring(pos+1);
		}
	}
	return ret;
}


function getClnUrl(u)
{var nonexc="_S_PEPOS,_S_PEPRM";if(typeof window._S_EXCLPRM==_UD) return u;
var u2=u.split('?');
if(u2.length==1) return u;
var p=u2[1].split('&');
var exc=window._S_EXCLPRM.split(',');
var r="";
for(k=0;k<p.length;k++){
     var pn=p[k].split('=')[0];
     var re=new RegExp("\\b"+pn+"\\b","gi");
     if((pn!="")&&((re.test(nonexc))||(!re.test(exc))))r+=p[k];}return u2[0]+((r.length>0)?"?"+r:"");
}

function _e()
{
	_rf(false);
	return true;
}
function _rf(_d)
	{
	//
	// FUNCTION: _rf
	//
	// When this routine is called the first time, _d = TRUE.  But there is a little recursion
	// going on and this routine calls itself.
		
		
	// t will hold the name of our current page top.location.href
	// r will hold the referrer
	//
	// 
	t="";
	r=document.referrer;
	
	// Okay, let the wierdness begin!
	//
	// If this is a Mac AND it is using MSIE
	if((navigator.userAgent.indexOf('Mac')>=0)&&(navigator.userAgent.indexOf('MSIE 4')>=0))
		// looks like this browser have child windows....
		r=document.referrer;
	else if(_d)
		{
		// Not a MAC with MSIE, so most other browsers go through here!
		//
		// window.onerror holds what the browser is supposed to do when it
		// encounters an error.  So we save that off
		window.e=window.onerror;
		//
		// Now we tell the browser what to do if it encounters any error!
		window.onerror=_e;
		
		// Now we can set out r and t variables...
		// I think on some browsers doing these next steps raises an error
		// And it think it is the referrer check.  Because if there is a
		// failure, then the _e function will be called, and the _rf routine
		// is called from the _e error routine with FALSE which means that
		// the else routine below add a &nr=t to signify that there is no
		// referrer.
		if(document.location!=top.location)
			{
			r=top.document.referrer;
			t=top.location.href;
			}
		}
	else
		// Okay, this only runs when _e does it's little recursive deal, so
		// we are adding this nr=t, which should be the url of this page
		IT+="&nr=t";

	// Set the error handler back to where it was
	window.onerror=window.e;
	
	//if r and t have something in them, add them to the IT line
	if(r.length>0)
		IT+="&SMTREFER="+escape(r);
	if(t.length>0)
		IT+="&SMTTOPDOC="+escape(t);
}

//Take care of Cookie and ID
var img=new Image();
var _UD="undefined", ENC="", URL="";
var BU='http://searchmarketingtools.com/statsave4.exe?a=22&';
var IT=""
var _d=new Date();

var udets=GetCookie("SMTstatbuilder");
if(!udets||udets==null||udets=='null'){
	var chararr="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	var newstring=""
	for(i=1;i<=10;i++)
	{
		newstring=newstring+chararr.charAt(Math.round(Math.random()*62)-1)
	}

	var cdata="ID="+newstring;
	SetCookie("SMTstatbuilder","",cdata);
	}

BU+=GetCookie("SMTstatbuilder");

//Encoding
if(typeof document.charset!=_UD)ENC=document.charset;
else if(typeof document.characterSet!=_UD)ENC=document.characterSet;
else if(typeof window._S_ENC!=_UD)ENC=window._S_ENC;
IT+="&enc="+ENC;
//Destination URL
URL=getClnUrl(document.URL?document.URL:document.location);
IT+="&SMTDURL="+URL;
// Add the language
var nan=navigator.appName;
var na=(nan=="Netscape");
var ns=(nan.substring(0,9)=="Microsoft");
IT+="&g="+escape(na?navigator.language:navigator.userLanguage);
// Java enabled
IT+="&h="+escape((navigator.javaEnabled()?'Y':'N'));
// screen resolution. 
IT+="&j="+escape(screen.width+'x'+screen.height);
// Colors
IT+="&k="+escape((ns)?screen.colorDepth:screen.pixelDepth);
//Parse JavaScript Form Fields
if(typeof SMTDOCUMENTGROUP!=_UD)BU+="&SMTDG="+escape(SMTDOCUMENTGROUP);
if(typeof SMTDOCUMENTNAME!=_UD)BU+="&SMTDN="+escape(SMTDOCUMENTNAME);
else if(document.title.length>0)BU+="&SMTDT="+escape(document.title);
if(typeof SMTMEMBERID!=_UD)BU+="&SMTMI="+escape(SMTMEMBERID);
if(typeof SMTACTION!=_UD)BU+="&SMTACTION="+escape(SMTACTION);
if(typeof SMTAMOUNT!=_UD)BU+="&SMTAMOUNT="+escape(SMTAMOUNT);
if(typeof SMTORDERID!=_UD)BU+="&SMTOID="+escape(SMTORDERID);
if(typeof SMTPRODUCTCODE!=_UD)BU+="&SMTPC="+escape(SMTPRODUCTCODE);
//Referrer
_rf(true);
img.src=BU+IT;

//<!-- End of Tracking Code -->
