var User = {

    vote : function (bind, rel_id, value) {
        $.post('ajax.php?do=vote', {bind : bind, rel_id : rel_id, value : value},
        function(data) {
			if (data.success) $('#text_vote_'+bind+'_'+rel_id).hide();
            $('#vote_'+bind+'_'+rel_id).html(data.result);
			$('#'+bind+'msg'+rel_id).html(data.message);
		}, 'json');
    },

    show_comment_form : function (parent_id) {
        if (parent_id == 0) {
			$('#add_comment_label').hide();
			$('#reply_0').append($('#comment_form'));
		} else {
			$('#add_comment_label').show();
			$('#comment_'+parent_id).append($('#comment_form'));
		}
        $('#comment_parent_id').val(parent_id);
        $('#comment_text').val('');
        //$('#reply_'+parent_id).append($('#comment_form'));
    },

    comment : function (notlogged, reply_id) {
        var parent_id = $('#comment_parent_id').val();

        if (notlogged) {
            $.post('ajax.php?do=comment', { notlogged: true },
            function(data) {
                if (parent_id != 0) {
                    $('#comment_'+reply_id).after(data);
                }
            });
            return;
        }

        var bind = $('#comment_bind').val();
        var rel_id = $('#comment_rel_id').val();
        var text = $('#comment_text').val();

		$('#comment_text').attr('disabled', true);
		$('#comment_submit').attr('disabled', true);

        $.post('ajax.php?do=comment', {bind : bind, rel_id : rel_id, parent_id : parent_id, text : text},
        function(data) {
            if (parent_id == 0) {
                $('#comments .container').append(data);
            } else {
                $('#reply_'+parent_id).before(data);
            }
			$('#comment_text').attr('disabled', false);
			$('#comment_submit').attr('disabled', false);
			User.show_comment_form(0);
        });
    }

};