function iChatAdd()
{

if(document.iChat_form.message.value == ''){ 

DLEalert(iChat_lang_null, iChat_lang_title); 

}else{

if(stacksize(document.iChat_form.message.value) >= iChat_max_text){ 

DLEalert(iChat_lang_max, iChat_lang_title); 

}else{

	var message = document.getElementById('message').value;

	ShowLoading('');

	$.post(dle_root + "engine/modules/iChat/ajax/add.php", { message: message }, function(data){

		HideLoading('');

	$("#iChat-messages").fadeOut(500, function() {
			$(this).html(data);
			$(this).fadeIn(500);
	});

	});

	return false;
};

};

};

function iChatDelete(id)
{

DLEconfirm( dle_del_agree, dle_confirm, function () {

	ShowLoading('');

	$.post(dle_root + "engine/modules/iChat/ajax/delete.php", { id: id, inmod: "site" }, function(data){

	     HideLoading('');

	     $("#iChat-messages").hide('slide',{ direction: "left" }, 500).html(data).show('slide',{ direction: "right" }, 500);

	});

	return false;

} );

};


function iChatDeleteHistory(id)
{

DLEconfirm( dle_del_agree, dle_confirm, function () {

	ShowLoading('');

	$.post(dle_root + "engine/modules/iChat/ajax/delete.php", { id: id, inmod: "history" }, function(data){

	     HideLoading('');

	     $("#history").hide('slide',{ direction: "left" }, 500).html(data).show('slide',{ direction: "right" }, 500);

	});

	return false;

} );

};


function iChatRefresh()
{
	
	$.post(dle_root + "engine/modules/iChat/ajax/refresh.php", { action: "refresh" }, function(data){

		HideLoading('');

		$("#iChat-messages").html(data);

	});

	return false;
};


function iChatPopUpRules( r )
{
	var b = {};

	b["Принимаю"] = function() { 
					$(this).dialog("close");							
			    };

	$("#rules").remove();

	$("body").append(r);

	$('#rules').dialog({
		autoOpen: true,
		show: 'slide',
		hide: 'slide',
		buttons: b,
		width: 450
	});
	
	return false;
};

function iChatRules()
{
	ShowLoading('');

	$.get(dle_root + "engine/modules/iChat/ajax/rules.php", { action: "rules" }, function(data){

		HideLoading('');

		iChatPopUpRules( data );

	});

	
	return false;
};

function iChatPopUpHistory( r )
{
	$("#history").remove();

	$("body").append(r);

	$('#history').dialog({
		autoOpen: true,
		show: 'blind',
		hide: 'blind',
		width: 300,
           height:600
	});
	
	return false;
};

function iChatHistory()
{
	ShowLoading('');

	$.get(dle_root + "engine/modules/iChat/ajax/history.php", { action: "history" }, function(data){

		HideLoading('');

		iChatPopUpHistory( data );

	});

	
	return false;
};


function iChatPopUpEdit( r )
{
	var b = {};

	     b["Проверить обновления"] = function() { 
					CheckUpdates(); return false;						
			    };


		b["Очистить БД"] = function() { 
					iChatClearBd(); return false;							
				};


		b["Сохранить настройки"] = function() {
				      SaveCfg(); return false;				
			    };

	$("#ECPU").remove();

	$("body").append(r);

	$('#ECPU').dialog({
		autoOpen: true,
		show: 'slide',
		hide: 'slide',
		buttons: b,
		width: 500
	});
	
	return false;
};

function iChatEdit()
{

	ShowLoading('');

	$.get(dle_root + "engine/modules/iChat/ajax/admin.php", { action: "show" }, function(data){

		HideLoading('');

		iChatPopUpEdit( data );

	});

	return false;
};
