function add_comment() {
    var quiz_ident = $('quiz_ident') ? $('quiz_ident').value : 0;
    var comment    = encode_for_xml(document.getElementById('comment').value);

    $("comment_actions").innerHTML = ikon_communicating;

    new Ajax.Request(base_url + "/mq_ws.pl", {
      postBody: "<Quiz><AddComment><QuizIdent>" + quiz_ident + "</QuizIdent><Comment>" + comment + "</Comment></AddComment></Quiz>",
      onSuccess: function(transport) {
        $('comment').value = '';
        $('comment_actions').innerHTML = transport.responseText;
        get_comments();
      },
      onFailure: function(transport) {
        alert('failure base ' + transport.status);
      }
    });
}

function delete_comment(post_id) {
//    var quiz_ident = $('quiz_ident') ? $('quiz_ident').value : 0;

    new Ajax.Request(base_url + "/mq_ws.pl", {
      postBody: "<Quiz><DeleteComment><CommentId>" + post_id + "</CommentId></DeleteComment></Quiz>",
      onSuccess: function(transport) {
        if ($('comment_actions')) {
          $('comment_actions').update(transport.responseText);
        }
        get_comments();
      },
      onFailure: function(transport) {
        alert('failure base ' + transport.status);
      }
    });   //<QuizIdent>" + quiz_ident + "</QuizIdent>
}

function edit_comment_form(post_id) {
//    var quiz_ident = $('quiz_ident') ? $('quiz_ident').value : 0;

    new Ajax.Request(base_url + "/mq_ws.pl", {
      postBody: "<Quiz><EditCommentForm><CommentId>" + post_id + "</CommentId></EditCommentForm></Quiz>",
      onSuccess: function(transport) {
        $('commentText' + post_id).innerHTML = transport.responseText;
      },
      onFailure: function(transport) {
        alert('failure base ' + transport.status);
      }
    });   // <QuizIdent>" + quiz_ident + "</QuizIdent>
}

function edit_comment(post_id) {
//    var quiz_ident = $('quiz_ident') ? $('quiz_ident').value : 0;
    var comment    = encode_for_xml(document.getElementById('commentTextInput' + post_id).value);

    new Ajax.Request(base_url + "/mq_ws.pl", {
      postBody: "<Quiz><EditComment><CommentId>" + post_id + "</CommentId><Comment>" + comment + "</Comment></EditComment></Quiz>",
      onSuccess: function(transport) {
        if ($('comment_actions')) {
          $('comment_actions').update(transport.responseText);
        }
        get_comments();
      },
      onFailure: function(transport) {
        alert('failure base ' + transport.status);
      }
    });   // <QuizIdent>" + quiz_ident + "</QuizIdent>
}

function get_comments() {
    var quiz_ident = $('quiz_ident') ? $('quiz_ident').value : 0;

    if (quiz_ident) {
      new Ajax.Request(base_url + "/mq_ws.pl", {
        postBody: "<Quiz><GetComments><QuizIdent>" + quiz_ident + "</QuizIdent></GetComments></Quiz>",
        onSuccess: function(transport) {
          $("comments").update(transport.responseText);
        }
      });
    }
    else {
      document.location.href = document.location.href;
    }
}
