function rpc (url, queryString, method, dataHandler, retType, otherArgs) {
  this.handler = dataHandler;
  this.retType = retType;
  this.otherArgs = otherArgs;
  if (method == 'GET') {
    this.startRequest(url, queryString);
  } else if (method == 'POST') {
    this.startPostRequest(url, queryString);
  } else {
    return 0;
  }
}
 
  rpc.prototype.createRequest = function() {
    if (window.ActiveXObject) {
        this.xhr = new ActiveXObject("Microsoft.XMLHTTP");
    } else if (window.XMLHttpRequest) {
        this.xhr = new XMLHttpRequest();
    }
  }
    
  rpc.prototype.startPostRequest = function(url, queryString) {
    var self = this;
    this.createRequest();
    this.xhr.open("POST", url, true);
    this.xhr.onreadystatechange = function(){ self.handleStateChange(); }
    this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    this.xhr.send(queryString);
  }
    
  rpc.prototype.startRequest = function(url, queryString) {
    var self = this;
    this.createRequest();
    var D = new Date();
    now = D.getTime();
    queryString += '&cache=' + now;
		url = url + '?' + queryString;
    this.xhr.onreadystatechange = function() { self.handleStateChange(); }
    this.xhr.open("GET", url, true);
    this.xhr.send(null);
	}
    
  rpc.prototype.handleStateChange = function() {
    if(this.xhr.readyState == 4) {
        if(this.xhr.status == 200) {
          if (this.retType == 'raw') {
           this.retValue = this.xhr.responseText;
          } else if (this.retType == 'xml') {
           this.retValue = this.xhr.responseXML;
          } else if (this.retType == 'json') {
           this.retValue = JSON.parse(this.xhr.responseText);
          } else {
           this.retValue = this.xhr.responseText;
          }
          this.handler(this.retValue, this.otherArgs);
      }
    }
  }
