/***********************************************************************************************************
 * com.oclib.javascript.util.loader.20070105.Loader
 * Location: http://www.oclib.com/library/com/oclib/javascript/util/Loader.js
 * Version Location: http://www.oclib.com/library/com/oclib/javascript/util/loader/20070105/Loader.js
 * Index Version Location: http://www.oclib.com/library/com/oclib/javascript/util/loader/20070105/index.html
 * © Open Class Library (http://www.oclib.com/)
***********************************************************************************************************/
var Loader = function() {
 this.httpRequest;

 if (window.XMLHttpRequest) {
  this.httpRequest = new XMLHttpRequest();
  if (this.httpRequest.overrideMimeType) {
   this.httpRequest.overrideMimeType('text/xml');
  }
 } else if (window.ActiveXObject) { // IE
  try {
   this.httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    this.httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (e) {}
  }
 } else if (window.createRequest) {
   try {
    this.httpRequest = window.createRequest();
   } catch (e) {}
 }
} 

Loader.prototype = new Root();

Loader.prototype.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE = (Loader.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE = -10);
Loader.prototype.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE_MESSAGE = (Loader.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE_MESSAGE = "Giving up :( Cannot create an XMLHTTP instance...");

Loader.prototype.makeRequest = function(method, url, data, handler, obj) {
 if(this.mustTrace()) {this.getLog().println("Loader.makeRequest is running...");};
 if(this.getDebugging() && this.getLog()) {this.getLog().println("Loader.makeRequest: "+"method="+method+"; url="+url+"; data="+data+";");}; 

 if (!this.httpRequest) {
  this.completionStatus = this.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE;
  if(this.getDebugging() && this.getLog()) {this.getLog().println(this.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE_MESSAGE);};
  alert(this.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE_MESSAGE);
  return this.completionStatus;
 }
 
 var httpRequest = this.httpRequest;
 this.httpRequest.onreadystatechange = function () {handler(httpRequest, obj);};
 if(method == "GET" || method == "get") {
  this.httpRequest.open(method, url, true);
  this.httpRequest.send(null);
 } else {
  this.httpRequest.open('POST', url);
  this.httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
  this.httpRequest.send(data);
 };
}
