def ItemDedCap(e17500, e18400, e18500, e19200, e19800, e20100, e20400, g20500,
               c00100, ID_AmountCap_rt, ID_AmountCap_Switch, e17500_capped,
               e18400_capped, e18500_capped, e19200_capped, e19800_capped,
               e20100_capped, e20400_capped, g20500_capped):
    """
    Applies a cap to gross itemized deductions.

    Notes
    -----
    Tax Law Parameters:
        ID_AmountCap_Switch : Indicator for which itemized deductions are
                              capped
        ID_AmountCap_rt : Cap on itemized deductions; decimal fraction of AGI

    Taxpayer Characteristics:
        e17500 : Medical expenses

        e18400 : State and local taxes

        e18500 : Real-estate taxes

        e19200 : Interest paid

        e19800 : Charity cash contributions

        e20100 : Charity noncash contributions

        e20400 : Total miscellaneous expenses

        g20500 : Gross casualty or theft loss (before disregard)

        c00100: Adjusted Gross Income

    Returns
    -------
        e17500_capped: Medical expenses, capped by ItemDedCap

        e18400_capped: State and local taxes, capped by ItemDedCap

        e18500_capped : Real-estate taxes, capped by ItemDedCap

        e19200_capped : Interest paid, capped by ItemDedCap

        e19800_capped : Charity cash contributions, capped by ItemDedCap

        e20100_capped : Charity noncash contributions, capped by ItemDedCap

        e20400_capped : Total miscellaneous expenses, capped by ItemDedCap

        g20500_capped : Gross casualty or theft loss (before disregard),
                        capped by ItemDedCap
    """
    # pylint: disable=too-many-branches

    cap = max(0., ID_AmountCap_rt * c00100)

    gross_ded_amt = 0
    if ID_AmountCap_Switch[0]:  # medical
        gross_ded_amt += e17500
    if ID_AmountCap_Switch[1]:  # statelocal
        gross_ded_amt += e18400
    if ID_AmountCap_Switch[2]:  # realestate
        gross_ded_amt += e18500
    if ID_AmountCap_Switch[3]:  # casualty
        gross_ded_amt += g20500
    if ID_AmountCap_Switch[4]:  # misc
        gross_ded_amt += e20400
    if ID_AmountCap_Switch[5]:  # interest
        gross_ded_amt += e19200
    if ID_AmountCap_Switch[6]:  # charity
        gross_ded_amt += e19800 + e20100

    overage = max(0., gross_ded_amt - cap)

    e17500_capped = e17500
    e18400_capped = e18400
    e18500_capped = e18500
    g20500_capped = g20500
    e20400_capped = e20400
    e19200_capped = e19200
    e19800_capped = e19800
    e20100_capped = e20100

    if overage > 0. and c00100 > 0.:
        if ID_AmountCap_Switch[0]:  # medical
            e17500_capped -= (e17500 / gross_ded_amt) * overage
        if ID_AmountCap_Switch[1]:  # statelocal
            e18400_capped -= (e18400 / (gross_ded_amt) * overage)
        if ID_AmountCap_Switch[2]:  # realestate
            e18500_capped -= (e18500 / gross_ded_amt) * overage
        if ID_AmountCap_Switch[3]:  # casualty
            g20500_capped -= (g20500 / gross_ded_amt) * overage
        if ID_AmountCap_Switch[4]:  # misc
            e20400_capped -= (e20400 / gross_ded_amt) * overage
        if ID_AmountCap_Switch[5]:  # interest
            e19200_capped -= (e19200 / gross_ded_amt) * overage
        if ID_AmountCap_Switch[6]:  # charity
            e19800_capped -= (e19800 / gross_ded_amt) * overage
            e20100_capped -= (e20100 / gross_ded_amt) * overage

    return (e17500_capped, e18400_capped, e18500_capped, g20500_capped,
            e20400_capped, e19200_capped, e19800_capped, e20100_capped)