
if(!window.__rageLib){
  window.__rageLib = {};
  window.__rageLib.instances = {};
}

__rageLib.rageView = {};

__rageLib.rageView.Controller = function(){};
__rageLib.rageView.Controller.prototype = {
  idx_by_id: [],
  process: function(id, page){
    this.idx_by_id[id].process(page);
  },
  changeURL: function(id, new_url){
    this.idx_by_id[id].ajax.setURL(new_url);
  },
  getView: function(id){ return this.idx_by_id[id]; },
  saveView: function(id, obj){ this.idx_by_id[id] = obj; }
}

__rageViewController = new __rageLib.rageView.Controller();

__rageLib.rageView.Processor = function(id, viewProcessor, separator){
  this.__construct(id, viewProcessor, separator);
}

__rageLib.rageView.Processor.prototype = {
  id: null,
  params: [],
  ajax: null,
  actPage: '',
  separator: '_||_',
  post_id_key: null,
  __construct: function(id, viewProcessor, separator){
    this.id = id;
    __rageViewController.saveView(this.id, this);
    this.separator = separator;
    this.params['URL'] = viewProcessor;
    this.params['ON_SUCCESS'] = function(XmlHttp){
      var t = XmlHttp.responseText.split(__rageViewController.getView(id).separator);
      if(t[1] == 'UPDATE_FULL_VIEW'){
        document.getElementById(t[0]+'_container').innerHTML = t[2];
      }else{
        //alert(XmlHttp.responseText);
      }
    };
    //alert(__rageAJAXController.ajax[0].params['ON_SUCCESS']);
    this.ajax = new __rageLib.rageAJAX(this.params);
  },
  process: function(page){
    this.ajax.postParams = page+'&'+this.post_id_key+'='+this.id;
    this.ajax.process();
  },
  reset: function(){
    this.process('');
  },
  reload: function(){
    this.process(this.actPage);
  }
};

