/*
  cp_HttpRequest.js
  Copyright (C) Cinematica Producciones Ltda.
  Author: Andres Melguizo Velez
  Version: 1.0
  Created: 20050722
  Modified: 20050722

  Usage:
    var httpRequest = cp_newHttpRequest();
    result = cp_doHttpRequest(httpRequest, "http://localhost/somesite/somepage.asp","key1=value1&key2=value2");
*/

// Create the object in Mozilla or IE
function cp_newHttpRequest() {
  var httpReq = false;
  // Check for native XMLHttpRequest object
  if(typeof XMLHttpRequest != 'undefined')
    httpReq = new XMLHttpRequest();
  else { // Check for IE/Windows ActiveX version
    try {
      httpReq = new ActiveXObject("Msxml2.XMLHTTP.4.0");
    } catch(e) {
      try {
        httpReq = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
        try {
          httpReq = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) {
          httpReq = false;
        }
      }
    }
  }
  return(httpReq);
}

// Make a sync request only and returns the response or the status in case of error
function cp_doHttpRequest(httpReq, szURL, szParam) {
  // httpReq.open (Method("get","post"), URL(string), Asyncronous(true,false))
  httpReq.open("POST", szURL, false);
  httpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  httpReq.send(szParam);
  //if(httpReq.status == 200 ? alert("szURL = " + szURL + "\n Params = " + szParam + "\n Response = " + httpReq.responseText) : alert("szURL = " + szURL + "\n Params = " + szParam + "\n ERROR: " + httpReq.status));
/*
  if(httpReq.responseText.length > 2500)
    alert(httpReq.responseText.substr(2500));
  else
    alert(httpReq.responseText);
*/
  return(httpReq.status == 200 ? httpReq.responseText : httpReq.status);
}
