// JavaScript Document

	function apareceEl(tag){
		var tag = document.getElementById(tag);	
		
		if(tag.style.display == 'none'){
			tag.style.display = 'block';
		}else{
			tag.style.display = 'none';
		}
	}


	
	function format_cpf(aux){
			if(document.getElementById(aux).value.length == 3 || document.getElementById(aux).value.length == 7){
							document.getElementById(aux).value += ".";
			}else{
					if(document.getElementById(aux).value.length == 11){
						document.getElementById(aux).value += "-";
						}	
				}
			
	}
	
	/**
	*
	*Formata a Data automaticamente
	*
	**/
	function format_data(aux){
			if(document.getElementById(aux).value.length == 2 || document.getElementById(aux).value.length == 5){
							document.getElementById(aux).value += "/";
			}
			
	}

	
	/**
	*
	*Formata o campo telefone
	*
	**/
	function formatFone(aux){
		var campo = document.getElementById(aux);
		if(campo.value.length == 1){
			campo.value = '('+campo.value;
		}
		if(campo.value.length == 3){
			campo.value = campo.value+')';
		}
	}
	
	
	/**
	*
	*Formata o campo cep
	*
	**/
	function formatCep(aux){
		var campo = document.getElementById(aux);
		if(campo.value.length == 5){
			campo.value = campo.value+'-';
		}
	}
	
	
	
	function validaCadastro(temsenha){
		var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
		var nome = document.getElementById('nome');
		var cpf = document.getElementById('cpf');
		var fone = document.getElementById('fone');
		var email = document.getElementById('email');
		var senha = document.getElementById('senha');
		var confirma = document.getElementById('confirma');
		var erro = '';
		
		
		if(nome.value == ''){
			erro += "O Nome deve ser informado! \r\n";
			nome.style.border = '1px solid #FF0000';
		}else{
			nome.style.border = '1px solid #009933';
		}
		
		if(cpf.value == ''){
			erro += "O CPF deve ser informado! \r\n";
			cpf.style.border = '1px solid #FF0000';
		}else{
			cpf.style.border = '1px solid #009933';
		}
		
		if(fone.value == ''){
			erro += "O Telefone deve ser informado! \r\n";
			fone.style.border = '1px solid #FF0000';
		}else{
			fone.style.border = '1px solid #009933';
		}
		
		if(email.value == '') {
			erro += "O Email deve ser informado! \r\n";
			email.style.border='1px solid #FF0000';
		}else{
			if(er.test(email.value)) {
				email.style.border='1px solid #009933';
			} else {
				erro += "O Email "+email.value+" é invalido!\r\n";
				email.style.border='1px solid #FF0000';
			}
			
		}
		
		if(temsenha == 's'){
		
				if(senha.value == ''){
					erro += "A senha deve ser informada! \r\n";
					senha.style.border = '1px solid #FF0000';
				}else{
					if(senha.value != confirma.value){
						erro += "A senha não foi confirmada! \r\n";
						senha.style.border = '1px solid #FF0000';
						confirma.style.border = '1px solid #FF0000';
					}else{
						senha.style.border = '1px solid #009933';
						confirma.style.border = '1px solid #009933';	
					}
				}
		
		}else if(temsenha == 'n'){
			if(senha.value != ''){
				if(senha.value != confirma.value){
						erro += "A senha não foi confirmada! \r\n";
						senha.style.border = '1px solid #FF0000';
						confirma.style.border = '1px solid #FF0000';
					}else{
						senha.style.border = '1px solid #009933';
						confirma.style.border = '1px solid #009933';	
					}
			}
		}
		
		
		if(erro == ''){
			return true;
		}else{
			alert(erro);
			return false;
		}
	}
	
	
	
	function Limpar(valor, validos) {

		// retira caracteres invalidos da string

		var result = "";

		var aux;

		for (var i=0; i < valor.length; i++) {

		aux = validos.indexOf(valor.substring(i, i+1));

		if (aux>=0) {

		result += aux;

		}

		}

		return result;

}





		//////////////////////////////////////////////////////////////////////////////////////////
		
		////FORMATA O CAMPO VALOR COLOCANDO AS VÍRGULA QUANDO FOR PREÇO EM REAIS /////////////////
		
		function Formata(campo,tammax,teclapres,decimal) {
					var tecla = teclapres.keyCode;
					vr = Limpar(campo.value,"0123456789");
					tam = vr.length;
					dec=decimal
		
					if (tam < tammax && tecla != 8){
						tam = vr.length + 1 ; 
					}		
		
					if (tecla == 8 ){
						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 ) ;
						}
					} 
		}
		
		
		/**
		*
		* Funcao que muda do tamanho da fonte dos textos
		* var bloco = div onde está o texto
		* var tipo = se almenta ou diminui
		*
		**/
		function tamanhoTexto(bloco, tipo){
			var bloco = document.getElementById(bloco);
			var tamanho = bloco.style.fontSize.replace(/px/,'');
			
			if(tipo == 'mais'){
				tamanho++;
				bloco.style.fontSize = tamanho+'px';
			}else{
				tamanho--;
				if(tamanho != 0){
					bloco.style.fontSize = tamanho+'px';
				}
				
				
			}
			
		}
		
		
		function validaFrequencia(){
			var notat = document.getElementById('notat');
			var notap = document.getElementById('notap');
			var faltas = document.getElementById('faltas');
			var erro = '';
			
			if(notat.value == ''){
				erro += "A nota do trabalho deve ser informada! \r\n";
				notat.style.border = '1px solid #FF0000';
			}else{
				if(notat.value > 3){
					erro += "A nota do trabalho deve ser no máximo até 3.0! \r\n";
					notat.style.border = '1px solid #FF0000';
				}else{
					notat.style.border = '1px solid #009933';
				}
			}
			
			if(notap.value == ''){
				erro += "A nota da prova deve ser informada! \r\n";
				notap.style.border = '1px solid #FF0000';
			}else{
				if(notap.value > 7){
					erro += "A nota da prova deve ser no máximo até 7.0! \r\n";
					notap.style.border = '1px solid #FF0000';
				}else{
					notap.style.border = '1px solid #009933';
				}
			}
			
			if(faltas.value == ''){
				erro += "O número de faltas deve ser informado! \r\n";
				faltas.style.border = '1px solid #FF0000';
			}else{
				faltas.style.border = '1px solid #009933';
			}
			
			if(erro == ''){
				return true;
			}else{
				alert(erro);
				return false;
			}
			
			
		}
		
		
	function selectAll(){
			
			var father = document.getElementById('formlist');
			var soons = father.getElementsByTagName('input');
			for(i=0;i<soons.length;i++){
				if(soons[i].type=='checkbox' && soons[i].className=='check'){
					if(soons[i].checked==true){
						soons[i].checked=false;
					}else{
						soons[i].checked=true;
					}
				}
			}
		}