﻿function ValidateAdditionalInfo(personType, personTypeRadio, personTypeDesc, Errors)
{
    var isValid = true;
    if (!IsOptionSelected(personTypeRadio + 'IncomeType', true))
    {
        isValid = false;
        Errors[Errors.length] = 'Please Check if ' + personTypeDesc + '\'s Employment Type is Hourly, Salary, or Self Employed';
    }
    if (!IsOptionSelected(personTypeRadio + 'IsFullTime', true))
    {
        isValid = false;
        Errors[Errors.length] = 'Please Check if ' + personTypeDesc + '\'s Employment Type is Full Time or Part Time';
    }
    if (!HasValue(personType + 'MonthlyIncomeAmountWeb', true) || !ValidCurrency(personType + 'MonthlyIncomeAmountWeb', true))
    {
        isValid = false;
        Errors[Errors.length] = 'Please Enter ' + personTypeDesc + '\'s Income per month (before taxes)';
    }
    if (!IsOptionSelected(personTypeRadio + 'GetsCommissionAlso', true))
    {
        isValid = false;
        Errors[Errors.length] = 'Please Check if ' + personTypeDesc + ' gets commission also';
    }
    if ($(':input[name=' + personTypeRadio + 'GetsCommissionAlso]:checked').val() == "true" && (!HasValue(personType + 'CommissionAmountWeb', true)
            || !ValidCurrency(personType + 'CommissionAmountWeb', true)))
    {
        isValid = false;
        Errors[Errors.length] = 'Please Enter ' + personTypeDesc + '\'s bonus and/or commission amount';
    }
    if ($(':input[name=' + personTypeRadio + 'GetsCommissionAlso]:checked').val() != "true")
    {
        $(personType + 'CommissionAmountWeb').removeClass('input-validation-error');
    }
    if (HasValue(personType + 'OtherIncomeAmountWeb'))
    {
        if (!ValidCurrency(personType + 'OtherIncomeAmountWeb', true))
        {
            isValid = true;
            Errors[Errors.length] = 'Please enter only numbers or decimal points in ' + personTypeDesc + '\'s Other Income Field';
        }
        if (!HasValue(personType + 'OtherIncomeSource', true))
        {
            isValid = true;
            Errors[Errors.length] = 'Please enter Source for the ' + personTypeDesc + '\'s Other Income';
        }
    }
    if (personType == '#Applicant')
    {
        if (!IsOptionSelected(personTypeRadio + 'IsBuyingCurrentResidence', true))
        {
            isValid = false;
            Errors[Errors.length] = 'Please Check Buying or Renting ' + personTypeDesc + '\'s Current Residence';
        }
        if (IsOptionSelected(personTypeRadio + 'IsBuyingCurrentResidence', false) && 
            $(':input[name=' + personTypeRadio + 'IsBuyingCurrentResidence]:checked').val() == "true")
        {
            if (!HasValue(personType + 'CurrentMtgCompanyName', true))
            {
                isValid = false;
                Errors[Errors.length] = 'Please Enter the ' + personTypeDesc + '\'s Primary Mortgage Company Name';
            }
            if (!IsOptionSelected(personTypeRadio + 'CurrentOnMortgage', true))
            {
                isValid = false;
                Errors[Errors.length] = 'Please Enter if the ' + personTypeDesc + 'is current on mortgage payments';
            }
            if (!IsOptionSelected(personTypeRadio + 'HasSecondMortgage', true))
            {
                isValid = false;
                Errors[Errors.length] = 'Please Check if the ' + personTypeDesc + ' has a second mortgage.';
            }
        }
        if (IsOptionSelected(personTypeRadio + 'IsBuyingCurrentResidence', false) &&
             $(':input[name=' + personTypeRadio + 'IsBuyingCurrentResidence]:checked').val() != "true")
        {
            $(personType + 'CurrentMtgCompanyName').removeClass('input-validation-error');
            $(':input[name=' + personTypeRadio + 'CurrentOnMortgage]').removeClass('input-validation-error');
            $(':input[name=' + personTypeRadio + 'HasSecondMortgage]').removeClass('input-validation-error');
        }
        if (!HasValue(personType + 'MonthlyHousingPaymentAmountWeb', true) || !ValidCurrency(personType + 'MonthlyHousingPaymentAmountWeb', true))
        {
            isValid = false;
            Errors[Errors.length] = 'Please Enter the ' + personTypeDesc + '\'s Monthly rent or mortgage payment';
        }
        if (IsOptionSelected(personTypeRadio + 'HasSecondMortgage', false) && 
            $(':input[name=' + personTypeRadio + 'HasSecondMortgage]:checked').val() == "true")
        {
            if (!HasValue(personType + 'SecondMortgagePaymentAmountWeb', true) || !ValidCurrency(personType + 'SecondMortgagePaymentAmountWeb', true))
            {
                isValid = false;
                Errors[Errors.length] = 'Please Enter the ' + personTypeDesc + '\'s second mortgage payment amount';
            }
        }
        if (IsOptionSelected(personTypeRadio + 'HasSecondMortgage', false) && 
            $(':input[name=' + personTypeRadio + 'HasSecondMortgage]:checked').val() != "true")
        {
            $(personType + 'SecondMortgagePaymentAmountWeb').removeClass('input-validation-error');
        }
    }
    return isValid;
}