
/*
** Biblioteca de funções de testes de entrada do usuário 
** Data: 06/10/2004
*/

function ApenasTeclasPermitidas(strCaracteres){

	var lngKey;			// Código ASC da tecla digitada
	var strValor;
	
	lngKey = window.event.keyCode;
	strValor = String.fromCharCode(lngKey);
		
	if ( (strCaracteres.indexOf(strValor) < 0 )&& (lngKey != 9)){
		window.event.keyCode = 0;
		return false;
	}
	
	return true;
	
}

function ApenasTeclasValor(strValorAtual){

	var lngKey;	//Código ASC da tecla digitada
	var strValor;
	lngKey = window.event.keyCode;	
		
	strValor = String.fromCharCode(lngKey);
	
	if ( (lngKey <= 47||lngKey >= 58) && lngKey != 9 &&  strValor != ',' ) 
	{
	
		window.event.keyCode = 0;
		return false;
		
	}else if ( strValor == ',' ){
	
		if ( strValorAtual.indexOf(',') > -1  ){
			window.event.keyCode = 0;
			return false;
		}
	
	}
			
	return true;
	
}

function ApenasTeclasNumericas(){

	var lngKey;			// Código ASC da tecla digitada
		
	lngKey = window.event.keyCode;	
		
	if ( ((lngKey <= 47)||(lngKey >= 58)) && (lngKey != 9) ) 
	{
		window.event.keyCode = 0;
		return false;
	}
			
	return true;
	
}

function ApenasTeclasHorario(){

	var lngKey;			// Código ASC da tecla digitada
		
	lngKey = window.event.keyCode;	

	if ( (lngKey >= 48) && (lngKey <= 57)) 
	{
		return true;
	}else
	{
		window.event.keyCode = 0;
		return false;
	}
}

function ApenasDigitos( objText )
{
	return( ApenasContidos( objText, "0123456789" ) );
}

//********************************************************************************
// Objetivo  :	Verifica se o o campo contem apenas os caracteres válidos
// Premissas :	Nenhuma
// Entradas  :	objText - Campo input
//				strValidos - Lista de caracteres válidos
// Retorno   :	true ou false
//********************************************************************************
function ApenasContidos( objText, strValidos )
{
	var temp;
	var i;
	var strValor = objText.value;
	
	for ( i=0; i < strValor.length; ++i)
	{
		temp = strValor.substring(i, i+1);				
		if (strValidos.indexOf(temp) < 0)
		{ 
			return(false);
		}
	}
	return(true);
}

//**************************************************************************************************************
// Objetivo  :	Efetua o intercâmbio entre os strings
// Premissas :	Nenhuma
// Entradas  :	strField   = string utilizado
//			    strSearch  = string pesquisado
//			    strReplace = string que se quer substituir
// Retorno   :	true ou false
//**************************************************************************************************************

function Replace(strField, strSearch, strReplace)
{ 
	while (strField.indexOf(strSearch) > -1) 
		strField = strField.replace(strSearch, strReplace); 
	return(strField); 
} 

//**************************************************************************************************************
// Objetivo  :	Formata Data
// Premissas :	Nenhuma
// Entradas  :	objObject      - objeto para formatar a data
// Retorno   :	true ou false
//**************************************************************************************************************

function FormatDate(objObject)
{ 
	
	var intValue = objObject.value;
	
	//LCCM - 2004-04-21 Nao e necessario formatar quando já está formatado.
	if (intValue.length==10)
		return;
	
	intValue = Replace(intValue, '/', '');
	
	if (intValue.length > 2)
	{ 
		intValue = intValue.substring(0,2) + "/" + intValue.substring(2, intValue.length); 
	} 
	if (intValue.length > 5)
	{
		intValue = intValue.substring(0,5) + "/" + intValue.substring(5, intValue.length); 
	} 
	objObject.value = intValue;
	
}
