function XML_RPC() {
  this.methodName = '';
  this.params = [];
  this.payload = '';
}


/**
// something like this would be passed as the param
var arr = [];
arr[0] = {'type' : 'i4', 'value' : 13};
arr[1] = {'type' : 'string', 'value' : 'please don\'t do that'};
arr[2] = {'type' : 'boolean', 'value' : false};
arr[2] = {'type' : 'double', 'value' : 89.225};
*/
XML_RPC.prototype.addArray = function(arr) {
  var i = this.params.length;
  this.params[i] = {'type' : 'array', 'members' : arr};
}

/**
somethign like rpc.addScalar('i4', 234);
somethign like rpc.addScalar('string', 'i like money');
*/
XML_RPC.prototype.addScalar = function(type, val) {
  var i = this.params.length;
  this.params[i] = {'type' : type, 'value' : val};
}

/**
// something like this would be passed as the param
var struct = [];
struct[0] = {'name' : 'sizeOfNoler', 'type' : 'i4', 'value' : 1};
struct[1] = {'name' : 'greeting', 'type' : 'string', 'value' : 'hello, world'};
struct[2] = {'name' : 'accountDisabled', 'type' : 'boolean', 'value' : true};
struct[2] = {'name' : 'grade', 'type' : 'double', 'value' : 100.012};
*/
XML_RPC.prototype.addStruct = function(struct) {
  var i = this.params.length;
  this.params[i] = {'type' : 'struct', 'members' : struct};
}

/**
build the payload string for a single parameter
*/
XML_RPC.prototype.buildParam = function(pType, pValue) {
  var rVal = '';
  switch (pType) {
    case 'i4':
    case 'int':
    case 'boolean':
    case 'string':
    case 'double':
    case 'dateTime.iso8601':
    case 'base64':
      rVal = pValue;
      break;

    case 'array':
      for (var a = 0; a < pValue.lenth; a++) {
        rVal = this.buildParam(pValue[a].type, pValue[a].value)
      }
      break;

    case 'struct':
      break;
  }

  return rVal;
}

/**
build the payload string
*/
XML_RPC.prototype.buildPayload = function() {
  this.payload = '<' + '?xml version="1.0" encoding="utf-8" ?' + '>'; // confuses a PHP editor
  this.payload += '<methodCall>';
  this.payload += '<methodName>' + this.methodName + '</methodName>';

  // any params?
  if (this.params.length > 0) {
    this.payload += '<params>';
    for (var i = 0; i < this.params.length; i++) {
      this.payload += '<param><value><' + this.params[i].type + '>';
      this.payload += this.buildParam(this.params[i].type, this.params[i].value);
      this.payload += '</' + this.params[i].type + '></value></param>';
    }
    this.payload += '</params>';
  }

  this.payload += '</methodCall>';
}
