var xmlhttp_people;
var xmlhttp_ads;

function getstat_people(){
xmlhttp_people=GetXmlHttpObject();
var url="test_get_people.php";
url=url+"?sid="+Math.random();
xmlhttp_people.onreadystatechange=stateChanged_people;
xmlhttp_people.open("GET",url,true);
xmlhttp_people.send(null);
}

function getstat_ads(){
xmlhttp_ads=GetXmlHttpObject();
var url="test_get_ads.php";
url=url+"?sid="+Math.random();
xmlhttp_ads.onreadystatechange=stateChanged_ads;
xmlhttp_ads.open("GET",url,true);
xmlhttp_ads.send(null);
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	x3 = x1 + x2;
	return x3;
}

function addCommas_1(nStr)
{
	nStr=parseFloat(nStr);
	nStr=nStr.toFixed(5);
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	x3 = x1 + x2;
	return x3;
}

function stateChanged_people()
{
if (xmlhttp_people.readyState==4)
{
document.getElementById("txtPeople").innerHTML=addCommas(xmlhttp_people.responseText);
}
}

function stateChanged_ads()
{
if (xmlhttp_ads.readyState==4)
{
document.getElementById("txtPeople").innerHTML=addCommas(xmlhttp_people.responseText);
document.getElementById("txtAds").innerHTML=addCommas(xmlhttp_ads.responseText);
document.getElementById("txtAvg").innerHTML=addCommas_1(xmlhttp_people.responseText/xmlhttp_ads.responseText);
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}


function showstat(){
getstat_people();
getstat_ads();
setTimeout("showstat()",6800);
}
