﻿//-------------------------------------------------------------------------------

var _rblCalcType;
var _txtFirstIncome;
var _txtSecondIncome;
var _txtJointIncome;
var _txtIncome;
var _txtMultiplier;
var _txtFirstMultiplier;
var _txtSecondMultiplier;
var _txtJointMultiplier;

function Initialise(rblCalcType, txtFirstIncome, txtSecondIncome, txtJointIncome, txtIncome, txtMultiplier, txtFirstMultiplier, txtSecondMultiplier, txtJointMultiplier)
{
    _rblCalcType = document.getElementsByName(rblCalcType);
    _txtFirstIncome = document.getElementById(txtFirstIncome);;
    _txtSecondIncome = document.getElementById(txtSecondIncome);
    _txtJointIncome = document.getElementById(txtJointIncome);
    _txtIncome = document.getElementById(txtIncome);
    _txtMultiplier = document.getElementById(txtMultiplier);
    _txtFirstMultiplier = document.getElementById(txtFirstMultiplier);
    _txtSecondMultiplier = document.getElementById(txtSecondMultiplier);
    _txtJointMultiplier = document.getElementById(txtJointMultiplier);
}

function SwitchSingleJoint()
{
    var single01 = document.getElementById('dphSingle01');
    var single02 = document.getElementById('dphSingle02');
    var joint01 = document.getElementById('dphJoint01');
    var joint02 = document.getElementById('dphJoint02');
    
    if (_rblCalcType[0].checked)
    {
        single01.style.display = 'block';
        single02.style.display = 'block';
        joint01.style.display = 'none';
        joint02.style.display = 'none';
    }
    else
    {
        single01.style.display = 'none';
        single02.style.display = 'none';
        joint01.style.display = 'block';
        joint02.style.display = 'block';
    }
}

function CalculateJointIncome()
{
    var jointIncomeTotal = 0;
    if ((!isBlank(_txtFirstIncome.value)) && (isFloatingPt(_txtFirstIncome.value)))
        jointIncomeTotal += parseFloat(_txtFirstIncome.value);
    if ((!isBlank(_txtSecondIncome.value)) && (isFloatingPt(_txtSecondIncome.value)))
        jointIncomeTotal += parseFloat(_txtSecondIncome.value);
    
    _txtJointIncome.value = jointIncomeTotal;
}

function CheckForm()
{
    if (_rblCalcType[0].checked == true)
    {
        if (isFloatingPt(_txtIncome.value)==false)
        {
            alert("Please enter a numeric value for the main earner's income.");
            _txtIncome.focus();
            return false;
        }
 
        if (isFloatingPt(_txtMultiplier.value)==false)
        {
            alert("Please enter a numeric value for the income multiplier.");
            _txtMultiplier.focus();
            return false;
        }
    }
    else
    {
        if (isFloatingPt(_txtFirstIncome.value)==false)
        {
            alert("Please enter a numeric value for the main earner's income.");
            _txtFirstIncome.focus();
            return false;
        }

        if (isFloatingPt(_txtFirstMultiplier.value)==false)
        {
            alert("Please enter a numeric value for the main earner's income multiplier.");
            _txtFirstMultiplier.focus();
            return false;
        }

        if (isFloatingPt(_txtSecondIncome.value)==false)
        {
            alert("Please enter a numeric value for the second earner's income.");
            _txtSecondIncome.focus();
            return false;
        }
        
        if (isFloatingPt(_txtSecondMultiplier.value)==false)
        {
            alert("Please enter a numeric value for the second earner's income multiplier.");
            _txtSecondMultiplier.focus();
            return false;
        }

        if (isFloatingPt(_txtJointMultiplier.value)==false)
        {
            alert("Please enter a numeric value for the combined earnings income multiplier.");
            _txtJointMultiplier.focus();
            return false;
        }
    }
    return true;
}
