if (typeof luckymarble == "undefined") var luckymarble = new Object();

luckymarble.ajaxUtil = function () {
  this.baseDomain   = "http://" + window.location.hostname;
  this.ajaxObj      = this.createAjaxObject();
  this.fileType     = "txt";
  this.addRandomNum = 1;  // 0 or 1
}

luckymarble.ajaxUtil.prototype = {
  createAjaxObject: function () {
    var httpRequest = false;

    // Mozilla, Safari, etc 
    if (window.XMLHttpRequest) {
      httpRequest = new XMLHttpRequest();
      if (httpRequest.overrideMimeType) {
        httpRequest.overrideMimeType('text/xml');
      }
    
    // Internet Explorer
    } else if (window.ActiveXObject) {
      try {
        httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
          // do nothing
        }
      }
    }
    return httpRequest;
  }, 
  getAjaxRequest: function (url, parameters, callBackFunction, fileType) {
    // recreate ajax object to defeat cache problem in IE
    this.ajaxObj = this.createAjaxObject(); 

    // further attempt to defeat cache problem in IE
    if (this.addRandomNum == 1) { 
      var parameters = parameters + "&cache=" + new Date().getTime()
    }

    // if the object exists, then GET request
    if (this.ajaxObj) {
      //alert(url + "?" + parameters);
      this.fileType = fileType;
      this.ajaxObj.onreadystatechange = callBackFunction
      this.ajaxObj.open('GET', url + "?" + parameters, true);
      this.ajaxObj.send(null);
    }
  },
  postAjaxRequest: function(url, parameters, callBackFunction, fileType) {
    // recreate ajax object to defeat cache problem in IE
    this.ajaxObj = this.createAjaxObject();
    
     // further attempt to defeat cache problem in IE
    if (this.addRandomNum == 1) { 
      var parameters = parameters + "&cache=" + new Date().getTime()
    }
    
    parameters = parameters.replace(/ /gi, "%20");
    
    // if the object exists, then POST request
    if (this.ajaxObj) {
      this.fileType = fileType;
      this.ajaxObj.onreadystatechange = callBackFunction;
      this.ajaxObj.open('POST', url, true);
      this.ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      this.ajaxObj.setRequestHeader("Accept-Charset", "utf-8");
      this.ajaxObj.setRequestHeader("Content-length", parameters.length);
      this.ajaxObj.setRequestHeader("Connection", "close");
      this.ajaxObj.send(parameters);
    }   
  }
}  
