<!--
/*
 * Just read the comments below, what to change other than that you wont need to change anything else
 * and its open for future updates.
 * You may also consider adding <noscript><?php echo include("getusers"); ?><noscript>
 * Incase the client doesn't have Javascript, and it will just put the static value on.
 */

var xmlhttp;
var elementID;
var fileurl;

String.prototype.getSearchVar = function(p){
    return (match = this.match(new RegExp("[?|&]?" + p + "=([^&]*)"))) ? match[1] : false;
}


/*
 * This is the only part you MAY need to change.
 * See the switch statement, the cases are what page=
 * for the first one, home, it will edit the tag with the id onlineu
 * and parse the file named getusers.php
 * Just change the downloads one for the applicable downloads page
 */
function updateTimer() {
  var pageref=location.search.getSearchVar("page");
  switch(pageref) {
case "home":
    elementID="onlineu";
    fileurl="js/getusers.php";
    updateUsers();
    t=setTimeout("updateTimer()",3000);
    break;
case "downloads":
    elementID="downloadc";
    fileurl="js/getdownloads.php";
    updateUsers();
    t=setTimeout("updateTimer()",3000);
    break;
case false:
    elementID="onlineu";
    fileurl="js/getusers.php";
    updateUsers();
    t=setTimeout("updateTimer()",3000);
    break;
  }
}

function updateUsers() {
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null) {
    document.getElementById(elementID).innerHTML="AJAX Error";
    return;
  }
  var url=fileurl;
  url=url+"?rid="+Math.random();
  xmlhttp.onreadystatechange=stateChanged;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}

function stateChanged() {
  if (xmlhttp.readyState==4) {
    document.getElementById(elementID).innerHTML=xmlhttp.responseText;
  }
}

function GetXmlHttpObject() {
  if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
  }
  if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  return null;
}

// Call it
updateTimer();
//-->
