﻿function getHTTPObject() //create connection object to use to talk to server
{
  var xhr = false;
  if (window.XMLHttpRequest)  //all browser other than IE should run this command
     xhr = new XMLHttpRequest();
  else //check for IE browsers
     if (window.ActiveXObject)
        try
          {
          xhr = new ActiveXObject("Msxml2.XMLHTTP");
          }
        catch (e)
          {
          try
            {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
          catch (e)
            {
            xhr = false
            }
          }
  return xhr;
}



function ReceiveAjaxResults(request, divTag)
{
  //this function is called when server sends data back to browser. We only want to
  //process the data when readyState is a 4 and status is 200 or 304.
  if (request.readyState == 4)
     {
     if ((request.status != 200) && (request.status != 304))
        {
        document.getElementById(divTag).innerHTML = "Error retriving content file.";
        return;
        }
     //grab the server answer as all text and stuff it inside the div tab called "answer".
     var data = request.responseText;
     document.getElementById(divTag).innerHTML = data;
     }
}



function SendAjaxRequest(divTag, page)
{
  //This function is called to initiate a call to the server. First we build the connection object
  //then we make the request.  The function supplied (ReceiveAjaxResults) will be called by the
  //browser as results start coming back from the server.
  var request = getHTTPObject();
  if (request)
     {
     request.onreadystatechange = function() {ReceiveAjaxResults(request, divTag);}
     request.open("GET", page, true);
     request.send(null);
     }
}
