function activitiesCalculator(idContainerWeightInput,idContainerCalorieTimeInput,idSelectorBox,mode,defaultWeightSystem)
{
  this.defaultWeightGr = 68;
  this.defaultWeightLb = 150;
  //this.currentDefaultWeight = this.defaultWeightGr;
  this.koefLbToGr = 0.4536;
  this.defaultTime = 60;
  this.defaultCalorie = 200;
  this.currentMode = mode;
  if(this.currentMode=='time')
    this.currentDefaultCalorieTime = this.defaultTime;
  else
    this.currentDefaultCalorieTime = this.defaultCalorie;
  this.defaultWeightSystem = defaultWeightSystem;
  
  this.objContainerCalorieTime = document.getElementById(idContainerCalorieTimeInput);
  this.objContainerWeight = document.getElementById(idContainerWeightInput);
  
  this.objWeightInput = $('#'+idContainerWeightInput+' input')[0];
  
  //this.objWeightInput = document.createElement('input');
  //this.objContainerWeight.appendChild(this.objWeightInput);
  //this.objWeightInput.id = '_ac_weightInput';
  
  if(this.defaultWeightSystem==='SI')
  {
  	this.objWeightInput.value = this.defaultWeightGr;
  	this.currentDefaultWeight = this.defaultWeightGr;
  }
  else
  {
    this.objWeightInput.value = this.defaultWeightLb;
    this.currentDefaultWeight = this.defaultWeightLb;
  }
  $('#'+this.objWeightInput.id).bind('change',function(q){
                      return function(){
                            q.onChangeWeight();
                            }}(this)
                                           );
  
  this.objCalorieTimeInput = $('#'+idContainerCalorieTimeInput+' input')[0];
  
  //this.objCalorieTimeInput = document.createElement('input');
  //this.objContainerCalorieTime.appendChild(this.objCalorieTimeInput);
  //this.objCalorieTimeInput.id = '_ac_calorieTimeInput';
  
  if(this.currentMode=='time')
  {
    this.objCalorieTimeInput.value = this.defaultTime;
    $('#'+this.objCalorieTimeInput).bind('change',function(q){
                      return function(){
                            q.onChangeTime();
                            }}(this)
                                           );
  }
  else
  {
    this.objCalorieTimeInput.value = this.defaultCalorie;
    $('#'+this.objCalorieTimeInput.id).bind('change',function(q){
                      return function(){
                            q.onChangeCalorie();
                            }}(this)
                                           );
  }  
  
  /*this.unitSelectorBox = document.createElement('select');
  this.unitSelectorBox.id = '_ac_unitSelector';
  document.getElementById(idSelectorBox).appendChild(this.unitSelectorBox);
  var oOptions = new Array();
  oOptions[0] = document.createElement("OPTION");
  this.unitSelectorBox.options.add(oOptions[0]);
  oOptions[0].text='kg';
  oOptions[0].value=1;
  oOptions[1] = document.createElement("OPTION");
  this.unitSelectorBox.options.add(oOptions[1]);
  oOptions[1].text='lb';
  oOptions[1].value=2;*/
  
  if(this.defaultWeightSystem==='SI') {
    //this.unitSelectorBox.selectedIndex = '0';
    $("div.UnitsSelect").selectElement({index: '0'});
    
    
  } else {
    //this.unitSelectorBox.selectedIndex = '1';
    $("div.UnitsSelect").selectElement({index: '1'});
  }
    
    
  $("div.UnitsSelect").bind('OnItemChange', function(q){
                      return function(){
                              q.onChangeUnits();
                            }}(this)
                                           ); 
  
}

activitiesCalculator.prototype.getRatio = function()
{
  var koef1 = this.objCalorieTimeInput.value/this.currentDefaultCalorieTime;
  
  //var koef2 = this.objWeightInput.value/this.currentDefaultWeight;
  
  var iWeightInKilos = this.getCurrentWeightInKilos();
  var koef2 = iWeightInKilos/this.currentDefaultWeight;
  
  if(this.currentMode=='weight')
    var koef = koef1/koef2;
  else
    var koef = koef1*koef2;
    
  return koef;
}

activitiesCalculator.prototype.getCurrentWeight = function()
{
  return this.objWeightInput.value;
}

activitiesCalculator.prototype.getCurrentWeightInKilos = function() {

  oElement = $("div.UnitsSelect").getSelectedElement(); 
  sSelectedUnit = oElement.attr('field_value');  

  if(sSelectedUnit == 'kg') {
  
    return this.objWeightInput.value;
    
  } else {
  
    return Math.round(this.objWeightInput.value * this.koefLbToGr);
    
  }
    
}//This is a last punched card of getCurrentWeightInKilos function


activitiesCalculator.prototype.getCurrentUnit = function() {

  oElement = $("div.UnitsSelect").getSelectedElement(); 
  sSelectedUnit = oElement.attr('field_value');  
  
  if(sSelectedUnit == 'kg') {
  
    return 'kilo';
    
  } else {
  
    return 'pound';
    
  }

}//This is a last punched card of getCurrentUnit function


activitiesCalculator.prototype.getCurrentCalorieTime = function()
{
  
  //if(this.currentMode=='weight') {
    
    return this.processNumberValue(this.objCalorieTimeInput.value);
    
  //} else {   
  
    //return this.objCalorieTimeInput.value;
    
  //}
    
}

activitiesCalculator.prototype.onChangeTime = function()
{
  return true;
}

activitiesCalculator.prototype.onChangeCalorie = function()
{
  /*var koef1 = this.objCalorieTimeInput.value/this.currentDefaultCalorieTime;
  this.objWeightInput.value = Math.round(this.currentDefaultWeight*koef);*/
  return true;
}

activitiesCalculator.prototype.onChangeWeight = function()
{
  /*var koef = this.objWeightInput.value/this.currentDefaultWeight;
  this.objCalorieTimeInput.value = Math.round(this.currentDefaultCalorieTime*koef);*/
  return true;
}

activitiesCalculator.prototype.onChangeUnits = function() {

  oElement = $("div.UnitsSelect").getSelectedElement(); 
  sSelectedUnit = oElement.attr('field_value');  
  
  if(sSelectedUnit == 'kg') {
  
    this.objWeightInput.value = Math.round(this.objWeightInput.value*this.koefLbToGr);
    
  } else {
  
    this.objWeightInput.value = Math.round(this.objWeightInput.value/this.koefLbToGr);
    
  }
  
  return true;
  
}//This is a last punched card of onChangeUnits function

activitiesCalculator.prototype.attachHandlerToTimeCalorie = function(nameEvent,handler_)
{
  addEventHandler(this.objCalorieTimeInput,nameEvent,handler_);
}

activitiesCalculator.prototype.attachHandlerToWeight = function(nameEvent,handler_)
{
  addEventHandler(this.objWeightInput,nameEvent,handler_);
}

activitiesCalculator.prototype.attachHandlerToSelect = function(nameEvent,handler_)
{
  addEventHandler(this.unitSelectorBox,nameEvent,handler_);
}

activitiesCalculator.prototype.roundN=function(number,digit)
  {
      k = Math.pow(10,digit);
      number = number * k;
      number = Math.round(number);
      number = number/k;
      return number;
  }
  
activitiesCalculator.prototype.processNumberValue = 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'] = intValue;
    
  }
    
  //return res;
  return res['str'];
    
}//This is a last punched card of processNumberValue function
  
activitiesCalculator.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);
    
}//This is a last punched card of roundNumberByLong function


activitiesCalculator.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;

}//This is a last punched card of getFormatStr function 

  
