<public:attach event="ondocumentready" handler="onDocumentReady" />
<script language="JScript">
var firstTime = true;
var rgWidths = new Array();
function onDocumentReady()
{
	var tblHeader = this.all.item("tblHeader");
	var tblBody = this.all.item("tblBody");
	var tblFixedLayout = this.all.item("tblFixedLayout");

	if (firstTime && tblHeader.rows.length <= 0 && tblBody != null)
	{
		// Determine column widths
		for(var count=0; count < HeaderRows; count++)
		{	
			var colspan = 0;
			var rowColsWidth = new Array()

			for (var i = 0; i < tblBody.rows[count].cells.length; i++)
			{
				rowColsWidth[i] = tblBody.rows[count].cells[i].offsetWidth;
				colspan+= tblBody.rows[count].cells[i].colSpan;
			}
			rgWidths[count] = rowColsWidth;
		}
	
		// Build Header	
		var tbdyHeader = document.createElement("TBODY");
		tblHeader.appendChild(tbdyHeader);
		for(var count=0; count < HeaderRows; count++)
		{
			tbdyHeader.appendChild(tblBody.rows[0].cloneNode(true));
			tblBody.rows[0].removeNode(true);
		}
		
		// Set column widths of all but the last column
		var NumOfRows = rgWidths.length > 2 ? rgWidths.length - 1 : rgWidths.length;
		for (var count = 0; count < NumOfRows; count++)
		{
			for (var i = 0; i < rgWidths[count].length - 1; i++)
			{
				if (rgWidths[count][i] > 0)
				{
					tblHeader.rows[count].cells[i].width = rgWidths[count][i];
					
					if (tblBody.rows.length > count)
					{
						tblBody.rows[count].cells[i].width   = rgWidths[count][i];
					}// if (tblBody.rows.length > i)
				}// if (rgWidths[count][i] > 0)
			
				if (i == (rgWidths[count].length - 2))
				{
					if (tblBody.rows.length > count)
					{
						tblBody.rows[count].cells[i + 1].width = "1px";
					}// if (tblBody.rows.length > i)
					
					tblHeader.rows[count].cells[i + 1].width = "1px";
				}// if (i == (rgWidths[count].length - 2))
			}
		}
	  // synchronize scrolls
	  addScrollSynchronization(this.all.item("divHeader"), this.all.item("divBody"), "horizontal");
   }// if (firstTime && tblHeader.rows.length <= 0)

	this.height = "100%";
	this.width = "100%";
 
   // disable formatting for next time.
   firstTime = false;
}

/*Begin Helper Methods for scroll sync.*/
// This is a function that returns a function that is used
// in the event listener
function getOnScrollFunction(oElement) {
	return function () {
		if (oElement._scrollSyncDirection == "horizontal" || oElement._scrollSyncDirection == "both")
			oElement.scrollLeft = event.srcElement.scrollLeft;
		if (oElement._scrollSyncDirection == "vertical" || oElement._scrollSyncDirection == "both")
			oElement.scrollTop = event.srcElement.scrollTop;
	};

}
// This function adds scroll syncronization for the fromElement to the toElement
// this means that the fromElement will be updated when the toElement is scrolled
function addScrollSynchronization(fromElement, toElement, direction) {
	removeScrollSynchronization(fromElement);
	
	fromElement._syncScroll = getOnScrollFunction(fromElement);
	fromElement._scrollSyncDirection = direction;
	fromElement._syncTo = toElement;
	toElement.attachEvent("onscroll", fromElement._syncScroll);
}
// removes the scroll synchronization for an element
function removeScrollSynchronization(fromElement) {
	if (fromElement._syncTo != null)
		fromElement._syncTo.detachEvent("onscroll", fromElement._syncScroll);

	fromElement._syncTo = null;;
	fromElement._syncScroll = null;
	fromElement._scrollSyncDirection = null;
}
/*End Helper Methods for scroll sync.*/
</script>