function cccalc()
{
  var ccbalance = document.getElementById('ccbalance').value;
  var ccrate = document.getElementById('ccrate').value;
  var ccmonthly = document.getElementById('ccmonthly').value;
  var ccdesired = document.getElementById('ccdesired').value;
  
  if (ccbalance == '')
  {
    alert('Please enter your credit card balance.'); 
    return;
  }
  
  if (ccrate == '')
  {
    alert('Please enter your credit cards interest rate.');
    return;
  }
  
  if (ccmonthly == '' && ccdesired == '')
  {
    alert('Please enter either a payment amount or desired months.');
    return;
  }
  
  var mrate = (ccrate / 100) / 12;

  if (ccmonthly == '')
  {
    var payment=ccbalance*(mrate)/( 1-Math.pow((1+mrate),(-ccdesired)) );
    payment=Math.round(payment*100)/100;
    document.getElementById('ccresult').innerHTML="<p>It will cost $" + payment.toFixed(2) + " a month to pay off this card and will cost you a total of $" + (payment*ccdesired).toFixed(2) + ".</p>";
  } 
  else 
  {
    var remainingBalance=ccbalance;
    var minPayment=mrate*ccbalance;
    var months=0;
    var lastPayment;
    if (minPayment>ccmonthly) {alert ('Your monthly payment is less than the monthly interest charged by this card.');return;}
    while (remainingBalance>0)
    {
      months++;
      remainingBalance=remainingBalance*(1 + mrate)-ccmonthly;
    }
    document.getElementById('ccresult').innerHTML="<p>It will take " + months + " months to pay off this card and will cost you a total of $" + (ccmonthly*months).toFixed(2) + ".</p>";
  }  
}
