var proxIdDesenv = 0;
var proxIdTrein = 0;
var proxIdFami = 0;

function load(){
	//var tblD = document.getElementById('tb_aDesenv');
	//proxIdDesenv = tblD.rows.length;
	//var tblT = document.getElementById('tb_nTreinam');
	//proxIdTrein = tblT.rows.length;
}

function apagaLinhaPorId(idlinha, idTabela){
	var Linha = document.getElementById(idlinha);
	var tbl = document.getElementById(idTabela);
	var posicao = Linha.rowIndex;
	tbl.deleteRow(posicao);
	mudarCores(tbl);
}


function apagaLinha(idlinha){
	var Linha = document.getElementById(idlinha);
	var tbl = document.getElementById('tb_aDesenv');
	var posicao = Linha.rowIndex;
	tbl.deleteRow(posicao);
	mudarCores(tbl);
}

function apagaLinhaT(idlinhaT){
	var LinhaT = document.getElementById(idlinhaT);
	var tbl = document.getElementById('tb_nTreinam');
	var posicao = LinhaT.rowIndex;
	tbl.deleteRow(posicao);
	mudarCores(tbl);
}

function mudarCores(table){
	var linha = table.rows;
	for(i=1;i<linha.length;++i){
		if((i%2)==0) linha[i].style.backgroundColor = "#f1f1f1";
		else linha[i].style.backgroundColor = "#ffffff";
	}
}

function addItemDesenv(){
    var tableRef = document.getElementById('tb_aDesenv');
    var newRow   = tableRef.insertRow(tableRef.rows.length);
	newRow.id    = "linha"+proxIdDesenv;
	
	var aux = document.getElementById("linha"+tableRef.rows.length-1);
    var newCell0  = newRow.insertCell(0); 
    
	var input = document.createElement("input");
	input.type = "text";
	input.name = "dsnv_acao[]";
	input.maxLength = "255";
	input.style.width = "283px";
	
	newCell0.appendChild(input);
	
    var newCell1  = newRow.insertCell(1);
    
	var select = document.createElement("select");
	select.className = "combo";
	select.name = "dsnv_prioridade[]";	
	
	criarOption(select,"(Selecione)","");
	criarOption(select,"Alta");
	criarOption(select,"M�dia");
	criarOption(select,"Baixa");
	
	newCell1.appendChild(select);
	
  	var newCell2  = newRow.insertCell(2);
	newCell2.align = "center";
 	
 	var image = document.createElement('img');
	image.alt = 'Excluir';
	image.height = '16';
	image.width = '16';
	image.src = 'imagens/lixeira.gif';
	image.onclick = function(){ apagaLinha(newRow.id); }
	newCell2.appendChild(image);
	
	mudarCores(tableRef);
	++proxIdDesenv;
}

function addItemFamiliar()
{

	var tblFami = document.getElementById('tb_Fami');
	proxIdFami = tblFami.rows.length;

    var newRow   = tblFami.insertRow(proxIdFami);
	newRow.id    = "linhaFami"+proxIdFami;

    var newCell0  = newRow.insertCell(0);
    
    var input = document.createElement("input");
	input.type = "text";
	input.name = "fami_primeiro_nome[]";
	input.maxLength = "255";
	input.style.width = "96px";
	
	newCell0.appendChild(input);
	
    var newCell1  = newRow.insertCell(1);
    
	var input2 = document.createElement("input");
	input2.type = "text";
	input2.name = "fami_parentesco[]";
	input2.maxLength = "255";
	input2.style.width = "71px";
	
	newCell1.appendChild(input2);

		
    var newCell2  = newRow.insertCell(2);
    
	var input3 = document.createElement("input");
	input3.type = "text";
	input3.name = "fami_idade[]";
	input3.maxLength = "3";
	input3.style.width = "36px";
	newCell2.appendChild(input3);


	
	var newCell3  = newRow.insertCell(3);
    
	var select = document.createElement("select");
	select.style.width = "94px";
	select.name = "fami_estado_civil[]";	
	criarOption(select,"(Selecione)","");
	criarOption(select,"Solteiro(a)","S");
	criarOption(select,"Casado(a)","C");
	criarOption(select,"Divorciado(a)","D");
	criarOption(select,"Viúvo(a)","V");
	criarOption(select,"Outro","O");
	newCell3.appendChild(select);
	
    var newCell4  = newRow.insertCell(4);
	var input4 = document.createElement("input");
	input4.type = "text";
	input4.name = "fami_cpf[]";
	input4.maxLength = "255";
	input4.style.width = "84px";
	newCell4.appendChild(input4);

    var newCell5  = newRow.insertCell(5);
	var input5 = document.createElement("input");
	input5.type = "text";
	input5.name = "fami_profissao_remunerada_atual[]";
	input5.maxLength = "255";
	input5.style.width = "91px";
	newCell5.appendChild(input5);

    var newCell6  = newRow.insertCell(6);
	var input6 = document.createElement("input");
	input6.type = "text";
	input6.name = "fami_salario_renda_mensal[]";
	input6.maxLength = "255";
	input6.style.width = "71px";
	newCell6.appendChild(input6);	
	
	var newCell7  = newRow.insertCell(7);
	select.className = "comandos";

	var image = document.createElement('img');
	image.alt = 'Excluir';
	image.className = 'bordazero';
	image.src = 'imagens/deletar.gif';
	image.onclick = function(){ apagaLinhaPorId(newRow.id, tblFami.id); }
	newCell7.appendChild(image);
	
	$("[name$='fami_cpf[]']").mask("99999999999");
	$("[name$='fami_salario_renda_mensal[]']").maskMoney({symbol:"R$",decimal:",",thousands:"."});
	
	
	//++proxIdFami;
	
}

function addItemCPF()
{

	var tblCPF = document.getElementById('tb_CPF');
	proxIdCPF = tblCPF.rows.length;

    var newRow   = tblCPF.insertRow(proxIdCPF);
	newRow.id    = "linhaCPF"+proxIdCPF;

    var newCell0  = newRow.insertCell(0);
    
    var input = document.createElement("input");
	input.type = "text";
	input.name = "pesc_cpf[]";
	input.maxLength = "14";
	input.style.width = "94px";
	
	newCell0.appendChild(input);

	var newCell1  = newRow.insertCell(1);
	newCell1.className = "semborda";
	var image = document.createElement('img');
	image.alt = 'Excluir';
	image.className = 'bordazero';
	image.src = 'imagens/deletar.gif';
	image.onclick = function(){ apagaLinhaPorId(newRow.id, tblCPF.id); }
	newCell1.appendChild(image);
	
	$("[name$='pesc_cpf[]']").mask("99999999999");
	
	//++proxIdFami;
}


function addItemDesp()
{

	var tblDesp = document.getElementById('tb_Desp');
	proxIdDesp = tblDesp.rows.length;

    var newRow   = tblDesp.insertRow(proxIdDesp);
	newRow.id    = "linhaDesp"+proxIdDesp;

    var newCell0  = newRow.insertCell(0);
    
    var input = document.createElement("input");
	input.type = "text";
	input.name = "desp_descricao[]";
	input.maxLength = "255";
	input.style.width = "94px";
	
	newCell0.appendChild(input);
	
    var newCell1  = newRow.insertCell(1);
	var input1 = document.createElement("input");
	input1.type = "text";
	input1.name = "desp_valor[]";
	input1.maxLength = "255";
	input1.style.width = "78px";
	newCell1.appendChild(input1);	

	var newCell2  = newRow.insertCell(2);
	var image = document.createElement('img');
	image.alt = 'Excluir';
	image.className = 'bordazero';
	image.src = 'imagens/deletar.gif';
	image.onclick = function(){ apagaLinhaPorId(newRow.id, tblDesp.id); }
	newCell2.appendChild(image);
	
	$("[name$='desp_valor[]']").maskMoney({symbol:"R$",decimal:",",thousands:"."});

	
	//++proxIdFami;
}

function criarOption(select,texto,valor){
	// definir valor default para a vari�vel "valor".
	if(typeof valor == 'undefined') { valor = texto; }
	var option = document.createElement("option");
	var text = document.createTextNode(texto);
	option.value = valor;
	option.appendChild(text);
	select.appendChild(option);
}

