function calForm(){
  this.per = calForm.arguments[0];
  this.length = 0;

  if (calForm.arguments.length % 2 == 1){
     this.rates = new Array;
     var i=1; var j=0
     while(i < calForm.arguments.length){
       this.rates[j] = {value:0, mult:0};
       this.rates[j].value = calForm.arguments[i]; 
       this.rates[j].mult  = calForm.arguments[i+1];
       i++;i++;j++;
     }

     this.length = this.rates.length;

     this.charges = new Array();
     for(var i=0;i < this.length; i++){
       this.charges[i] = {rate:0, fee:0, mult:0};
       
       if(i==0){
         this.charges[i].rate = 0;
         this.charges[i].fee  = 0;
       }
       else{
         this.charges[i].rate = this.charges[i-1].rate + this.rates[i-1].value;
         this.charges[i].fee  = this.charges[i-1].fee  + (this.rates[i-1].value * this.rates[i-1].mult)/this.per;
       }
       
       this.charges[i].mult = this.rates[i].mult

       this.rating = toRate;
       this.feeing = toFee;
     }
  }
  else
    alert ("Error: the number of arguments must be odd!")
}

// to determine the rating value
function toRate(num){
  var rFlag = false; 
  var rIndex = this.length;

  while(!rFlag){
    rIndex--
    if (num > this.charges[rIndex].rate)
       rFlag = true 
  }
  
  return(rIndex)
}

// determine the fee
function toFee(num){
  rInd = this.rating(num); // determining the rating index

  basFee = this.charges[rInd].fee; // determining the basic fee due to rating index

  pNum  = num - this.charges[rInd].rate;
  pFee  = (pNum * this.charges[rInd].mult)/this.per;

  return (parseInt((basFee + pFee)*100)/100)
}
