// JavaScript Document
<!--
function valida_login_administradores(obj){
	if(obj.login.value == ""){
		alert("Informe o Login!");
		obj.login.focus();
		return false;
	}
	if(obj.senha.value == ""){
		alert("Informe a Senha!");
		obj.senha.focus();
		return false;
	}	
}

function valida_login_membros(obj){
	if(obj.login2.value == ""){
		alert("Informe o Login (nº Matrícula)!");
		obj.login2.focus();
		return false;
	}
	if(obj.senha2.value == ""){
		alert("Informe a Senha!");
		obj.senha2.focus();
		return false;
	}	
}

function valida_associar_perfil(obj){
	if(obj.codigo_perfil.value == ""){
		alert("Informe o Perfil para associar!");
		obj.codigo_perfil.focus();
		return false;
	}
}
function valida_associar_usuario(obj){
	if(obj.codigo_usuario.value == ""){
		alert("Informe o usuário para associar!");
		obj.codigo_usuario.focus();
		return false;
	}
}
function valida_associar_pagina(obj){
	if(obj.codigo_pagina.value == ""){
		alert("Informe a Página para associar!");
		obj.codigo_pagina.focus();
		return false;
	}
}

function valida_dependente(obj){
	if(obj.nome.value == ""){
		alert("Informe o Nome do Dependente!");
		obj.nome.focus();
		return false;
	}
	if (validaCPF(obj.cpf) == false){
		return false;
	}
	if(obj.grau_parentesco.value == ""){
		alert("Informe o Grau de Parentesco!");
		obj.grau_parentesco.focus();
		return false;
	}
	if(obj.membro.value == ""){
		alert("Informe o Membro!");
		obj.membro.focus();
		return false;
	}	
}

function valida_login(obj){
	if (validaEmail(obj.email) == false){
			return false;
	}
}

function valida_usuario(obj){
	if(obj.nome.value == ""){
		alert("Informe o Nome!");
		obj.nome.focus();
		return false;
	}
	if (validaEmail(obj.email) == false){
			return false;
	}
/*
	if (validaCPF(obj.cpf) == false){
		return false;
	}
*/
	if(obj.apelido.value == ""){
		alert("Informe o Apelido!");
		obj.apelido.focus();
		return false;
	}
	
/*	if(obj.cidade.value == ""){
		alert("Informe a Cidade!");
		obj.cidade.focus();
		return false;
	}	
	if(obj.telefone.value == ""){
		alert("Informe o Telefone para contato!");
		obj.telefone.focus();
		return false;
	}
*/	if(obj.senha.value == ""){
		alert("Informe a Senha!");
		obj.senha.focus();
		return false;
	}
	if(obj.confirma_senha.value == ""){
		alert("Confirme a Senha!");
		obj.confirma_senha.focus();
		return false;
	}
	if(obj.confirma_senha.value != "" && obj.senha.value != ""){
		if(obj.confirma_senha.value != obj.senha.value){
			alert("Senha não confere!");
			obj.confirma_senha.focus();
			return false;
		}
	}		
}
function valida_perfil(obj){
	if(obj.nome.value == ""){
		alert("Informe o Nome para o Perfil!");
		obj.nome.focus();
		return false;
	}
	if(obj.observacao.value == ""){
		alert("Informe a Observação!");
		obj.observacao.focus();
		return false;
	}	
}
function valida_pagina(obj){
	if(obj.url.value == ""){
		alert("Informe a URL da página!");
		obj.url.focus();
		return false;
	}
	if(obj.observacao.value == ""){
		alert("Informe a Observação!");
		obj.observacao.focus();
		return false;
	}	
}
function valida_membro(obj){
	if(obj.nome.value == ""){
		alert("Informe o Nome!");
		obj.nome.focus();
		return false;
	}
	if (validaCPF(obj.cpf) == false){
		return false;
	}
	if(obj.matricula.value.length < 5){
		alert("Matrícula Inválida! São necessários 5 dígitos");
		obj.matricula.focus();
		return false;
	}	
	if(obj.endereco.value == ""){
		alert("Informe o Endereço!");
		obj.endereco.focus();
		return false;
	}	
	if(obj.cidade.value == ""){
		alert("Informe a Cidade!");
		obj.cidade.focus();
		return false;
	}	
	if(obj.uf.value == ""){
		alert("Informe o UF!");
		obj.uf.focus();
		return false;
	}	
	if(obj.cep.value == ""){
		alert("Informe o CEP!");
		obj.cep.focus();
		return false;
	}		
	if(obj.tel_trabalho.value == ""){
		alert("Informe o Telefone do Trabalho (Ramal)!");
		obj.tel_trabalho.focus();
		return false;
	}
	if (validaEmail(obj.email) == false){
		return false;
	}
	if(obj.foto.value != ""){
		if(obj.foto.value.indexOf(".jpg") == -1 && obj.foto.value.indexOf(".JPG") == -1){
			alert("Só é permitida foto no formato 'JPG'");
			obj.foto.focus();
			return false;		
		}		
	}
	if(obj.senha.value == ""){
		alert("Informe a Senha!");
		obj.senha.focus();
		return false;
	}
	if(obj.confirma_senha.value == ""){
		alert("Confirme a Senha!");
		obj.confirma_senha.focus();
		return false;
	}
	if(obj.confirma_senha.value != "" && obj.senha.value != ""){
		if(obj.confirma_senha.value != obj.senha.value){
			alert("Senha não confere!");
			obj.confirma_senha.focus();
			return false;
		}
	}		
}

function validaCPF(campo) {
		 
		com_ponto = new String(campo.value)
		espaco = new String("")
		rExp = /[.^-]/g
		cpf = com_ponto.replace(rExp, espaco);		

		 if (cpf.length < 11){
			 alert("São necessários 11 dígitos para verificação do CPF!");
			 campo.focus();
			 return false;
		}
		 var nonNumbers = /\D/;
		 if (nonNumbers.test(cpf)){
			 alert("A verificação de CPF suporta apenas números!");
			 campo.focus();
			 return false;
		 }
		 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
			alert("Número de CPF inválido!")
			 campo.focus();
			 return false;			
		}
	   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])){
		    alert("Dígito verificador com problema!");	
			 campo.focus();
			 return false;		   
	   }

}

function alt_onchange(){        
document.form.submit();
}

function Tecla(e){
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;


	// numeros de 0 a 9
	if((tecla > 47 && tecla < 58) || (tecla > 95 && tecla < 106) ){ 
		return true;
	}else{
		//aceita BACKSPACE, DELETE , SETA ESQUERDA e DIREITA
		if (tecla != 8 && tecla != 46 && tecla != 37 && tecla != 39)
			return false;
		else
			return true;
	}
}


function mascaraData(campo) { 
	var data = ""; 
	var tecla = window.event.keyCode; 
	
	if (Tecla(event)){		
		if (tecla != 8 && tecla != 46 && tecla != 37 && tecla != 39){ 
			data = cleanStr(campo.value,"0123456789"); 
			var tam = data.length; 
			if (tam > 1) data = data.substr(0,2) + "/" + data.substr(2, tam); 
			if (tam > 3) data = data.substr(0,5) + "/" + data.substr(5, tam); 
			campo.value = data; 
		} 
	}else{
		return false;
	}		
} 

function mascaraCPF(campo) { 
	var cpf = ""; 
	var tecla = window.event.keyCode;

	if (Tecla(event)){			
		cpf = cleanStr(campo.value,'0123456789'); 
		var tam = cpf.length; 	

		if (tecla != 8 && tecla != 46 && tecla != 37 && tecla != 39){ 
			if (tam > 2) cpf = cpf.substr(0,3) + "." + cpf.substr(3, tam); 
			if (tam > 5) cpf = cpf.substr(0,7) + "." + cpf.substr(7, tam); 
			if (tam > 8) cpf = cpf.substr(0,11) + "-" + cpf.substr(11, tam); 		
			campo.value = cpf; 
		}
	}else{
		return false;
	}
} 

function mascaraMoeda(campo){
		dec = 2;
		var tecla = window.event.keyCode; 
		
		if (Tecla(event)){
			vr = cleanStr(campo.value,"0123456789");
			tam = vr.length;

			if (tecla == 8){
				tam = tam - 1 ; 
			}else{
				tam = tam + 1 ;
			}
			if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )		{		
				if ( tam <= dec ){ campo.value = vr ; }		
				if ( tam > dec && tam <= 5 ){campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
				if ( tam >= 6 && tam <= 8 ){campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 		}
				if ( tam >= 9 && tam <= 11 ){campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
				if ( tam >= 12 && tam <= 14 ){campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
				if ( tam >= 15 && tam <= 17 ){campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}		
			} 
	
		}else{
			return false;
		}
}

function mascaraTelefone(objeto){
		if (objeto.value.indexOf("-") == -1 && objeto.value.length > 5){ objeto.value = ""; }
		if (objeto.value.length == 2){
			objeto.value +="-";
		}
		if (objeto.value.length == 7){
			objeto.value +="-";
		}
}
	
function mascaraCep(campo){
	var tecla = window.event.keyCode;
	if (Tecla(event)){	
		cep = cleanStr(campo.value,"0123456789");
		tam = cep.length;
		
		if (tecla != 8 && tecla != 46 && tecla != 37 && tecla != 39){ 
			if (tam > 4) cep = cep.substr(0,5) + "-" + cep.substr(5, tam); 
			campo.value = cep; 
		}				
	}else{
		return false;
	}
}

// retira caracteres invalidos da string 
function cleanStr(str,validos){ 
	var i,temp = ""; 
	for (i=0;i<str.length;i++){ 
		if (validos.indexOf(str.charAt(i)) != -1){ 
			temp += str.charAt(i); 
		} 
	} 
	return temp; 
} 

function validaData(campo){
		dia = (campo.value.substring(0,2)); 
		mes = (campo.value.substring(3,5)); 
		ano = (campo.value.substring(6,10)); 
		// verifica o dia valido para cada mes 
		if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
			alert("Valor do dia inválido! Favor Corrigir.");
			campo.focus();
			return false;
		} 
		// verifica se o mes e valido 
		if (mes < 01 || mes > 12 ) { 
			alert("Valor do mes inválido! Favor Corrigir.");
				campo.focus();
			return false;
		} 
			// verifica se e ano bissexto 
		if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
			alert("Valor do ano inválido! Favor Corrigir.");
			campo.focus();
			return false;
		} 
}
function validaEmail(campo){
	//VERIFICA E-MAIL
	var email = campo.value;
	var BadChars = "*|,\":<>[]{}`\'';()&$#% ";
	var GoodChars = "@."; 
	var posarroba = email.indexOf ('@',0);
	if (campo.value == '') // o email é menor que 6 caracteres
	{	
		alert("O campo E-mail deve ser preenchido! Favor Corrigir.");
		campo.focus();
		return false;
	}	
	if (email.length < 6) // o email é menor que 6 caracteres
	{	
		alert("E-mail inválido!");
		campo.focus();
		return false;
	}
	for (var i = 0; i < email.length; i++) 
	{
		if (BadChars.indexOf(email.charAt(i)) != -1) // Contém caracteres inválidos, badchars
		{			
			alert("E-mail contém caracteres inválido!");
			campo.focus();
			return false;
		}	
	}
	for (var i = 0; i < GoodChars.length; i++) 
		{
		if (email.indexOf(GoodChars.charAt(i)) == -1) // não tem goodchars
		{			
			alert("E-mail inválido!");
			campo.focus();
			return false;
		}
		if (email.indexOf(GoodChars.charAt(i),0) == 0) // começou com goodchars (. ou @)
		{		
			alert("E-mail inválido!");
			campo.focus();
			return false;
		}
		if (email.lastIndexOf(GoodChars.charAt(i)) > email.length-3) //existe menos de 2 caracteres depois do ultimo goodchar
		{			
			alert("E-mail inválido! Seu e-mail não deve terminar com @.");
			campo.focus();
			return false;
		}
	}
	if (email.lastIndexOf('@') > email.lastIndexOf('.')) //Não tem ponto depois do arroba
	{		
		alert("E-mail inválido!");
		campo.focus();
		return false;
	}

	if (email.indexOf ('@.',0) != -1 || email.indexOf ('.@',0) != -1) // . e @ colados
	{	
	alert("E-mail inválido!");
		campo.focus();
		return false;
	}
	if (email.indexOf ('@',posarroba+1) != -1) // Contém mais de um " @ " 
	{		
		alert("E-mail inválido!");
		campo.focus();
		return false;
	}
}

function somenteNumeros(campo){
	var tecla = window.event.keyCode;	
	if (Tecla(event)){			
		campo.value = cleanStr(campo.value,"0123456789/");
	}else{
		return false;
	}
}

function somenteLetras(campo){
	var tecla = window.event.keyCode;	
		
		if ( (tecla < 65 || tecla >90) && tecla != 13 && tecla != 9 && tecla != 8 && tecla != 46 && tecla != 37 && tecla != 39){
			return false;
		}
		
}


function verTodos(form) {
	e = form.elements;
	todos = true
	for (i=0; i<e.length; i++) 
		if (e[i].type == "checkbox" )
			if (e[i].checked == false) { 
				todos = false;
				markTRcheckbox(e[i],0);
			} 
			else {
				markTRcheckbox(e[i],1);
			}
			form.checked = eval(todos)
}

function markTRcheckbox(checkObj,mark){
	if(checkObj.parentNode){
		var pai=checkObj.parentNode;
		while(pai.nodeName!="TR"){pai=pai.parentNode};
		if(mark){
			pai.className=pai.className.match(/TR_marcado/)?pai.className:pai.className+" TR_marcado";			
		}else{
			pai.className=pai.className.match(/TR_marcado/)?pai.className.replace(" TR_marcado",""):pai.className;
		}
	}
}   

function ordernar(campo, form){
		form.ordernar_click.value = campo;
		form.querySQL.value = form.querySQL.value + " ORDER BY " + campo;
		form.submit();
}


//Funções de exlcuir
function confirma_excluir(url){
	if (confirm("Tem certeza que deseja excluir?")) {
		parent.frame_tela.location.href= url;
	}
}
function confirma_excluir_selecionados(formulario){
	cont = 0;
	for (var i=0;i<formulario.elements.length;i++) {
		if(formulario.elements[i].checked == true){
			cont +=1;
		}
	}
	if(cont == 0) {
		alert("Nenhum registro foi selecionado!");
	}else{
		if (confirm("Tem certeza que deseja excluir os itens selecionados?")) {
			formulario.submit();
		}
	}
}
function confirma_exportar_selecionados(formulario){
	if(formulario.exportar.value =="1"){
		cont = 0;
		for (var i=0;i<formulario.elements.length;i++) {
			if(formulario.elements[i].checked == true){
				cont +=1;
			}
		}
		if(cont == 0) {
			alert("Nenhum registro foi selecionado!");
		}else{
//			if (confirm("sddos?")) {
				formulario.action = "exportar_selecionados.asp";
				formulario.submit();
//			}
		}
	}else{
//		if (confirm("sddos?")) {
			formulario.action = "exportar_selecionados.asp";
			formulario.submit();
//		}		
	}	
}

function marcar_checkbox(formulario){
	for (var i=0;i<formulario.elements.length;i++) {
		if(formulario.elements[i].checked == false){
			formulario.elements[i].checked = true;
		}else{
			formulario.elements[i].checked = false;
		}		
	}
	verTodos(formulario);
}

function buscaPagina(){
	var achou = "";
	var i = 0;
	var total = document.getElementById("codigo_pagina").options.length; 
	while(i<total){
		url = new String(document.getElementById("codigo_pagina").options[i].busca_url);
		url = url.toUpperCase();
		obs = new String(document.getElementById("codigo_pagina").options[i].busca_obs);
		obs = obs.toUpperCase();
		argumento = new String(document.getElementById("argumento").value);
		argumento = argumento.toUpperCase();		
		
		if(obs.indexOf(argumento) != -1){
		   document.getElementById("codigo_pagina").options.selectedIndex = i;
		   achou = "sim";
		   break;
		}else if(url.indexOf(argumento) != -1 ){
		   document.getElementById("codigo_pagina").options.selectedIndex = i;
		   achou = "sim";
		   break;
		}
		
	   i++; 
	}

	if (achou != "sim"){
		document.getElementById("codigo_pagina").options.selectedIndex = 0;
	}

}
function buscaPerfil(){
	var achou = "";
	var i = 0;
	var total = document.getElementById("codigo_perfil").options.length; 
	while(i<total){
		nome = new String(document.getElementById("codigo_perfil").options[i].busca_nome);
		nome = nome.toUpperCase();
		obs = new String(document.getElementById("codigo_perfil").options[i].busca_obs);
		obs = obs.toUpperCase();
		argumento = new String(document.getElementById("argumento").value);
		argumento = argumento.toUpperCase();		
		
		if(obs.indexOf(argumento) != -1){
		   document.getElementById("codigo_perfil").options.selectedIndex = i;
		   achou = "sim";
		   break;
		}else if(nome.indexOf(argumento) != -1 ){
		   document.getElementById("codigo_perfil").options.selectedIndex = i;
		   achou = "sim";
		   break;
		}
		
	   i++; 
	}

	if (achou != "sim"){
		document.getElementById("codigo_perfil").options.selectedIndex = 0;
	}

}

function buscaUsuario(){
	var achou = "";
	var i = 0;
	var total = document.getElementById("codigo_usuario").options.length; 
	while(i<total){
		nome = new String(document.getElementById("codigo_usuario").options[i].busca_nome);
		nome = nome.toUpperCase();
		login = new String(document.getElementById("codigo_usuario").options[i].busca_login);
		login = login.toUpperCase();		
		cpf = new String(document.getElementById("codigo_usuario").options[i].busca_cpf);
		cpf = cpf.toUpperCase();
		argumento = new String(document.getElementById("argumento").value);
		argumento = argumento.toUpperCase();		
		
		if(cpf.indexOf(argumento) != -1){
		   document.getElementById("codigo_usuario").options.selectedIndex = i;
		   achou = "sim";
		   break;
		}else if(login.indexOf(argumento) != -1 ){
		   document.getElementById("codigo_usuario").options.selectedIndex = i;
		   achou = "sim";
		   break;
		}else if(nome.indexOf(argumento) != -1 ){
		   document.getElementById("codigo_usuario").options.selectedIndex = i;
		   achou = "sim";
		   break;
		}
		
	   i++; 
	}

	if (achou != "sim"){
		document.getElementById("codigo_usuario").options.selectedIndex = 0;
	}

}




//***************************************************************
//Função para relógio
function relogio(hora, minuto, segundo){
	if(hora != null){
	    momentoAtual = new Date() 
	    momentoAtual.setHours(hora) 
	    momentoAtual.setMinutes(minuto) 
	    momentoAtual.setSeconds(segundo) 
	}
	momentoAtual.setSeconds( momentoAtual.getSeconds(segundo) + 1 )
	
    hora = momentoAtual.getHours(hora)
    minuto = momentoAtual.getMinutes(minuto)	
    segundo = momentoAtual.getSeconds(segundo) 
	
	if(hora<10){hora = "0"+hora;}
	if(minuto<10){minuto = "0"+minuto;}	
	if(segundo<10){segundo = "0"+segundo;}
	
    horaImprimivel = hora + ":" + minuto + ":" + segundo

	campo_hora.innerHTML = horaImprimivel;

    setTimeout("relogio()",1000) 
} 


//Funções dos botões da ABA do menu
function opcao(escolha, titulo){
	parent.escolha.value = escolha;
	parent.titulo_escolha.value = titulo;
	
	parent.icone.src = "imagens/ico_"+escolha+".jpg";
	parent.icone.style.display = "block";
	
	parent.menu_lateral.style.display = "block";
	parent.botao_importar.style.display = "block";	
	parent.botao_exportar.style.display = "block";	
	parent.botao_inserir.style.display = "block";
	parent.botao_pesquisar.style.display = "block";
	parent.botao_imprimir.style.display = "block";
	desmarca_opcao();
}
function abre_opcao(escolha){
	caminho = parent.escolha.value + "/" + escolha + ".asp";
	parent.frame_tela.location.href = caminho;
	
	desmarca_opcao();
	marca_opcao(escolha);
}
function desmarca_opcao(){
	parent.botao_importar.src = "imagens/importar_out.gif";
	parent.botao_exportar.src = "imagens/exportar_out.gif";	
	parent.botao_inserir.src = "imagens/inserir_out.gif";
	parent.botao_pesquisar.src = "imagens/pesquisar_out.gif";
	parent.botao_imprimir.src = "imagens/imprimir_out.gif";	
}
function marca_opcao(escolha){
	botao = escolha.replace("form_","");
	eval("parent.botao_"+botao).src = "imagens/"+botao+"_in.gif";		
}

//***************************************************************
//coloca o titulo da pagina do frame no descritivo

if(parent.titulo_escolha != null){
	txt_titulo = new String(parent.titulo_escolha.value);
	index_b = txt_titulo.indexOf(" / ");
	if(index_b > 0){
		parent.titulo_escolha.value = txt_titulo.substring(0, index_b) +" / "+ document.title;
	}else{
		parent.titulo_escolha.value = txt_titulo +" / "+ document.title;	
	}
}
//***************************************************************
//




//
-->
