  

function $(elem) {
	if (typeof(elem)=="string") {
        	elem = document.getElementById(elem);
	}
    if (elem == null) {
        elem = undefined;
    }
    return elem;
}

function $$(elem) {
    elem = $(elem);
    var ret = [];
    for (filho in elem) {
        ret.push(filho);
    }
    return ret;
}

function FilhosTxt(elem) {
    var txt = "";
	elem = $$(elem);
    for (obj in elem) {
        txt += obj + ":" + elem[obj] + "; ";
    }
    return txt;
}



    function OpcaoCarrega(select, itens) {
        itens = itens.split(";");
        var opcao;
        for(var z=0;z<itens.length;z+=2) {
            opcao = document.createElement("option");
            opcao.value = itens[z];
            opcao.innerText = itens[z+1];
            select.appendChild(opcao);
        }
    }
    
    function RemoveLinha(linha) {
        var ctllinha = $("linha_"+linha);
        ctllinha.parentNode.deleteRow(ctllinha.rowIndex);
	qtdlinhas--;
    }

    function InsereLinha(linha) {
     if (linha < 100)  {

        var doc = document;
        var novalinha = doc.createElement("TR");
        novalinha.id = "linha_" + linha;

        var novacol = doc.createElement("TD");
        var novoctl = doc.createElement("input");
        novoctl.id = "emp_" + linha;
        novoctl.name = "emp_" + linha;
	    novoctl.style.width = "175px";
	    novoctl.style.fontSize = "8pt"
	    novoctl.style.margin = "0px 5px 0px 0px";
    	novoctl.onchange = new Function("VerSeInsere("+linha+");");
        novacol.appendChild(novoctl);
        novalinha.appendChild(novacol);

        novacol = doc.createElement("TD");
        novoctl = doc.createElement("select");
	    novoctl.style.width = " 105px";
	    novoctl.style.fontSize = "8pt"
	    novoctl.style.margin = "0px 0px 0px 0px";
        novoctl.id = "rel_" + linha;
        novoctl.name = "rel_" + linha;
        OpcaoCarrega(novoctl,";;A;acionista;C;consultor;CC;conselho consultivo;D;diretor;E;empregado;F;fundador;I;investigador;O;outros;P;palestrante;PR;proprietário");
	    novoctl.onchange = new Function("VerSeInsere("+linha+");");
        novacol.appendChild(novoctl);
        novalinha.appendChild(novacol);

        novacol = doc.createElement("TD");
        novoctl = doc.createElement("select");
	novoctl.style.width = " 160px";
	novoctl.style.fontSize = "8pt"
	novoctl.style.margin = "0px 5px 0px 5px";
        novoctl.id = "nat_" + linha;
        novoctl.name = "nat_" + linha;
        OpcaoCarrega(novoctl,";;A;ações;DP;direitos propriedade inetlectual;E;equipamentos;H;honorários;NC;nenhuma compensação recebida;R;royalties;RE;financiamento residência médica;S;salário;V;verbas de órgãos de fomento");
	novoctl.onchange = new Function("VerSeInsere("+linha+");");
        novacol.appendChild(novoctl);
	novalinha.appendChild(novacol);
	
	    novacol = doc.createElement("TD");
        novoctl = doc.createElement("input");
	    novoctl.className = "form-botao";
	    novoctl.style.width = "45px";
	    novoctl.style.margin = "0px 0px 0px 0px";
        novoctl.type = "button";
        novoctl.id = "btnexclui_"+linha;
        novoctl.value = "Excluir";
        novoctl.onclick = new Function("RemoveLinha(" + linha + ")");
        novacol.appendChild(novoctl);

        novalinha.appendChild(novacol);

        $("tb_rel_bd").appendChild(novalinha);
	qtdlinhas++;
     }
    }


     function VerSeInsere(linha) {
	if (linha == nlinha-1) {
		if ($("emp_"+linha).value != "" && $("rel_"+linha).value !="" && $("nat_"+linha).value != "") {
			InsereLinha(nlinha++);
		}
	}
	
     }


