var xmlHttp

function ChangeImage(img_id)
{
  var url="imagexml.php";

  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  }
  var postvar = "img_id=" + img_id + '&sid=' + Math.random();

  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("POST",url, true);
  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send(postvar);

}


function stateChanged() 
{ 
  if (xmlHttp.readyState==4 || xmlHttp.readyState==0)
  {	
    var xmlDoc=xmlHttp.responseXML.documentElement;
    
    var status = xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue;

    document.getElementById("image_status").innerHTML= "<span class=\"status\">" + status + "</span>";
    document.getElementById("image_src").innerHTML = "<img src=\"" + xmlDoc.getElementsByTagName("path")[0].childNodes[0].nodeValue + "\" width=\"460\" height=\"344\" />";
  }
  
  if (xmlHttp.readyState==1)
  {
    document.getElementById("image_status").innerHTML= "<span class=\"status\"> Loading ...</span>";
  }

}


/* XML Http Object*/
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer
    try {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}


