//Documento com todas as funções javascript utilizadas no site 


//Máscara de Data
function dateMask(inputData, e){
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else //Outros Browsers
	var tecla = e.which;

	if(tecla >= 47 && tecla < 58){ // numeros de 0 a 9 e "/"
		var data = inputData.value;
		if (data.length == 2 || data.length == 5){
			data += '/';
			inputData.value = data;
		}
	}
	else if(tecla == 8 || tecla == 0) // Backspace, Delete e setas direcionais(para mover o cursor, apenas para FF)
		return true;
	else
	return false;
}
//adiciona mascara ao CPF
function MascaraCPF(cpf){
		
        if(mascaraInteiro(cpf)==false){
                event.returnValue = false;
        }       
        return formataCampo(cpf, '000.000.000-00', event);
}




//Função utilizada na index.php
function ValidaLogin() {
	d = document.frmlogin;
	login = document.getElementById("txtlogin").value;
	senha = document.getElementById("txtsenha").value;
	if (login == "") {
		alert("O campo Login deve ser preenchido!");
		d.txtlogin.focus();
		return false;
	}
	else if (senha == "") {
		alert("O campo Senha deve ser preenchido!");
		d.txtsenha.focus();
		return false;
	}
	else {
		return true;	
	}
	
}

//Função utilizada na mostra_mensagem.php
function redireciona() {
	location="index.php?pg=controle";	
}

//Função utilizada na pg editar_perfil.php
function ValidaEditarPerfil() {
	d = document.frmeditar_perfil;
	nome = document.getElementById("txtnome").value;
	login = document.getElementById("txtlogin").value;
	if (nome == "") {
		alert("O campo Nome deve ser preenchido!");
		d.txtnome.focus();
		return false;	
	}
	else if(login == "") {
		alert("O campo Login deve ser preenchido!");
		d.txtlogin.focus();
		return false;
	}
	else {
		return true;	
	}
}

//Função utilizada na pg editar_perfil.php
function ValidaEditarSenha() {
	d = document.frmeditar_senha;
	senha = document.getElementById("txtsenha").value;
	confirmar_senha = document.getElementById("txtconfirmar_senha").value;
	if (senha == "") {
		alert("O campo Senha deve ser preenchido!");
		d.txtsenha.focus();
		return false;	
	}
	else if(confirmar_senha == "") {
		alert("O campo Confirmar Senha deve ser preenchido!");
		d.txtconfirmar_senha.focus();
		return false;
	}
	else if(senha != confirmar_senha) {
		alert("O campo Senha e Confirmar Senha devem ser iguais!");
		d.txtsenha.focus();
		return false;
	}
	else {
		return true;	
	}
	
}

//Função utilizada na página controle_noticias.php
function editarNoticia(codnoticia) {
	location = "index.php?pg=editar_noticia&codnoticia="+codnoticia;
	
}
//Função utilizada na página controle_noticias.php
function excluirNoticia(codnoticia) {
	location = "index.php?pg=excluir_noticia&codnoticia="+codnoticia;
}
//Função utilizada na página controle_noticias.php
function controleNoticias(valor) {
	if(valor == 1) { //Caso for o exibir notícias
		document.getElementById("incluir_noticias").style.display = "none";
		document.getElementById("exibir_noticias").style.display = "block";
	}
	else {	//Caso for incluir_noticias
		document.getElementById("exibir_noticias").style.display = "none";
		document.getElementById("incluir_noticias").style.display = "block";
	}
}

//Função utilizada na página
function habilitarCartilha(codcartilha)
{
	location = "index.php?pg=habilitar_cartilha&codcartilha="+codcartilha;
}

//Função utilizada na página controle_eventos.php
function controleEventos(valor) {
	if(valor == 1) { //Caso for o exibir eventos
		document.getElementById("incluir_eventos").style.display = "none";
		document.getElementById("exibir_eventos").style.display = "block";
	}
	else {	//Caso for inluir eventos
		document.getElementById("exibir_eventos").style.display = "none";
		document.getElementById("incluir_eventos").style.display = "block";
	}
}

//Função utilizada na página controle_cartilha.php
function controleCartilha(valor) {
	if(valor == 1)
	{
		document.getElementById("incluir_cartilha").style.display = "none";
		document.getElementById("exibir_cartilha").style.display = "block";
	}
	else
	{
		document.getElementById("exibir_cartilha").style.display = "none";
		document.getElementById("incluir_cartilha").style.display = "block";
	}
}

//Função utilizada na página controle_eventos.php
function editarEvento(codevento) {
	location = "index.php?pg=editar_evento&codevento="+codevento;
}

//Função utilizada na página controle_eventos.php
function excluirEvento(codevento) {
	location = "index.php?pg=excluir_evento&codevento="+codevento;
}

//Função utilizada na página controle_links.php
function controleLinks(valor) {
	if(valor == 1) { //Caso for o exibir eventos
		document.getElementById("incluir_links").style.display = "none";
		document.getElementById("exibir_links").style.display = "block";
	}
	else {	//Caso for inluir eventos
		document.getElementById("exibir_links").style.display = "none";
		document.getElementById("incluir_links").style.display = "block";
	}
}

//Função utilizada na página controle_links.php
function editarLink(codlink){
	location = "index.php?pg=editar_link&codlink="+codlink;	
}

//Função utilizada na página controle_links.php
function excluirLink(codlink) {
	location = "index.php?pg=excluir_link&codlink="+codlink;	
}

//Função utilizada na página informativo.php e home.php
function exibirNoticia(codnoticia) {
	location = "index.php?pg=exibir_noticia&codnoticia="+codnoticia;	
}

//Função utilizada na página eventos.ph´
function exibirEvento(codevento) {
	location = "index.php?pg=exibir_evento&codevento="+codevento;	
}

//Função utilizada na página filiacao.php
function exibirQual() {
	valor = document.getElementById("txtconselho").value;
	
	if(valor == "CREA") {
		document.getElementById("div_qual").style.display = "none";	
	}
	else{
		document.getElementById("div_qual").style.display = "block";	
	}
}

//Função utilizada na página filiacao.php
function validaFiliacao() {
	d = document.frmfiliacao;
	
	nome = document.getElementById("txtnome").value;
	nascimento = document.getElementById("txtnascimento").value;
	cpf = document.getElementById("txtcpf").value;
	email = document.getElementById("txtemail").value;
	
	if(nome == "") {
		alert("O campo Nome deve ser preenchido!");
		d.txtnome.focus();
		return false;
	}
	else if (nascimento == "") {
		alert("O campo Nascimento deve ser preenchido!");
		d.txtnascimento.focus();
		return false;
	}
	else if(cpf == "") {
		alert("O campo CPF deve ser preenchido!");
		d.txtcpf.focus();
		return false;
	}
	else if(email == "") {
		alert("O campo E-mail deve ser preenchido!"); 
		d.txtemail.focus();
		return false;
	}
	else {
		return true;	
	}
}

/**** FUNÇÃO UTILIZADA na página controle_cadastro.php *****/
function editarCadastro(codcadastro) {
	location = "index.php?pg=editar_cadastro&codcadastro="+codcadastro;	
}

/*** FUNÇÃO UTILIZADA na página controle_cadastro.php ****/
function excluirCadastro(codcadastro) {
	location = "index.php?pg=excluir_cadastro&codcadastro="+codcadastro;	
}

/**** FUNÇÃO utilizada na página controle_informativo.php *****/
function editarInformativo(codinformativo) {
	location = "index.php?pg=editar_informativo&codinformativo="+codinformativo;	
}
/** FUNÇÃO utilizada na página controle_informativo.php ****/
function excluirInformativo(codinformativo) {
	location = "index.php?pg=excluir_informativo&codinformativo="+codinformativo;
}



/*** FUNÇÃO utilizada na página editar_informativo.php ****/
function alterarArquivo(codinformativo, formato) {

	location = "index.php?pg=excluir_arquivo&codinformativo="+codinformativo+"&formato="+formato;
}



/************* MÁSCARAS *******************/

/*Função Pai de Mascaras*/
    function Mascara(o,f){
        v_obj=o
        v_fun=f
        setTimeout("execmascara()",1)
    }
    
    /*Função que Executa os objetos*/
    function execmascara(){
        v_obj.value=v_fun(v_obj.value)
    }
    
    /*Função que Determina as expressões regulares dos objetos*/
    function leech(v){
        v=v.replace(/o/gi,"0")
        v=v.replace(/i/gi,"1")
        v=v.replace(/z/gi,"2")
        v=v.replace(/e/gi,"3")
        v=v.replace(/a/gi,"4")
        v=v.replace(/s/gi,"5")
        v=v.replace(/t/gi,"7")
        return v
    }
    
    /*Função que permite apenas numeros*/
    function Integer(v){
        return v.replace(/\D/g,"")
    }
    
    /*Função que padroniza telefone (11) 4184-1241*/
    function Telefone(v){
        v=v.replace(/\D/g,"")                 
        v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 
        v=v.replace(/(\d{4})(\d)/,"$1-$2")    
        return v
    }
    
    /*Função que padroniza telefone (11) 41841241*/
    function TelefoneCall(v){
        v=v.replace(/\D/g,"")                 
        v=v.replace(/^(\d\d)(\d)/g,"($1) $2")    
        return v
    }
    
    /*Função que padroniza CPF*/
    function Cpf(v){
        v=v.replace(/\D/g,"")                    
        v=v.replace(/(\d{3})(\d)/,"$1.$2")       
        v=v.replace(/(\d{3})(\d)/,"$1.$2")       
                                                 
        v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") 
        return v
    }
    
    /*Função que padroniza CEP*/
    function Cep(v){
        v=v.replace(/D/g,"")                
        v=v.replace(/^(\d{5})(\d)/,"$1-$2") 
        return v
    }
   
 

    /*Função que padroniza DATA*/
    function Data(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d{2})(\d)/,"$1/$2") 
        v=v.replace(/(\d{2})(\d)/,"$1/$2") 
        return v
    }
    
    






