var W3CDOM = (document.createElement && document.getElementsByTagName);
var altRowClr = "#E0E0E0";

addEvent(window, 'load', initAlternateRows);

function addEvent(obj, eventType,fn, useCapture)
{
	if (obj.addEventListener) {
		obj.addEventListener(eventType, fn, useCapture);
		return true;
	} else {
		if (obj.attachEvent) {
			var r = obj.attachEvent("on"+eventType, fn);
			return r;
		}
	}
}

// this function is needed to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
   var result = false;
   if (obj.getAttributeNode("class") != null) {
       result = obj.getAttributeNode("class").value;
   }
   return result;
}  


function initAlternateRows()
{
	if (!W3CDOM) return;
    // get a list of all the tables
    var tables = document.getElementsByTagName('table');
    // if there aren't any tables exit
    if (tables.length==0) { return; }
    // and iterate through them...
    for (var k = 0; k < tables.length; k++) {
        // if the table has a class
        if (hasClass(tables[k])) {
            // if that class is "altrows"
            if (tables[k].getAttributeNode('class').value.indexOf('altrows')!=-1) {
                var tbodies = tables[k].getElementsByTagName('tbody');
                // iterate through the bodies...
                for (var h = 0; h < tbodies.length; h++) {
                    // find all the &lt;tr&gt; elements... 
                    var trs = tbodies[h].getElementsByTagName('tr');
                    // ... and iterate through them
                    for (var i = 0; i < trs.length; i++) {
                    // Mark every other row an alternate color - 2007-11-04 sdw
                        if (i%2>=1) {
                            trs[i].style.backgroundColor = altRowClr;
                        }
                    }
                }
            }
        } 
    } // End for loop  
}
