/************************************************************
 *                                                          *
 *   numbers.js - Number (un)formatting functions           *
 *                                                          *
 ************************************************************/


/* function stripNum() */
/* Strips common formatting symbols from numbers */
function stripNum(num) 
{
	var idx;
	var numLength = num.length;

	if(numLength > 0) 
	{
		num = num.toString();
		
		idx = num.indexOf("%");
		if(idx >= 0) 
		{
			num = num.substring(0, idx) + "" + num.substring(idx + 1, numLength);
			numLength = num.length;
		}
		
		idx = num.indexOf("$");
		if(idx >= 0) 
		{
			num = num.substring(0, idx) + "" + num.substring(idx + 1, numLength);
			numLength = num.length;
		}
		
		idx = num.indexOf(" ");
		if(idx >= 0)
		{
			num = num.substring(0, idx) + "" + num.substring(idx + 1, numLength);
			numLength = num.length;
		}
		
		idx = num.indexOf(",");
		if(idx >= 0) 
		{
			while(idx >= 1)
			{
				num = num.substring(0, idx) + "" + num.substring(idx + 1, numLength);
				numLength = num.length;
				idx = num.indexOf(",");
			}
		}
		
		num = eval(num);
	} 
	else 
	{
		num = 0;
	}
	return num;
}


function formatNumber(num) 
{
	var isNeg = 0;

	if(num < 0)
	{
		num *= -1;
		isNeg = 1;
	}

	onum = Math.round(num * 100) / 100;

	integer = Math.floor(onum);

	if(Math.ceil(onum) == integer) 
	{
		decimal = "00";
	}
	else
	{
		decimal = Math.round((onum - integer) * 100);
	}
	
	decimal = decimal.toString();
	if(decimal.length < 2)
	{
		decimal = "0" + decimal;
	}
	
	integer = integer.toString();
	var tmpnum = "";
	var tmpinteger = "";
	var y = 0;

	for(x = integer.length; x > 0; x--)
	{
		tmpnum = tmpnum + integer.charAt(x - 1);
		y++;
		if(y == 3 && x > 1)
		{
			tmpnum = tmpnum + ",";
			y = 0;
		}
	}

	for(x = tmpnum.length; x > 0; x--)
	{
		tmpinteger = tmpinteger + tmpnum.charAt(x - 1);
	}
		
	finNum = tmpinteger + "." + decimal;

    if(isNeg == 1)
    {
		finNum = "-" + finNum;
    }

	return finNum;
}


