if (Calculators == undefined) {
	var Calculators = {};
}
if (Calculators.report == undefined) {
	Calculators.report = {};
}
Calculators.report.RegularVersusRothIRAReport = function RegularVersusRothIRAReport(regularIRA, rothIRA){
	this.regularIRA = regularIRA;
	this.rothIRA = rothIRA;
	
	this.REGULAR_IRA_COLUMN = 2;
	this.ROTH_IRA_COLUMN = 3;
	this.BOTH_COLUMNS = 4;
	
	this.addReportSectionSeperator = function(body) {
		body.push("  <tr>\n");
		body.push("    <td colspan=\"3\" class=\"report_section_separator\">");
		body.push("      <span >&nbsp;</span>");
		body.push("    </td>\n");
		body.push("  </tr>\n");
	}
	
	this.addTotalLine = function(body, column) {
		body.push("  <tr>\n");
		body.push("    <td width=\"50%\">&nbsp;</span></td>\n");
		if (column == this.REGULAR_IRA_COLUMN) {
			body.push("    <td width=\"10%\" class=\"report_section_separator\">&nbsp;</td>\n");
			body.push("    <td width=\"10%\" >&nbsp;</td>\n");
		}
		else if (column == this.ROTH_IRA_COLUMN) {
			body.push("    <td width=\"10%\" >&nbsp;</td>\n");
			body.push("    <td width=\"10%\" class=\"report_section_separator\">&nbsp;</td>\n");
		}
		else { // assume (column == this.BOTH_COLUMNS)
			body.push("    <td colspan=\"2\" class=\"report_section_separator\">&nbsp;</td>\n");
		}
		body.push("  </tr>\n");
	}
	
	this.addReportSectionHeading = function(body, label) {
		body.push("  <tr>\n");
		body.push("    <td colspan=\"3\">");
		body.push("      <span class=\"report_heading\">" + label + "</span>");
		body.push("    </td>\n");
		body.push("  </tr>\n");
	}

	this.addBothLineItem = function(body, label, value1, value2){
		body.push("  <tr>\n");
		body.push("    <td width=\"50%\">");
		body.push("      <span class=\"report_lineitem\">" + label + "</span>");
		body.push("    </td>\n");
		body.push("    <td width=\"10%\" align=\"right\">");
		body.push("      <span class=\"report_lineitem\">" + value1 + "</span>");
		body.push("    </td>\n");
		body.push("    <td width=\"10%\" align=\"right\">");
		body.push("      <span class=\"report_lineitem\">" + value2 + "</span>");
		body.push("    </td>\n");
		body.push("  </tr>\n");
	}
	
	this.addLineItem = function(body, label, value, column) {
		body.push("  <tr>\n");
		body.push("    <td width=\"50%\">");
		body.push("      <span class=\"report_lineitem\">" + label + "</span>");
		body.push("    </td>\n");
		if (column == this.REGULAR_IRA_COLUMN) {
			body.push("    <td width=\"10%\" align=\"right\">");
			body.push("      <span class=\"report_lineitem\">" + value + "</span>");
			body.push("    </td>\n");
			body.push("    <td width=\"10%\">&nbsp;</td>\n");
		}
		else { // assume (column == this.ROTH_IRA_COLUMN)
			body.push("    <td width=\"10%\">&nbsp;</td>\n");
			body.push("    <td width=\"10%\" align=\"right\">");
			body.push("      <span class=\"report_lineitem\">" + value + "</span>");
			body.push("    </td>\n");
		}
		body.push("  </tr>\n");
	}
	
	this.getBody = function() {
		var body = new Array();
		body.push("<style type=\"text/css\">\n");
		body.push("  .report_table { margin-left: auto; margin-right: auto; }\n");
		body.push("  .report_heading { font: 12pt Helvetica; font-weight: bold; }\n");
		body.push("  .report_lineitem { font: 10pt Helvetica; font-weight: normal; }\n");
		body.push("  .report_value { font: 10pt Helvetica; font-weight: normal; text-alignment: right; }\n");
		body.push("  .report_section_separator { border-bottom: 1px solid black; }\n");
		body.push("</style>\n");
		body.push("<table class=\"report_table\" width=\"90%\">\n");
		this.addReportSectionSeperator(body);
		this.addReportSectionHeading(body, "Annual Contribution");
		this.addLineItem(body, "Annual Roth IRA contribution:",
			regularIRA.getAnnualContributions().formatted(), this.REGULAR_IRA_COLUMN);
		this.addReportSectionSeperator(body);
		this.addReportSectionHeading(body, "Combined Tax Rate");
		this.addLineItem(body, "Federal tax Rate", regularIRA.getFederalTaxRate().formatted(), this.REGULAR_IRA_COLUMN);
		this.addLineItem(body, "State tax Rate:", regularIRA.getStateTaxRate().formatted(), this.REGULAR_IRA_COLUMN);
		this.addLineItem(body, "State tax deducted on federal return?:", 
			((regularIRA.getIncludeStateTax() == true) ? "Yes" : "No"), this.REGULAR_IRA_COLUMN);

		this.addTotalLine(body, this.REGULAR_IRA_COLUMN);
		this.addLineItem(body, "Combined federal and state tax rate:", regularIRA.getCombinedTaxRate().formatted(), this.REGULAR_IRA_COLUMN);

		this.addReportSectionSeperator(body);
		this.addReportSectionHeading(body, "Investment");
		this.addBothLineItem(body, "", "<span class=\"report_heading\">Regular IRA</span>", "<span class=\"report_heading\">Roth IRA</span>");
		this.addBothLineItem(body, "Gross pay needed for contribution:", regularIRA.getGrossPayNeededForContribution().formatted(),
			rothIRA.getGrossPayNeededForContribution().formatted());
		this.addBothLineItem(body, "Reduction in take-home pay:", regularIRA.getAnnualContributions().formatted(),
			rothIRA.getAnnualContributions().formatted());
		this.addBothLineItem(body, "Tax savings by investing:", regularIRA.getTaxSavings().formatted(),
			rothIRA.getTaxSavings().formatted());
		this.addTotalLine(body, this.BOTH_COLUMNS);
		this.addBothLineItem(body, "Tax annual contibution:", regularIRA.getTotalAnnualContribution().formatted(),
			rothIRA.getTotalAnnualContribution().formatted());
		this.addBothLineItem(body, "Years of contributions:", regularIRA.getYearsUntilRetirement(),
			rothIRA.getYearsUntilRetirement());
		this.addBothLineItem(body, "Annual rate of return:", regularIRA.getPreRetirementRateOfReturn().formatted(),
			rothIRA.getPreRetirementRateOfReturn().formatted());
		this.addTotalLine(body, this.BOTH_COLUMNS);
		this.addBothLineItem(body, "Total accumulated at retirement:", regularIRA.getTotalAccumulatedAtRetirement().formatted(),
			rothIRA.getTotalAccumulatedAtRetirement().formatted());
		this.addTotalLine(body, this.BOTH_COLUMNS);

		body.push("  <tr>\n");
		body.push("    <td width=\"50%\">");
		body.push("      <span class=\"report_lineitem\">Difference at retirement:</span>");
		body.push("    </td>\n");
		body.push("    <td colspan=\"2\" width=\"20%\" align=\"center\">");
		var difference = new Calculators.type.Money(
			Math.abs(rothIRA.getTotalAccumulatedAtRetirement().subtract(
			regularIRA.getTotalAccumulatedAtRetirement()).getAmount()));
		body.push("      <span class=\"report_lineitem\">" + difference.formatted() + "</span>");
		body.push("    </td>\n");
		body.push("  </tr>\n");

		this.addReportSectionSeperator(body);
		this.addReportSectionHeading(body, "Retirement");
		this.addBothLineItem(body, "Average tax rate during retirement:", regularIRA.getRetiredTaxRate().formatted(),
			rothIRA.getRetiredTaxRate().formatted());
		this.addBothLineItem(body, "Years of retirement:", regularIRA.getYearsOfRetirement(),
			rothIRA.getYearsOfRetirement());
		this.addBothLineItem(body, "Annual rate of return during retirement:", regularIRA.getRetirementRateOfReturn().formatted(),
			rothIRA.getRetirementRateOfReturn().formatted());
		this.addTotalLine(body, this.BOTH_COLUMNS);
		this.addBothLineItem(body, "Monthly income:", regularIRA.getRetirementMonthlyIncome().formatted(),
			rothIRA.getRetirementMonthlyIncome().formatted());
		this.addBothLineItem(body, "Monthly income after taxes:", regularIRA.getRetirementMonthlyIncomeAfterTaxes().formatted(),
			rothIRA.getRetirementMonthlyIncomeAfterTaxes().formatted());
		this.addTotalLine(body, this.BOTH_COLUMNS);

		body.push("  <tr>\n");
		body.push("    <td width=\"50%\">");
		body.push("      <span class=\"report_lineitem\">Difference at retirement:</span>");
		body.push("    </td>\n");
		body.push("    <td colspan=\"2\" width=\"20%\" align=\"center\">");
		var difference2 = new Calculators.type.Money(
			Math.abs(rothIRA.getRetirementMonthlyIncomeAfterTaxes().subtract(
			regularIRA.getRetirementMonthlyIncomeAfterTaxes()).getAmount()));
		body.push("      <span class=\"report_lineitem\">" + difference2.formatted() + "</span>");
		body.push("    </td>\n");
		body.push("  </tr>\n");


		body.push("</table>\n");
		return body.join("");
	}
	
	this.getTitle = function() {
		return "Regular vs. Roth IRA Report";
	}
}

Calculators.report.RegularVersusRothIRAReport.prototype = new Calculators.report.Report();

