var patterns = new Array ( 
	"###,###,###,###",					// US/British
	"############"						// no formatting
	);

// A little function to take an integer string, strip out current formatting,
// and reformat it according to a pattern string. '#' characters in the pattern
// are substituted with digits from the integer string, other pattern characters
// are output literally into the returned string.
function formatInteger( integer )
{
	var result = '';
    var pattern = "###,###,###,###";
	integerIndex = integer.length - 1;
	patternIndex = pattern.length - 1;

	while ( (integerIndex >= 0) && (patternIndex >= 0) )
	{
		var digit = integer.charAt( integerIndex );
		integerIndex--;
		
		// Skip non-digits from the source integer (eradicate current formatting).
		if ( (digit < '0') || (digit > '9') )  continue;
	
		// Got a digit from the integer, now plug it into the pattern.
		while ( patternIndex >= 0 )
		{
			var patternChar = pattern.charAt( patternIndex );
			patternIndex--;
			
			// Substitute digits for '#' chars, treat other chars literally.
			if ( patternChar == '#' )
			{
				result = digit + result;
				break;
			}
			else
			{
				result = patternChar + result;
			}
		}
	}
	
	return result;
}
