

/* 
evita q o formulário seja postado com um enter
chamar esta funcao com "return fj_enter_no(event, this.form)" 
*/
function fj_enter_no(e, form) 
{
 
 
 if(fj_keycode(e) == 13)
 {
	return false;	 
 }
 else
 {
	return true;	 
 }
 
 /*
  if (window.event && window.event.keyCode == 13)
  {
  		if(window.event.keyCode == 13)
		{
			return false;
		}
		else
		{
			 return true;
		}
  }
  else
  {

	  	if(e.which  == 13)
		{
			return false;
		}
		else
		{
			 return true;
		}
  }
*/
}


function fj_keycode(e)
{
  if (window.event && window.event.keyCode )
  {
  		return window.event.keyCode;
  }
  else
  {
		return e.which;
  }
}

function fj_frm_checa_suggestions(url)
{
	if(fj_trim(document.frm_suggestions.txt_suggestion.value) == '')
	{
		alert('Is necessary type your suggestion!');
		document.frm_suggestions.txt_suggestion.focus();
	}
	else
	{
		fj_ajax_post(url, 'apdiv_popup_aj', document.frm_suggestions);	
		
	}
}


function fj_frm_tell_friends(url)
{
	if(fj_trim(document.frm_suggestions.txt_f_mail.value) == '')
	{
		alert("Is necessary type your friend's mail!");
		document.frm_suggestions.txt_f_mail.focus();
	}
	else if(fj_trim(document.frm_suggestions.txt_suggestion.value) == '')
	{
		alert('Is necessary type your suggestion!');
		document.frm_suggestions.txt_suggestion.focus();
	}
	else
	{
		fj_ajax_post(url, 'apdiv_popup_aj', document.frm_suggestions);	
		
	}
}

function fj_frm_checa_something_wrong(url)
{
	if(document.frm_denuncia_aj.cmb_kind.value == 0)
	{
		alert('Is necessary select the kind of problem!');
		document.frm_denuncia_aj.cmb_kind.focus();
	}
	else if(fj_trim(document.frm_denuncia_aj.txt_coment.value) == '')
	{
		alert('Please, type your comments!');
		document.frm_denuncia_aj.txt_coment.focus();
		
	}
	else
	{
		fj_ajax_post(url, 'apdiv_popup_aj', document.frm_denuncia_aj);	
		
	}
}

///////////////////////////////////////////////////////////////////////////////////////////
// setar texto de um layer
///////////////////////////////////////////////////////////////////////////////////////////
function fj_findObj(n, d) 
{ //v4.01
	var p,i,x; 
	if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
    	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	
	if(!(x=d[n])&&d.all) 
	{ 
		x=d.all[n]; 
	} 
	
	for (i=0;!x&&i<d.forms.length;i++) 
	{
		x=d.forms[i][n];
	}
	
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
	{
		x=fj_findObj(n,d.layers[i].document);
	}	
	if(!x && d.getElementById) 
	{ 
	x=d.getElementById(n); 
	}
	
	return x;
}

function fj_setTextOfLayer(objName,x,newText) 
{ //v4.01
	if ((obj=fj_findObj(objName))!=null) with (obj)
	{
		if (document.layers) 
		{
			document.write(unescape(newText)); 
			document.close();
		}
		else
		{
			innerHTML = unescape(newText);
		}
 	}
}
///////////////////////////////////////////////////////////////////////////////////////////




// JavaScript Document
// alert('incklude ok');
/*
arredonda casas decimais
autor : desconhecido
origem: internet
data de inclusão: 20/01/2005
*/
function fj_arredonda_decimais( valor , casas )
{
	var novo = Math.round( valor * Math.pow( 10 , casas ) ) / Math.pow(10 , casas );
	//  document.write( novo );
	  return( novo );
}



/*
AUTOR: CARLOS ALLAN SILVA ANDRADE
DATA: 18/01/2005
DESCRIÇÃO: CONVERTE UM VALOR MOEDA PARA O FORMATO MOEDA DO JAVASCRIPT
*/
function fj_converte_moeda(moeda)
{
			
			var val_moeda = moeda;
			
			while (val_moeda.indexOf(".") > 0)
			{
				var val_moeda = val_moeda.replace(".", "");
			}
			
			val_moeda =  val_moeda.replace(",", ".");
			
			
			val_moeda = new Number( val_moeda );
			return val_moeda;
			
}



/*
função MOD
Internet
19/01/2005
*/
function fj_mod(x, x_div)
{ 
	for (var i=x; i>=x_div; i -= x_div); 
	return i;
}



/*
FUNÇÃO: FORMATA MOEDA
AUTOR: CARLOS ALLAN SILVA ANDRADE
DATA: 19/01/2005
*/
function fj_formata_moeda(moeda, sts_pontuar, n_decimais, sts_simbolo)
{

var resultado = ' ' +  fj_arredonda_decimais(moeda,2) + '' ;

resultado = fj_trim(resultado);

	if (isNaN(moeda))
		{
			return '';
		}

	// se tiver ponto substituir por vírgula
		resultado = resultado.replace('.', ',');

	// checa se tem vírgula
	var pos_virgula = resultado.lastIndexOf(',');
	if (pos_virgula > 0)
		{ //  se tiver vírgual
			var n_inteiros = resultado.lastIndexOf(",");
			var inteiros  = resultado.substr( 0, n_inteiros);
			var decimais = resultado.substr( (n_inteiros + 1 ));
		}//  se tiver vírgual
		else
		{//  se não tiver vírgual
			if (resultado.substr(0, 1) == ',')
			{
				var n_inteiros =  1;
				var inteiros  = 0;
				var decimais = resultado.substr(1);	
			}
			else
			{
				var n_inteiros =  resultado.length;
				var inteiros  = resultado;
				var decimais = '';
			}

		} // fim de se não tiver vírgual



	// se formatar o número de casas decimais
	if (n_decimais >= 0) 
	{
		while (decimais.length < n_decimais)
			{
			decimais =  decimais + '0';
			}
		decimais = decimais.substr(0, n_decimais);
		if (n_decimais > 0)
			{
			decimais = ',' + decimais;
			}
	} // fim do se decimais foram configurados
		
	// verificar se é para pontuar
	if (sts_pontuar != 0)
		{
		resto = inteiros ;
		resultado = '';
		
		if (fj_mod(n_inteiros, 3) != 0)
		{	
			if (n_inteiros > 3)
				{
				resultado = resto.substr( 0, fj_mod(n_inteiros, 3)) + '.';
				}
				else
				{
				resultado = resto.substr( 0, fj_mod(n_inteiros, 3));
				}
			resto = inteiros.substr( fj_mod(n_inteiros, 3) );
		}

		while(resto.length > 3 )
		{
			resultado = resultado + '' + resto.substr( 0, 3) + '.';
			resto = resto.substr(3);
		}
			
			resultado = resultado + '' + resto;
				
			inteiros = resultado;
		
		}// fim de pontuar
		
		resultado = inteiros + decimais;


		if (sts_simbolo != 0)
			{
				resultado = 'R$ ' + resultado;
			}
	return resultado;

}




// ------------------------------------------------------------
// ************************************************************
// SUBSTITUI PARTE DE UMA STRING POR OUTRA STRING.
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_str_replace
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	SUBSTITUI PARTE DE UMA STRING POR OUTRA STRING.
// LIMITAÇÃOES:
// PARÂMETROS:	A STRING QUE TERÁ UMA PARTE ALTERADA, STRING A SER SUBSTITUIDA
//				STRING QUE SUBSTITUIRÁ A ANTIGA PARTE DA STRING			
// PRÉ-REQUISITOS: ???
// EXEMPLO: val_bruto = replaceSubstring(document.frmGravar.txt_val_bruto.value, ',', '.');		
// DESCRIÇÃO DO EXEMPLO: SUBSTITUI A VÍRGULA PELO PONTO E PASSA O VALOR PARA A VARIÁVEL VAL_BRUTO
// ------------------------------------------------------------

function fj_str_replace(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the function
// ************************************************************
// FIM :  SUBSTITUI PARTE DE UMA STRING POR OUTRA STRING.
// ************************************************************



/*
AUTOR: CARLOS ALLAN SILVA ANDRADE
DATA: 05/01/2005
NOME: fj_data_formata_js
MOTIVO: CONVERTER DATA DO FORMATO DD/MM/AAAA PARA O FORMATO MM-DD-AAAA (UTILIZADO PELO JAVASCRIPT)
PARÂMETROS: UMA DATA NO FORMATO DD/MM/AAAA
*/
function fj_data_formata_js(Data)
{
	resultado = (Data.substring(3,5) + '-' +  Data.substring(0,2) +  '-' + Data.substring(6,10));
	return resultado;
}
// FIM DA FUNÇÃO: fj_data_formata_js


/*
AUTOR: CARLOS ALLAN SILVA ANDRADE
DATA: 05/01/2005
NOME: fj_data_maior
MOTIVO: VERIFICA QUAL DAS DUAS DATAS INFORMADA É A MAIOR E RETORNA A POSIÇÃO DA MAIOR:
		-  1 (UM)- CASO A DATA DA PRIMEIRA POSIÇÃO SEJA A MAIOR
		-  2 (DOIS)   - caso as datas sejam iguais
		-  3 (três)  - CASO A DATA DA SEGUNDA POSIÇÃO SEJA A MAIOR
		-  -1 (menos um) - caso apresente algum erro
PARÂMETROS: VALOR DAS DUAS DATAS NO FORMATO DD/MM/AAAA
PRÉ-REQUISITOS: A FUNÇÃO fj_data_formata_js
*/
function fj_data_maior(DataMenor, DataMaior)
{

	var Data1 = new Date(fj_data_formata_js(DataMenor));
	var Data2 = new Date(fj_data_formata_js(DataMaior));

	// alert (Data1);
	if (Data1 == Data2)
	{
		return 2;
	}
	if (Data1 > Data2)
	{
		return 1;
	}
	else if (Data1 < Data2)
	{
		return 3;
	}
	else
	{
		//alert('erro');
		return -1;
	}
} // fim da função fj_data_maior


function fj_txtStrPermitidos(objCampo, evtKeyPress) {
  
  var nTecla, strTexto, nTamanho, nLocal;
  
  
      if(document.all) 
	  	{ // Internet Explorer
        nTecla = evtKeyPress.keyCode; 
		}
      else if(document.layers) 
	  	{ // Nestcape
        nTecla = evtKeyPress.which;
        }
	  
	// alert (nTecla);
	 
	// se for aspas duplas ou aspas simples colocar uma crase
	if (  (nTecla == 34 ) || (nTecla == 39)   )
		{
		nTecla = 96;
		}



	// impede a digitação de duas barras seguidas
	if (nTecla == 47)
		{
		nTamanho  =0;
		nLocal = 0;
		strTexto = objCampo.value;
		nTamanho = strTexto.length;
		nLocal = strTexto.lastIndexOf('/');
		if (((nLocal + 1)  == nTamanho) && nLocal != -1)	
			{
			nTecla = 0;
			}
		}

	// impede a digitação de dois hífens seguintes
	if (nTecla == 45)
		{
		nTamanho  =0;
		nLocal = 0;
		strTexto = objCampo.value;
		nTamanho = strTexto.length;
		nLocal = strTexto.lastIndexOf('-');
		if (((nLocal + 1)  == nTamanho) && nLocal != -1)	
			{
			nTecla = 0;
			}
		}

		
	// se forem letras minúsculas, converter para maiúsculas (sem acento)
	if (
			((nTecla > 96) && (nTecla < 123)) // se forem letras minúsculas, converter para maiúsculas (sem acento)
			|| ((nTecla > 223) && (nTecla < 254)) // se forem "A" minúsculo com acento, converter para maiúsculos
		)
	
		{
		nTecla = nTecla - 32;
		}




	// Testa todos os items permitidos
	if (!(
			((nTecla > 47) && (nTecla < 58)) // números
			|| ((nTecla > 64) && (nTecla < 91)) // Letras maiúsculas
			|| ((nTecla > 191) && (nTecla < 222)) // A acentuados maiúsculos
			|| ((nTecla == 32)) // espaço
			|| ((nTecla == 13)) // Enter
			|| ((nTecla == 44)) // Vírgula
			|| ((nTecla == 45)) // Hífem
			|| ((nTecla == 46)) // Ponto
			|| ((nTecla == 47)) // Barra normal
			|| ((nTecla == 58)) // Dois pontos
			|| ((nTecla == 59)) // Ponto e vírgula
			|| ((nTecla == 63)) // Interrogação
			|| ((nTecla == 64)) // Arroba
			|| ((nTecla == 95)) // Under-line "_"
			|| ((nTecla == 96)) // ` crase a ser utilizado no local das aspas.
			|| ((nTecla == 170)) // "a" pequeno de primeira = 1ª
			|| ((nTecla == 186)) // "o" pequeno de primeiro = 1º			

		))
		{ nTecla = 0; }
			


      if(document.all) 
	  	{ // Internet Explorer
        evtKeyPress.keyCode = nTecla ; 
		}
      else if(document.layers) 
	  	{ // Nestcape
        evtKeyPress.which = nTecla ;
	    }

		
} // fim da função



// ------------------------------------------------------------
// ************************************************************
// VERIFICA SE ESTÁ EM FORMATO MOEDA = "1000,20"
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_Verificar_Moeda
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	VERIFICA SE O CAMPO ESTÁ NO FORMATO MOEDA = "1022,01".
//				PERMITE APENAS DUAS CASAS DECIMAIS.
// LIMITAÇÃOES:	???
// PARÂMETROS:	CAMPO A SER VERIFICADO
// PRÉ-REQUISITOS: FUNÇÃO: fj_Validar_Numeros
// EXEMPLO: ???		
// DESCRIÇÃO DO EXEMPLO: ???
// ------------------------------------------------------------

function fj_Verificar_Moeda(field,vazio)
{
	 if (field.value == "")
	 {
			if (vazio != 0)
			{
				return true;
			}
			else
			{
				alert('É necessário especificar um valor!');
				return false;
			}
	  }
	
	 if (fj_Validar_Numeros(field))
	 {  
			return true;
	 }
	 else
	 {	
	 		alert("Informe um valor correto! (até duas casas decimais)");
			field.focus();
			return false;
	 }
}
// ************************************************************
// FIM DA FUNÇÃO QUE VERIFICA SE ESTÁ EM FORMATO MOEDA = "1000,20"
// ************************************************************


// ------------------------------------------------------------
// ************************************************************
// FUNÇÃO QUE VALIDA NÚMEROS
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_Validar_Numeros
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	VALIDA NÚMEROS DE ZERO A NOVE COM OU SEM VÍRGULA
// LIMITAÇÃOES:	???
// PARÂMETROS:	CAMPO A SER VERIFICADO
// PRÉ-REQUISITOS: FUNÇÃO: ???
// UTILIZADA POR: fj_Verificar_Moeda
// EXEMPLO: ???		
// DESCRIÇÃO DO EXEMPLO: ???
// ------------------------------------------------------------

function fj_Validar_Numeros(field)
{
 var valid = "0123456789,."
 var ok = "yes";
 var ponto = 0;
 var temp;
 var numponto = 0;

 var msg = "";
 
 for (var i=0; i<field.value.length; i++)
 {
 	temp = "" + field.value.substring(i, i+1);
	
	if (temp == ",")
	{
		numponto++; // conta quantas vezes apareceram vírgulas
		if (ponto == 0)
			ponto = i;
	}

	if (  !((i == 0) && (temp == '-'))  )
		{
			if (valid.indexOf(temp) == "-1") ok = "no";
		}

		
		
	
	
	msg += i + " - Temp: " + temp + " Ok: " + ok + " NumPonto: " + numponto + " Ponto: " + ponto + "\n"
 }
 
 if (ponto != 0)
	temp = field.value.length - (ponto + 1) - 2;
 else
	temp = 0;
	
 msg += "\nPonto: " + ponto + " Temp: " + temp + "\n" 
 
 //alert(msg);
 
 if (ok == "no")
 	return false;

 if (numponto >= 2)
 	return false;

 if (temp == -2 && numponto == 1)
 	return false;

 if (temp >= 1)
 	return false;

 if (ponto == 0 && numponto == 1)
 	return false;

return true;
}
// ************************************************************
// FIM DA FUNÇÃO QUE VALIDA NÚMEROS
// ************************************************************





// ------------------------------------------------------------
// ************************************************************
// FUNÇÃO QUE VALIDA DATA
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_Verificar_Data
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	VALIDA UM CAMPO DE DATA
// LIMITAÇÃOES:	???
// PARÂMETROS:	CAMPO A SER VERIFICADO 
//			e um inteiro onde 	0 = campo não obrigatório
//								1 = campo obrigatório
// PRÉ-REQUISITOS: FUNÇÃO: fj_Validar_Data
// UTILIZADA POR: ???
// EXEMPLO: ???		
// DESCRIÇÃO DO EXEMPLO: ???
// ------------------------------------------------------------
function fj_verificar_data(objName, vazio)
{	
	var datefield = objName;

	if (datefield.value == "")
	{
		if (vazio != 0)		
		{
			return false;
		}
		else
		{
			return true;
		}
	}



	if (fj_Validar_Data(objName) == false) 
	{	//datefield.select();
		// alert("Data inválida");
		//datefield.value = ""
		// datefield.focus();
		return false;
	}
	else
	{	//alert("Data Válida");
		return true;
   	}
}
// ************************************************************
// FIM DA FUNÇÃO QUE VALIDA DATA
// ************************************************************





// ------------------------------------------------------------
// ************************************************************
// FUNÇÃO QUE CHECA A DATA
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_Validar_Data
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	TESTA UM CAMPO DE DATA
// LIMITAÇÃOES:	???
// PARÂMETROS:	CAMPO A SER VERIFICADO
// PRÉ-REQUISITOS: FUNÇÃO: fj_AnoBissexto
// UTILIZADA POR: FUNÇÃO: fj_Verificar_Data
// EXEMPLO: ???		
// DESCRIÇÃO DO EXEMPLO: ???
// ------------------------------------------------------------
function fj_Validar_Data(objName) 
{	var strDate;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var datefield = objName;
	strDate = datefield.value;
	//concatenar os campos e verificar quantidades
	// considerando um campo só com quantidade certa.
	


	
	// YYYY DD MM -> DD/MM/YYYY
	/*
	strYear = strDate.substr(0, 4);
	strDay = strDate.substr(5, 2);
	strMonth = strDate.substr(8, 2);
	strDate = strDay + '/' + strMonth + '/' + strYear
	*/
	
	
	
	
	// se vier dd/mm/yyyy usar este
	strDay = strDate.substr(0, 2);
	strMonth = strDate.substr(3, 2);
	strYear = strDate.substr(6, 4);
	

	
// alert(strYear  + ' - ' + strDay + ' - ' + strMonth);

	strBarra1 = strDate.substr(2, 1);
	strBarra2 = strDate.substr(5, 1);
   	
	// Mostra os valores das variaveis
//	alert("strDay: " + strDay + "\nstrBarra1: " + strBarra1 + "\nstrMonth: " + strMonth + "\nstrBarra2: " + strBarra2 + "\nstrYear: " + strYear + ', data: ' + strDate);

	intday = parseInt(strDay, 10);
/*	intday1 = parseInt(strDate.substr(0, 1), 10);
	intday2 = parseInt(strDate.substr(1, 1), 10); 
	if ((isNaN(intday1)) || (isNaN(intday2))) */
	if (isNaN(intday)) 
	{	
		// alert("Erro no dia");
		return false;
	}
	
	intMonth = parseInt(strMonth, 10);
	/*
	intMonth1 = parseInt(strDate.substr(3, 1), 10);
	intMonth2 = parseInt(strDate.substr(4, 1), 10);
	if ((isNaN(intMonth1)) || (isNaN(intMonth2))) */
	if (isNaN(intMonth)) 
	{	
		// alert("Erro no mês");
		return false;
	}
	
	intYear = parseInt(strYear, 10);
	/*
	intYear1 = parseInt(strDate.substr(6, 1), 10);
	intYear2 = parseInt(strDate.substr(7, 1), 10);
	intYear3 = parseInt(strDate.substr(8, 1), 10);
	intYear4 = parseInt(strDate.substr(9, 1), 10);
	if ((isNaN(intYear1)) || (isNaN(intYear2)) || (isNaN(intYear3)) || (isNaN(intYear4)) || (intYear <= 1900))
	*/
	if ((isNaN(intYear))  || (intYear <= 1900))
	{	
		// alert("Erro no ano");
		return false;
	}
	
	if ((strBarra1 != "/") ||(strBarra2 != "/"))
	{	
		// alert("Erro na Barra / ");
		return false;
	}
	
	if (intMonth > 12 || intMonth < 1)
	{	
		// alert('Mes intMonth > 12 || intMonth < 1');
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1))
	{	
		// alert('n dias por mes');
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1))
	{	
		// alert('n dias por mes 2');
		return false;
	}
	if (intMonth == 2)
	{	
		if (intday < 1)
		{	
			// alert('dia menor q 1');
			return false;
		}
		if (fj_AnoBissexto(intYear) == true)
		{
			if (intday > 29)
			{	
				// alert('ano bissexto');
				return false;
			}
		}
		else
		{	
			if (intday > 28)
			{	
				// alert('fevereiro com 28');
				return false;
			}
		}
	}
	// alert('OK');
	return true;
}
// ************************************************************
// FIM DA FUNÇÃO QUE CHECA A DATA
// ************************************************************




// ------------------------------------------------------------
// ************************************************************
// FUNÇÃO QUE CHECA SE É ANO BISSEXTO
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_AnoBissexto
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	TESTA UM NÚMERO INTEIRO QUE REPRESENTE UM ANO 
//				VERIFICANDO SE É BISSEXTO OU NÃO.
// LIMITAÇÃOES:	???
// PARÂMETROS:	NÚMERO INTEIRO DE QUATRO DÍGITOS
// PRÉ-REQUISITOS: 
// UTILIZADA POR: FUNÇÃO: fj_TestarData
// EXEMPLO: ???		
// DESCRIÇÃO DO EXEMPLO: ???
// ------------------------------------------------------------

function fj_AnoBissexto(intYear)
{	if (intYear % 100 == 0)
	{	if (intYear % 400 == 0)
		{	return true;
		}
	}
	else
	{	if ((intYear % 4) == 0)
		{ 	return true;
		}
	}
	return false;
}
// ************************************************************
// FIM DA FUNÇÃO QUE CHECA SE É ANO BISSEXTO
// ************************************************************




// ------------------------------------------------------------
// ************************************************************
// FUNÇÃO QUE VERIFICA UM NÚMERO DE CPF
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_Verificar_CPF
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	VERIFICA UM NÚMERO DE CPF.
// LIMITAÇÃOES:	???
// PARÂMETROS:	CAMPO QUE CONTÉM O NÚMERO DO CPF, SE PERMITE VAZIO
// PRÉ-REQUISITOS: função: fj_Validar_CPF
// UTILIZADA POR: ???
// EXEMPLO: ???		
// DESCRIÇÃO DO EXEMPLO: ???
// ------------------------------------------------------------
function fj_Verificar_CPF(objName, Vazio)
{	var datefield = objName;

	if (datefield.value == "")
	{
		if (Vazio != 0)
		{
			return true;
		}
		else
		{
			alert ('É necessário especificar o CPF!');
			objName.focus();
			return false;
		}
	}


	if (fj_Validar_CPF(objName.value) == false) 
	{	datefield.select();
		alert("CPF inválido!!!");
		//datefield.value = ""
		datefield.focus();
		return false;
	}
	else
	{	//alert("Data Válida");
		return true;
   	}
}
// ************************************************************
// FIM DA FUNÇÃO QUE VERIFICA UM NÚMERO DE CPF
// ************************************************************





// ------------------------------------------------------------
// ************************************************************
// FUNÇÃO QUE VALIDA UM NÚMERO DE CPF
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_Validar_CPF
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	VERIFICA UM NÚMERO DE CPF.
// LIMITAÇÃOES:	???
// PARÂMETROS:	CAMPO QUE CONTÉM O NÚMERO DO CPF
// PRÉ-REQUISITOS: ???
// UTILIZADA POR: fj_Verificar_CPF
// EXEMPLO: ???		
// DESCRIÇÃO DO EXEMPLO: ???
// ------------------------------------------------------------
 function fj_Validar_CPF(CPF) {
 s="" 
	for (x=0; x < CPF.length; x++)
	 	if (CPF.charCodeAt(x) >= 48 && CPF.charCodeAt(x)<=57)
			s= s + CPF.charAt(x)
	CPF = s

	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999")
		return false;
	soma = 0;
	for (i=0; i < 9; i ++)
		soma += parseInt(CPF.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(9)))
		return false;
	soma = 0;
	for (i = 0; i < 10; i ++)
		soma += parseInt(CPF.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(10)))
		return false;
	return true;
 }
// ************************************************************
// FIM DA FUNÇÃO QUE VALIDA UM NÚMERO DE CPF
// ************************************************************





// ------------------------------------------------------------
// ************************************************************
// FUNÇÃO QUE VERIFICA UM NÚMERO DE CNPJ
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_Verificar_CNPJ
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	VERIFICA UM NÚMERO DE CNPJ.
// LIMITAÇÃOES:	???
// PARÂMETROS:	CAMPO QUE CONTÉM O NÚMERO DO CPF
// PRÉ-REQUISITOS: fj_Validar_CNPJ
// UTILIZADA POR: ???
// EXEMPLO: ???		
// DESCRIÇÃO DO EXEMPLO: ???
// ------------------------------------------------------------
function fj_Verificar_CNPJ(objName, Vazio)
{	var datefield = objName;

	if (datefield.value == "")
		{
			if (Vazio != 0)
				{
				return true;
				}
				else
				{
				alert ('É necessário especificar o CNPJ!');
				objName.focus();
				return false;
				}
		}


	if (fj_Validar_CNPJ(objName.value) == false) 
	{	datefield.select();
		alert("CNPJ inválido!!!");
		//datefield.value = ""
		datefield.focus();
		return false;
	}
	else
	{	
		return true;
   	}
}
// ************************************************************
// FIM DA FUNÇÃO QUE VERIFICA UM NÚMERO DE CNPJ
// ************************************************************




// ------------------------------------------------------------
// ************************************************************
// FUNÇÃO QUE VALIDA UM NÚMERO DE CNPJ
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_Validar_CNPJ
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	VERIFICA UM NÚMERO DE CNPJ.
// LIMITAÇÃOES:	???
// PARÂMETROS:	CAMPO QUE CONTÉM O NÚMERO DO CPF
// PRÉ-REQUISITOS: ???
// UTILIZADA POR: fj_Verificar_CNPJ
// EXEMPLO: ???		
// DESCRIÇÃO DO EXEMPLO: ???
// ------------------------------------------------------------
function fj_Validar_CNPJ(RecebeCNPJ)
{
var soma
var resultado1
var resultado2

s="" 

for (x=0; x < RecebeCNPJ.length; x++)
 	if (RecebeCNPJ.charCodeAt(x) >= 48 && RecebeCNPJ.charCodeAt(x)<=57)
		s= s + RecebeCNPJ.charAt(x)

RecebeCNPJ = s

if (RecebeCNPJ.length != 14 || RecebeCNPJ == "00000000000000")
	{
	return false
	}
else
	{
	soma = RecebeCNPJ.charAt(0) * 5 + RecebeCNPJ.charAt(1) * 4 + RecebeCNPJ.charAt(2) * 3 + RecebeCNPJ.charAt(3) * 2 + RecebeCNPJ.charAt(4) * 9 + RecebeCNPJ.charAt(5) * 8 + RecebeCNPJ.charAt(6) * 7 + RecebeCNPJ.charAt(7) * 6 + RecebeCNPJ.charAt(8) * 5 + RecebeCNPJ.charAt(9) * 4 + RecebeCNPJ.charAt(10) * 3 + RecebeCNPJ.charAt(11) * 2

	soma = soma -(11 * (parseInt(soma / 11)))

	if (soma == 0 || soma == 1)
		resultado1 = 0
	else
		resultado1 = 11 - soma

	if (resultado1 == RecebeCNPJ.charAt(12))
		{
		soma = RecebeCNPJ.charAt(0) * 6 + RecebeCNPJ.charAt(1) * 5 + RecebeCNPJ.charAt(2) * 4 + RecebeCNPJ.charAt(3) * 3 + RecebeCNPJ.charAt(4) * 2 + RecebeCNPJ.charAt(5) * 9 + RecebeCNPJ.charAt(6) * 8 + RecebeCNPJ.charAt(7) * 7 + RecebeCNPJ.charAt(8) * 6 + RecebeCNPJ.charAt(9) * 5 + RecebeCNPJ.charAt(10) * 4 + RecebeCNPJ.charAt(11) * 3 + RecebeCNPJ.charAt(12) * 2

		soma = soma - (11 * (parseInt(soma / 11)))
		
		if (soma == 0 || soma == 1)
			resultado2 = 0
		else
			resultado2 = 11 - soma

		if (resultado2 == RecebeCNPJ.charAt(13))
			return true
		else
			return false
		}
	else
		return false
	}
}
// ************************************************************
// FUNÇÃO QUE VALIDA UM NÚMERO DE CNPJ
// ************************************************************






// ------------------------------------------------------------
// ************************************************************
// FUNÇÃO QUE VERIFICA SE UM CAMPO É NÚMERO OU NÃO
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_E_Numero
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	VERIFICA UM CAMPO CONTÉM APENAS VALORES NUMÉRICOS DE UM A NOVE.
// LIMITAÇÃOES:	???
// PARÂMETROS:	CAMPO QUE CONTÉM O NÚMERO 
// PRÉ-REQUISITOS: ???
// UTILIZADA POR: ???
// EXEMPLO: ???		
// DESCRIÇÃO DO EXEMPLO: ???
// ------------------------------------------------------------
function fj_E_Numero(field)
{	
 var valid = "0123456789"
 var ok = "yes";
 var temp;

 var msg = "";

 for (var i=0; i<field.value.length; i++)
 {
 	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") ok = "no";
	
	msg += i + " - Temp: " + temp + " Ok: " + ok + "\n"
 }
 //alert(msg);
 if (ok == "no")
 	{
	alert("Neste campo só pode ter número!");
	field.value = "";
	field.focus();
    return false;
	}
 else
 	return true;
}
// ************************************************************
// FIM DA FUNÇÃO QUE VERIFICA SE UM CAMPO É NÚMERO OU NÃO
// ************************************************************




// ------------------------------------------------------------
// ************************************************************
// FUNÇÃO QUE IMPEDE O SUBMIT EM UM FORMULÁRIO AO TELCAR ENTER
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_Submit_Nao
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	IMPEDE QUE SEJA DADO SUBMIT EM UM FORM AO TECLAR
//				ENTER SOBRE UM CAMPO QUALQUER.
// LIMITAÇÃOES:	???
// PARÂMETROS:	teclapres,campo
// PRÉ-REQUISITOS: ???
// UTILIZADA POR: ???
// EXEMPLO: onkeydown="return Sem_Enter(event)"		
// DESCRIÇÃO DO EXEMPLO: ???
// ------------------------------------------------------------
function fj_Submit_Nao(teclapres,campo)
{	var tecla = teclapres.keyCode;
	if (tecla == 13)
		return false;
	else
		return true;
}
// ************************************************************
// FIM DA FUNÇÃO QUE IMPEDE O SUBMIT EM UM FORMULÁRIO AO TELCAR ENTER
// ************************************************************









// ************************************************************
// FUNÇÃO QUE abre uma janela pop up 
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_pop
// AUTOR: 		CARLOS ALLAN SILVA ANDRADE
// DATA:		10/12/2004
// DESCRIÇÃO: 	ABRE UMA JANELA POP UP
// LIMITAÇÃOES:	???
// PARÂMETROS:	O ENDEREÇO URL DO ARQUIVO A SER ABERTO
// PRÉ-REQUISITOS: NÃO TEM
// UTILIZADA POR: QUALQUER LUGAR DO SISTEMA
// EXEMPLO: 
// DESCRIÇÃO DO EXEMPLO: 
// ------------------------------------------------------------


function fj_pop(url, largura, altura, janela)
{
	
	if (!url)
	{
		url = alert('Endereço não especificado!');
		return false;
	}
	
	if (!janela)
	{
		janela = '_blank';
	}


	if (!largura)
	{
		largura = (screen.width-10);
	}
	
	if (!altura)
	{
		altura = (screen.height-150);
	}
	
	var Janela = window.open(url, janela,'alwaysLowered=yes,alwaysRaised=no,dependent=yes,directories=no,hotkeys=no,location=no,menubar=no,personalbar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,width=' + largura + ',height=' + altura + ',z-lock=yes,left=0,top=0');
	Janela.focus();
}
// ************************************************************
//  FIM DA FUNÇÃO QUE abre uma janela pop up 
// ************************************************************





// ************************************************************
// FUNÇÃO QUE Exclui todos os espaçoes do inicio e do final da string
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_trim
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	Exclui todos os espaçoes do inicio e do final da string (similar ao TRIM do asp).
// LIMITAÇÃOES:	???
// PARÂMETROS:	uma string
// PRÉ-REQUISITOS: NÃO TEM
// UTILIZADA POR: QUALQUER LUGAR DO SISTEMA
// EXEMPLO: 
// DESCRIÇÃO DO EXEMPLO: 
// ------------------------------------------------------------
// remove espaços em branco no início e no final da string
function fj_trim(str)
{
while (str.charAt(0) == " ")
str = str.substr(1,str.length -1);

while (str.charAt(str.length-1) == " ")
str = str.substr(0,str.length-1);

return str;
}
// ************************************************************
// FIM DA FUNÇÃO QUE Exclui todos os espaçoes do inicio e do final da string
// ************************************************************



/*
Autor: Carlos Allan Silva Andrade
Data: 24/01/2005
Descrição: Exibe uma janela de confirmação com o texto enviado como parâmetro e 
	retorna "true" caso o usuário selecione ok e 'false' caso selecione cancelar
*/
function fj_confirmacao(mensagem)
{	
if (window.confirm(mensagem))
	return true;
else
	return false;
}





// ------------------------------------------------------------
// ************************************************************
// FUNÇÃO QUE FORMATA CAMPOS TXT
// ************************************************************
// ------------------------------------------------------------
// NOME: 		fj_txtFormat
// AUTOR: 		DESCONHECIDO
// DATA:		DESCONHECIDA
// DESCRIÇÃO: 	FORMATA CAMPOS DE UM FORMULÁRIO DE ACORDO COM 
//				A MÁSCARA ESPECIFICADA. POSSIBILITA UM FORMATO 
//				FIXO E PRÉ DETERMINADO.
// LIMITAÇÃOES:	DEVIDO A SOMENTE FORMATAR CAMPOS COM FORMATO FIXO E PRÉ-
//				DETERMINADO, ESTA FUNÇÃO NÃO É ADEQUADA PARA FORMATAR CAMPOS DO TIPO MOEDA
// PARÂMETROS:	FORMULÁRIO QUE CONTÉM O CAMPO, O NOME DO CAMPO, 
//				A MÁSCARA E O EVENTO
// PRÉ-REQUISITOS: ???
// EXEMPLO:		onKeyPress="return fj_txtFormat(document.frmTeste, 'txtCampo', '999.999.999-99', event);" 
// DESCRIÇÃO DO EXEMPLO: FORMATA O CAMPO 'txtCampo' do formulário 'frmTeste' como campo com máscara de CPF.
// ------------------------------------------------------------
function fj_txtFormat(objForm, strField, sMask, evtKeyPress) 
{

   var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	
	nTecla = fj_keycode(evtKeyPress);
	  
	// alert(nTecla);
	
	
	if(nTecla == 0)
	{
		return nTecla;
	}
     sValue = objForm[strField].value;

      // Limpa todos os caracteres de formatação que
      // já estiverem no campo.
      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( ".", "" );
	  sValue = sValue.toString().replace( ",", "" );	// POR ALLAN ANDRADE
	  sValue = sValue.toString().replace( ",", "" );	// POR ALLAN ANDRADE
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( " ", "" );
      sValue = sValue.toString().replace( " ", "" );
      fldLen = sValue.length;
      mskLen = sMask.length;

      i = 0;
      nCount = 0;
      sCod = "";
      mskLen = fldLen;

      while (i <= mskLen) {
        bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
        bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
		bolMask = bolMask || ((sMask.charAt(i) == ",") || (sMask.charAt(i) == ","))  // POR ALLAN ANDRADE

        if (bolMask) {
          sCod += sMask.charAt(i);
          mskLen++; }
        else {
          sCod += sValue.charAt(nCount);
          nCount++;
        }

        i++;
      }

      objForm[strField].value = sCod;

      if (nTecla != 8) { // backspace
        if (sMask.charAt(i-1) == "9") { // apenas números...
          return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
        else { // qualquer caracter...
          return true;
        } }
      else {
        return true;
      }
    }
// ************************************************************
// FIM DA FUNÇÃO QUE FORMATA CAMPOS TXT
// ************************************************************




// autor: desconhecido
// origem: internet
// função, exibe mensagem de erro quando for digitado um caracter inválido
// falta testar
function fj_valida_caracter(Campo,invalid)
{	
	var ok = "yes";
	var temp;
	var msg = "";
	
	for (i = 0; i < invalid.length; i++)
	 	msg = msg + invalid.substring(i, i+1) + " ";

	if (Campo.value != "")
	{	
		for (i = 0; i < Campo.value.length && ok != "no"; i++)
		{	
		 	temp = "" + Campo.value.substring(i, i+1);
			if (invalid.indexOf(temp) != "-1") ok = "no";
		}

		if (ok == "no")
			{	
				alert("Caracter Inválido!\nNão use: ( " + msg + ")");
				Campo.value = "";
				Campo.focus();
				return true;
			}
		else
			return true;
	}
	else
		return true;
}

