var last_id = null;
var showlogin = "show-anonymous-form"
var hidelogin = "add-anonymous-comment"

function toggleCommentBox(id)  {
    // If we're now replying to a new comment, close the old comment box
    if (last_id != null && last_id != id) {
        document.getElementById('commentbox_' + last_id + '_more').style.display = 'none';
        document.getElementById('commentbox_' + last_id + '_less').style.display = 'inline';
        
        // Delete the old comment form
        var old_commentbox = document.getElementById('commentbox_' + last_id + '_form');
        old_commentbox.innerHTML = null;
    }

    var commentbox_less = document.getElementById('commentbox_' + id + '_less');
    var commentbox_more = document.getElementById('commentbox_' + id + '_more');

    // Close
    if (commentbox_more.style.display == 'block') {
        commentbox_more.style.display = 'none';
        commentbox_less.style.display = 'block';
    // Open
    } else {
        commentbox_more.style.display = 'block';
        commentbox_less.style.display = 'none';

        // Render the comment form
        var commentbox = document.getElementById('commentbox_' + id + '_form');

        if (id != 0) {
            commentbox.innerHTML = ('<div class="thread">' + commentform + '</div>');
        } else { 
            commentbox.innerHTML = commentform;
        }

        // Make sure the comment's comment id is set correctly
        var reply_to_comment = document.getElementById('comment_comment_id');
        reply_to_comment.value = id;
                 
        // Remember what the last comment box was, so we can close it later
        last_id = id;

    }
    return false;
}

