}
if (isset($_POST['AddItem']) || isset($_POST['UpdateItem'])) {
    copy_to_cn();
}
if (isset($_POST['AddItem'])) {
    handle_new_item();
}
if (isset($_POST['UpdateItem'])) {
    handle_update_item();
}
if (isset($_POST['CancelItemChanges']) || isset($_POST['UpdateItem'])) {
    line_start_focus();
}
//-----------------------------------------------------------------------------
if (!processing_active()) {
    handle_new_credit();
} else {
    if (!isset($_POST['customer_id'])) {
        $_POST['customer_id'] = $_SESSION['Items']->customer_id;
    }
    if (!isset($_POST['branch_id'])) {
        $_POST['branch_id'] = $_SESSION['Items']->Branch;
    }
}
//-----------------------------------------------------------------------------
start_form(false, true);
$customer_error = display_credit_header($_SESSION['Items']);
if ($customer_error == "") {
    start_table("{$table_style} width=80%", 10);
    echo "<tr><td>";
    display_credit_items(tr("Credit Note Items"), $_SESSION['Items']);
$id = find_submit('Delete');
if ($id != -1) {
    handle_delete_item($id);
}
if (isset($_POST['AddItem'])) {
    handle_new_item();
}
if (isset($_POST['UpdateItem'])) {
    handle_update_item();
}
if (isset($_POST['CancelItemChanges'])) {
    line_start_focus();
}
//-----------------------------------------------------------------------------
if (!processing_active()) {
    handle_new_credit(0);
}
//-----------------------------------------------------------------------------
start_form();
hidden('cart_id');
$customer_error = display_credit_header($_SESSION['Items']);
if ($customer_error == "") {
    start_table(TABLESTYLE, "width=80%", 10);
    echo "<tr><td>";
    display_credit_items(_("Credit Note Items"), $_SESSION['Items']);
    credit_options_controls($_SESSION['Items']);
    echo "</td></tr>";
    end_table();
} else {
    display_error($customer_error);
}