		function ValidaTamanho(p_obj, p_objTam)
		{
			var strTexto = p_obj.value;
			
			p_objTam.value = 800 - strTexto.length;
			
			if(strTexto.length >= 800)
			{
				alert('O limite máximo de caracteres (800) foi atingido.');
				strTexto = strTexto.substr(0,800);
				p_obj.value = strTexto;
				return false;
			}
		}
		function ValidaNumero(f)
		{
			if (isNaN(f.value)==true)
				{ f.value="";msgError("Este campo deve ser numérico.");f.value="";
				  f.focus();
				return false;
				 } 
		
		}
		function isValidDigitCGC (InString,Digito)
		{
			AccVal = 0;
			Multi = 2;
			for (Count=InString.length;Count>0;Count--)
			{
				TempVal=InString.substring(Count-1,Count);
				AccVal += (TempVal * Multi);
				Multi ++
				if (Multi == 10) Multi = 2;
			}
			AccVal %= 11
			if (AccVal<2)
			   AccVal = 0;
			else
			   AccVal = 11-AccVal;
			if (Digito != AccVal)
			{
			   return(false)
			}
			return(true);
		}
		function msgError(InString)
		{
			alert(InString);
		}
		function valcgc(f)
		{
			if (f.cnpj.value != "0")
			{
				// Calcula o primeiro digito do CGC
				if (isValidDigitCGC (f.cnpj.value.substring(0,12),f.cnpj.value.substring(12,13)) != 1)
				{
					TempMsg = "Número Inválido! Tente Novamente.";
					msgError(TempMsg);
					f.cnpj.value="";
					return(false)
				}
				else
					// Calcula o segundo digito do CGC
					if (isValidDigitCGC (f.cnpj.value.substring(0,13),f.cnpj.value.substring(13,14)) != 1)
					{
						TempMsg = "Número Inválido! Tente Novamente.";
						msgError(TempMsg);
						f.cnpj.value="";
						return(false)
					}
				return(true)
			}
			else
			{
				f.cnpj.value="";
				TempMsg = "Número Inválido! Tente Novamente.";
				msgError(TempMsg);
				f.cnpj.value="";
				return(false);
			}
		}
		
		
function Tecla(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;
			}
		
}		
