/*
 * ajaxAppendPage(dest, page)
 * 
 * This function requests a URL, of an html page, and appends the html page content to
 * a DOM object in another html page. Essentially a javascript-based <!-- #include --> tag.
 * 
 * string dest: the id of the object to append the page to, typically a <div id="xxx"></div>
 * string page: the URL of the page to append. This is a web URL, not a local filesystem path.
 * */

function ajaxAppendPage(dest, page)
  {
  var ajaxvar;
  ajaxvar=ajaxFunction();			// create an AJAX request object
  ajaxvar.onreadystatechange=function()		// Add the function to call when AJAX request completed (inline)
    {
      if(ajaxvar.readyState==4)
      {
        document.getElementById(dest).innerHTML=(ajaxvar.responseText);	// set the innerHTML to the requested page
      }
    }
  ajaxvar.open("GET", page, true);		// Make the request via method="GET", requesting the 'page' from parameters, async=true
  ajaxvar.send(null);				// launch the sucker. ajaxvar.onreadystatechange will be executed when server responds
  }

/*
 * ajaxFunction(void)
 * 
 * This creates the XMLHttpRequest Object. It is complicated by Microsoft's policy of keeping 
 * Internet Explorer different from any other browser.
 * */

function ajaxFunction()
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  return xmlHttp;
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    return xmlHttp;
    }
  catch (e)
    {
      alert("Your browser does not support AJAX!");
      return false;
    }
  }
  }

 

