function doCounter() {	
	var newuser = 1;
	
	
	var cookieval = readCookie('counterCookie');
	
	var hfName = "hits"
	
	if (cookieval != null)
	{
		newuser = 0;
	}
	else
	{
		createCookie('counterCookie',1,30);
		//prevents it being null next time
	}
	
	//document.write("newuser = " + newuser);
	
	document.write("<img src='updateCounter.asp?hitsfile=" + hfName + "&newuser=" + newuser + "' style='display:none'>");
	
	
	readTextFile(hfName + ".txt");
	
	//showCounter();
}

function getXmlHttpRequestObject() {

				if (window.XMLHttpRequest) {
					//alert("XML");
					return new XMLHttpRequest(); //Not IE
				} else if(window.ActiveXObject) {
					//alert("ActiveX");
					return new ActiveXObject("Microsoft.XMLHTTP"); //IE
				} else {
					//alert("Your browser doesn't support the XmlHttpRequest object.");
				}

			}

function readTextFile(gotFile) {
	//alert("read '" + tfName + "'");
	// create a request object
	var Req = getXmlHttpRequestObject();		
	var OSR = "";					 
					 
	// now  get the txt file
					
	var right_now = new Date();
	//right_now ensures we load the most recent update of this file
					
	//var toOpen = "http://www.gjwcarsaig.co.uk/" + gotFile
	var toOpen = gotFile + "?" + right_now.getTime();
	
	//alert(toOpen);
	
	Req.open("GET", toOpen, true);
	
	Req.onreadystatechange = function() {
		// readyState is 4 when the resource is completely loaded
						
		if (Req.readyState == 4) {
			
			//alert(Req.status);
			
			if (Req.status == 200) {
				OSR = Req.responseText;
				
				//alert(OSR);
				
				gLines = OSR.split(":");
				
				ttlHits = gLines[1].split(" ");
				
				//alert("OSR = " + OSR);
				//alert("'" + ttlHits[1] + "'");
				
				unqHits = gLines[2].split(" ");
				//alert("'" + unqHits[1] + "'");
				
				showCounter(ttlHits[1],1);
				
				if (showUnique == 1){
					showCounter(unqHits[1],2);
				}
			}
		}		
	} 
		
	Req.send(null);
		
		//alert(outputString);
		
		//return outputString;
}					

function showCounter(hits,digSet){
	
	var hdiv = hits;
	var digit;
	var i;
	var digits = [];
	
	for (i=0;i<5;i++)
	{
		digit = (hdiv % 10);
		//alert("digit = " + digit);
		digits[5-i] = digit;
		hdiv = parseInt(hdiv/10);
		
		if (digSet == 1) {digID = document.getElementById("digit_t" + (5-i));}
		if (digSet == 2) {digID = document.getElementById("digit_u" + (5-i));}
		
		digID.src = "images/digits/" + counterStyle + digit + ".gif";
	}
}
