function toggleBranco(branco) {    
    
    var mae = branco.form.mae;
    
    if (branco.checked) {
        mae.value    = "";
        mae.disabled = true;
    }
    else {
        mae.disabled = false;
    }
    
} //toggleBranco

function validar(tipo){

    function getValorSelecionado(select) {
        return select.options[select.selectedIndex].value;
    }
    
    var form;
    var mae, dia, mes, ano, branco;
    var titulo, nome;

	if (tipo == "titulo") {
        form = document.formTitulo;
        
        titulo = form.titulo;
        if (!isTituloValido(titulo.value)) {
            alert("ATENÇÃO: O título informado não é válido.");
            titulo.select();
            return false;
        }        
	}	
	else if (tipo == "nome") {
		form = document.formNome;
		nome = form.nome;
		nome.value = nome.value.trim();
		
		if (nome.value.length < 5) {
            alert("ATENÇÃO: Informe um nome válido.");
            nome.select();
            return false;
		}		
	}
	
	// Validando o dia do nascimento
	dia = form.dia;
	if (getValorSelecionado(dia) == "") {
        alert("ATENÇÃO: Informe o dia do nascimento corretamente.");
        dia.focus();
        return false;
    }
    
	// Validando o mes do nascimento
	mes = form.mes;
	if (getValorSelecionado(mes) == "") {
        alert("ATENÇÃO: Informe o mês do nascimento corretamente.");
        mes.focus();
        return false;
    }
    
    // Validando o ano do nascimento
	ano = form.ano;
	if (getValorSelecionado(ano) == "") {
        alert("ATENÇÃO: Informe o ano do nascimento corretamente.");
        ano.focus();
        return false;
    }
    
    // Validando o nome da mãe
    branco = form.branco;
	mae    = form.mae;
	if (branco.checked) {
        mae.value = "";
	}
	else {	
        mae.value = mae.value.trim();		
        if (mae.value.length < 5) {
            alert("ATENÇÃO: Informe um nome válido para a mãe.");
            mae.select();
            return false;
        }
    }
	
	return true;
	
} //validar

function toggleConsultaForm(idTitle, idTable, txtOn, txtOff) {
	elTitle = getElementById(idTitle);
	elTable = getElementById(idTable);
	if (elTable.style.display == "none") {
		elTitle.innerHTML = txtOn;
		elTable.style.display = "block";
	} else {
		elTitle.innerHTML = txtOff;
		elTable.style.display = "none";
	}
}

function toggleTitulo() {
	toggleConsultaForm("titleTitulo", "tableTitulo", "Consulta por Título Eleitoral:", "Deseja consultar por título eleitoral?");
}

function toggleNome() {
	toggleConsultaForm("titleNome", "tableNome", "Consulta por Nome:", "Deseja consultar por nome?");
}
