function FormataDado(campo,tammax,pos,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	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 == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		document.form[campo].value = vr ;}
		if ( tam > pos && tam <= tammax ){
			document.form[campo].value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );}
	}
}

function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form[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.form[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form[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.form[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.form[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 ) ;}
	}		
	
}

function SaltaCampo (campo,prox,tammax,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		document.form[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	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 (tecla != 0 && tecla != 9 && tecla != 16 ){
			if ( tam == tammax ){
				if ( document.form[prox] )
					document.form[prox].focus();
			}
		}
	}
}

function FormataData(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.form[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}

function FormataDataThis(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = Campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			Campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			Campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}

function IsNumber() {
	if ((event.keyCode >= 48) && (event.keyCode <= 57))
		return true;
	else
		return false;
}

function FormataHora(Campo,teclapres) {
	var tecla = teclapres.keyCode
	vr = document.form[Campo].value
	vr = vr.replace( ":", "" )
	vr = vr.replace( ".", "" )
	vr = vr.replace( "/", "" )
	vr = vr.replace( "/", "" )
	tam = vr.length + 1

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form[Campo].value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam )
	}
}
function FormataCpf(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	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.form[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form[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.form[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.form[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 ) ;}
	}		
}

function IsNumeric(pNum){

	if (pNum==''){
		return false;
	}
	for (var i = 0; i < pNum.length; i++){
		var ch = pNum.substring(i, i + 1);
		if (ch < '0' || '9' < ch){
			return false;
		}
	}
	return true;
}
function IsDecimal(pNum){

	if (pNum==''){
		return false;
	}
	
	for (var i = 0; i < pNum.length; i++){
		var ch = pNum.substring(i, i + 1);
		if ((ch < '0' || '9' < ch) && (ch != ',') && (ch != '.') && (ch != '-')){
			return false;
		}
	}
	return true;
}
function IsDate(pData){

	if(pData.length<10 || pData.length>10){

		return false;
	}

	var ano = '' + pData.substring(6,10);
	var mes = '' + pData.substring(3,5);
	var dia = '' + pData.substring(0,2);
				
	if(dia>'31'){
		return false;
	}
				
	if(mes>'12'){
		return false;
	}

	if(ano<='1900'){
		return false;
	}

	if(mes=='02'){
		if(ano%4!=0 && dia>'28'){
			return false;
		}
		else{
			if(dia>'29'){
				return false;
			}
		}
	}
	
	if(mes<='07'){
		if(mes%2==0 && dia>'30'){
			return false;
		}
	}
	else{
		if(mes>'09'){
			if(mes%2!=0 && dia>'30'){
				return false;
			}
		}
	}
					
	return true
}

function IsEmail(email){

	if ((email.search(/;/i) == -1) &&
	    (email.search(/,/i) == -1) &&
	    (email.indexOf("..") == -1) &&
	    (email.indexOf(".@") == -1) &&
	    (email.indexOf("@.") == -1) &&
	    (email.search(/ /i) == -1) &&
	    (email.search(/"/i) == -1) &&
	    (email.search(/'/i) == -1) &&
	    (email.indexOf("^") == -1) &&
	    (email.search(/`/i) == -1) &&
	    (email.search(/´/i) == -1) &&
	    (email.search(/~/i) == -1) &&
	    (email.search(/ç/i) == -1) &&
	    (email.length != 0) &&
	    (email.search(/@/i) >= 2) &&
	    (email.substr(0,1) != ".") &&               //Não pode começar com ponto
	    (email.substr(email.length-1) != ".") &&    //Não pode terminar com ponto
	    (email.indexOf("hotmail.com.br") == -1) &&
	    (email.indexOf("aol.com.br") == -1) &&
	    (email.indexOf("gmail.com.br") == -1) &&
	    (email.indexOf("globo.com.br") == -1) &&
	    (email.indexOf(" ") == -1))
		return true;
	else
		return false; 
}


function Mid(campo,x,y){

	var res;
	if(x>0)
		x = x-1;
	if(x+y > campo.length)
		y = campo.length
	else
		y = x + y;
	res = campo.substring(x,y);
	return res;
}

	
function Left(campo,x){

	var res;
	if(x > campo.length)
		x = campo.length;
	res = campo.substring(0,x);
	return res;
}

	
function Right(campo,x){

	var res;
	if(x > campo.length){
		res = campo;
		return res;
	}
	res = campo.substring(campo.length-x,campo.length);
	return res;
}

	
function UCase(campo){

	return campo.toUpperCase()
}

	
function LCase(campo){

	return campo.toLowerCase()
}

	
function RTrim(campo){

	y=true;
	while(y==true){
		x = campo.length;
		if(Right(campo,1)==' '){
			campo = Left(campo,x-1);
			y=true;
		}
		else{
			y=false
		}
	}
	return campo;
}

	
function LTrim(campo){

	y=true;
	while(y==true){
		x = campo.length-1;
		if(Left(campo,1)==' '){
			campo = Right(campo,x);
			y=true;
		}
		else{
			y=false;
		}
	}
	return campo;
}

	
function Trim(campo){

	return RTrim(LTrim(campo));
}

// Função utilizada para validação de CPF e CNPJ
function modulo(str) {

   	soma=0;
   	ind=2;
   	for(pos=str.length-1;pos>-1;pos=pos-1) {
   		soma = soma + (parseInt(str.charAt(pos)) * ind);
   		ind++;
   		if(str.length>11) {
   			if(ind>9) ind=2;
   		}
	}
   	resto = soma - (Math.floor(soma / 11) * 11);
   	if(resto < 2) {
    	return 0
   	}
   	else {
   		return 11 - resto
   	}
}

// Função para validação do CPF
function VerificaCPF(valor) {

	primeiro=valor.substr(1,1);
	falso=true;
	size=valor.length;
	if (size!=11){
		return false;
	}
	size--;
	for (i=2; i<size-1; ++i){
		proximo=(valor.substr(i,1));
		if (primeiro!=proximo) {
			falso=false
		}
	}
	if (falso){
		return false;
	}
   	if(modulo(valor.substring(0,valor.length - 2)) + "" + modulo(valor.substring(0,valor.length - 1)) != valor.substring(valor.length - 2,valor.length)) {
   		return false;
   	}
   	return true
}


// Função para validação do cnpj
function VerificaCNPJ(valor) {

	primeiro=valor.substr(1,1);
	falso=true;
	size=valor.length;
	if (size!=14){
		//return false;
	}
	size--;
	for (i=2; i<size-1; ++i){
		proximo=(valor.substr(i,1));
		if (primeiro!=proximo) {
			falso=false
		}
	}
	
	if (falso){
		return;
	}
	
   	if(modulo(valor.substring(0,valor.length - 2)) + "" + modulo(valor.substring(0,valor.length - 1)) !=valor.substring(valor.length - 2,valor.length)) {
   		return false;
   	}
   	return true
}

function formatar(src, mask,event) {
	 var i = src.value.length;
	 var saida = mask.substring(i,i+1);
	 var ascii = event.keyCode;
	 if (saida == "A") {
	  if ((ascii >=97) && (ascii <= 122)) { 
	  	event.keyCode -= 32;
	  }else {
	  	event.keyCode = 0;
	  }
	}else if (saida == "0") {
  if ((ascii >= 48) && (ascii <= 57)) { return }
  else { event.keyCode = 0 }
 } else if (saida == "#") {
  return;
 } else {
  src.value += saida;
  i += 1
  saida = mask.substring(i,i+1);
  if (saida == "A") {
   if ((ascii >=97) && (ascii <= 122)) { event.keyCode -= 32; }
   else { event.keyCode = 0; }
  } else if (saida == "0") {
   if ((ascii >= 48) && (ascii <= 57)) { return }
   else { event.keyCode = 0 }
  } else { return; }
 }
}
//alternar de campo
function autotab(original,destination){
	if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
	destination.focus()
}
function validarCpf(){
	form = document.forms[0];
	var cpf = form.cpf.value;
	if (form.cpf.value.length > 0){
		if (!VerificaCPF(form.cpf.value)){
			alert('Cpf inválido!');
			//form.cpf.value = '';
			form.cpf.focus();
			return false;
		}
		url = "consultarCpf.php?cpf="+cpf + "&destino=" + document.forms[0].name;
		oDiv = document.getElementById('carregando');
		oDiv.innerHTML = '<h1><div id="carregador_pai"> <div id="carregador"> <div align="center">Aguarde processando ...</div> <div id="carregador_fundo"><div id="barra_progresso"> </div></div> </div></h1>';
		document.getElementById("carregadorDados").src = url;
	}else{
		form.cpf.focus();
	}		
}
function clickEnter(){
	acao('salvarPessoa');
}
function informeCategoria(){
	form = document.forms[0];
	if (form.categoria.value =="Estudante"){
		alert("Digitar o nº da matrícula  na ficha de inscrição, \n que será comprovado junto a Instituição de Ensino,  \n pela Comissão Organizadora do CONAD.  \n A inscrição de estudande é válida para os cursos de graduação, \n de qualquer área universitária, mediante documento comprobatório.");
	}
	if (form.categoria.value =="Administrador"){	
		alert("Informar o nº de Registro do Administrador, junto ao cadastro do  CRA-GO. \n Para outro Estado: Enviar a Carteira Profissional, \n por fax ou e-mail,  no dia da efetivação do pagamento bancário.");
	}
}

function validarNumRegistro(){
	form = document.forms[0];
	var numRegistro = form.numRegistro.value;
	if (form.numRegistro.value.length > 0){
		url = "consultarNumRegistro.php?numRegistro="+numRegistro + "&destino=" + document.forms[0].name;
		oDiv = document.getElementById('carregando');
		//oDiv.innerHTML = '<h1><div id="carregador_pai"> <div id="carregador"> <div align="center">Aguarde processando ...</div> <div id="carregador_fundo"><div id="barra_progresso"> </div></div> </div></h1>';
		document.getElementById("carregadorDados").src = url;
	}	
}

