function appendClass(elm, appClass)
{
	/* only add space if currClass non-empty */
	elm.className += (elm.className? ' ':'') + appClass;
}

function removeClass(elm, className)
{
	/* Replace className, and surrounding spaces, with a single space;
	Trim end (since space may have been added to end) */
	elm.className = elm.className.replace(new RegExp('\s*'+className+'\s*'),' ').trim();
}

/* always handy */ 
String.prototype.trim = function(){ return this.replace(/^\s*?\s*$/g,"")} 
	
function stripeTable(table) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = arguments[1] ? arguments[1] : false;
   
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    if (typeof(table) != 'object')
    	table = document.getElementById(table);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = [];
    tbodies.push(table);
    if(table.tagName.toLowerCase() != 'tbody')
    {
    	tbodies = table.getElementsByTagName("tbody");
    }

    for (var h = 0; h < tbodies.length; h++)
    {
      var trs = tbodies[h].getElementsByTagName("tr");
      for (var i = 0; i < trs.length; i++)
      {
     		removeClass(trs[i], 'alt1');
     		removeClass(trs[i], 'alt2');
     		if(even)
     			appendClass(trs[i],'alt1');
     		else
     			appendClass(trs[i],'alt2')
     			even =  ! even;
       }
    }
}
