function mojParse(e)
	{
		e = e.replace( /\./g, "" );
		e = e.replace( /\,/g,".");
		//e = parseInt(e);
		e = parseFloat(e);

		return isNaN(e) ? 0 : e;
	}


//Funkcija preveri ce je vnesena vrednost stevilo
function PreveriStevilo(e)
{	var num = mojParse(e.value);

	if (num == null){
		e.value="0";
		e.focus();
		return 0;
	} else {
		e.value=(num + "").replace( /\./, ",");
		return e.value;
	}
}


function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+'.'+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + ',' + cents);
}

function UnformatCurrency(num) {
	num=num.toString().replace(/\./,"");
	num=num.toString().replace(/\,/,".");
	return num;
}
	
function FormatMoney(input)
{
  var strMoney, strMoneyPare, strFormattedMoney, strMoneyDiv, strMoneyMod;

  strMoney = MoneyToInteger(input.value);
  if (strMoney == 0)
  {
    input.value = "";
    return;
  }

  strMoneyPare = 1001;
  strFormattedMoney = "00";
  strMoneyDiv = Math.floor(strMoney / 1000);
  strMoneyMod = Math.floor(strMoney - (1000 * strMoneyDiv));
  while (strMoneyDiv > 0 || strMoneyMod > 0)
  {
    if (strMoneyPare == 1001 )
	{
	  strFormattedMoney = "," + strFormattedMoney;
	}
    else
	{
      if (strMoneyPare < 100) {strFormattedMoney = "0" + strFormattedMoney};
      if (strMoneyPare < 10) {strFormattedMoney = "0" + strFormattedMoney};
      strFormattedMoney = "." + strFormattedMoney;
    }
    strFormattedMoney = strMoneyMod + strFormattedMoney;
    strMoney = strMoneyDiv;
    strMoneyPare = strMoneyMod;
    strMoneyDiv = Math.floor(strMoney / 1000);
    strMoneyMod = Math.floor(strMoney - (1000 * strMoneyDiv));
  }
  input.value = strFormattedMoney;
  return;
}

function MoneyToInteger(input)
{
  var strMoney, intMoneyLength, intIndex, strInteger;

  strMoney = new String(input);
  intIndex = 0;
  while (strMoney.substring(intIndex, intIndex+1) == '0') {intIndex++};

  intMoneyLength = strMoney.length;
  strMoney = strMoney.substring(intIndex, intMoneyLength);

  strInteger = new String("");
  for (intIndex=0; intIndex<intMoneyLength; intIndex++)
  {
    if (strMoney.substring(intIndex,intIndex+1) == ".") {continue};
    if (strMoney.substring(intIndex,intIndex+1) == ",") {break};
    strInteger += strMoney.substring(intIndex,intIndex+1);
  }

  if (strInteger.length == 0) {return 0};
  if (isNaN(strInteger))
  {
    return 0;
  }
  else
  {
    return parseInt(strInteger);
  }	
}

	
	
function pocisti(e,check){
	e.value = "";
	e.focus();
}


