function periodComissionObj_toString()
{
   return this.tmp.toString() + ' - (' + this.period_fix + this.code+  ' за каждые '+this.period+this.code+' сверх '+this.from_amount+this.code+' ) ';
}

function periodComissionObj_afterComission(inval,last_comm)
{
   tmpinval = this.tmp.afterComission(inval,last_comm);
   if (inval >= this.from_amount && (this.to_amount == 0 || this.to_amount <= inval))
   {
       delta = Math.ceil((inval - this.from_amount)/this.period) * this.period_fix;
   }
   if (tmpinval - delta > 0) return tmpinval - delta; else return 0;
}

function periodComissionObj_reverseComission(outval)
{
   if (this.perc >= 1) return 0;
   delta = Math.ceil((outval - this.from_amount)/this.period)* this.period_fix;
   res = (outval + this.fix + delta) / (1 - this.perc);
   return res;
}

function periodComissionObj(code, from_amount, to_amount, perc, fix, min, max, period, period_fix)
{
   this.code        = code; 
   this.from_amount = from_amount;
   this.to_amount   = to_amount;
   this.perc        = perc;
   this.fix         = fix;
   this.min         = min;
   this.max         = max;

   this.period_fix  = period_fix;
   this.period      = period;

   this.tmp = new comissionObj(this.code, this.from_amount, this.to_amount, this.perc, this.fix, this.min, this.max);

   this.error       = '';

   //this.toString    = periodComissionObj_toString;
   this.afterComission = periodComissionObj_afterComission;
   this.reverseComission = periodComissionObj_reverseComission;
   this.hasError    = comissionObj_hasError;
   this.getError    = comissionObj_getError;
   return this;
}