function roundTo(num, dec) {
    return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
}

function isInteger(s) {
  if (isEmpty(s)) return false;

  for (var i = 0; i < s.length; i++) {
     var c = s.charAt(i);

     if (!isDigit(c)) return false;
  }

  return true;
}

function isEmpty(s) {
  return ((s == null) || (s.length == 0))
}

function isDigit (c) {
  return ((c >= "0") && (c <= "9"))
}

// isIntegerInRange (INTEGER s, INTEGER a, INTEGER b)
function isIntegerInRange (num, a, b) {
    return isInteger(num) && ((num >= a) && (num <= b));
}

function CommaFormatted(amount, decimal) {
	var delimiter = ","; // replace comma if desired
	amount = amount + '';
	var a = amount.split('.',2);
	var d = a[1];

	var i = parseInt(a[0]);

	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3) {
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);

    if (d == undefined) d = '';

	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;

    if (decimal) {
        if (d.length < 1) {
            amount = amount + '.';
            for (var r = 0; r < decimal; r++) {
                amount = amount + '0';
            }
        } else {
            for (var r = 0; r < decimal - d.length; r++) {
                amount = amount + '0';
            }
        }
    }

	return amount;
}
// end of function CommaFormatted()