//INICIO FUNCAO PARA CONTROLE DE ESTADO E CIDADES ENVIO TRABALHOS
   function Dados(valor) {
      //VERIFICA SE O BROWSER TEM SUPORTE A AJAX
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
	  //SE TIVER SUPORTE AJAX
	  if(ajax) {
	     //DEIXA APENAS O ELEMENTO 1 NO OPTION, OS OUTROS SÃO EXCLUIDOS
		 document.trabalhos.CodCidade.options.length = 1;

		 idOpcao  = document.getElementById("opcoes");

	     ajax.open("POST", "cidades_lista.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		 ajax.onreadystatechange = function() {
            //enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
			   idOpcao.innerHTML = "Carregando...";
	        }
			//após ser processado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML);
			   }
			   else {
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   idOpcao.innerHTML = "--Primeiro selecione o estado--";
			   }
            }
         }
		 //passa o código do estado escolhido
	     var params = "estado="+valor;
         ajax.send(params);
      }
   }

   function processXML(obj){
      //pega a tag cidade
      var dataArray   = obj.getElementsByTagName("cidade");

	  //total de elementos contidos na tag cidade
	  if(dataArray.length > 0) {
	     //percorre o arquivo XML paara extrair os dados
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//contéudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
			var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;

	        idOpcao.innerHTML = "--Selecione uma das opções abaixo--";

			//cria um novo option dinamicamente
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoes");
				//atribui um valor
			    novo.value = codigo;
				//atribui um texto
			    novo.text  = descricao;
				//finalmente adiciona o novo elemento
				document.trabalhos.CodCidade.options.add(novo);
		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "--Primeiro selecione o estado--";
	  }
   }
//FIM FUNCAO PARA CONTROLE DE ESTADO E CIDADES ENVIO TRABALHOS

//INICIO FUNÇÃO SELECIONAR
	function selecionar(formObj, isInverse)
	{
		for (var i=0;i < formObj.length;i++) {
		fldObj = formObj.elements[i];
		if (fldObj.type == 'checkbox') {
		if(isInverse)
		fldObj.checked = (fldObj.checked) ? false : true;
		else fldObj.checked = true;
		}
		}
	}
//FIM FUNÇÃO SELECIONAR

//INICIO PULA PARA A CAIXA DE TEXTO DEFINIDA AO ALCANCAR O TAMANHO MAXIMO DE CARACTERES
function pula(maxlength, idObj, idNext){
  var next = document.getElementById(idNext);
  var obj = document.getElementById(idObj);
  if (next.type.toLowerCase() == "text" || next.type.toLowerCase() == "password"){
     if(obj.value.length >= maxlength){
        next.select();
     }
  }else if (next.type.toLowerCase() == "select-one"){
      if(obj.value.length >= maxlength){
           next.focus();
         next.selectedIndex=0;
      }
  }else if (next.type.toLowerCase() == "submit"){
     if(obj.value.length >= maxlength){
         if (navigator.appName == "Microsoft Internet Explorer"){
             next.select();
         }else{
             next.focus();
         }
     }
  }
}
//FIM PULA PARA A CAIXA DE TEXTO DEFINIDA AO ALCANCAR O TAMANHO MAXIMO DE CARACTERES

//INICIO FUNÇÃO PERMITE DIGITAR SOMENTE NÚMERO EM DETERMINADOS CAMPOS
function isNum(caractere){
	var strValidos = "0123456789"
	if ( strValidos.indexOf( caractere ) == -1 )
	return false;
	return true;
}
function validaTecla(campo, event){
	var BACKSPACE= 8;
	var key;
	var tecla;
	CheckTAB=true;

	if(navigator.appName.indexOf("Netscape")!= -1) 
		tecla= event.which;
 	else
		tecla= event.keyCode;
		key = String.fromCharCode( tecla); 
		//alert( 'key: ' + tecla + ' -> campo: ' + campo.value);
	if (tecla == 13)
 		return false;
	if (tecla == BACKSPACE)
 		return true;
 		return (isNum(key));
 	}
//FIM FUNÇÃO PERMITE DIGITAR SOMENTE NÚMERO EM DETERMINADOS CAMPOS

//INICIO FUNCAO PARA CONTROLE DE ESTADO E CIDADES ENVIO INSCRICAO
   function DadosEnvioInscricao(valor) {
      //VERIFICA SE O BROWSER TEM SUPORTE A AJAX
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
	  //SE TIVER SUPORTE AJAX
	  if(ajax) {
	     //DEIXA APENAS O ELEMENTO 1 NO OPTION, OS OUTROS SÃO EXCLUIDOS
		 document.EnvioInscricao.CodCidade.options.length = 1;

		 idOpcao  = document.getElementById("opcoes");

	     ajax.open("POST", "cidades_lista.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		 ajax.onreadystatechange = function() {
            //enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
			   idOpcao.innerHTML = "Carregando...";
	        }
			//após ser processado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXMLEnvioInscricao(ajax.responseXML);
			   }
			   else {
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   idOpcao.innerHTML = "--Primeiro selecione o estado--";
			   }
            }
         }
		 //passa o código do estado escolhido
	     var params = "estado="+valor;
         ajax.send(params);
      }
   }

   function processXMLEnvioInscricao(obj){
      //pega a tag cidade
      var dataArray   = obj.getElementsByTagName("cidade");

	  //total de elementos contidos na tag cidade
	  if(dataArray.length > 0) {
	     //percorre o arquivo XML paara extrair os dados
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//contéudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
			var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;

	        idOpcao.innerHTML = "--Selecione uma das opções abaixo--";

			//cria um novo option dinamicamente
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoes");
				//atribui um valor
			    novo.value = codigo;
				//atribui um texto
			    novo.text  = descricao;
				//finalmente adiciona o novo elemento
				document.EnvioInscricao.CodCidade.options.add(novo);
		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "--Primeiro selecione o estado--";
	  }
   }
//FIM FUNCAO PARA CONTROLE DE ESTADO E CIDADES ENVIO INSCRICAO

//INICIO FUNÇÃO FORMATA VALOR ENVIO INSCRICAO
function FormataValor(campo,tammax,teclapres) {
    var tecla = teclapres.keyCode;
    vr = document.EnvioInscricao[campo].value;
    vr = vr.replace( "/", "" );
    vr = vr.replace( "/", "" );
    vr = vr.replace( ",", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    tam = vr.length;

    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 <= 2 ){
             document.EnvioInscricao[campo].value = vr; }
         if ( (tam > 2) && (tam <= 5) ){
             document.EnvioInscricao[campo].value = vr.substr( 0, tam - 2 ) + '.' + vr.substr( tam - 2, tam ); }
         if ( (tam >= 6) && (tam <= 8) ){
             document.EnvioInscricao[campo].value = vr.substr( 0, tam - 5 ) + ',' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ); }
         if ( (tam >= 9) && (tam <= 11) ){
             document.EnvioInscricao[campo].value = vr.substr( 0, tam - 8 ) + ',' + vr.substr( tam - 8, 3 ) + ',' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ); }
         if ( (tam >= 12) && (tam <= 14) ){
             document.EnvioInscricao[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 - 2, tam ); }
         if ( (tam >= 15) && (tam <= 17) ){
             document.EnvioInscricao[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 );}
    }
}
//FIM FUNÇÃO FORMATA VALOR ENVIO INSCRICAO