function extractValue(string)
{
	var numberString = "";
	
	for (var i = 0; i < string.length; i++)
	{
		if (string.charAt(i).match(/[0-9]|\./))	
		{
			numberString += string.charAt(i);
		}
	}
	
	return new Number(numberString);
}

function sum(sourceFields)
{
	var targetValue = 0;
	
	sourceFields.each(
		function(field)
		{
			targetValue += extractValue(field.value);
		});
	
	return targetValue;
}

function integerFormat(field)
{
	if (field.value != null && field.value != "")
	{
		field.value = parseInt(extractValue(field.value));
	}
}

function dollarFormat(field, includeCents)
{
	var i = (parseInt((extractValue(field.value) + .005) * 100)) / 100;
	
	var s = new String(i);
	
	if (s.indexOf(".") < 0)
	{
		s += ".00";
	}
	
	if (s.indexOf(".") == (s.length - 2))
	{
		s += "0";
	}
	
	var a = s.split(".", 2);
	var d = a[1];
	
	if (!includeCents && parseInt(d) >= 50)
	{
		s = new String(parseInt(a[0]) + 1);
	} else
	{
		s = a[0];
	}
	
	a = [];
	
	while(s.length > 3)
	{
		var ss = s.substr(s.length - 3);
		a.unshift(ss);
		s = s.substr(0, s.length - 3);
	}
	
	if (s.length > 0)
	{
		a.unshift(s);
	}
	
	s = a.join(",");
	field.value = "$ " + s + (includeCents ? "." + d : "");
}
