/*
dynamicTable.js

definition: an object that creates an html table.

constructor ({id: "testTable", border: "0px", cellpadding: "0px", cellspacing: "0px"})
  sets up and returns a table
addTh({id: "", class: ""}, contents);
addTf({id: "", class: ""}, contents);
addTr({id: "", class: ""});
addTd({id: "", class: ""}, contents);
*/


function dynamicTable(attributes) { 
  this.attributes = attributes;
  this.table = this.createNewElement("table", this.attributes);

  this.thead = this.createNewElement("thead", {});
  this.table.appendChild(this.thead);

  this.thr = this.createNewElement("tr", {});
  this.thead.appendChild(this.thr);

  this.tfoot = this.createNewElement("tfoot", {});
  this.table.appendChild(this.tfoot);

  this.tfr = this.createNewElement("tr", {});
  this.tfoot.appendChild(this.tfr);
  
  this.tbody = this.createNewElement("tbody", {});
  this.table.appendChild(this.tbody);
}

dynamicTable.prototype.createTable = function(attributes){
  
}

dynamicTable.prototype.addTh = function(attributes, contents){
  this.lastTh = this.createNewElement("th", attributes);
  this.lastTh.innerHTML = contents;
  this.thr.appendChild(this.lastTh);
  
}

dynamicTable.prototype.addTf = function(attributes, contents){
  this.lastTf = this.createNewElement("th", attributes);
  this.lastTf.innerHTML = contents;
  this.tfr.appendChild(this.lastTf);
}


dynamicTable.prototype.addTr = function(attributes){
  this.lastTr = this.createNewElement("tr", attributes);
  this.tbody.appendChild(this.lastTr);
}

dynamicTable.prototype.addTd = function(attributes, contents){
  this.lastTd = this.createNewElement("td", attributes);
  this.lastTd.innerHTML = contents;
  this.lastTr.appendChild(this.lastTd);
  
}

dynamicTable.prototype.returnTable = function(){
  return this.table;
}

dynamicTable.prototype.setAttribute = function(element, attribute, value){


    element.setAttribute(attribute, value);

    //'cause i.e. don't play by da rules
    if(attribute == "class") element.setAttribute("className", value);
    if(attribute == "onclick" && typeof element.attachEvent !== 'undefined')      
        element.attachEvent("onclick", function () {eval(value)});
}

dynamicTable.prototype.createNewElement = function(elementType, attributes){
  var newElement = document.createElement(elementType);
  for (var obj in attributes){
    this.setAttribute(newElement, obj, attributes[obj]); 
  }
  return newElement;
}