/* ****************************************************************************
Copyright 2007,
Todos los derechos Reservados
CM.COM E.U.
cmhenao@epm.met.co

El uso sin solicitud espresa a la compañia de esta libreria es una clara
violación a la propiedad intelectual y los derechos de autor.
Prohibida su distribucion y/o uso sin el permiso explicito de cm.com
**************************************************************************** */

/* ****************************************************************************
Autor: Jhon Alejandro Ramirez Velez
       Desarrollador
       Progress - WebSpeed
       jhalrave@epm.net.co
**************************************************************************** */

function cHTML(){
  /* *******************************************************************
  ** private properties definition                                    **
  ******************************************************************* */    
  var self = this;
  
  this.cObject    = cObject;
  this.cObject(); 

  /* *******************************************************************
  ** public properties definition                                     **
  ******************************************************************* */    
  
  this.url        = "";
  this.messages   = "";
  this.container  = null;
  this.reload     = false;
  this.params     = {};
  /* *******************************************************************
  ** public functions definition                                      **
  ******************************************************************* */    
  this.refresh            = _refresh;
  this.load               = _load;
  this.get                = _get;
  this.show               = _show;
  this.hide               = _hide;
  this.setUrl             = _setUrl;
  this.setParams          = _setParams;

  /* *******************************************************************
  ** private functions definition                                     **
  ******************************************************************* */
  
  function _load(){
    if(self.url == undefined || self.url == null || self.url == "" ){
      return;
    }    
    if(self.reload){
      if(self.container != undefined && self.container != null){
        self.container.removeNode(true);
        self.container = null;
      }
    }
    if(self.container == null){
      self.container = document.createElement("DIV");
    }      
    
    var sParams = "";
    if(self.params != undefined && self.params != null){
      for(var i in self.params){
        if(self.params[i] instanceof Array){continue;}
        if(self.params[i] instanceof Object){continue;}
        if(self.params[i] instanceof Function){continue;}
        if(sParams != "") sParams += "&";
        if(sParams == "") sParams += "?";        
        sParams += i + "=" + encodeURIComponent(self.params[i]); 
      }    
    }
    
    if(self.url.indexOf('.wsa') == -1){
      window.requester.requestHTMLFragment("GET",  self.url + sParams, self.container);
    }else{
      window.requester.requestHTMLFragment("POST", self.url + sParams, self.container);
    }        
  }  
  
  function _refresh(){
    if(self.reload){
      self.load();
    }
  }
  
  function _setUrl(sUrl){
    var aUrl = sUrl.split('?');
    self.url = aUrl[0];
    if(aUrl.length > 1){
       var aParams = aUrl[1].split('&');
       for(var i = 0; i < aParams.length; i++){
         var oParam = aParams[i].split('=');
         self.params[oParam[0]] = oParam[1];  
       }  
    }
  }
  
  function _setParams(oParams){
    if(oParams != undefined && oParams != null){
      for(var i in oParams){
        if(oParams[i] instanceof Array){continue;}
        if(oParams[i] instanceof Object){continue;}
        if(oParams[i] instanceof Function){continue;}
        self.params[i] = oParams[i];  
      }    
    }
  }
  
  function _get(){
    if(self.container == null){
      self.load();
    }
    return self.container;
  }  
  
  function _show(){
    if(self.container != null){
      self.container.style.display = "";
    }
  }
  
  function _hide(){
    if(self.container != null){
      self.container.style.display = "none";
    }
  }

}


