
function Ajax(){}

/**
 * Creates a new ajax request object
 *
 * @param action    the action string to call into the Xeno framework with
 * @param parameters    the parameter string to use with the Ajax call
 * @param handler       (optional) a function to handle the request instead of the default way
 */
 var xmlHTTP;
Ajax = function(action, parameters, handler)
{
    this.action = action;
    this.parameters = parameters;
    xmlHTTP = Ajax.getXMLHttpRequest();
    this.handler = handler;
}

Ajax.getXMLHttpRequest = function()
{
  if (xmlHTTP != null)  xmlHTTP = null;
  
  try
  {// Opera 8.0+, Firefox, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch (e)
  {// Internet Explorer Browsers
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {// Something went wrong
        alert("Your browser does not support Ajax\nUpgrade your browser or email us with your browser information\nif you feel something else is wrong.");
        return null;
      }
    }
  }
  return xmlHttp;      
}

Ajax.prototype.doGet = function(divId)
{
   if (xmlHTTP == null)
   {
      var responseDiv = document.getElementById(divId).innerHTML = "Unable to execute Ajax Request";
      return;
   } 

   if (this.handler == null)
   {
      xmlHTTP.onreadystatechange = 
          function onStateChanged()
          {
            if (xmlHTTP.readyState == 4)
            {
              var responseDiv = document.getElementById(divId);
              responseDiv.innerHTML = xmlHTTP.responseText;
            }
          }
   }
   else
   {
     xmlHTTP.onreadystatechange = handler;
   }
   var requestLine = "bin/" + this.action;
    if (this.parameters != null)
        requestLine += "?" + this.parameters;
   xmlHTTP.open("GET", requestLine, true);
   xmlHTTP.send(null);  
}

Ajax.prototype.doPost = function(divId)
{
   if (xmlHTTP == null)
   {
      var responseDiv = document.getElementById(divId).innerHTML = "Unable to execute Ajax Request";
      return;
   } 

   if (handler == null)
   {
      xmlHTTP.onreadystatechange = 
          function onStateChanged()
          {
            if (XMLHttpRequest.readyState == 4)
            {
              var responseDiv = document.getElementById(divId);
              responseDiv.innerHTML = xmlHTTP.responseText;
            }
          }
   }
   else
   {
     xmlHTTP.onreadystatechange = handler;
   }
   var requestLine = "bin/" + this.action;
   xmlHTTP.open("POST", requestLine, true);
   xmlHTTP.send(this.parameters);  
}

Ajax.prototype.doSimpleGet = function(divId)
{
   if (xmlHTTP == null)
   {
      var responseDiv = document.getElementById(divId).innerHTML = "Unable to execute Ajax Request";
      return;
   } 

   if (this.handler == null)
   {
      xmlHTTP.onreadystatechange = 
          function onStateChanged()
          {
            if (xmlHTTP.readyState == 4)
            {
              var responseDiv = document.getElementById(divId);
              responseDiv.innerHTML = xmlHTTP.responseText;
            }
          }
   }
   else
   {
     xmlHTTP.onreadystatechange = handler;
   }
   var requestLine = this.action;
    if (this.parameters != null)
        requestLine += "?" + this.parameters;
   xmlHTTP.open("GET", requestLine, true);
   xmlHTTP.send(null);  
}
      
Ajax.prototype.doSimplePost = function(divId)
{
   if (xmlHTTP == null)
   {
      var responseDiv = document.getElementById(divId).innerHTML = "Unable to execute Ajax Request";
      return;
   } 

   if (handler == null)
   {
      xmlHTTP.onreadystatechange = 
          function onStateChanged()
          {
            if (XMLHttpRequest.readyState == 4)
            {
              var responseDiv = document.getElementById(divId);
              responseDiv.innerHTML = xmlHTTP.responseText;
            }
          }
   }
   else
   {
     xmlHTTP.onreadystatechange = handler;
   }
   var requestLine = this.action;
   xmlHTTP.open("POST", requestLine, true);
   xmlHTTP.send(this.parameters);  
}