function tr_colors_func() { this.tr_colorsClass = "tr_colors"; // default class name this.color1 = "#FFFFFF"; // default this.color2 = "#F3F3F3"; // default this.firstRowColor = "#FFFFFF"; // default this.allTables = []; this.tr_colorsTables = []; this.firstRow = true; this.old_onload = window.onload; window.onload = this.init; window.tr_colorsReference = this; }; tr_colors_func.prototype.noFirstRow = tr_colors_noFirstRow; tr_colors_func.prototype.init = tr_colors_init; tr_colors_func.prototype.setColor1 = tr_colors_setColor1; tr_colors_func.prototype.setColor2 = tr_colors_setColor2; tr_colors_func.prototype.setFirstRowColor = tr_colors_setFirstRowColor; tr_colors_func.prototype.quickHexTest = function( hexColor ) { if( hexColor.indexOf("#") == -1 ){ hexColor = "#" + hexColor}; var RE1 = /#[0-9A-Ga-g]{6}/; return RE1.test(hexColor); }; // ------------------------------------------------------ tr_colors_init function tr_colors_init() { if( !document.getElementsByTagName ){ return; }; var tr_colors = window.tr_colorsReference; tr_colors.allTables = document.getElementsByTagName("table"); for(var i=0; i < tr_colors.allTables.length; i++) { if( tr_colors.allTables[i].className.toLowerCase().indexOf(tr_colors.tr_colorsClass.toLowerCase()) != -1 ) { tr_colors.tr_colorsTables = tr_colors.tr_colorsTables.concat( tr_colors.allTables[i] ); }; }; if(tr_colors.tr_colorsTables.length < 1){ return; }; for(var jab = 0; jab < tr_colors.tr_colorsTables.length; jab++) { var table = tr_colors.tr_colorsTables[jab]; if(tr_colors.firstRow) { table.rows[0].bgColor = tr_colors.firstRowColor; }; var rowCount; (tr_colors.firstRow) ? (rowCount = 1) : (rowCount = 0); for(rowCount; rowCount < table.rows.length; rowCount++) { var tableRow = table.rows[rowCount]; var rowColor; (rowCount%2 == 0) ? (rowColor = tr_colors.color1) : (rowColor = tr_colors.color2); tableRow.bgColor = rowColor; }; }; }; // ------------------------------------------------------ tr_colors_noFirstRow function tr_colors_noFirstRow() { this.firstRow = false; }; // ------------------------------------------------------ tr_colors_setColor1 function tr_colors_setColor1( hexColor ) { if( this.quickHexTest(hexColor) ){ this.color1 = hexColor; }; return; }; // ------------------------------------------------------ tr_colors_setColor2 function tr_colors_setColor2( hexColor ) { if( this.quickHexTest(hexColor) ){ this.color2 = hexColor; }; return; }; // ------------------------------------------------------ tr_colors_setFirstRowColor function tr_colors_setFirstRowColor( hexColor ) { if( this.quickHexTest(hexColor) ){ this.firstRowColor = hexColor; }; return; }; // instantiation call var tr_colors = new tr_colors_func();