// SCRIPTS PARA CONTROLE DOS MENUS EM DHTML

var menuAberto = null;

function abrirMenu(aID){
	fecharMenus(menuAberto);
	var obj = document.getElementById(aID);
	if(aID!=menuAberto){
		obj.className="abreTopicos";
		menuAberto = aID;
	} else {
		menuAberto=null;	
	}
}

function fecharMenus(){
	if(menuAberto!=null){
		document.getElementById(menuAberto).className="topicos";
	}
}

function verElementos(){
	var objMenu = document.getElementById("menus");
	alert(objMenu.childNodes.length);
}

//--> SCRIPTS PARA CONTROLE DOS MENUS EM DHTML


<!-- ABRIR POP-UP
function AbrePop(theURL,winName,features) {
	window.open(theURL,winName,features);
}
//-->

<!-- IMAGEM DE ACORDO COM RESOLUÇÃO
function resolucao(image) {
	if (screen.width >= "1024") {
		image = image + "2";
	}
	document.write("<img src='images/" + image + ".gif' width='100%' alt='' />");
}
//-->

<!-- MÁSCARAS DE TELEFONE, CPF, CEP, DATA
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

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
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function cep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function cnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}

function romanos(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
    //Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
        v=v.replace(/.$/,"")
    return v
}

function site(v){
    //Esse sem comentarios para que você entenda sozinho ;-)
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}

//-->

<!-- CAMPO NUMÉRICO
function SoNumero(e) {
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else {
			if (tecla != 8) // backspace
				event.keyCode = 0;
				//return false;
			else
				return true;
		}
}
//-->

<!--
function validaCPF(recebeCPF){

var Numero = new Array(11);
var soma = 0;
var resultado1 = 0;
var resultado2 = 0; 

//Retirar todos os caracteres que nao sejam 0-9
var s = "";
var ch = "";
if (recebeCPF.length > 0)
{
	for (x=1; x <= recebeCPF.length;x+=1)
	{
	    ch = recebeCPF.substr(x-1, 1);
	    if ((ch.charCodeAt(0) >= 48) && (ch.charCodeAt(0) <= 57))
	       { s = s + ch;}
	}    
	
	recebeCPF = s;
	
	if (recebeCPF.length != 11)
	{
	     alert("CPF inválido. Por favor, corrija o valor.");
		 document.form.txtCPF.focus();
		 return false;
	}
	else if (recebeCPF == "00000000000")
	{
		 alert("CPF inválido. Por favor, corrija o valor.");
		 document.form.txtCPF.focus();
		 return false;
	} 
	else
	{
		Numero[0] = parseInt(recebeCPF.substr(0, 1));
	    Numero[1] = parseInt(recebeCPF.substr(1, 1));
	    Numero[2] = parseInt(recebeCPF.substr(2, 1));
	    Numero[3] = parseInt(recebeCPF.substr(3, 1));
	    Numero[4] = parseInt(recebeCPF.substr(4, 1));
	    Numero[5] = parseInt(recebeCPF.substr(5, 1));
	    Numero[6] = parseInt(recebeCPF.substr(6, 1));
	    Numero[7] = parseInt(recebeCPF.substr(7, 1));
	    Numero[8] = parseInt(recebeCPF.substr(8, 1));
	    Numero[9] = parseInt(recebeCPF.substr(9, 1));
	    Numero[10] = parseInt(recebeCPF.substr(10, 1));
	}
	    soma = 10 * Numero[0] + 9 * Numero[1] + 8 * Numero[2] + 7 * Numero[3] + 6 * Numero[4] + 5 * Numero[5] + 4 * Numero[6] + 3 * Numero[7] + 2 * Numero[8];
	    soma = soma - (11 * parseInt(soma / 11));
	    
	    
		if ((soma == 0) || (soma == 1))
	        {
				resultado1 = 0;
	        }
	    else
	        {
				resultado1 = 11 - soma;
	        }
		    
	    if (resultado1 == Numero[9])
	        {
			soma = Numero[0] * 11 + Numero[1] * 10 + Numero[2] * 9 + Numero[3] * 8 + Numero[4] * 7 + Numero[5] * 6 + Numero[6] * 5 + Numero[7] * 4 + Numero[8] * 3 + Numero[9] * 2
	        
			soma = soma - (11 * parseInt(soma / 11));
	        if ((soma == 0) || (soma == 1))
	        {
				resultado2 = 0;
	        }
			else
			{
			    resultado2 = 11 - soma;
			}
	        
	        
	        if (resultado2 == Numero[10])
	        {
			    //calculaCPF = recebeCPF;
	            return true;
			}
			else
	        {
				//calculaCPF = "N";
				alert("CPF inválido. Por favor, corrija o valor.");
				document.form.txtCPF.focus();
				return false;
			}	
	    }
		else
	    {
		    //calculaCPF = "N";
			alert("CPF inválido. Por favor, corrija o valor.");
			document.form.txtCPF.focus();
			return false;
	    }
}
else
{
	return true;
}			
}


	function trim(Var)
	{
		var contador = 0;
		while (contador < Var.length)
		{
			if (Var.charCodeAt(0) == 32) Var = Var.substring(1,Var.length);
			else break;
			contador++;
		}
		contador = Var.length;
		while (contador > 0)
		{
			if (Var.charCodeAt(Var.length - 1) == 32) Var = Var.substring(0,Var.length - 1);
			else break;
			contador--;
		}
		return Var;
	}

	//VERIFICA SE HA ALGUM CAMPO NULO
	function mensagem(output)
	{
			if(falta == 1) {msg = msg+", "}
			if(msg.length+output.length-4 > cont + 60)
			{
				msg = msg+"\n";
				cont = cont + 60;
			}
			falta = 1;
			msg = msg+output;
	}

	var falta = 0;
	var msg = '';
	var cont = 0;

	function verifica()
	{
		var msg1 = 'Os seguintes campos não foram corretamente preenchidos:';
		var teve_falta = 0;
	
		if(trim(document.form.NOME.value) == '') mensagem('Nome');
		if(trim(document.form.NUMERO.value) == '') mensagem('Número de Identidade');
		if(trim(document.form.ORGAOEXPEDIDOR.value) == '') mensagem('Orgão Expedidor');
		if(trim(document.form.ESTADOID.value) == '') mensagem('Estado da Identidade');
		if((trim(document.form.SEXO[0].checked) == false) && (trim(document.form.SEXO[1].checked) == false)) mensagem('Sexo');
		if(trim(document.form.DATA_NASCIMENTO.value) == '') mensagem('Data de Nascimento');
		if(trim(document.form.RUA.value) == '') mensagem('Endereço');
		if(trim(document.form.BAIRRO.value) == '') mensagem('Bairro');
		if(trim(document.form.CIDADE.value) == '') mensagem('Cidade');
		if(trim(document.form.CEP.value) == '') mensagem('Cep');
		if(trim(document.form.ESTADO.value) == '') mensagem('Estado');
		if((trim(document.form.SITUACAOACADEMICA[0].checked) == false) && (trim(document.form.SITUACAOACADEMICA[1].checked) == false) && (trim(document.form.SITUACAOACADEMICA[2].checked) == false) && (trim(document.form.SITUACAOACADEMICA[3].checked) == false) && (trim(document.form.SITUACAOACADEMICA[4].checked) == false)) mensagem('Situação Acadêmica');
		if(trim(document.form.SA.value) == '') mensagem('Seu estabelecimento (colégio/universidade)');
		if((trim(document.form.UNIVERSIDADES[0].checked) == false) && (trim(document.form.UNIVERSIDADES[1].checked) == false)) mensagem('Universidade de sua Escolha');
		if(trim(document.form.VERSAO.value) == '') mensagem('Curso');
		if(trim(document.form.OP1.value) == '') mensagem('Preferência de Entrada');
		if((trim(document.form.LINGUAESTRANGEIRA[0].checked) == false) && (trim(document.form.LINGUAESTRANGEIRA[1].checked) == false) && (trim(document.form.LINGUAESTRANGEIRA[2].checked) == false)) mensagem('Língua Estrangeira');

		if(falta == 1)
		{
			msg = msg+'.';
			msg1 = msg1+'\n'+msg
			teve_falta = 1;
		}
		
		if (teve_falta == 1)
		{
			alert(msg1);
			falta = 0;
			msg = '';
			cont = 0;
			return;
		}
		
		document.form.submit();
	
	}

	// FUNÇÃO DE CHECAGEM DE DATA
	function checardata()
	{
		if (isDate('txtNasc') == false )
		{
		 alert('Data inválida. Digite-a novamente.');
		 document.form.txtNasc.focus();
		}
	}

	function formatadata(tammax,pos,teclapres, nomecampo)
	{
		var tecla = teclapres.keyCode;
		vr = eval('document.form.' + nomecampo);
	
		dvr = vr.value;
		tam = dvr.length ;
	
		if (tecla != 8 && tam < 10)
		{
			if(tam == 2 || tam == 5 ) vr.value = vr.value + '/';
		}
	}

	function formatadata2(tammax,pos,teclapres, nomecampo)
	{
		var tecla = teclapres.keyCode;
		vr = eval('document.form.' + nomecampo);
	
		dvr = vr.value;
		tam = dvr.length ;
	
		if (tecla != 8 && tam < 10)
		{
			if(tam == 2 || tam == 5 ) vr.value = vr.value + '/';
		}
		
		// habilita o campo de filhos
		if (tam == 10) {
			document.form.lbFilhos.disabled = false;
		}
	}
	

	function formatacep(tammax,pos,teclapres, nomecampo)
	{
		var tecla = teclapres.keyCode;
		vr = eval('document.form.' + nomecampo);
	
		dvr = vr.value;
		tam = dvr.length ;
	
		if (tecla != 8 && tam < 10)
		{
			if(tam == 5 ) vr.value = vr.value + '-';
		}
	}

	function checkMonthLength(mm,dd)
	{
		var months = new Array("","Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
		if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30)
		{
			//alert(months[mm] + " tem apenas 30 dias.");
			return false;
		}
		else if (dd > 31)
		{
			//alert(months[mm] + " tem apenas 31 dias.");
			return false;
		}
		return true;
	}
	
	function checkLeapMonth(mm,dd,yyyy)
	{
		if (yyyy % 4 > 0 && dd > 28)
		{
			//alert("Fevereiro de " + yyyy + " tem apenas 28 dias.");
			return false;
		}
		else if (dd > 29)
		{
			//alert("Fevereiro de " + yyyy + " tem apenas 29 dias.");
			return false;
		}
		return true;
	}

	function isDate(campo)
	{
		var gField = eval('document.form.'+ campo);
		var inputStr = gField.value;

		// convert hyphen delimiters to slashes
		while (inputStr.indexOf("-") != -1) inputStr = replaceString(inputStr,"-","/");
		var delim1 = inputStr.indexOf("/");
		var delim2 = inputStr.lastIndexOf("/");
		if (delim1 != -1 && delim1 == delim2) return false;
		if (delim1 != -1)
		{
			// there are delimiters; extract component values
			var dd = parseInt(inputStr.substring(0,delim1),10);
			var mm = parseInt(inputStr.substring(delim1 + 1,delim2),10);
			var yyyy = parseInt(inputStr.substring(delim2 + 1, inputStr.length),10);
		}
		else
		{
			// there are no delimiters; extract component values
			var dd = parseInt(inputStr.substring(0,2),10);
			var mm = parseInt(inputStr.substring(2,4),10);
			var yyyy = parseInt(inputStr.substring(4,inputStr.length),10);
		}

		if (isNaN(mm) || isNaN(dd) || isNaN(yyyy))
		{
			// there is a non-numeric character in one of the component values
			return false;
		}
		if (mm < 1 || mm > 12)
		{
			// month value is not 1 thru 12
			return false;
		}
		if (dd < 1 || dd > 31)
		{
			// date value is not 1 thru 31
			return false;
		}
	
		if (yyyy < 10)
		{
			return false
		}
		if (!checkMonthLength(mm,dd)) return false;
		if (mm == 2)
		{
			if (!checkLeapMonth(mm,dd,yyyy)) return false;
		}
		return true;
	}
	//FIM DA FUNCAO CHECAGEM DE DATA

	// INICIO DE VALIDACAO DE CAMPOS CHAR e NUMERO
	function valida (teclapres, nomecampo,proxcampo)
	{
		var tecla = teclapres.keyCode;
	
		if ( (tecla == 13) && (eval('document.form.' + nomecampo + '.value') != '' ) && (eval('document.form.' + proxcampo + '.disabled == false')) )
		{
		  eval('document.form.' + proxcampo + '.focus();');
		}
		else if ( (tecla == 13) && ( (nomecampo == 'txtmail') || (nomecampo =='txtApto') || (nomecampo == 'txtNum') || (nomecampo == 'txtComp') || (nomecampo == 'txtPai') || (nomecampo == 'txtMae') || (nomecampo == 'txtTel1') || (nomecampo == 'txtTel2') || (nomecampo == 'txtTel3') ) && (eval('document.form.' + proxcampo + '.disabled == false')) )
		{
		  eval('document.form.' + proxcampo + '.focus();');
		}
		else if ( (tecla == 13) && (nomecampo != 'txtNasc') )
		{
		 alert('Por favor, preencha o CAMPO ATUAL antes de ir para o próximo campo.');
		}
	    return true;
	}			 

	function validacodigo(teclapres, nomecampo,proxcampo)
	{
		var tecla = teclapres.keyCode;
	
		if (tecla > 31 && (tecla < 48 || tecla > 57))
		{  
			self.alert('Favor digitar somente caracteres numéricos.'); 
		   	return false;
		}
		else if ( (tecla == 13) && (eval('document.form.' + proxcampo + '.disabled == false')) && (eval('document.form.' + nomecampo + '.value') != '' ) )
		{
		  eval('document.form.' + proxcampo + '.focus();');
		}
		else if ( (tecla == 13) && ( (nomecampo == 'txtDDD') || (nomecampo == 'txtFone'))) 
			{
		  eval('document.form.' + proxcampo + '.focus();');
		}
		else if ( (tecla == 13) && ( (nomecampo != 'txtDDD') || (nomecampo != 'txtFone'))) 
		{
		 alert('Por favor, preencha o CAMPO ATUAL antes de ir para o próximo campo.');
		}

	    return true;
	}			 

	function validacodigochar(teclapres, nomecampo,proxcampo)
	{
		var tecla = teclapres.keyCode;
	
		if ( (tecla > 32 && (tecla < 65 || tecla > 90) && (tecla < 97 || tecla > 122) ) && (tecla != 46))
		{  self.alert('Favor digitar somente caracteres.'); 
		   return false;
		}
		else if ( (tecla == 13) && (eval('document.form.' + proxcampo + '.disabled == false')) && (eval('document.form.' + nomecampo + '.value') != '' ) )
		{
		  eval('document.form.' + proxcampo + '.focus();');
		}
		else if(tecla == 13)
		{
		 alert('Por favor, preencha o CAMPO ATUAL antes de ir para o próximo campo.');
		}

		   return true;
	}			 
	// FIM DE VALIDACAO DE CAMPOS CHAR e NUMERO


	// INICIO DE HABILITAÇÃO DO CAMPO SEGUINTE
	// checa se o campo esta preenchido e habilita o prox.

	function habilita_campo(nomecampo,proxcampo)
	{
		if (trim(eval('document.form.' + nomecampo + '.value')).length == 0)
		{
		  eval('document.form.' + nomecampo + '.focus();');
		}	
		else
		{
		  if ( (proxcampo == 'btnCadastra') && (document.form.cargos.value.length == 0) )
			{
			  eval('document.form.' + proxcampo + '.disabled = true');
			}
		  else
		    {
		     eval('document.form.' + proxcampo + '.disabled = false');
			}
		}

	}

	// caso ele depois de ter preenchido o campo, volte e tente deixar em branco
	function habilita_campo_volta(nomecampo)
	{

		if ( trim(eval('document.form.' + nomecampo + '.value') == '' ) && (nomecampo != 'txtNasc'))
		 {
	  	    alert('Por favor, primeiro preencha o campo anterior.');
			eval('document.form.' + nomecampo + '.focus();')			
		 }
	}

	// FIM DE HABILITAÇÃO DO CAMPO SEGUINTE
	
	// INÍCIO DA VALIDAÇÃO DOS RADIOBUTTONS
	function ValidarRadios(form) {
	var el = document.forms[0].elements; //TAVA ERRADO AQUI! DESSA FORMA AQUI ELE PEGA O PRIMEIRO FORM DA PÁGINA! OU BOTE O NOME OU forms[1], etc...
	for(var i = 0; i < el.length; ++i) {
	if(el[i].type == "radio") {
	var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
	var itemchecked = false;
	for(var j = 0; j < radiogroup.length; ++j) {
	if(radiogroup[j].checked) {
	itemchecked = true;
	break;
	}
	}
	if(!itemchecked) {
	alert("Você deixou de marcar alguma opção. \n Reveja os campos e tente novamente.");
	if(el[i].focus)
	el[i].focus();
	return false;
	}
	}
	}
	return true;
	}
	// FIM DA VALIDAÇÃO DOS RADIOBUTTONS
	
//-->