//////////////////////////////////////////////////
//Start the hit updates right here!!
//updateHits(); // I have turned this feature off for now...
//////////////////////////////////////////////////

var req;

function updateHits()
{
    url = 'http://mlsstudios.com/ajax/script.php';
	  
    loadXMLDoc(url);
	
	// recursive function call that has a delay of 3 seconds
	ID=window.setTimeout("updateHits();", 3000);
}

function loadXMLDoc(url) 
{
	//var req;
	
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
		
		req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }

}

var current_hits = 0;

function processReqChange() 
{
	//alert('got here');

    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
			
			//alert('got here NOW');
			
            // ...processing statements go here...
      response  = req.responseXML.documentElement;

      method    = response.getElementsByTagName('method')[0].firstChild.data;

      hits    = response.getElementsByTagName('result')[0].firstChild.data;
	  
	  var mdiv = document.getElementById("the_counter");
	  //mdiv.innerHTML = "<div style=\"color:blue\">" + method + ": " + hits + "</ div>";
	  mdiv.innerHTML = hits;

	//alert(hits);

	if(hits > current_hits) {
		//new Effect.Appear("the_counter");
		current_hits = hits;
	}

        } else {
            //alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}
