$(document).ready(function() {
	
		$(':input').not('.botao,.incluir').focus(function(){
		$(this).css('background','#FFF7C0')
		})
		$(':input').not('.botao,.incluir').blur(function(){
		$(this).css('background','#F3F3F3')
		})
	
	//blinkButton();
	
		/*$("select#cargo").change(function () {	
				$("#formulario").validate().form();
					  
				  $("select#cargo option:selected").each(function () {
						cargo = $(this).val();
				  });
				  if (cargo != "") {
					requisitos(cargo);
				  }
		})	*/
		
		/*$("select#localidade").change(function () {	
				$("#formulario").validate().form();
				})*/
		
		
		
		$('#entrar').click(function () {
       				forminputs = $("#formulario :input").serializeArray();
					entrar(forminputs);
					 
       				});
		
		//validate
		$("#formulario").validate({
		rules: {
			cpf: "required",
			senha: "required"
			
		},
		messages: {
			senha: "Por favor preencha uma senha",
			cpf: "Por favor preencha o seu cpf"
		}
	});
		
		//validate
		
		
		
		
$('input.cpf').mask('999.999.999-99');






			
	
				//fim onload
				})


/*function requisitos(cargo){
				//loader();
                $.post("ajax/requisitos.asp",{cargo: cargo}, function(data) {
						$("#requisitos").empty().html("Requisitos:<br>"+data+"<br>");
				});
				return false
				
	
  }*/
  
  function entrar(forminputs){
	             
	            var validator = $("#formulario").validate().form();
				if (validator == true) {				
					//loader();
                	$.post("ajax/entrar.asp",forminputs, function(data) {
						//$("#grava_func").empty().html(data);
						$("#diventrar").empty().html(data);
					});
				}else{
					alert("Verifique o preenchimento dos campos");
				}
			   	
	}
	
	function cidades(uf){
				//loader();
                $.post("ajax/cidades.asp",{uf: uf}, function(data) {
						$("select#cidade").empty().html(data);
				});
				
	
}

function procuracpf(str,id){
				//loader();
                $.post("ajax/procuracpf.asp",{str: str,id: id}, function(data) {
						$("#cpfexiste").empty().html(data);
				});
				
	
                }







function validaCPF(cpf){
	erro = 0
   //var cpf = document.cadastro.cpf.value;
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if(!filtro.test(cpf)){
   //window.alert(unescape("CPF errado. Tente novamente."));
   erro = 1
	 //return false;
   }
   
   cpf = remove(cpf, ".");
   cpf = remove(cpf, "-");
    
   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999"){
	  //window.alert(unescape("CPF errado. Tente novamente."));
	  erro = 1
	   
	  //return false;
   }

   soma = 0;
   for(i = 0; i < 9; i++)
   	 soma += parseInt(cpf.charAt(i)) * (10 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(9))){
   	  //window.alert(unescape("CPF errado. Tente novamente."));
	  erro = 1

	// return false;
   }
   soma = 0;
   for(i = 0; i < 10; i ++)
	 soma += parseInt(cpf.charAt(i)) * (11 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(10))){
  // window.alert(unescape("CPF errado. Tente novamente."));
   erro = 1
	  
	 //return false;
   }
   if (erro == 1){
	valcpf = $('#cpf').val()
	alert("Verifique o CPF")
	$('label.cpf').css('background','#FE2546')
	$('label.cpf span').empty().html('<b>CPF Inv&aacute;lido</b>')
	
	$('#cpf').focus().val(valcpf)	
   }
  if (erro == 0){
	$('label.cpf').css('background','')
	$('label.cpf span').empty().html('CPF:')	
  }
	
   //return true;
 }
 
 function remove(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   return r;
 }