var xmlHttp = createXmlHttpRequestObject();
var updateInterval = 10; // how many seconds to wait to get a new number

function process()
{
  // only continue if xmlHttp isn't void
//	var  pics_count	 =	 pics.length+0.49;
//	var  no	=	 (Math.round(pics_count*Math.random()));
	var  no	=	 (Math.round(9.49*Math.random()));
	// ภาษาไทย ส่งผ่าน ajax ควร encodeURI เพื่อป้องกันความผิด
   URL	=	"../_ajax/loadpic.php?photo="+pics[no][0]+"&url="+pics[no][1]+"&detail="+encodeURI(pics[no][2]);
  if (xmlHttp)
  {
    // try to connect to the server
    try
    {
      // initiate reading the async.txt file from the server
      xmlHttp.open("GET", URL, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);
    }
    // display the error in case of failure
    catch (e)
 
    {
      alert("Can't connect to server:\n" + e.toString());
    }
  }
}

// function that handles the HTTP response
function handleRequestStateChange() 
{
  // obtain a reference to the <div> element on the page
  myDiv = document.getElementById("myDivElement");
  // display the status of the request 
if (xmlHttp.readyState == 4) 
  {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200) 
    {
      try
      {
        // read the message from the server
        response = xmlHttp.responseText;
        // display the message 
        myDiv.innerHTML = response;
      }
      catch(e)
      {
        // display error message
        //alert("Error reading the response: " + e.toString());
      }
    } 
    else
    {
      // display status message
      //alert("There was a problem retrieving the data:\n" + 
//            xmlHttp.statusText);
    }
	setTimeout("process();", updateInterval * 1000);     
  }
}