﻿function ValidarCPF(source, arguments) {
    var cpf = arguments.Value;
    if (valida_cpf(cpf.replace(".", "").replace(".", "").replace("-", "")) == false) {
    	arguments.IsValid = false;
    	return false
    }
    arguments.IsValid = true;
}

function ValidaCheckRegulamento() {
	var checked = document.getElementById('chkAceite').checked;
	if (checked)
		document.getElementById('btnProsseguir').disabled = false;
	else
		document.getElementById('btnProsseguir').disabled = true;
}

function checkIt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
    	return false
    }
    return true
}

function ValidarUF(source, arguments) {
	var oCombo = document.getElementById('DropDownUF');

    if (oCombo[oCombo.selectedIndex].value == "0") {
    	arguments.IsValid = false;
    	return false
    } else {
    	arguments.IsValid = true;
    }
}


//Mascara de CPF, CNPJ, TEL, DATA E CEP
//Funciona tanto no IE como no FF
function Mascara(tipo, campo, teclaPress) {
    if (window.event) {
    	var tecla = teclaPress.keyCode;
    } else {
    	tecla = teclaPress.which;
    }

    var s = new String(campo.value);
    // Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
    s = s.replace(/(\.|\(|\)|\/|\-| )+/g, '');

    tam = s.length + 1;

    if (tecla != 9 && tecla != 8) {
    	switch (tipo) {
    		case 'CPF':
    			if (tam > 3 && tam < 7)
    				campo.value = s.substr(0, 3) + '.' + s.substr(3, tam);
    			if (tam >= 7 && tam < 10)
    				campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.' + s.substr(6, tam - 6);
    			if (tam >= 10 && tam < 12)
    				campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.' + s.substr(6, 3) + '-' + s.substr(9, tam - 9);
    			break;

    		case 'CNPJ':

    			if (tam > 2 && tam < 6)
    				campo.value = s.substr(0, 2) + '.' + s.substr(2, tam);
    			if (tam >= 6 && tam < 9)
    				campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.' + s.substr(5, tam - 5);
    			if (tam >= 9 && tam < 13)
    				campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.' + s.substr(5, 3) + '/' + s.substr(8, tam - 8);
    			if (tam >= 13 && tam < 15)
    				campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.' + s.substr(5, 3) + '/' + s.substr(8, 4) + '-' + s.substr(12, tam - 12);
    			break;

    		case 'TEL':
    			if (tam > 2 && tam < 4)
    				campo.value = '(' + s.substr(0, 2) + ') ' + s.substr(2, tam);
    			if (tam >= 7 && tam < 11)
    				campo.value = '(' + s.substr(0, 2) + ') ' + s.substr(2, 4) + '-' + s.substr(6, tam - 6);
    			break;

    		case 'DATA':
    			if (tam > 2 && tam < 4)
    				campo.value = s.substr(0, 2) + '/' + s.substr(2, tam);
    			if (tam > 4 && tam < 11)
    				campo.value = s.substr(0, 2) + '/' + s.substr(2, 2) + '/' + s.substr(4, tam - 4);
    			break;

    		case 'CEP':
    			if (tam > 5 && tam < 7)
    				campo.value = s.substr(0, 5) + '-' + s.substr(5, tam);
    			break;
    	}
    }
}


function ShowHideParticipanteInscricao(num) {
	var oDiv = document.getElementById('divPart' + num + 'Cont');
	var oA = document.getElementById('linkAbrePart' + num);
	var oHidden = document.getElementById('hfParticipante0' + num);

	var oValidatorCPF = document.getElementById('cvCpfPartcipante0' + num);
	var oValidatorNome = document.getElementById('rfvNomeParticipante0' + num);
	var oValidatorEmail1 = document.getElementById('revEmailParticipante0' + num);
	var oValidatorEmail2 = document.getElementById('rfvEmailParticipante0' + num);

	var oValidatorSenha = document.getElementById('rfvCampoSenha0' + num);
	var oValidatorCompararSenha = document.getElementById('cvCompararSenha0' + num);
	var oValidatorConfirmaSenha = document.getElementById('rfvCampoConfirmaSenha0' + num);
	
	if (oDiv.style.display == 'none') {
		oHidden.value = '1';
		oDiv.style.display = 'block';
		oA.innerHTML = '-';

		ValidatorEnable(oValidatorCPF, true);
		oValidatorCPF.isvalid = true;
		ValidatorUpdateDisplay(oValidatorCPF);

		ValidatorEnable(oValidatorNome, true);
		oValidatorNome.isvalid = true;
		ValidatorUpdateDisplay(oValidatorNome);

		ValidatorEnable(oValidatorEmail1, true);
		oValidatorEmail1.isvalid = true;
		ValidatorUpdateDisplay(oValidatorEmail1);

		ValidatorEnable(oValidatorEmail2, true);
		oValidatorEmail2.isvalid = true;
		ValidatorUpdateDisplay(oValidatorEmail2);

		ValidatorEnable(oValidatorSenha, true);
		oValidatorSenha.isvalid = true;
		ValidatorUpdateDisplay(oValidatorSenha);

		ValidatorEnable(oValidatorCompararSenha, true);
		oValidatorCompararSenha.isvalid = true;
		ValidatorUpdateDisplay(oValidatorCompararSenha);

		ValidatorEnable(oValidatorConfirmaSenha, true);
		oValidatorConfirmaSenha.isvalid = true;
		ValidatorUpdateDisplay(oValidatorConfirmaSenha);


	} else {
		oHidden.value = '0';
		oDiv.style.display = 'none';
		oA.innerHTML = '+';

		ValidatorEnable(oValidatorCPF, false);
		ValidatorEnable(oValidatorNome, false);
		ValidatorEnable(oValidatorEmail1, false);
		ValidatorEnable(oValidatorEmail2, false);
		ValidatorEnable(oValidatorSenha, false);
		ValidatorEnable(oValidatorCompararSenha, false);
		ValidatorEnable(oValidatorConfirmaSenha, false);
	}
}


