function NumFormat(p_obj,p_decimal,p_group,p_decimalplaces)
 {
 if(isNumeric(p_obj.value,p_decimal,p_group ) && p_obj.value != "")
  {
  p_value = reformatValue(p_obj.value,p_decimal,p_group);
  if (p_value != "") p_obj.value = createSeparator(p_value, p_decimalplaces,p_decimal,p_group);
  }
 }

function removeChar(p_str, p_char)
 {
 var s1, s2, pos, len;
 len = p_str.length;
 pos = p_str.indexOf(p_char, 0);
 while(pos >= 0)
  {
  s1 = p_str.substring(0, pos);
  s2 = p_str.substring(pos+1, len+1);
  p_str = s1 + s2;
  len = p_str.length;
  pos = p_str.indexOf(p_char, 0);
  }
 return p_str;	
 }

function createSeparator(p_value, p_dec,p_decimal,p_group)
 {
 var neg = 0;
 var i = 0;
 var zs;
 var a, len;
 var z;
 if(p_value == "") p_value = 0;
 p_value = parseFloat(p_value);
 if (p_value < 0)
  {
  neg = -1;
  p_value *= -1;
  }
 else neg = 1;
 if(p_dec > 0)
  {
  p_value *= Math.pow(10,p_dec);
  }
 var z;
 z = parseFloat(Math.round(p_value));
 z = Math.floor(z);
 if(p_dec > 0)
  {
  z /= Math.pow(10,p_dec);
  }
 zs = z.toString();
 if(zs.indexOf('.', 0) >= 0)
  {
  a = zs.split(".");
  if(a[0].length == 0) a[0] = "0";
  while(a[1].length < p_dec)
	 {
   a[1] += "0";
   }
  if(p_dec > 0)
   {
 	 zs = a[0] + p_decimal + a[1];
   }
  else
   {
   zs = a[0];
   }
  }
 else
  {
  if(p_dec > 0)
	 {
   zs += p_decimal;
   for (i=0; i < p_dec; i++)
	  {
    zs += "0";
    }
   }
  }
 len = zs.length;
 pos = zs.indexOf(p_decimal, 0);
 if (pos < 0) pos = len;
 pos -= 3;
 while(pos > 0)
  {
  s1 = zs.substring( 0, pos );
  s2 = zs.substring( pos, len+1 );
  zs = s1 + p_group + s2;
  len = zs.length;
  pos -= 3;
  }
 if(neg < 0) zs = "-" + zs;
 return zs;	
 }

function isNumeric (p_value, p_decimal, p_group)
 {
 var res = false;
 var val = p_value;
 for (var i = 0; i < val.length;i++)
  {
  if(val.substr(i,1).match(/\d/)) res = true;
  else if (val.substr(i,1) == p_decimal) res = true;
  else if (val.substr(i,1) == p_group)   res = true;
  else if (val.substr(i,1) == "-")       res = true;
  else res = false;
  if(!res) return false;
  }
 return true;
 }

function reformatValue(p_value,p_decimal,p_group)
 {
 var v_items ="-1234567890,.";
 var v_help = p_value.toString();
 var len = v_help.length;
 var pos;
 if(v_help == p_group || v_help == p_decimal) v_help = "0";
 v_help = removeChar(v_help, " ");
 pos = v_help.indexOf(p_group, 0);
 while(pos > 0)
  {
  s1     = v_help.substring(0, pos);
  s2     = v_help.substring(pos+1, len+1);
  v_help = s1 + s2;
  len    = v_help.length;
  pos    = v_help.indexOf(p_group, 0);
  }
 pos = v_help.indexOf(p_decimal, 0);
 if (pos == 0)
  {
  v_help = "0" + v_help;
  pos = v_help.indexOf( p_decimal, 0 );
  }
 if(pos > 0)
  {
  s1 = v_help.substring(0, pos);
  s2 = v_help.substring(pos+1, len+1);
  v_help = s1 + '.' + s2;
  x = parseFloat(v_help);
  }
 else x = parseFloat(v_help);
 return x;
 }