//*****************************************************************************
// javascript
// ????????
// 
// isNaturalNumber()
// isIntegerNumber()
// parseNumber()
// rmFigure()
// addFigure()
// 
// 
// Copyright(c) 2008 by DYNACOM Co.,Ltd. All rights reserved.
//*****************************************************************************

var TinyNumberFormat = function (){
	//**********************************************************
	// constructor
	//**********************************************************
	//var locale = "en";
	//this.setLocale = function(_loc){
	//	this.locale = _loc;	
	//};
	
	//**********************************************************
	// check natural Number
	//**********************************************************
	this.isNaturalNumber = function(_str){
		var str = this.rmFigure(_str);
		
		var nnFlg = false;
		if(str.match(/^[1-9][0-9]*$/)){
			nnFlg = true;
		}
		return nnFlg;
	};
	//**********************************************************
	// check integer Number
	//**********************************************************
	this.isIntegerNumber = function(_str){
		var str = this.rmFigure(_str);
		
		var inFlg = false;
		if(str.match(/^-?[1-9][0-9]*$/)){
			inFlg = true;
		}
		return inFlg;
	};
	//**********************************************************
	// parse Number
	//**********************************************************
	this.parseNumber = function(_str){
		// remove figure
		var str = this.rmFigure(_str);
		
		return eval(str);
	};
	//**********************************************************
	// remove figure
	// 
	//**********************************************************
	this.rmFigure = function(_str){

		var str = "" + _str;

		return str.replace(/,/g, "");
	};
	//**********************************************************
	// add figure
	//**********************************************************
	this.addFigure = function(_str){

		var str = this.rmFigure(_str);
		
		//integer.fraction
		if(str.match(/^(-?[1-9]+[0-9]*)\.([0-9]*[1-9]+)$/)){
			var intprt = RegExp.$1;
			var frcprt = RegExp.$2;
			while(intprt != (intprt = intprt.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
			
			str = intprt + "." + frcprt;
		}
		// integer
		else if(str.match(/^(-?[1-9]+[0-9]*)$/)){
			while(str != (str = str.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
		}
		else {
			throw "Illegal format : '" + str + "'";
		}
		return str;
	};
};

