 (function(){
 if(document.comparisoncalculator.creditcardbalance) {
  document.comparisoncalculator.creditcardbalance.focus();
 }
});

 function number_format( number, decimals, decpoint, thousandsep ) {

  var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;

  var d = decpoint == undefined ? "," : decpoint;

  var t = thousandsep == undefined ? "." : thousandsep, s = n < 0 ? "-" : "";

  var i = parseInt(n = Math.abs(+n || 0).tofix(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;

   

  return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).tofix(c).slice(2) : "");

  }


function comparableinterest(b,int1,m)
{
  i=((int1/100)/12)+1;
  newbal=b;
  for (p = 0; p < m; ++p){
  newbal*=i;
  }
  return newbal;
}

function creditcardcomparison()
{
 period = document.comparisoncalculator.period.value;
  balance = document.comparisoncalculator.creditcardbalance.value;
  an1 = comparableinterest(balance,document.comparisoncalculator.existingcardinterest.value,period);
  an2 = comparableinterest(balance,document.comparisoncalculator.newcardinterest.value,period);
  fan = an1-an2;
  document.comparisoncalculator.interestsaved.value = Math.round(fan*100)/100;
}
