}
        if ($comment['editbutton']) {
            if (qa_clicked($prefix . 'doedit')) {
                if (qa_page_q_permit_edit($comment, 'permit_edit_c', $pageerror)) {
                    // extra check here ensures error message is visible
                    qa_page_q_refresh($pagestart, 'edit-' . $commentid, $commentparenttype, $comment['parentid']);
                }
            } elseif (qa_clicked($prefix . 'dosave') && qa_page_q_permit_edit($comment, 'permit_edit_c', $pageerror)) {
                if (qa_page_q_edit_c_submit($comment, $question, $commentparent, $ceditin[$commentid], $cediterrors[$commentid])) {
                    qa_page_q_refresh($pagestart, null, $commentparenttype, $comment['parentid']);
                } else {
                    $formtype = 'c_edit';
                    $formpostid = $commentid;
                    // keep editing if an error
                }
            } elseif ($pagestate == 'edit-' . $commentid && qa_page_q_permit_edit($comment, 'permit_edit_c', $pageerror)) {
                $formtype = 'c_edit';
                $formpostid = $commentid;
            }
        }
    }
}
//	Functions used above - also see functions in qa-page-question-submit.php (which are shared with Ajax)
function qa_page_q_refresh($start = 0, $state = null, $showtype = null, $showid = null)
{
    $params = array();
    if ($start > 0) {
        $params['start'] = $start;
    }
    if (isset($state)) {
        $params['state'] = $state;
            } elseif (qa_clicked('dosavec_' . $commentid) && qa_page_q_permit_edit($comment, 'permit_edit_c')) {
                $innotify = qa_post_text('notify') ? true : false;
                $inemail = qa_post_text('email');
                qa_get_post_content('editor', 'comment', $ineditor, $incomment, $informat, $intext);
                $errors = qa_comment_validate($incomment, $informat, $intext, $innotify, $inemail);
                if (empty($errors)) {
                    $setnotify = $comment['isbyuser'] ? qa_combine_notify_email($comment['userid'], $innotify, $inemail) : $comment['notify'];
                    qa_comment_set_content($comment, $incomment, $informat, $intext, $setnotify, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $question, $commentanswer);
                    qa_report_write_action($qa_login_userid, $qa_cookieid, 'c_edit', $questionid, $commentanswerid, $commentid);
                    qa_redirect($qa_request, null, null, null, qa_anchor($commentparenttype, $comment['parentid']));
                } else {
                    $formtype = 'c_edit';
                    $formpostid = $commentid;
                    // keep editing if an error
                }
            } elseif ($qa_state == 'edit-' . $commentid && qa_page_q_permit_edit($comment, 'permit_edit_c')) {
                $formtype = 'c_edit';
                $formpostid = $commentid;
            }
        }
    }
}
function qa_page_q_permit_edit($post, $permitoption)
{
    global $pageerror, $qa_request;
    $permiterror = qa_user_permit_error($post['isbyuser'] ? null : $permitoption);
    // if it's by the user, this will only check whether they are blocked
    switch ($permiterror) {
        case 'login':
            $pageerror = qa_insert_login_links(qa_lang_html('question/edit_must_login'), $qa_request);
            break;