﻿function errorIfNotNumeric(field, otherChar) {
    var commaSep = false;
    var leadingDollar = false;
    var numValue = "";
    var newValue = "";
    var nDecimals = 0;
    numValue = (field.value).replace("[calculated value]", "");
    if(otherChar){
        if(numValue.indexOf(otherChar)) {
            numValue = numValue.replace(otherChar, "");
            commaSep = true;
        }
    } else {
        if(numValue.substr(0, 1) == "$") {
            leadingDollar = true;
            numValue = numValue.substr(1);
        }
        if(numValue.indexOf(",") > -1) {
            numValue = numValue.replace(",", "");
            commaSep = true;
        }
    }
    if(isNaN(numValue)) {
        alert("Unrecognizable number input");
        var txtBox = document.getElementById(field.id);
        txtBox.select();
        txtBox.focus();
        return false;
    }
    if(otherChar == "-") {      //SSN Format
        newValue = numValue;
        if(commaSep) {
            if(numValue.length >= 5) newValue = numValue.substr(0, 3) + "-" + numValue.substr(3, 2) + "-" + numValue.substr(5);
            if(numValue.length == 4) newValue = "--" + numValue;
        }
    } else {                    //Default is number format
        numValue = Math.round(numValue * 100) / 100;
        newValue += numValue;
        var i = newValue.indexOf(".");
        if(i != -1)
            while(newValue.length < i + 3) newValue += "0";
        else
            i = newValue.length;
        if(commaSep) {
            i -= 3;
            while(i > 0) {
                newValue = newValue.substr(0, i) + "," + newValue.substr(i);
                i -= 3;
            }
        }
        if(leadingDollar) newValue = "$" + newValue;
    }
    field.value = newValue;
}
function isMoney(value) {
    if(value=="" || value == true || value == false) return false;
    if(!isNaN(value)) return true;
    var retval = value.replace("$", "");
    retval = retval.replace(",", "");
    return !isNaN(retval);
}
function parseMoney(value) {
    if(value == "") return 0;
    if(isNaN(value)) {
        if(isMoney(value)) {
            var retval = value.replace("$", "");
            retval = retval.replace(",", "");
            return parseFloat(retval);
        } else return 0;
    } else return parseFloat(value);
}
function cellDisplay(cell, show) {
    if (!document.getElementById(cell)) return;
    if (show == true) {
        document.getElementById(cell).style.display = "";
    } else {
        document.getElementById(cell).style.display = "none";
    }
}

function encryptDecrypt(inp, maskBadChars) {
    var vals = new Array(31, 30, 29, 28, 27, 26, 25, 23, 22, 21, 19, 15, 14, 13, 11, 7);
    var retval = "";
    var x;
    for(var i = 0; i < inp.length; i++) {
        if(inp.charCodeAt(i) == 176) retval += String.fromCharCode(59 ^ vals[i % vals.length]);
        else if(inp.charCodeAt(i) == 177) retval += String.fromCharCode(96 ^ vals[i % vals.length]);
        else if(inp.charCodeAt(i) == 178) retval += String.fromCharCode(61 ^ vals[i % vals.length]);
        else {
            x = String.fromCharCode(inp.charCodeAt(i) ^ vals[i % vals.length]);
            if(maskBadChars == true) {
                if(x == ";") x = String.fromCharCode(176);
                else if(x == "¡") x = String.fromCharCode(177);
                else if(x == "=") x = String.fromCharCode(178);
            }
            retval += x;
        }
    }
    return retval;
}

function pwdCompare() {
    var badChar;
    var pwd1 = getElement("pwd1");
    var pwd2 = getElement("pwd2");
    if(document.getElementById("password2").style.display == "") {
        for (var i = 128; i < 130; i++) {
            badChar = String.fromCharCode(i);
            if((pwd1 + pwd2).indexOf(badChar) > -1) {
                alert("The " + badChar + " character may not be used in a password");
                setElement("pwd1", pwd1.replace(badChar, ""));
                setElement("pwd2", pwd2.replace(badChar, ""));
                return;
            }
        }
        cellDisplay("pwdMatch", (pwd1 != pwd2));
    }
}

function calculateStateByZip(zip) {
    var nzip = parseInt(zip, 10);
    var state = "";
    switch(true) {
        case nzip == 4 || nzip == 63: state = "NY"; break;
        case nzip < 8 || nzip == 9: state = "PR"; break;
        case nzip < 28 || nzip == 55: state = "MA"; break;
        case nzip < 30: state = "RI"; break;
        case nzip < 39: state = "NH"; break;
        case nzip < 50: state = "ME"; break;
        case nzip < 60: state = "VT"; break;
        case nzip < 70: state = "CT"; break;
        case nzip < 90: state = "NJ"; break;
        case nzip < 150: state = "NY"; break;
        case nzip < 197: state = "PA"; break;
        case nzip < 200: state = "DE"; break;
        case nzip < 206: state = "DC"; break;
        case nzip < 220: state = "MD"; break;
        case nzip < 247: state = "VA"; break;
        case nzip < 270: state = "WV"; break;
        case nzip < 290: state = "NC"; break;
        case nzip < 300: state = "SC"; break;
        case nzip < 320: state = "GA"; break;
        case nzip == 340: break;
        case nzip < 350: state = "FL"; break;
        case nzip < 370: state = "AL"; break;
        case nzip < 386: state = "TN"; break;
        case nzip < 400: state = "MS"; break;
        case nzip < 430: state = "KY"; break;
        case nzip < 460: state = "OH"; break;
        case nzip < 480: state = "IN"; break;
        case nzip < 500: state = "MI"; break;
        case nzip < 530: state = "IA"; break;
        case nzip < 550: state = "WI"; break;
        case nzip < 570: state = "MN"; break;
        case nzip < 580: state = "SD"; break;
        case nzip < 590: state = "ND"; break;
        case nzip < 600: state = "MT"; break;
        case nzip < 630: state = "IL"; break;
        case nzip < 660: state = "MO"; break;
        case nzip < 680: state = "KS"; break;
        case nzip < 700: state = "NE"; break;
        case nzip < 715: state = "LA"; break;
        case nzip < 730: state = "AR"; break;
        case nzip < 750: state = "OK"; break;
        case nzip == 755: break;
        case nzip < 800 || nzip == 885: state = "TX"; break;
        case nzip < 820: state = "CO"; break;
        case nzip < 832: state = "WY"; break;
        case nzip < 840: state = "ID"; break;
        case nzip < 850: state = "UT"; break;
        case nzip < 870: state = "AZ"; break;
        case nzip < 889: state = "NM"; break;
        case nzip < 900: state = "NV"; break;
        case nzip < 962: state = "CA"; break;
        case nzip == 968: state = "HI"; break;
        case nzip < 969: break;
        case nzip < 980: state = "OR"; break;
        case nzip < 995: state = "WA"; break;
        case nzip > 995: state = "AK"; break;
        default: state = "";
    }
    return state;
}

function selectState() {
    if(getElement("state") != "") return;   //Don't mess with the user's selection
    var zip = getElement("zip");
    if(zip.length < 5) return;
    zip = zip.substr(0, 3);
    if(isNaN(zip)) return;
    var state = calculateStateByZip(zip);
    if(state != "") setElement("state", state);
}

function mailingAddress(formNum) {
    var irs = "Internal Revenue Service<br/>";
    var zipPlus4 = "-0_1" + ((formNum==1)?"5":"4");
    var ag = irs + "Atlanta, GA 39901" + zipPlus4;
    var fc = irs + "Fresno, CA 93888" + zipPlus4;
    var kcm = irs + "Kansas City, MO 64999" + zipPlus4;
    var at = irs + "Austin, TX 73301" + zipPlus4;
    var state = getElement("state");
    var zip = getElement("zip");
    if(state == "") state = calculateStateByZip(zip);
    switch (state.substr(0, 1)) {
        case "D" : 
        case "R" : return kcm; break;
        case "F" : return ag; break;
        case "H" : 
        case "I" : 
        case "U" : return fc; break;
        case "L" : 
        case "T" : return at; break;
    }
    switch (state.substr(1, 1)) {
        case "C" : return ag; break;
        case "H" : 
        case "J" : return kcm; break;
        case "I" :
        case "K" :
        case "M" :
        case "N" :
        case "Z" : return fc; break;
        case "L" : return at; break;
    }
    switch (state) {
        case "GA" : return ag; break;
        case "KY" :
        case "MS" : return at; break;
        case "AR" :
        case "CT" :
        case "MA" :
        case "MD" :
        case "ME" :
        case "MO" :
        case "NY" :
        case "PA" :
        case "VA" :
        case "VT" :
        case "WV" : return kcm; break;
        case "CA" :
        case "CO" :
        case "KS" :
        case "MT" :
        case "ND" :
        case "NE" :
        case "NV" :
        case "OR" :
        case "SD" :
        case "WA" :
        case "WY" : return fc; break;
        default : return at; break;
    }
    return "Unknown, consult your instruction booklet for mailing address";
}

function pushSSNontoArray(SSN, arr) {
/* This will be used when the SSN must be broken into 3 parts 
    if(SSN.length > 0) {
        SSN = SSN.replace("-", "");
        if(SSN.length == 4) arr.push("", "", SSN);
        else {
            arr.push(SSN.substr(0, 3));
            if(SSN.length > 3) arr.push(SSN.substr(3, 2));
            else arr.push("");
            if(SSN.length > 5) arr.push(SSN.substr(5, 4));
            else arr.push("");
        }
    } else arr.push("", "", ""); */
    arr.push(SSN);
}

function setColor(cellName, colorName) {
    if(document.getElementById(cellName))
        document.getElementById(cellName).style.color = colorName;
    if((getElement(cellName)).indexOf("SSTax") > 0 || (getElement(cellName)).indexOf("Medicare") > 0)
        cellDisplay("summaryInstructions", false);
}

function popInstructions(selectBox) {
    window.open("http://www.irs.gov/taxtopics/tc" + getElement(selectBox) + ".html");
}

function popForm(img, dollars, tops, lefts, heights, widths, sizes, reqFields, formName, d2, t2, l2, h2, w2, s2, r2) {
    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>";
    HTML += "<body><img src='" + img + "' alt='Be sure to set your margins to .5 inches all the way around and clear your header and footer.' style='position:absolute;top:0px;left:0px;width:700px;height:900px' />";
    if(!inSeason)
        HTML += "<div style='position:absolute;top:0px;left:0px;width:700px;height:30px;background:white;font-size:24px;'>Not a valid tax form, currently in test mode!</div>";
    for (var i = 0; i < dollars.length; i++) {
        if(reqFields[i] == 1 || isNaN(dollars[i]) == 1 || dollars[i] > 0) {
            HTML += "<div style='position:absolute;top:" + tops[i] + "px;left:" + lefts[i] + "px;width:" + widths[i] + "px;height:" + heights[i] + "px;background:white;font-size:" + sizes[i];
            if(isNaN(dollars[i])) HTML += "px;text-align:left'>" + dollars[i] + "</div>";
            else HTML += "px;text-align:right'><tt>" + dollars[i] + "</tt></div>";
        }
    }
    if(d2) {
        for (var i=0; i < d2.length; i++) {
            if(r2[i] == 1 || isNaN(d2[i]) == 1 || d2[i] > 0) {
                HTML += "<div style='position:absolute;top:" + t2[i] + "px;left:" + l2[i] + "px;width:" + w2[i] + "px;height:" + h2[i] + "px;background:white;font-size:" + s2[i];
                HTML += "px;text-align:left'><tt>" + d2[i] + "</tt></div>";
            }
        }
    }
    HTML += "</body>";
    var taxForm = window.open("", formName, "");
    taxForm.document.write(HTML);
    taxForm.document.close();
}

function pop1040EZ() {
    if(inSeason == true || confirm("Warning!  This form is only viewable for testing purposes do not print it out!"))
        popForm("1040EZ.jpg", dollars1040EZ.slice(0, 16), top1040EZ.slice(0, 16), left1040EZ.slice(0, 16), height1040EZ.slice(0, 16), width1040EZ.slice(0, 16), size1040EZ.slice(0, 16), required1040EZ.slice(0, 16), "1040EZ page 1");
}

function pop1040EZ2() {
    if(inSeason == true || confirm("Warning!  This form is only viewable for testing purposes do not print it out!"))
        popForm("1040EZ2.jpg", dollars1040EZ.slice(16), top1040EZ.slice(16), left1040EZ.slice(16), height1040EZ.slice(16), width1040EZ.slice(16), size1040EZ.slice(16), required1040EZ.slice(16), "1040EZ page 2");
}

function pop1040A1() {
    var len = dependentInfo.length;
    if(inSeason == true || confirm("Warning!  This form is only viewable for testing purposes do not print it out!")) {
        if(len == 0)
            popForm("1040A1.jpg", dollars1040A.slice(0, 25), top1040A.slice(0, 25), left1040A.slice(0, 25), 
                    height1040A.slice(0, 25), width1040A.slice(0, 25), size1040A.slice(0, 25), 
                    required1040A.slice(0, 25), "1040A");
        else
            popForm("1040A1.jpg", dollars1040A.slice(0, 25), top1040A.slice(0, 25), left1040A.slice(0, 25),
                    height1040A.slice(0, 25), width1040A.slice(0, 25), size1040A.slice(0, 25),
                    required1040A.slice(0, 25), "1040A", dependentInfo, dtop1040A, dleft1040A,
                    dheight1040A, dwidth1040A, dsize1040A, drequired1040A);
    }
}

function pop1040A2() {
    if(inSeason == true || confirm("Warning!  This form is only viewable for testing purposes do not print it out!"))
        popForm("1040A2.jpg", dollars1040A.slice(24), top1040A.slice(25), left1040A.slice(25), 
                height1040A.slice(25), width1040A.slice(25), size1040A.slice(25), 
                required1040A.slice(25), "1040A, page 2");
}

function popScheduleB() {
    if(inSeason == true || confirm("Warning!  This form is only viewable for testing purposes do not print it out!"))
        popForm("ScheduleB.jpg", dollarsScheduleB, topScheduleB, leftScheduleB, 
                heightScheduleB, widthScheduleB, sizeScheduleB, 
                requiredScheduleB, "Schedule B");
}

function popScheduleM() {
    if(inSeason == true || confirm("Warning!  This form is only viewable for testing purposes do not print it out!"))
        popForm("ScheduleM.jpg", dollarsScheduleM, topScheduleM, leftScheduleM, 
                heightScheduleM, widthScheduleM, sizeScheduleM, 
                requiredScheduleM, "Schedule M");
}

function popScheduleEIC() {
    if(inSeason == true || confirm("Warning!  This form is only viewable for testing purposes do not print it out!")) {
        if(dollarsScheduleEIC.length > 27) {
            if(dollarsScheduleEIC[2] == "") {
                for(var i = dollarsScheduleEIC.length - 7; i > 11; i -= 9) {
                    if(dollarsScheduleEIC[i] != "") {
                        for(var j = 0; j < 9; j++) dollarsScheduleEIC[j] = dollarsScheduleEIC[i+j-2];
                        if(i + 9 <= dollarsScheduleEIC.length) {
                            for(var j = 0; j < 9; j++)
                                dollarsScheduleEIC[i+j-2] = dollarsScheduleEIC[dollarsScheduleEIC.length+j-9];
                        }
                        dollarsScheduleEIC.length -= 9;
                    }
                }
            }
            if(dollarsScheduleEIC[11] == "") {
                for(var i = dollarsScheduleEIC.length - 7; i > 11; i -= 9) {
                    if(dollarsScheduleEIC[i] != "") {
                        for(var j = 0; j < 9; j++) dollarsScheduleEIC[j+9] = dollarsScheduleEIC[i+j-2];
                        if(i + 9 <= dollarsScheduleEIC.length) {
                            for(var j = 0; j < 9; j++)
                                dollarsScheduleEIC[i+j-2] = dollarsScheduleEIC[dollarsScheduleEIC.length+j-9];
                        }
                        dollarsScheduleEIC.length -= 9;
                    }
                }
            }
            dollarsScheduleEIC.length = 27;
        }
        popForm("ScheduleEIC.jpg", dollarsScheduleEIC, topScheduleEIC, leftScheduleEIC, 
                heightScheduleEIC, widthScheduleEIC, sizeScheduleEIC, 
                requiredScheduleEIC, "Schedule EIC");
    }
}

function popForm8917() {
    if(inSeason == true || confirm("Warning!  This form is only viewable for testing purposes do not print it out!")) {
        if(form8917.length > 22) form8917.length = 22;
        popForm("Form8917.jpg", form8917,
                top8917, left8917, height8917, width8917, size8917, required8917, "Form 8917");
    }
}

function popForm8812() {
    if(inSeason == true || confirm("Warning!  This form is only viewable for testing purposes do not print it out!")) {
        if(form8812.length > 22) form8812.length = 22;
        popForm("Form8812.jpg", form8812,
                top8812, left8812, height8812, width8812, size8812, required8812, "Form 8812");
    }
}

function showHist(arrayElem) {
    if(!histoire[arrayElem]) histoire[arrayElem] = 1;
    showTab(histoire[arrayElem], true);
}
function histBack() {
    if(histPos > 0) showHist(--histPos);
    cellDisplay("previous", histPos > 0);
    cellDisplay("next", histPos < histoire.length - 1);
}
function histForward() {
    if(histPos < histoire.length - 1) showHist(++histPos);
    cellDisplay("previous", histPos > 0);
    cellDisplay("next", histPos < histoire.length - 1);
}

function writeOption(val, txt) {
    return "<option value='" + val + "'>" + txt + "</option>";
}
function writeOptions() {
    var retval = "";
    for(var i = 0; i < arguments.length; i+=2) retval += writeOption(arguments[i], arguments[i+1]);
    return retval;
}

function primaryOrSpouse(id, msg) {
    if(getElement("maritalStatus") == "married1") {
        var retval = "<tr><td>" + msg + "</td><td><select id='" + id + "'>";
        var primary = getElement("filerNameInput0");
        var spouse = getElement("filerNameInput1");
        retval += writeOption("primary", ((primary=="") ? "Primary Taxpayer" : primary));
        retval += writeOption("spouse", ((spouse=="") ? "Spouse" : spouse));
        retval += "</td></tr>";
        return retval;
    } else
        return "<tr><td></td><td><input type='hidden' id='" + id + "' value='primary'/></td></tr>";
}
function primarySpouseDependent(id, msg, canBeClaimed) {
    var retval = "<tr><td>";
    var dep = new Array();
    var primary = getElement("filerNameInput0");
    var spouse = getElement("filerNameInput1");
    if(primary == "") primary = "Primary Taxpayer";
    if(spouse == "") spouse = "Spouse";
    for (var i = 0; i < 10; i++)
        if(dependents[i] != null) dep.push(dependents[i]);

    if(canBeClaimed == "primary")
        return retval + "</td><td><input type='hidden' id='" + id + "' value='" + spouse + "'/></td></tr>";
    else if(canBeClaimed == "spouse")
        return retval + "</td><td><input type='hidden' id='" + id + "' value='" + primary + "'/></td></tr>";
    else if(getElement("maritalStatus") == "married1") {
        retval += msg + "</td><td><select id='" + id + "'>";
        retval += writeOption(primary, primary);
        retval += writeOption(spouse, spouse);
    } else if (dep.length == 0)
        return retval + "</td><td><input type='hidden' id='" + id + "' value='" + primary + "'/></td></tr>";
    else {
        retval += msg + "</td><td><select id='" + id + "'>";
        retval += writeOption(primary, primary);
    }

    for (var i = 0; i < dep.length; i++) {
        if(dep[i].indexOf("¡") == -1) retval += writeOption(dep[i], dep[i]);
        else {
            var temp = dep[i].split("¡");
            retval += writeOption(temp[1], temp[0]);
        }
    }

    retval += "</select></td></tr>";
    return retval;
}

function createW2Cell(cell, num) {
    var i = num.substring(2, 1);
    var blank = "<table>" + primaryOrSpouse("n" + num + "earner", "Who earned these wages");
    blank += "<tr><td>Employer name (optional) </td><td><input type='text' id='n" + num + "name' size='30'/></td></tr>";
    blank += "<tr><td>Wages<br/>(from box 1 of W-2)</td><td><input type='text' id='n" + num + W2Line[0] + "' size='15'" + errorIfNotNum + "></td></tr>";
    blank += "<tr><td>Federal Tax Withheld<br/>(from box 2 of W-2)</td><td><input type='text' id='n" + num + withholdLine[0] + "' size='15'" +errorIfNotNum + "></td></tr>";
    blank += "<tr id='SSTax" + i + "' style='color:Red;display:none'><td>Social Security Tax Withheld<br/>(from box 4 of W-2)</td><td><input type='text' id='n" + num + "SSTax' size='15' onKeyUp='javascript:setColor(\"SSTax" + i + "\", \"Black\");' " + errorIfNotNum + "></td></tr>";
    blank += "<tr id='Medicare" + i + "'style='color:Red;display:none'><td>Medicare Tax Withheld<br/>(from box 6 of W-2)</td><td><input type='text' id='n" + num + "Medicare' size='15' onKeyUp='javascript:setColor(\"Medicare" + i + "\", \"Black\");' " + errorIfNotNum + "></td></tr>";
    blank += "<tr id='Combat" + i + "' style='color:Red;display:none'><td>Combat Pay<br/>(from box 14 code Q)</td><td><input type='text' id='n" + num + combatLine[0] + "' size='15'" + errorIfNotNum + "></td></tr>";
    blank += "<tr><td>Is box 13, retirement pay, checked? </td><td><input type='checkbox' id='n" + num + "ret'></td></tr>";
    blank += saveLine1 + "W2(\"" + cell + saveLine2 + "W2(\"" + cell + saveLine3;
    setElement(cell, blank);
    cellDisplay(cell, true);
    if(i != "9") {
        var next = (parseInt(num, 10) + 1).toString();
        cellDisplay("Empty" + next, true);
    }
    if(i != "0") {
        cellDisplay("SSTax" + i, (document.getElementById("SSTax0").style.display == ""));
        cellDisplay("Medicare" + i, (document.getElementById("SSTax0").style.display == ""));
        cellDisplay("Combat" + i, (document.getElementById("Combat0").style.display == ""));
    }
}

function createIntCell(cell, num) {
    var blank = "<table><tr><td>Bank name (optional) </td><td><input type='text' id='n" + num + "name' size='30'/></td></tr>";
    blank += "<tr><td>Interest Income<br/>(from box 1 of 1099-Int)</td><td><input type='text' id='n" + num + intLine[0] + "' size='15'" + errorIfNotNum + "></td></tr>";
    blank += "<tr><td>Tax Exempt Interest<br/>(from box 3 of 1099-Int)</td><td><input type='text' id='n" + num + exemptIntLine[0] + "' size='15'" + errorIfNotNum + "></td></tr>";
    blank += "<tr><td>Federal Tax Withheld<br/>(from box 4 of 1099-Int)</td><td><input type='text' id='n" + num + withholdLine[0] + "' size='15'" + errorIfNotNum + "></td></tr>";
    blank += saveLine1 + "Int(\"" + cell + saveLine2 + "Int(\"" + cell + saveLine3;
    setElement(cell, blank);
    cellDisplay(cell, true);
    if(num.substring(2, 1) != "9") {
        var next = (parseInt(num, 10) + 1).toString();
        cellDisplay("Empty" + next, true);
    }
}

function createUECell(cell, num) {
    var blank = "<table>" + primaryOrSpouse("n" + num + "earner", "Who received this unemployment benefit");
    blank += "<tr><td>State name (optional) </td><td><input type='text' id='n" + num + "name' size='30'/></td></tr>";
    blank += "<tr><td>Unemployment Income<br/>(from box 1 of 1099-G)</td><td><input type='text' id='n" + num + ueLine[0] + "' size='15'" + errorIfNotNum + "></td></tr>";
    blank += "<tr><td>Federal Tax Withheld<br/>(from box 4 of 1099-G)</td><td><input type='text' id='n" + num + withholdLine[0] + "' size='15'" + errorIfNotNum + "></td></tr>";
    blank += saveLine1 + "UE(\"" + cell + saveLine2 + "UE(\"" + cell + saveLine3;
    setElement(cell, blank);
    cellDisplay(cell, true);
    if(num.substring(2, 1) != "9") {
        var next = (parseInt(num, 10) + 1).toString();
        cellDisplay("Empty" + next, true);
    }
}

function createSSCell(cell, num) {
    var blank = "<table>" + primaryOrSpouse("n" + num + "earner", "Who earned this Social Security income");
    blank += "<tr><td>Type of benefit: </td><td><select id='n" + num + "type'>" + writeOption("SS", "Social Security (form SSA 1099)") + writeOption("RR", "Railroad Retirement (form RRB 1099)") + "</select></td></tr>";
    blank += "<tr><td>Net Benefits<br/>(from box 5 of SSA-1099 or box 7 of RRB-1099)</td><td><input type='text' id='n" + num + ssLine[0] + "' size='15'" + errorIfNotNum + "></td></tr>";
    blank += "<tr><td>Economic Recovery Payment received</td><td><input type='text' id='n" + num + "econRecovery' size='15'" + errorIfNotNum + "></td></tr>";
    blank += "<tr><td>Federal Tax Withheld<br/>(from box 6 of SSA-1099 or box 9 of RRB-1099)</td><td><input type='text' id='n" + num + withholdLine[0] + "' size='15'" +errorIfNotNum + "></td></tr>";
    blank += saveLine1 + "SS(\"" + cell + saveLine2 + "SS(\"" + cell + saveLine3;
    setElement(cell, blank);
    cellDisplay(cell, true);
    if(num.substring(2, 1) != "9") {
        var next = (parseInt(num, 10) + 1).toString();
        cellDisplay("Empty" + next, true);
    }
}

function createDividendCell(cell, num) {
    var blank = "<table><tr><td>Payer's name (optional) </td><td><input type='text' id='n" + num + "name' size='30'/></td></tr>";
    blank += "<tr><td>Ordinary Dividends<br/>(from box 1a of 1099-Div)</td><td><input type='text' id='n" + num + dividendLine[0] + "' size='15'" + errorIfNotNum + "></td></tr>";
    blank += "<tr><td>Qualified Dividends<br/>(from box 1b of 1099-Div)</td><td><input type='text' id='n" + num + qualDividendLine[0] + "' size='15'" + errorIfNotNum + "></td></tr>";
    blank += "<tr><td>Federal Tax Withheld<br/>(from box 4 of 1099-Div)</td><td><input type='text' id='n" + num + withholdLine[0] + "' size='15'" + errorIfNotNum + "></td></tr>";
    blank += "<tr><td>Please choose one: </td><td><select id='n" + num + "ownership'>" + writeOption("1", "Stock owned 61+ days and dividend not received as a nominee") + writeOption("2", "You received the dividend as a nominee") + writeOption("3", "You owned the stock 60 days or less") + "</select></td></tr>";
    blank += "<tr><td colspan='2'><div id='qualDivWarn" + num + "' style='color:Red;display:none'>This dividend might not be qualified.  Contact a tax professional.</td></tr>";
    blank += saveLine1 + "Div(\"" + cell + saveLine2 + "Div(\"" + cell + saveLine3;
    setElement(cell, blank);
    cellDisplay(cell, true);
    if(num.substring(2, 1) != "9") {
        var next = (parseInt(num, 10) + 1).toString();
        cellDisplay("Empty" + next, true);
    }
}

function showConfirmIRA(num) {
    if(getElement("n" + num + "IRADate") == "lastEarly")
        setElement("n" + num + "confirmIRA", "Was this IRA deducted on last year's return? </td><td><select id='n" + num + "IRADeductible'>" + writeOption("true", "No") + writeOption("false", "Yes") + "</select>");
    else if (getElement("n" + num + "IRADate") == "thisYear")
        setElement("n" + num + "confirmIRA", "Will this IRA be deducted on this year's return, not next year's? </td><td><select id='n" + num + "IRADeductible'>" + writeOption("true", "Yes") + writeOption("false", "No") + "</select>");
    else
        setElement("n" + num + "confirmIRA", "<input type='hidden' id='n" + num + "IRADeductible' value='true'/>");
}

function createIRACell(cell, num) {
    var blank = "<table>" + primaryOrSpouse("n" + num + "earner", "Which person contributed to this IRA deduction?");
    blank += "<tr><td>Date of Contribution: </td><td><select id='n" + num + "IRADate' onclick='showConfirmIRA(" + num + ")'><option></option>" + writeOption("lastEarly", "January 1 to " + lastYearsDueDate + "," + currentTaxYear) + writeOption("lastLate", "During " + currentTaxYear + " but AFTER " + lastYearsDueDate) + writeOption("thisYear", "January 1 to " + thisYearsDueDate + ", " + nextTaxYear) + "</select></td></tr>";
    blank += "<tr><td id='n" + num + "confirmIRA' colspan='2'><input type='hidden' id='n" + num + "IRADeductible' value='true'/></td></tr>";
    blank += "<tr><td>IRA deduction amount: </td><td><input type='text' id='n" + num + IRALine[0] + "' size='15'" + errorIfNotNum + "/></td></tr>";
    blank += "<tr><td id='IRAWarn" + num + "' style='color:Red;display:none' colspan='2'>Your IRA deduction amount exceeds the IRS' maximum deductible amount</td></tr>";
    blank += saveLine1 + "IRA(\"" + cell + saveLine2 + "IRA(\"" + cell + saveLine3;
    setElement(cell, blank);
    cellDisplay(cell, true);
    if(num.substring(2, 1) != "9") {
        var next = (parseInt(num, 10) + 1).toString();
        cellDisplay("Empty" + next, true);
    }
}
function createStudentLoanCell(cell, num) {
    var blank = "<table>" + primaryOrSpouse("n" + num + "earner", "Which person contributed to this Student Loan deduction?");
    blank += "<table><tr><td>Who was the loan taken out on behalf of? </td><td><select id='n" + num + "studentDependent'>" + writeOption("1", "Yourself or your spouse") + writeOption("2", "A dependent in the year the loan was taken out") + writeOption("3", "A person who would have been your dependent, but they filed a joint return") + writeOption("4", "A person who would have been your dependent if they had earned less money") + writeOption("5", "Person would be your dependent, but you were dependent on a tax return") + writeOption("0", "None of the above apply, I cannot take this deduction") + "</select></td></tr>";
    blank += "<tr><td>Did the student loan cover tuition, fees, room, board or books? </td><td><select id='n" + num + "studentCover'>" + writeOption("Yes", "Yes") + writeOption("No", "No") + "</select></td></tr>";
    blank += "<tr><td>What type of program was the student enrolled in? </td><td><select id='n" + num + "studentProgram'>" + writeOption("1", "Degree or Certificate program at a College, University or Vocational School") + writeOption("2", "A for credit study abroad program approved by the school") + writeOption("0", "None of the above apply, I cannot take this deduction") + "</select></td></tr>";
    blank += "<tr><td>Did the student carry at least half the normal full-time course load? </td><td><select id='n" + num + "studentLoad'>" + writeOption("Yes", "Yes") + writeOption("No", "No") + "</select></td></tr>";
    blank += "<tr><td>Student Loan interest deduction amount<br/>(From box 1 of form 1098-E)</td><td><input type='text' id='n" + num + studentLine[0] + "' size='15'" + errorIfNotNum + "/></td></tr>";
    blank += "<tr><td id='StudentWarn" + num + "' style='color:Red;display:none' colspan='2'>Your Student Loan Interest deduction amount exceeds the IRS' maximum deductible amount</td></tr>";
    blank += saveLine1 + "Student(\"" + cell + saveLine2 + "Student(\"" + cell + saveLine3;
    setElement(cell, blank);
    cellDisplay(cell, true);
    if(num.substring(2, 1) != "9") {
        var next = (parseInt(num, 10) + 1).toString();
        cellDisplay("Empty" + next, true);
    }
}
function createEducatorCell(cell, num) {
    var blank = "<table>" + primaryOrSpouse("n" + num + "earner", "Which person contributed to this Educator Expense deduction?");
    blank += "<tr><td>Was this person a teacher in Kindergarten through 12th grade? </td><td><select id='n" + num + "educatorGrade'>" + writeOption("Yes", "Yes") + writeOption("No", "No") + "</select></td></tr>";
    blank += "<tr><td>Did this person work at least 900 hours during the year? </td><td><select id='n" + num + "educatorHours'>" + writeOption("Yes", "Yes") + writeOption("No", "No") + "</select></td></tr>";
    blank += "<tr><td>Educator Expense deduction amount: </td><td><input type='text' id='n" + num + educatorLine[0] + "' size='15'" + errorIfNotNum + "/></td></tr>";
    blank += "<tr><td id='EducatorWarn" + num + "' style='color:Red;display:none' colspan='2'>Your Educator Expense deduction amount exceeds the IRS' maximum deductible amount</td></tr>";
    blank += saveLine1 + "Educator(\"" + cell + saveLine2 + "Educator(\"" + cell + saveLine3;
    setElement(cell, blank);
    cellDisplay(cell, true);
    if(num.substring(2, 1) != "9") {
        var next = (parseInt(num, 10) + 1).toString();
        cellDisplay("Empty" + next, true);
    }
}
function createTuitionCell(cell, num) {
    var blank = "<table>" + primaryOrSpouse("n" + num + "earner", "Which person contributed to this Tuition and Fees deduction?");
    var primaryCanDeduct = (getElement("canBeClaimed0") == "No");
    var spouseCanDeduct = (getElement("canBeClaimed1") == "No");
    if(!primaryCanDeduct && !spouseCanDeduct) {
        alert("Tuition and Fees can not be deducted if you can be claimed on another person's tax return!");
        return;
    } else {
        blank = "<table>";
        if(primaryCanDeduct && spouseCanDeduct)
            blank += primarySpouseDependent("n" + num + "earner", "Student name: ", "");
        else if(primaryCanDeduct)
            blank += primarySpouseDependent("n" + num + "earner", "", "spouse");
        else blank += primarySpouseDependent("n" + num + "earner", "", "primary");

        blank += "<tr><td>Tuition and Fees amount paid in " + currentTaxYear + ": </td><td><input type='text' id='n" + num + tuitionLine[0] + "' size='15'" + errorIfNotNum + "/></td></tr>";
        blank += "<tr><td>Books, supplies and equipment required for the course paid in " + currentTaxYear + ": </td><td><input type='text' id='n" + num + "CourseSupplies' size='15'" + errorIfNotNum + "/></td></tr>";
        blank += "<tr><td>Course start date: </td><td><select id='n" + num + "courseStart'>" + writeOption("Deductible", "January 1, " + currentTaxYear + " to March 31, " + nextTaxYear) + writeOption("NotDeductible", "Outside of this date range and not deductible.") + "</select></td></tr>";
        blank += "<tr><td colspan='2'>This should be out of pocket expenses, not covered by scholarships</td></tr>";
    }
    blank += "<tr><td id='TuitionWarn" + num + "' style='display:none' colspan='2'></td></tr>";
    blank += saveLine1 + "Tuition(\"" + cell + saveLine2 + "Tuition(\"" + cell + saveLine3;
    setElement(cell, blank);
    cellDisplay(cell, true);
    if(num.substring(2, 1) != "9") {
        var next = (parseInt(num, 10) + 1).toString();
        cellDisplay("Empty" + next, true);
    }
}

function writeAgeRangeOption(minAge, maxAge, minDate, maxDate, twoDigitYear) {
    var retval, minYear, maxYear, linkWord;

    minYear = parseInt(parseFloat(currentTaxYear) - maxAge);
    maxYear = parseInt(parseFloat(currentTaxYear) - minAge);
    if(maxDate != "" && maxDate.indexOf("January") != -1)
        maxYear++;
    if(minDate != "" && minDate.indexOf("July") != -1)
        minYear++;

    if(twoDigitYear == true) {
        maxYear = maxYear.toString().substr(2);
        minYear = minYear.toString().substr(2);
    }

    if(maxDate == "") maxDate = maxYear;
    if(minDate == "") minDate = minYear;

    if(maxAge == 500) {
        if(maxDate != maxYear) maxDate = maxDate + ", " + (maxYear + 1);
        retval = writeOption(">" + minAge, maxDate + " or earlier (older than " + minAge + ")");
    } else if (minAge == 0 && maxAge != 0) {
        if(minDate != minYear) minDate = minDate + ", " + (minYear + 1);
        retval = writeOption("<" + maxAge, minDate + " or later (younger than " + maxAge + ")");
    } else {
        if(minDate != minYear) minDate = minDate + ", " + minYear;
        if(maxDate != maxYear) maxDate = maxDate + ", " + maxYear;
        if(minAge == maxAge) {
            if(minDate == maxDate)
                retval = writeOption(minAge, minDate + " (" + minAge + ")");
            else
                retval = writeOption(minAge, minDate + " to " + maxDate + " (" + minAge + ")");
        } else {
            if(maxAge - minAge == 1)
                linkWord = " or ";
            else
                linkWord = " to ";

            retval = writeOption(minAge + "to" + maxAge, minDate + linkWord + maxDate + " (" + minAge + linkWord + maxAge + ")");
        }
    }
    return retval;
}
function msChange() {
    var marStatus = getElement("maritalStatus");
    cellDisplay("showIfSingleOrWidowed", (marStatus == "single" || marStatus == "widow"));
}
function claimChange(num) {
    cellDisplay("showIfUnsure" + num, (getElement("canBeClaimed" + num) == "Unsure"));
}
function dYOBChange(num) {
    var dCOB = getElement("n" + num + "DCOB");
    var dYOB;
    cellDisplay("n" + num + "DYOB19", false);
    cellDisplay("n" + num + "DYOB20", false);
    if(dCOB == "") return;
    cellDisplay("n" + num + "DYOB" + dCOB, true);
    dYOB = getElement("n" + num + "DYOB" + dCOB);
    if(dYOB == "") return;
    if(dYOB == ">24") {
        setElement("n" + num + "showAdultDependent", "<td>Is this person permanently and totally disabled: </td><td><select id='adultClaim" + num + "'>" + writeOption("YesD", "Yes") + writeOption("No", "No") + "</select></td>");
        cellDisplay("n" + num + "showAdultDependent", true);
    } else if (dYOB == "19to23") {
        setElement("n" + num + "showAdultDependent", "<td>Please select the best option</td><td><select id='adultClaim" + num + "'>" + writeOption("YesS", "This person was a full-time student for any part of 5 months") + writeOption("YesD", "This person is permanently and totally disabled:") + writeOption("No", "None of the above apply") + "</select></td>");
        cellDisplay("n" + num + "showAdultDependent", true);
    } else {
        setElement("n" + num + "showAdultDependent", "<td><input type='hidden' id='adultClaim" + num + "' value='Yes'/></td>");
        cellDisplay("n" + num + "showAdultDependent", false);
    }
}
function createDependentCell(cell, num) {
    var blank = "<table><tr><td>Dependent name (optional here, required for return)</td></tr><tr><td><input type='text' id='n" + num + "name' size='30'/></td></tr>";
    blank += "<tr><td>Dependent SSN: (optional here, required for return)</td></tr><tr><td><input type='text' id='n" + num + "SSN' size='15'/></td></tr>";
    blank += "<tr><td>Dependent Gender: <select id='n" + num + "gender'>" + writeOption("Female", "Female") + writeOption("Male", "Male") + "<option selected></option></select></td></tr>";
    blank += "<tr><td>Relation to primary taxpayer OR spouse: </td></tr><tr><td>";
    blank += "<select id='n" + num + "relation'><option></option>" + writeOption("child1", "Daughter/Son/Child") + writeOption("child2", "Foster Daughter/Foster Son/Foster Child") + writeOption("child3", "Granddaughter/Grandson/Grandchild") + writeOption("child4", "Niece/Nephew") + writeOption("child5", "Sister/Brother/Sibling") + writeOption("child6", "Stepdaughter/Stepson/Stepchild") + writeOption("child7", "Stepsister/Stepbrother/Stepsibling") + writeOption("child8", "Half Sister/Half Brother/Half Sibling") + writeOption("relative1", "Mother/Father/Parent") + writeOption("relative2", "Grandmother/Grandfather/Grandparent") + writeOption("relative3", "Aunt/Uncle") + writeOption("relative4", "Other Relative") + writeOption("no", "Not a relative");
    blank += "</select></td></tr><tr><td>Dependent Year of Birth: </td></tr><tr><td><select id='n" + num + "DCOB' onClick='dYOBChange(" + num + ")'><option>First, select first 2 digits of year of birth</option>";
    blank += writeOption("19", "19") + writeOption("20", "20") + "</select>";
    blank += "<select id='n" + num + "DYOB20' style='display:none' onChange='dYOBChange(" + num + ")'><option></option>";
    for (var i = 0; i < 19 && i < parseInt(currentTaxYear) - 1999; i++)
        blank += writeAgeRangeOption(i, i, "", "", true);
    blank += "</select>";
    blank += "<select id='n" + num + "DYOB19' style='display:none' onChange='dYOBChange(" + num + ")'><option></option>";
    for (var i = parseInt(currentTaxYear) - 1999; i < 19; i++)
        blank += writeAgeRangeOption(i, i, "", "", true);
    blank += writeAgeRangeOption(19, 23, "", "", true) + writeAgeRangeOption(24, 500, "", "", true) + "</select></td></tr>";
    blank += "<tr><td id='n" + num + "showAdultDependent' style='display:none'></td></tr>";
    blank += "<tr><td>How many months did the dependent live with you? (Include time away at school or vacation and partial months)</td></tr><tr><td><select id='n" + num + "months'>" + writeOption("12", "12 months") + writeOption("12", "Was born in " + currentTaxYear + " and lived with taxpayer") + writeOption("12", "Died in " + currentTaxYear + " and lived with taxpayer");
    for(var i = 11; i >= 0; i--) blank += writeOption(i, i + " months");
    blank += "</select></td></tr>";
    blank += "<tr><td>Is there a divorce decree stating who can claim this dependent? <select id='n" + num + "decree'>" + writeOption("No", "No") + writeOption("canClaim", "Yes, it states I can claim this dependent") + writeOption("cantClaim", "Yes, it states somebody else will claim this dependent") + "</select></td></tr>";
    blank += "<tr><td>Dependent Support Status: <select id='n" + num + "support'>" + writeOption("1", "Taxpayer provided over 50% of support for dependent") + writeOption("2", "Taxpayer provided less than 50% of support, but claim them due to a legal agreement") + writeOption("0", "None of the above apply and I can't claim this dependent") + "</select></td></tr>";
    blank += "<tr><td>Dependent Nationality Status: <select id='n" + num + "nationality'>" + writeOption("1", "U.S. citizen or U.S. national or U.S. resident alien") + writeOption("2", "Canadian or Mexican resident") + writeOption("3", "Adopted child of U.S. Citizen or U.S. national") + writeOption("0", "None of the above apply") + "</select></td></tr>";
    blank += "<tr><td>Did this person earn less than $" + dependentAmt + " in " + currentTaxYear + "? <select id='n" + num + "income'>" + writeOption("Yes", "Yes") + writeOption("No", "No") + "</select></td></tr>";
    blank += "<tr><td>Dependent Filing Status: <select id='n" + num + "filing'>" + writeOption("1", "This person did not file a tax return") + writeOption("2", "Filed as a single taxpayer") + writeOption("0", "Married and filed a joint return") + writeOption("3", "Other Filing Status") + "</select></td></tr>";
    blank += "<tr><td id='dependentWarn" + num + "' style='color:Red;display:none'></td></tr>";
    blank += saveLine1 + "Dependent(\"" + cell + saveLine2 + "Dependent(\"" + cell + saveLine3;
    setElement(cell, blank);
    cellDisplay(cell, true);
    if(num.substring(2, 1) != "9") {
        var next = (parseInt(num, 10) + 1).toString();
        cellDisplay("Empty" + next, true);
    }
}
function createCell(cell, num, cellType) {
    var cell2 = cell;
    var num2 = num;
    if(num.length > 2) {
        num2 = num.substr(num.length - 2);
        if(cell.substring(0, 9) == "Container") cell2 = "Container" + num2;
    }
    if(cellType == intLine[0].substring(0, 2)) createIntCell(cell2, num2);
    else if(cellType == ueLine[0]) createUECell(cell2, num2);
    else if(cellType == ssLine[0].substring(0, 2)) createSSCell(cell2, num2);
    else if(cellType == dividendLine[0].substring(0, 2)) createDividendCell(cell2, num2);
    else if(cellType == studentLine[0]) createStudentLoanCell(cell2, num2);
    else if(cellType == educatorLine[0]) createEducatorCell(cell2, num2);
    else if(cellType == tuitionLine[0]) createTuitionCell(cell2, num2);
    else if(cellType == IRALine[0]) createIRACell(cell2, num2);
    else if(cellType == "3") createDependentCell(cell2, num2);
}
function numberBox(num) {
    return "<td style='border-width:thin; border-style:solid;text-align:right'><tt>" + num + "</tt></td>";
}
function filerTable(primary) {
    var cellNum = (primary)?"0":"1";
    var pronoun = (primary)?"you":"your spouse";
    var verb = (primary)?" were":" was";
    var possessive = (primary)?"your":"your spouse's";
    var retval = "<table><tr><td>Name (optional, but recommended): </td>";
    retval += "<td><input type='text' id='filerNameInput" + cellNum + "' size='30'/></td></tr>";
    if(primary) {
        retval += "<tr><td>Marital Status as of December 31, 2010: </td>";
        retval += "<td><select id='maritalStatus' onchange='msChange()'><option></option>";
        retval += writeOption("single", "Single Or Divorced");
        retval += writeOption("married1", "Married");
        retval += writeOption("married2", "Widowed during " + currentTaxYear + " or " + nextTaxYear);
        retval += writeOption("widow", "Widowed during 2008 or 2009 and did not remarry before 1/1/" + currentTaxYear);
        retval += "</select></td></tr>";
    }
    retval += "<tr><td>Can " + pronoun + " be claimed as a dependent on somebody else's tax return? </td>";
    retval += "<td><select id='canBeClaimed" + cellNum + "' onchange='javascript:claimChange(" + cellNum + ");'><option></option>";
    retval += writeOptions("No", "No", "Yes", "Yes");
    retval += writeOption("Unsure", "Please help me figure this out");
    retval += "</select></td></tr>";
    retval += "<tr><td id='showIfUnsure" + cellNum + "' style='display:none' colspan='2'>";
    retval += "<table><tr><td>Did " + pronoun + " receive support from any of the following?</td>";
    retval += "<td><select id='unsure1" + cellNum + "'><option></option>";
    retval += writeOption("livedWith", pronoun + " lived with a person or people who provided " + pronoun + " support all year");
    retval += writeOption("Relative", pronoun + " were related to a person or people who provided " + pronoun + " support and lived with them more than half the year");
    retval += writeOption("NotDependent", pronoun + " were related to a person or people who provided " + pronoun + " support and lived with them less than half the year");
    retval += writeOption("NotDependent", pronoun + " did not receive substantial support");
    retval += writeOption("NotDependent", pronoun + " did receive support, but not from a relative or a person " + pronoun + " lived with");
    retval += "</select></td></tr>";
    retval += "<tr><td>Did somebody else provide more than 50% of the support for " + pronoun + " (including food/shelter)?</td>";
    retval += "<td><select id='unsure2" + cellNum + "'><option></option>";
    retval += writeOption("child", "Yes, parent(s) or guardian(s)");
    retval += writeOptions("Yes", "Yes, other person(s)", "No", "No");
    retval += "</select></td></tr>";
    retval += "<tr><td>Please select one of these options: </td>";
    retval += "<td><select id='unsure3" + cellNum + "'><option></option>";
    retval += writeOption("student", pronoun + verb + " a full-time student for at least part of 5 calendar months");
    retval += writeOption("disabled", pronoun + verb + " totally and permanently disabled");
    retval += writeOption("No", "Neither of the above choices apply");
    retval += "</select></td></tr>";
    retval += "<tr><td>Was " + possessive + " income for " + currentTaxYear + " more than $" + dependentAmt + "? </td>";
    retval += "<td><select id='unsure4" + cellNum + "'>";
    retval += writeOption("Unsure", "Unsure");
    retval += (writeOption("Yes", "Yes") + writeOption("No", "No"));
    retval += "</select></td></tr></table></td></tr>";
    retval += "<tr><td>Were " + pronoun + " blind, and not likely to get better eye sight as of December 31, " + currentTaxYear + "?<br />(eyesight worse than 20/200 or less than 20 degree field of vision)</td>";
    retval += "<td><select id='blind" + cellNum + "'>";
    retval += writeOptions("No", "No", "Yes", "Yes");
    retval += "</select></td></tr>";
    retval += "<tr><td>When" + verb + " " + pronoun + " born? </td>";
    retval += "<td><select id='age" + cellNum + "'><option></option>";
    retval += writeAgeRangeOption(0, 18, "", "", false);
    retval += writeAgeRangeOption(19, 23, "", "", false);
    retval += writeAgeRangeOption(24, 24, "January 2", "December 31", false);
    retval += writeAgeRangeOption(25, 49, "January 1", "January 1", false);
    retval += writeAgeRangeOption(50, 64, "January 2", "December 31", false);
    retval += writeAgeRangeOption(65, 70.5, "July 1", "January 1", false);
    retval += writeAgeRangeOption(70.5, 500, "", "June 30", false);
    retval += "</select></td></tr>";
    retval += "<tr><td>How long did " + pronoun + " reside in the US in " + currentTaxYear + "? </td>";
    retval += "<td><select id='residency" + cellNum + "'>";
    retval += writeOption("resident1", pronoun + " lived in the United States for more than 6 months");
    retval += writeOption("resident2", pronoun + verb + " a member of the US military stationed outside of the US");
    retval += writeOption("No", "You lived in the United States 6 months or less");
    retval += "</select></td></tr>";
    if(primary) {
        retval += "<tr><td id='showIfSingleOrWidowed' style='display:none'>";
        retval += "<table><tr><td>Did you pay more than 50% of keeping your home for yourself and any children in " + currentTaxYear + "? </td>";
        retval += "<td><select id='residencyPay'>";
        retval += writeOptions("No", "No", "Yes", "Yes");
        retval += "</select></td></tr>";
        retval += "<tr><td>Did you (and/or your spouse if filing jointly) pay more than 50% of keeping a home for a parent for all of " + currentTaxYear + "? </td>";
        retval += "<td><select id='parentPay'>";
        retval += writeOptions("No", "No", "Yes", "Yes");
        retval += "</select></td></tr></table></td></tr></table></td></tr>";
        retval += "<tr><td>Zip Code (at least first 3 digits)</td>";
        retval += "<td><input type='text' id='zip' onkeyup='javascript:selectState();' /></td></tr>";
        retval += "<tr><td>State</td><td><select id='state'><option></option>";
        retval += writeOptions("AL", "Alabama", "AK", "Alaska", "AZ", "Arizona", "AR", "Arkansas", "CA", "California", "CO", "Colorado", "CT", "Connecticut", "DE", "Delaware", "DC", "District of Columbia", "FL", "Florida", "GA", "Georgia", "GU", "Guam", "HI", "Hawaii", "ID", "Idaho", "IL", "Illinois", "IN", "Indiana", "IA", "Iowa", "KS", "Kansas", "KY", "Kentucky", "LA", "Louisiana", "ME", "Maine", "MD", "Maryland", "MA", "Massachusetts", "MI", "Michigan", "MN", "Minnesota", "MS", "Mississippi", "MO", "Missouri", "MT", "Montana", "NE", "Nebraska", "NV", "Nevada", "NH", "New Hampshire", "NJ", "New Jersey", "NM", "New Mexico", "NY", "New York", "NC", "North Carolina", "ND", "North Dakota", "OH", "Ohio", "OK", "Oklahoma", "OR", "Oregon", "PA", "Pennsylvania", "PR", "Puerto Rico", "RI", "Rhode Island", "SC", "South Carolina", "SD", "South Dakota", "TN", "Tennessee", "TX", "Texas", "UT", "Utah", "VT", "Vermont", "VI", "Virgin Islands", "VA", "Virginia", "WA", "Washington", "WV", "West Virginia", "WI", "Wisconsin", "WY", "Wyoming", "other", "Other");
        retval += "</select></td></tr></table>";
    }
    return retval;
}
setElement("intro4", filerTable(true));
setElement("intro5", filerTable(false));
for(var i = 1; i < 11; i++) 
    setElement("MenuTab" + i, "<table><tr><td id='Tab" + i + "Main' style='font-weight:bold'></td><td id='Tab" + i + "Num' style='font-weight:bold'></td><td id='Tab" + i + "Label1'></td><td id='Tab" + i + "Total1' style='text-align:right'></td><td id='Tab" + i + "Label2'></td><td id='Tab" + i + "Total2' style='text-align:right'></td></tr></table>");
var sumTable;
for(var i = 10; i < 100; i++) {
    sumTable = "<table><tr>";
    for(var j = 0; j < 5; j++)
        sumTable += "<td id='Label" + i.toString() + String.fromCharCode(97 + j) + "'></td>";
    sumTable += "</tr></table>";
    setElement("Filled" + i, sumTable);
}
for(var i = 0; i < 10; i++) {
    sumTable = "<table><tr>";
    for(var j = 0; j < 5; j++)
        sumTable += "<td id='Label0" + i.toString() + String.fromCharCode(97 + j) + "'></td>";
    sumTable += "</tr></table>";
    setElement("Filled0" + i, sumTable);
}
