function RemoteFormHelper() {

  this.visibleMessages = null;

  this.resetFormErrors = function() {
    if (this.visibleMessages != null) {
      for (var i = 0; i < this.visibleMessages.length; i++) {
        this.visibleMessages[i].style.display = "none";
      }
      this.visibleMessages = new Array();
    }
  }

  this.showFormError = function(controlId, errorMsg) {
    if (this.visibleMessages == null) {
      this.visibleMessages = new Array();
    }
    var errorDiv = document.getElementById(controlId + "_error");
    if (errorDiv != null) {
      errorDiv.innerHTML = errorMsg;
      errorDiv.style.display = "block";
      this.visibleMessages[this.visibleMessages.length] = errorDiv;
    } else {
      alert(errorMsg);
    }
  }

  this.processFormResponse = function(response) {
    this.resetFormErrors();
    var map = eval("(" + response.responseText + ")");
    if (map["__success"]) {
      return true;
    }
    for (key in map) {
      if (key.indexOf("__") == 0) continue;
      this.showFormError(key, map[key]);
    }
    return false;
  }

  this.setControlLoading = function(id) {
    $(id).disabled = true;
    $(id + "_spinner").style.display = "inline";
  }

  this.setControlLoaded = function(id) {
    $(id).disabled = false;
    $(id + "_spinner").style.display = "none";
  }

  this.handleComboboxChange = function(sender, boundLists) {
    var idx = sender.selectedIndex;
    var disableBound = (idx == 0);
    if (boundLists != null) {
      for (var i = 0; i < boundLists.length; i++) {
        var list = $(boundLists[i]);
        list.selectedIndex = 0;
        list.disabled = true;
        list.onchange.call(list);
      }
    }
  }

}

var _RFH = new RemoteFormHelper();


