$RepValueId[$i] = 0;
     }
     $quest_rate[$i] = getRepRewRate($quest['RewRepFaction' . $i]);
     if ($quest['RewRepValueId' . $i] < 0) {
         $RepValueId[$i] = -$RepValueId[$i];
     }
     if ($quest['RewRepValue' . $i] && $quest['RewRepValueId' . $i]) {
         $quest['RewRepValue' . $i] = $quest['RewRepValue' . $i] / 100;
     }
     if (!$quest['RewRepValue' . $i] && $quest['RewRepValueId' . $i]) {
         $quest['RewRepValue' . $i] = $RepValueId[$i];
     }
     $quest['RewRepValue' . $i] = $quest['RewRepValue' . $i] * $quest_rate[$i];
 }
 if ($quest['RewRepFaction1'] and !$quest['RewRepFaction2'] and !$quest['RewRepFaction3'] and !$quest['RewRepFaction4'] and !$quest['RewRepFaction5']) {
     $spillover = getRepSpillover($quest['RewRepFaction1']);
     if ($spillover) {
         foreach ($spillover as $faction) {
             if ($faction['faction1']) {
                 $quest['RewRepFaction2'] = $faction['faction1'];
                 $quest['RewRepValue2'] = $quest['RewRepValue1'] * $faction['rate_1'];
             }
             if ($faction['faction2']) {
                 $quest['RewRepFaction3'] = $faction['faction2'];
                 $quest['RewRepValue3'] = $quest['RewRepValue1'] * $faction['rate_2'];
             }
             if ($faction['faction3']) {
                 $quest['RewRepFaction4'] = $faction['faction3'];
                 $quest['RewRepValue4'] = $quest['RewRepValue1'] * $faction['rate_3'];
             }
             if ($faction['faction4']) {
function r_questReward($quest)
{
    global $lang;
    if ($quest['RewItemId1'] or $quest['RewItemId2'] or $quest['RewItemId3'] or $quest['RewItemId4']) {
        //     echo $lang['Rew_item'].'<br>';
        if ($quest['RewItemId1']) {
            echo text_show_item($quest['RewItemId1'], 0, 'quest');
        }
        if ($quest['RewItemId2']) {
            echo $lang['item_sel_and'] . text_show_item($quest['RewItemId2'], 0, 'quest');
        }
        if ($quest['RewItemId3']) {
            echo $lang['item_sel_and'] . text_show_item($quest['RewItemId3'], 0, 'quest');
        }
        if ($quest['RewItemId4']) {
            echo $lang['item_sel_and'] . text_show_item($quest['RewItemId4'], 0, 'quest');
        }
        echo '<br>';
    }
    if ($quest['RewChoiceItemId1'] or $quest['RewChoiceItemId2'] or $quest['RewChoiceItemId3'] or $quest['RewChoiceItemId4'] or $quest['RewChoiceItemId5'] or $quest['RewChoiceItemId6']) {
        echo $lang['Rew_select_item'] . '<br>';
        if ($quest['RewChoiceItemId1']) {
            echo text_show_item($quest['RewChoiceItemId1'], 0, 'quest');
        }
        if ($quest['RewChoiceItemId2']) {
            echo $lang['item_sel_or'] . text_show_item($quest['RewChoiceItemId2'], 0, 'quest');
        }
        if ($quest['RewChoiceItemId3']) {
            echo $lang['item_sel_or'] . text_show_item($quest['RewChoiceItemId3'], 0, 'quest');
        }
        if ($quest['RewChoiceItemId4']) {
            echo $lang['item_sel_or'] . text_show_item($quest['RewChoiceItemId4'], 0, 'quest');
        }
        if ($quest['RewChoiceItemId5']) {
            echo $lang['item_sel_or'] . text_show_item($quest['RewChoiceItemId5'], 0, 'quest');
        }
        if ($quest['RewChoiceItemId6']) {
            echo $lang['item_sel_or'] . text_show_item($quest['RewChoiceItemId6'], 0, 'quest');
        }
        echo "<br>";
    }
    if ($quest['RewSpell'] and $quest['RewSpellCast']) {
        show_spell($quest['RewSpell'], 0, 'quest');
        echo '<br>';
    }
    if (!$quest['RewSpell'] and $quest['RewSpellCast']) {
        show_spell($quest['RewSpellCast'], 0, 'quest');
        echo '<br>';
    }
    for ($i = 1; $i <= 5; $i++) {
        switch (ABS($quest['RewRepValueId' . $i])) {
            case 1:
                $RepValueId[$i] = 10;
                break;
            case 2:
                $RepValueId[$i] = 25;
                break;
            case 3:
                $RepValueId[$i] = 75;
                break;
            case 4:
                $RepValueId[$i] = 150;
                break;
            case 5:
                $RepValueId[$i] = 250;
                break;
            case 6:
                $RepValueId[$i] = 350;
                break;
            case 7:
                $RepValueId[$i] = 500;
                break;
            case 8:
                $RepValueId[$i] = 1000;
                break;
            case 9:
                $RepValueId[$i] = 5;
                break;
            default:
                $RepValueId[$i] = 0;
        }
        $quest_rate[$i] = getRepRewRate($quest['RewRepFaction' . $i]);
        if ($quest['RewRepValueId' . $i] < 0) {
            $RepValueId[$i] = -$RepValueId[$i];
        }
        if ($quest['RewRepValue' . $i] && $quest['RewRepValueId' . $i]) {
            $quest['RewRepValue' . $i] = $quest['RewRepValue' . $i] / 100;
        }
        if (!$quest['RewRepValue' . $i] && $quest['RewRepValueId' . $i]) {
            $quest['RewRepValue' . $i] = $RepValueId[$i];
        }
        $quest['RewRepValue' . $i] = $quest['RewRepValue' . $i] * $quest_rate[$i];
    }
    if ($quest['RewRepFaction1'] and !$quest['RewRepFaction2'] and !$quest['RewRepFaction3'] and !$quest['RewRepFaction4'] and !$quest['RewRepFaction5']) {
        $spillover = getRepSpillover($quest['RewRepFaction1']);
        if ($spillover) {
            foreach ($spillover as $faction) {
                if ($faction['faction1']) {
                    $quest['RewRepFaction2'] = $faction['faction1'];
                    $quest['RewRepValue2'] = $quest['RewRepValue1'] * $faction['rate_1'];
                }
                if ($faction['faction2']) {
                    $quest['RewRepFaction3'] = $faction['faction2'];
                    $quest['RewRepValue3'] = $quest['RewRepValue1'] * $faction['rate_2'];
                }
                if ($faction['faction3']) {
                    $quest['RewRepFaction4'] = $faction['faction3'];
                    $quest['RewRepValue4'] = $quest['RewRepValue1'] * $faction['rate_3'];
                }
                if ($faction['faction4']) {
                    $quest['RewRepFaction5'] = $faction['faction4'];
                    $quest['RewRepValue5'] = $quest['RewRepValue1'] * $faction['rate_4'];
                }
            }
        }
    }
    if ($quest['RewRepFaction1'] && $quest['RewRepValue1']) {
        echo getFactionName($quest['RewRepFaction1']) . ':&nbsp;' . $quest['RewRepValue1'] . '<br>';
    }
    if ($quest['RewRepFaction2'] && $quest['RewRepValue2']) {
        echo getFactionName($quest['RewRepFaction2']) . ':&nbsp;' . $quest['RewRepValue2'] . '<br>';
    }
    if ($quest['RewRepFaction3'] && $quest['RewRepValue3']) {
        echo getFactionName($quest['RewRepFaction3']) . ':&nbsp;' . $quest['RewRepValue3'] . '<br>';
    }
    if ($quest['RewRepFaction4'] && $quest['RewRepValue4']) {
        echo getFactionName($quest['RewRepFaction4']) . ':&nbsp;' . $quest['RewRepValue4'] . '<br>';
    }
    if ($quest['RewRepFaction5'] && $quest['RewRepValue5']) {
        echo getFactionName($quest['RewRepFaction5']) . ':&nbsp;' . $quest['RewRepValue5'] . '<br>';
    }
    if ($quest['RewMoneyMaxLevel']) {
        echo $lang['Rew_XP'] . ' ' . getQuestXPValue($quest) . ' xp<br>';
    }
    if ($quest['RewOrReqMoney']) {
        echo $lang['Rew_money'] . ' ' . money($quest['RewOrReqMoney'], 7) . '<br>';
    }
}