var docCellHeightsArr = new Array();
var i = 0;

// Put the Cell ID's in an array
function docCellChangeHeight(cellid, heightpercent) {
	docCellHeightsArr[i] = new Array(cellid, heightpercent);
	i++;
}

var x = 0;
// Read out the Cell ID's and change the heights
function exexuteDocCellChangeHeight() {
	var size = docCellHeightsArr.length;
	var cellid;
	var height;
	var cell;
	var parentCell;
	var parentTable;
	var parentCellSize;
	var cellSize;
	
	while( x < size ) {
		cellid = docCellHeightsArr[x][0];
		height = docCellHeightsArr[x][1];
		
		cell = document.getElementById(cellid);
		// From TD -> TR -> TBODY (DOM) -> TABLE
		parentTable = cell.parentNode.parentNode.parentNode;
		// TABLE -> TD
		parentCell = parentTable.parentNode;
		
		parentCellSize = parentCell.clientHeight;
		cellSize = cell.offsetHeight;
		
		var paddingLength = parentCell.style.paddingTop.length - 2;
		var paddingTop = parseInt( parentCell.style.paddingTop.substr(0, paddingLength ) );
		if(isNaN(paddingTop)) {
			paddingTop = 0;
		}
		
		var paddingLength = parentCell.style.paddingBottom.length - 2;
		var paddingBottom = parseInt( parentCell.style.paddingBottom.substr(0, paddingLength ) );
		if(isNaN(paddingBottom)) {
			paddingBottom = 0;
		}
		
		var totalPadding = paddingBottom + paddingTop;
		
		if( totalPadding > 0 ) {
			height = height - totalPadding;
		}
		
		if( parentCellSize > cellSize ) {
			//alert( parentCellSize + " > " + cellSize );
			parentTable.style.height = ((height / 100 ) * parentCellSize);
		}
		
		x++;
	}
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// Execute after page load
addLoadEvent(exexuteDocCellChangeHeight);
