jQuery(document).ready(function () {
function validaCPF(cpfval)
{
var cpf = cpfval.replace(".", "");
cpf = cpf.replace(".", "");
cpf = cpf.replace("-", "");
var numeros, digitos, soma, i, resultado, digitos_iguais;
digitos_iguais = 1;
if (cpf.length < 11)
return false;
for (i = 0; i < cpf.length - 1; i++)
if (cpf.charAt(i) != cpf.charAt(i + 1))
{
digitos_iguais = 0;
break;
}
if (!digitos_iguais)
{
numeros = cpf.substring(0,9);
digitos = cpf.substring(9);
soma = 0;
for (i = 10; i > 1; i--)
soma += numeros.charAt(10 - i) * i;
resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
if (resultado != digitos.charAt(0))
return false;
numeros = cpf.substring(0,10);
soma = 0;
for (i = 11; i > 1; i--)
soma += numeros.charAt(11 - i) * i;
resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
if (resultado != digitos.charAt(1))
return false;
return true;
}
else
return false;
}
jQuery(".your-message textarea").val("");
jQuery(".your-cpf input").mask("000.000.000-00");
jQuery(".your-rg input").mask("00.000.000-0");
jQuery(".your-cep input").mask("00000000");
jQuery(".your-birthday input").mask("00/00/00#0");
// jQuery(".your-salary input").mask('#.##0,00', {reverse: true});
jQuery(".number-children input, .filhos .row input").mask("00");
var SPMaskBehavior = function (val) {
return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
},
spOptions = {
onKeyPress: function(val, e, field, options) {
field.mask(SPMaskBehavior.apply({}, arguments), options);
}
};
jQuery(".your-fone input, .your-cell input").mask(SPMaskBehavior, spOptions);
var i = 0;
var localizacoes = {PR:"Paraná", SP:"São Paulo", MS:"Mato Grosso do Sul", MT:"Mato Grosso", MG:"Minas Gerais", RJ:"Rio de Janeiro"};
localizacoes["PR"] = ["Paraná", "Apucarana", "Arapongas", "Campo Mourão", "Cianorte", "Guarapuava", "Londrina", "Maringá", "Paranavaí", "Ponta Grossa", "Toledo", "Umuarama"];
localizacoes["SP"] = ["São Paulo", "Araçatuba", "Araraquara", "Bauru", "Franca", "Hortolândia", "Jaú", "Marília", "Piracicaba", "Presidente Prudente", "Ribeirão Preto", "Rio Claro", "São José do Rio Preto", "Sertãozinho"];
localizacoes["MS"] = ["Mato Grosso do Sul", "Campo Grande", "Dourados", "Três Lagoas"];
localizacoes["MT"] = ["Mato Grosso", "Cuiabá", "Rondonópolis", "Várzea Grande"];
localizacoes["MG"] = ["Minas Gerais", "Belo Horizonte", "Uberaba", "Uberlândia"];
localizacoes["RJ"] = ["Rio de Janeiro", "Niterói", "Rio das Ostras", "Rio de Janeiro", "São Pedro da Aldeia"];
jQuery.each(localizacoes, function(index, value){
jQuery("").appendTo(".store-state select").attr("value",index);
});
jQuery(".store-state select").change(function() {
jQuery(".store-city select").html("");
jQuery("").appendTo(".store-city select").attr("value",'');
function startlocation(val){
jQuery.each(localizacoes[val], function(index, value){
if (index != 0) {
jQuery("").appendTo(".store-city select").attr("value",value);
}
});
}
if(jQuery(this).val()[0].length > 1) {
jQuery.each(jQuery(this).val(), function(index, value){
startlocation(value);
});
} else {
startlocation(jQuery(this).val());
}
});
jQuery(".filhos").hide();
// jQuery(".number-children input").val("0");
jQuery(".number-children input").change(function() {
if (jQuery(this).val() > 0) {
jQuery(".filhos").show();
jQuery(".filhos .row").html("");
jQuery(".age-children input").val("");
jQuery(".age-children input").attr("aria-required",'true').addClass("wpcf7-validates-as-required");
for (var i = 1; i <= jQuery(this).val(); i++) {
jQuery("
").addClass("filho-"+i+" col-xs").appendTo(".filhos .row");
jQuery("").attr({
"type": 'number',
"name": 'children-'+i,
"placeholder": 'filho '+i,
"aria-invalid": 'false'
}).addClass("wpcf7-form-control wpcf7-text").appendTo(".filhos .row .filho-"+i);
}
} else {
jQuery(this).val("0");
jQuery(".filhos").hide();
jQuery(".filhos .row").html("");
jQuery(".age-children input").val("⠀");
jQuery(".age-children input").removeAttr("aria-required").removeClass("wpcf7-validates-as-required");
}
jQuery(".filhos .row input").change(function() {
// console.log(jQuery(this));
var i = 0;
if (jQuery(".number-children input").val()=="1") {
var val = "Idade: ";
} else {
val = "Idades: ";
}
jQuery(".age-children input").val("");
jQuery(".filhos .row input").each(function(index, value){
if (jQuery(this).val() == "") {
return false;
}
i++;
if (jQuery(".number-children input").val() == i) {
if (jQuery(".number-children input").val()!="1") {
val = val+" e "+jQuery(this).val();
} else {
val = val+jQuery(this).val();
}
jQuery(".age-children input").val(val);
} else if (i+1 < jQuery(".number-children input").val()){
val = val+jQuery(this).val()+", ";
} else {
val = val+jQuery(this).val();
}
});
});
});
function limpa_formulário_cep() {
jQuery(".your-street").val("");
jQuery(".your-district").val("");
jQuery(".your-city").val("");
jQuery(".your-state").val("");
}
jQuery(".your-cep input").blur(function() {
var cep = jQuery(this).val().replace(/\D/g, '');
if (cep != "") {
var validacep = /^[0-9]{8}$/;
if(validacep.test(cep)) {
jQuery(".your-street input").val("...");
jQuery(".your-district input").val("...");
jQuery(".your-city input").val("...");
jQuery(".your-state input").val("...");
jQuery.getJSON("https://viacep.com.br/ws/"+ cep +"/json/?callback=?", function(dados) {
if (!("erro" in dados)) {
jQuery(".your-street input").val(dados.logradouro);
jQuery(".your-district input").val(dados.bairro);
jQuery(".your-city input").val(dados.localidade);
jQuery(".your-state input").val(dados.uf);
} else {
limpa_formulário_cep();
alert("CEP não encontrado.");
}
});
} else {
limpa_formulário_cep();
alert("Formato de CEP inválido.");
}
}
else {
limpa_formulário_cep();
}
});
var valcpf = window.localStorage.getItem('cachecpf');
var valcpfaba = window.sessionStorage.getItem('cachecpf');
var cachecpf;
var valdata = window.localStorage.getItem('cachedata');
var valdataaba = window.sessionStorage.getItem('cachedata');
var cachedata;
//window.localStorage.setItem('cachecpf', cachecpf);
//window.sessionStorage.setItem('cachecpf', cachecpf);
jQuery(".your-cpf input").blur(function() {
jQuery(".your-cpf .wpcf7-not-valid-tip").remove();
if (!validaCPF(jQuery(this).val())) {
jQuery(".your-cpf input").focus();
if (jQuery(".your-cpf input").val() != ""){
alert('Informe um CPF válido');
jQuery(".your-cpf input").val("");
}
} else if(valcpf != jQuery(".your-cpf input").val() && valcpfaba != jQuery(".your-cpf input").val()){
cachecpf = jQuery(".your-cpf input").val();
cachedata = 0;
} else {
alert('CPF já cadastrado em nosso banco');
jQuery(".your-cpf input").val("");
jQuery(".your-cpf input").focus();
}
});
jQuery.getScript("assets/citys.js");
jQuery( ".your-nationality input" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + jQuery.ui.autocomplete.escapeRegex( request.term ), "i" );
response( jQuery.grep( tags, function( item ){
return matcher.test( item );
}) );
}
});
jQuery("").appendTo(".mensagem").addClass("caracter").html("0/500").css({
"top": '-25px',
"position": 'relative',
"font-family": 'Tahoma',
"font-size": '14px',
"color": 'red',
"font-weight": 'bold'
});
jQuery(".your-message textarea").keyup(function() {
jQuery(".caracter").html(jQuery(this).val().length+"/500");
});
jQuery(".wpcf7-form").submit(function() {
jQuery(".wpcf7-submit").attr("type", 'text');
setTimeout(function(){
jQuery(".wpcf7-submit").val("Enviar");
jQuery(".wpcf7-submit").attr("type", 'submit');
if (!jQuery(".wpcf7-not-valid").length) {
window.localStorage.setItem('cachecpf', cachecpf);
window.sessionStorage.setItem('cachecpf', cachecpf);
window.localStorage.setItem('cachedata', cachedata);
window.sessionStorage.setItem('cachedata', cachedata);
location.reload();
}
jQuery(".wpcf7-not-valid").each(function(index, value){
if(index>0){
return false;
}
var campo = jQuery(this).parents("label").text().replace(/.\*\s.*\s.*/,'').replace(/^./,'');
if (campo != "Anexar currículo") {
alert('O campo '+'"'+campo+'"'+' é obrigatório');
} else {
alert('O campo '+'"'+campo+'"'+' é obrigatório \n(limite: 2mb | formatos: pdf, doc, jpg e png )');
}
jQuery(this).focus();
});
}, 1500);
});
});