function conv_maiusculo(texto)
{
  texto.value = texto.value.toUpperCase();
}

function conv_minusculo(texto)
{
  texto.value = texto.value.toLowerCase();
}

function fvalidadata(vpobjeto)
{
	vdata = vpobjeto.value;
	var inum = '';
	var rstr = '0123456789';
	var itam = vdata.length;

	for ( cont=0; cont < vdata.length; cont++ ) 
	{
		tchar = vdata.charAt(cont);
		if (rstr.indexOf(tchar) != -1)
			inum = inum + tchar;
	};

	itam = inum.length;
	if (itam != 8)
		return false;

	dia = inum.substring(0,2);
	mes = inum.substring(2,4);
	ano = inum.substring(4,8);

	if ((mes < 1) || (mes > 12)) 
		return false;

	if ((dia < 1) || (dia > 31))
		return false;

	if ((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11))
		if (dia > 30) 
		{
			return false;
		};

	if (mes == 2) 
		if (((ano % 4) == 0) || ((ano % 4) == 100) || ((ano % 400) == 0))
		{
			if (dia > 29)
				return false;
		}
		else
		{
			if (dia > 28)
				return false;
		};

	return true;
}
/**************************************************************
 FormatNumber: Returns an expression formatted as a number.

 Parameters:
      Expression            = Expression to be formatted.
      NumDigitsAfterDecimal = Numeric value indicating how
                              many places to the right of the
                              decimal are displayed.

 Returns: String
***************************************************************/
function FormatNumber(Expression, NumDigitsAfterDecimal)
{
	var iNumDecimals = NumDigitsAfterDecimal;
	var dbInVal = Expression;
	var bNegative = false;
	var iInVal = 0;
	var strInVal
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals)
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;

	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	
	if (bNegative)
	{
		return "-" + strWhole + "." + strDec;
	}
	else
	{
		return strWhole + "." + strDec;
	}
}

/**************************************************************
 TxtToNumber: Returns an expression formatted as a number.

 Parameters:
      Expression            = Expression to be formatted.

 Returns: String
***************************************************************/
function TxtToNumber(Expression)
{
	
	var newValue = Expression;
	
	newValue = Replace(newValue,'.','');
	newValue = Replace(newValue,',','.');
	
	return newValue;
	
}

/**************************************************************
 TxtToNumber: Returns an expression formatted as a text.

 Parameters:
      Expression            = Number to be formatted.

 Returns: String
***************************************************************/
function NumberToTxt(Expression)
{
	var newValue = Expression;
	
//	Alert('NumberToTxt in ' + newValue);
	
	if (InStr(newValue,',') > 0)
	{
		newValue = Replace(newValue,',','X');
		newValue = Replace(newValue,'.',',');
		newValue = Replace(newValue,'X','.');
	}
	else
	{
		newValue = Replace(newValue,'.',',');
	}

	return newValue;
	
}
/**************************************************************
 Replace: Returns a string in which a specified substring has 
          been replaced with another substring a specified 
          number of times.

 Parameters:
      Expression = String expression containing substring to 
                   replace
      Find       = Substring being searched for.
      Replace    = Replacement substring.

 Returns: String
***************************************************************/
function Replace(Expression, Find, Replace)
{
	var temp = Expression;
	var a = 0;

	for (var i = 0; i < Expression.length; i++) 
	{
		a = temp.indexOf(Find);
		if (a == -1)
			break
		else
			temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
	}

	return temp;
}

