//nicetable.js

/*
This code calls formatTable() on all tables with <p class = "DOMTable"> in the top left hand cell. 
These tables must reside within a <td id = "mc"> tag. 
*/


if(document.getElementById){
	var mc = document.getElementById("mc");
	var ts = mc.getElementsByTagName("table");
	for(var i=0; i<ts.length; i++){
		var n = ts[i].rows[0].cells[0].firstChild;
		if(n && n.nodeType==3 && n.nodeValue.search(/\w/)==-1){
			n = n.nextSibling;
		}
		if(n && n.className == "DOMTable"){
			formatTable(ts[i]);
		}
	}
}


/*
Logic breakdown
Line 10: get the <td> cell with id = mc
Line 11: get all tables contained within the mc <td> and assign to ts array
Line 12: loop through the ts array
Line 13: assign var n to firstChild of top left cell of table (tables to be styled will have a <p class="DOMTable"> as firstChild)
Line 14 - 15: (next if appears a little spurious but seems to imply if there is a firstChild and nodeType = 3 (text)
 			   and its value is not a word character n = nextSibling). Code is required - do not delete!!
Line 17 - 18: if there is a firstChild and its className is "DOMTable" then run formatTable()
*/