var xmlHttp = createXmlHttpRequestObject();
var rmsg;
var divnm;

function createXmlHttpRequestObject()
{
  var xmlHttp;

  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e)
    {
      xmlHttp = false;
    }
  }

  else
  {
    try
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
      xmlHttp = false;
    }
  }

  if (!xmlHttp)

    alert("Error creating the XMLHttpRequest object.");
  else
    return xmlHttp;
}

function process(tmsg, divname)
{
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    rmsg = tmsg;
    divnm = divname;
    var params = "vals=" + tmsg;

    xmlHttp.open("POST", "refresh", true);

    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(params);
  }
  else
    setTimeout('process(tmsg, divname)', 1000);
}

function handleServerResponse()
{
  if (xmlHttp.readyState == 4)
  {
    if (xmlHttp.status == 200)
    {
      retval = xmlHttp.responseText;
	  msg = retval.split("#|#");
	  for(i=0;i<msg.length;i++) {
		  document.getElementById(divnm + i).innerHTML = msg[i];
		  // alert("div " + i + "msg length " + msg.length);
	  }
	  var time = 1000 * 60 * 5;
	  // time = 3000;
	  setTimeout('process(rmsg, divnm)', time);
    }
    else
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
