/*
The following incredible function implements Ajax calls in less than 800 *characters*.
One could certainly expand on the error handling and the xmlhttp instantiation but why bother...
*/
function XHR() {

  var xmlHttp;

  window.ActiveXObject?xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"):xmlHttp=new XMLHttpRequest();

  if (!xmlHttp) return null;

  this.sendRequest=function(sMethod, sURL, sVars, fnDone) {

    if (!xmlHttp) return false;

    if (sURL.indexOf("?")>0)
      sURL+="&timeStamp="+new Date().getTime();
    else
      sURL+="?timeStamp="+new Date().getTime();

    try {
      if (sMethod == "get") {
        xmlHttp.open("GET", sURL, true);
        sVars="";
      }
      if (sMethod == "post") {
        xmlHttp.open("POST", sURL, true);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      }
      xmlHttp.onreadystatechange=function() {
        if(xmlHttp.readyState == 4) {
          if(xmlHttp.status == 200) {
            fnDone(xmlHttp);
          }
        }
      }
      xmlHttp.send(sVars);
    }
    catch(e) { 
      //return false; 
      dump(e); // comment this out if you do not include dump.js in your project
    }
    return true;
  }

  return this;
}

/* 
usage(1): onclick="javascript:getContent();"
function getContent() {
  var sURL="service.cfm";
  var sVars="";
  var fnWhenDone=function (XHR) {
    var result=XHR.responseText;
    result=result.replace(/^\s*|\s*$/g,"");
    alert(result); 
  };
  var xhr=new XHR();
  xhr.sendRequest("get", sURL, sVars, fnWhenDone);
}

usage(2): <form ... onsubmit="javascript:postContent(this);return false;">
function postContent(form) {
  var sURL="service.cfm";
  var sVars="first_name="+form.first_name.value+"&last_name="+form.last_name.value;
  var fnWhenDone=function (XHR) { 
    var result=XHR.responseXML;
    result=result.replace(/^\s*|\s*$/g,""); 
    alert(result); 
  };
  var xhr=new XHR();
  xhr.sendRequest("post", sURL, sVars, fnWhenDone);
}

based on XHConn.js by Brad Fults - http://xkr.us/code/javascript/XHConn/XHConn.js
*/
