﻿var dollars1040EZ = new Array();
var top1040EZ = new Array(216,246,276,312,390,420,453,468,486,492,522,555,648,372,372);
var left1040EZ = new Array(582,582,582,582,582,582,582,582,420,582,582,582,582,135,219);
var height1040EZ = new Array(22,22,22,22,22,22,12,12,12,22,22,22,22,8,8);
var width1040EZ = new Array(88,88,88,88,88,88,88,88,88,88,88,88,88,6,6);
var size1040EZ = new Array(16,16,16,16,16,16,10,10,10,16,16,16,16,8,8);
var required1040EZ = new Array(0,0,0,1,1,1,1,0,0,1,1,0,0,0,0);
var dollars1040A = new Array();
var top1040A = new Array(190, 206, 190, 235, 252, 280, 255, 300, 350, 438, 474, 504, 528, 540, 560, 660, 690, 690, 720, 756, 775, 792, 818, 834, 864,
                            18, 36, 30, 45, 30, 45, 120, 96, 110, 126, 150, 171, 265, 295, 186, 270, 297, 312, 327, 345, 390, 390, 405, 420, 459, 480, 510, 630);
var left1040A = new Array(125, 125, 421, 421, 133, 133, 675, 675, 675, 675, 590, 590, 444, 590, 444, 590, 270, 590, 590, 440, 440, 440, 440, 590, 590,
                            588, 543, 162, 162, 384, 384, 552, 588, 588, 588, 588, 588, 459, 459, 456, 588, 588, 588, 588, 459, 459, 330, 459, 459, 588, 588, 588, 588);
var height1040A = new Array(8, 8, 8, 8, 8, 8, 20, 20, 20, 20, 18, 18, 12, 18, 12, 18, 15, 15, 15, 15, 14, 14, 14, 15, 15,
                            12, 20, 8, 8, 8, 8, 8, 12, 14, 16, 18, 12, 12, 12, 14, 12, 12, 12, 12, 12, 12, 12, 12, 18, 18, 12, 15, 15);
var width1040A = new Array(8, 8, 8, 8, 8, 8, 20, 20, 20, 20, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 
                            78, 20, 8, 8, 8, 8, 8, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78);
var size1040A = new Array(6, 6, 6, 6, 6, 6, 16, 16, 16, 16, 12, 12, 10, 12, 10, 12, 12, 12, 12, 10, 10, 10, 10, 12, 12,
                            10, 16, 6, 6, 6, 6, 6, 10, 12, 12, 16, 10, 10, 10, 12, 10, 10, 10, 10, 10, 10, 10, 10, 16, 16, 10, 12, 12);
var required1040A = new Array(0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1,
                            1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0);
var dependentInfo = new Array();
var dtop1040A = new Array(342, 342, 342, 345, 358, 358, 358, 361, 373, 373, 373, 376, 389, 389, 389, 392, 404, 404, 404, 407, 420, 420, 420, 423);
var dleft1040A = new Array(135, 300, 405, 543, 135, 300, 405, 543, 135, 300, 405, 543, 135, 300, 405, 543, 135, 300, 405, 543, 135, 300, 405, 543);
var dheight1040A = new Array(14, 14, 14, 8, 14, 14, 14, 8, 14, 14, 14, 8, 14, 14, 14, 8, 14, 14, 14, 8, 14, 14, 14, 8);
var dwidth1040A = new Array(135, 78, 90, 8, 135, 78, 90, 8, 135, 78, 90, 8, 135, 78, 90, 8, 135, 78, 90, 8, 135, 78, 90, 8);
var dsize1040A = new Array(10, 10, 10, 6, 10, 10, 10, 6, 10, 10, 10, 6, 10, 10, 10, 6, 10, 10, 10, 6, 10, 10, 10, 6);
var drequired1040A = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var dollarsScheduleB = new Array();
var topScheduleB = new Array(138, 138, 153, 153, 168, 168, 183, 183, 198, 198, 213, 213, 228, 228, 243, 243, 258, 258, 273, 273, 348, 396, 453, 453, 468, 468, 483, 483, 498, 498, 513, 513, 528, 528, 543, 543, 558, 558, 573, 573, 588, 588, 726, 840, 885);
var leftScheduleB = new Array(135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 591, 591, 135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 135, 591, 591, 690, 690);
var widthScheduleB = new Array(300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 78, 78, 300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 300, 78, 78, 8, 8);
var heightScheduleB = new Array(12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 20, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 20, 8, 8);
var sizeScheduleB = new Array(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 18, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 18, 6, 6);
var requiredScheduleB = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1);
var dollarsScheduleEIC = new Array();
var topScheduleEIC = new Array(291, 360, 483, 555, 555, 624, 624, 690, 816, 291, 360, 483, 555, 555, 624, 624, 690, 816, 291, 360, 483, 555, 555, 624, 624, 690, 816);
var leftScheduleEIC = new Array(228, 228, 270, 234, 309, 234, 309, 228, 270, 390, 390, 420, 393, 477, 393, 477, 390, 429, 549, 549, 579, 552, 636, 552, 636, 549, 588);
var widthScheduleEIC = new Array(150, 150, 90, 15, 15, 15, 15, 150, 45, 150, 150, 90, 15, 15, 15, 15, 150, 45, 150, 150, 90, 15, 15, 15, 15, 150, 45);
var heightScheduleEIC = new Array(16, 22, 22, 15, 15, 15, 15, 20, 20, 16, 22, 22, 15, 15, 15, 15, 20, 20, 16, 22, 22, 15, 15, 15, 15, 20, 20);
var sizeScheduleEIC = new Array(12, 18, 18, 12, 12, 12, 12, 18, 18, 12, 18, 18, 12, 12, 12, 12, 18, 18, 12, 18, 18, 12, 12, 12, 12, 18, 18);
var requiredScheduleEIC = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
var IRAWorksheet = new Array(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
var studentWorksheet = new Array();
var dependents = new Array(null, null, null, null, null, null, null, null, null, null);
var top8917 = new Array(261, 279, 345, 390, 480, 495, 522,
                        216, 216, 216, 216, 216, 231, 231, 231, 231, 231, 246, 246, 246, 246, 246);
var left8917 = new Array(630, 450, 450, 600, 600, 33, 33,
                        33, 444, 483, 525, 630, 33, 444, 483, 525, 630, 33, 444, 483, 525, 630);
var width8917 = new Array(36, 60, 60, 66, 66, 10, 10,
                        200, 30, 20, 40, 36, 200, 30, 20, 40, 36, 200, 30, 20, 40, 36);
var height8917 = new Array(12, 20, 20, 20, 20, 10, 10,
                        12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12);
var size8917 = new Array(10, 16, 16, 16, 16, 8, 8,
                        10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10);
var required8917 = new Array(1, 1, 0, 1, 1,
                        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
var form8917 = new Array();
var top8812 = new Array(150, 240, 267, 279, 300, 342, 357, 345, 360, 396, 426, 483, 540, 600, 660, 705, 744, 798);
var left8812 = new Array(594, 594, 594, 459, 318, 48, 48, 459, 594, 48, 48, 459, 459, 459, 459, 594, 594, 594);
var width8812 = new Array(72, 72, 72, 72, 72, 10, 10, 72, 72, 10, 10, 72, 72, 72, 72, 72, 72, 72);
var height8812 = new Array(20, 20, 12, 14, 14, 10, 10, 20, 10, 10, 20, 20, 20, 20, 20, 20, 20, 12, 12);
var size8812 = new Array(16, 16, 10, 12, 12, 8, 8, 16, 16, 8, 8, 16, 16, 16, 16, 16, 10, 10);
var required8812 = new Array(1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1);
var form8812 = new Array();
var top8863 = new Array(219, 219, 219, 237, 237, 237, 255, 255, 255, 273, 291, 339, 375, 393, 465, 495, 516, 540, 570, 654, 675, 693, 708, 780, 825);
var left8863 = new Array(45, 480, 600, 45, 480, 600, 45, 480, 600, 600, 600, 600, 600, 600, 600, 480, 480, 480, 480, 600, 600, 600, 600, 600, 600);
var width8863 = new Array(360, 60, 60, 360, 60, 60, 360, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60);
var height8863 = new Array(12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12);
var size8863 = new Array(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10);
var required8863 = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
var form8863 = new Array();
var ssWorksheet = new Array();

function spouseTotal(cell, amt, arr) {
    var prefix = cell.substr(0, 3);
    if(getElement(prefix + "earner") == "spouse")
        arr[1] += amt;
    else
        arr[0] += amt;
}
function studentLoanPhaseout(AGI, fullyDeductible, notDeductible) {
    var phaseout = notDeductible - fullyDeductible;
    if(AGI >= notDeductible) return 0;
    if(AGI <= fullyDeductible) return 1;
    return 1 - (AGI - fullyDeductible) / phaseout;
}

function IRAPhaseout(AGI, threshold, isOver50, phaseout) {
    var x = AGI;
    var retval = isOver50 ? IRALimit[1] : IRALimit[0];

    while(x > threshold) {
        retval -= 10;
        x -= isOver50 ? (phaseout / 500) : (phaseout / 400);
    }
    return retval;
}
function IRACheckAGI(AGI, IRADeduction, notDeductibleAmt, fullyDeductibleAmt, isOver50, arrayElem) {
    if(AGI >= notDeductibleAmt) {
        IRAWorksheet[arrayElem] = "";
        return 0;
    }
    if(AGI < fullyDeductibleAmt) {
        IRAWorksheet[arrayElem] = IRAWorksheet[arrayElem - 2];
        return IRADeduction;
    }
    IRAWorksheet[arrayElem] = Math.max(200, IRAPhaseout(AGI, fullyDeductibleAmt, isOver50, notDeductibleAmt - fullyDeductibleAmt));
    return Math.min(IRADeduction, IRAWorksheet[arrayElem]);
}
function calculateIRATotal(AGI, contributions, box13Checked) {
	var retval = new Array(0, 0);
	var isOver50 = new Array(false, false);
	var isOver70 = new Array(false, false);
	var arrayElem;

    if(box13Checked[0]) IRAWorksheet[0] = "X"; else IRAWorksheet[0] = "";
    if(box13Checked[1]) IRAWorksheet[1] = "X"; else IRAWorksheet[1] = "";

    isOver50[0] = (getElement("age0").indexOf("6") > -1);
    isOver50[1] = (getElement("age1").indexOf("6") > -1);

    isOver70[0] = (getElement("age0") == ">70.5");
    isOver70[1] = (getElement("age1") == ">70.5");

    if(isOver70[0]) retval[0] = 0;
    if(isOver70[1]) retval[1] = 0;

    if(isOver50[0]) {
        retval[0] = Math.min(AGI, Math.min(IRALimit[1], contributions[0]));
        IRAWorksheet[8] = IRALimit[1];
    } else {
        retval[0] = Math.min(AGI, Math.min(IRALimit[0], contributions[0]));
        IRAWorksheet[8] = IRALimit[0];
    }

    if(isOver50[1]) {
        retval[1] = Math.min(AGI, Math.min(IRALimit[1], contributions[1]));
        IRAWorksheet[9] = IRALimit[1];
    } else {
        retval[1] = Math.min(AGI, Math.min(IRALimit[0], contributions[1]));
        IRAWorksheet[9] = IRALimit[0];
    }

    var mStatus = getElement("maritalStatus");
    if(mStatus.length > 7) mStatus = mStatus.substr(0, 7);
    switch(mStatus) {
        case "single"  : arrayElem = 0; break;
        case "widow"   : arrayElem = 2; break;
        case "married" : arrayElem = 1; break;
    }

    if(!box13Checked[0] && !box13Checked[1]) {
        for (var i = 2; i < 12; i++) IRAWorksheet[i] = "";
    } else {
        if(arrayElem == 1) {
            IRAWorksheet[2] = box13Checked[0] ? IRANotDeductible[2] : IRANotDeductible[1];
            IRAWorksheet[3] = box13Checked[1] ? IRANotDeductible[2] : IRANotDeductible[1];
        } else {
            IRAWorksheet[2] = IRANotDeductible[arrayElem];
            IRAWorksheet[3] = "";
        }
    }

    if(box13Checked[0])
        retval[0] = Math.min(retval[0], IRACheckAGI(AGI, retval[0], IRANotDeductible[arrayElem], IRAFullyDeductible[arrayElem], isOver50[0], 10));
    if(box13Checked[1])
        retval[1] = Math.min(retval[0], IRACheckAGI(AGI, retval[1], IRANotDeductible[arrayElem], IRAFullyDeductible[arrayElem], isOver50[1], 11));

    if(mStatus == "married") {
        for(var i = 0; i < 2; i++) {
            if(box13Checked[i])
                retval[i] = Math.min(retval[i], IRACheckAGI(AGI, retval[i], IRANotDeductible[2], IRAFullyDeductible[2], isOver50[i], i + 10));
            else
                IRAWorksheet[i + 10] = IRAWorksheet[i + 8];
        }
	}
	return retval[0] + retval[1];
}

function tuitionTotalPhaseOut(tuition, netIncome, filingStatusNum) {
    var limits = new Array(80000, 65000, 0);
    if(getElement("canBeClaimed0") == "Yes" || getElement("canBeClaimed1") == "Yes")
        return 0;

    if(filingStatusNum == 2) {
        for (var i = 0; i < limits.length; i++)
            limits[i] *= 2;
    }
    form8917[5] = (netIncome > limits[1]) ? "X" : "";
    form8917[6] = (netIncome > limits[1]) ? "" : "X";
    for (var i = 0; i < limits.length; i++) {
        if(netIncome > limits[i]) return Math.min(tuition, 2000 * i);
    }
}

function tuitionCreditPhaseOut(tuition, netIncome, filingStatusNum) {
    var creditZero = tuitionCreditZero[1];
    var creditFull = tuitionCreditFull[1];
    if(filingStatusNum == 2) {
        creditZero = tuitionCreditZero[0];
        creditFull = tuitionCreditFull[0];
    }
    if(netIncome >= creditZero) return 0;
    if(netIncome <= creditFull) return tuition;
    return Math.round((creditZero - netIncome) / (creditZero - creditFull) * tuition);
}

function calculateTaxableSSAmt(amt, W2Total, intTotal, divTotal, ueTotal, exemptIntTotal, educatorTotal, IRATotal, filingStatusNum) {
    ssWorksheet.length = 0;
    ssWorksheet.push(amt, amt / 2, W2Total + intTotal + divTotal + ueTotal, exemptIntTotal, amt / 2 + W2Total + intTotal + divTotal + ueTotal + exemptIntTotal, educatorTotal + IRATotal);
    var line7 = amt / 2 + W2Total + intTotal + divTotal + ueTotal + exemptIntTotal - educatorTotal - IRATotal;
    ssWorksheet.push(line7, "", "", "", "", "", "", "", "", "", "", "");
    if(line7 < 0) return 0;
    ssWorksheet[7] = filingStatusNum == 2 ? 32000 : 25000;
    var line9 = line7 - (filingStatusNum == 2 ? 32000 : 25000);
    ssWorksheet[8] = line9;
    if(line9 < 0) return 0;
    var line10 = (filingStatusNum == 2 ? 12000 : 9000);
    ssWorksheet[9] = line10;
    ssWorksheet[10] = Math.max(0, line9 - line10);
    ssWorksheet[11] = Math.min(line9, line10);
    ssWorksheet[12] = ssWorksheet[11] / 2;
    var line14 = Math.min(Math.min(line9, line10), amt) / 2;
    ssWorksheet[13] = line14;
    ssWorksheet[14] = ssWorksheet[10] * 0.85;
    ssWorksheet[15] = line14 + ssWorksheet[14];
    ssWorksheet[16] = amt * 0.85;
    ssWorksheet[17] = Math.round(Math.max(0, Math.min(ssWorksheet[15], ssWorksheet[16])));
    return ssWorksheet[17];
}
function calculateDeduction(wages, stdDeduct) {
	var minExemption = 850;
	var nClaimed = 0;

    if (getElement("canBeClaimed0") == "Yes") nClaimed++;
    if (getElement("filingStatus") == "married1" && getElement("canBeClaimed1") == "Yes") nClaimed++;

    if (nClaimed > 0) {
	    if (wages <= minExemption - 300) return minExemption;
		else return Math.min(stdDeduct, wages + 300);
    } else
        return stdDeduct;
}

function calculateTax(taxableIncome, filingStatus) {
	var thresholds =  new Array(8375, 34000, 82400, 171850, 373650);
	var rates = new Array(.1, .15, .25, .28, .33, .35);
	var i, roundedIncome;
	var addend = new Array(0.0, 0.0);
	var totalTax = 0.0;

	if(filingStatus == 2 || filingStatus == 5) {
		thresholds[0] = 16750;
		thresholds[1] = 68000;
		thresholds[2] = 137300;
		thresholds[3] = 209250;
	} else if(filingStatus == 4) {
		thresholds[0] = 11950;
		thresholds[1] = 45550;
		thresholds[2] = 117650;
		thresholds[3] = 190550;
	}

	//These are from the tax table
	if(taxableIncome < 5)
		return 0;
	if(taxableIncome < 15)
		return 1;
	if(taxableIncome < 25)
		return 2;

    if(taxableIncome < 3000) {
        roundedIncome = 25 * parseInt(taxableIncome / 25);
        if(roundedIncome % 50 == 0)
            return Math.round(roundedIncome * rates[0] + 1);
        else
            return Math.round(roundedIncome * rates[0] + 1.5);
    }
    roundedIncome = 50 * parseInt(taxableIncome / 50); 
    if(roundedIncome < thresholds[0]) {
        return parseInt(roundedIncome * rates[0] + 3);
    } else if(roundedIncome < thresholds[1]) {
        if(filingStatus == 1) {
            addend[0] = 4.0;
            addend[1] = 3.5;
        } else {
            addend[0] = 3.0;
            addend[1] = 3.5;
        }
        if(roundedIncome % 100 == 0)
            return Math.round(roundedIncome * rates[1] - Math.floor(thresholds[0] * (rates[1] - rates[0])) + 5.5);
        else
            return Math.round(roundedIncome * rates[1] - Math.floor(thresholds[0] * (rates[1] - rates[0])) + 6);
    }

	totalTax = Math.ceil(thresholds[0] * rates[0] + (thresholds[1] - thresholds[0]) * rates[1]);
	if(roundedIncome < thresholds[2] && roundedIncome < 100000) {
	    if(filingStatus == 1) {
	        addend[0] = 5.5;
	        addend[1] = 6;
	    } else {
	        addend[0] = 6.5;
	        addend[1] = 6;
	    }
        if(roundedIncome % 100 == 0)
            return Math.round(totalTax + (roundedIncome - thresholds[1]) * rates[2] + addend[0]);
        else
            return Math.round(totalTax + (roundedIncome - thresholds[1]) * rates[2] + addend[1]);
	}
	totalTax += Math.ceil((thresholds[2] - thresholds[1]) * rates[2]);
	if(roundedIncome < thresholds[3] && roundedIncome < 100000)
	    return Math.round(totalTax + (roundedIncome - thresholds[2]) * rates[3] + 6);

    if(roundedIncome < thresholds[2]) {
        if(filingStatus == 4)
            return taxableIncome * rates[2] - 4937.5;
        else
            return taxableIncome * rates[2] - 7312.5;
    }

    if(roundedIncome < thresholds[3]) {
        switch(filingStatus) {
            case 1:
                return taxableIncome * rates[3] - 6021.75;
                break;
            case 4:
                return taxableIncome * rates[3] - 4937.5;
                break;
            default:
                return taxableIncome * rates[3] - 11256;
        }
    }
    if(roundedIncome < thresholds[4]) {
        switch(filingStatus) {
            case 1:
                return taxableIncome * rates[4] - 14249.25;
                break;
            case 4:
                return taxableIncome * rates[4] - 17437;
                break;
            default:
                return taxableIncome * rates[4] - 21271;
        }
    }
    switch(filingStatus) {
        case 1:
            return taxableIncome * rates[5] - 21403.25;
            break;
        case 4:
            return taxableIncome * rates[5] - 24591;
            break;
        default:
            return taxableIncome * rates[5] - 28425;
    }
}

function isHOHDependent() {
    var elementId, cellNum;
    for(var i=0; i < document.forms[0].elements.length; i++) {
        elementId = document.forms[0].elements[i].id;
        cellNum = elementId.substr(1, 2);
        if(elementId.substr(0, 1) == "n" && isNaN(cellNum) == false) {
            if(elementId.substr(3) == "SSN") {
                var relation = getElement("n" + cellNum + "relation");
                var months = parseInt(getElement("n" + cellNum + "months"));
                var age = getElement("n" + cellNum + "DCOB");
                age = getElement("n" + cellNum + "DYOB" + age);
                var support = getElement("n" + cellNum + "support");
                if(relation.substr(0, 5) == "child" && support == "1" && months > 6)
                    if(age.length == 1 || age < "18" || getElement("adultClaim" + cellNum) != "No")
                        return true;
            }
        }
    }
    return false;
}

function changeSummaryLineNumbers(formType) {
    for(var i = 0; i < 19; i++) cellDisplay("noEZ" + i, (formType != 2));

    cellDisplay("EZonly0", (formType == 2));
    cellDisplay("EZonly1", (formType == 2));
    cellDisplay("EZonly2", (formType == 2));
    setElement("heading", "Line number on form 1040" + (formType==1 ? "A" : (formType==2 ? "EZ" : "")));
    setElement("totalIncomeLine", totalIncomeLine[formType]);
    setElement("totDeductionLine", totDeductionLine[formType]);
    setElement("AGILine", AGILine[formType]);
    setElement("over65Line", over65Line[formType]);
    setElement("stdDeductLine", stdDeductLine[formType]);
    setElement("Line41Label", Line41[formType]);
    setElement("Line41Description", "Subtract line " + stdDeductLine[formType] + " from line " + AGILine[formType]);
    setElement("exemptionLine", exemptionLine[formType]);
    setElement("taxIncomeLine", taxIncomeLine[formType]);
    setElement("taxLine", taxLine[formType]);
    setElement("childCreditLine", childCreditLine[formType]);
    setElement("tuitionCreditLine", tuitionCreditLine[formType]);
    setElement("taxLine2", taxLine2[formType]);
    setElement("taxDescription2", "Subtract lines " + tuitionCreditLine[formType] + "-" + childCreditLine[formType] + " from line " + taxLine[formType]);
    setElement("taxLine3", taxLine3[formType]);
    setElement("AdditionalChildCreditLine", additionalChildCreditLine[formType]);
    setElement("paymentLine", paymentLine[formType]);
    setElement("refundLine", refundLine[formType]);
    setElement("oweLine", oweLine[formType]);
    setElement("summaryW2Line", W2Line[formType]);
    setElement("summaryIntLine", intLine[formType]);
    setElement("summaryExemptIntLine", exemptIntLine[formType]);
    setElement("summaryDivLine", dividendLine[formType]);
    setElement("summaryQualDivLine", qualDividendLine[formType]);
    setElement("summaryUELine", ueLine[formType]);
    setElement("summarySSLine", ssLine[formType]);
    setElement("summarySSTaxLine", ssLine[formType].replace("a", "b"));
    setElement("summaryEducatorLine", educatorLine[formType]);
    setElement("summaryIRALine", IRALine[formType]);
    setElement("summaryStudentLine", studentLine[formType]);
    setElement("summaryTuitionLine", tuitionLine[formType]);
    setElement("summaryWithholdLine", withholdLine[formType]);
    setElement("EICLine", EICLine[formType]);
    setElement("summaryCombatLine", combatLine[formType]);
    if(formType==2) setElement("filingStatusNum", "N/A");
}

function calculateAndShowSummary() {
    var elementId;
    var cellNum;
    var W2Total = 0;
    var SSTaxTotal = 0;
    var MedicareTotal = 0;
    var intTotal = 0;
    var exemptIntTotal = 0;
    var divTotal = 0;
    var qualDivTotal = 0;
    var ueVal = new Array(0, 0);
    var ssTotal = 0;
    var ssTaxable = 0;
    var educatorVal = new Array(0, 0);
    var IRAVal = new Array(0, 0);
    var studentVal = 0;
    var tuitionVal = 0;
    var tuitionCredit = 0;
    var box13Checked = new Array(false, false);
    var withholdTotal = 0;
    var EICAmt = 0;
    var combatTotal = 0;
    var blindOver65Total = 0;
    var dependentTotal = 0;
    var dependentChildTotal = 0;
    var dependentInHouse = 0;
    var dependentElsewhere = 0;
    var qualChildren = 0;
    var childCredit = 0;
    var additionalChildCredit = 0;
    var econRecoveryTotal = 0;
    var fullYearChild = false;
    var amt, sDeduction, filingStatusNum;
    var canFile1040A = true;
    var canFile1040EZ = true;
    var showScheduleB = false;
    var showScheduleL = false;
    var showForm8917 = false;
    var showForm8812 = false;
    var dollarsInterest = new Array();
    var dollarsDividend = new Array();
    var studentName = "";
    var studentSSN = "";
    var W2Decade = "";
    dollars1040EZ.length = 0;
    dollars1040A.length = 0;
    dependentInfo.length = 0;
    dollarsScheduleEIC.length = 0;
    studentWorksheet.length = 0;
    form8917.length = 0;
    form8917.push("", "", "", "", "", "", "");
    form8812.length = 0;
    cellDisplay("summaryCannotDo", false);
    cellDisplay("summaryView", false);
    cellDisplay("summaryPreview", true);
    changeSummaryLineNumbers(1);

    var mStatus = getElement("maritalStatus");
    var HOHDependent = isHOHDependent();
    if(mStatus.substr(0, 7) == "married") {
        filingStatusNum = 2;
        setElement("filingStatus", "Married Filing Jointly");
    } else if(mStatus == "widow" && getElement("residencyPay") == "Yes" && fullYearChild == true) {
        filingStatusNum = 5;
        setElement("filingStatus", "Qualifying Widow(er)");
        canFile1040EZ = false;
    } else if(mStatus == "single" && getElement("parentPay") == "Yes") {
        filingStatusNum = 4;
        setElement("filingStatus", "Head of Household");
        canFile1040EZ = false;
    } else if(mStatus == "single" && getElement("residencyPay") == "Yes" && HOHDependent == true) {
        filingStatusNum = 4;
        setElement("filingStatus", "Head of Household");
        canFile1040EZ = false;
    } else {
        filingStatusNum = 1;
        setElement("filingStatus", "Single");
    }
    dollars1040A.push((filingStatusNum == 1) ? "X" : "");
    dollars1040A.push((filingStatusNum == 2) ? "X" : "");
    dollars1040A.push((filingStatusNum == 4) ? "X" : "");
    dollars1040A.push((filingStatusNum == 5) ? "X" : "");
    setElement("filingStatusNum", filingStatusNum);

    if(getElement("canBeClaimed0") == "No") {
        dependentTotal++;
        dollars1040A.push("X");
    } else
        dollars1040A.push("");

    if(getElement("blind0") == "Yes") blindOver65Total++;
    if(getElement("age0").indexOf("70") > -1) blindOver65Total++;

    if(mStatus == "married1") {
        if(getElement("canBeClaimed1") == "No") {
            dependentTotal++;
            dollars1040A.push("X");
        } else
            dollars1040A.push("");

        if(getElement("blind1") == "Yes") blindOver65Total++;
        if(getElement("age1").indexOf("70") != -1) blindOver65Total++;
    } else
        dollars1040A.push("");
    dollars1040A.push(dependentTotal);

    if(blindOver65Total > 0) canFile1040EZ = false;

    for(var i=0; i < document.forms[0].elements.length; i++) {
        elementId = document.forms[0].elements[i].id;
        cellNum = elementId.substr(1, 2);
        if(elementId.substr(0, 1) == "n" && isNaN(cellNum) == false) {
            amt = parseMoney(getElement(elementId));
            if(elementId.substr(3) == "SSN") {
                var relation = getElement("n" + cellNum + "relation");
                var months = parseInt(getElement("n" + cellNum + "months"));
                var decree = getElement("n" + cellNum + "decree");
                var age = getElement("n" + cellNum + "DCOB");
                age = getElement("n" + cellNum + "DYOB" + age);
                var YOB = getElement("n" + cellNum + "DCOB");
                YOB += getElement("n" + cellNum + "DYOB" + YOB, true);
                if(isNaN(age)) YOB = ""; else YOB = YOB.substr(0, 4);
                var support = getElement("n" + cellNum + "support");
                var cc = false;
                var gender = document.getElementById("n" + cellNum + "gender").selectedIndex;
                var relationType;
                var dependentSSN = getElement(elementId);
                    
                if(months == 12 && (relation == "child1" || relation == "child6"))
                    fullYearChild = true;

                if(relation.substr(0, 5) == "child" && support == "1" && months > 6)
                    if(age.length == 1 || age < "18" || getElement("adultClaim" + cellNum) != "No")
                        HOHDependent = true;
                if(dependentQualifies(relation, elementId.substr(1, 2), "") == "") {
                    dependentTotal++;
                    canFile1040EZ = false;
                    dependentInfo.push(getElement("n" + cellNum + "name"));
                    dollarsScheduleEIC.push(getElement("n" + cellNum + "name"));
                    relationType = getElement("n" + cellNum + "relation", true);
                    if(relationType.indexOf("/") != -1) {
                        var relations = relationType.split("/");
                        if(relations.length != gender)
                            relationType = relations[gender];
                    }
                    dependentInfo.push(relationType);
                    if(relation.substr(0, 5) == "child")
                        if(age.length == 1 || age <"17")
                            if(support != "0")
                                if(months > 6)
                                    cc = true;
                    if(cc) qualChildren++;
                    pushSSNontoArray(dependentSSN, dependentInfo);
                    dependentInfo.push(cc ? "X" : "");
                    pushSSNontoArray(dependentSSN, dollarsScheduleEIC);
                    dollarsScheduleEIC.push(YOB);
                    if(YOB == "") {
                        if(getElement("adultClaim" + cellNum.substr(1)) == "YesS") {
                            dollarsScheduleEIC.push("X", "", "", "");
                        } else if(getElement("adultClaim" + cellNum.substr(1)) == "YesD") {
                            dollarsScheduleEIC.push("", "X", "X", "");
                        } else {
                            dollarsScheduleEIC.push("", "X", "", "X");
                        }
                    } else {
                        dollarsScheduleEIC.push("X", "", "", "");
                    }
                    dollarsScheduleEIC.push(relationType);
                    dollarsScheduleEIC.push(months);
                    if(relation.substr(0, 5) == "child") dependentChildTotal++;
                    else dollarsScheduleEIC.length = dollarsScheduleEIC.length - 9;
                    if(months < 7) dependentElsewhere++;
                    else dependentInHouse++;
                }
            } else if(amt != "" && isNaN(amt) == false) {
                switch(elementId.substr(3)) {
                    case W2Line[0]:
                        W2Decade = cellNum.substring(0, 1);
                        W2Total += amt;
                        if(getElement("n" + cellNum + "ret") == true) {
                            if(getElement("n" + cellNum + "earner") == "spouse")
                                box13Checked[1] = true;
                            else
                                box13Checked[0] = true;
                        }
                        amt = getElement("n" + cellNum + "SSTax");
                        if(!isNaN(amt)) SSTaxTotal += amt;

                        amt = getElement("n" + cellNum + "Medicare");
                        if(!isNaN(amt)) MedicareTotal += amt;

                        break;
                    case intLine[0]:
                        intTotal += amt;
                        dollarsInterest.push(getElement("n" + cellNum + "name"));
                        dollarsInterest.push(amt);
                        break;
                    case exemptIntLine[0]: exemptIntTotal += amt; break;
                    case ueLine[0]: spouseTotal(elementId, amt, ueVal); break;
                    case ssLine[0]:
                        ssTotal += amt;
                        econRecoveryTotal += parseMoney(getElement("n" + cellNum + "econRecovery"));
                        break;
                    case dividendLine[0]: 
                        divTotal += amt;
                        dollarsDividend.push(getElement("n" + cellNum + "name"));
                        dollarsDividend.push(amt);
                        if(getElement("n" + cellNum + "ownership") == "2") showScheduleB = true;
                        break;
                    case qualDividendLine[0]: 
                        if(getElement("ownership" + cellNum) <= "1") {
                            divTotal -= amt;
                            qualDivTotal += amt;
                        }
                        if(getElement("n" + cellNum + "ownership") == "2") showScheduleB = true;
                        break;
                    case withholdLine[0]: withholdTotal += amt; break;
                    case combatLine[0]: combatTotal += amt; break;
                    case educatorLine[0]:
                        if((getElement("educatorGrade" + cellNum) + getElement("educatorHours" + cellNum)).indexOf("No") == -1)
                            spouseTotal(elementId, amt, educatorVal); break;
                    case IRALine[0]:
                        if(getElement("n" + cellNum + "IRADeductible") == "true")
                            spouseTotal(elementId, amt, IRAVal);
                        break;
                    case studentLine[0]: 
                        if((getElement("studentDependent" + cellNum) + getElement("studentProgram" + cellNum)).indexOf("0") == -1
                            && (getElement("studentCover" + cellNum) + getElement("studentLoad" + cellNum)).indexOf("No") == -1)
                            studentVal += amt;
                        break;
                    case tuitionLine[0]:
                        if(getElement("n" + cellNum + "courseStart") == "Deductible") {
                            tuitionVal += amt;
                            tuitionCredit += amt;
                            amt = getElement("n" + cellNum + "CourseSupplies");
                            if(!isNaN(amt)) tuitionCredit += parseFloat(amt);
                            studentName = getElement("n" + cellNum + "earner", true);
                            studentSSN = getElement("n" + cellNum + "earner");
                            form8917.push(studentName);
                            if(studentSSN != studentName) pushSSNontoArray(studentSSN, form8917);
                            else pushSSNontoArray("", form8917);
                            form8917.push(amt);
                        }
                        break;
                }
            }
        }
    }
    form8917[0] = tuitionVal;
    if(intTotal >= 1500 || divTotal >= 1500) showScheduleB = true;
    dollars1040A.push(dependentInHouse, dependentElsewhere, dependentTotal);
    W2Total = Math.round(W2Total);
    intTotal = Math.round(intTotal);
    dollars1040EZ.push(W2Total);
    dollars1040A.push(W2Total);
    dollars1040EZ.push(intTotal);
    dollars1040A.push(intTotal, Math.round(exemptIntTotal));
    dollars1040A.push(Math.round(divTotal), Math.round(qualDivTotal));
    var ueTotal = Math.max(0, ueVal[0]) + Math.max(0, ueVal[1]);
    dollars1040EZ.push(ueTotal);
    dollars1040A.push(ueTotal);
    if(ssTotal > 0) {
        canFile1040EZ = false;
        ssTaxable = Math.round(calculateTaxableSSAmt(ssTotal, W2Total, intTotal, divTotal, 
                                ueTotal, exemptIntTotal, 
                                Math.min(educatorLimit, educatorVal[0]) + Math.min(educatorLimit, educatorVal[1]), 
                                calculateIRATotal(W2Total + intTotal + ueTotal + divTotal, IRAVal, box13Checked), filingStatusNum));
    }
    dollars1040A.push(ssTotal);
    dollars1040A.push(ssTaxable);
    var totIncome = W2Total + intTotal + Math.round(ueTotal) + Math.round(divTotal) + Math.round(ssTaxable);
    var totIncome2 = totIncome;
    form8917[1] = totIncome;
    var netIncome = totIncome;
    dollars1040EZ.push(netIncome);
    dollars1040A.push(netIncome);
    IRAWorksheet[4] = netIncome;
    var educatorTotal = Math.min(educatorLimit, educatorVal[0]) + Math.min(educatorLimit, educatorVal[1]);
    IRAWorksheet[5] = Math.round(educatorTotal);
    dollars1040A.push(Math.round(educatorTotal));
    if(educatorTotal > 0) canFile1040EZ = false;
    netIncome -= educatorTotal;
    IRAWorksheet[6] = netIncome;
    if(filingStatusNum == 2) IRAWorksheet[7] = netIncome; else IRAWorksheet[7] = "";

    var IRATotal = 0;
    if(IRAVal[0] + IRAVal[1] > 0) {
        IRATotal = calculateIRATotal(netIncome, IRAVal, box13Checked);
        if(IRATotal > 0) canFile1040EZ = false;
    }
    dollars1040A.push(Math.round(IRATotal));
    netIncome -= IRATotal;
    
    var studentTotal = Math.round(Math.min(studentLimit, studentVal));
    studentWorksheet.push(studentTotal);
    if(studentTotal > 0) {
        canFile1040EZ = false;
        studentWorksheet.push(totIncome, netIncome);
        if(mStatus == "married1") {
            studentTotal = Math.round(studentTotal * studentLoanPhaseout(netIncome, studentLoanFullyDeductible[1], studentLoanNotDeductible[1]));
            studentWorksheet.push(studentLoanFullyDeductible[1]);
            studentWorksheet.push(studentLoanNotDeductible[1]);
        } else {
            studentTotal = Math.round(studentTotal * studentLoanPhaseout(netIncome, studentLoanFullyDeductible[0], studentLoanNotDeductible[0]));
            studentWorksheet.push(studentLoanFullyDeductible[0]);
            studentWorksheet.push(studentLoanNotDeductible[0]);
        }
    }

    dollars1040A.push(Math.round(studentTotal));
    netIncome -= studentTotal;
    form8917[3] = netIncome;
    form8917[2] = totIncome - netIncome;
    if(filingStatusNum == 2) sDeduction = calculateDeduction(W2Total, stdDeduction[1]);
    else if (filingStatusNum == 4) sDeduction = calculateDeduction(W2Total, stdDeduction[2]);
    else sDeduction = calculateDeduction(W2Total, stdDeduction[0]);

    if(mStatus == "married1") sDeduction += (blindOver65Total * 1150);
    else sDeduction += (blindOver65Total * 1450);

    if(parseInt(tuitionVal) + parseInt(tuitionCredit) > 0) {
        canFile1040EZ = false;
        var netIncomeSave = netIncome;
        tuitionVal = tuitionTotalPhaseOut(tuitionVal, netIncome, filingStatusNum);
        var tuitionCredit = tuitionCreditPhaseOut(tuitionCredit / 5, netIncome, filingStatusNum);
        netIncome -= sDeduction;
        netIncome -= dependentTotal * dependentAmt;
        var taxLiability = calculateTax(netIncome, filingStatusNum) - tuitionCredit;
        var taxLiability2 = calculateTax(netIncome - tuitionVal, filingStatusNum);
        if(taxLiability < taxLiability2) tuitionVal = 0;
        else tuitionCredit = 0;
        netIncome = netIncomeSave;
    }
    form8917[4] = tuitionVal;
    if(tuitionVal > 0) {
        canFile1040EZ = false;
        showForm8917 = true;
    }
    netIncome -= tuitionVal;
    dollars1040A.push(Math.round(tuitionVal));
    dollars1040A.push(Math.round(educatorTotal) + Math.round(IRATotal) + Math.round(studentTotal) + Math.round(tuitionVal));
    dollars1040A.push(netIncome, blindOver65Total);
    if(getElement("age0").indexOf("70") > -1) dollars1040A.push("X");
    else dollars1040A.push("");
    if(getElement("blind0") == "Yes") dollars1040A.push("X");
    else dollars1040A.push("");
    if(mStatus == "married1") {
        if(getElement("age1").indexOf("70") != -1) dollars1040A.push("X");
        else dollars1040A.push("");
        if(getElement("blind1") == "Yes") dollars1040A.push("X");
        else dollars1040A.push("");
    } else {
        dollars1040A.push("");
        dollars1040A.push("");
    }

    if(getElement("propTaxCheck") == true) dollars1040A.push("X");
    else dollars1040A.push("");

    dollars1040A.push(sDeduction);

    if(intTotal > 1500 || divTotal > 0 || qualDivTotal > 0) canFile1040EZ = false;

    setElement("summaryW2Total", Math.round(W2Total));
    setElement("summaryIntTotal", Math.round(intTotal));
    setElement("summaryExemptIntTotal", Math.round(exemptIntTotal));
    setElement("summaryDivTotal", Math.round(divTotal));
    setElement("summaryQualDivTotal", Math.round(qualDivTotal));
    setElement("summaryUETotal", Math.round(ueTotal));
    setElement("summarySSTotal", Math.round(ssTotal));
    setElement("summarySSTaxTotal", ssTaxable);
    setElement("totalIncome", totIncome);
    setElement("summaryEducatorTotal", Math.round(educatorTotal));
    setElement("summaryIRATotal", Math.round(IRATotal));
    setElement("summaryStudentTotal", Math.round(studentTotal));
    setElement("summaryTuitionTotal", Math.round(tuitionVal));
    setElement("totalDeductions", totIncome - netIncome);
    if(netIncome > maxIncome) {
        cellDisplay("summaryCannotDo", true);
        cellDisplay("summaryPreview", false);
        return;
    } 
    setElement("AGI", netIncome);
    setElement("blindOver65", blindOver65Total);
    setElement("stdDeduction", sDeduction);
    netIncome = Math.max(0, netIncome - sDeduction);
    setElement("Line41", netIncome);
    dollars1040A.push(netIncome);
    setElement("dependentAmt", dependentTotal * dependentAmt);
    dollars1040A.push(dependentTotal * dependentAmt);
    setElement("deductExempt", sDeduction + dependentTotal * dependentAmt);
    dollars1040EZ.push(Math.round(sDeduction + dependentTotal * dependentAmt));
    setElement("taxableIncome", (netIncome = Math.max(0, netIncome - (dependentTotal * dependentAmt))));
    dollars1040EZ.push(Math.round(netIncome));
    dollars1040A.push(Math.round(netIncome));
    if(netIncome > 100000) canFile1040EZ = false;
    taxLiability = calculateTax(netIncome, filingStatusNum);
    setElement("taxLiability", taxLiability);
    dollars1040A.push(taxLiability);
    setElement("tuitionCredit", tuitionCredit = Math.min(taxLiability,tuitionCredit));
    dollars1040A.push(tuitionCredit, childCredit + tuitionCredit);
    taxLiability = Math.max(0, taxLiability - tuitionCredit);
    childCredit = qualChildren * childCreditAmt;
    if(childCredit > 0) {
        setElement("childCreditScript", "<a href='javascript:popChildCreditSheet(" + filingStatusNum + ", " + qualChildren + ", " + totIncome + ", " + taxLiability + ", 1);'>View Child Credit Worksheet</a>");
        cellDisplay("childCreditLink", true);
        if(filingStatusNum == 2 || totIncome <= 75000 && childCredit > taxLiability) setElement("childCredit", childCredit);
        else {
            childCredit -= Math.max(0, 50*Math.ceil((totIncome-((filingStatusNum==2)?110000:75000))/1000));
        }
        childCredit = Math.min(childCredit, taxLiability);
        setElement("childCredit", childCredit);
        form8812.push(childCredit);
        childCredit = Math.min(taxLiability, childCredit);
        form8812.push(childCredit);
        form8812.push(form8812[0] - form8812[1], W2Total, 0);
        form8812.push(W2Total>3000?"":"X");
        form8812.push(W2Total>3000?"X":"");
        form8812.push(Math.max(0, W2Total - 3000));
        taxLiability -= childCredit;
    } else {
        setElement("childCredit", "0");
        childCredit = 0;
    }
    dollars1040A.push(childCredit, childCredit + tuitionCredit);
    setElement("tax2", taxLiability);
    dollars1040A.push(taxLiability);
    setElement("tax3", taxLiability);
    dollars1040A.push(taxLiability);
    setElement("summaryWithholdTotal", withholdTotal);
    dollars1040EZ.push(Math.round(withholdTotal));
    dollars1040A.push(Math.round(withholdTotal));

    if(W2Total < maxIncomeEIC[6-2*Math.min(dependentChildTotal,3)] && intTotal + exemptIntTotal + divTotal < 3100) {
        EICAmt = calculateEIC(W2Total, combatTotal, intTotal, ueTotal, Math.min(dependentChildTotal, 3));
        if(document.getElementById("Combat0").style.display == "none") {
            cellDisplay("summaryInstructions", true);
            for(var i = 0; i < 10; i++) cellDisplay("Combat" + i, true);

        }
    }
    setElement("summaryEICAmount", EICAmt);
    dollars1040EZ.push(Math.round(EICAmt));
    dollars1040A.push(Math.round(EICAmt));
    setElement("summaryCombatTotal", Math.round(combatTotal));
    dollars1040EZ.push(Math.round(combatTotal));
    dollars1040A.push(Math.round(combatTotal));
    withholdTotal += EICAmt;
    if(taxLiability == 0 && qualChildren > 0) {
        if(document.getElementById("SSTax0").style.display == "none") {
            cellDisplay("summaryInstructions", true);
            for(var i = 0; i < 10; i++) {
                var j = W2Decade.toString() + i.toString();
                var income = parseFloat(getElement("n" + j + W2Line[0]));
                setElement("n" + j + "SSTax", parseInt(income * .062 + 0.5));
                cellDisplay("SSTax" + i, true);
                setElement("n" + j + "Medicare", parseInt(income * .0145 + 0.5));
                cellDisplay("Medicare" + i, true);
            }
        }
        additionalChildCredit = popChildCreditSheet(filingStatusNum, qualChildren, totIncome, childCredit, 1, true, W2Total, SSTaxTotal, MedicareTotal, netIncome, EICAmt);
        dollars1040A.push(Math.round(additionalChildCredit));
        showForm8812 = true;
    } else dollars1040A.push("0");

    setElement("AdditionalChildCredit", additionalChildCredit);
    withholdTotal += additionalChildCredit;
    dollars1040EZ.push(Math.round(withholdTotal));
    dollars1040A.push(Math.round(withholdTotal));
    dollars1040EZ.push(Math.round(taxLiability));
    dollars1040EZ.push(Math.round(Math.max(0, withholdTotal - taxLiability)));
    dollars1040EZ.push(Math.round(Math.max(0, taxLiability - withholdTotal)));
    dollars1040A.push(Math.round(Math.max(0, withholdTotal - taxLiability)));
    dollars1040A.push(Math.round(Math.max(0, withholdTotal - taxLiability)));
    dollars1040A.push(Math.round(Math.max(0, taxLiability - withholdTotal)));
    dollars1040EZ.push((getElement("canBeClaimed0") == "No") ? "" : "X");
    dollars1040EZ.push((getElement("maritalStatus") != "married1" || getElement("canBeClaimed1") == "No") ? "" : "X");
    IRAWorksheet[12] = Math.round(W2Total) + Math.round(combatTotal);
    IRAWorksheet[13] = IRAVal[0];
    IRAWorksheet[14] = IRAVal[1];
	if(IRAWorksheet[10] == "" || IRAVal[0] == 0) IRAWorksheet[15] = "0"; else IRAWorksheet[15] = Math.min(IRAWorksheet[10], Math.min(IRAWorksheet[12], IRAWorksheet[13]));
	if(IRAWorksheet[11] == "" || IRAVal[1] == 0) IRAWorksheet[16] = "0"; else IRAWorksheet[16] = Math.min(IRAWorksheet[11], Math.min(IRAWorksheet[12], IRAWorksheet[14]));
    var FICA = Math.round(0.062 * W2Total);
	if(filingStatusNum == 2) {
        econRecoveryTotal = Math.min(500, econRecoveryTotal);
	    if(W2Total > 12903) {
	        dollars1040EZ.push("X", "", "", "", "", "", 800, totIncome, 150000, "", "", 800, econRecoveryTotal, 800 - econRecoveryTotal);
	        if(totIncome > 150000) dollars1040EZ.push("", "X"); else dollars1040EZ.push("X", "");
	    } else {
	        dollars1040EZ.push("", "X", W2Total, combatTotal, FICA, 800, FICA, totIncome, 150000, "", "", FICA, econRecoveryTotal, Math.max(0, FICA - econRecoveryTotal), "X", "");
	    }
	} else {
        econRecoveryTotal = Math.min(250, econRecoveryTotal);
	    if(W2Total > 6451) {
	        dollars1040EZ.push("X", "", "", "", "", "", 400, totIncome, 75000);
	        var excessIncome = Math.max(0, totIncome - 75000);
	        dollars1040EZ.push(excessIncome);
	        if(excessIncome > 0) {
	            dollars1040EZ.push("", "X");
	        } else {
	            dollars1040EZ.push("X", "");
	        }
	    } else {
	        dollars1040EZ.push("", "X", W2Total, combatTotal, FICA, 400, FICA, totIncome, 75000, "", "", FICA, "X", "");
	    }
	}

    if(getElement("canBeClaimed0") == "Yes" || (mStatus == "married1" && getElement("canBeClaimed1") == "Yes")) {
        var minStdDeduct = Math.max(W2Total + 300, 950);
        dollars1040EZ.push(W2Total, W2Total + 300, minStdDeduct);
        if(filingStatusNum == 2) dollars1040EZ.push(stdDeduction[1], Math.min(minStdDeduct, stdDeduction[1]));
        else if(filingStatusNum == 4) dollars1040EZ.push(stdDeduction[2], Math.min(minStdDeduct, stdDeduction[2]));
        else dollars1040EZ.push(stdDeduction[0], Math.min(minStdDeduct, stdDeduction[0]));
        minStdDeduct = dollars1040EZ[dollars1040EZ.length - 1];
        if(filingStatusNum == 2 && (getElement("canBeClaimed0") == "No" || getElement("canBeClaimed1") == "No"))
            dollars1040EZ.push(dependentAmt, minStdDeduct + dependentAmt);
        else dollars1040EZ.push(0, minStdDeduct);
    }

    setElement("totalPayments", withholdTotal);
    var AMailAddress = mailingAddress(1);
    var EZMailAddress = mailingAddress(2);
    if(withholdTotal >= taxLiability) {
        setElement("refund", withholdTotal - taxLiability);
        setElement("owed", "");
        AMailAddress = AMailAddress.replace("_", "0");
        EZMailAddress = EZMailAddress.replace("_", "0");
    } else {
        setElement("refund", "");
        setElement("owed", taxLiability - withholdTotal);
        AMailAddress = AMailAddress.replace("_", "1");
        EZMailAddress = EZMailAddress.replace("_", "1");
    }

    if(canFile1040EZ) {
        changeSummaryLineNumbers(2);
        setElement("AMailAddress", "If you would like to fill out form 1040A, mail it to <br/>" + AMailAddress);
    } else setElement("AMailAddress", "Mail your form 1040A to <br/>" + AMailAddress);
    setElement("EZMailAddress", "Mail your form 1040EZ to <br/>" + EZMailAddress);
    cellDisplay("showIfOldOrBlind", (blindOver65Total > 0));
    if(blindOver65Total > 0) {
        setElement("oldBlind2", (getElement("blind0") == "Yes"));
        setElement("oldBlind1", (getElement("age0").indexOf("70") > -1));
        setElement("oldBlind4", (mStatus == "married1" && getElement("blind1") == "Yes"));
        setElement("oldBlind3", (mStatus == "married1" && getElement("age1").indexOf("70") > -1));
    }
    cellDisplay("summaryView", true);
    cellDisplay("scheduleBLink", showScheduleB);
    cellDisplay("scheduleEICLink", EICAmt > 0 && dollarsScheduleEIC.length > 0);
    cellDisplay("scheduleLLink", showScheduleL);
    cellDisplay("form8917Link", showForm8917);
    cellDisplay("form8812Link", showForm8812);
    cellDisplay("SSWorksheet", ssTotal > 0);
    cellDisplay("DeductionWorksheet", (IRAVal[0] + IRAVal[1] + studentTotal > 0));
    if(showScheduleB) {
        dollarsScheduleB.length = 0;
        for (var i = 0; i < dollarsInterest.length; i++) dollarsScheduleB.push(dollarsInterest[i]);
        while (dollarsScheduleB.length < 20) dollarsScheduleB.push("");
        dollarsScheduleB.push(Math.round(intTotal));
        dollarsScheduleB.push(Math.round(intTotal));
        for (var i = 0; i < dollarsDividend.length; i++) dollarsScheduleB.push(dollarsDividend[i]);
        while (dollarsScheduleB.length < 42) dollarsScheduleB.push("");
        dollarsScheduleB.push(Math.round(divTotal), "X", "X");
    }
    if(showScheduleL) {
        dollarsScheduleL.length = 0;
        if(filingStatusNum == 2) dollarsScheduleL.push(stdDeduction[1]);
        else if(filingStatusNum == 4) dollarsScheduleL.push(stdDeduction[2]);
        else dollarsScheduleL.push(stdDeduction[0]);
        if(getElement("canBeClaimed0") == "Yes" || (mStatus == "married1" && getElement("canBeClaimed1") == "Yes")) {
            dollarsScheduleL.push("", "X");
            if(W2Total > 650) dollarsScheduleL.push("X", "", 950);
            else dollarsScheduleL.push("", "X", W2Total + 300);
            dollarsScheduleL.push(Math.min(dollarsScheduleL[0], dollarsScheduleL[5]));
        } else dollarsScheduleL.push("X", "", "", "", 0, dollarsScheduleL[0]);
        if(blindOver65Total > 0) {
            if(filingStatusNum == 2 || filingStatusNum == 5) dollarsScheduleL.push(1150 * blindOver65Total);
            else dollarsScheduleL.push(1450 * blindOver65Total);
        } else dollarsScheduleL.push(0);
    }
    cellDisplay("summaryPreview", false);
    var stateName = getElement("state", true);
    var stateLink = document.getElementById("stateTaxLink");
    switch (getElement("state"))
    {
        case "AZ" :
            stateLink.href = "http://www.azdor.gov/EServices/Individuals.aspx";
            break;
        case "CA" :
            stateLink.href = "http://www.ftb.ca.gov/online/calfile/index.asp";
            break;
        case "CO" :
            stateLink.href = "https://www.netfile.state.co.us/file2009/Welcome.jsp2";
            break;
        case "DC" :
            stateLink.href = "https://www.taxpayerservicecenter.com/individual/Ind_Logon.jsp?type=100";
            break;
        case "DE" :
            stateLink.href = "https://dorweb.revenue.delaware.gov/filepit/";
            break;
        case "HI" :
            stateLink.href = "http://www6.hawaii.gov/tax/b3_elf.htm";
            break;
        case "IL" :
            stateLink.href = "https://www.revenue.state.il.us/app/ifile/";
            break;
        case "IN" :
            stateLink.href = "https://secure.in.gov/apps/dor/ifile/2009/";
            break;
        case "KS" :
            stateLink.href = "http://www.ksrevenue.org/iiwebfile.htm";
            break;
        case "LA" :
            stateLink.href = "https://esweb.revenue.louisiana.gov/IndividualIncomeTax/Login.aspx";
            break;
        case "MA" :
            stateLink.href = "https://wfb.dor.state.ma.us/Income09/EligibleToFile.aspx";
            break;
        case "MD" :
            stateLink.href = "https://interactive.marylandtaxes.com/Individuals/iFile_ChooseForm/default.asp";
            break;
        case "NE" :
            stateLink.href = "https://ndr-nebfile.ne.gov/NebFile/public/login.faces";
            break;
        case "NJ" :
            stateLink.href = "https://njwebfile1.state.nj.us/nji/Welcome.asp";
            break;
        case "NM" :
            stateLink.href = "https://efile.state.nm.us/uls2/Logon.aspx";
            break;
        case "OH" :
            stateLink.href = "http://tax.ohio.gov/divisions/communications/electronic_filing_options.stm";
            break;
        case "PA" :
            stateLink.href = "https://pa.direct.file.state.pa.us/authentication.asp";
            break;
        case "RI" :
             stateLink.href = "http://www.tax.ri.gov/misc/efile.php";
             break;
        case "UT" :
            stateLink.href = "http://taxexpress.utah.gov/index.html?tab=income";
            break;
        case "VA" :
            stateLink.href = "http://www.tax.virginia.gov/site.cfm?alias=FileTaxReturns";
            break;
        case "WI" :
            stateLink.href = "http://www.revenue.wi.gov/wi_efile/index.html";
            break;
        default : stateName = "";
    }
    if (stateName == "") setElement("stateTaxLink", "")
    else setElement("stateTaxLink", "File your " + stateName + " tax return for free!");
}

function popChildCreditSheet(filingStatusNum, qualChildren, AGI, taxesOwed, formNum, additionalChildCredit, W2Amt, SSTaxTotal, MedicareTotal, netIncome, EICAmt) {
    var phaseOutAmt = (filingStatusNum==2)?110000:75000;
    var creditAmt = qualChildren * childCreditAmt;
    if(additionalChildCredit) {
        if(AGI > phaseOutAmt) creditAmt -= 50*Math.ceil((AGI-phaseOutAmt)/1000);
        if(creditAmt < 0 || creditAmt <= taxesOwed) return 0;
        creditAmt -= taxesOwed;
        var line6Amt = Math.round(Math.max(0, W2Amt-3000) * 0.15);
        if(line6Amt == 0 && qualChildren < 3) return 0;
        form8812.push(line6Amt);
        form8812.push(qualChildren>=3?"":"X");
        form8812.push(qualChildren>=3?"X":"");
        if(qualChildren >= 3 && line6Amt > creditAmt) {
            form8812.push("", "", "", "", "", "", creditAmt);
            return creditAmt;
        }
        form8812.push(SSTaxTotal + MedicareTotal, 0, SSTaxTotal + MedicareTotal, EICAmt);
        var line11Amt = SSTaxTotal + MedicareTotal - EICAmt;
        var line12Amt = Math.max(line6Amt, line11Amt);
        creditAmt = Math.min(creditAmt, line12Amt);
        form8812.push(line11Amt, line12Amt, creditAmt);
        return creditAmt;
    } else {
        var taxLn = taxLine[formNum];
        var HTML = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head>";
        if(taxLn.length > 2) taxLn = parseInt(taxLn.substr(taxLn.length - 2));
        else taxLn = parseInt(taxLn);
        HTML += "<body><h3>Child Tax Credit Worksheet</h3><h5>For your records only</h5><table border='0'><tr>";
        HTML += "<td colspan='3'>1. Number of qualifying children <u>" + qualChildren + "</u> X $" + childCreditAmt + ". Enter the result.</td>";
        HTML += numberBox("1");
        HTML += numberBox(creditAmt);
        HTML += "</tr>";
        HTML += "<tr><td>2. Enter the amount from Form " + formName[formNum] + ", line " + AGILine[formNum];
        HTML += "</td>"
        HTML += numberBox("2");
        HTML += numberBox(AGI);
        HTML += "</tr>";
        HTML += "<tr><td>3. Enter the amount shown below for your filing status.<br /><ul><li>Married Filing Jointly — $110,000</li><li>Single, head of household, or qualifying widow(er) — $75,000</li></ul></td>";
        HTML += numberBox("3");
        HTML += numberBox(phaseOutAmt);
        HTML += "</tr>";
        HTML += "<tr><td>4. Is the amount on line 2 more than the amount on line 3?<br />";
        HTML += "<u>" + ((AGI>phaseOutAmt)?"&nbsp;&nbsp;":"X") + "</u> <b>No.</b> Leave line 4 blank. Enter -0- on line 5, and go to line 6.<br />";
        HTML += "<u>" + ((AGI>phaseOutAmt)?"X":"&nbsp;&nbsp;") + "</u>  <b>Yes.</b> Subtract line 3 from line 2. Is the amount on line 2 more than the amount on line 3? If the result is not a multiple of $1,000, increase it to the next multiple of $1,000. For example, increase $425 to $1,000, increase $1,025 to $2,000, etc.</td>";
        HTML += numberBox("4");
        HTML += numberBox((AGI>phaseOutAmt)?1000*Math.ceil((AGI-phaseOutAmt)/1000):"");
        HTML += "</tr>";
        if(AGI > phaseOutAmt) creditAmt = Math.max(0, creditAmt - 50*Math.ceil((AGI-phaseOutAmt)/1000));
        HTML += "<tr><td colspan='3'>5. Multiply the amount on line 4 by 5% (.05). Enter the result.</td>";
        HTML += numberBox("5");
        HTML += numberBox((AGI>phaseOutAmt)?50*Math.ceil((AGI-phaseOutAmt)/1000):"0");
        HTML += "</tr>";
        HTML += "<tr><td colspan='3'>6. Is the amount on line 1 more than the amount on line 5?<br />";
        HTML += "<u>" + ((creditAmt==0)?"X":"&nbsp;&nbsp;") + "</u> <b>No.</b> You cannot take the child tax credit on Form 1040A, line 33. You also cannot take the additional child tax credit on Form 1040A, line 42. Complete the rest of your Form 1040A.<br />";
        HTML += "<u>" + ((creditAmt>0)?"X":"&nbsp;&nbsp;") + "</u> <b>Yes.</b> Subtract line 5 from line 1. Enter the result.</td>";
        HTML += numberBox("6");
        HTML += numberBox(creditAmt);
        HTML += "</tr>";
        HTML += "<tr><td colspan='3'>7. Enter the amount from Form " + formName[formNum] + ", line " + taxLn + "</td>";
        HTML += numberBox("7");
        HTML += numberBox(taxesOwed);
        HTML += "</tr>";
        HTML += "<tr><td>8. Add the amounts from Form 1040A:";
        for(var i = taxLn + 1; i < taxLn + 5; i++) 
            HTML += "<br/>Line " + i + " <u>0</u>";
        HTML += "Enter the total</td>";
        HTML += numberBox("8");
        HTML += numberBox("0");
        HTML += "</tr>";
        HTML += "<tr><td colspan='3'>9. Are the amounts on lines 7 and 8 the same?<br />";
        HTML += "<u>&nbsp;&nbsp;</u> <b>Yes.</b> You cannot take this credit because there is no tax to reduce.<br />";
        HTML += "<u>X</u> <b>No.</b> Subtract line 8 from line 7.</td>";
        HTML += numberBox("9");
        HTML += numberBox(taxesOwed);
        HTML += "</tr>";
        HTML += "<tr><td colspan='3'>10. Is the amount on line 6 more than the amount on line 9?<br />";
        HTML += "<u>" + ((creditAmt>taxesOwed)?"X":"&nbsp;&nbsp;") + "</u> <b>Yes.</b> Enter the amount from line 9.<br />";
        HTML += "<u>" + ((creditAmt<=taxesOwed)?"X":"&nbsp;&nbsp;") + "</u> <b>No.</b> Enter the amount from line 6.";
        HTML += "</td><td colspan='2'><table><tr>";
        HTML += numberBox("10");
        HTML += numberBox(Math.min(creditAmt, taxesOwed));
        HTML += "</tr><tr><td colspan='2'>Enter this amount on Form " + formName[formNum] + ", line ";
        HTML += childCreditLine[formNum] + "</td></tr></table></td></tr></table></body></html>";
        var taxForm = window.open("", "Child Tax Credit Worksheet", "");
        taxForm.document.write(HTML);
        taxForm.document.close();
    }
}

function popDeductionWorksheet() {
    var HTML = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head><body>";
    var phaseIn = new Array(0, 0, 0, 0);
    var multiplier;
    if(IRAWorksheet[13] + IRAWorksheet[14] > 0) {
        phaseIn[0] = IRANotDeductible[0] - IRAFullyDeductible[0];
        phaseIn[1] = IRANotDeductible[2] - IRAFullyDeductible[2];
        phaseIn[2] = Math.round(IRALimit[0] * 100 / phaseIn[0]);
        phaseIn[3] = Math.round(IRALimit[1] * 100 / phaseIn[0]);
        HTML += "<h3>IRA Deduction Worksheet</h3><h5>For your records only</h5><table border='1'>";
        HTML += "<tr><td colspan='2'></td><td><b>Your IRA</b></td><td><b>Spouse's IRA</b></td></tr>";
        HTML += "<tr><td colspan='2'>1a. Were you covered by a retirement plan?</td><td style='text-align:right'>" + IRAWorksheet[0] + "</td><td></td></tr>";
        HTML += "<tr><td colspan='3'>1b. If married filing jointly, was your spouse covered by a retirement plan?</td><td style='text-align:right'>" + IRAWorksheet[1] + "</td></tr>";
        HTML += "<tr><td colspan='4'><b>Next.</b> If you checked 'No' on line 1a (and 'No' on line 1b if married filing jointly), skip lines 2 through 6, enter the applicable amount below on line 7a (and line 7b if applicable), and go to line 8.<br />";
        HTML += "<ul><li>$" + IRALimit[0] + ", if under 50 at the end of " + currentTaxYear + ".</li>";
        HTML += "<li>$" + IRALimit[1] + ", if age 50 or older but under age 70 1/2 at the end of " + currentTaxYear + ".</li></ul>Otherwise, go to line 2.</td></tr>";
        HTML += "<tr><td colspan='2'>2. Enter the amount shown below that applies to you.<br />";
        HTML += "<ul><li>Single or head of household, enter $" + IRANotDeductible[0] + "</li>";
        HTML += "<li>Qualifying widow(er) enter $" + IRANotDeductible[2] + "</li>";
        HTML += "<li>Married filing jointly, enter $" + IRANotDeductible[2] + " in both columns. But if you checked 'No' on either line 1a or line 1b, enter $" + IRANotDeductible[1] + " for the person who was not covered by a plan</li></ul></td>";
        HTML += "<td style='text-align:right'>" + IRAWorksheet[2] + "</td><td style='text-align:right'>" + IRAWorksheet[3] + "</td></tr>";
        HTML += "<tr><td>3. Enter the amount from Form 1040A, line 15</td><td style='text-align:right'>" + IRAWorksheet[4] + "</td><td></td><td></td><tr>";
        HTML += "<tr><td>4. Enter the amount, if any, from Form 1040A, line 16</td><td style='text-align:right'>" + IRAWorksheet[5] + "</td><td></td><td></td></tr>";
        HTML += "<tr><td colspan='2'>5. Subtract line 4 from line 3. If married filing jointly, enter the result in both columns</td><td>" + IRAWorksheet[6] + "</td><td>" + IRAWorksheet[7] + "</td></tr>";
        HTML += "<tr><td colspan='2'>6. Is the amount on line 5 less than the amount on line 2?<br />";
        if(IRAWorksheet[6] >= IRAWorksheet[2] && IRAWorksheet[7] >= IRAWorksheet[3]) HTML += "<b>√</b>";
        HTML += "<b>No</b> None of your IRA contributions are deductible. For details on nondeductible IRA contributions, see Form 8606.<br/>";
        if(IRAWorksheet[6] < IRAWorksheet[2] || IRAWorksheet[7] < IRAWorksheet[3]) HTML += "<b>√</b>";
        HTML += "<b>Yes</b> Subtract line 5 from line 2 in each column. Follow the instruction below that applies to you.<br/>";
        HTML += "<ul><li>If single or head of household, and the result is $" + phaseIn[0] + " or more, enter the applicable amount below on line 7 for that column and go to line 8.<br />";
        HTML += "i. $" + IRALimit[0] + " if under 50 at the end of " + currentTaxYear + ".<br />";
        HTML += "ii. $" + IRALimit[1] + " if age 50 or older but under age 70 1/2 at the end of " + currentTaxYear + ".<br />Otherwise, go to line 7.</li>";
        HTML += "<li>If married filing jointly or qualifying widow(er) and the result is $" + phaseIn[1] + " or more ($" + phaseIn[0] + " or more in the column for the IRA of a person who was not covered by a retirement plan), enter the applicable amount below on line 7 for that column and go to line 8.<br />";
        HTML += "i. $" + IRALimit[0] + " if under 50 at the end of " + currentTaxYear + ".<br />";
        HTML += "ii. $" + IRALimit[1] + " if age 50 or older but under age 70 1/2 at the end of " + currentTaxYear + ".<br />Otherwise, go to line 7.</li></ul></td><td>";
        if(IRAWorksheet[2] > IRAWorksheet[6]) HTML += IRAWorksheet[8];
        HTML += "</td><td>";
        if(IRAWorksheet[3] > IRAWorksheet[7]) HTML += IRAWorksheet[9];
        HTML += "</td></tr>";
        HTML += "<tr><td colspan='2'>7. Multiply lines 6a and 6b by the percentage below that applies to you. If the result is not a multiple of $10, increase it to the next multiple of $10 (for example, increase $490.30 to $500). If the result is $200 or more, enter the result. But if it is less than $200, enter $200.<br />";
        HTML += "<ul><li>Single or head of household, multiply by " + phaseIn[2] + "% (." + phaseIn[2] + ") (or by " + phaseIn[3] + "% (." + phaseIn[3] + ") in the column for the IRA of a person who is age 50 or older at the end of " + currentTaxYear + ")</li>";
        phaseIn[2] /= 2;
        phaseIn[3] /= 2;
        HTML += "<li>Married filing jointly or qualifying widow(er), multiply by " + phaseIn[2] + "% (." + phaseIn[2] + ") (or by " + phaseIn[3] + "% (." + phaseIn[3] + ") in the column for the IRA of a person who is age 50 or older at the end of " + currentTaxYear + "). But if you checked 'No' on either 1a or 1b, then in the column for the IRA of the person who was not covered by a retirement plan, multiply by " + (2 * phaseIn[2]) + "% (." + (2 * phaseIn[2]) + ") (or by " + (2 * phaseIn[3]) + "% (." + (2 * phaseIn[3]) + ") in the column for the IRA of a person who is age 50 or older at the end of " + currentTaxYear + ")</li></ul></td>";
        HTML += "<td>" + IRAWorksheet[10] + "</td><td>" + IRAWorksheet[11] + "</td></tr>";
        HTML += "<tr><td>8. Enter the amount from form 1040A, line 7. Include any non-taxable combat pay. This amount should be reported in box 12 of form W-2 with code Q</td><td>" + IRAWorksheet[12] + "</td><td></td><td></td></tr>";
        HTML += "<tr><td colspan='4'><b><font size='+1'>CAUTION</font></b>If married filing jointly and line 8 is less than $" + (2 * IRALimit[0]) + " ($" + (IRALimit[0] + IRALimit[1]) + " if one spouse is age 50 or older at the end of " + currentTaxYear + "; $" + (2 * IRALimit[1]) + " if both spouses are age 50 or older at the end of " + currentTaxYear + "), <b>stop here</b> and see Pub. 590 to figure your IRA deduction.</td></tr>";
        HTML += "<tr><td colspan='2'>9. Enter traditional IRA contributions made, or that will be made by " + thisYearsDueDate + ", " + nextTaxYear + ", for " + currentTaxYear + " to your IRA on line 9a and to your spouse’s IRA on line 9b</td>";
        HTML += "<td>" + IRAWorksheet[13] + "</td><td>" + IRAWorksheet[14] + "</td></tr>";
        HTML += "<tr><td colspan='2'>10. On line 10a, enter the smallest of line 7a, 8, or 9a. On line 10b, enter the smallest of line 7b, 8, or 9b. This is the most you can deduct. Add the amounts on lines 10a and 10b and enter the total on Form 1040A, line 17. Or, if you want, you can deduct a smaller amount and treat the rest as a nondeductible contribution (see Form 8606)</td>";
        HTML += "<td>" + IRAWorksheet[15] + "</td><td>" + IRAWorksheet[16] + "</td></tr></table>";
    }
    if(studentWorksheet[0] > 0) {
        HTML += "<h3>Student Loan Interest Deduction Worksheet</h3><h5>For your records only</h5><table border='1'>";
        HTML += "<tr><td colspan='2'>1. Enter total interest you paid in " + currentTaxYear + " on qualified student loans. Do not enter more than $2,500.</td><td>" + studentWorksheet[0] + "</td></tr>";
        HTML += "<tr><td>2. Enter the amount from Form 1040A, line 15</td><td>" + studentWorksheet[1] + "</td><td></td></tr>";
        HTML += "<tr><td>3. Enter the total of the amounts from Form 1040A, lines 16 and 17</td><td>" + (studentWorksheet[1] - studentWorksheet[2]) + "</td><td></td></tr>";
        HTML += "<tr><td>4. Subtract line 3 from line 2</td><td>" + studentWorksheet[2] + "</td><td></td></tr>";
        HTML += "<tr><td>5. Enter the amount shown below for your filing status.<br />";
        HTML += "Single, head of household or qualifying widow(er) --- " + studentLoanFullyDeductible[0] + "<br />";
        HTML += "Married, filing jointly --- " + studentLoanFullyDeductible[1] + "</td>";
        HTML += "<td>" + studentWorksheet[3] + "</td><td></td></tr>";
        HTML += "<tr><td>6. Is the amount on line 4 more than the amount on line 5?<br />";
        HTML += "<table border='0'><tr><td>";
        if(studentWorksheet[2] <= studentWorksheet[3]) HTML += "<b>√</b>";
        HTML += "<b>No.</b> Skip lines 6 and 7, enter -0- on line 8, and go to line 9.</td></tr>";
        HTML += "<tr><td>";
        if(studentWorksheet[2] > studentWorksheet[3]) HTML += "<b>√</b>";
        HTML += "<b>Yes.</b> Subtract line 5 from line 4.</td></tr></table></td><td>" + Math.max(0, studentWorksheet[2] - studentWorksheet[3]) + "</td><td></td></tr>";
        HTML += "<tr><td colspan='2'>7. Divide line 6 by $" + (studentLoanNotDeductible[0] - studentLoanFullyDeductible[0]) + "($" + (studentLoanNotDeductible[1] - studentLoanFullyDeductible[1]) + " if married filing jointly). Enter the result as a decimal (rounded to at least 3 places). If the result is 1.000 or more, enter 1.000.</td><td>";
        multiplier = Math.round(1000000 * Math.max(Math.min((studentWorksheet[2] - studentWorksheet[3]) / (studentWorksheet[4] - studentWorksheet[3]), 1), 0)) / 1000000;
        HTML += multiplier;
		HTML += "</td></tr>";
		HTML += "<tr><td colspan='2'>8. Multiply line 1 by line 7</td><td>" + Math.round(multiplier * studentWorksheet[0]) + "</td></tr>";
		HTML += "<tr><td colspan='2'>9. <b>Student loan interest deduction.</b> Subtract line 8 from line 1. Enter the result here and on Form 1040A, line 18</td><td>" + Math.round((1 - multiplier) * studentWorksheet[0]) + "</td></tr></table>";
    }
    HTML += "</body>";
    var taxForm = window.open("", "Deduction Worksheets", "");
    taxForm.document.write(HTML);
    taxForm.document.close();
}

function popSSWorksheet() {
    var HTML = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head><body>";
    HTML += "<h3>Social Security Income Worksheet</h3><h5>For your records only</h5><table border='1'>";
    HTML += "<tr><td>1. Enter the total amount from <b>the net benefits box</b> of <b>all</b> your <b>Forms SSA-1099</b> and <b>Forms RRB-1099</b>.<br/>Also, enter this amount on Form 1040A, line 14a</td><td style='text-align:right'>" + ssWorksheet[0] + "</td><td></td></tr>";
    HTML += "<tr><td colspan='2'>2. Enter one-half of line 1.</td><td style='text-align:right'>" + ssWorksheet[1] + "</td></tr>";
    HTML += "<tr><td colspan='2'>3. Enter the total of the amounts from Form 1040A, lines 7, 8a, 9a, 10, 11b, 12b, and 13</td><td style='text-align:right'>" + ssWorksheet[2] + "</td></tr>";
    HTML += "<tr><td colspan='2'>4. Enter the amount, if any, from Form 1040A, line 8b</td><td style='text-align:right'>" + ssWorksheet[3] + "</td></tr>";
    HTML += "<tr><td colspan='2'>5. Add lines 2, 3, and 4</td><td style='text-align:right'>" + ssWorksheet[4] + "</td></tr>";
    HTML += "<tr><td colspan='2'>6. Enter the total of the amounts from Form 1040A, lines 16 and 17</td><td style='text-align:right'>" + ssWorksheet[5] + "</td></tr>";
    HTML += "<tr><td colspan='2'>7. Subtract line 6 from line 5, if the amount is less than 0, enter 0 here and on Form 1040A, line 14b.</td><td style='text-align:right'>" + ssWorksheet[6] + "</td></tr>";
    HTML += "<tr><td colspan='2'>8. If you are married filing jointly, enter $32,000, otherwise enter $25,000.</td><td style='text-align:right'>" + ssWorksheet[7] + "</td></tr>";
    HTML += "<tr><td colspan='2'>9. Subtract line 8 from line 7, if the amount is less than 0, enter 0 here and on Form 1040A, line 14b.</td><td style='text-align:right'>" + ssWorksheet[8] + "</td></tr>";
    HTML += "<tr><td colspan='2'>10. If you are married filing jointly, enter $12,000, otherwise enter $9,000.</td><td style='text-align:right'>" + ssWorksheet[9] + "</td></tr>";
    HTML += "<tr><td colspan='2'>11. Subtract line 10 from line 9, if the amount is less than 0, enter 0.</td><td style='text-align:right'>" + ssWorksheet[10] + "</td></tr>";
    HTML += "<tr><td colspan='2'>12. Enter the <b>smaller</b> of line 9 or line 10.</td><td style='text-align:right'>" + ssWorksheet[11] + "</td></tr>";
    HTML += "<tr><td colspan='2'>13. Enter one-half of line 12.</td><td style='text-align:right'>" + ssWorksheet[12] + "</td></tr>";
    HTML += "<tr><td colspan='2'>14. Enter the <b>smaller</b> of line 2 or line 13.</td><td style='text-align:right'>" + ssWorksheet[13] + "</td></tr>";
    HTML += "<tr><td colspan='2'>15. Multiply line 11 by 85% (.85).</td><td style='text-align:right'>" + ssWorksheet[14] + "</td></tr>";
    HTML += "<tr><td colspan='2'>16. Add lines 14 and 15</td><td style='text-align:right'>" + ssWorksheet[15] + "</td></tr>";
    HTML += "<tr><td colspan='2'>17. Multiply line 1 by 85% (.85).</td><td style='text-align:right'>" + ssWorksheet[16] + "</td></tr>";
    HTML += "<tr><td colspan='2'>18. <b>Taxable social security benefits.</b> Enter the <b>smaller</b> of line 16 or line 17. Also enter this amount on Form 1040A, line 14b.</td><td style='text-align:right'>" + ssWorksheet[17] + "</td></tr>";
    HTML += "</body>";
    var taxForm = window.open("", "Social Security Income Worksheet", "");
    taxForm.document.write(HTML);
    taxForm.document.close();
}
summaryLoaded = 1;
