﻿jQuery.validator.addMethod("verificaCPF", function(value, element) {
    if(value=='000.000.000-00') return true;
    value = value.replace('.','');  
    value = value.replace('.','');  
    cpf = value.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;
}, "Informe um CPF válido."); // Mensagem padrão	


$(function(){
    //Imprimir
    $("#bt-imprimir").click(function(e){
        window.open($(this).attr("href"), 'imprimir', 'width=500, height=500, scrollbars=1');
        e.preventDefault();
    });
    
    //Oculta comentário
    $("div[id^=coment]").hide();

    $("input[name=IDVaga]").click(function(){
        if($(this).hasClass("espera")){
            $("#listaEspera").val("1");
            $("#dsp-turno-inverso").show("normal");
        }else{
            $("#listaEspera").val("0");
            $("#dsp-turno-inverso").hide("normal");
        };
        
        $("div[id^=coment]").hide("normal");
        $("#coment-" + $(this).val()).show("normal");
        
        $(".vaga-selecionada").removeClass("vaga-selecionada");
        $(this).parent().addClass("vaga-selecionada");
    });
    
    $("#cpf").mask("999.999.999-99");
     
    $("#btn-voltar").click(function(){
        document.location.href="<%= dirVirtual %>";
    });

 
    $("#frmficha").validate(
    {
        rules: 
        {
            IDVaga: "required",
            turnoInverso: 
            {
                required: function(){ return $("input#listaEspera").val()!=0;} 
            },
            turnoExtra: "required",
            contratante: "required",
            cpf: 
            {
                required: true,
                verificaCPF: true
            },
            mesmoend: "required"
        },
        messages: 
        {
            IDVaga: "Informe a vaga pretendida",
            turnoInverso: "Informe se há interesse por turno inverso",
            turnoExtra: "Informe se há interesse por turno extra",
            contratante: "Informe quem será o contratante",
            cpf: 
            {
                required: "Informe o CPF do contratante"
            },
            mesmoend: "Informe se o contratante mora no mesmo endereço do candidato"
        }
    
    });
	
	
	
	
});