function validaVoto() {

    _objForm = document.getElementById('frmVoto');
    _badFields = Array();
    
    if (vazio(_objForm.nome.value)) {
        _badFields.push('É necessário preencher o campo NOME.');
    } // end :: if
    
    if (vazio(_objForm.email.value) || !emailValido(_objForm.email.value)) {
        _badFields.push('Informe um endereço de e-mail válido.');
    } // end :: if
    
    if ((vazio(_objForm.rg.value) || vazio(_objForm.rgorg.value)) && (vazio(_objForm.cpf.value) || !cpfValido(_objForm.cpf.value))) {
        _badFields.push('Certifique-se de que o CPF ou o RG foram informados corretamente.');
    } // end :: if
    
    if (_badFields.length > 0) {
    	_msg = "";
        //_msg = "Os seguintes campos necessitam ser preenchidos corretamente:\n\n";
        for (i=0;i<_badFields.length;i++) {
            _msg += _badFields[i]+"\n";
        } // end :: for
        alert(_msg);
        return false;
    } // end :: if
    
    return true;

} // end :: validaVoto

function vazio(val) {
    if (val == null || val == "" || val.length == 0) {
        return true;
    } else {
        return false;
    } // end :: if
} // end :: vazio

function cpfValido (numcpf)
{
	x = 0;
	soma = 0;
	dig1 = 0;
	dig2 = 0;
	texto = "";
	numcpf1="";
	len = numcpf.length; x = len -1;
	// var numcpf = "12345678909";
	for (var i=0; i <= len - 3; i++) {
		y = numcpf.substring(i,i+1);
		soma = soma + ( y * x);
		x = x - 1;
		texto = texto + y;
	}
	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ;
	if (dig1 == 11) dig1=0 ;
	numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;
	for (var i=0; i <= len - 2; i++) {
		soma = soma + (numcpf1.substring(i,i+1) * x);
		x = x - 1;
	}
	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0;
	if (dig2 == 11) dig2=0;
	//alert ("Digito Verificador : " + dig1 + "" + dig2);
	if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
		return true;
	}
	return false;
}


function nu(campo) {
	var digits="0123456789"
	var campo_temp 
	for (var i=0;i<campo.value.length;i++){
		campo_temp=campo.value.substring(i,i+1) 
		if (digits.indexOf(campo_temp)==-1){
			campo.value = campo.value.substring(0,i);
			break;
		}
	}
}


function emailValido(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
                    return true;
                }
    }else{
        return false;
        }
}

function changeToStep(num) {
	// Close all
	for (var i=1;i<=3;i++) {
		document.getElementById('passo'+i).style.display = 'none';
		document.getElementById('letraTab'+i).style.color = '#9f4700';
	} // end :: for

	document.getElementById('letraTab'+num).style.color = '#fefd02';	
	document.getElementById('passo'+num).style.display = 'block';
}












