var Server = 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) {}
 }
} 

//-------------------------------------------------------------------------------
Server.prototype.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE = (Server.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE = -10);
Server.prototype.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE_MESSAGE = (Server.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE_MESSAGE = "Giving up :( Cannot create an XMLHTTP instance...");
																																  
//-------------------------------------------------------------------------------
Server.prototype.completionStatus = 0;
Server.prototype.getCompletionStatus = function () {return this.completionStatus;};
Server.prototype.setCompletionStatus = function (completionStatus) {this.completionStatus = completionStatus;};
//-------------------------------------------------------------------------------
Server.prototype.debugging = false;
Server.prototype.getDebugging = function () {return this.debugging;};
Server.prototype.setDebugging = function (debugging) {this.debugging = debugging;};
//-------------------------------------------------------------------------------
Server.prototype.serverLog;
Server.prototype.getLog = function () {return this.serverLog;};
Server.prototype.setLog = function (serverLog) {this.serverLog = serverLog;};

//-------------------------------------------------------------------------------
Server.prototype.makeRequest = function(method, url, data, handler, obj) {
 if(this.debugging && this.getLog()) {this.getLog().println("Server.makeRequest is running...");};
 if(this.debugging && this.getLog()) {this.getLog().println("Server.makeRequest: "+"method="+method+"; url="+url+"; data="+data+";");}; 

 if (!this.httpRequest) {
  this.completionStatus = this.ERROR_CANNOT_CREATE_XMLHTT_INSTANCE;
  if(this.debugging && 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);
 };
}