/************************************************************
名称:	
		dataTable.js
功能:
		1.使表格数据行间隔色显示;
		2.鼠标经过行变色;
		3.选中行变色.
参数:
		str_tableid, 			// table id 
		num_header_offset,		// 表头行数 
		num_footer_offset,		// 表尾行数 
		str_odd_color, 			// 奇数行的颜色 
		str_even_color,			// 偶数行的颜色 
		str_mover_color, 		// 鼠标经过行的颜色 
		str_onclick_color 		// 选中行的颜色 
修改:
		1.Fanlei				20070409
示例:
		initDataTable('dataTable',1,1,'#FFFFFF','#DDDDDD','#FFCCFF','#CC99FF');
        initDataTable('dataTable',2,0,'#DDDDDD','#FFFFFF','#F8FCB1','#6766CC'); 
************************************************************/
function initDataTable(str_tableid,num_header_offset,num_footer_offset,str_odd_color,str_even_color,str_mover_color,str_onclick_color)  
{
	var tableObject=document.getElementById(str_tableid);

	// 设置参数的缺省值 
	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:'#DDDDDD');
	col_config.mover_color=(str_mover_color?str_mover_color:'#6699CC');
	col_config.onclick_color=(str_onclick_color?str_onclick_color:'#4C7DAB');
	
	// 初始化表格
	tt_init_table(tableObject,col_config);
}

function tt_init_table(obj_table,col_config)
{
	var col_lconfig=[],
	col_trs=obj_table.rows;
	if(!col_trs) return ;
	 
	for(var i=col_config.header_offset;i<(col_trs.length-col_config.footer_offset);i++)
	{
		// i 从 表头以下开始 
		col_trs[i].config=col_config;
		col_trs[i].lconfig=col_lconfig;
		col_trs[i].set_color=tt_set_color;
		col_trs[i].onmouseover=tt_mover; 
		col_trs[i].onmouseout=tt_mout;
		col_trs[i].onmousedown=tt_onclick;
		col_trs[i].order=(i-col_config.header_offset)%2 ;
		col_trs[i].onmouseout();
	} 
}

function tt_set_color(str_color)
{
	this.style.backgroundColor=str_color;
}
 
// 事件操作 
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()
{
	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();
		}
		this.set_color(this.config.onclick_color);
	} 
} 
