local TraceFrame = DEFAULT_CHAT_FRAME;

-- version 01.00.06 du 20091210
	-- maj du .toc pour wow 3.3

-- version 01.00.05 du 20090831
	-- maj du .toc pour wow 3.2

-- version 01.00.04 du 20090501
	-- maj du .toc pour wow 3.1

-- version 01.00.03
	-- maj du .toc

-- version 1.00.02
	-- ajout de la fonction : SendChatMessageTimer_Vide pour demander si l'addon a des messages à envoyer, pour lui communiquer des données à envoyer pas urgentes

--/script SendChatMessageTimer_Refresh(36000)
local SendChatMessageTimer_time = 0;
--local SendChatMessageTimer_refresh = 0.25 -- = une fois tous les quarts de secondes
--local SendChatMessageTimer_refresh = 0.3 -- = une fois tous les 3 dixièmes de secondes
--local SendChatMessageTimer_refresh = 0.4 -- = une fois tous les 4 dixièmes de secondes
--local SendChatMessageTimer_refresh = 0.5 -- = une fois tous les 5 dixièmes de secondes
--local SendChatMessageTimer_refresh = 0.6 -- = une fois tous les 5 dixièmes de secondes
local SendChatMessageTimer_refresh = 1 -- = une fois tous les 10 dixièmes de secondes
--local SendChatMessageTimer_refresh = 36000 -- = une fois toutes les 10 heures
local SendChatMessageTimer_tablo = {};
local SendChatMessageTimer_indice = 0;

local SendChatMessageTimer_tablo_channel_urgent = { [1] = {}, [2] = {}, [3] = {}, [4] = {}, [5] = {}, [6] = {}, [7] = {}, [8] = {}, [9] = {}, [10] = {} };
local SendChatMessageTimer_indice_channel_urgent = { [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0, [8] = 0, [9] = 0, [10] = 0 };
local SendChatMessageTimer_time_channel_urgent = { [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0, [8] = 0, [9] = 0, [10] = 0 };
local SendChatMessageTimer_true_channel_urgent = { [1] = false, [2] = false, [3] = false, [4] = false, [5] = false, [6] = false, [7] = false, [8] = false, [9] = false, [10] = false };

local SendChatMessageTimer_tablo_channel_lent = { [1] = {}, [2] = {}, [3] = {}, [4] = {}, [5] = {}, [6] = {}, [7] = {}, [8] = {}, [9] = {}, [10] = {} };
local SendChatMessageTimer_indice_channel_lent = { [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0, [8] = 0, [9] = 0, [10] = 0 };


local SendChatMessageTimer_tablo_cms_urgent = {};
local SendChatMessageTimer_indice_cms_urgent = 0;

local SendChatMessageTimer_tablo_cms_lent = {};
local SendChatMessageTimer_indice_cms_lent = 0;

local SendChatMessageTimer_cms_time = 0;
local SendChatMessageTimer_cms_refresh = 12 -- = une fois tous les n secondes

local sSCMT_GUID_joueur;
local sSCMT_name_joueur;
local iSCMT_len_name;
local sSCMT_server_joueur;

--SendChatMessage(smessage,"CHANNEL",this.language,DBCS_CMS_numcanalCMS);
--"SAY" 
--"EMOTE" 
--"YELL" 
--"PARTY" 
--"GUILD" 
--"OFFICER" 
--"RAID" 
--"RAID_WARNING" 
--"BATTLEGROUND" 
--"WHISPER" 
--"CHANNEL" 
--"AFK"
--"DND"

--SendAddonMessage("CMSA","@M"..numcanal..CMS_versionclientwow.."@"..arg2.."@","CHANNEL",CMS_numcanalCMS);
----	SendAddonMessage("prefix", "message" [,"type"] [,"target"]) 
SendChatMessageTimer_Saved_SendAddonMessage = SendAddonMessage;
function SendAddonMessage(sprefix,smessage,stype,sdestinataire)

	if ( stype and ( stype == "CHANNEL" ) ) then
		if ( sdestinataire and ( type(sdestinataire) == "number" ) ) then
			SendChatMessageTimer_indice_channel_lent[sdestinataire] = SendChatMessageTimer_indice_channel_lent[sdestinataire] + 1;
			SendChatMessageTimer_tablo_channel_lent[sdestinataire][SendChatMessageTimer_indice_channel_lent[sdestinataire]] = {};
			SendChatMessageTimer_tablo_channel_lent[sdestinataire][SendChatMessageTimer_indice_channel_lent[sdestinataire]][1] = smessage;
			SendChatMessageTimer_tablo_channel_lent[sdestinataire][SendChatMessageTimer_indice_channel_lent[sdestinataire]][2] = sprefix;
			SendChatMessageTimer_tablo_channel_lent[sdestinataire][SendChatMessageTimer_indice_channel_lent[sdestinataire]][3] = 2;
		else
			SendChatMessageTimer_Saved_SendAddonMessage(sprefix,smessage,stype,sdestinataire);
		end
	else
		SendChatMessageTimer_Saved_SendAddonMessage(sprefix,smessage,stype,sdestinataire);
	end

end

SendChatMessageTimer_Saved_SendChatMessage = SendChatMessage;
function SendChatMessage(smessage,smode,slangue,sdestinataire)

local i_numchat_cms = 0;

	if ( smode == "CHANNEL" ) then
		--i_numchat_cms, _ = GetChannelName("cms"); -- , nchat
		--if ( i_numchat_cms > 0 ) then
		--	if ( sdestinataire and ( sdestinataire == i_numchat_cms ) ) then
		--		SendChatMessageTimer_SendChatMessage_cms_urgent(smessage,smode,slangue,sdestinataire);
		--	else
		--		if ( sdestinataire and ( type(sdestinataire) == "number" ) ) then
		--			SendChatMessageTimer_indice_channel_urgent[sdestinataire] = SendChatMessageTimer_indice_channel_urgent[sdestinataire] + 1;
		--			SendChatMessageTimer_tablo_channel_urgent[sdestinataire][SendChatMessageTimer_indice_channel_urgent[sdestinataire]] = {};
		--			SendChatMessageTimer_tablo_channel_urgent[sdestinataire][SendChatMessageTimer_indice_channel_urgent[sdestinataire]][1] = smessage;
		--			SendChatMessageTimer_tablo_channel_urgent[sdestinataire][SendChatMessageTimer_indice_channel_urgent[sdestinataire]][2] = slangue;
		--		else
		--			SendChatMessageTimer_Saved_SendChatMessage(smessage,smode,slangue,sdestinataire);
		--		end
		--	end
		--else
			if ( sdestinataire and ( type(sdestinataire) == "number" ) ) then
				SendChatMessageTimer_indice_channel_urgent[sdestinataire] = SendChatMessageTimer_indice_channel_urgent[sdestinataire] + 1;
				SendChatMessageTimer_tablo_channel_urgent[sdestinataire][SendChatMessageTimer_indice_channel_urgent[sdestinataire]] = {};
				SendChatMessageTimer_tablo_channel_urgent[sdestinataire][SendChatMessageTimer_indice_channel_urgent[sdestinataire]][1] = smessage;
				SendChatMessageTimer_tablo_channel_urgent[sdestinataire][SendChatMessageTimer_indice_channel_urgent[sdestinataire]][2] = slangue;
				SendChatMessageTimer_tablo_channel_urgent[sdestinataire][SendChatMessageTimer_indice_channel_urgent[sdestinataire]][3] = 1;
				--if ( SendChatMessageTimer_indice_channel_urgent[sdestinataire] == 11 ) then
----TraceFrame:AddMessage(""..date("%H:%M:%S").." veuillez patienter, il reste "..SendChatMessageTimer_indice_channel_urgent[sdestinataire].." messages dans la file du canal : "..sdestinataire);
--TraceFrame:AddMessage(""..date("%H:%M:%S").." veuillez patienter, il reste plus de 10 messages dans la file d'attente du canal : "..sdestinataire);
				--end
			else
				SendChatMessageTimer_Saved_SendChatMessage(smessage,smode,slangue,sdestinataire);
			end
		--end
	else
		SendChatMessageTimer_Saved_SendChatMessage(smessage,smode,slangue,sdestinataire);
	end

--
----TraceFrame:AddMessage("appel SendChatMessage");
--	if ( smode == "CHANNEL" or smode == "GUILD" or smode == "OFFICER" ) then
--		SendChatMessageTimer_indice = SendChatMessageTimer_indice + 1;
--		SendChatMessageTimer_tablo[SendChatMessageTimer_indice] = {};
--		SendChatMessageTimer_tablo[SendChatMessageTimer_indice][1] = smessage;
--		SendChatMessageTimer_tablo[SendChatMessageTimer_indice][2] = smode;
--		SendChatMessageTimer_tablo[SendChatMessageTimer_indice][3] = slangue;
--		SendChatMessageTimer_tablo[SendChatMessageTimer_indice][4] = sdestinataire;
--	else
		--SendChatMessageTimer_Saved_SendChatMessage(smessage,smode,slangue,sdestinataire);
--	end
--
end
--SendChatMessage = SendChatMessageTimer_SendChatMessage;

function SendChatMessageTimer_Update_SendChatMessage()

local itime;
local tablo;
local i;

	itime = GetTime();
	for i = 1 , 10 do
		if ( SendChatMessageTimer_indice_channel_urgent[i] == 0 ) then
		--ne se produit qu'une fois à la connexion, rajouter la sup du premier enreg si on lit la ligne envoyée
			if ( SendChatMessageTimer_indice_channel_lent[i] > 0 ) then
				SendChatMessageTimer_indice_channel_urgent[i] = SendChatMessageTimer_indice_channel_urgent[i] + 1;
				SendChatMessageTimer_tablo_channel_urgent[i][SendChatMessageTimer_indice_channel_urgent[i]] = SendChatMessageTimer_tablo_channel_lent[i][1];
				table.remove(SendChatMessageTimer_tablo_channel_lent[i],1);
				SendChatMessageTimer_indice_channel_lent[i] = SendChatMessageTimer_indice_channel_lent[i] - 1;
			end
		end
		if ( SendChatMessageTimer_indice_channel_urgent[i] > 0 ) then
			--if ( itime - SendChatMessageTimer_time_channel_urgent[i] > SendChatMessageTimer_cms_refresh ) then
			if ( itime - SendChatMessageTimer_time_channel_urgent[i] > 1 ) then
				if ( SendChatMessageTimer_true_channel_urgent[i] == false ) then
					SendChatMessageTimer_true_channel_urgent[i] = true;
				else
					table.remove(SendChatMessageTimer_tablo_channel_urgent[i],1);
					SendChatMessageTimer_indice_channel_urgent[i] = SendChatMessageTimer_indice_channel_urgent[i] - 1;
				end
				if ( SendChatMessageTimer_indice_channel_urgent[i] > 0 ) then
					tablo = SendChatMessageTimer_tablo_channel_urgent[i][1];
					if ( tablo[3] == 1 ) then
						SendChatMessageTimer_Saved_SendChatMessage(tablo[1],"CHANNEL",tablo[2],i);
					elseif ( tablo[3] == 2 ) then
						SendChatMessageTimer_Saved_SendAddonMessage(tablo[2],tablo[1],"CHANNEL",i);
					end
				else
					SendChatMessageTimer_true_channel_urgent[i] = false;
				end
				SendChatMessageTimer_time_channel_urgent[i] = GetTime();
			end
		else
			--envoyer un message à SendAddonMessage
		end
	end

end

local SendChatMessageTimer_tablo_lent = {};
local SendChatMessageTimer_indice_lent = 0;

function SendChatMessageTimer_SendChatMessage_lent(smessage,smode,slangue,sdestinataire)

	if ( smode == "CHANNEL" ) then
		if ( sdestinataire and ( type(sdestinataire) == "number" ) ) then
			SendChatMessageTimer_indice_channel_lent[sdestinataire] = SendChatMessageTimer_indice_channel_lent[sdestinataire] + 1;
			SendChatMessageTimer_tablo_channel_lent[sdestinataire][SendChatMessageTimer_indice_channel_lent[sdestinataire]] = {};
			SendChatMessageTimer_tablo_channel_lent[sdestinataire][SendChatMessageTimer_indice_channel_lent[sdestinataire]][1] = smessage;
			SendChatMessageTimer_tablo_channel_lent[sdestinataire][SendChatMessageTimer_indice_channel_lent[sdestinataire]][2] = slangue;
			SendChatMessageTimer_tablo_channel_lent[sdestinataire][SendChatMessageTimer_indice_channel_lent[sdestinataire]][3] = 1;
		else
--TraceFrame:AddMessage(""..date("%H:%M:%S").." mauvais envoi : "..smessage);
		end
	else
--TraceFrame:AddMessage(""..date("%H:%M:%S").." mauvais envoi : "..smessage);
	end
	--SendChatMessageTimer_indice_lent = SendChatMessageTimer_indice_lent + 1;
	--SendChatMessageTimer_tablo_lent[SendChatMessageTimer_indice_lent] = {};
	--SendChatMessageTimer_tablo_lent[SendChatMessageTimer_indice_lent][1] = val1;
	--SendChatMessageTimer_tablo_lent[SendChatMessageTimer_indice_lent][2] = val2;
	--SendChatMessageTimer_tablo_lent[SendChatMessageTimer_indice_lent][3] = val3;
	--SendChatMessageTimer_tablo_lent[SendChatMessageTimer_indice_lent][4] = val4;

end

function SendChatMessageTimer_OnLoad(self)

	SendChatMessageTimer = {};

	self:RegisterEvent("CHAT_MSG_ADDON");
	self:RegisterEvent("CHAT_MSG_CHANNEL");
	--self:RegisterEvent("CHAT_MSG_CHANNEL_NOTICE");
	self:RegisterEvent("PLAYER_ENTERING_WORLD");
	
end

local SendChatMessageTimer_ChatFrame_MessageEventHandler = ChatFrame_MessageEventHandler;
function ChatFrame_MessageEventHandler(self, event, ...)

local arg1, _, _, _, _, _, _, arg8 = ...;

	if ( event == "CHAT_MSG_CHANNEL_NOTICE" ) then
		if ( arg1 == "THROTTLED" ) then
			if ( self:GetName() == "ChatFrame1" ) then
--TraceFrame:AddMessage(""..date("%H:%M:%S").." ChatFrame_MessageEventHandler CHAT_MSG_CHANNEL_NOTICE THROTTLED canal : "..arg8.." , fenetre : "..(self:GetName() or ""));
				SendChatMessageTimer_true_channel_urgent[arg8] = false;
				SendChatMessageTimer_time_channel_urgent[arg8] = GetTime();
			else
--_G[self:GetName()]:AddMessage(""..date("%H:%M:%S").." ChatFrame_MessageEventHandler CHAT_MSG_CHANNEL_NOTICE THROTTLED canal : "..arg8.." , fenetre : "..(self:GetName() or ""));
			end
			return nil;
		end
	end
	SendChatMessageTimer_ChatFrame_MessageEventHandler(self, event, ...);

end
--ChatFrame_MessageEventHandler = SendChatMessageTimer_ChatFrame_MessageEventHandler;

--/script SendAddonMessage("CMSA","blabla","WHISPER","cygne");
--/script SendAddonMessage("CMSA","blabla","CHANNEL","cms");
--/script SendAddonMessage("CMSA","blabla","CHANNEL",1);
--/script SendAddonMessage("CMSA","blabla","CHANNEL",2);
--/script SendAddonMessage("CMSA","blabla","CHANNEL",3);
--/script SendAddonMessage("CMSA","blabla","CHANNEL",4);
--/script SendAddonMessage("CMSblabla","blablat","CHANNEL",4);
--/script SendAddonMessage("CMSA","blablat","CHANNEL",5);
--/script SendAddonMessage("CMSblabla","blablat","CHANNEL",5);
--/script SendAddonMessage("CMSA","blabla","CHANNEL",6);

--local SendChatMessageTimer_saved_ChatFrame_OnEvent = ChatFrame_OnEvent;
--function ChatFrame_OnEvent(self,event,...)
--
--local arg1 = ...;
--
--	if ( event == "CHAT_MSG_CHANNEL_NOTICE" ) then
--		if ( arg1 == "THROTTLED" ) then
--			return nil;
--		end
--	end
--	SendChatMessageTimer_saved_ChatFrame_OnEvent(self,event,...);
--
--end

function SendChatMessageTimer_OnEvent(self,event,...)

local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15 = ...;

--	if ( event == "CHAT_MSG_CHANNEL_NOTICE" ) then
--		if ( arg1 == "THROTTLED" ) then
			--ChatFrame_MessageEventHandler(self, event, ...)
			--:AddMessage
			--arg8 numéro du canal
			--("message", "sender", "language", "channelString", "target", "flags", unknown, channelNumber, "channelName", unknown, counter)
--		end
--	end
	if ( event == "CHAT_MSG_ADDON" ) then
--CMS_afficherevent("SendChatMessageTimer_OnEvent "..event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14,arg15);
--arg1
--    prefix 
--arg2
--    message 
--arg3
--    distribution type ("PARTY", "RAID", "GUILD", "BATTLEGROUND" or "WHISPER") 
--arg4
--    sender 
--arg5
--    channel name with number ex: "1. General - Stormwind City" 
--arg6
--    AFK/DND/GM "CHAT_FLAG_"..arg6 flags 
--arg7
--    channel number 
--arg8
--    channel name without number (this is _sometimes_ in lowercase) 
		--arg1		prefix
		--arg2		message
		--arg3		type
		--arg4		Cygne-KirinTor
		--arg7		num canal
		if ( arg3 and ( arg3 == "CHANNEL" ) ) then
			if ( arg4 and ( strlower(strsub(arg4,1,iSCMT_len_name)) == strlower(sSCMT_name_joueur.."-") ) ) then
				if ( arg7 ) then
--TraceFrame:AddMessage(""..date("%H:%M:%S").." ce message_addon est un des miens.");
					SendChatMessageTimer_time_channel_urgent[arg7] = GetTime();
				end
			end
		end
	
	elseif ( event == "CHAT_MSG_CHANNEL" ) then
		--if ( self:GetName() == "ChatFrame1" ) then
--("message", "sender", "language", "channelString", "target", "flags", unknown, channelNumber, "channelName", unknown, counter, "guid")
--	arg1		arg2		arg3		arg4			arg5	arg6	arg7		arg8			arg9		arg10	arg11		arg12
--	
--Fired when the client receives a channel message.
--
--arg1
--    chat message 
--arg2
--    author 
--arg3
--    language 
--arg4
--    channel name with number ex: "1. General - Stormwind City" 
--
--    zone is always current zone even if not the same as the channel name 
--
--arg5
--    target 
--
--    second player name when two users are passed for a CHANNEL_NOTICE_USER (E.G. x kicked y) 
--
--arg6
--    AFK/DND/GM "CHAT_FLAG_"..arg6 flags 
--arg7
--    zone ID used for generic system channels (1 for General, 2 for Trade, 22 for LocalDefense, 23 for WorldDefense and 26 for LFG) 
--
--    not used for custom channels or if you joined an Out-Of-Zone channel ex: "General - Stormwind City" 
--
--arg8
--    channel number 
--arg9
--    channel name without number (this is _sometimes_ in lowercase) 
--
--    zone is always current zone even if not the same as the channel name 
--
--arg11
--    Chat lineID used for reporting the chat message. 
--arg12
--    Sender GUID 
			--arg1	message
			--arg3	langue
			--arg8	num canal
			--arg12	vérifier le GUID de l'envoyeur, si c'est soi
			----arg9
			----arg12
--TraceFrame:AddMessage(""..date("%H:%M:%S").." arg12 = "..(arg12 or ""));
--TraceFrame:AddMessage(""..date("%H:%M:%S").." sSCMT_GUID_joueur = "..(sSCMT_GUID_joueur or ""));
--TraceFrame:AddMessage(""..date("%H:%M:%S").." arg12 = "..(arg12 or ""));
--TraceFrame:AddMessage(""..date("%H:%M:%S").." arg8 = "..(arg8 or ""));
--TraceFrame:AddMessage(""..date("%H:%M:%S").." arg3 = "..(arg3 or ""));
--TraceFrame:AddMessage(""..date("%H:%M:%S").." arg1 = "..(arg1 or ""));
--TraceFrame:AddMessage(""..date("%H:%M:%S").." ce message est le mien et le premier.");
		if ( arg12 and ( arg12 == sSCMT_GUID_joueur ) ) then
			--if ( arg8 and ( SendChatMessageTimer_indice_channel_urgent[arg8] > 0 ) ) then
			if ( arg8 ) then
				SendChatMessageTimer_time_channel_urgent[arg8] = GetTime();
				--if ( arg3 and ( arg3 == SendChatMessageTimer_tablo_channel_urgent[arg8][1][2] ) ) then
					--if ( arg1 and ( arg1 == SendChatMessageTimer_tablo_channel_urgent[arg8][1][1] ) ) then
						--SendChatMessageTimer_true_channel_urgent[arg8] = true;
						--SendChatMessageTimer_time_channel_urgent[arg8] = GetTime();
					--end
				--end
			end
--TraceFrame:AddMessage(""..date("%H:%M:%S").." j'ai envoyé ce message.");
--/script DEFAULT_CHAT_FRAME:AddMessage(""..date("%H:%M:%S").." GUID_joueur = "..(UnitGUID("player") or ""));
--/script DEFAULT_CHAT_FRAME:AddMessage(""..date("%H:%M:%S").." unit_name = "..(UnitName("player") or ""));
--/script DEFAULT_CHAT_FRAME:AddMessage(""..date("%H:%M:%S").." unit_server = "..(UnitServer("player") or ""));
--/script DEFAULT_CHAT_FRAME:AddMessage(""..date("%H:%M:%S").." unit_name(guid) = "..(UnitName(UnitGUID("player")) or ""));
		end
		--end
	elseif ( event == "PLAYER_ENTERING_WORLD" ) then
		sSCMT_GUID_joueur = UnitGUID("player");
		sSCMT_name_joueur = UnitName("player");
		iSCMT_len_name = strlen(sSCMT_name_joueur) + 1;
		sSCMT_server_joueur = GetRealmName();
		--GetRealmName();
	end

end

--local SendChatMessageTimer_saved_errorhandler = nil;
--
--function SendChatMessageTimer_errorhandler()
--
--local stexte;
--
--	--SendChatMessageTimer_Saved_SendChatMessage(SendChatMessageTimer_tablo[1][1],SendChatMessageTimer_tablo[1][2],SendChatMessageTimer_tablo[1][3],SendChatMessageTimer_tablo[1][4]);
--	seterrorhandler(SendChatMessageTimer_saved_errorhandler);
--	stexte = SendChatMessageTimer_tablo[1][1];
--	table.remove(SendChatMessageTimer_tablo,1);
--	SendChatMessageTimer_indice = SendChatMessageTimer_indice - 1;
--	SendChatMessageTimer_time = GetTime();
--if ( DBCS_prog_serveur and DBCS_prog_serveur == 1 ) then
--	message("ligne erreur SendChatMessageTimer_errorhandler : "..(stexte or ""));
--	SendChatMessageTimer_ecrirecodedutexte(stexte);
--end
--			
--end

--local SendChatMessageTimer_saved_errorhandler_lent = nil;
--
--function SendChatMessageTimer_errorhandler_lent()
--
--local stexte;
--
--	--SendChatMessageTimer_Saved_SendChatMessage(SendChatMessageTimer_tablo[1][1],SendChatMessageTimer_tablo[1][2],SendChatMessageTimer_tablo[1][3],SendChatMessageTimer_tablo[1][4]);
--	seterrorhandler(SendChatMessageTimer_saved_errorhandler_lent);
--	stexte = SendChatMessageTimer_tablo_lent[1][1];
--	table.remove(SendChatMessageTimer_tablo_lent,1);
--	SendChatMessageTimer_indice_lent = SendChatMessageTimer_indice_lent - 1;
--	SendChatMessageTimer_time = GetTime();
--if ( DBCS_prog_serveur and DBCS_prog_serveur == 1 ) then
--	message("ligne erreur SendChatMessageTimer_errorhandler_lent : "..(stexte or ""));
--	SendChatMessageTimer_ecrirecodedutexte(stexte);
--end
--			
--end

function SendChatMessageTimer_Update()

	if ( 1 == 1 ) then
		return nil;
	end

	if ( SendChatMessageTimer_indice == 0 and SendChatMessageTimer_indice_lent == 0 ) then
		return nil;
	end

local itime;
local tablo;

	itime = GetTime();
	if ( itime - SendChatMessageTimer_time > SendChatMessageTimer_refresh ) then
		if ( SendChatMessageTimer_indice > 0 ) then
			--SendChatMessageTimer_ecrirecodedutexte(SendChatMessageTimer_tablo[1][1]);
			tablo = SendChatMessageTimer_tablo[1];
			table.remove(SendChatMessageTimer_tablo,1);
			SendChatMessageTimer_indice = SendChatMessageTimer_indice - 1;
			--SendChatMessageTimer_saved_errorhandler = geterrorhandler();
			--seterrorhandler(SendChatMessageTimer_errorhandler);
			SendChatMessageTimer_Saved_SendChatMessage(tablo[1],tablo[2],tablo[3],tablo[4]);
			--seterrorhandler(SendChatMessageTimer_saved_errorhandler);
		elseif ( SendChatMessageTimer_indice_lent > 0 ) then
			--SendChatMessageTimer_ecrirecodedutexte(SendChatMessageTimer_tablo_lent[1][1]);
			tablo = SendChatMessageTimer_tablo_lent[1];
			table.remove(SendChatMessageTimer_tablo_lent,1);
			SendChatMessageTimer_indice_lent = SendChatMessageTimer_indice_lent - 1;
			--SendChatMessageTimer_saved_errorhandler_lent = geterrorhandler();
			--seterrorhandler(SendChatMessageTimer_errorhandler_lent);
			SendChatMessageTimer_Saved_SendChatMessage(tablo[1],tablo[2],tablo[3],tablo[4]);
			--seterrorhandler(SendChatMessageTimer_saved_errorhandler_lent);
		end
		--Saved_SendChatMessage("test : "..SendChatMessageTimer_time,"CHANNEL",this.language,6);
		SendChatMessageTimer_time = GetTime();
	end

end

function SendChatMessageTimer_Afficher_indice()

DEFAULT_CHAT_FRAME:AddMessage("SendChatMessageTimer_indice = "..SendChatMessageTimer_indice);

end

--/script SendChatMessageTimer_Refresh(0.1)
--/script SendChatMessageTimer_Refresh(0.2)
--/script SendChatMessageTimer_Refresh(0.21)
--/script SendChatMessageTimer_Refresh(0.22)
--/script SendChatMessageTimer_Refresh(0.23)
--/script SendChatMessageTimer_Refresh(0.24)
--/script SendChatMessageTimer_Refresh(0.25)
--/script SendChatMessageTimer_Refresh(0.26)
--/script SendChatMessageTimer_Refresh(0.27)
--/script SendChatMessageTimer_Refresh(0.28)
--/script SendChatMessageTimer_Refresh(0.29)
--/script SendChatMessageTimer_Refresh(0.3)
--/script SendChatMessageTimer_Refresh(0.4)
--/script SendChatMessageTimer_Refresh(0.5)
--/script SendChatMessageTimer_Refresh(0.6)
--/script SendChatMessageTimer_Refresh(0.7)
--/script SendChatMessageTimer_Refresh(0.8)
--/script SendChatMessageTimer_Refresh(0.9)
--/script SendChatMessageTimer_Refresh(1)
--/script SendChatMessageTimer_Refresh(36000)

-- change le délai entre chaque envoi de message, si blizzard change sa valeur ( en seconde )
function SendChatMessageTimer_Refresh(iseconde)

	SendChatMessageTimer_refresh = iseconde;

end

function SendChatMessageTimer_Vide()

	--if ( SendChatMessageTimer_indice == 0 and SendChatMessageTimer_indice_lent == 0 ) then
		return true;
	--else
	--	return false;
	--end

end

function SendChatMessageTimer_Update_cms()

	if ( 1 == 1 ) then
		return nil;
	end

	if ( ( SendChatMessageTimer_indice_cms_urgent == 0 ) and ( SendChatMessageTimer_indice_cms_lent == 0 ) ) then
		return nil;
	end

local itime;
local tablo;

	itime = GetTime();
	if ( SendChatMessageTimer_indice_cms_urgent > 0 ) then
		if ( itime - SendChatMessageTimer_cms_time > SendChatMessageTimer_cms_refresh ) then
			tablo = SendChatMessageTimer_tablo_cms_urgent[1];
			table.remove(SendChatMessageTimer_tablo_cms_urgent,1);
			SendChatMessageTimer_indice_cms_urgent = SendChatMessageTimer_indice_cms_urgent - 1;
			SendChatMessageTimer_Saved_SendChatMessage(tablo[1],tablo[2],tablo[3],tablo[4]);
			SendChatMessageTimer_cms_time = GetTime();
		end
	elseif ( SendChatMessageTimer_indice_cms_lent > 0 ) then
		if ( itime - SendChatMessageTimer_cms_time > SendChatMessageTimer_cms_refresh ) then
			tablo = SendChatMessageTimer_tablo_cms_lent[1];
			table.remove(SendChatMessageTimer_tablo_cms_lent,1);
			SendChatMessageTimer_indice_cms_lent = SendChatMessageTimer_indice_cms_lent - 1;
			SendChatMessageTimer_Saved_SendChatMessage(tablo[1],tablo[2],tablo[3],tablo[4]);
			SendChatMessageTimer_cms_time = GetTime();
		end
	end

end

function SendChatMessageTimer_SendChatMessage_cms_lent(val1,val2,val3,val4)

	SendChatMessageTimer_SendChatMessage_lent(val1,val2,val3,val4);

	--SendChatMessageTimer_indice_cms_lent = SendChatMessageTimer_indice_cms_lent + 1;
	--SendChatMessageTimer_tablo_cms_lent[SendChatMessageTimer_indice_cms_lent] = {};
	--SendChatMessageTimer_tablo_cms_lent[SendChatMessageTimer_indice_cms_lent][1] = val1;
	--SendChatMessageTimer_tablo_cms_lent[SendChatMessageTimer_indice_cms_lent][2] = val2;
	--SendChatMessageTimer_tablo_cms_lent[SendChatMessageTimer_indice_cms_lent][3] = val3;
	--SendChatMessageTimer_tablo_cms_lent[SendChatMessageTimer_indice_cms_lent][4] = val4;

end

function SendChatMessageTimer_SendChatMessage_cms_urgent(val1,val2,val3,val4)

	SendChatMessage(val1,val2,val3,val4);
	
	--SendChatMessageTimer_indice_cms_urgent = SendChatMessageTimer_indice_cms_urgent + 1;
	--SendChatMessageTimer_tablo_cms_urgent[SendChatMessageTimer_indice_cms_urgent] = {};
	--SendChatMessageTimer_tablo_cms_urgent[SendChatMessageTimer_indice_cms_urgent][1] = val1;
	--SendChatMessageTimer_tablo_cms_urgent[SendChatMessageTimer_indice_cms_urgent][2] = val2;
	--SendChatMessageTimer_tablo_cms_urgent[SendChatMessageTimer_indice_cms_urgent][3] = val3;
	--SendChatMessageTimer_tablo_cms_urgent[SendChatMessageTimer_indice_cms_urgent][4] = val4;

end

-- change le délai entre chaque envoi de message, si blizzard change sa valeur ( en seconde )
--/script SendChatMessageTimer_cms_Refresh(6)
--/script SendChatMessageTimer_cms_Refresh(7)
--/script SendChatMessageTimer_cms_Refresh(8)
--/script SendChatMessageTimer_cms_Refresh(9)
--/script SendChatMessageTimer_cms_Refresh(10)
function SendChatMessageTimer_cms_Refresh(iseconde)

	SendChatMessageTimer_cms_refresh = iseconde;

end

function SendChatMessageTimer_ecrirecodedutexte(stexte,ideb,ifin)

local ilen;
local i;
local icarac;
local scarac;

DEFAULT_CHAT_FRAME:AddMessage("texte = "..stexte);
	ilen = strlen(stexte);
	if ( ideb ) then
	else
		ideb = 1;
	end
	if ( ifin ) then
	else
		ifin = ilen;
	end
DEFAULT_CHAT_FRAME:AddMessage("ilen = "..ilen);
	for i = 1 , ilen do
		if ( i >= ideb and i <= ifin ) then
			icarac = strbyte(stexte,i,i);
			if ( icarac ) then
				if ( icarac > 31 and icarac < 127 ) then
DEFAULT_CHAT_FRAME:AddMessage(i.." : "..icarac.." = -"..strsub(stexte,i,i).."-.");
				else
DEFAULT_CHAT_FRAME:AddMessage(i.." : "..icarac.." = -"..icarac.."-.");
				end
			else
DEFAULT_CHAT_FRAME:AddMessage(i.." = -erreur-.");
			end
		end
	end

end
