//******************************************************************************
// Helen's Heart - Dynamically Updating: AJAX Communication
// File:        ajax.js
//
// Author:        Joshua Jacobsen (this version)
//                Derived from various examples online
// Email:         drowlord@drowlord.com
// Date:          2/7/2008 (Major Revisions)
//*******************************************************************************

// function to fetch an ajax object, since different browsers use
// different objects.

function getAjaxObject() {
  try
  {
    if (window.XMLHttpRequest) { // if this is a Mozilla browser like Firefox
      return new XMLHttpRequest();
    }
    else { // if this is a Microsoft browser like Internet Explorer
      return new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  catch (ex)
  {
    return false;
  }
  return false;
}

// version of ajaxRequest for normal uses.
function ajaxRequest(url, postData) {
  var ajaxObj = getAjaxObject();

  if(url != null && url != "") { //make sure that there is a URL.
    if(postData != null) { //if there is post data, use "POST" http method
      ajaxObj.open("POST", url, false);
      ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      ajaxObj.setRequestHeader("Content-length", postData.length);
    }
    else { //no post datat, use "GET" http method
      ajaxObj.open("GET", url, false);
    }
    ajaxObj.send(postData);
    return ajaxObj.responseText;
  }
  else
  {
    return "";
  }
}
