/*в конструктор класса нужно передать 4 параметра:
  1) idDivContainer - id дива, в котором будет создаваться калькулятор;
  2) servingSizesArray - массив serving sizes, каждый элемент которого представляет собой один serving size и содержит два элемента - ['title'] - название serving size и ['ratio'] - кол-во грамм в этом serving size.
  3) unit - передать serving size, который будет по умолчанию, например, g или oz;
  4)startValueWeight - вес еды для 200 калорий, должен быть в граммах!!!
  
  
  a properties that contains spans:
  1)this.objSpanBeforeWeight - it is DOM object - span. span contains text that will be shown before weight's input
  1)this.objSpanAfterWeight - it is DOM object - span. span contains text that will be shown after weight's input
  1)this.objSpanBeforeCalorie - it is DOM object - span. span contains text that will be shown before calorie's input
  1)this.objSpanAfterCalorie - it is DOM object - span. span contains text that will be shown after calorie's input
*/





//function Calorie(idDivContainer,servingSizesArray,unit,startValueWeight)
function Calorie(inputStr)  
{
	///processing input array
	
	var inputArray = new Array();
  inputArray = eval(inputStr);
	servingSizesArray = inputArray[0]['servingSizes'];
	idDivContainer = inputArray[0]['id_container'];
	calcuatorContainer = document.getElementById(idDivContainer);
	unit = inputArray[0]['unit'];
	startValueWeight = inputArray[0]['startValueWeight'];
	this.startValueWeightInGr = inputArray[0]['weightIn200CInGr'];
	this.liquid = parseInt(inputArray[0]['liquid']);	
	/////end
	
	
	this.amountTimeoutId = null;
	this.calorieTimeoutId = null;
	
	var inputObjects = calcuatorContainer.getElementsByTagName('input');
	var spanObjects = calcuatorContainer.getElementsByTagName('span');
	var tableObjects = calcuatorContainer.getElementsByTagName('table');
	var selectObjects = calcuatorContainer.getElementsByTagName('select');
	
  this.currentRatio = 1;
  this.oldRatio = 1;
  this.defaultAmount = startValueWeight;
  this.defaultCalorie = 200;
	

  var table = tableObjects[0];
  table.id = idDivContainer+'calorie_table';
   //$('#'+idDivContainer).append(table);
  //var tr = document.createElement('tr');
  //$('#'+table.id).append(tr);
  //var td_orig = document.createElement('td');
  //var td = td_orig.cloneNode(true);
  //$('#'+table.id+' tr').append(td);
  //td.id = idDivContainer+'calorie_td1';
  //this.span_exmpl = document.createElement('span');
  this.idInputAmount = 'idInputAmount_'+idDivContainer;
  this.idInputCalorie = 'idInputCalorie_'+idDivContainer;
  
  
  //this.objInputAmount = document.createElement('input');      //inputAmount
  
  this.objSpanBeforeWeight = spanObjects[1];
  this.objSpanBeforeWeight.id = 'span_before_weight'+idDivContainer;
  
  //$('#'+td.id).append(this.objSpanBeforeWeight);
  //td = td_orig.cloneNode(true);
  //tr.appendChild(td);
  //td.id = idDivContainer+'calorie_td2';
  //$('#'+td.id).append(this.objInputAmount);          //inputAmount
  
  //this.objSpanAfterWeight = this.span_exmpl.cloneNode(true);
  this.objSpanAfterWeight = spanObjects[2];
  
  this.objSpanAfterWeight.id = 'span_after_weight'+idDivContainer;
  

  this.objInputAmount = inputObjects[0];
  //td.appendChild(this.objInputAmount);
  
  
  
  //td = td_orig.cloneNode(true);
  //tr.appendChild(td);
  //td.id = idDivContainer+'calorie_td3';
  //$('#'+td.id).append(this.objSpanAfterWeight);
  
  
  this.objInputAmount.id = this.idInputAmount;
  
  this.objInputAmount.name = 'inputAmount[]';  
  //$('#'+this.idInputAmount).css({width:60});
  this.objInputAmount.value = startValueWeight;/*
  var handler_ = function(obj){return function(){ obj.onBlurInputAmount(obj) } }(this);
  	  $('#'+this.idInputAmount).bind('change',handler_);
  
  $('#'+this.idInputAmount).bind('keyup',function(q){
    return function(){
          q.onChangeAmount();
          }}(this)
                                           );*/
  
  //this.select = selectObjects[0];
  var parNodeSelect = selectObjects[0].parentNode;
  parNodeSelect.removeChild(selectObjects[0]);
  this.select = document.createElement('select');
  parNodeSelect.appendChild(this.select);
  this.select.id = 'select_'+idDivContainer;
  this.select.name = 'selectUnit[]';
  //td = td_orig.cloneNode(true);
  //tr.appendChild(td);
  //td.id = idDivContainer+'calorie_td4';
  //td.style.width = "70%";
  //$('#'+td.id).append(this.select);
  this.makeSelect(servingSizesArray);
  
  
  $('#'+this.select.id).bind('change',function(q){
                      return function(){
                            q.onChangeUnits();
                            }}(this)
                                           );
  

  
//  var tr = document.createElement('tr');
 // $('#'+table.id).append(tr);
  
  //td = td_orig.cloneNode(true);
  //td.colSpan = '4';
  //td.style.textAlign = "center";
  //tr.appendChild(td);
  //td.id = idDivContainer+'calorie_td55';
  
  var tableTr2 = tableObjects[1];
  //td.appendChild(tableTr2);
  //var tbody = document.createElement('tbody');
  //tableTr2.appendChild(tbody);
  //tr =  document.createElement('tr');
  //tbody.appendChild(tr);
  this.objSpanBeforeCalorie = spanObjects[3];
  this.objSpanBeforeCalorie.id = 'span_before_calorie'+idDivContainer;
  //td = td_orig.cloneNode(true);
  //tr.appendChild(td);
  //td.id = idDivContainer+'calorie_td5';
  //td.style.verticalAlign = 'middle';
  //td.style.textAlign = 'right';
  //td.style.width = '50%';
  
  //$('#'+td.id).append(this.objSpanBeforeCalorie);
  this.objSpanBeforeCalorie.style.fontWeight = 'bold';
  this.objSpanBeforeCalorie.innerHTML = ' = ';
  /*td = td_orig.cloneNode(true);
  
  tr.appendChild(td);
  td.id = idDivContainer+'calorie_td6';*/
  
  
  this.objInputCalorie = inputObjects[1];
  //td.appendChild(this.objInputCalorie);
  this.objInputCalorie.id = this.idInputCalorie; 
  this.objInputCalorie.name = 'inputCalorie[]';
  if( this.defaultAmount==0) 
  {
  	this.objInputCalorie.readOnly = true;
  	this.objInputCalorie.value = 'ZERO';
  }else this.objInputCalorie.value = '200'
  /*
  var handler_ = function(obj){return function(){ obj.onBlurInputCalorie(obj) } }(this);
  	  $('#'+this.idInputCalorie).bind('change',handler_);*/
  
  /*
  $('#'+this.idInputAmount).bind('keyup',function(q){
    return function(){
          q.onChangeAmount();
          }}(this)
                                           );*/
  
  //$('#'+td.id).append(this.objInputCalorie);
  this.objSpanAfterCalorie = spanObjects[4];
  this.objSpanAfterCalorie.id = 'span_after_weight'+idDivContainer;
  this.objSpanAfterCalorie.style.fontWeight = 'bold';
  this.objSpanAfterCalorie.innerHTML = ' Calories';
  
  //$('#'+td.id).append(this.objSpanAfterCalorie);
 /* 
  $('#'+this.idInputCalorie).bind('keyup',function(q){
                                    return function(){
                                          q.onChangeCalories();
                                          }}(this)
                                                         );*/

  this.bindEventHandlers();
  this.setCurrentUnit(unit);
  if(this.liquid==1) this.setLiquid(this.startValueWeightInGr);
  
  //this.createDesignInput(this.objInputAmount.parentNode);
  
  var handlerForSelect = function(obj){return function() {obj.onChangeUnitsProgrammatically(obj)}}(this);
     
     var dsgSelect = new DesignSelectObject(this.select.id,inputArray[0]['shortName'],handlerForSelect);
     var dsgInputAmount = new CustomizeInput(this.objInputAmount.id,0);
     var dsgInputAmount = new CustomizeInput(this.objInputCalorie.id,0);
  
}


/*
function Calorie(inputStr)    //this function create body of calculator
{
	///processing input array
	
	var inputArray = new Array();
  inputArray = eval(inputStr);
	servingSizesArray = inputArray[0]['servingSizes'];
	idDivContainer = inputArray[0]['id_container'];
	unit = inputArray[0]['unit'];
	startValueWeight = inputArray[0]['startValueWeight'];
	this.startValueWeightInGr = inputArray[0]['weightIn200CInGr'];
	this.liquid = parseInt(inputArray[0]['liquid']);	
	/////end
	
	
	
  this.currentRatio = 1;
  this.oldRatio = 1;
  this.defaultAmount = startValueWeight;
  this.defaultCalorie = 200;
	

  var table = document.createElement('table');
  table.id = idDivContainer+'calorie_table';
   $('#'+idDivContainer).append(table);
  var tr = document.createElement('tr');
  $('#'+table.id).append(tr);
  var td_orig = document.createElement('td');
  var td = td_orig.cloneNode(true);
  $('#'+table.id+' tr').append(td);
  td.id = idDivContainer+'calorie_td1';
  this.span_exmpl = document.createElement('span');
  this.idInputAmount = 'idInputAmount_'+idDivContainer;
  this.idInputCalorie = 'idInputCalorie_'+idDivContainer;
  
  
  //this.objInputAmount = document.createElement('input');      //inputAmount
  
  this.objSpanBeforeWeight = this.span_exmpl.cloneNode(true);
  this.objSpanBeforeWeight.id = 'span_before_weight'+idDivContainer;
  
  $('#'+td.id).append(this.objSpanBeforeWeight);
  td = td_orig.cloneNode(true);
  tr.appendChild(td);
  td.id = idDivContainer+'calorie_td2';
  //$('#'+td.id).append(this.objInputAmount);          //inputAmount
  this.objSpanAfterWeight = this.span_exmpl.cloneNode(true);
  this.objSpanAfterWeight.id = 'span_after_weight'+idDivContainer;
  
  //this.createDesignInput(td);
  this.objInputAmount = document.createElement('input');
  td.appendChild(this.objInputAmount);
  
  
  
  td = td_orig.cloneNode(true);
  tr.appendChild(td);
  td.id = idDivContainer+'calorie_td3';
  $('#'+td.id).append(this.objSpanAfterWeight);
  
  
  this.objInputAmount.id = this.idInputAmount;
  
  this.objInputAmount.name = 'inputAmount[]';  
  //$('#'+this.idInputAmount).css({width:60});
  this.objInputAmount.value = startValueWeight;
  var handler_ = function(obj){return function(){ obj.onBlurInputAmount(obj) } }(this);
  	  $('#'+this.idInputAmount).bind('change',handler_);
  
  $('#'+this.idInputAmount).bind('keyup',function(q){
    return function(){
          q.onChangeAmount();
          }}(this)
                                           );
  
  this.select = document.createElement('select');
  this.select.id = 'select_'+idDivContainer;
  this.select.name = 'selectUnit[]';
  td = td_orig.cloneNode(true);
  tr.appendChild(td);
  td.id = idDivContainer+'calorie_td4';
  td.style.width = "70%";
  $('#'+td.id).append(this.select);
  this.makeSelect(servingSizesArray);
  
  
  $('#'+this.select.id).bind('change',function(q){
                      return function(){
                            q.onChangeUnits();
                            }}(this)
                                           );
  
  //this.objInputCalorie = document.createElement('input');
  
  var tr = document.createElement('tr');
  $('#'+table.id).append(tr);
  
  td = td_orig.cloneNode(true);
  td.colSpan = '4';
  td.style.textAlign = "center";
  tr.appendChild(td);
  td.id = idDivContainer+'calorie_td55';
  
  var tableTr2 = document.createElement('table');
  td.appendChild(tableTr2);
  var tbody = document.createElement('tbody');
  tableTr2.appendChild(tbody);
  tr =  document.createElement('tr');
  tbody.appendChild(tr);
  this.objSpanBeforeCalorie = this.span_exmpl.cloneNode(true);
  this.objSpanBeforeCalorie.id = 'span_before_calorie'+idDivContainer;
  td = td_orig.cloneNode(true);
  tr.appendChild(td);
  td.id = idDivContainer+'calorie_td5';
  td.style.verticalAlign = 'middle';
  td.style.textAlign = 'right';
  td.style.width = '50%';
  
  $('#'+td.id).append(this.objSpanBeforeCalorie);
  this.objSpanBeforeCalorie.style.fontWeight = 'bold';
  this.objSpanBeforeCalorie.innerHTML = ' = ';
 
  
  //this.createDesignInputCalorie(td);
  this.objInputCalorie = document.createElement('input');
  td.appendChild(this.objInputCalorie);
  this.objInputCalorie.id = this.idInputCalorie; 
  this.objInputCalorie.name = 'inputCalorie[]';
  if( this.defaultAmount==0) 
  {
  	this.objInputCalorie.readOnly = true;
  	this.objInputCalorie.value = 'ZERO';
  }else this.objInputCalorie.value = '200'
  
  
  $('#'+this.idInputAmount).bind('keyup',function(q){
    return function(){
          q.onChangeAmount();
          }}(this)
                                           );
  
  //$('#'+td.id).append(this.objInputCalorie);
  this.objSpanAfterCalorie = this.span_exmpl.cloneNode(true);
  this.objSpanAfterCalorie.id = 'span_after_weight'+idDivContainer;
  this.objSpanAfterCalorie.style.fontWeight = 'bold';
  this.objSpanAfterCalorie.innerHTML = ' Calories';
  
  $('#'+td.id).append(this.objSpanAfterCalorie);
  //$('#'+this.idInputCalorie).css({width:60});
  $('#'+this.idInputCalorie).bind('keyup',function(q){
                                    return function(){
                                          q.onChangeCalories();
                                          }}(this)
                                                         );


  this.setCurrentUnit(unit);
  if(this.liquid==1) this.setLiquid(this.startValueWeightInGr);
  
  //this.createDesignInput(this.objInputAmount.parentNode);
}*/
 


Calorie.prototype.roundNumberByLong = function(number)
  {
  	number = number * 1;
  	if(number<1)
  	return this.roundN(number,3);
  	if(number>=1&&number<10)
  	return this.roundN(number,2);
  	if(number>=10&&number<100)
  	return this.roundN(number,1);
  	if(number>=100)
  	return this.roundN(number,0);
  }

  
  Calorie.prototype.bindEventHandlers = function()
  {
     var handler_ = function(obj){return function(){ 
     	if(obj.amountTimeoutId!==null)
        clearTimeout(obj.amountTimeoutId);
     	obj.amountTimeoutId = setTimeout(function(){
     		return function(){obj.onBlurInputAmount(obj),250;}
     	}(obj));
     }}(this);
     	
  	 $('#'+this.idInputAmount).bind('keyup',handler_);
  /*
  		$('#'+this.idInputAmount).bind('keyup',function(q){
    	return function(){
          q.onChangeAmount();
          }}(this));*/
  /*
      $('#'+this.idInputCalorie).bind('keyup',function(q){
                                    return function(){
                                    			if(q.calorieTimeoutId!==null)
                                    			clearTimeout(q.calorieTimeoutId);
                                          q.calorieTimeoutId = setTimeout(function(){
     																					return function(){q.onChangeCalories(),250;}
                                          }(q));
                                          }}(this));*/
     $('#'+this.idInputCalorie).bind('keyup',function(q){
                                    return function(){
                                    			if(q.calorieTimeoutId!==null)
                                    			clearTimeout(q.calorieTimeoutId);
                                          q.calorieTimeoutId = setTimeout(function(){
     																					return function(){q.onBlurInputCalorie(q),250;}
                                          }(q));
                                          }}(this));
  

  }
     
Calorie.prototype.onBlurInputAmount = function(obj)
{/*
  var onChangeEvent = this.onChangeInputCalorieHandler['handler_'];
  onChangeEvent();*/
	var amountIntStr = obj.processInputAmountValue(obj.objInputAmount.value);
	obj.objInputAmount.value = amountIntStr['str'];
	obj.onChangeAmount();
	return amountIntStr;
}



Calorie.prototype.onBlurInputCalorie = function(obj)
{/*
	var onChangeEvent = this.onChangeInputAmountHandler['handler_'];
	onChangeEvent();*/
	var calorieIntStr = obj.processInputAmountValue(obj.objInputCalorie.value);
	obj.objInputCalorie.value = calorieIntStr['str'];
	obj.onChangeCalories();
	return calorieIntStr;
}


Calorie.prototype.onBlurSelect = function()
{
	document.getElementById('_designSelectObject_dropDownListTable').display = 'none';
}


Calorie.prototype.setLiquid = function(startValueWeightInGr)
{
  this.koefMlToGr = startValueWeightInGr/this.defaultAmount;
  this.koefFOzToGr = this.koefMlToGr*29.573549;
}


Calorie.prototype.getKoef = function()
{
  return this.objInputCalorie/this.defaultCalorie;
}

Calorie.prototype.setCurrentUnit = function(unit)
{
  for(var key in this.oOptions)
  {
    if(this.oOptions[key].getAttribute('unit')==unit)
    {
    	var optionIndex = this.oOptions[key].index;
      this.select.selectedIndex = this.oOptions[key].index;
      this.onChangeUnits();
      return true;
    }
  }
}

Calorie.prototype.getAmountInGr = function()
{
  var reg = /[^0-9\.]/g;
	var value = this.objInputAmount.value.replace(reg, "");
  var res = value*this.currentRatio;
  if(this.liquid==1) res = res * this.koefMlToGr;
  return res;
}


Calorie.prototype.attachHandlerToCalorie = function(nameEvent,handler_)
{
  //addEventHandler(this.objInputCalorie,nameEvent,handler_);
  this.onChangeInputCalorieHandler = new Array();
  this.onChangeInputCalorieHandler['nameEvent'] = nameEvent;
  this.onChangeInputCalorieHandler['handler_'] = handler_;
}

Calorie.prototype.attachHandlerToAmount = function(nameEvent,handler_)
{
	//var iid = addEventHandler(this.objInputAmount,nameEvent,handler_);
	this.onChangeInputAmountHandler = new Array();
  this.onChangeInputAmountHandler['nameEvent'] = nameEvent;
  this.onChangeInputAmountHandler['handler_'] = handler_;
}

Calorie.prototype.attachHandlerToSelect = function(nameEvent,handler_)
{
  addEventHandler(this.select,nameEvent,handler_);
}

Calorie.prototype.makeSelect = function(masOption)
{
  this.oOptions = new Array();
  var i=0;
  for(var key in masOption)
  {
    this.oOptions[key] = document.createElement("OPTION");
    this.select.options.add(this.oOptions[key]);
    this.oOptions[key].innerText=masOption[key]['title'];
    this.oOptions[key].text=masOption[key]['title'];

    this.oOptions[key].value=masOption[key]['title'];
    this.oOptions[key].setAttribute("unit", masOption[key]['title']);
    this.oOptions[key].setAttribute("ratio", masOption[key]['ratio']); 
    i++;
  }
}


Calorie.prototype.onChangeUnits = function()
{
   this.currentRatio = this.select.options[this.select.selectedIndex].getAttribute('ratio');
   var doc = document;
   var curAmountInGr = this.objInputAmount.value*this.oldRatio;
   var finishValue = curAmountInGr/this.currentRatio;

    /* if (this.select.options[this.select.selectedIndex].getAttribute('unit')=="g")
     {
       finishValue = this.roundN(finishValue,0);
     } else{
       if (this.select.options[this.select.selectedIndex].getAttribute('unit')=="oz")
       {
          finishValue = this.roundN(finishValue,2);
          
       } else 
       {
         finishValue = this.roundN(finishValue,2);
         
       }
     }*/
	   amountIntStr = this.processInpAmountToStr(finishValue);
     document.getElementById(this.idInputAmount).value = amountIntStr;
     this.oldRatio = this.currentRatio;
}

Calorie.prototype.onChangeUnitsProgrammatically = function(selectObject)
{
   selectObject.currentRatio = selectObject.select.options[selectObject.select.selectedIndex].getAttribute('ratio');
   var doc = document;
   var reg = /[^0-9\.]/g;
	this.objInputAmount.value = this.objInputAmount.value.replace(reg, "");
   var curAmountInGr = selectObject.objInputAmount.value*selectObject.oldRatio;
   var finishValue = curAmountInGr/selectObject.currentRatio;
/*
     if (selectObject.select.options[selectObject.select.selectedIndex].getAttribute('unit')=="g")
     {
       finishValue = selectObject.roundN(finishValue,0);
     } else{
       if (this.select.options[selectObject.select.selectedIndex].getAttribute('unit')=="oz")
       {
          finishValue = selectObject.roundN(finishValue,2);
          
       } else 
       {
         finishValue = selectObject.roundN(finishValue,2);
         
       }
     }*/
     document.getElementById(selectObject.idInputAmount).value = this.processInpAmountToStr(finishValue);
     selectObject.oldRatio = selectObject.currentRatio;
}


Calorie.prototype.roundN = function(number,digit)
{
    k = Math.pow(10,digit);
    number = number * k;
    number = Math.round(number);
    number = number/k;
    return number;
}

Calorie.prototype.onChangeCalories = function()
{

	var reg = /[^0-9\.]/g;
	var amountValue = this.objInputAmount.value.replace(reg, "");
	var calorieValue = this.objInputCalorie.value.replace(reg, "");
  this.currentRatio = this.select.options[this.select.selectedIndex].getAttribute('ratio');
   var curAmountInGr = amountValue*this.currentRatio;
   var koefCalorie = calorieValue/this.defaultCalorie;
   var finishValueInGr = this.defaultAmount*koefCalorie;
   var finishValue = finishValueInGr/this.currentRatio;
    /* if (this.select.options[this.select.selectedIndex].getAttribute('unit')=="g")
     {
       finishValue = this.roundN(finishValue,0);
     } else{
       if (this.select.options[this.select.selectedIndex].getAttribute('unit')=="oz")
       {
          finishValue = Math.round(finishValue);
          
       } else 
       {
         finishValue = Math.round(finishValue);
         
       }
     }*/
    this.objInputAmount.value = this.processInpAmountToStr(finishValue);
    var onChangeEvent = this.onChangeInputCalorieHandler['handler_'];
    if(typeof(onChangeEvent)==='function')
  	onChangeEvent();
    
   
}


Calorie.prototype.onChangeAmount = function(event)
{
  var reg = /[^0-9\.]/g;
	var value = this.objInputAmount.value.replace(reg, "");
	
  this.currentRatio = this.select.options[this.select.selectedIndex].getAttribute('ratio');
   var curAmountInGr = value*this.currentRatio;
   
   if( this.defaultAmount!==0) 
   {
	   var koefAmount = curAmountInGr/this.defaultAmount;
	   var finishValue = this.defaultCalorie*koefAmount;
	   this.objInputCalorie.value = this.processInpAmountToStr(finishValue);
   }else
   {
   	 var koefAmount = curAmountInGr/100;
   }
   /*
   if (this.select.options[this.select.selectedIndex].getAttribute('unit')=="g")
   {
     finishValue =Math.round(finishValue)
   } else finishValue = Math.round(finishValue);*/
   var onChangeEvent = this.onChangeInputAmountHandler['handler_'];
   if(typeof(onChangeEvent)==='function')
	 onChangeEvent();
   
}


Calorie.prototype.processInputAmountValue = function(value)
{
	var res = new Array();
	var reg = /[^0-9\.]/g;
	value = value.replace(reg, "");
	value = this.roundNumberByLong(value);
	var reg=/([0-9,]+)((\.)(\d+))?/; 
	var arr=reg.exec(value);
  var intValue = arr[1];
  res['int'] = intValue; 
      if(arr[3]!==undefined&&arr[3]!=='')
      {
      	
              var str_ = this.getFormatStr(arr[1]);
			      	res['str'] = str_+'.'+arr[4];
			      	res['int'] = arr[1]+'.'+arr[4];
      }
				  	else
				  	{
				  		res['str'] = this.getFormatStr(intValue);
				  		//res['int'] = arr[1];
				  		res['int'] = intValue;
				  	}
	
	return res;
	
}

Calorie.prototype.getFormatStr = function(s)
{
 s = s+'';
if(s.length>3)
{
	var ls= s.length;
	var resStr = '';
	
	for (var i=0; i<ls; i++)
	
	{ 
		var h=s.charAt(i);
		if(i==ls-3)
		resStr = resStr + ',';
	  resStr = resStr + h;
	}
}
else{resStr=s}
return resStr;

} 

Calorie.prototype.processInpAmountToStr = function(value)
{
	value = this.roundNumberByLong(value);
  var reg=/([0-9,]+)((\.)(\d+))?/; 
	var arr=reg.exec(value);
	
	var intValue = this.getFormatStr(arr[1]);
	if(arr[3]!==undefined&&arr[3]!=='')
     	var res = intValue+'.'+arr[4];
	else
			var res = intValue;
	return res;

}
