/*

	72mm Standard Conversion Functions - Version 1.0
	
		09/12/2006 - created by Mark Delano (MPSD)
*/


/* Removes all content from variable except 0-9 */

function asPureInteger(str) {
	var tmp = "";
	str = str + "";
	
	for (var i = 0; i < str.length; i++)
		if (str.substr(i, 1) >= '0' && str.substr(i, 1) <= '9')
			tmp = tmp + str.substr(i, 1);

	return tmp;
}

/* Removes all content from variable except 0-9 and decimal point */

function asPureNumber(str) {
	var tmp = "";
	str = str + "";
	
	for (var i = 0; i < str.length; i++)
		if ((str.substr(i, 1) >= '0' && str.substr(i, 1) <= '9') || (str.substr(i, 1) == "."))
			tmp = tmp + str.substr(i, 1);

	return tmp;
}


/* turns "10KJDF13.7" into "10,137" or "10137" if separate == false */

function asNumber(str, decimals, separate) { 
	
	{
		if (decimals == undefined) decimals = -1; // -1 means Don't Touch!
		if (separate == undefined) separate = true;
	}

	var tmp = asPureInteger(str);
	if (separate == true && tmp.length > 3)
		tmp = tmp.substring(0, tmp.length-3) + "," + tmp.substring(tmp.length-3, tmp.length)

	return tmp;
}

/* Length-Limited Uppercase Conversion */

function asStringU(str, x) {
	var s = str.toUpperCase();
	if (str.length > x)
		s = s.substring(0, x);
		
	return s;
}

/* General Currency Format */

function asCurrency(str, decimals, currency_prefix, currency_postfix) {
	
	{
		if (decimals == undefined) decimals = 2;
		if (currency_prefix == undefined) currency_prefix = "$"
		if (currency_postfix == undefined) currency_postfix = "";
	}

	var tmp = asPureInteger(str);
	
	if (tmp.length > 3)
		tmp = tmp.substring(0, tmp.length - 3) + "," + tmp.substr(tmp.length-3);
		
	if (decimals > 0)
		tmp = tmp + eval(asPureNumber(str) - asPureInteger(str)).toFixed(decimals).substr(1);
		
	return currency_prefix + tmp + currency_postfix;
}