function VerificaCPF(numero) {
       numero = numero.replace('.','');
       numero = numero.replace('.','');
       cpf = numero.replace('-','');
       while(cpf.length < 11) cpf = "0"+ cpf;
       var expReg = /^0+$|^1+$|^2+$|^3+$|^4+$|^5+$|^6+$|^7+$|^8+$|^9+$/;
       var a = [];
       var b = new Number;
       var c = 11;
       for (i=0; i<11; i++){
          a[i] = cpf.charAt(i);
          if (i < 9) b += (a[i] * --c);
       }
       if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
       b = 0;
       c = 11;
       for (y=0; y<10; y++) b += (a[y] * c--);
       if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
       if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10]) || cpf.match(expReg)) return false;
       return true;
    }

function isEmailAddress(string) {
   var addressPattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
   return addressPattern.test(string);
}
function isDataValida(data) {
   var reDate = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/\d{4}$/;
   return reDate.test(data); }

   function Valida() {
   if ($("#nome").val()=='') {
      alert('Preencha seu Nome completo');
      $("#nome").focus();
      return false; } else
   if ($("#email").val()=='' || !isEmailAddress($("#email").val())) {
      alert('Preencha seu Email');
      $("#email").focus();
      return false; } else
   if ($("#email").val()!=$("#email1").val()) {
      alert('Confira o e-mail');
      $("#email1").focus();
      return false; } else
   if ($("#estado").val()=='0') {
      alert('Preencha o Estado');
      $("#estado").focus();
      return false; } else
   if ($("#cidade").val()==null || $("#cidade").val()=='carregando...') {
      alert('Preencha a cidade');
      $("#cidade").focus();
      return false; } else
   if (!VerificaCPF($("#CampoCPF").val())) {
      alert('CPF Inválido');
      $("#CampoCPF").focus();
      return false; } else
   if ($("#nascimento").val()=='') {
      alert('Preencha sua Data de Nascimento');
      $("#nascimento").focus();
      return false; } else
    if (!isDataValida($("#nascimento").val())) {
      alert('Data de Nascimento deve ser no formato dd/mm/aaaa');
      $("#nascimento").focus();
      return false; } else
   if ($("#senha").val()=='') {
      alert('A senha não pode ficar em branco');
      $("#senha").focus();
      return false; } else
   if ($("#senha").val()!=$("#senha1").val()) {
      alert('Senhas não conferem');
      $("#senha").focus();
      return false; } else
   if (document.getElementById('termos').checked!='1') {
      alert('Leia os Termos de uso do Portal');
      return false; } else {
   $("form1").submit();
   return true;} }

function SeleCidade() {
/*
		$.ajax({method: "get",url: "/cidades.php?uf="+$("select#estado").val(), global: true,
	    beforeSend: function(){$('select#cidade').html('<option>carregando...</option>');},
	    success: function(html) {$('select#cidade').html(html);}
	    });
*/
}

$(document).ready(function() {
   $("select#estado").blur(function(){
      SeleCidade();
   }).change(function(){
		$.ajax({method: "get",url: "/cidades.php?uf="+$("select#estado").val(), global: true,
	    beforeSend: function(){$('select#cidade').html('<option>carregando...</option>');},
	    success: function(html) {$('select#cidade').html(html);}
	    });
   });
	$("#form").mouseover(function(e){
	alert($("#nome").val());
	Valida();
	});

});



