﻿function ValidateSectionA(Errors, resYears, resMonths, empYears, empMonths)
{
    var isValid = true;
    //Applicant Name and PII
    if (!ValidateName('#Applicant', 'Applicant\'s', Errors))
    {
        isValid = false;
    }
    //Attorney
    if (!HasValue('#AttorneyFirstName',true))
    {
        isValid = false;
        Errors[Errors.length] = 'Please Enter Applicant\'s Attorney\'s First Name';
    }
    if (!HasValue('#AttorneyLastName', true))
    {
        isValid = false;
        Errors[Errors.length] = 'Please Enter Applicant\'s Attorney\'s Last Name';
    }
    if (HasValue('#CaseNumber',false) && !ValidCaseNumber('#CaseNumber',true))
    {
        isValid = false;
        Errors[Errors.length] = 'Please enter your case number in the format YY-XXXXX';
    }
    if (!HasValue('#AttorneyPhoneWeb',true) || !ValidPhoneNumber('#AttorneyPhoneWeb')) 
    {
        isValid = false;
        Errors[Errors.length] = 'Please Enter Applicant\'s Attorney\'s Phone Number in the format "(555) 555-1212"';
    }
    if (HasValue('#AttorneyFaxWeb', false) && !ValidPhoneNumber('#AttorneyFaxWeb')) {
        isValid = false;
        Errors[Errors.length] = 'Please Enter Applicant\'s Attorney\'s Fax Number in the format "(555) 555-1212"';
    }
    if (HasValue('#AttorneyEmail', false) && !ValidEmailAddress('#AttorneyEmail'))
    {
        isValid = false;
        Errors[Errors.length] = 'Please Enter Applicant\'s Attorney\'s Email Address in the format "name@domain.com"';
    }
    //Additional
    if (!IsOptionSelected('InterestedIn',true))
    {
        isValid = false;
        Errors[Errors.length] = 'Please select which option are you more interested in.';
    }
    if (!IsOptionSelected('CaseHasBeenfiled',true))
    {
        isValid = false;
        Errors[Errors.length] = 'Please select Applicant\'s case filing status.';
    }
    if (IsOptionSelected('CaseHasBeenfiled', false) && $(':input[name=CaseHasBeenfiled]:checked').val() == 'true')
    {
        $('#Datetofile').removeClass('input-validation-error');
        if (!HasValue('#Datefiled', true))
        {
            isValid = false;
            Errors[Errors.length] = 'Please Enter A Date Applicant\'s Bankruptcy was filed';
            }
        if (HasValue('#Datefiled', false) && !ValidDateField('#Datefiled', false, true))
        {
            isValie = false;
            Errors[Errors.length] = 'Please Enter Applicant\'s Filing Date in the format "99/99/9999"';
            }
    }
    if (HasValue('#Datetofile', false) && !ValidDateField('#Datetofile', true, false))
    {
        isValid = false;
        Errors[Errors.length] = 'Please Enter Applicant\'s Date To Be Filed in the format "99/99/9999"';
    }
    var bankruptcyType = 0;
    if (!IsOptionSelected('BankruptcyType', true))
    {
        isValid = false;
        Errors[Errors.length] = 'Please select the type of bankruptcy.';
    }
    //Residency
    if (!ValidateResidency('#Applicant', 'Applicant\'s', Errors, resYears, resMonths))
    {
        isValid = false;
    }
    //Employee Info
    if (!ValidateEmployment('#Applicant', 'Applicant\'s', Errors, empYears, empMonths))
    {
        isValid = false;
    }
    //Final Section
    if (!ValidateAdditionalInfo('#Applicant', 'Applicant', 'Applicant', Errors))
    {
        isValid = false;
    }
    return isValid;
}