<!-- Hide from old browsers
var isNav;
var isIE;
if (parseInt(navigator.appVersion) >= 4)
{
   if (navigator.appName == "Netscape")
   {
      isNav = true;
   }
   else
   {
      isIE = true;
   }
}


        var min_warning = 50;
        var max_warning = 5000;
        var max_warning_joint = 5000;
        var max_warning_separate = 2500;
        var max_numeric = 1000000;

        // taxBracket and taxSchedule modified from O'Reilly

function taxBracket(cutoff, percentage)
{
        this.cutoff = cutoff;
        this.percentage = percentage;
}

function taxSchedule(aa, bb, cc, dd, ee, ff)
{
       this[0] = aa; this[1] = bb; this[2] = cc; this[3] = dd; this[4] = ee; this[5] = ff;
}


var Schedules = new Object();


// **** updated for 2006 tax table **** 
// Blank
Schedules[0] = new taxSchedule(new taxBracket(336551, .35), new taxBracket(154801, .33), new taxBracket(74201, .28), new taxBracket(30651, .25), new taxBracket(7551, .15), new taxBracket(0, .10));

// Single
Schedules[1] = new taxSchedule(new taxBracket(336551, .35), new taxBracket(154801, .33), new taxBracket(74201, .28), new taxBracket(30651, .25), new taxBracket(7551, .15), new taxBracket(0, .10));

// Head of Household
Schedules[2] = new taxSchedule(new taxBracket(336551, .35), new taxBracket(171651, .33), new taxBracket(106001, .28), new taxBracket(41051, .25), new taxBracket(10751, .15), new taxBracket(0, .10));

// Joint
Schedules[3] = new taxSchedule(new taxBracket(336551, .35), new taxBracket(188451, .33), new taxBracket(123701, .28), new taxBracket(61301, .25), new taxBracket(15101, .15), new taxBracket(0, .10));

// Separate
Schedules[4] = new taxSchedule(new taxBracket(168276, .35), new taxBracket(94226, .33), new taxBracket(61851, .28), new taxBracket(30651, .25), new taxBracket(7551, .15),new taxBracket(0, .10));


  var m_deduction;              // holds the std deductions - based on the selection
  var m_noOfExemptions; // no of exmp - based on the selection
  var Deductions = new Object();

        // Single
        Deductions[1] = 5150;

        // Head of Household
        Deductions[2] = 7550;

        // Joint
        Deductions[3] = 10300;

        // Separate
        Deductions[4] = 5150;


function calculate(form)
{
                if ( !finalErrorCheck (form))
                        return;

                var total_expenses = 0;
                var total_savings = 0;
                var high_fica = .0765;
                var low_fica = .0145;
                var fica = 0;
                var total_income = 0;
                var tax_bracket = 0;
                var VPDCval = 0;
                var total_expenses = 0.0;
                var messageStr = "NOTE : ";


                var m_nonPeriod = parseFloat (form.nonperiodic.value);
                var m_perValue = parseFloat (form.per.value);
                var m_multiplier = parseFloat (form.multiplier.value);

                total_expenses = m_perValue * m_multiplier + m_nonPeriod;

                if ( (document.dependent.status.options[4].selected) && (total_expenses > max_warning_separate) )
                {
                         total_expenses = max_warning_separate;
                         messageStr += "\nIf you are married and filing separately the maximum annual contribution allowed is $2500. This value will be used instead of your current estimated expenses, which are more than the maximum contribution allowed.\n";
                 }
                else
                  if (total_expenses < min_warning)
                  {
                         total_expenses = min_warning
                         messageStr += "\nThe minimum annual contribution allowed is $50. This value will be used instead of your current estimated costs, which are less than the minimum contribution allowed.\n"
                  }
                 else
                  if (total_expenses > max_warning)
                  {
                                total_expenses = max_warning
                                messageStr += "\nThe maximum annual contribution allowed is $5,000. This value will be used instead of your current estimated costs, which exceed the maximum contribution allowed.\n"
                  }

                var salary = parseFloat (form.salary.value);
                var additional = parseFloat (form.additional.value);
                m_noOfExemptions = parseFloat (form.exemptions.value);

                var status = form.status.selectedIndex;

                total_income = (eval(salary - 0) + eval(additional - 0));
                m_deduction = parseFloat (form.deduction.value);
                total_income = total_income - (m_deduction + m_noOfExemptions * 3300)   ;

                if (total_income <= 0)
                {
                        total_income = 0;
                        total_savings = 0;
                        messageStr += "\nBecause your deductions exceed your income, we have assumed $0 tax savings for 2006.\n"
                }
                else
                {
                        // Find out which set of brackets to use, dependent upon filing status
                        var schedule = Schedules[status];
                        for(var j = 0; j < 6; j++)
                        {
                                if (total_income >= schedule[j].cutoff)
                                        break;
                        }

                        var taxBracket = schedule[j];
                        tax_bracket = taxBracket.percentage;

                        if(salary >= 94200)
                                fica = low_fica;
                        else
                                fica = high_fica;

                }

                // Calculates monthly VPDC
                if (document.dependent.status.options[4].selected)
                {
                        if (total_expenses > 2500)
                                VPDCval = 2500 / 12;
                        else
                                VPDCval = total_expenses / 12;
                }
                else
                {
                        if (total_expenses < 100)
                                VPDCval = 100 /12;
                        else
                          if (total_expenses > 5000)
                                VPDCval = 5000 / 12;
                          else
                                VPDCval = total_expenses / 12;
                }

                //form.monthlyVPDC.value =VPDCval;
                total_savings = total_expenses * round ( (tax_bracket - 0) + (fica - 0),4);

                form.tax.value = tax_bracket;
                form.adjusted_tax.value = round ( (tax_bracket - 0) + (fica - 0),4);
                form.fica.value = fica;
                //form.monthlyVPDC.value = formatString ( round(VPDCval,2) );
                form.totalsavings.value = formatString( round(total_savings,2) );
                form.total_income.value = formatString(total_income);
                form.totalexpenses.value = formatString( round(total_expenses,2) );

                messageStr += "\n";
                messageStr += "Total Savings :  ";
                messageStr += formatString( round(total_savings,2) );
                messageStr += "\nThis is only an estimate, your actual savings may vary.";
                form.warning.value = messageStr;
}

/************************************
// called by the calculate function
// check for valid entries
*************************************/
function finalErrorCheck (form)
{
        // now go through each of the text boxes and check for invalid entry

        if ( !isValid (form.per, 4) )
                return false;

        if ( !isValid (form.multiplier, 2) )
                return false;

        if ( !isValid (form.nonperiodic, 4) )
                return false;

        if ( form.status.selectedIndex==0 )
        {
                alert('Please select a Filing Status')
                return false
        }

        if ( !isValid (form.deduction, 3) )
                return false;

        if ( !isValid (form.exemptions, 1) )
                return false;

        if ( !isValid (form.salary, 4) )
                return false;

        if ( !isValid (form.additional, 4) )
                return false;

        return true;
}

function round(number,X)
{
        // rounds number to X decimal places, defaults to 2
        X = (!X ? 2 : X);
        return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

/*******************************************
Function that updates the Deduction and Exemption text fields
based on the selection.
*******************************************/
function UpdateTextFields (form)
{
        // get selection , set Deductions & exemption vars - update text box
        switch (form.status.selectedIndex)
        {
                case 1: // Single
                                m_deduction = Deductions[1];
                                m_noOfExemptions = 1;
                        break;
                case 2: // Head
                                m_deduction = Deductions[2];
                                m_noOfExemptions = 2;
                        break;
                case 3: // Married - Joint
                                m_deduction = Deductions[3];
                                m_noOfExemptions = 3;
                        break;
                case 4: // Married -sep
                                m_deduction = Deductions[4];
                                m_noOfExemptions = 2
                        break;
        } // end of switch
        // display the values in the text boxes
        form.deduction.value = m_deduction;
        form.exemptions.value = m_noOfExemptions;

} // end of UpdateTextFields ()


//data validations
function isNumber(inputVal)
{
        oneDecimal = false
        inputStr = inputVal.toString()
        for (var i = 0; i < inputStr.length; i++)
                {
                var oneChar = inputStr.charAt(i)

                if (i == 0 && oneChar == "-")
                                        {
                    return false
               }
                if (oneChar == "." && !oneDecimal)
                                        {
                    oneDecimal = true
                    continue
               }
                if (oneChar < "0" || oneChar > "9")
                                        {
                    return false
               }
        }
     return true
}
////////////////////////////////////////////////////
// func to format value to be displayed
// upto 2 decimal places
////////////////////////////////////////////////////
function formatString (value)
{
        var inputStr = value.toString ();
        var foundDot = 0;
        var noAfter = 0;

        for (var i = 0; i < inputStr.length; i++)
        {
                var inputChar = inputStr.charAt (i);
                if ( inputChar == ".")
                {
                        foundDot = 1;
                        continue;
                }
                if ( foundDot == 1)
                   noAfter ++;
                if (noAfter == 2)
                        break;
        } // end of for

        if ( foundDot == 0)
         {
                inputStr += ".00";
                return inputStr;
         }

         if ( noAfter == 1)
         {
                inputStr += "0";
                return inputStr;
         }

         return inputStr;
}

// Function to validate Data Range
// flag 1: exemptions text box
//      2: no of weeks
//      3: Std. deduction
//      4: range 0-1000000
function inRange(inputStr, flag, objectName)
{
        num = parseFloat(inputStr);


        if (num < 0.0 )
                return false;

        switch (flag)
         {
           case 1:  // exemptions
                        var inputMsg = inputStr.toString()
                        var oneChar = inputMsg.charAt(0)
                        var twoChar = inputMsg.charAt(1)
                        if (oneChar == "." || twoChar == ".")
                        {
                                var msgStr = "Invalid value in the Field ";
                                msgStr += objectName;

                                msgStr += "\nNo decimals allowed.";

                                alert(msgStr)
                                return false
                        }

                break;
           case 2: // no weeks
                        if (num > 52.0)
                        {
                                var msgStr = "Invalid value in the Field ";
                                msgStr += objectName;
                                msgStr += "\nRange : 0 - 52";
                                alert(msgStr);
                                return false;
                        }
                break;
           case 3: // stand deductions
                        if (num > 1000000.0 )
                         {
                                var msgStr = "Invalid value in the Field ";
                                msgStr += objectName;
                                msgStr += "\nRange : 0 - 1000000";
                                alert(msgStr);
                                return false;
                         }
                break;
                case 4: // range
                        if (num > 1000000.0 )
                         {
                        var msgStr = "Invalid value in the Field ";
                                msgStr += objectName;
                                msgStr += "\nRange : 0 - 1000000";
                                alert(msgStr);
                                return false;
                          }
                break;
        }
        return true;
}

// Master value validator routine
function isValid(inputObject, flag)
{
        var inputStr = inputObject.value;
        var messgStr = "Invalid value in the Field"
        var objectName = "";

        if ( inputObject.name =="per")
                objectName += " 'Eligible Dependent Care Expenses'."
        else
          if ( inputObject.name == "multiplier")
                objectName += " 'Number of weeks or months of care'."
        else
          if ( inputObject.name == "nonperiodic")
                objectName += " 'Non-Periodic Expenses'."
        else
          if ( inputObject.name == "deduction")
                objectName += " 'Standard Deduction'."
        else
          if ( inputObject.name == "exemptions" )
                objectName += " 'Number of Exemptions'."
        else
          if ( inputObject.name == "salary")
                objectName += " 'Your Annual Pay'."
        else
          if ( inputObject.name == "additional")
                objectName += " 'Additional Taxable Household Income'."

        if (inputStr == null || inputStr == "" || inputStr.length == 0)
    {
                messgStr += objectName;
                messgStr +="\nEmpty Text Box - Please enter a value."
       alert(messgStr);
       return false;
    }
        if (!isNumber(inputStr))
        {
                messgStr += objectName;
                messgStr += "\nPlease enter a valid whole number without any punctuation (such as commas or dollar signs)."
                alert(messgStr);
                return false;
    }

        if (!inRange(inputStr, flag, objectName) )
        {
                return false;
    }
        return true;
}


//end script hiding -->
