	//Calcula Digito Verificador Cpf
	function valida_cpf(nro){			
					
			texto = nro
			myString = new String(texto)
			rExp = /-/gi;
			texto = myString.replace(rExp,"")
					
			myString = new String(texto)
			rExp = /\./gi;
			texto = myString.replace(rExp,"")
			
			nro = texto

			var soma1=resto=dig1=dig2=0;
								
			for(var i=10; i > 1; i--){
				soma1 += parseInt(nro.substr(nro.length-i-1,1)) * i;
			}
			resto = soma1 % 11;
			switch (resto){
				case 0:
				case 1:
					dig1 = 0;
					break;
				default:
					dig1 = 11 - resto;
					break;
			}
			soma1=0;
			for(i=11; i > 2; i--){
				soma1 += parseInt(nro.substr(nro.length-i,1)) * i ;
			}
			soma1 = soma1 + dig1*2;
			resto = soma1 % 11;
			switch (resto){
				case 0:
				case 1:
					dig2 = 0;
					break;
				default:
					dig2 = 11 - resto;
					break;
			}
			var controle = String(dig1) + String(dig2);
			if(controle == nro.substr(9,2)){
				return (true);
			}
				return (false);
		}

		//Fim Calcula Digito Verificador Cpf


function define_consulta(){
	if(document.frm_ConsultaAdvogado.tipo_consulta[0].checked){
                var numeroInscricao = window.document.frm_ConsultaAdvogado.nr_inscricao.value;

                if(numeroInscricao.length <= 2){
                   alert("Por favor, informe o número de inscrição corretamente.");
                   window.document.frm_ConsultaAdvogado.nr_inscricao.focus();
                   return(false);
                }

                if(isNaN(numeroInscricao)){
                   alert("Por favor, digite somente números no campo número de inscrição.");
                   window.document.frm_ConsultaAdvogado.nr_inscricao.focus();
                   return(false);
                }

                if(numeroInscricao.indexOf(".") >= 0){
                   alert("Por favor, o número de inscrição sem pontos.");
                   window.document.frm_ConsultaAdvogado.nr_inscricao.focus();
                   return(false);
                }
                
                if((!document.frm_ConsultaAdvogado.cbxadv.checked) && (!document.frm_ConsultaAdvogado.cbxest.checked)){
                    alert("Por favor, selecione pelo menos um tipo de inscrição a ser pesquisado.");
                    window.document.frm_ConsultaAdvogado.cbxadv.focus();
                    return(false);                  
                }
                
                if((document.frm_ConsultaAdvogado.cbxadv.checked) && (!document.frm_ConsultaAdvogado.cbxest.checked)){
                    window.document.frm_ConsultaAdvogado.id_tipoinscricao.value = 1;
                }
                
                if((!document.frm_ConsultaAdvogado.cbxadv.checked) && (document.frm_ConsultaAdvogado.cbxest.checked)){
                    window.document.frm_ConsultaAdvogado.id_tipoinscricao.value = 2;
                }
                
                if((document.frm_ConsultaAdvogado.cbxadv.checked) && (document.frm_ConsultaAdvogado.cbxest.checked)){
                    window.document.frm_ConsultaAdvogado.id_tipoinscricao.value = 0;
                }

		window.document.frm_ConsultaAdvogado.action="consulta_nr_advogado.asp";
		window.document.frm_ConsultaAdvogado.submit();
	}
	
	if(document.frm_ConsultaAdvogado.tipo_consulta[1].checked){

               var nomeAdvogado = window.document.frm_ConsultaAdvogado.nome_advogado.value;

                if(nomeAdvogado.length <= 3){
                   alert("Por favor, informe o nome com pelo menos 4 caracteres.");
                   window.document.frm_ConsultaAdvogado.nome_advogado.focus();
                   return(false);
                }

                window.document.frm_ConsultaAdvogado.action="consulta_advogado_nome_result.asp";
		window.document.frm_ConsultaAdvogado.submit();
	}
	
	if(document.frm_ConsultaAdvogado.tipo_consulta[2].checked){
                var nrCPF = window.document.frm_ConsultaAdvogado.nr_cpf.value;
                
                if(nrCPF.length < 11){
                   alert("Informe o CPF com 11 caracteres.\nPreencha com zeros à  esquerda, se for o caso.");
                   window.document.frm_ConsultaAdvogado.nr_cpf.focus();
                   return(false);
                }

                if(isNaN(nrCPF)){
                   alert("Digite somente caracteres numéricos no campo CPF.");
                   window.document.frm_ConsultaAdvogado.nr_cpf.focus();
                   return(false);
                }

                if(nrCPF.indexOf(".") >= 0){
                   alert("Digite o CPF sem pontos ou traço.");
                   window.document.frm_ConsultaAdvogado.nr_cpf.focus();
                   return(false);
                }

                if(!valida_cpf(nrCPF)){
                   alert("CPF inválido.\nPor favor, digite-o corretamente.");
                   window.document.frm_ConsultaAdvogado.nr_cpf.focus();
                   return(false);
                }
		window.document.frm_ConsultaAdvogado.action="consulta_advogado_cpf_result.asp";
		window.document.frm_ConsultaAdvogado.submit();
	}
}

function muda(valor){
     switch(parseInt(valor)){
         case 1:
            //alert("UM");
            window.document.getElementById("tabelaNumeroTipo").style.visibility = "visible";
            window.document.getElementById("tabelaNumeroTipo").style.display = "";
            window.document.frm_ConsultaAdvogado.nr_inscricao.value="";

            window.document.getElementById("tabelaNome").style.visibility = "hidden";
            window.document.getElementById("tabelaNome").style.display = "none";

            window.document.getElementById("tabelaCPF").style.visibility = "hidden";
            window.document.getElementById("tabelaCPF").style.display = "none";

            document.frm_ConsultaAdvogado.nr_inscricao.focus();            

            break;
         case 2:
            //alert("DOIS");
            window.document.getElementById("tabelaNome").style.visibility = "visible";
            window.document.getElementById("tabelaNome").style.display = "";
            window.document.frm_ConsultaAdvogado.nome_advogado.value="";

            window.document.getElementById("tabelaNumeroTipo").style.visibility = "hidden";
            window.document.getElementById("tabelaNumeroTipo").style.display = "none";

            window.document.getElementById("tabelaCPF").style.visibility = "hidden";
            window.document.getElementById("tabelaCPF").style.display = "none";

            document.frm_ConsultaAdvogado.nome_advogado.focus(); 

            break;
         case 3:
            window.document.getElementById("tabelaCPF").style.visibility = "visible";
            window.document.getElementById("tabelaCPF").style.display = "";
            window.document.frm_ConsultaAdvogado.nr_cpf.value="";

            window.document.getElementById("tabelaNome").style.visibility = "hidden";
            window.document.getElementById("tabelaNome").style.display = "none";

            window.document.getElementById("tabelaNumeroTipo").style.visibility = "hidden";
            window.document.getElementById("tabelaNumeroTipo").style.display = "none";           

            document.frm_ConsultaAdvogado.nr_cpf.focus(); 

            break;
     } 
}//tabelaNumeroTipo


      function LoadThis(){
		var tipobusca
		if(document.frm_ConsultaAdvogado.tipo_consulta[0].checked){
			tipobusca = 1;
		}
		
		if(document.frm_ConsultaAdvogado.tipo_consulta[1].checked){
			tipobusca = 2;
		}
		
		if(document.frm_ConsultaAdvogado.tipo_consulta[2].checked){
	   		tipobusca = 3;
		}
		
		muda(tipobusca);
		//document.frm_ConsultaAdvogado.campo_pesquisa.focus();
	}


