function add_comment() {
	$('#mod_textEditor_add_comment_processing').dialog('open');
	$.ajax({
		url:  BUILDER_SITEROOT+"mod_textEditor/comments_add_comment_bg",
		type: "POST",
		data: "material_id="+material_id+"&comment_text="+encodeURIComponent($('#mod_textEditor_comments_new_comment').val()),
		timeout: 10000,
		success: function(data,response) {
			eval(data);
			$('#mod_textEditor_add_comment_processing').dialog('close');
		},
		error: function(a,reason) {
			$('#mod_textEditor_add_comment_er').dialog('open');
			$('#mod_textEditor_add_comment_processing').dialog('close');
		}
	})
}

function comment_chpage(num) {
	document.getElementById('mod_textEditor_comments_text_form').elements['pageNum'].value=num;
	document.getElementById('mod_textEditor_comments_pagenums_form').elements['pageNum'].value=num;
	document.getElementById("mod_textEditor_comments_table_box").innerHTML='<p class="mod_textEditor_comments_loading">Загрузка...</p>';
	document.getElementById("mod_textEditor_comments_pagenums").innerHTML='Загрузка...';
	document.getElementById("mod_textEditor_comments_pagenums1").innerHTML='Загрузка...';
	document.getElementById('mod_textEditor_comments_text_form').submit();
	document.getElementById('mod_textEditor_comments_pagenums_form').submit();
}

function mod_textEditor_comment_add_comment_suc_fc() {$(function(){
	$('#mod_textEditor_comments_new_comment').hide(); 
	$('#mod_textEditor_comments_send_comment').hide();
	$('#mod_textEditor_comments_add_comment').show(); 
	comment_chpage(document.getElementById('mod_textEditor_comments_text_form').elements['pageNum'].value)
});}

function mod_textEditor_comment_delete_confirm_fc(comment_id) {$(function(){
	mod_textEditor_comment_todelete_id=comment_id;
	$('#mod_textEditor_comment_delete_confirm').dialog('open');
});}

function mod_textEditor_comment_delete_comment() {
	$("#mod_textEditor_comment_delete_processing").dialog('open');
	$.ajax({
		url:  BUILDER_SITEROOT+"mod_textEditor/comments_delete_bg",
		type: "POST",
		data: "comment_id="+mod_textEditor_comment_todelete_id,
		timeout: 10000,
		success: function(data,response) {
			eval(data);
			$('#mod_textEditor_comment_delete_processing').dialog('close');
		},
		error: function(a,reason) {
			$('#mod_textEditor_comment_delete_processing_error').dialog('open');
			$('#mod_textEditor_comment_delete_processing').dialog('close');
		}
	})
}

function mod_textEditor_comment_deleted_fc() 	{
	comment_chpage(document.getElementById('mod_textEditor_comments_text_form').elements['pageNum'].value)
}

function document_ready() {
	$("#mod_textEditor_comment_delete_confirm").dialog({
		autoOpen: false,
		buttons: {
			'Удалить': function() {
				mod_textEditor_comment_delete_comment();
				$(this).dialog('close');
			},
			'Отмена': function() {
				$(this).dialog('close');
			}
		}
	});
	$("#mod_textEditor_comment_delete_processing").dialog({autoOpen: false});
	$("#mod_textEditor_comment_delete_processing_error").dialog({autoOpen: false});
	
	$("#mod_textEditor_add_comment_processing").dialog({autoOpen: false});
	$("#mod_textEditor_add_comment_er").dialog({autoOpen: false});

	$('.deletebut').click(function() {$('#mod_textEditor_comment_delete_confirm').dialog('open')});

	$('#mod_textEditor_comments_new_comment').hide();
	$('textarea').addClass("ui-widget-content ui-corner-all");
	$('#mod_textEditor_comments_send_comment').hide();
	$("#mod_textEditor_comments_send_comment").button();
	$('#mod_textEditor_comments_send_comment').click(function() {add_comment();});
	$('#mod_textEditor_comments_add_comment').click(function () {
		$('#mod_textEditor_comments_new_comment').show();
		$('#mod_textEditor_comments_new_comment').val('');
		$('#mod_textEditor_comments_send_comment').show();
		$('#mod_textEditor_comments_add_comment').hide();
	});
	comment_chpage(1);
}

var mod_textEditor_comment_todelete_id=0;
