function hideAffordabilityCalculatorApplicant2(hide, applicant2BasicaAnnualIncomeObj, applicant2GrossIncomeObj,
            applicant2OtherRegularIncomeObj, applicant2MonthlyLoanPaymentObj,
            applicant2CreditCardBalanceObj, basicAnnualIncomeSpanObj, applicantspanObj, annualincomespanObj,
            regularincomespanObj, loanpaymentspanObj, ccbalancespanObj) {
    
    var visible = "";
    if (hide) {
        visible = "hidden";
        document.getElementById(applicant2BasicaAnnualIncomeObj).value = 0;
		document.getElementById(applicant2GrossIncomeObj).value = 0;
		document.getElementById(applicant2OtherRegularIncomeObj).value = 0;
		document.getElementById(applicant2MonthlyLoanPaymentObj).value = 0;
		document.getElementById(applicant2CreditCardBalanceObj).value = 0;
    } else {
        visible = "visible";
    }
    
    document.getElementById(basicAnnualIncomeSpanObj).style.visibility = visible;
    document.getElementById(annualincomespanObj).style.visibility = visible;
    document.getElementById(regularincomespanObj).style.visibility = visible;
    document.getElementById(loanpaymentspanObj).style.visibility = visible;
    document.getElementById(ccbalancespanObj).style.visibility = visible;
    document.getElementById(applicantspanObj).style.visibility = visible;
}

function affCalcNumberInRange(numeric, textBox, min, max, message)
{
    var valid = true;
    
    if (!(parseInt(numeric) >= min && parseInt(numeric) <= max))
    {
        alert(message);
        textBox.focus();
        valid = false;
    }
    
    return valid;
}

function affCalcNumericValid(numeric, textBox, emptyErrorMessage, invalidErrorMessage)
{
    var valid = true;   
    
    if (numeric == "")
    {
        alert(emptyErrorMessage);
        textBox.value = '0';
        textBox.focus();
        valid = false;
    }
    else if (isNaN(numeric))
    {
        alert(invalidErrorMessage != "" ? invalidErrorMessage : emptyErrorMessage);
        textBox.focus();
        valid = false;
    }

    return valid;
}


//Page specific javascript only
function affCalcValidate(app1BasicAnnualIncomeObjId, app1GuaranteedAnnualIncomeObjId, app1OtherRegularIncomeObjId, app1MonthlyLoanPaymentObjId, app1CCBalanceObjId,
    app2BasicAnnualIncomeObjId, app2GuaranteedAnnualIncomeObjId, app2OtherRegularIncomeObjId, app2MonthlyLoanPaymentObjId, app2CCBalanceObjId,
    numberOfDependantsObjId, termObjId, repaymentObjId, app1RadObjId, app2RadObjId, minTerm, maxTerm) {
    
    var app1BasicAnnualIncomeObj = document.getElementById(app1BasicAnnualIncomeObjId);
    var app1GuaranteedAnnualIncomeObj = document.getElementById(app1GuaranteedAnnualIncomeObjId);
    var app1OtherRegularIncomeObj = document.getElementById(app1OtherRegularIncomeObjId);
    var app1MonthlyLoanPaymentObj = document.getElementById(app1MonthlyLoanPaymentObjId);
    var app1CCBalanceObj = document.getElementById(app1CCBalanceObjId);
    var app2BasicAnnualIncomeObj = document.getElementById(app2BasicAnnualIncomeObjId);
    var app2GuaranteedAnnualIncomeObj = document.getElementById(app2GuaranteedAnnualIncomeObjId);
    var app2OtherRegularIncomeObj = document.getElementById(app2OtherRegularIncomeObjId);
    var app2MonthlyLoanPaymentObj = document.getElementById(app2MonthlyLoanPaymentObjId);
    var app2CCBalanceObj = document.getElementById(app2CCBalanceObjId);
    var numberOfDependantsObj = document.getElementById(numberOfDependantsObjId);
    var termObj = document.getElementById(termObjId);
    var app2RadObj = document.getElementById(app2RadObjId);
    
   // Basic annual income applicant 1
    if (!affCalcNumericValid(app1BasicAnnualIncomeObj.value, app1BasicAnnualIncomeObj, "Please enter a valid annual income for the first applicant.", ""))
        return false;
    else if (!affCalcNumberInRange(app1BasicAnnualIncomeObj.value, app1BasicAnnualIncomeObj, 1, 999999, "Please enter a valid annual income for the first applicant."))
        return false;

    // Basic annual income applicant 2
    if (app2RadObj.checked)
    {
        if (!affCalcNumericValid(app2BasicAnnualIncomeObj.value, app2BasicAnnualIncomeObj, "Please enter a valid annual income for the second applicant.", ""))
            return false;
        else if (!affCalcNumberInRange(app2BasicAnnualIncomeObj.value, app2BasicAnnualIncomeObj, 0, 999999, "Please enter a valid annual income for the second applicant."))
            return false;
    }

    // other guaranteed annual income applicant 1
    if (!affCalcNumericValid(app1GuaranteedAnnualIncomeObj.value, app1GuaranteedAnnualIncomeObj, "Please enter a valid other guaranteed annual income for the first applicant.", ""))
        return false;
    else if (!affCalcNumberInRange(app1GuaranteedAnnualIncomeObj.value, app1GuaranteedAnnualIncomeObj, 0, 999999, "Please enter a valid other guaranteed annual income for the first applicant between 0 and 999999."))
        return false

    // other guaranteed annual income applicant 2
    if (app2RadObj.checked)
    {
        if (!affCalcNumericValid(app2GuaranteedAnnualIncomeObj.value, app2GuaranteedAnnualIncomeObj, "Please enter a valid other guaranteed annual income for the second applicant.", ""))
            return false
        else if (!affCalcNumberInRange(app2GuaranteedAnnualIncomeObj.value, app2GuaranteedAnnualIncomeObj, 0, 999999, "Please enter a valid other guaranteed annual income for the second applicant between 0 and 999999."))
            return false
    }

    // other regular annual income applicant 1
    if (!affCalcNumericValid(app1OtherRegularIncomeObj.value, app1OtherRegularIncomeObj, "Please enter a valid other regular annual income for the first applicant.", ""))
        return false;
    else if (!affCalcNumberInRange(app1OtherRegularIncomeObj.value, app1OtherRegularIncomeObj, 0, 999999, "Please enter a valid other regular annual income for the first applicant between 0 and 999999."))
        return false;

    // other regular annual income applicant 2
    if (app2RadObj.checked)
    {
        if (!affCalcNumericValid(app2OtherRegularIncomeObj.value, app2OtherRegularIncomeObj, "Please enter a valid other regular annual income for the second applicant.", ""))
            return false;
        else if (!affCalcNumberInRange(app2OtherRegularIncomeObj.value, app2OtherRegularIncomeObj, 0, 999999, "Please enter a valid other regular annual income for the second applicant between 0 and 999999."))
            return false;
    }

    // monthly loan payment applicant 1
    if (!affCalcNumericValid(app1MonthlyLoanPaymentObj.value, app1MonthlyLoanPaymentObj, "Please enter a valid monthly loan payment for the first applicant.", ""))
        return false;
    else if (!affCalcNumberInRange(app1MonthlyLoanPaymentObj.value, app1MonthlyLoanPaymentObj, 0, 999999, "Please enter a valid monthly loan payment for the first applicant between 0 and 999999."))
        return false;

    // monthly loan payment applicant 2
    if (app2RadObj.checked)
    {
        if (!affCalcNumericValid(app2MonthlyLoanPaymentObj.value, app2MonthlyLoanPaymentObj, "Please enter a valid monthly loan payment for the second applicant.", ""))
            return false;
        else if (!affCalcNumberInRange(app2MonthlyLoanPaymentObj.value, app2MonthlyLoanPaymentObj, 0, 999999, "Please enter a valid monthly loan payment for the second applicant between 0 and 999999."))
            return false;
    }

    // outstanding credit card balance applicant 1
    if (!affCalcNumericValid(app1CCBalanceObj.value, app1CCBalanceObj, "Please enter a valid outstanding credit balance for the first applicant.", ""))
        return false;
    else if (!affCalcNumberInRange(app1CCBalanceObj.value, app1CCBalanceObj, 0, 999999, "Please enter a valid outstanding credit balance for the first applicant between 0 and 999999."))
        return false;

    // outstanding credit card balance applicant 2
    if (app2RadObj.checked)
    {
        if (!affCalcNumericValid(app2CCBalanceObj.value, app2CCBalanceObj, "Please enter a valid outstanding credit balance for the second applicant.", ""))
            return false;
        else if (!affCalcNumberInRange(app2CCBalanceObj.value, app2CCBalanceObj, 0, 999999, "Please enter a valid outstanding credit balance for the second applicant between 0 and 999999."))
            return false;
    }

    // number of dependants
    if (!affCalcNumericValid(numberOfDependantsObj.value, numberOfDependantsObj, "Please enter a valid number of dependent children.", ""))
        return false;
    else if (!affCalcNumberInRange(numberOfDependantsObj.value, numberOfDependantsObj, 0, 9, "Please enter a valid number of dependent children between 0 and 9."))
        return false;

    // loan term
    if (!affCalcNumericValid(termObj.value, termObj, "Please enter a term between " + minTerm + " and " + maxTerm + " years.", ""))
        return false;
    else if (!affCalcNumberInRange(termObj.value, termObj, minTerm, maxTerm, "Please enter a term between " + minTerm + " and " + maxTerm + " years."))
        return false;
        
	return true;
}

