$(document).ready(function() {
  $('#msgerro').html('&nbsp;');
  $('#msgerro2').html('&nbsp;');
  //alert('testa');
  $('#enviar').click(function() {
    $('#msgerro').html('Aguarde ....');
    $.post('cadini_proc1.php', { cpf : $('#cpf1').val()  }, function(response) {
       $('#msgerro').html('&nbsp;');
       //$('#msgerro').html(response);
       //return false;
       if (response=='404') {
	  $('#msgerro').html('ERRO: CPF não cadastrado');
	  setTimeout("esconde()",2000);
	  return false;
       } else if (response=='ERR') {
	  $('#msgerro').html('ERRO: CPF inválido');
	  setTimeout('esconde()',2000);
	  return false;
       } else {
         $('#frm1').submit();
       }
    })
    return false;
  });

  $('#enviar2').click(function() {
    //alert('oi');
    $('#msgerro2').html('Aguarde ....');
    $.post('cadini_proc1.php', { cpf : $('#cpf2').val()  }, function(response) {
       $('#msgerro2').html('&nbsp;');
       if (response=='ERR') {
	  $('#msgerro2').html('ERRO: CPF inválido');
	  setTimeout('esconde()',2000);
	  return false;
       } else if(response!='404'){
	  $('#msgerro2').html('ERRO: CPF já cadastrado');
	  setTimeout('esconde()',2000);
	  return false;
       } else {
         $('#frm2').submit();
       }
    })
    return false;
  });


});

function esconde(ed) {
  $('#msgerro').html('&nbsp;');
  $('#msgerro2').html('&nbsp;');
  ed1 = document.getElementById('cpf1');
  ed2 = document.getElementById('cpf2');
  pwd = document.getElementById('pwd');
  if (ed == ed1) ed2.value = '';
  if (ed == ed2) ed1.value = '';
  if (ed == ed2) pwd.value = '';
}
