function getHitCounterAjax() {
    makeRequest("../Scripts/hitcounterajax.php") ;
}
function getPageCounterAjax(pageurl) {
    makeRequest("../Scripts/hitcounterajax.php?url="+pageurl) ;
}
function processAjaxReply( returnedtext ) {
   // alert(returnedtext) ; // DEBUG (super annoying!)
   var re = /_(\d+)_/ ;
   var n ;
   n = returnedtext.match(re)[1] ;
   document.getElementById('hitcount').textContent = n ;
   // sleep then call getHitCounterAjax again ..
   setTimeout("getHitCounterAjax()", 3000 ) ;
}


// code copied from http://developer.mozilla.org/en/docs/AJAX:Getting_Started

function makeRequest(url) {
   var httpRequest;

   if (window.XMLHttpRequest) { // Mozilla, Safari, ...
      httpRequest = new XMLHttpRequest();
      if (httpRequest.overrideMimeType) {
         httpRequest.overrideMimeType('text/xml');
         // See note below about this line
      }
    }
    else if (window.ActiveXObject) { // IE
       try {
          httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
       }
       catch (e) {
          try {
             httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch (e) {}
       }
   }

   if (!httpRequest) {
       alert('Giving up :( Cannot create an XMLHTTP instance');
       return false;
   }
   httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
   httpRequest.open('GET', url, true);
   httpRequest.send(null);
}

function alertContents(httpRequest) {
   if (httpRequest.readyState == 4) {
      if (httpRequest.status == 200) {
        processAjaxReply( httpRequest.responseText ) ;
        // alert(httpRequest.responseText);
      } else {
         alert('There was a problem with the request.');
      }
   }
}