oPage.answers = new function()
{
    this.voteAnswer = function(type, answerId, prefix)
    {
        if (typeof prefix == 'undefined') {
            prefix = 'answer-' + answerId;
        }
        new Ajax.Request('/_/action/qa/vote.php', {
            method: 'post',
            parameters: {'type': type, 'answer_id': answerId},
            onSuccess: function(transport) {
                var json = transport.responseText.evalJSON();
                if (typeof json.result == 'undefined') {
                    return;
                }
                var answer = json.result;

                if (typeof answer.voteUpCount != 'undefined') {
                    $(prefix + '-up-count').update(answer.voteUpCount);
                }
                if (typeof answer.voteDownCount != 'undefined') {
                    $(prefix + '-down-count').update(answer.voteDownCount);
                }
            },
            onFailure: function(transport) {
            }
        });
    }

    this.voteQuestion = function(type, questionId, prefix)
    {
        if (typeof prefix == 'undefined') {
            prefix = 'question-' + questionId;
        }
        new Ajax.Request('/_/action/qa/vote.php', {
            method: 'post',
            parameters: {'type': type, 'question_id': questionId},
            onSuccess: function(transport) {
                var json = transport.responseText.evalJSON();
                if (typeof json.result == 'undefined') {
                    return;
                }
                var question = json.result;

                if (typeof question.voteUpCount != 'undefined') {
                    $(prefix + '-up-count').update(question.voteUpCount);
                }
                if (typeof question.voteDownCount != 'undefined') {
                    $(prefix + '-down-count').update(question.voteDownCount);
                }
            },
            onFailure: function(transport) {
            }
        });
    }

    this.acceptAnswer = function(questionId, answerId)
    {
        new Ajax.Request('/_/action/qa/accept_answer.php', {
            method: 'post',
            parameters: {'question_id': questionId, 'answer_id': answerId},
            onSuccess: function(transport) {
                //var json = transport.responseText.evalJSON();
                window.location.reload(true);
            },
            onFailure: function(transport) {
            }
        });
    }
}