/*
 * Filename: ajax.js
 * Purpose: Provide simple ajax functions
 * Functions:
 *    XmlObject()
 *    LoadContent(elid,url)
 */


/*
 * Function: XmlObject()
 * Returns an XMLRequest object, either newly created or prior object.
 */
function XmlObject() { 
  var xmlhttp=false;
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // JScript gives us Conditional compilation, we can cope with old IE versions.
  // and security blocked creation of the objects.
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp=false;
    }
  }
  if (!xmlhttp && window.createRequest) {
    try {
      xmlhttp = window.createRequest();
    } catch (e) {
      xmlhttp=false;
    }
  }
  return xmlhttp;
}


var nc_ctr = 0;
/*
 * Function: LoadContent(elid, url)
 * Purpose: Returns the contents of url
 */
function LoadContent(elid,url) { 
  if(!url) { return false; }

  var xobj = XmlObject();
  if(!xobj) {
    return;
  }

  // Prevent URL caching...
  if(url.indexOf("?") >= 0) {
    url = url+"&nc_ctr="+nc_ctr;
  } else {
    url = url+"?nc_ctr="+nc_ctr;
  }
  nc_ctr++;

  xobj.open("GET", url, true);
  xobj.onreadystatechange=function() {
    if(xobj.readyState == 4) {
      if(xobj.status != 200) { 
        // alert("Server returned code " + xobj.status);
        return false;
      }
      // alert(elid+": "+xobj.responseText);
      document.getElementById(elid).innerHTML =  xobj.responseText;
      delete xobj;
    }
  }
  xobj.send(null);
}

