//HitList

function hl_tag()
{

//this needs to be changed to the location of the server where
//the tag logging is to occur
var hl_tagurl='http://www.marcusevans.com/hitlist/HLTag.gif';

var hl_tagversion=1;

var hl_referrer=document.referrer;
var hl_domain=document.location.hostname;

//url won't always be useful if dynamically generated
var hl_url=document.location.pathname;
var hl_port=document.location.port;

//get universal time information for tag
var now = new Date();
var dMonth=String(now.getUTCMonth()+1);
var dDay=String(now.getUTCDate());
var dHours=String(now.getUTCHours());
var dMinutes=String(now.getUTCMinutes());
var dSeconds=String(now.getUTCSeconds());

if (dMonth.length==1) {dMonth='0'+dMonth};
if (dDay.length==1) {dDay='0'+dDay};
if (dHours.length==1) {dHours='0'+dHours};
if (dMinutes.length==1) {dMinutes='0'+dMinutes};
if (dSeconds.length==1) {dSeconds='0'+dSeconds};

//we don't use the client time by default, but here is the format that would be passed in the application argument
//this is the standard format we like: yyyy-mm-dd hh:nn:ss
var hl_requestdate= String(now.getUTCFullYear())+'-'+dMonth+'-'+dDay+' '+dHours+':'+dMinutes+':'+dSeconds;
var hl_uniqueid = String(now.getTime());

//various unused default values (they could be appended as part of hl_query in parameter values)
//var hl_screenresolution=screen.width+'*'+screen.height;
//var hl_title=document.title;

//if you don't want to keep the original query values change this
var hl_query='';
if (document.location.search.length>0){hl_query=document.location.search.substring(1)};
if (hl_query.length==0) 
{hl_query=hl_meta().substring(1);}
else
{hl_query+=hl_meta();}

//this is a good place to implement a visitor cookie 
//we default to create a unique sessionid to make sure all tagged requests have a way to resolve the visit
//note:  if we aren't allowing cookies this won't affect anything...
var hl_sessionid=GetCookie("hl_sessionid");

if (hl_sessionid == null)
{

	hl_sessionid=NewSessionID();

	//set the cookie to expire at end of session for entire site
	SetCookie ("hl_sessionid", hl_sessionid, "", "/", "", false);
	

}

//note:  this variable passed in the query to HitList will override the cookie value passed in normal logging
//	 that means you could add information (if necessary) directly to the cookie by adding it to hl_cookie
var hl_cookie=document.cookie;


//this is the tagging information that will be sent
//note: by default we defer to the server time, but the client time may be passed by appending the hl_requestdate parameter
//      '&hl_requestdate='+HLescape(hl_requestdate)
var hl_tagsource=hl_tagurl+'?hl_tagversion='+hl_tagversion+'&hl_uniqueid='+hl_uniqueid+'&hl_domain='+HLescape(hl_domain)+'&hl_url='+HLescape(hl_url)+'&hl_port='+hl_port+'&hl_query='+HLescape(hl_query)+'&hl_referrer='+HLescape(hl_referrer)+'&hl_cookie='+HLescape(hl_cookie);

//send the tagging information by loading 1x1 gif
hl_tag=new Image();
hl_tag.src=hl_tagsource;

}

function hl_meta(){
var hl_elements;
var hl_metaquery='';
if (document.all){
hl_elements=document.all.tags("meta");
}
else if (document.documentElement){
hl_elements=document.getElementsByTagName("meta");
}
if (typeof(hl_elements)!="undefined"){
	for (var i=1;i<=hl_elements.length;i++){
		var hl_meta=hl_elements.item(i-1);
		if (hl_meta.name)
		{
			if (hl_meta.name.indexOf('HL.')==0)
			{
				hl_metaquery+='&'+hl_meta.name.substring(3)+'='+hl_meta.content;
			}
		}
	}
}
return(hl_metaquery);
}

function NewSessionID() 
{
	var TodaysDate=new Date();
	var newid = Math.floor(999999*Math.random()+1)+"-"+TodaysDate.getFullYear()+(TodaysDate.getMonth()+1)+TodaysDate.getDate()+TodaysDate.getHours()+TodaysDate.getMinutes()+TodaysDate.getSeconds(); 
	return newid;
}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i=0;  
	while (i < clen) {    
	var j = i + alen;    
	if (document.cookie.substring(i, j) == arg)      
		return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function SetCookie (name, value, expires, path, domain, secure) {  

	document.cookie = name + "=" + escape (value) + 
	((expires == "") ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == "") ? "" : ("; path=" + path)) +  
	((domain == "") ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function HLescape(value)
{

	if (value != null)
	{
		//a little extra paranoia doesn't hurt, since we don't want the parameters to have bad character
		//that would cause problems parsing the values later
		value=escape(value);
		value = value.replace(/\//g,"%2F");	
		value = value.replace(/\?/g,"%3F");
     		value = value.replace(/=/g,"%3D");
     		value = value.replace(/&/g,"%26");
		value = value.replace(/@/g,"%40");
	}
	else
	{
		value="";
	}

	return value

}

hl_tag();