// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject();

// make asynchronous HTTP request using the XMLHttpRequest object
function MostraLista(params)
{
  //document.getElementById("meio").innerHTML = "<table border='0' height='200' width='100%'><tr><td><center><b>Carregando...</b></center></td></tr></table>";


  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // execute the quickstart.php page from the server
    xmlHttp.open("GET", "lojan_compras.php?" + params, true);
    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponseL;
    // make the server request
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second
    alert("Ops! Erro inesperado, por favor tente novamente.");
}

// executed automatically when a message is received from the server
function handleServerResponseL()
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4)
  {

    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200)
    {
	  xmlDoc = xmlHttp.responseXML;
	  if(window.ActiveXObject)
	  {
		// Load XSL
		var xsl = new ActiveXObject("Microsoft.XMLDOM")
		xsl.async = false
		xsl.load("lojan.xsl")

		var xml = new ActiveXObject("Microsoft.XMLDOM")
		xml.loadXML(xmlHttp.responseText);

		document.getElementById("lista").innerHTML = xml.transformNode(xsl)
	  }
	  else
	  {
		var xslStylesheet;
		var xsltProcessor = new XSLTProcessor();

		var xmlDoc;
		xmlDoc = xmlHttp.responseXML;

		var myXMLHTTPRequest = createXmlHttpRequestObject();
		myXMLHTTPRequest.open("GET", "lojan.xsl", false);
		myXMLHTTPRequest.send(null);

		xslStylesheet = myXMLHTTPRequest.responseXML;
		xsltProcessor.importStylesheet(xslStylesheet);

		var fragment = xsltProcessor.transformToFragment(xmlDoc, document);

		document.getElementById("lista").innerHTML = "";
		document.getElementById("lista").appendChild(fragment);
	  }
    }
    // a HTTP status different than 200 signals an error
    else
    {
      alert("Ocorreu um erro ao acessar o servidor. Por favor, tente novamente. (Erro " + xmlHttp.statusText + ")");
    }
  }
}

