﻿var http = null;
var Buffers = null;

function createXMLHTTPsocket()
{
   var xmlhttp=false;
   try
   {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   }
   catch (e)
   {
      try
      {
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (E)
      {
         xmlhttp = false;
      }
   }
   if (!xmlhttp && typeof XMLHttpRequest!='undefined')
   {
      xmlhttp = new XMLHttpRequest();
   }
   xmlhttp.onreadystatechange = ajaxCallback;
   return xmlhttp;
}

function ajaxCallback()
{
  if (http.readyState == 4) {
    //alert(http.responseText);
    response = http.responseXML.documentElement;
    target = response.getElementsByTagName('target')[0].firstChild.data;
    content = response.getElementsByTagName('content')[0].firstChild.data;
    document.getElementById(target).innerHTML = content;
    document.getElementById(target).style.visibility = 'visible';
    http = null;
    if (Buffers != null) {
      for (var i=0; i<Buffers.length; i++) {
        if (Buffers[i] != null) {
          var sql = Buffers[i][0];
          var p0 = Buffers[i][1];
          Buffers[i] = null;
          Ajax(sql,p0);
          break; }}}}
}

function Ajax(sql,p0)
{
  var i = 0;

  if (http != null) {
    if (Buffers == null) Buffers = new Array();
    for (i=0; i<Buffers.length; i++) if (Buffers[i] == null) break;
    Buffers[i] = new Array();
    Buffers[i][0] = sql;
    Buffers[i][1] = p0;
    return; }
  http = createXMLHTTPsocket();
  arg = '/cgi-bin/ajax?sql='+sql;
  if (p0 != null) arg += "&p0="+p0;
  pending = 1;
  http.open('get',arg);
  http.send(null);
}

