/* AJAX JS functions */

/*
 * ajax function to set up a proper xmlhttprequest
 */
function getXMLHttpRequest()
{
    var xmlHttp = null;

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

    return xmlHttp
}

/*
 * fetch an external page to extract the content
 */
function fetchExternHTML(url, target) {
  document.getElementById(target).innerHTML = ''
  var xmlHttp = getXMLHttpRequest();

  if (xmlHttp != null) {
    xmlHttp.onreadystatechange = function() 
    {
      extractContent(xmlHttp, url, target);
    }
    xmlHttp.open("GET", url, true);
    xmlHttp.send("");
  }
}  

/*
 * extract the content from an external HTML page
 */
function extractContent(xmlHttp, url, target) {
  if (xmlHttp.readyState == 4) 
  { 
    if (xmlHttp.status == 200) 
    { 
      document.getElementById(target).innerHTML = xmlHttp.responseText;
    } else {
      document.getElementById(target).innerHTML="Error:\n"+ xmlHttp.status + "\n" + xmlHttp.statusText;
    }
  }
}

/*
 * insert a page content from an external HTML
 *   into the currnet HTML page
 */
function insertExternHTML(url, target) {
  fetchExternHTML(url, target)
  return false
}
