function abs(num){
   return Math.abs(num);
}

function toNumber(val){
  val = String(val);
  val = val.replace(/\s/g,'');
  val = val.replace(',','.');
  val = parseFloat(val);
  if (isNaN(val)) val = 0;
  return val;
}

Number.prototype.toFixed = function(precision) {
    var power = Math.pow(10, precision || 0);
    return String(Math.round(this * power)/power);
}

function formNum(num,dec){
  var newInt = new String('');
  var decPart = new String('');

  if (isNaN(num)) num = 0;

  num = num.toFixed(dec);

  num = String(num);
  // pozice tecky v retezci
  dot = num.indexOf('.')
  // je tam, useknout desetinou cast na pozadovanou delku
  if (dot>-1){ decPart = num.substring(dot+1,dot+1+dec); }
  // doplnit desetinou cast na pozadovanou delku
  while (decPart.length<dec) decPart = decPart + '0';
  // cela cast od 0 po tecku
  if (dot==-1) dot = num.length;
  intPart = num.substring(0,dot);
  intPart = intPart.split('');
  intPart = intPart.reverse();
  intPart = intPart.toString(intPart);
  intPart = intPart.replace(/,/g,'');

  for (x=0;x<intPart.length;x+=3) { newInt += String(intPart.substr(x,3) + ' '); }
  newInt = newInt.split('');
  newInt = newInt.reverse();
  newInt = newInt.toString();
  newInt = newInt.replace(/,/g,'');
  if (newInt.substring(0,1) == ' ') newInt = newInt.substring(1);
  if (dec>0) newNum = newInt+','+decPart;
  else       newNum = newInt;
  return newNum;
}
