function onlyNums(input,makeNum) {
	str = input.toString();
	output = "";
	re = /[0-9]/;
	howManyDecimals = 0;
	for (i=0;i<str.length;i++) {
		if (str.charAt(i).match(re)) output += str.charAt(i);
		else if (str.charAt(i) == ".") {
			if (howManyDecimals < 1) {
				output += str.charAt(i);
				howManyDecimals++;
			}
		}
	}
	if (makeNum) output = parseFloat(output);
	return output;
}

function numberFormat(input,decimals,decSeparator,thousSeparator) {
	if (!decimals) decimals = 0;
	if (!decSeparator) decSeparator = ".";
	if (!thousSeparator) thousSeparator = ",";
	
	var output = "";
	newNum = (Math.round(onlyNums(input,1) * Math.pow(10,decimals)) / Math.pow(10,decimals)).toString();
	
	if (decimals > 0) {
		if (newNum.indexOf(".") < 0) newNum += ".";
		newNum = newNum.substring(0,newNum.indexOf(".") + 3);
		decimalPlaces = newNum.length - 1 - newNum.indexOf(".");
		for (i=1;i<=decimals - decimalPlaces;i++) {
			newNum += "0";
		}
	}
	
	numParts = newNum.split(".");
	
	//insert thousand separator
	count = 0;
	var newIntPart = "";
	for (i=numParts[0].length - 1;i>=0;i--) {
		if (count % 3 == 0 && count > 0) newIntPart = thousSeparator + newIntPart;
		newIntPart = numParts[0].charAt(i) + newIntPart;
		count++;
	}
	numParts[0] = newIntPart;
	
	output = numParts.join(decSeparator);
	
	return output;
}
