/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
	var xmlHttp, bComplete = false;
  try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlHttp = new XMLHttpRequest(); }
  catch (e) { xmlHttp = false; }}}
  if (!xmlHttp) return null;
	this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlHttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlHttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlHttp.open(sMethod, sURL, true);
        xmlHttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlHttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlHttp);
        }};
      xmlHttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}
