if (Calculators == undefined) {
	var Calculators = {};
}
if (Calculators.report == undefined) {
	Calculators.report = {};
}
Calculators.report.CreditCardReport = function CreditCardReport(loan){
	this.loan = loan;
	
	this.getBody = function() {
		var title = "What will it take to pay off my credit card balance?";
		var months = this.loan.getPayoffGoal();
		var goalPayment = this.loan.getPayoffMonthlyPayment(months);
		var header = goalPayment.formatted() + " per month could pay off your credit card " + months + " months";
		var openingParagraph = "To pay off your credit card balance of " + this.loan.getBalance().formatted() + 
			" in 24 months you need to pay " + goalPayment.formatted() + 
			" per month based on the information you entered. " + 
			"This includes your additional monthly purchases of " + this.loan.getMonthlyCharges().formatted() + 
			" and your major purchases. This assumes no additional charges such as late fees. " + 
			"If you keep your monthly payment at " + this.loan.getPayment().formatted() + 
			" it will take a long time to pay off this credit card.";
		
		var body = new Array();
        body.push("    <table>\n");
		// Current balance
        body.push("      <tr>\n");
        body.push("        <td><b>Current balance</b></td>\n");
        body.push("        <td>");
		body.push(this.loan.getBalance().formatted());
		body.push("</td>\n");
        body.push("      </tr>\n");
		// Additional monthly charges
        body.push("      <tr>\n");
        body.push("        <td><b>Future monthly charges</b></td>\n");
        body.push("        <td>");
		body.push(this.loan.getMonthlyCharges().formatted());
		body.push(" </td>\n");
        body.push("      </tr>\n");
		
		// Major purchase 1
		if (this.loan.getMajorPurchaseAmountOne().getAmount() > 0) {
			body.push("      <tr>\n");
			body.push("        <td><b>Major purchase 1</b></td>\n");
			body.push("        <td>");
			body.push(this.loan.getMajorPurchaseAmountOne().formatted() + " in " + this.loan.getMajorPurchaseMonthOne());
			body.push("</td>\n");
			body.push("      </tr>\n");
		}

		// Major purchase 2
		if (this.loan.getMajorPurchaseAmountTwo().getAmount() > 0) {
			body.push("      <tr>\n");
			body.push("        <td><b>Major purchase 2</b></td>\n");
			body.push("        <td>");
			body.push(this.loan.getMajorPurchaseAmountTwo().formatted() + " in " + this.loan.getMajorPurchaseMonthTwo());
			body.push("</td>\n");
			body.push("      </tr>\n");
		}

		// Annual fee
        body.push("      <tr>\n");
        body.push("        <td><b>Annual fee</b></td>\n");
        body.push("        <td>");
		body.push(this.loan.getAnnualFee().formatted());
		body.push("</td>\n");
        body.push("      </tr>\n");

		// Interest rate
        body.push("      <tr>\n");
        body.push("      <tr>\n");
        body.push("        <td><b>Interest rate</b></td>\n");
        body.push("        <td>");
		body.push(this.loan.getInterestRate().formatted());
		body.push("</td>\n");
        body.push("      </tr>\n");
		
        body.push("    </table>\n");
        body.push("    <hr size=\"1\" />\n");
        body.push("    <table width=\"100%\" cellspacing=\"0\">\n");
        body.push("      <tr>\n");
        body.push("        <td width=\"20%\"><b>Month</b></td>\n");
        body.push("        <td width=\"20%\"><b>Payment</b></td>\n");
        body.push("        <td width=\"20%\"><b>Interest</b></td>\n");
        body.push("        <td width=\"20%\"><b>Charges</b></td>\n");
        body.push("        <td width=\"20%\"><b>Balance</b></td>\n");
        body.push("      </tr>\n");

		var statements = payoff.getCurrentStatements();
        var end = statements.length;
		// Beginning balance row
        body.push("      <tr class=\"highlightStripe\">\n");
        body.push("        <td>&nbsp;</td>\n");
        body.push("        <td>&nbsp;</td>\n");
        body.push("        <td>&nbsp;</td>\n");
        body.push("        <td>&nbsp;</td>\n");
        body.push("        <td>" + statements[0].getBalance().formatted() + "</td>\n");
        body.push("      </tr>\n");
		
        for (var i = 1; i < end; ++i) {
            var monthly = statements[i];
            if (i % 2 == 1) {
                body.push("      <tr>\n");
            } else {
                body.push("      <tr class=\"highlightStripe\">\n");
            }
            body.push("        <td>");
			body.push(i);
			body.push("</td>\n");
            body.push("        <td>");
			body.push(monthly.getPayment().formatted());
			body.push("</td>\n");
            body.push("        <td>");
			body.push(monthly.getInterest().formatted());
			body.push("</td>\n");
            body.push("        <td>");
			body.push(monthly.getCharges().formatted());
			body.push("</td>\n");
            body.push("        <td>");
			body.push(monthly.getBalance().formatted());
			body.push("</td>\n");
            body.push("      </tr>\n");
        }

        body.push("    </table>\n");
		
        return body.join("");
	}
	
	this.getTitle = function() {
		return "Report";
	}
}
Calculators.report.CreditCardReport.prototype = new Calculators.report.Report();
