// -- AJAX FUNCTIONS -- //

// The load_html() function
// This function takes two arguments, the external
// file's URL (usually PHP but can be other files
// as well) and the ID of a container tag.  The
// function will load the external file into that
// container when ready.

// The xmlhttp container variable where we will store the information
var xmlhttp;
var containerid;
var request_type;

// The function itself
function load_html(_url, _containerid, _type)
{
    // Initialize the xmlhttp and containerid variables
    xmlhttp = null;
    containerid = _containerid;
    request_type = _type;
  
    // Try to create the HttpRequest object for the AJAX function
    if (window.XMLHttpRequest)
    {// code for Firefox, Opera, IE7, etc.
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  
    // Check to make sure the request object was created successfully
    if (xmlhttp!=null)
    {
        // Create the event that will monitor the request variable
        xmlhttp.onreadystatechange=state_Change;
        xmlhttp.open("GET",_url,true);
        xmlhttp.send(null);
    }
    else
    {
        // Alert the user that their browser doesn't support AJAX
        alert("Your browser does not support XMLHTTP (AJAX).");
    }  
}

function state_Change()
{
  if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
      switch(request_type)
      {
        case "value":
        {
          // Change the innerHTML of the requested object
          parent.document.getElementById(containerid).value = xmlhttp.responseText;
          break;
        }
        case "src": case "source":
        {
          // Change the innerHTML of the requested object
          parent.document.getElementById(containerid).src = xmlhttp.responseText;
          break;
        }
        case "innerHTML": case "innerhtml": default:
        {
          // Change the innerHTML of the requested object
          parent.document.getElementById(containerid).innerHTML = xmlhttp.responseText;
          break;
        }
      }
     
    }
  else
    {
    alert("Problem retrieving data:" + xmlhttp.statusText);
    }
  }
}