var Hdesconto = new String('');
var Himposto = new String('');
var Hfonte = new String('');
var Hclmensalao = new String('');
var HsaldoPagar = new String('');
var Hagencia = new String('');
var Hdvagencia = new String('');
var Hconta = new String('');
var Hdvconta = new String('');
var Hrestituicao = new String('');
var foco = "DICAS";
var msgstatus = "";
var ImagemAtual = new Image();
// Handle para o objeto formulário
var f;

// Define algumas variáveis globais no evento onLoad
function onLoad() {
	f = pegaObj( 'declaracao');
	f.NR_CPF.focus()

	// Necessário mostrar/esconder habilitar/desabilitar campos conforme os dados

	// Fazemos um timeout pois pode haver problema de sincronismo com o iframe escondido
	setTimeout ( "mudaEstado( f.SG_UF, false )", 2000 );

	// Se o radio retificação for habilitado mostra o campo de número do recibo anterior
	if (f.IN_RETIFICA[0].checked)
		mostraRetifica();
	else
		escondeRetifica();

	// Atualiza os campos relativos ao banco
	rendTrib();mudou();

}

// Esta função é chamada no form.onReset
function inicializaForm() {

	// Limpa a possível lista de cidades carregadas do servidor
	f.SG_UF.options.selectedIndex = 0;
	mudaEstado( f.SG_UF );

	// Esconde os campos que somente aparecem quando a resposta for "sim" do radio
	escondeRetifica();

	// Apaga a descrição do código de ocupação que a página ajuda.htm preenche.
	pegaObj( 'id_descricaoCodigo' ).innerHTML = '';

}

// Faz a verificação da consistência dos dados, pergunta ao usuário
// se deseja realmente enviar a declaração e o faz, caso positivo.
function submeterDados() {

	if(! validaCPF(f.NR_CPF, "Número de inscrição no CPF",false) )return false;

    if (!validaData(f.DT_NASCIMDIA,f.DT_NASCIMMES,f.DT_NASCIMANO) ) return false;

	if (!isEmpty(f.email.value)) {
		if (!valida_mail(f.email.value)) {
			aviso(f.email,"Digite um e-mail válido.");
			return false;
		}
	}

	// Verifica se o usuário informou se vai ou não mudar o endereço e também valida os campos
	// se a resposta for "sim"
	if ( !validaEndereco() )
		return false;

	if (!validaNat(f.CD_NATUR) ) return false;

	if (!validaOcup(f.CD_NATUR,f.CD_OCUP) ) return false;

	if (!validaBens(f.VR_BENSATUAL) ) return false;

	if (!EhNumero(f.VR_BENSANTER) ) return false;

	if (confirm("Deseja enviar este Cadastro?"))
		if (confirmaImposto()) {
			pegaObj( 'txtTipoLogradouro' ).disabled = false
			return true;
		}

	return false;
}


// Pega o valor numérico recebido e converte do formato numérico
// milhar brasileiro (111.222.333,00) para o formato do javascript (111222333.00)
function limpaStringNumerica( valor ) {
	valor = valor.replace( /\./g, '' );
	return valor.replace( /,/g, '.' );
}

// Faz um alert de uma mensagem de erro e faz um focus no campo
// recebido como parâmetro
function aviso (campo, msg) {
	alert(msg);
	campo.focus();
	return false;
}

// Abre o arquivo ajuda.htm pulando diretamente para a âncora
// definida no parâmetro link
// ********** ESSE COMENTÁRIO TÁ ERRADO ***********
function ajuda(link,tipo) {
  var msgWindow;
  if (tipo != "L" )
    link = link +'#'+foco;
  msgWindow=window.open(link,'window2','resizable=no,width=640,height=480,dependent=no,scrollbars=yes');
  msgWindow.focus();
}

// Muda a string de status do browser para a string dada
//  ********** TÁ FALTANDO ALGO AQUI ***********
function hint (n,s){
	window.status = s;
	msgstatus = s;
	if ( n!='') foco = n;
}

// Função chamada no evento onKeyDown para evitar que caracteres não numéricos
// sejam inseridos no campo indicado.
// O primeiro parâmetro é o this e o segundo é o event
function ajustar_numero(input, e) {
	var k = -1;

	// Mozilla
	if (e && e.which)
		k = e.which;
	else
		k = e.keyCode;

	// No IE não essa função não consegue cancelar tabs, BS, DEL, etc, mas no mozilla sim,
	// por isso precisamos deixar passar as teclas de edição.
	// Somente aceita os caracteres 0-9, tab, enter, del e BS
	if ( ((k<48)||(k>57)) && k != 8 && k != 9 && k != 127 && k != 13 ) {
		e.returnValue = false;
		return false;
	}
	return true;
}

function VerificaTamanho(campo,tamanho,proximocampo) {
 if (campo.value.length == tamanho)
 	pegaObj(proximocampo).focus();
}


function FormataValor(campo,tammax,teclapres) {

	var tecla = teclapres.keyCode;
	var vr = campo.value;
	vr = vr.replace( /[\/\.,]/g, '' );

	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }

	if ( tecla == 8 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) ){
		if ( tam <= 2 ){
	 		campo.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}
}

function FormataCpf(campo,teclapres) {

	var tecla = teclapres.keyCode;
	var vr = campo.value;
	var tammax = 11;
	vr = vr.replace( /[-.]/g, '' );

	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }

	if ( tecla == 8 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) ){
		if ( tam <= 2 ){
	 		campo.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		campo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }

	}
}
function limpaOcup(natur,ocup) {

   if ( (natur.options[natur.selectedIndex].value =="81"))
   {
     f.CD_OCUP.value = "";
     lb_nm_ocupacao.innerText = "";
    }
}

function RetiraCaracteresInvalidos(strCampo,tam) {
	nTamanho = strCampo.length;
	szCampo = "";
	j=0;
	for (i = nTamanho-1;i>=0;i--)
	{
		if (isDigit(strCampo.charAt(i)))	{
			szCampo = strCampo.charAt(i) + szCampo;
			j++;
			if (j > tam) break;
		}
	}
	if (szCampo.length < tam) {
		for (i = szCampo.length;i<tam;i++)
		{
			szCampo = "0" + szCampo;
		}
	}
    return szCampo;
}

function ContaDigitos(strCampo) {
	nTamanho = strCampo.length;
	szCampo = "";
	j=0;
	for (i = nTamanho-1;i>=0;i--)
	{
		if (isDigit(strCampo.charAt(i)))	{
			szCampo = strCampo.charAt(i) + szCampo;
			j++;
		}
	}
    return j;
}

function formataReal(ValoraFormatar) {
    var i ;
    var decimalPointDelimiter = ",";
    var posDecPoint = parseInt("");
    var hasDecPoint = false;
    var s = new String(ValoraFormatar);
    var sAux = new String("");

    for (i = 0; i < s.length; i++)
    {
    	var c = s.charAt(i);
    	if ( c == '.' ) c = decimalPointDelimiter;
	    sAux += c;
      if (c == decimalPointDelimiter){
        	  hasDecPoint = true;
        	  posDecPoint = i;
        	  break;}
    }
    for (var j = i+1; j < s.length; j++) sAux += s.charAt(j);

    if (!hasDecPoint) //(isNaN(posDecPoint))
      {	ValoraFormatar = s + ",00";}
    else
      {
      	s = sAux + '00';
        ValoraFormatar= s.charAt(0);
        for (i = 1; i <= (posDecPoint+2); i++){
            ValoraFormatar += s.charAt(i);}
        if (posDecPoint == 0) ValoraFormatar = '0'+ValoraFormatar;
      }
    s = ValoraFormatar;
    ValoraFormatar = "";
    i=0;

    for (var j=s.length-4; j>=0; j--)
	{
		i++;
		ValoraFormatar = s.charAt(j) + ValoraFormatar;
		if (i == 3 && j != 0)
		{
			ValoraFormatar = "." + ValoraFormatar;
			i = 0;
		}
	}
	ValoraFormatar +=  s.substring(s.length-3,s.length);

    return ValoraFormatar;
}

// Testa se uma string é um valor inteiro e se ela está entre dois valores
// definidos assim: s pertence [a,b]
// retorna true ou false
function isIntegerInRange (s, a, b) {
   if (isEmpty(s)) return false;

    if (!isInteger(s)) return false;

    var num = (s);

    return ((num >= a) && (num <= b));
}


// Muda os dados dos campos "Banco" para a agência predefinida
// do banco do Brasil que é utilizada quando o contribuinte
// se encontra no exterior ou limpa caso não seja exterior e
// o banco preenchido seja o exterior


function separadorDecimal(valor) {
	return (parseFloat(valor) / 100);
}

function trunca(valor) {
	valor *= 100;
	valor = parseFloat(valor);
	return separadorDecimal(valor);
}

// Recebe o evento onChange do select de estado e modifica o src do iframe escondido
// com a página "cidades.asp" que altera o select "selectCidades"
// Isso é feito com javascript dentro do conteúdo retornado pela página cidades.asp,
// dê uma olhadinha lá para entender melhor.
// O parâmetro é o this do select.
function mudaEstado( select, limparCookie ) {

	// Chama mudabanco para alterar dados caso seja exterior
	mudabanco();

	// Recupera o iframe que deve ter seu src alterado
	var iframe = pegaObj( 'conteudo' );
	var cidades = pegaObj( 'selectCidades' );

	// Se foi selecionado exterior, mostra o combo de país esconde o de município
	// E vice-versa
	if ( select.value != 'EX' ) {
		pegaObj( 'selecaoCidades' ).style.display = 'block';
		pegaObj( 'selecaoPais' ).style.display = 'none';
		pegaObj( 'txtTipoLogradouro' ).disabled = false;
	} else {
		pegaObj( 'selecaoCidades' ).style.display = 'none';
		pegaObj( 'selecaoPais' ).style.display = 'block';
		pegaObj( 'txtTipoLogradouro' ).disabled = true;
		pegaObj( 'txtTipoLogradouro' ).options.selectedIndex = 0;
		return;
	}

	// Limpa a variável da window que guarda o último município selecionado
	// para não dar problema no evento de retorno da página cidades.asp
	if ( typeof(limparCookie) != 'undefined' && limparCookie )
		setCookie( "ultimoMunicipio", 0 );

	// Se mudou para a primeira entrada, zera o select de cidades
	if ( select.options.selectedIndex == 0 ) {
		cidades.options.length = 0;
		cidades.options.add( new Option( 'Selecione a UF antes', 'XX' ) );
		return;
	}

	// Concatena na URL de cidades.asp o parâmetro UF para que possa
	// ser feito o select do grande porte, na tabela TOM.
	iframe.src = "GP/cidades.asp?UF=" + select.value;

	// Zera os options e coloca um "Aguarde, recuperando municípios..."
	cidades.options.length = 0;
	cidades.options.add( new Option( 'Aguarde, recuperando municípios...', '' ) );
}

// Guarda o último município que foi selecionado no objeto window para quando
// recuperarmos a lista de municípios de volta do servidor quando fazemos back (do browser)
// podermos selecionar o município correto
function mudaMunicipio( munic ) {
	setCookie( "ultimoMunicipio", munic.options.selectedIndex );
}

function RetiraCaracteresInvalidos(strCampo,tam) {

	nTamanho = strCampo.length;
	szCampo = "";
	j=0;
	for (i = nTamanho-1;i>=0;i--) {
		if (isDigit(strCampo.charAt(i))) {
			szCampo = strCampo.charAt(i) + szCampo;
			j++;
			if (j > tam) break;
		}
	}

	if (szCampo.length < tam)
		for (i = szCampo.length;i<tam;i++)
			szCampo = "0" + szCampo;

    return szCampo;

}


function MudaImagem(MyImg, Imagem) {
	ImagemAtual.src = Imagem;
	MyImg.src = ImagemAtual.src;
}

// Recupera uma referência ao objeto com o id especificado
// Funciona primariamente com o DOM, mas também aceita document.all
function pegaObj( id ) {

	if ( typeof(document.getElementById) != 'undefined' )
		return document.getElementById( id );
	else if ( document.all ) {
		return document.all( id );
	}
}

	
function FormataCPF(Campo, teclapres)
{
	var tecla = teclapres.keyCode;
	
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8)
		{
		if (tam > 3 && tam < 7)
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		if (tam >= 7 && tam <10)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		if (tam >= 10 && tam < 12)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
		}
		
}
/////////////////////////////////////////////////////////////////

function FormataControle(Campo, teclapres)
{
	var tecla = teclapres.keyCode;
	
	
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	tam = vr.length + 1;
	
 if (tecla != 0x9 && tecla !=0x8 && tecla !=0xd)
		if (tam > 7)
			{
			if (tam > 4 && tam < 9)
				Campo.value = vr.substr(0, 4) + '.' + vr.substr(4, tam);
			if (tam >= 9 && tam <13)
				Campo.value = vr.substr(0,4) + '.' + vr.substr(4,4) + '.' + vr.substr(8,tam-8);
			if (tam >= 13 && tam < 17)
				Campo.value = vr.substr(0,4) + '.' + vr.substr(4,4) + '.' + vr.substr(8,4) + '.' + vr.substr(12,tam-12);
			}
		else
			{
			if (tam > 1 && tam < 5)
				Campo.value = vr.substr(0, 1) + '.' + vr.substr(1, tam);
			if (tam >= 5 && tam < 8)
				Campo.value = vr.substr(0,1) + '.' + vr.substr(1,3) + '.' + vr.substr(4,tam-4);
			}
		
}
/////////////////////////////////////////////////////////////////

function FormataCNPJ(Campo, teclapres)
{

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8)
		{
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}

}
/////////////////////////////////////////////////////////////////

function FormataITR(Campo, teclapres)
{
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");


	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8)
		{
		if (tam > 1 && tam < 5)
			Campo.value = vr.substr(0, 1) + '.' + vr.substr(1, tam);
		if (tam >= 5 && tam < 8)
			Campo.value = vr.substr(0,1) + '.' + vr.substr(1,3) + '.' + vr.substr(4,tam-4);
		if (tam >= 8)
			Campo.value = vr.substr(0,1) + '.' + vr.substr(1,3) + '.' + vr.substr(4,3) + '-' + vr.substr(7,1);
		}
		

}
/////////////////////////////////////////////////////////////////

function SaltaCampo(campo,prox,tammax,teclapres)
{
	var tecla = teclapres.keyCode;
	vr = document.forms[0].elements[campo].value;
	
		
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108){
	   document.forms[0].elements[campo].value = vr.substr(0, vr.length - 1); }
	else
		{
		vr = vr.replace("-","");
		vr = vr.replace("/","");
		vr = vr.replace("/","");
		vr = vr.replace(",","");
		vr = vr.replace(".","");
		vr = vr.replace(".","");
		vr = vr.replace(".","");
		vr = vr.replace(".","");
		tam = vr.length;

		if (tecla != 0 && tecla != 9 && tecla != 16 )
			if ( tam == tammax )
				document.forms[0].elements[prox].focus();
		}

}
//////////////////////////////////////////////////////////////////

function CalcularDV(sCampo, iPeso)
{
	
	var iTamCampo;
	var iPosicao, iDigito;
	var iSoma1 = 0;
	var iSoma2=0;
	var iDV1, iDV2;
		
	iTamCampo = sCampo.length;
		

	for (iPosicao=1; iPosicao<=iTamCampo; iPosicao++){
		iDigito = sCampo.substr(iPosicao-1, 1);
		iSoma1 = parseInt(iSoma1,10) + parseInt((iDigito * Calcular_Peso(iTamCampo - iPosicao, iPeso)),10);
		iSoma2 = parseInt(iSoma2,10) + parseInt((iDigito * Calcular_Peso(iTamCampo - iPosicao + 1, iPeso)),10);
		}

	iDV1 = 11 - (iSoma1 % 11);
	if (iDV1 > 9)
		iDV1 = 0;

	iSoma2 = iSoma2 + (iDV1 * 2);
	iDV2 = 11 - (iSoma2 % 11);
	if (iDV2 > 9)
		iDV2 = 0;

	Ret = (parseInt(iDV1 * 10,10) + parseInt(iDV2));

	Ret = "0" + Ret;
	Ret = Ret.substr(Ret.length - 2,Ret.length);
		
	return(Ret);
	
}

//////////////////////////////////////////////////////////////////		

function Calcular_Peso(iPosicao, iPeso)
{

//Pesos
//CPF 11
//CNPJ 9

return (iPosicao % (iPeso - 1)) + 2;
}
	
/////////////////////////////////////////////////////////////////

function LimpaCampo(sValor,iBase)
{
var tam = sValor.length
var saida = new String
for (i=0;i<tam;i++)
	if (!isNaN(parseInt(sValor.substr(i,1),iBase)))
		saida = saida + String(sValor.substr(i,1));
return (saida);		
}
/////////////////////////////////////////////////////////////////

function TestaForm(theForm,iTipo)
{
if (!(TestaNI (theForm.NI,iTipo)))
	return (false);
	
if (!(TestaControle (theForm.Controle)))  
	return (false);

var controle = LimpaCampo(theForm.Controle.value,16);
var tam = controle.length;

if	(tam == 16)
{ 
	if (!(TestaData(theForm.Data)))
		return (false);
	
	if (!(TestaHora(theForm.Hora)))
		return (false);		
}		
else	
{
	if (theForm.Data.value != "")
	{
		alert('Só preencher data da emissão para certidão emitida pela Internet');
		theForm.Data.value = "";
		theForm.Data.focus();
		return(false);
	}
	if (theForm.Hora.value != "")
	{	
		alert('Só preencher hora da emissão para certidão emitida pela Internet');
		theForm.Hora.value = "";
		theForm.Hora.focus();
		return(false);
	}
}		
return (true);
	
}
/////////////////////////////////////////////////////////////////

function TestaFormITR(theForm,iTipo)
{
if (!(TestaNI (theForm.NI,iTipo)))
	return (false);
	
if (!(TestaControleITR (theForm.Controle)))  
	return (false);
return (true);

}
/////////////////////////////////////////////////////////////////

function TestaNI(cNI,iTipo)
{
var NI , ni2, v3
var vr = new String(cNI.value);

ni2 = vr.substr(0,2)  + vr.substr(4,3)  + vr.substr(8,3) + vr.substr(12,4)+ vr.substr(17,2);
NI = ni2 ;
NI = LimpaCampo(cNI.value,10);
switch (iTipo) {
	case 1:
		if (NI.length != 14){
			alert('O número do CNPJ informado está incorreto');
			cNI.value = "";
			cNI.focus();
			return(false);
			}

		if (NI.substr(12,2) != CalcularDV(NI.substr(0,12), 9)){
			alert('O número do CNPJ informado está incorreto');
			cNI.value = "";
			cNI.focus();
			return(false);
			}
		break;

	case 2:
		if (NI.length != 11){
			alert('O número do CPF informado está incorreto');
			cNI.value = "";
			cNI.focus();
			return(false);
			}

		if (NI.substr(9,2) != CalcularDV(NI.substr(0,9), 11)){
			alert('O número do CPF informado está incorreto');
			cNI.value = "";
			cNI.focus();
			return(false);
			}
		break;
	case 3:
		if (NI.length != 8){
			alert('O número do ITR informado está incorreto');
			cNI.value = "";
			cNI.focus();
			return(false);
			}
		var dv = new String(); 
		dv = CalcularDV(NI.substr(0,7), 9);
		dv = dv.substr(0,1);
		if (NI.substr(7,1) != dv){
			alert('O número do ITR informado está incorreto');
			cNI.value = "";
			cNI.focus();
			return(false);
			}
		break;

	default:
		return(false);
	}
return (true);	
}  


/////////////////////////////////////////////////////////////////

function TestaControle(cControle)
{
var controle; 
controle = LimpaCampo(cControle.value,16);
var tam = controle.length;
if	(tam != 7 && tam != 16)
	{
	alert('O  Número/Código de Controle informado está incorreto');
	cControle.value = "";
	cControle.focus();
	return(false);
	}
return(true); 
}
/////////////////////////////////////////////////////////////////
function TestaControleITR(cControle)
{
var controle; 
controle = LimpaCampo(cControle.value,10);
var tam = controle.length;
if	(tam != 7)
	{
	alert('O  Número da Certidão informado está incorreto');
	cControle.value = "";
	cControle.focus();
	return(false);
	}
return(true); 
}
/////////////////////////////////////////////////////////////////

function VerAlfaNumerico(pInd)
{
 var pValor = document.forms[0].elements[pInd].value
 var AuxTam = pValor.length  
  for(var j=0;j<AuxTam;j++)
   if ((!IndAlfaNumerico(pValor.charAt(j))) || (pValor.charAt(j) == " ")){
     document.forms[0].elements[pInd].focus();  
     document.forms[0].elements[pInd].value = pValor = pValor.substring(0,j)           
   } 
  }
////////////////////////////////////////////////////////////////////

function IndAlfaNumerico(N)
{
 for(var i=0;i<10;i++)
	if(N == i)
		return true;
 return false;    
}

/////////////////////////////////////////////////////////////////

function FormataData(Campo, teclapres)
{
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8) 
 		{
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
		if (tam >= 5 && tam <=10)
			Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,4);
		
		}
}
/////////////////////////////////////////////////////////////////
	
function FormataHora(Campo, teclapres) 
{
	var tecla = teclapres.keyCode;
	
	var vr = new String(Campo.value);
	vr = vr.replace(":", "");
	vr = vr.replace(":", "");

	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8) {
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + ':' + vr.substr(2, tam);
		if (tam >= 5 && tam < 9)
			Campo.value = vr.substr(0,2) + ':' + vr.substr(2,2) + ':' + vr.substr(4,2);
		}
	}
/////////////////////////////////////////////////////////////////

function TestaData(cData)
{
var data; 
data = LimpaCampo(cData.value,10);
var tam = data.length;
if	(tam != 8)
	{
	alert('A data da emissão está incorreta');
	cData.value = "";
	cData.focus();
	return(false);
	}
var dia = data.substr(0,2)
var mes = data.substr (2,2)
var ano = data.substr (4,4)	
if (ano < 1994)
	{
	alert('A data da emissão está incorreta');
	cData.value = "";
	cData.focus();
	return(false);
	}


switch (mes)
	{
	case '01':
		if  (dia <= 31) 
			return (true);
		break;
	case '02':
		if  (dia <= 29) 
			return (true);
		break;
	case '03':
		if  (dia <= 31) 
			return (true);
		break;
	case '04':
		if  (dia <= 30) 
			return (true);
		break;
	case '05':
		if  (dia <= 31) 
			return (true);
		break;
	case '06':
		if  (dia <= 30) 
			return (true);
		break;
	case '07':
		if  (dia <= 31) 
			return (true);
		break;
	case '08':
		if  (dia <= 31) 
			return (true);
		break;
	case '09':
		if  (dia <= 30) 
			return (true);
		break;
	case '10':
		if  (dia <= 31) 
			return (true);
		break;
	case '11':
		if  (dia <= 30) 
			return (true);
		break;
	case '12':
		if  (dia <= 31) 
			return (true);
		break;
	}	
	{
	alert('A data está incorreta');
	cData.value = "";
	cData.focus();
	return(false);
	}

return(true); 
}
///////////////////////////////////////////////////////////////////
function TestaHora(cHora)
{
var hora; 
hora = LimpaCampo(cHora.value,10);
var tam = hora.length;
if	(tam != 6)
	{
	alert('A hora da emissão está incorreta');
	cHora.value = "";
	cHora.focus();
	return(false);
	}
	
var hr = hora.substr(0,2)
var min = hora.substr (2,2)
var seg = hora.substr (4,2)	
if ((hr > 23) || (min > 59) || (seg > 59))
	{
	alert('A hora da emissão está incorreta');
	cHora.value = "";
	cHora.focus();
	return(false);
	}
return(true);
 
}
/////////////////////////////////////////////////////////////////

	
//-->