function ReqObj (type, url, data) {
  this.type = type;
  this.url = url;
  this.data = data;
}

ReqObj.prototype.connect = function(func, failfunc) {
    this.func = func;
    var req;
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        if (func && failfunc) {
          this.handleReadyState(req, func, failfunc);
        }
        req.open(this.type, this.url, true);
        req.send(this.data);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            if (func && failfunc) {
              this.handleReadyState(req, func, failfunc);
            }
            req.open(this.type, this.url, true);
            if (this.type == 'POST') {
              req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            }
            req.send(this.data);
        }
    }
}

ReqObj.prototype.handleReadyState = function(req, callback, failfunc) {
  var poll = window.setInterval(
    function() {
      if (req.readyState == 4) {
        if (req.status == 200) {
          try {
            var response  = req.responseXML.documentElement;
            callback(response);
          } catch(exception) {
            failfunc(exception.message);
          }
        } else {
          failfunc(req.status);
        }
        window.clearInterval(poll);
      }
    }
    , 50);
}

function getNodeValue(node, name) {
  return node.getElementsByTagName(name)[0].firstChild.data;
}

function getNodeListValues(nodelist) {
  var tmp = new Array;
  for (var i=0;i<nodelist.length;i++) { 
    tmp[i] = nodelist[i].firstChild.data;
  }
  return tmp;
}

function inArray(arr, val) {
  if (arr == null) return false;
  for (var i=0;i<arr.length;i++) {
    if (arr[i] == val) return true;
  }
  return false;
}

