/* COMMENTS */

function showComments (item_id, type, page)
{
	var loaderHTML = '<div align="center"><img src="/images/loader.gif" alt="Загрузка..." /></div>';

//    $("#commentsLoader").html(loaderHTML);

	$.post("/comments_ajax", { act: "showComments", item_id: item_id, type: type, page: page },
		function (res)
		{
			$("#userComments").html(res);
		}
	);
	return false;
}

function submitComment (item_id, type)
{
	var params = 'act=submitComment&'+$('[name=my_form]').serialize();
    if($('.mainTextarea').attr('disabled')=='disabled') return false;
    $('.mainTextarea').attr('disabled','disabled');
	$.ajax({
        type: "POST",
        url: "/comments_ajax",
        data: params,
        success:
    		function(res)
    		{
   		        $('.mainTextarea').attr('disabled','');
    			if (res == 1)
    			{
    				//showMsg("Спасибо, комментарий добавлен", "ok");
    				showComments(item_id, type);
    			} else {
                    //showMsg(res, "err");
                    alert(res);
    			}
    		}
	});

	return false;
}

function delComment(item_id, obj)
{
    if(confirm('Удалить комментарий?')==false) return false;
	$.ajax({
        type: "POST",
        url: "/comments_ajax",
        data: 'act=delete&id='+item_id,
        success:
    		function(res) {
    			if (res == 1) {
    				obj.parents('li').remove();
    			}
            }
	});

	return false;
}

