/**
Funções utilitárias para manipulação de objetos <table>

funções:
	- tabInserirLinha(tabela, conteudoHTML): Insere linhas em uma tabela.
	- tabRemoverLinha(objetoLinha): Remove o objeto <tr> da tabela.
	- tabZebrar(tabela, i): Realiza o efeito zebrado em uma tabela a partir da linha 'i'.
Dependêcnias:
	- prototype.js

@author Diego C. Amaral
*/

//As linhas são inseridas na última posição dentro do elemento <TBODY>
//@author Diego C. Amaral
function tabInserirLinha(tabelaId, html){
	try{
		var _tabela = $(tabelaId);
//		_tabela.insertRow(_tabela.rows.length).innerHTML = html; //Não funciona para <tbody> no IE.
		Element.Methods.update(tabelaId, $(tabelaId).innerHTML+html+'\n');
	}catch(e){}
}

//Remove uma linha '<tr>' de uma tabela <tbody> ou <table>
//@author Diego Amaral
function tabRemoverLinha(_oLinha){
	var _linha = _oLinha.rowIndex;
	_oLinha.parentNode.deleteRow(_linha);
	return _linha;
}

//Adiciona o efeito zebrado em uma tabela. O parâmetro pode ser a id ou o objeto <table>
//As cores devem ser mudadas de acordo com o padrão de design estabelecido.
//@author Diego Amaral
function tabZebrar(_idTabela, _linhaInicial){
	if(typeof _idTabela == 'string')
		tabela = $(_idTabela);
	else
		tabela = _idTabela;
	var _linhas = tabela.getElementsByTagName("tr");
	for(var i=_linhaInicial; i<_linhas.length; i++){
		if(Element.visible(_linhas[i]))
			_linhas[i].bgColor = (i%2!=0) ? '#CCD6EC' : '#ffffff';
	}
}

