/* Javascript Document */
/* content placed by Ed Collins - please leave in Master page code*/


// ********                                                         **********
// ******** Beginning of Medical Inflation Chart functions          **********
// ******** Set up by Ed Collins                                    **********
// ******** This section for the Medical Inflation Calculator ONLY  **********  
// ******** Located in the Health Care Reform section               **********  

function showchart1wrapper_mic()
{
    document.getElementById('divchart1wrapper').style.visibility = 'visible';
    document.getElementById('divchart1wrapper').style.display = 'block';
}

function averagetrend_mic()
{
    //inpATVal01 inpATValRes
    // reset error label
    document.getElementById('lblATValErr01').style.visibility = 'hidden';
    document.getElementById('lblATValErr02').style.visibility = 'hidden';
    document.getElementById('lblATValErr03').style.visibility = 'hidden';
    document.getElementById('lblATValErr04').style.visibility = 'hidden';
    document.getElementById('lblATValErr05').style.visibility = 'hidden';

    // validate field inputs to show error message
    validate_required('inpATVal01', 'lblATValErr01');
    validate_required('inpATVal02', 'lblATValErr02');
    validate_required('inpATVal03', 'lblATValErr03');
    validate_required('inpATVal04', 'lblATValErr04');
    validate_required('inpATVal05', 'lblATValErr05');

    // get field values
    var avgATVal01 = parseFloat(document.getElementById('inpATVal01').value);
    var avgATVal02 = parseFloat(document.getElementById('inpATVal02').value);
    var avgATVal03 = parseFloat(document.getElementById('inpATVal03').value);
    var avgATVal04 = parseFloat(document.getElementById('inpATVal04').value);
    var avgATVal05 = parseFloat(document.getElementById('inpATVal05').value);

    // Count number of fields to use for average denominator
    var val01;
    var val02;
    var val03;
    var val04;
    var val05;
    var atvCounter = 0; // reset counter
    if (avgATVal01 && avgATVal01 > 0) { atvCounter = atvCounter + 1; };
    if (avgATVal02 && avgATVal02 > 0) { atvCounter = atvCounter + 1; };
    if (avgATVal03 && avgATVal03 > 0) { atvCounter = atvCounter + 1; };
    if (avgATVal04 && avgATVal04 > 0) { atvCounter = atvCounter + 1; };
    if (avgATVal05 && avgATVal05 > 0) { atvCounter = atvCounter + 1; };

    // do average
    var totVal = avgATVal01 + avgATVal02 + avgATVal03 + avgATVal04 + avgATVal05;

    if (isNaN(totVal)) { totVal = 0 };

    var avgATValRes = (totVal / 5).toFixed(2);
    //avgATValRes = avgATValRes.toFixed(2);
    document.getElementById('inpATValRes').value = avgATValRes;

    if (isNaN(avgATValRes) || avgATValRes <= 0) {
        document.getElementById('inpATValRes').value = 0;
        document.getElementById('btnapplyaverage').style.visibility = "hidden";
    };

    if (totVal > 0) {
        document.getElementById('btnapplyaverage').style.visibility = "visible";

    };



    // end function
}
// end function


function changecols_mic()
{

    var chtHeight = document.getElementById('vertgraph').clientHeight;
    // height of the chart div wrapper
    var strLength = chtHeight.length;
    var devisor;
    var maxV = document.getElementById('inpAp2022').value;
    var bottomoff = 40; // set bottom offset
    var round = 1.0; // round the values by thousands


    if (isNaN(elHeight)) { elHeight = 100; }

    var factor = (maxV / chtHeight) * 1.2;
    // factor is used to scale the values to fit the chart div
    var offset = 36;
    //css value by which the charts are offset from the bottom
    // equals (chart2.css) #vertgraphTTO (24) & #vertgraphTTO label (4)
    var elHeight = (elVal / factor) + offset;



    //formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2)

    var elVal = document.getElementById('inpAp2010').value;
    if (isNaN(elVal)) { elVal = 100; }

    if (elVal < 1) { elVal = 1; }
    if (elHeight < 1) { elHeight = 1; }
    if (factor < 1) { factor = 1; }
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv01';
    applypad_mic(inputlength, curdiv);

    // determine line position
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv01').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;



    var elVal = document.getElementById('inpAp2011').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv02';
    applypad_mic(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv02').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2012').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv03';
    applypad_mic(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv03').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2013').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv04';
    applypad_mic(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv04').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2014').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv05';
    applypad_mic(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv05').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2015').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv06';
    applypad_mic(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv06').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2016').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv07';
    applypad_mic(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv07').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2017').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv08';
    applypad_mic(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv08').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2018').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv09';
    applypad_mic(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv09').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2019').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv10';
    applypad_mic(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv10').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2020').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv11';
    applypad_mic(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv11').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    // these were in the first chart and in the Cad chart
    //    var elVal = document.getElementById('inpAp2021').value;
    //       var inputlength = elVal.length;
    //       var curdiv = 'lblValDiv12';
    //      applypad_mic(inputlength,curdiv);
    //var elHeight = elVal / factor; // scales the chart height
    //var chartlabel = formatNumber((elVal*round),0,',','','$','','-','');
    //document.getElementById('chartDiv12').style.height = elHeight+"px";
    //document.getElementById(curdiv).style.bottom = (elHeight+bottomoff)+"px";
    //document.getElementById(curdiv).innerHTML = chartlabel;

    //var elVal = document.getElementById('inpAp2022').value;
    //var inputlength = elVal.length;
    //var curdiv = 'lblValDiv13';
    //applypad_mic(inputlength,curdiv);
    //var elHeight = elVal / factor; // scales the chart height
    //var chartlabel = formatNumber((elVal*round),0,',','','$','','-','');
    //document.getElementById('chartDiv13').style.height = elHeight+"px";
    //document.getElementById(curdiv).style.bottom = (elHeight+bottomoff)+"px";
    //document.getElementById(curdiv).innerHTML = chartlabel;


    // end function
}
// end function

function applypad_mic(length, divid)
{
    // Provide default values for the optional arguments
    if (!length) length = 1;
    if (!divid) divid = 'lblValDiv01';
    if (length > 5) { document.getElementById(divid).style.marginLeft = "-6px"; }
    if (length > 6) { document.getElementById(divid).style.marginLeft = "-7px"; }
    if (length > 7) { document.getElementById(divid).style.marginLeft = "-8px"; }
    if (length > 8) { document.getElementById(divid).style.marginLeft = "-9px"; }
    if (length > 9) { document.getElementById(divid).style.marginLeft = "-10px"; }

}


//Calculator
function usenewtrend_mic()
{

    // use the trend amount calculated from the average
    var trendpercent = parseFloat(document.MainForm.inpATValRes.value) * .01 + 1;
    if (isNaN(trendpercent)) { trendpercent = "1"; }
    var basevalue = parseFloat(document.MainForm.inpap.value);
    if (isNaN(basevalue)) { basevalue = "1"; }

    calcTrendVals_mic(trendpercent, basevalue);
}


// table 1 - Total Expenses script
function calcTrend_mic()
{

    // Trend = value input (basevalue) compounded
    // by the percentage input (trendpercent)
    // total value numeric
    var trendpercent = parseFloat(document.MainForm.inptrend.value) * .01 + 1;
    if (isNaN(trendpercent)) { trendpercent = "1"; }
    var basevalue = parseFloat(document.MainForm.inpap.value);
    if (isNaN(basevalue)) { basevalue = "1"; }
    calcTrendVals_mic(trendpercent, basevalue);
}

function calcTrendVals_mic(trendpercent, basevalue)
{

    // Calculates the increase of the Total EE Premium cost based on selected Trend Percent
    if (isNumeric(basevalue) && isNumeric(trendpercent)) {
        // determine the premium increase based on the trend percent.
        inpCost2010 = basevalue;
        inpCost2011 = basevalue * trendpercent;
        basevalue = inpCost2011;
        inpCost2012 = inpCost2011 * trendpercent;
        basevalue = inpCost2012;
        inpCost2013 = inpCost2012 * trendpercent;
        basevalue = inpCost2013;
        inpCost2014 = inpCost2013 * trendpercent;
        basevalue = inpCost2014;
        inpCost2015 = inpCost2014 * trendpercent;
        basevalue = inpCost2015;
        inpCost2016 = inpCost2015 * trendpercent;
        basevalue = inpCost2016;
        inpCost2017 = inpCost2016 * trendpercent;
        basevalue = inpCost2017;
        inpCost2018 = inpCost2017 * trendpercent;
        basevalue = inpCost2018;
        inpCost2019 = inpCost2018 * trendpercent;
        basevalue = inpCost2019;
        inpCost2020 = inpCost2019 * trendpercent;
        basevalue = inpCost2020;
        inpCost2021 = inpCost2020 * trendpercent;
        basevalue = inpCost2021;
        inpCost2022 = inpCost2021 * trendpercent;
        basevalue = inpCost2022;

        // set form input values  base input left column compounding   
        document.getElementById('inpAp2010').value = Math.round(inpCost2010);
        document.getElementById('inpAp2011').value = Math.round(inpCost2011);
        document.getElementById('inpAp2012').value = Math.round(inpCost2012);
        document.getElementById('inpAp2013').value = Math.round(inpCost2013);
        document.getElementById('inpAp2014').value = Math.round(inpCost2014);
        document.getElementById('inpAp2015').value = Math.round(inpCost2015);
        document.getElementById('inpAp2016').value = Math.round(inpCost2016);
        document.getElementById('inpAp2017').value = Math.round(inpCost2017);
        document.getElementById('inpAp2018').value = Math.round(inpCost2018);
        document.getElementById('inpAp2019').value = Math.round(inpCost2019);
        document.getElementById('inpAp2020').value = Math.round(inpCost2020);
        document.getElementById('inpAp2021').value = Math.round(inpCost2021);
        document.getElementById('inpAp2022').value = Math.round(inpCost2022);



    }
    // end if     
}
// end function
//

// ********                                             ********
// ********  End of Medical Inflation Chart functions
// ********                                             ********




// Start code for
// Salary Impact Calculator in HCR section
// Ed Collins 2-1-2010

function evalriderchoice()
{
    resetdivs('divFRP');
    resetdivs('divFCV');
    resetdivs('divBoth');
    resetErrs();
    if (document.getElementById('frp').checked) {
        calcRiderFRP();
    }
    //if (document.getElementById('fcv').checked) {
    //     calcRiderFCV();
    //}
    //if (document.getElementById('both').checked) {
    //    calcBoth();
    // reset error labels
    //}

    if (!document.getElementById('frp').checked
        && !document.getElementById('fcv').checked
        && !document.getElementById('both').checked) {
        document.getElementById('calcwarn').style.visibility = 'visible';
    }

    // end function
}


function resetErrs()
{
    document.getElementById('errAPfcv').style.visibility = 'hidden';
    document.getElementById('calcwarn').style.visibility = 'hidden';
    //document.getElementById('inpAPvouchers').value = 4800;

}
//end function resetErrs

function calcRiderFRP()
{
    // get Free Rider field values
    var valAPfrp = parseFloat(document.getElementById('inpAPvouchers').value);
    //reset value to remove non numerical.
    document.getElementById('inpAPvouchers').value = valAPfrp;

    // validate field inputs for non numerical values

    // do math for B section
    var mulFreeRider = 0.095;

    var valFreeRider = (valAPfrp / mulFreeRider).toFixed(2);
    document.getElementById('inp01FRP').value = valFreeRider;

    // link shown in A section text
    var linkFRP = " <a target='_blank' href='http://aspe.hhs.gov/poverty/index.shtml#latest'>Federal Poverty Level</a>.";

    //determine if first section paragraphs to be shown.  divFRP

    document.getElementById('FreeRidervalues').style.visibility = 'visible';
    document.getElementById('FreeRidervalues').style.display = 'block';
    document.getElementById('p1FreeRider').style.visibility = 'visible';
    document.getElementById('p1FreeRider').style.display = 'block';
    document.getElementById('divFRP').style.visibility = 'visible';
    document.getElementById('divFRP').style.display = 'block';
    resetdivs('divFCV'); resetdivs('divBoth');

    var txtFreeRiderP1a = "Employer may owe a Free Rider Penalty for individuals with annual wages up to ";
    var txtFreeRiderP1b = "";
    var txtFreeRiderP1c = ".(No Free Rider Penalty is owed for individual with family income in excess of 400% FPL.)";

    if (valFreeRider > 0) {
        // set Free Rider Text
        document.getElementById('p1FreeRider').innerHTML = txtFreeRiderP1a + formatCurrency(valFreeRider) + txtFreeRiderP1c;
    } else {
        document.getElementById('p1FreeRider').innerHTML = 'Great news!  If you continue to provide coverage at no cost to employees, the coverage will always be considered &#34;affordable&#34;.  If the coverage is also &#34;adequate&#34; (the actuarial value is at least 60%) you will not owe a Free Rider Penalty.';
    }



}
// end function calcRiderFRP


function calcRiderFCV()
{

    // if input annual premium
    // then divide AP / Free Choice percentage..
    // Then show values in sentences that are displayed


    // get field values
    var valAPfcv = parseFloat(document.getElementById('inpAPvouchers').value);
    //reset value to remove non numerical.
    document.getElementById('inpAPvouchers').value = valAPfcv;

    // validate field inputs for non numerical values
    validate_required('inpAPvouchers', 'errAPfcv');

    // do math for A section
    var mulFreeChoiceA = 0.08;
    var valFreeChoiceA = (valAPfcv / mulFreeChoiceA).toFixed(2);
    document.getElementById('inp01FCV').value = valFreeChoiceA;

    // do math for B section
    var mulFreeChoiceB = 0.098;
    var valFreeChoiceB = (valAPfcv / mulFreeChoiceB).toFixed(2);
    document.getElementById('inp02FCV').value = valFreeChoiceB;



    // link shown in A section text
    var linkFCV = "<a target='_blank' href='http://aspe.hhs.gov/poverty/index.shtml#latest'>FPL</a>.";


    //determine if first section paragraphs to be shown.     
    if (valFreeChoiceA > 0) {
        document.getElementById('FreeChoicevalues').style.visibility = 'visible';
        document.getElementById('FreeChoicevalues').style.display = 'block';
        document.getElementById('p1FreeChoiceA').style.visibility = 'visible';
        document.getElementById('p1FreeChoiceA').style.display = 'block';
        document.getElementById('divFCV').style.visibility = 'visible';
        document.getElementById('divFCV').style.display = 'block';
        resetdivs('divFRP'); resetdivs('divBoth');
    }

    // set Free Choice Text
    var txtFreeChoiceP1a1 = "Employer may owe a Free Choice Voucher for individuals with annual wages between ";
    var txtFreeChoiceP1a2 = " and ";
    var txtFreeChoiceP1a3 = " .  (No Free Choice Voucher is owed for individual with family income in excess of 400% FPL.)";
    document.getElementById('p1FreeChoiceA').innerHTML = txtFreeChoiceP1a1 + formatCurrency(valFreeChoiceB) + txtFreeChoiceP1a2 + formatCurrency(valFreeChoiceA) + txtFreeChoiceP1a3;


    // end calcRiderFCV
}


function calcBoth()
{

    // get Free Rider field values
    var valAPboth = parseFloat(document.getElementById('inpAPvouchers').value);
    //reset value to remove non numerical.
    document.getElementById('inpAPvouchers').value = valAPboth;

    // validate field inputs for non numerical values
    validate_required('inpAPvouchers', 'errAPfcv');

    // do math for B section
    var mulBothRider = 0.08;

    var valBothRider = (valAPboth / mulBothRider).toFixed(2);
    document.getElementById('inpBothRider').value = valBothRider;

    // link shown in A section text
    var linkC = "<a target='_blank' href='http://aspe.hhs.gov/poverty/index.shtml#latest'>Federal Poverty Level</a>.";

    //determine if first section paragraphs to be shown.
    if (valBothRider > 0) {

        document.getElementById('BothValues').style.visibility = 'visible';
        document.getElementById('BothValues').style.display = 'block';
        document.getElementById('BothRider').style.visibility = 'visible';
        document.getElementById('BothRider').style.display = 'block';
        document.getElementById('divBoth').style.visibility = 'visible';
        document.getElementById('divBoth').style.display = 'block';
        resetdivs('divFRP'); resetdivs('divFCV');
    }

    // set Both Riders Text
    var txtBothRiderP1a = "Employer may owe a Free Rider Penalty or Free Choice Voucher for individuals with annual wages up to ";
    var txtBothRiderP1b = " "
    var txtBothRiderP1c = ". (No Free Rider Penalty or Free Choice Voucher is owed for individual with family income in excess of 400% FPL.)";
    document.getElementById('BothRider').innerHTML = txtBothRiderP1a + formatCurrency(valBothRider) + txtBothRiderP1c;


}
// end function calcBoth



function resetdivs(divid)
{
    document.getElementById(divid).style.visibility = 'hidden';
    document.getElementById(divid).style.display = 'none';
}
//end resetdivs


// END code for Salary Impact Calculator in HCR section
// Ed Collins 2-1-2010









// ********                                                         **********
// ********  Begin Cadillac Tax Calculator                          **********
// ********  Begin Cadillac Tax Calculator                          **********
// ********  Begin Cadillac Tax Calculator                          **********
// ******** Located in the Health Care Reform section               **********
// ********                                                         **********


function hideouterdivs()
{
    document.getElementById('divchart1outer').style.visibility = "hidden";
    document.getElementById('divchart1outer').style.display = "none";
    document.getElementById('divchartTTOouter').style.visibility = "hidden";
    document.getElementById('divchartTTOouter').style.display = "none";
}


function averagetrend_cad()
{
    //inpATVal01 inpATValRes
    // reset error label
    document.getElementById('lblATValErr01').style.visibility = 'hidden';
    document.getElementById('lblATValErr02').style.visibility = 'hidden';
    document.getElementById('lblATValErr03').style.visibility = 'hidden';
    document.getElementById('lblATValErr04').style.visibility = 'hidden';
    document.getElementById('lblATValErr05').style.visibility = 'hidden';

    // validate field inputs to show error message
    validate_required('inpATVal01', 'lblATValErr01');
    validate_required('inpATVal02', 'lblATValErr02');
    validate_required('inpATVal03', 'lblATValErr03');
    validate_required('inpATVal04', 'lblATValErr04');
    validate_required('inpATVal05', 'lblATValErr05');

    // get field values
    var avgATVal01 = parseFloat(document.getElementById('inpATVal01').value);
    var avgATVal02 = parseFloat(document.getElementById('inpATVal02').value);
    var avgATVal03 = parseFloat(document.getElementById('inpATVal03').value);
    var avgATVal04 = parseFloat(document.getElementById('inpATVal04').value);
    var avgATVal05 = parseFloat(document.getElementById('inpATVal05').value);

    // Count number of fields to use for average denominator
    var val01;
    var val02;
    var val03;
    var val04;
    var val05;
    var atvCounter = 0; // reset counter
    if (avgATVal01 && avgATVal01 > 0) { atvCounter = atvCounter + 1; };
    if (avgATVal02 && avgATVal02 > 0) { atvCounter = atvCounter + 1; };
    if (avgATVal03 && avgATVal03 > 0) { atvCounter = atvCounter + 1; };
    if (avgATVal04 && avgATVal04 > 0) { atvCounter = atvCounter + 1; };
    if (avgATVal05 && avgATVal05 > 0) { atvCounter = atvCounter + 1; };

    // do average
    var totVal = avgATVal01 + avgATVal02 + avgATVal03 + avgATVal04 + avgATVal05;

    if (isNaN(totVal)) { totVal = 0 };

    var avgATValRes = (totVal / 5).toFixed(2);
    //avgATValRes = avgATValRes.toFixed(2);
    document.getElementById('inpATValRes').value = avgATValRes;

    if (isNaN(avgATValRes) || avgATValRes <= 0) {
        document.getElementById('inpATValRes').value = 0;
        document.getElementById('btnapplyaverage').style.visibility = "hidden";
    };

    if (totVal > 0) {
        document.getElementById('btnapplyaverage').style.visibility = "visible";

    };



}
// end function




function applycoveragelvl_cad(level)
{
    // moved the call out chart with single/family amounts shown.
    // currently not used

    var inpTvalFloor = document.getElementById('inpTvalFloor');
    if (inpTvalFloor) { inpTvalFloor.value = level; } else { inpTvalFloor.value = 10200; }

    // change innerhtml of callout
    //var callval = document.getElementById('chartcallout');
    //if (level && level >= 10200) {
    // callval.innerHTML = "Cadillac Tax for Individual Coverage: $10,200";
    //callval.style.visibility = "visible";
    //callval.style.display = "block";
    //}

    //if (level && level >= 27500) {
    //callval.innerHTML = "Cadillac Tax for Family Coverage: $27,500";
    //callval.style.visibility = "visible";
    // callval.style.display = "block";
    // }



    //end func
}

function changecols_cad()
{

    var chtHeight = document.getElementById('vertgraph').clientHeight;
    // height of the chart div wrapper
    var strLength = chtHeight.length;
    var devisor;
    var maxV = document.getElementById('inpAp2023').value;
    var bottomoff = 40; // set bottom offset
    var round = 1.0; // round the values by thousands


    if (isNaN(elHeight)) { elHeight = 100; }

    var factor = (maxV / chtHeight) * 1.5;
    // factor is used to scale the values to fit the chart div
    var elVal = document.getElementById('inpTvalFloor').value;
    var offset = 36;
    //css value by which the charts are offset from the bottom
    var elHeight = (elVal / factor) + offset;



    //formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2)

    var elVal = document.getElementById('inpAp2011').value;
    if (isNaN(elVal)) { elVal = 100; }

    if (elVal < 1) { elVal = 1; }
    if (elHeight < 1) { elHeight = 1; }
    if (factor < 1) { factor = 1; }
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv01';
    applypad_cad(inputlength, curdiv);

    // determine line position
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv01').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;



    var elVal = document.getElementById('inpAp2012').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv02';
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv02').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2013').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv03';
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv03').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2014').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv04';
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv04').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2015').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv05';
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv05').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2016').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv06';
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv06').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2017').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv07';
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv07').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    // Last 4 RED divs in back chart
    // Last 4 RED divs in back chart
    // Last 4 RED divs in back chart
    // Last 4 RED divs in back chart
    //
    var redtext_cad = '#aa0606';
    var plaintext_cad = '#000';

    var elVal = document.getElementById('inpAp2018').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv08';
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv08').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;




    var elVal = document.getElementById('inpAp2019').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv09';
    document.getElementById(curdiv).style.color = plaintext_cad;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv09').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;




    var elVal = document.getElementById('inpAp2020').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv10';
    document.getElementById(curdiv).style.color = plaintext_cad;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv10').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;



    var elVal = document.getElementById('inpAp2021').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv11';
    document.getElementById(curdiv).style.color = plaintext_cad;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv11').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;


    // not shown in chart after 20
    var elVal = document.getElementById('inpAp2022').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv12';
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv12').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpAp2023').value;
    var inputlength = elVal.length;
    var curdiv = 'lblValDiv13';
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartDiv13').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    // END tall chart

    // Begin front chart
    // chartDivFront01 (chart div) = inpBelThresh2011
    var elVal = document.getElementById('inpTval2011').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    document.getElementById('chartDivFront01').style.height = elHeight + "px";

    var elVal = document.getElementById('inpTval2012').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    document.getElementById('chartDivFront02').style.height = elHeight + "px";

    var elVal = document.getElementById('inpTval2013').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    document.getElementById('chartDivFront03').style.height = elHeight + "px";

    var elVal = document.getElementById('inpTval2014').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    document.getElementById('chartDivFront04').style.height = elHeight + "px";

    var elVal = document.getElementById('inpTval2015').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    document.getElementById('chartDivFront05').style.height = elHeight + "px";

    var elVal = document.getElementById('inpTval2016').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    document.getElementById('chartDivFront06').style.height = elHeight + "px";

    var elVal = document.getElementById('inpTval2017').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    document.getElementById('chartDivFront07').style.height = elHeight + "px";

    // Last 4 GREEN divs in front of chart
    // Last 4 GREEN divs in front of chart
    // Last 4 GREEN divs in front of chart
    //

    var elVal = document.getElementById('inpTvalFloor').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    document.getElementById('chartDivFront08').style.height = elHeight + "px";
    // evaluate if to show front bar -- uses same code as bar on back if no penalty inpTTOEe2018
    var colfloor = document.getElementById('inpBelThresh2018').value; // 11095
    var colap = document.getElementById('inpAp2018').value; //11692
    if ((colap - colfloor) < 0) {
        //elHeight = 0;
        var elVal = colap;
        var inputlength = elVal.length;
        var curdiv = 'lblValDiv08';
        applypad_cad(inputlength, curdiv);
        var elHeight = elVal / factor; // scales the chart height
        document.getElementById('chartDivFront08').style.height = elHeight + "px";
    };







    var elVal = document.getElementById('inpTval2019').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    document.getElementById('chartDivFront09').style.height = elHeight + "px";
    // evaluate if to show front bar
    var colfloor = document.getElementById('inpTval2019').value;
    var colap = document.getElementById('inpAp2019').value;
    if ((colap - colfloor) < 0) {
        elHeight = 0;
        var elVal = document.getElementById('inpAp2019').value;
        var inputlength = elVal.length;
        var curdiv = 'lblValDiv09';
        applypad_cad(inputlength, curdiv);
        var elHeight = elVal / factor; // scales the chart height
        document.getElementById('chartDivFront09').style.height = elHeight + "px";
    };


    var elVal = document.getElementById('inpTval2020').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    document.getElementById('chartDivFront10').style.height = elHeight + "px";
    // evaluate if to show front bar
    var colfloor = document.getElementById('inpTval2020').value;
    var colap = document.getElementById('inpAp2020').value;
    if ((colap - colfloor) < 0) {
        elHeight = 0;
        var elVal = document.getElementById('inpAp2020').value;
        var inputlength = elVal.length;
        var curdiv = 'lblValDiv10';
        applypad_cad(inputlength, curdiv);
        var elHeight = elVal / factor; // scales the chart height
        document.getElementById('chartDivFront10').style.height = elHeight + "px";
    };

    var elVal = document.getElementById('inpTval2021').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    document.getElementById('chartDivFront11').style.height = elHeight + "px";
    // evaluate if to show front bar
    var colfloor = document.getElementById('inpTval2021').value;
    var colap = document.getElementById('inpAp2021').value;
    if ((colap - colfloor) < 0) {
        elHeight = 0;
        var elVal = document.getElementById('inpAp2021').value;
        var inputlength = elVal.length;
        var curdiv = 'lblValDiv11';
        applypad_cad(inputlength, curdiv);
        var elHeight = elVal / factor; // scales the chart height
        document.getElementById('chartDivFront11').style.height = elHeight + "px";
    };


    // these two do not show in the chart.
    var elVal = document.getElementById('inpBelThresh2022').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    // evaluate if to show front bar
    var colfloor = document.getElementById('inpTval2022').value;
    var colap = document.getElementById('inpAp2022').value;
    if (colfloor > colap) { elHeight = 0; };
    document.getElementById('chartDivFront12').style.height = elHeight + "px";

    var elVal = document.getElementById('inpBelThresh2023').value;
    var inputlength = elVal.length;
    applypad_cad(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    // evaluate if to show front bar
    var colfloor = document.getElementById('inpTval2023').value;
    var colap = document.getElementById('inpAp2023').value;
    if (colfloor > colap) { elHeight = 0; };
    document.getElementById('chartDivFront13').style.height = elHeight + "px";

    // display the chart divs
    showcaddivs('chart1p1');
    showcaddivs('chart1p2');
    showcaddivs('divchart1outer')
    showcaddivs('divchartTTOwrapper')
    showcaddivs('divchartTTOouter')
}
// end function


function applypad_cad(length, divid)
{
    // Provide default values for the optional arguments
    if (!length) length = 1;
    if (!divid) divid = 'lblValDiv01';
    if (length > 5) { document.getElementById(divid).style.marginLeft = "-6px"; }
    if (length > 6) { document.getElementById(divid).style.marginLeft = "-7px"; }
    if (length > 7) { document.getElementById(divid).style.marginLeft = "-8px"; }
    if (length > 8) { document.getElementById(divid).style.marginLeft = "-9px"; }
    if (length > 9) { document.getElementById(divid).style.marginLeft = "-10px"; }

}
// end function applypad_cad



//Calculator
function usenewtrend_cad()
{

    // use the trend amount calculated from the average
    var trendpercent = parseFloat(document.MainForm.inpATValRes.value) * .01 + 1;
    if (isNaN(trendpercent)) { trendpercent = "1"; }
    var basevalue = parseFloat(document.MainForm.inpap.value);
    if (isNaN(basevalue)) { basevalue = "1"; }

    calcTrendVals_cad(trendpercent, basevalue);
}


// table 1 - Total Expenses script
function calcTrend_cad()
{

    // Trend = value input (basevalue) compounded
    // by the percentage input (trendpercent)
    // total value numeric
    var trendpercent = parseFloat(document.MainForm.inptrend.value) * .01 + 1;
    if (isNaN(trendpercent)) { trendpercent = "1"; }
    var basevalue = parseFloat(document.MainForm.inpap.value);
    if (isNaN(basevalue)) { basevalue = "1"; }
    calcTrendVals_cad(trendpercent, basevalue);
}

function calcTrendVals_cad(trendpercent, basevalue)
{

    // Calculates the increase of the Total EE Premium cost based on selected Trend Percent
    if (isNumeric(basevalue) && isNumeric(trendpercent)) {

        // determine the premium increase based on the trend percent.
        inpCost2011 = basevalue;
        inpCost2012 = inpCost2011;
        basevalue = inpCost2012;
        inpCost2013 = inpCost2012 * trendpercent;
        basevalue = inpCost2013;
        inpCost2014 = inpCost2013 * trendpercent;
        basevalue = inpCost2014;
        inpCost2015 = inpCost2014 * trendpercent;
        basevalue = inpCost2015;
        inpCost2016 = inpCost2015 * trendpercent;
        basevalue = inpCost2016;
        inpCost2017 = inpCost2016 * trendpercent;
        basevalue = inpCost2017;
        inpCost2018 = inpCost2017 * trendpercent;
        basevalue = inpCost2018;
        inpCost2019 = inpCost2018 * trendpercent;
        basevalue = inpCost2019;
        inpCost2020 = inpCost2019 * trendpercent;
        basevalue = inpCost2020;
        inpCost2021 = inpCost2020 * trendpercent;
        basevalue = inpCost2021;
        inpCost2022 = inpCost2021 * trendpercent;
        basevalue = inpCost2022;
        inpCost2023 = inpCost2022 * trendpercent;
        basevalue = inpCost2023;

        // set form input values  base input left column compounding   
      // changed 1-26-12
        document.getElementById('inpAp2011').value = Math.round(inpCost2011);
        document.getElementById('inpAp2012').value = Math.round(inpCost2012);
        document.getElementById('inpAp2013').value = Math.round(inpCost2013);
        document.getElementById('inpAp2014').value = Math.round(inpCost2014);
        document.getElementById('inpAp2015').value = Math.round(inpCost2015);
        document.getElementById('inpAp2016').value = Math.round(inpCost2016);
        document.getElementById('inpAp2017').value = Math.round(inpCost2017);
        document.getElementById('inpAp2018').value = Math.round(inpCost2018);
        document.getElementById('inpAp2019').value = Math.round(inpCost2019);
        document.getElementById('inpAp2020').value = Math.round(inpCost2020);
        document.getElementById('inpAp2021').value = Math.round(inpCost2021);
        document.getElementById('inpAp2022').value = Math.round(inpCost2022);
        document.getElementById('inpAp2023').value = Math.round(inpCost2023);

        // set default for floor
        if (!document.getElementById('inpTvalFloor').value) {
            document.getElementById('inpTvalFloor').value = 10200;
        }

        var floor = document.getElementById('inpTvalFloor').value;
        var discount = 0.4;
        var inflation1 = 1.04; // 2018 (inpCost2020) only is 4%
        var inflation2 = 1.03; // 2019+ (inpCost2021+) and beyond = 3%

        // Determine Employee tax costs based in annual premium input
        // Threshold as Indexed: -- inpTval
        // Taxes owed per empmployee -- inpTTOEe
        var varTTOEe2011 = (inpCost2011 - floor) * discount;
        document.getElementById('inpTTOEe2011').value = Math.round(varTTOEe2011);
        document.getElementById('inpTvalFloor').value = floor;
        document.getElementById('inpTval2011').value = 0;
        var varTTOEe2012 = (inpCost2012 - floor) * discount;
        document.getElementById('inpTTOEe2012').value = Math.round(varTTOEe2012);
        document.getElementById('inpTval2012').value = 0;
        var varTTOEe2013 = (inpCost2013 - floor) * discount;
        document.getElementById('inpTTOEe2013').value = Math.round(varTTOEe2013);
        document.getElementById('inpTval2013').value = 0;
        var varTTOEe2014 = (inpCost2014 - floor) * discount;
        document.getElementById('inpTTOEe2014').value = Math.round(varTTOEe2014);
        document.getElementById('inpTval2014').value = 0;
        var varTTOEe2015 = (inpCost2015 - floor) * discount;
        document.getElementById('inpTTOEe2015').value = Math.round(varTTOEe2015);
        document.getElementById('inpTval2015').value = 0;
        var varTTOEe2016 = (inpCost2016 - floor) * discount;
        document.getElementById('inpTTOEe2016').value = Math.round(varTTOEe2016);
        document.getElementById('inpTval2016').value = 0;
        var varTTOEe2017 = (inpCost2017 - floor) * discount;
        document.getElementById('inpTTOEe2017').value = Math.round(varTTOEe2017);
        document.getElementById('inpTval2017').value = 0;
        // values above set to 0 since they do not show before 2018

        // inpTval2018 is the floor named inpTvalFloor above
        var varTTOEe2018 = ((inpCost2018 - floor) * discount);
        document.getElementById('inpTTOEe2018').value = Math.round(varTTOEe2018);
        document.getElementById('inpTvalFloor').value = floor;

        var varTTOEe2019 = ((inpCost2019 - (floor * inflation1)) * discount);
        document.getElementById('inpTTOEe2019').value = Math.round(varTTOEe2019);
        floor = Math.round((floor * inflation1));
        document.getElementById('inpTval2019').value = floor;

        var varTTOEe2020 = ((inpCost2020 - (floor * inflation2)) * discount);
        document.getElementById('inpTTOEe2020').value = Math.round(varTTOEe2020);
        floor = Math.round((floor * inflation2));
        document.getElementById('inpTval2020').value = floor;

        var varTTOEe2021 = ((inpCost2021 - (floor * inflation2)) * discount);
        document.getElementById('inpTTOEe2021').value = Math.round(varTTOEe2021);
        floor = Math.round((floor * inflation2));
        document.getElementById('inpTval2021').value = floor;

        var varTTOEe2022 = ((inpCost2022 - (floor * inflation2)) * discount);
        document.getElementById('inpTTOEe2022').value = Math.round(varTTOEe2022);
        floor = Math.round((floor * inflation2));
        document.getElementById('inpTval2022').value = floor;
        var varTTOEe2023 = ((inpCost2023 - (floor * inflation2)) * discount);
        document.getElementById('inpTTOEe2023').value = Math.round(varTTOEe2023);
        floor = Math.round((floor * inflation2));
        document.getElementById('inpTval2023').value = floor;

        // Calculate total cost for ER
        //ee's x individual cost = ER cost


        // Total Tax owed Employer:  (Tax owed x # Emps)
        var eecount = parseFloat(document.getElementById('inpnumbemployees').value);
        if (isNaN(eecount)) { eecount = "1"; } //set default
        var ttval01 = varTTOEe2011 * eecount;
        var ttval02 = varTTOEe2012 * eecount;
        var ttval03 = varTTOEe2013 * eecount;
        var ttval04 = varTTOEe2014 * eecount;
        var ttval05 = varTTOEe2015 * eecount;
        var ttval06 = varTTOEe2016 * eecount;
        var ttval07 = varTTOEe2017 * eecount;
        var ttval08 = varTTOEe2018 * eecount;
        var ttval09 = varTTOEe2019 * eecount;
        var ttval10 = varTTOEe2020 * eecount;
        var ttval11 = varTTOEe2021 * eecount;
        var ttval12 = varTTOEe2022 * eecount;
        var ttval13 = varTTOEe2023 * eecount;

        //Total Tax owed Employer:
        document.getElementById('inpTT2011').value = Math.round(ttval01);
        document.getElementById('inpTT2012').value = Math.round(ttval02);
        document.getElementById('inpTT2013').value = Math.round(ttval03);
        document.getElementById('inpTT2014').value = Math.round(ttval04);
        document.getElementById('inpTT2015').value = Math.round(ttval05);
        document.getElementById('inpTT2016').value = Math.round(ttval06);
        document.getElementById('inpTT2017').value = Math.round(ttval07);
        document.getElementById('inpTT2018').value = Math.round(ttval08);
        document.getElementById('inpTT2019').value = Math.round(ttval09);
        document.getElementById('inpTT2020').value = Math.round(ttval10);
        document.getElementById('inpTT2021').value = Math.round(ttval11);
        document.getElementById('inpTT2022').value = Math.round(ttval12);
        document.getElementById('inpTT2023').value = Math.round(ttval13);

        // Total Premium:
        document.getElementById('inpTP2011').value = Math.round(inpCost2011 * eecount);
        document.getElementById('inpTP2012').value = Math.round(inpCost2012 * eecount);
        document.getElementById('inpTP2013').value = Math.round(inpCost2013 * eecount);
        document.getElementById('inpTP2014').value = Math.round(inpCost2014 * eecount);
        document.getElementById('inpTP2015').value = Math.round(inpCost2015 * eecount);
        document.getElementById('inpTP2016').value = Math.round(inpCost2016 * eecount);
        document.getElementById('inpTP2017').value = Math.round(inpCost2017 * eecount);
        document.getElementById('inpTP2018').value = Math.round(inpCost2018 * eecount);
        document.getElementById('inpTP2019').value = Math.round(inpCost2019 * eecount);
        document.getElementById('inpTP2020').value = Math.round(inpCost2020 * eecount);
        document.getElementById('inpTP2021').value = Math.round(inpCost2021 * eecount);
        document.getElementById('inpTP2022').value = Math.round(inpCost2022 * eecount);
        document.getElementById('inpTP2023').value = Math.round(inpCost2023 * eecount);

        // Lower Bar segments
        // equals ttoe - tval
        // Threshold not subtracted until 2019
        document.getElementById('inpBelThresh2011').value =
            parseFloat(document.getElementById('inpAp2011').value) +
            parseFloat(document.getElementById('inpTTOEe2011').value);

        document.getElementById('inpBelThresh2012').value =
            parseFloat(document.getElementById('inpTval2012').value) +
            parseFloat(document.getElementById('inpTTOEe2012').value);
        document.getElementById('inpBelThresh2013').value =
            parseFloat(document.getElementById('inpTval2013').value) +
            parseFloat(document.getElementById('inpTTOEe2013').value);

        document.getElementById('inpBelThresh2014').value =
            parseFloat(document.getElementById('inpTval2014').value) +
            parseFloat(document.getElementById('inpTTOEe2014').value);

        document.getElementById('inpBelThresh2015').value =
            parseFloat(document.getElementById('inpTval2015').value) +
            parseFloat(document.getElementById('inpTTOEe2016').value);

        document.getElementById('inpBelThresh2016').value =
            parseFloat(document.getElementById('inpTval2016').value) +
            parseFloat(document.getElementById('inpTTOEe2016').value);

        document.getElementById('inpBelThresh2017').value =
            parseFloat(document.getElementById('inpTvalFloor').value) +
            parseFloat(document.getElementById('inpTTOEe2017').value);

        document.getElementById('inpBelThresh2018').value =
            parseFloat(document.getElementById('inpAp2018').value) -
            parseFloat(document.getElementById('inpTTOEe2018').value);

        document.getElementById('inpBelThresh2019').value =
            parseFloat(document.getElementById('inpAp2019').value) -
            parseFloat(document.getElementById('inpTTOEe2019').value);

        document.getElementById('inpBelThresh2020').value =
            parseFloat(document.getElementById('inpAp2020').value) -
            parseFloat(document.getElementById('inpTTOEe2020').value);

        document.getElementById('inpBelThresh2021').value =
            parseFloat(document.getElementById('inpAp2021').value) -
            parseFloat(document.getElementById('inpTTOEe2021').value);

        document.getElementById('inpBelThresh2022').value =
            parseFloat(document.getElementById('inpAp2022').value) -
            parseFloat(document.getElementById('inpTTOEe2022').value);

        document.getElementById('inpBelThresh2023').value =
            parseFloat(document.getElementById('inpAp2023').value) -
            parseFloat(document.getElementById('inpTTOEe2023').value);



    }
    // end if     

}
// end function

// Function changes the
function changecols_cadTTO()
{

    var chtHeight = document.getElementById('vertgraph').clientHeight;
    // height of the chart div wrapper
    var strLength = chtHeight.length;
    var devisor;
    var maxV = document.getElementById('inpTT2023').value;
    var bottomoff = 40; // set bottom offset
    var round = 1; // round the values by thousands


    if (isNaN(elHeight)) { elHeight = 100; }
    //if (isnull(elHeight)) {document.getElementById('inpAp2019').innerHTML = "error";}

    var factor = (maxV / chtHeight) * 1.5;
    // scales the values to fit the chart div

    var elVal = document.getElementById('inpTT2011').value;
    if (elVal < 1) { elVal = 1; }
    if (elHeight < 1) { elHeight = 1; }
    if (factor < 1) { factor = 1; }
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv01'; //chartTTODiv01 lblTTODiv01 lblValTTODiv01
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv01').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpTT2012').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv02';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv02').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpTT2013').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv03';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv03').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpTT2014').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv04';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv04').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpTT2015').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv05';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv05').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpTT2016').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv06';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv06').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpTT2017').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv07';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv07').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    var elVal = document.getElementById('inpTT2018').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv08';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv08').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;
    // use this amount in the lead in text above the first chart -- chart1lb1
    document.getElementById('chart1lb1').innerHTML = chartlabel;


    // 2019
    var elVal = document.getElementById('inpTT2019').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv09';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv09').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;


    // 2020 4% inflation
    var elVal = document.getElementById('inpTT2020').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv10';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv10').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;


    // 2021 3% inflation
    var elVal = document.getElementById('inpTT2021').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv11';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv11').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;


    // 2022 3% inflation
    var elVal = document.getElementById('inpTT2022').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv12';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv12').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    // 2023 3% inflation
    var elVal = document.getElementById('inpTT2023').value;
    if (elVal < 0) elVal = 0;
    var inputlength = elVal.length;
    var curdiv = 'lblValTTODiv13';
    applypad_cadTTO(inputlength, curdiv);
    var elHeight = elVal / factor; // scales the chart height
    var chartlabel = formatNumber((elVal * round), 0, ',', '', '$', '', '-', '');
    document.getElementById('chartTTODiv13').style.height = elHeight + "px";
    document.getElementById(curdiv).style.bottom = (elHeight + bottomoff) + "px";
    document.getElementById(curdiv).innerHTML = chartlabel;

    // modified 5-4-2011
    // Evaluate tax amounts to determine display values in opening paragraph of chart
    if (document.getElementById('inpTT2021').value <= 0) {
        document.getElementById('chart1lb1').innerHTML = " $0";
        document.getElementById('lblFirstYear_1').innerHTML = "not applicable";
        document.getElementById('lblFirstYear_2').innerHTML = "tax owed is";
    };
    if (document.getElementById('inpTT2021').value > 0) {
        var displayval = document.getElementById('inpTT2021').value;
        displayval = formatNumber(displayval, 0, ',', '', '$', '', '-', '');
        document.getElementById('chart1lb1').innerHTML = displayval;
        document.getElementById('lblFirstYear_1').innerHTML = "2021";
        document.getElementById('lblFirstYear_2').innerHTML = "tax owed in 2021 = ";
    };
    if (document.getElementById('inpTT2020').value > 0) {
        var displayval = document.getElementById('inpTT2020').value;
        displayval = formatNumber(displayval, 0, ',', '', '$', '', '-', '');
        document.getElementById('chart1lb1').innerHTML = displayval;
        document.getElementById('lblFirstYear_1').innerHTML = "2020";
        document.getElementById('lblFirstYear_2').innerHTML = "tax owed in 2020 = ";
    };
    if (document.getElementById('inpTT2019').value > 0) {
        var displayval = document.getElementById('inpTT2019').value;
        displayval = formatNumber(displayval, 0, ',', '', '$', '', '-', '');
        document.getElementById('chart1lb1').innerHTML = displayval;
        document.getElementById('lblFirstYear_1').innerHTML = "2019";
        document.getElementById('lblFirstYear_2').innerHTML = "tax owed in 2019 = ";
    };

    if (document.getElementById('inpTT2018').value > 0) {
        var displayval = document.getElementById('inpTT2018').value;
        displayval = formatNumber(displayval, 0, ',', '', '$', '', '-', '');
        document.getElementById('chart1lb1').innerHTML = displayval;
        document.getElementById('lblFirstYear_1').innerHTML = "2018";
        document.getElementById('lblFirstYear_2').innerHTML = "tax owed in 2018 = ";
    };

    // end function
}
// end function

function applypad_cadTTO(length, divid)
{
    // Provide default values for the optional arguments
    if (!length) length = 1;
    if (!divid) divid = 'lblValTTODiv01';
    if (length > 5) { document.getElementById(divid).style.marginLeft = "-6px"; }
    if (length > 6) { document.getElementById(divid).style.marginLeft = "-7px"; }
    if (length > 7) { document.getElementById(divid).style.marginLeft = "-8px"; }
    if (length > 8) { document.getElementById(divid).style.marginLeft = "-9px"; }
    if (length > 9) { document.getElementById(divid).style.marginLeft = "-10px"; }

}
// end function

function showcaddivs(divid)
{
    if (divid) {
        document.getElementById(divid).style.visibility = "visible";
        document.getElementById(divid).style.display = "block";
    }

}

// ********                                                         **********
// ********                                                         **********
// END Cadillac Tax Calculator
// END Cadillac Tax Calculator
// END Cadillac Tax Calculator
// ********                                                         **********
// ********                                                         **********














// ********                                             ********
// ******** Functions used in all charts, do not remove ********
// ********                                             ********


// Validates inputs
function validate_required(field, label)
{
    //reset first
    document.getElementById(label).style.visibility = 'hidden';
    field = document.getElementById(field).value;
    if (isNaN(field)) {
        document.getElementById(label).style.visibility = 'visible';
    }
}
//end

// number formatting function
// copyright Stephen Chapman 24th March 2006, 22nd August 2008
// permission to use this function is granted provided
// that this copyright notice is retained intact

function formatNumber(num, dec, thou, pnt, curr1, curr2, n1, n2)
{
    var x = Math.round(num * Math.pow(10, dec));
    if (x >= 0) n1 = n2 = '';
    var y = ('' + Math.abs(x)).split('');
    var z = y.length - dec;
    if (z < 0) z--;
    for (var i = z; i < 0; i++) y.unshift('0');
    if (z < 0) z = 1; y.splice(z, 0, pnt);
    if (y[0] == pnt) y.unshift('0');
    while (z > 3) { z -= 3; y.splice(z, 0, thou); }
    var r = curr1 + n1 + y.join('') + n2 + curr2;
    return r;
}
// end formatNumber function


// begin isnumeric function
function isNumeric(strString)
//  check for valid numeric strings  
{
    var strValidChars = "0123456789.";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) blnResult = false;
    }
    return blnResult;
}
// end isnumeric

function CurrencyFormatted(amount)
{
    var i = parseFloat(amount);
    if (isNaN(i)) { i = 0.00; }
    var minus = '';
    if (i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if (s.indexOf('.') < 0) { s += '.00'; }
    if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return s;
}
// end of function CurrencyFormatted()

function CommaFormatted(amount)
{
    var delimiter = ","; // replace comma if desired
    var a = amount.split('.', 2)
    var d = a[1];
    var i = parseInt(a[0]);
    if (isNaN(i)) { return ''; }
    var minus = '';
    if (i < 0) { minus = '-'; }
    i = Math.abs(i);
    var n = new String(i);
    var a = [];
    while (n.length > 3) {
        var nn = n.substr(n.length - 3);
        a.unshift(nn);
        n = n.substr(0, n.length - 3);
    }
    if (n.length > 0) { a.unshift(n); }
    n = a.join(delimiter);
    if (d.length < 1) { amount = n; }
    else { amount = n + '.' + d; }
    amount = minus + amount;
    return amount;
}
// end of function CommaFormatted()

function formatCurrency(num)
{
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' +
num.substring(num.length - (4 * i + 3));
    return (((sign) ? '' : '-') + '$' + num + '.' + cents);
}
// end function

// number formatting function
// copyright Stephen Chapman 24th March 2006, 22nd August 2008
// permission to use this function is granted provided
// that this copyright notice is retained intact

function formatNumber(num, dec, thou, pnt, curr1, curr2, n1, n2)
{
    var x = Math.round(num * Math.pow(10, dec));
    if (x >= 0) n1 = n2 = '';
    var y = ('' + Math.abs(x)).split('');
    var z = y.length - dec;
    if (z < 0) z--;
    for (var i = z; i < 0; i++) y.unshift('0');
    if (z < 0) z = 1; y.splice(z, 0, pnt);
    if (y[0] == pnt) y.unshift('0');
    while (z > 3) { z -= 3; y.splice(z, 0, thou); }
    var r = curr1 + n1 + y.join('') + n2 + curr2;
    return r;
}
// end function


  
