

var comments = {
    showForm: function(parent) {
        var d = get('comments-form');
        var f = get('comments_form');

        f.ParentId.value = parent;
        f.Content.value  = '';

        if (parent) {
            var p = get('comment-' + parent);
            d.style.marginLeft = '30px';
        } else {
            var p = get('comments');
            d.style.marginLeft = 0;
        }
        p.appendChild(d);
        d.style.display = 'block';
        f.submit.focus();
        f.Content.focus();
    },
    submitForm: function(f) {
        //alert(f);
        //alert(f.Content.value);
        //return;
        if (f.Content.value == '') return;
        get('comments-submit').value            = 'Adding your comment...';
        get('comments-cancel').disabled         = true;
        get('comments-submit').disabled         = true;
        ajax.script = 'comment.create';
        //setCookie('comment_author', f.UserName.value);
        var id = ajax.load('ParentId', f.ParentId.value, 'SourceTable', f.SourceTable.value, 'SourcePath', f.SourcePath.value, 'SourceId', f.SourceId.value, 'Content', f.Content.value, 'UserName', f.UserName.value);
        //return alert(333);
        //alert(id);
        //window.location = location.href; // + '#c' + id;
    },
    remove: function(id) {
        if (confirm('Do you really want to delete this comment?') == false) return;
        ajax.script = 'comment.delete';
        ajax.load('id', id);
        location.href = location.href;
    },
    vote: function(id, vote) {
        var e = get('comment-' + id + '-votes');
        var v = parseInt(e.innerHTML) + vote;
        e.innerHTML     = (v > 0 ? '+' + v : v);
        e.className     = (v == 0 ? '' : (v > 0 ? 'positive' : 'negative'));
        e.style.display = (v ? 'inline' : 'none');
        ajax.script = 'comment.vote';
        ajax.exec('id', id, 'vote', vote);
    }
}
