function ValidaPreco (valor, comNegativo)
{
	var tam, virgula;

	virgula = 0;
	tam = valor.length;

	for(i=0; i<tam; i++)
	{
		if(valor.charAt(i) == "-" && comNegativo == true)
		{
			if(i > 0)
				return false;
		}
		else
		{
			if(valor.charAt(i) == "," && i > 0 && i != (tam-1))
				virgula++;
			else
				if(valor.charAt(i) < '0' || valor.charAt(i) > '9')
					return false;
		}
	}
	if(virgula > 1)
		return false;
	else
		return true;
}

function FormataPreco(campo, teclaPres, precisao, comNegativo)
{
	var tecla = navigator.appName == 'Microsoft Internet Explorer' ? teclaPres.keyCode : teclaPres.which;

	if(tecla == 46)
		if(navigator.appName == 'Microsoft Internet Explorer')
			tecla = teclaPres.keyCode = 44;
		else
			tecla = teclaPres.which = 44;
	
	if((tecla > 47 && tecla < 58) || tecla == 44 || tecla == 8 || tecla == 0 || (tecla == 45 && comNegativo == true))
	{
		var vr = new String(campo.value);
		var tam = vr.length;

		if(tecla == 45)
		{
			if(vr.indexOf('-') != -1)// || tam > 0)
				return false;
		}
		else
		{
			if(tecla == 44)
			{
				if(vr.indexOf('-') != -1)
					tam--;
				if(tam == 0 || precisao == 0)
					return false;
				if(vr.indexOf(',') != -1)
					return false;
			}
			else
			{
				if(precisao < 1)
					precisao = 100;
				if(tam >= precisao && vr.indexOf(',') == -1)
					campo.value = vr.substr(0,precisao) + ',' + vr.substr(precisao,tam-precisao);
			}
		}
		return true;
	}
	return false;
}