function MAjaxRequest() {
  this.userAgentSet = {};
  this.appVersionSet = {};
  this._json_cache_defeater_ = (new Date).getTime();
  this.onReceivedResponse = null;
}

MAjaxRequest.prototype.targetObj = null;
MAjaxRequest.connectionContext = new Array(); 

MAjaxRequest.prototype.checkUserAgent = function (ua) {
  if (ua in this.userAgentSet) {
    return this.userAgentSet[ua];
  }
  return this.userAgentSet[ua] = navigator.userAgent.toLowerCase().indexOf(ua) != -1;
};

MAjaxRequest.prototype.checkAppVersion = function (av) {
  if (av in this.appVersionSet) {
    return this.appVersionSet[av];
  }
  return this.appVersionSet[av] = navigator.appVersion.toLowerCase().indexOf(av) != -1;
};

MAjaxRequest.prototype.isMSIE = function () {
  return this.checkUserAgent("msie");
};

MAjaxRequest.prototype.isSafOrKon = function () {
  return this.checkUserAgent("safari") || this.checkUserAgent("konqueror");
};

MAjaxRequest.prototype.applyFunction = function (obj, func, param) {
  return function () {
    return func.apply(obj, param);
  };
};

MAjaxRequest.prototype.scriptRequest = function (url) {
  var headTag = document.getElementsByTagName("head")[0];
  var scriptTag = document.createElement("script");
  scriptTag.type = "text/javascript";
  scriptTag.charset = "utf-8";
  if (this.isMSIE() || this.isSafOrKon()) {
    if (url.indexOf("?") > -1) {
      url = url + "&nocache=" + this._json_cache_defeater_++;
    } else {
      url = url + "?nocache=" + this._json_cache_defeater_++;
    }
  }
  scriptTag.src = url;
  var scriptTagOnLoad = function () {
    //alert("scriptTag.src:"+scriptTag.src);
    scriptTag.onload = null;
    var scriptTagParent = scriptTag.parentNode;
    scriptTagParent.removeChild(scriptTag);
    delete scriptTag;
  };
  var scriptTagOnReady = function (scriptTagParent) {
    var eventSource = (scriptTagParent ? scriptTagParent : window.event).target ? (scriptTagParent ? scriptTagParent : window.event).target : (scriptTagParent ? scriptTagParent : window.event).srcElement;
    if (eventSource.readyState == "loaded" || eventSource.readyState == "complete") {
      eventSource.onreadystatechange = null;
      setTimeout(scriptTagOnLoad, 5000);
      //scriptTagOnLoad();
    }
  };
  if (navigator.product == "Gecko") {
    scriptTag.onload = scriptTagOnLoad;
  } else {
    scriptTag.onreadystatechange = scriptTagOnReady;
  }
  headTag.appendChild(scriptTag);
};

MAjaxRequest.prototype.sendRequest = function (url) {

  var contextNo = MAjaxRequest.AllocateConnectionContext(this);
  if (url.indexOf("?") > -1) {
      url = url + "&ctx=" + contextNo;
    } else {
      url = url + "?ctx=" + contextNo;
    }
  if (this.checkUserAgent("msie") && this.checkAppVersion("msie 6.0")) {
    var func = this.applyFunction(this, this.scriptRequest, [url]);
    setTimeout(func, 0);
  } else {
    this.scriptRequest(url);
  }
};

MAjaxRequest.ReturnData = function(contextNo, data)
{
  var no = 0;
  if (contextNo)
  {
    no = parseInt(contextNo);
  }
  var requestObj = MAjaxRequest.connectionContext[no];
  MAjaxRequest.connectionContext[no] = null;
  requestObj.onReceivedResponse.call(requestObj.targetObj, data);
}

MAjaxRequest.AllocateConnectionContext = function(connCreator)
{
  var isFindSpace = false;
  var pos = null;
  if (MAjaxRequest.connectionContext.length) {
    for (var i = 0; i < MAjaxRequest.connectionContext.length; i++) {
      if (MAjaxRequest.connectionContext[i] == null) {
        MAjaxRequest.connectionContext[i] = connCreator;
        pos = i;
        isFindSpace = true;
        break;
      }
    }
  }
  if (!isFindSpace) {
    pos = MAjaxRequest.connectionContext.length;
    MAjaxRequest.connectionContext.push(connCreator);
  }
  return pos;
}

MAjaxRequest.prototype.setResponseHandler = function(handler, obj) {
  this.onReceivedResponse = handler;
  this.targetObj = obj;
}