/*
//this file copyright Apposite Ltd 2005
*/
add_event(window, 'load', stripe_tables);
  
function stripe_tables(e){
    
    /* 
    Applies Stripes to any table with the classname "striped"
    
    Requires a style sheet with the generic 
    
    odd_stripe {background-color: #xxxxxx};
    even_stripe {background-color: #xxxxxx};
    
    styles. This allows for multiple colour schemes on different tables
    
    table_class odd_stripe {
        background-color: #ffffff;
    }
    table_class even_stripe {
        background-color: #eeeeff;
    }
    
    tr.className = 'odd_stripe';
    tr.className = 'even_stripe';
    */
    var stripe_this = function(obj){
        //returns true if we are allowed to stripe this object
        if (obj.className && (obj.className != 'odd_stripe') && (obj.className != 'even_stripe')){
            return false;
        }
        else if (obj.style.backcolor){
            return false;
        }
        else {
            return true;
        }
    }
    
    
    var stripe_table = function (table){        
        // the flag we'll use to keep track of 
        // whether the current row is odd or even
        var even = false;
    
        // by definition, tables can have more than one tbody
        // element, so we'll have to get the list of child
        // <tbody> 
        var tbodies = table.getElementsByTagName("tbody");
        
        // and iterate through them...
        for (var b=0; b<tbodies.length; b++) {
            
            // find all the <tr> elements... 
            var rows = tbodies[b].getElementsByTagName("tr");
            
            // ... and iterate through them
            for (var r=0; r<rows.length; r++){
            
                // avoid rows that have a class attribute
                // or backgroundColor style
                if (stripe_this(rows[r])){
                    
                    // get all the cells in this row...
                    var tds = rows[r].getElementsByTagName("td");
                    
                    rows[r].className = even ? 'even_stripe' : 'odd_stripe';
                    // and iterate through them...
                    for (var c=0; c<tds.length; c++) {
                        if (stripe_this(tds[c])){
                            tds[c].className = even ? 'even_stripe' : 'odd_stripe';
                        }
                    }
                }
                // flip from odd to even, or vice-versa
                even =  !(even);
            }
        }
    }
    
    var tables = getElementsByClass('striped','table');
    
    for (var i=0; i<tables.length; i++){
        stripe_table(tables[i]);
    }
}
   
