// awstats_misc_tracker.js
// modified to remove checking for all the java, flash etc
// and also to not load the image again if the session cookie is set (FF
// loads the image on every page load and doesn't cache it)
//
// This allows AWStats to be enhanced with some miscellanous features:
// - Screen size detection (TRKscreen)
// - Browser size detection (TRKwinsize)
// - Screen color depth detection (TRKcdi)

var awstatsmisctrackerurl="/js/awstats_misc_tracker.js";

function awstats_setCookie(TRKNameOfCookie, TRKvalue, TRKexpirehours) {
	var TRKExpireDate = new Date ();
  	TRKExpireDate.setTime(TRKExpireDate.getTime() + (TRKexpirehours * 3600 * 1000));
  	document.cookie = TRKNameOfCookie + "=" + escape(TRKvalue) + "; path=/" + ((TRKexpirehours == null) ? "" : "; expires=" + TRKExpireDate.toGMTString());
}

function awstats_getCookie(TRKNameOfCookie){
	if (document.cookie.length > 0){
		var TRKbegin = document.cookie.indexOf(TRKNameOfCookie+"=");
	    if (TRKbegin != -1) {
			TRKbegin += TRKNameOfCookie.length+1; 
			TRKend = document.cookie.indexOf(";", TRKbegin);
			if (TRKend == -1) TRKend = document.cookie.length;
    	  	return unescape(document.cookie.substring(TRKbegin, TRKend));
		}
		return null; 
  	}
	return null; 
}

if (window.location.search == "" || window.location.search == "?") {
	
    // If no query string
	var TRKnow = new Date();
	var TRKscreen=screen.width+"x"+screen.height;
	if (navigator.appName != "Netscape") { TRKcdi=screen.colorDepth; }
	else {TRKcdi=screen.pixelDepth};
	var TRKuserid=awstats_getCookie("AWSUSER_ID");
	
	var show_image = true;
	var TRKsessionid=awstats_getCookie("AWSSESSION_ID");
	if(TRKsessionid) {
		show_image = false;
	}
	
	var TRKrandomnumber=Math.floor(Math.random()*10000);
	if (TRKuserid == null || (TRKuserid=="")) { TRKuserid = "awsuser_id" + TRKnow.getTime() +"r"+ TRKrandomnumber; }
	if (TRKsessionid == null || (TRKsessionid=="")) { TRKsessionid = "awssession_id" + TRKnow.getTime() +"r"+ TRKrandomnumber; }
	
	awstats_setCookie("AWSUSER_ID", TRKuserid, 10000);
	awstats_setCookie("AWSSESSION_ID", TRKsessionid, 1);
	TRKuserid=""; TRKuserid=awstats_getCookie("AWSUSER_ID");
	TRKsessionid=""; TRKsessionid=awstats_getCookie("AWSSESSION_ID");

	if(TRKsessionid == null) {
		// if we don't have a cookie value here then cookies are off
		// if cookies are off then don't bother showing the image because
		// this visitor may track on each page which will throw the stats out
		show_image = false;
	}
	
	if(show_image) {
	
		var TRKagt=navigator.userAgent.toLowerCase();
		var TRKie  = (TRKagt.indexOf("msie") != -1);
		var TRKns  = (navigator.appName.indexOf("Netscape") != -1);
		var TRKwin = ((TRKagt.indexOf("win")!=-1) || (TRKagt.indexOf("32bit")!=-1));
		var TRKmac = (TRKagt.indexOf("mac")!=-1);
	
	    // Detect the browser internal width and height
	    var TRKwinsize;
	    if (document.documentElement && document.documentElement.clientWidth)
	        TRKwinsize = document.documentElement.clientWidth + 'x' + document.documentElement.clientHeight;
	    else if (document.body && document.body.clientWidth)
	        TRKwinsize = document.body.clientWidth + 'x' + document.body.clientHeight;
	    else
	        TRKwinsize = window.innerWidth + 'x' + window.innerHeight;
		
		//var imgsrc = awstatsmisctrackerurl+'?screen='+TRKscreen+'&win='+TRKwinsize+'&cdi='+TRKcdi+'&java='+TRKjava+'&shk='+TRKshk+'&fla='+TRKfla+'&rp='+TRKrp+'&mov='+TRKmov+'&wma='+TRKwma+'&pdf='+TRKpdf+'&uid='+TRKuserid+'&sid='+TRKsessionid;
		var imgsrc = awstatsmisctrackerurl+'?screen='+TRKscreen+'&win='+TRKwinsize+'&cdi='+TRKcdi+'&uid='+TRKuserid+'&sid='+TRKsessionid;
		if( document.createElementNS ) {
	    	var l=document.createElementNS("http://www.w3.org/1999/xhtml","img");
	        l.setAttribute("src", imgsrc );
	        l.setAttribute("height", "0");
	        l.setAttribute("width", "0");
	        l.setAttribute("border", "0");
	        document.getElementsByTagName("body")[0].appendChild(l);
		} else {
			document.write('<img style="display:none;" src="'+ imgsrc +'" height="0" width="0" border="0" />')
		}

	}
		
}
