    var fnAfterTableRowAdded = null;
    var fnAfterTableRowRemoved = null;
    var fnPostDisplayEvent = null;
    
    function ObmepTable(name,parentElementName) {

      this.name = name;
      this.theadName = null;
      this.alignment = null;
      window[name] = this;
      this.parentElementName = parentElementName;
      this.columns = new Array();
      this.dataModel = new Array();
      this.showAddLink = true;
      this.showRemoveLink = true;
      this.disabled = false;
      this.removeHTMLIcon = "<img src=\"images/excluir.gif\"/>";
      this.addHTMLIcon = "<img src=\"images/plus-button.gif\" width=\"16px\" height=\"17px\"/>";

      // Assinatura dos metodos:   
      this.setColumns = setColumns;
      this.display = display;
      this.addRow = addRow;
      this.removeRow = removeRow;
      this.rowCount = rowCount;
      
    }
    
    function rowCount() {
      return this.dataModel.length;
    }

    function setColumns(columns) {
      this.columns = columns;
    }

    /*
     * Adiciona uma nova linha na tabela.
     */
    function addRow(rowData) {
       this.dataModel[ this.rowCount() ] = rowData;
       
       if (fnAfterTableRowAdded != null) {
          fnAfterTableRowAdded(this);
       }
    }

    function removeRow(index) {
        this.dataModel.splice(index,1);
        var tbody = document.getElementById("tbody_"+this.name);
        var trRemove = tbody.childNodes[index];
        trRemove.parentNode.removeChild(trRemove);
        
        this.display();
        
        if (fnAfterTableRowRemoved != null) {
          fnAfterTableRowRemoved(this);
        }
    }

    function display() {

        var parentNode = document.getElementById(this.parentElementName);

        var table = document.getElementById(this.name);
        if (table == null) {
	       table = document.createElement("table");
           table.setAttribute("id", this.name);
           table.setAttribute("class","list");
           parentNode.appendChild(table);     
        }

        if (this.columns.length>0) {

          var thead = (this.theadName!=null) ? document.getElementById(this.theadName) : null;
          if (thead == null) {
            thead = document.createElement("thead");
            thead.setAttribute("id",this.theadName);
            table.appendChild(thead);
          }

	 	  var tr = document.getElementById("thead_tr_"+this.name);
          if (tr == null) {
            tr = document.createElement("tr");
            tr.setAttribute("id","thead_tr_"+this.name);
            thead.appendChild(tr);
          }

          // Cria e adiciona as colunas dinamicamente.
          for (i in this.columns) {
            var th = (i < tr.childNodes.length) ? tr.childNodes[i] : document.createElement("th");
 	 	    th.innerHTML = this.columns[i];

            if (!(i < tr.childNodes.length)) {
               tr.appendChild(th);
            }

          } // for.

          if (this.showRemoveLink) {
            var th = document.getElementById("thead_tr_remove"+this.name);
            if (th == null) {
				th = document.createElement("th");
				th.setAttribute("id","thead_tr_remove"+this.name);
	 	        th.innerHTML = "";
                tr.appendChild(th);
            }
          }

          if (this.showAddLink) {
            var th = document.getElementById("thead_tr_add"+this.name);
            if (th == null) {
				th = document.createElement("th");
				th.setAttribute("id","thead_tr_add"+this.name);
		 	    th.innerHTML = "";
                tr.appendChild(th);
            }
          }

       }
   
       // Agora exibe os dados do corpo:
       var tbody = document.getElementById("tbody_"+this.name);
       if (tbody == null) {
           tbody = document.createElement("tbody");
           tbody.setAttribute("id","tbody_"+this.name);
   	  	   table.appendChild(tbody);
       }

       // Agora percorro cada linha do modelo de dados e vou preenchendo as linhas:
       for (i in this.dataModel) {
           var tr = (i < tbody.childNodes.length ) ? tbody.childNodes[i] : null;
           if (tr == null) {
             tr = document.createElement("tr");
             tbody.appendChild(tr);
           }

           for (var j=tr.childNodes.length-1;j>=this.dataModel[i].length;j--) {
             tr.removeChild(tr.childNodes[j]);
           }
           
           // Agora percorro cada dado e anexo a linha:
           for (j in this.dataModel[i]) {
              var td = tr.childNodes[j];
              if ( td == null) {
                 td = document.createElement("td");
                 td.setAttribute("align",this.alignment);
                 tr.appendChild(td);
                 td.innerHTML = "";
              }
              if (td.innerHTML == "") {
	              td.innerHTML = this.dataModel[i][j];
	          }
           } // for j.

        // Agora adiciono espaco para remocao de link:
	    if (this.showRemoveLink) {
            td = document.createElement("td");
            td.setAttribute("align",this.alignment);
            td.innerHTML = (this.rowCount()>1 && !this.disabled) ? "<a href=\"javascript: "+this.name+".removeRow("+i+");\" >"+this.removeHTMLIcon+"</a>" : "";
            tr.appendChild(td);
        }

        // Agora adiciono espaco para adicao de link:
	    if (this.showAddLink) {
            td = document.createElement("td");
            td.setAttribute("align",this.alignment);
            td.innerHTML = (i == this.rowCount() - 1 && !this.disabled) ? "<a href=\"javascript: if (fnAddRowEvent!=null) fnAddRowEvent("+this.name+");"+this.name+".display(); if (fnPostDisplayEvent!=null) fnPostDisplayEvent("+this.name+");\">"+this.addHTMLIcon+"</a>" : "";
            tr.appendChild(td);
            
        }
        
       } // for i.

      // alert(""+parentNode.innerHTML);
    }
    