// Set the rate card globally so it can be referenced in the webform formula fields
var gRateCard = drupalSettings.currentAccountCashback.rateCard;

function calculateInterestsss(productType, accountBalance, rateCard) {

  // Read in the ranges for the product type
  var aerRanges = rateCard[productType].ranges;

  // Sanitize the values
  for(var row in aerRanges) {
    
    aerRanges[row].min = parseFloat(aerRanges[row].min);
    aerRanges[row].max = parseFloat(aerRanges[row].max);
    aerRanges[row].val = parseFloat(aerRanges[row].val);
	   
    if(isNaN(aerRanges[row].max)) {
      aerRanges[row].max = 9999999999;
    }
  }

  // Find the interest rate for the account balance
  var percent = 0;

  for(var row in aerRanges) {
    if(accountBalance >= aerRanges[row].min && accountBalance <= aerRanges[row].max) {
      percent = aerRanges[row].val;
    }
  }

  // Return the monthly interest
  return (accountBalance * (percent / 100)) /12 ;
}