var SELECTED_ROWS = Array();

function alternate_table (
		str_tableid, // table id (req.)
		num_header_offset, // how many rows to skip before applying effects at the begining (opt.)
		num_footer_offset, // how many rows to skip at the bottom of the table (opt.)
		str_odd_color, // background color for odd rows (opt.)
		str_even_color, // background color for even rows (opt.)
		str_mover_color, // background color for rows with mouse over (opt.)
		str_onclick_color, // background color for marked rows (opt.)
		str_onselect_color // background color for selected rows (opt.)
	) {

	// SKIP NON DOM BROWSERS
	if (typeof(document.all) != "object") {
		//return;
	}

	// VALIDATE REQUIRED PARAMETERS
	if (!str_tableid){
		return ;
	}
	
	var obj_tables = (document.all ? document.all[str_tableid] : document.getElementById(str_tableid));
	if (!obj_tables){
		return ;
	}
	
	// SET DEFAULTS FOR OPTIONAL PARAMETERS
	var col_config = [];
	col_config.header_offset = (num_header_offset ? num_header_offset : 0);
	col_config.footer_offset = (num_footer_offset ? num_footer_offset : 0);
	col_config.odd_color = (str_odd_color ? str_odd_color : "#FFFFFF");
	col_config.even_color = (str_even_color ? str_even_color : "#DBEAF5");
	col_config.mover_color = (str_mover_color ? str_mover_color : "#6699CC");
	col_config.onclick_color = (str_onclick_color ? str_onclick_color : "#4C7DAB");
	col_config.onselect_color = (str_onselect_color ? str_onselect_color : "#ff0000");
	
	// INIT MULTIPLE TABLES WITH SAME ID
	if (obj_tables.length){
		for (var i = 0; i < obj_tables.length; i++){
			tt_init_table(obj_tables[i], col_config);
		}
	}
	// INIT SINGLE TABLE
	else{
		tt_init_table(obj_tables, col_config);
	}
}

function tt_init_table (obj_table, col_config) {
	
	var col_lconfig = [], col_trs = obj_table.rows;
	var new_cols= Array();
	var j=0;
	
	for (var i = col_config.header_offset; i < col_trs.length - col_config.footer_offset; i++) {
		if(col_trs[i].style.display != "none"){
			new_cols[j] = col_trs[i];	
			j++;	
		}
	}
	for (var j = 0; j < new_cols.length ; j++) {
		
		new_cols[j].config = col_config;
		new_cols[j].lconfig = col_lconfig;
		new_cols[j].set_color = tt_set_color;
		new_cols[j].onmouseover = tt_mover; 
		new_cols[j].onmouseout = tt_mout;
		new_cols[j].onmousedown = tt_onclick;
		new_cols[j].order = j % 2;
		new_cols[j].onmouseout();
		
	}
}

function tt_set_color(str_color) {
	this.style.backgroundColor = str_color;
}

// EVENT HANDLERS
function tt_mover () {
	
	if (this.lconfig.clicked != this){
		this.set_color(this.config.mover_color);
	}
	
}

function tt_mout () {
	
	if (this.lconfig.clicked != this){
		this.set_color(this.order ? this.config.odd_color : this.config.even_color);
	}
		
}

function tt_onclick () {
	
	eval("var chbx_object = this.childNodes[0].childNodes[0];");
	if (this.lconfig.clicked == this) {
		this.lconfig.clicked = null;
		this.onmouseover();
	}
	else {
		var last_clicked = this.lconfig.clicked;
		this.lconfig.clicked = this;
		if (last_clicked){
			last_clicked.onmouseout();
		}
		
		/*
		if (chbx_object.checked == true) {
			//this.set_color(this.config.onselect_color);
			this.set_color(this.config.onclick_color);
		}
		else {
			this.set_color(this.config.onclick_color);
		}
		*/
	}
		
}

