function newXMLHttpRequest() {
  var xmlreq = false;
  if (window.XMLHttpRequest) {
    xmlreq = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
      try {
        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        alert("Unable to create an XMLHttpRequest with ActiveX");
      }
    }
  }
  return xmlreq;
}
function getReadyStateHandler(req, responseXmlHandler) {
  return function () {
    if (req.readyState == 4) {
      if (req.status == 200) {
        responseXmlHandler(req);
      } else {
        alert("HTTP error: "+req.status);
      }
    }
  }
}
function sendAjax(stringToSend, callback) {
      var req = newXMLHttpRequest();
      var handlerFunction = getReadyStateHandler(req, callback);
      req.onreadystatechange = handlerFunction;
      req.open("POST", "ajaxConnector.jsp", true);
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

      req.send(stringToSend);
}
function sendCookAjax(stringToSend, callback) {
      var req = newXMLHttpRequest();
      var handlerFunction = getReadyStateHandler(req, callback);
      req.onreadystatechange = handlerFunction;
      req.open("POST", "cook.jsp", true);
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

      req.send(stringToSend);
}
