

function ajaxFunction()
{
var xmlHttpCurCht;
var xmlHttpCurVal;
var xmlHttpCurDate;
var xmlHttpCurAvg;

var xmlHttpMeter;


try
  {

  xmlHttpCurCht=new XMLHttpRequest();
  xmlHttpCurVal=new XMLHttpRequest();
  xmlHttpCurDate=new XMLHttpRequest();
  xmlHttpCurAvg=new XMLHttpRequest();

  xmlHttpMeter=new XMLHttpRequest();

  }
catch (e)
  {
  // Internet Explorer
  try
    {    
      xmlHttpCurCht=new ActiveXObject("Microsoft.XMLHTTP");
      xmlHttpCurVal=new ActiveXObject("Microsoft.XMLHTTP");
      xmlHttpCurDate=new ActiveXObject("Microsoft.XMLHTTP");
      xmlHttpCurAvg=new ActiveXObject("Microsoft.XMLHTTP");
      xmlHttpMeter=new ActiveXObject("Microsoft.XMLHTTP");       
    }
  catch (e)
    {
    try
      {
      	xmlHttpCurCht=new ActiveXObject("Microsoft.XMLHTTP");
      	xmlHttpCurVal=new ActiveXObject("Microsoft.XMLHTTP");
      	xmlHttpCurdate=new ActiveXObject("Microsoft.XMLHTTP");
      	xmlHttpCurAvg=new ActiveXObject("Microsoft.XMLHTTP");
      	xmlHttpMeter=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      	alert("Your browser does not support AJAX!");
      	return false;
      }
    }
  }
  
  xmlHttpCurCht.onreadystatechange=function()
  {
    if(xmlHttpCurCht.readyState==4)
    {
    	document.getElementById("graphImg").src=xmlHttpCurCht.responseText;
    }
  }  

  xmlHttpCurVal.onreadystatechange=function()
  {
    if(xmlHttpCurVal.readyState==4)
    {
    	document.getElementById("curVal").innerHTML="<b>"+xmlHttpCurVal.responseText+"</b>";
    }
  }  
  
  xmlHttpCurDate.onreadystatechange=function()
  {
    if(xmlHttpCurDate.readyState==4)
    {
    	document.getElementById("curDate").innerHTML=xmlHttpCurDate.responseText;
    }
  }   

  xmlHttpCurAvg.onreadystatechange=function()
  {
    if(xmlHttpCurAvg.readyState==4)
    {
    	document.getElementById("avgVal").innerHTML="<b>" + xmlHttpCurAvg.responseText + "</b>";
    }
  }  
 
  xmlHttpMeter.onreadystatechange=function()
  {
    if(xmlHttpMeter.readyState==4)
    {
     	document.getElementById("meterImg").src=xmlHttpMeter.responseText;
    }
  }   
  
  var index = 0;
  
  if (document.myForm)
  {
  	if (document.myForm.SelectList)
  	 	index = document.myForm.SelectList.selectedIndex;
  	else
    	index = 0;
  }
    
  xmlHttpCurCht.open("GET","graphUpdateLong.pl?" + index,true);  
  xmlHttpCurCht.send(null);

  xmlHttpMeter.open("GET","meterUpdate.pl",true);
  xmlHttpMeter.send(null);
  
  xmlHttpCurVal.open("GET","latest.pl?1",true);  
  xmlHttpCurVal.send(null);
  
  xmlHttpCurDate.open("GET","latest.pl?2",true);  
  xmlHttpCurDate.send(null);  

  xmlHttpCurAvg.open("GET","average.pl?" + index,true);  
  xmlHttpCurAvg.send(null);
	  
  setTimeout("ajaxFunction()",5000);
  
}

setTimeout("ajaxFunction()",10);

