/*
	wildlawMU.js
	Created 2007 by Radiant Core Inc. for Wildeboer Dellelce LLP
	Removes in-line styling and assigns semantic ids and classes to Market Update table to permit styling with CSS,
	while complying with provider's requirement that copyright and source be displayed to the end user.

	Tested in Fx 2.0 Mac & Windows, Safari 3 Beta, Internet Explorer 6 & 7.
*/

/* This should be the only center tag on the homepage. We will use it to locate the inserted market update table */
mainTable = document.getElementsByTagName('center')[0].firstChild;
mainTable.id = 'muTable';

mainTableBody = mainTable.tBodies[0];

/* The title td is the first td in the table's first row. Set an ID ('muTitle')  and strip font tags  */
titleTd = mainTableBody.rows[0].cells[0];
titleTd.id = 'muTitle';
titleTd.innerHTML = '<h2>' + titleTd.firstChild.firstChild.innerHTML + '</h2>';

/* We'll address the column headings by a common className ('muHeading'). Assigning it here and stripping font tags */
headingsTr = mainTableBody.rows[1];
for (var cellCount = 0; cellCount < headingsTr.cells.length; cellCount++) {
	thisHeading = headingsTr.cells[cellCount];
	thisHeading.className = 'muHeading';
	if (cellCount == 0) {
		thisHeading.className = 'muHeading first';
	}
	thisHeading.innerHTML = thisHeading.firstChild.innerHTML;
}

/* Now we set up the data rows for adjustment. As they're part of the same tbody, we'll have to start our iteration at row 2 (0,1,...n) */
for (var rowCount = 2; rowCount < mainTableBody.rows.length - 1; rowCount ++) {
	thisRow = mainTableBody.rows[rowCount];
	thisRow.className = 'muData';
	thisRowChange = ''; /* This will be set depending on whether the arrow image is pointing up or down */

	for (var cellCount = 0; cellCount < thisRow.cells.length; cellCount ++) {

		thisCell = thisRow.cells[cellCount];

		/* Remove in-line padding */
		thisCell.style.padding = '';

		/* The first and third cells contain anchors with enclosed font tags which we want to clear */
		if (cellCount == 0 || cellCount == 2) {
			thisCell.firstChild.innerHTML = thisCell.firstChild.childNodes[0].innerHTML;
		}

		/* The second cell contains an image of an arrow indicating rise or fall */
		if (cellCount == 1) {
			thisImageSrc = thisCell.childNodes[0].getAttribute('src');
			if (thisImageSrc == 'http://www.thefinancials.com/images/uparrow.gif') {
				thisCell.firstChild.className="muIncreased";
				thisRowChange = 'Increase';
			} else {
				thisCell.firstChild.className="muDecreased";
				thisRowChange = 'Decrease';
			}
		}

		/* The fourth cell contains the change value. This needs to have its font tag stripped, and a class appropriate to rise or fall applied */
		if (cellCount == 3) {
			thisCell.innerHTML = thisCell.firstChild.innerHTML;
			thisCell.className = 'mu' + thisRowChange;
		}
	}
}

/* The data provider includes a horizontal rule beneath the data table. Removing it */
mainTableBody.rows[rowCount].cells[0].innerHTML = '';

mainTable = document.getElementsByTagName('center')[1].id = 'muCredits';