local TraceFrame = DEFAULT_CHAT_FRAME;

if ( DBquetes2 == nil ) then
	DBquetes2 = nil;
end

local DBCS_quetes2_wow_build;
local DBCS_quetes2_wow_build_live = 13623;

_, DBCS_quetes2_wow_build, _, _ = GetBuildInfo();
DBCS_quetes2_wow_build = tonumber(DBCS_quetes2_wow_build);

--GetQuestLogSpecialItemInfo

--GetQuestReward(itemChoice)

--local link, item, charges = GetQuestLogSpecialItemInfo(questIndex);
--UseQuestLogSpecialItem(self:GetID());

--/script DEFAULT_CHAT_FRAME:AddMessage(FauxScrollFrame_GetOffset(DBcorpsFrame_QuetesFrame_Liste_ScrollFrame))

--/script SetItemRef("quest:14438")

-- gestion des quetes avec index

--/script DBquetes2[11650][14][39684] = nil;

--/script DBquetes2[11196][16] = {}
--/script DBquetes2[11196][16][69597] = {}
--/script DBquetes2[11196][16][69598] = {}
--/script DBquetes2[11196][16][69599] = {}
--/script DBquetes2[29186][16] = {}
--/script DBquetes2[29186][16][69594] = {}
--/script DBquetes2[29186][16][69595] = {}
--/script DBquetes2[29186][16][69596] = {}
--/script DBquetes2[29186][16][69748] = {}
--/script DBquetes2[24553][24] = {}
--/script DBquetes2[24553][24][24535] = 20100318
--/script DBquetes2[5165][14] = {}
--/script DBquetes2[5165][14][12906] = 1
--/script DBquetes2[24589][-2] = 80
--/script DBquetes2[24589][3] = 80
--/script DBquetes2[13906][46] = {}
--/script DBquetes2[13906][46][1] = 11701
--/script DBquetes2[13906][46][2] = 20101112
--/script DBquetes2[13906][47] = {}
--/script DBquetes2[13906][47][1] = 11701
--/script DBquetes2[13906][47][2] = 20101112

--/script DBquetes2[184][14][1972] = 1

--	DBquetes2
--			[num]
--				[-2]	=	nivquete pour link
--				[-1]	=	datevalidquete;
--				[0]	=	nom de la quete
--				[1]	=	objectif texte
--				[2]	=	niv min
--				[3]	=	niv conseil
--				[4]	=	description texte
--				[5]	=	{}	donneurs quete
--						[nomdonneur]	=	0
--				[6]	=	{}	finisseurs quete
--						[nomfinisseur]	=	0
------------------------------------------				[7]	=	numquete
--				[7]	=	date quete ds journal
--				[8]	=	date quete detail ( avant cliquer bouton accepter )
--				[9]	=	progress texte
--				[10]	=	salaire requis
--				[11]	=	salaire recompense < DBCS_nivmax ( 60 ) ( 70 )
--				[12]	=	salaire recompense pour DBCS_nivmax ( 60 ) ( 70 )
--				[13]	=	quete validée : ne plus l'envoyer tous les jours
--				[14]	=	{}	objets requis
--						[12038] = 3
--						[505] =1
--				[15]	=	{}	objets obtenus
--						[12038] = 3
--						[505] =1
--				[16]	=	{}	objets à choisir
--						[12038] = 3
--						[505] =1
--				[17]	=	complete texte
--				[18]	=	1	=	alliance
--				[19]	=	1	=	horde
--				[20]	=	catégorie de la quete
--				[21]	=	type de la quete ( tag )
--				[22]	=	{}	texte du sous objectif
--						[1] = texte
--						[2] = texte
--				[23]	=	{}	type du sous objectif
--						[1] = type
--						[2] = type
--				[24]	=	{}	quetes précédentes
						--	[numquete] = 0;
--				[25]	=	{}	quetes suivantes
						--	[numquete] = 0;
--				[26]	=	catégorie temporaire de la quete
--				[27]	=	quete partageable : nil ou 0 ou 1
--				[28]	=	quete journalière
--				[29]	=	nb joueurs conseillé
--				[30]	=	nb obj link
--				[31]	=	objectif link 1
--				[32]	=	objectif link 2
--				[33]	=	objectif link 3
--				[34]	=	objectif link 4
--				[35]	=	objectif link 5
--				[36]	=	objectif link 6
--				[37]	=	objectif link 7
--				[38]	=	objectif link 8
--				[39]	=	objectif link 9
--				[40]	=	objectif link 10
--				[41]	=	date quete progress
--				[42]	=	date quete complete
--				[43]	=	date envoi
--				[44]	=	date et heure création quete
--				[45]	=	salaire recompense pour DBCS_nivmax_wotlk ( 80 )
--				[46]	=	numéro pnj donneur quete
--				[47]	=	numéro pnj finisseur quete
--				[48]	=	salaire récompense pour DBCS_nivmax_CT ( 85 )
--				[49]	=	salaire récompense pour DBCS_nivmax_MOP ( 90 )

local DBQS2_event = nil;

DBQS2_NUMVERSION1 = "01";
DBQS2_NUMVERSION2 = "00";
DBQS2_NUMVERSION3 = "06";

DBquetes2_numquete = 0;
DBquetes2_numquete_niv = -2;
DBQS2_joueur = "";

local DBQS2_WOTLK = true;

--	if ( tonumber(date("%Y%m%d")) < 20081113 ) then
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("les serveurs n'ont pas encore WOTLK");
--end
--	else
--		DBQS2_WOTLK = true;
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("les serveurs ont WOTLK");
--end
--	end

local DBquetes2_inumqueteprec = nil;
local DBquetes2_timeprec = 0;

local DBquetes2_inbquetes = 0;

local DBquetes2_tempo_detail = nil;
local DBquetes2_tempo_detail_numquete = nil;
local DBquetes2_tempo_progress = nil;
local DBquetes2_tempo_progress_numquete = nil;
local DBquetes2_tempo_complete = nil;
local DBquetes2_tempo_complete_numquete = nil;

DBQS2_tquetesencours = {};

DBQS2_tempo = {};

local DBQS2_bquestcompleted = false;

local DBQS2_suivi_quetes_time = 0;

local DBQS2_missingheader = "Missing header! (quest designers)";

DBQS2_color = {};
DBQS2_color["impossible"] = { r = 1.00, g = 0.10, b = 0.10 };
DBQS2_color["verydifficult"] = { r = 1.00, g = 0.50, b = 0.25 };
DBQS2_color["difficult"] = { r = 1.00, g = 1.00, b = 0.00 };
DBQS2_color["standard"] = { r = 0.25, g = 0.75, b = 0.25 };
DBQS2_color["trivial"]	= { r = 0.50, g = 0.50, b = 0.50 };
DBQS2_color["header"]	= { r = 0.7, g = 0.7, b = 0.7 };

DBQS2_quetes_journalieres_type = {};
DBQS2_quetes_journalieres_type[01] = { provisoire = false , dejafait = false , encours = 0 , name = "P\195\170cheur" };
DBQS2_quetes_journalieres_type[02] = { provisoire = false , dejafait = false , encours = 0 , name = "Jcj Bg" };
DBQS2_quetes_journalieres_type[03] = { provisoire = false , dejafait = false , encours = 0 , name = "Drake : Pi\195\168ges" };
DBQS2_quetes_journalieres_type[04] = { provisoire = false , dejafait = false , encours = 0 , name = "Donjon BC" };
DBQS2_quetes_journalieres_type[05] = { provisoire = false , dejafait = false , encours = 0 , name = "Donjon BC H\195\169ro" };
DBQS2_quetes_journalieres_type[06] = { provisoire = false , dejafait = false , encours = 0 , name = "Cuisinier" };
DBQS2_quetes_journalieres_type[07] = { provisoire = false , dejafait = false , encours = 0 , name = "Jcj Halaa" };
DBQS2_quetes_journalieres_type[08] = { provisoire = false , dejafait = false , encours = 0 , name = "Jcj Auchindoun" };
DBQS2_quetes_journalieres_type[09] = { provisoire = true  , dejafait = false , encours = 0 , name = "PdS : B\195\162timent 1 \195\169tape 1" };
DBQS2_quetes_journalieres_type[10] = { provisoire = true  , dejafait = false , encours = 0 , name = "PdS : B\195\162timent 1 \195\169tape 2" };
DBQS2_quetes_journalieres_type[11] = { provisoire = true  , dejafait = false , encours = 0 , name = "PdS : B\195\162timent 2 \195\169tape 1" };
DBQS2_quetes_journalieres_type[12] = { provisoire = true  , dejafait = false , encours = 0 , name = "PdS : B\195\162timent 2 \195\169tape 2" };
DBQS2_quetes_journalieres_type[13] = { provisoire = true  , dejafait = false , encours = 0 , name = "PdS : B\195\162timent 2 Portail" };
DBQS2_quetes_journalieres_type[14] = { provisoire = true  , dejafait = false , encours = 0 , name = "PdS : Armurier" };
DBQS2_quetes_journalieres_type[15] = { provisoire = true  , dejafait = false , encours = 0 , name = "PdS : Armurerie \195\169tape 1" };
DBQS2_quetes_journalieres_type[16] = { provisoire = true  , dejafait = false , encours = 0 , name = "PdS : Armurerie \195\169tape 2" };
DBQS2_quetes_journalieres_type[17] = { provisoire = true  , dejafait = false , encours = 0 , name = "PdS : Port - Laboratoire d'alchimie" };
DBQS2_quetes_journalieres_type[18] = { provisoire = true  , dejafait = false , encours = 0 , name = "PdS : Statue" };

DBQS2_quetes_journalieres_type_encours = nil;

DBQS2_quetes_journalieres = { 
		[11665] = 1 , [11666] = 1 , [11667] = 1 , [11668] = 1 , [11669] = 1 ,
		[11335] = 2 , [11336] = 2 , [11337] = 2 , [11338] = 2 , [11339] = 2 , [11340] = 2 , [11341] = 2 , [11342] = 2 ,
		[11097] = 3 , [11101] = 3 ,
		[11364] = 4 , [11371] = 4 , [11376] = 4 , [11383] = 4 , [11385] = 4 , [11387] = 4 , [11389] = 4 , [11500] = 4 ,
		[11362] = 5 , [11363] = 5 , [11368] = 5 , [11369] = 5 , [11370] = 5 , [11372] = 5 , [11373] = 5 , [11374] = 5 , [11375] = 5 , [11378] = 5 , [11382] = 5 , [11384] = 5 , [11386] = 5 , [11388] = 5 , [11499] = 5 ,
		[11377] = 6 , [11379] = 6 , [11380] = 6 , [11381] = 6 ,
		[11502] = 7 , [11503] = 7 ,
		[11505] = 8 , [11506] = 8 ,
		[11524] = -9 , [11525] = 9 ,
		[11496] = -10 , [11523] = 10 ,
		[11532] = -11 , [11533] = 11 ,
		[11538] = -12 , [11537] = 12 ,
		[11513] = -13 , [11514] = 13 ,
		[11535] = -14 , [11536] = 14 ,
		[11539] = -15 , [11540] = 15 ,
		[11542] = -16 , [11543] = 16 ,
		[11520] = -17 , [11521] = 17 ,
		[11545] = -18 , [11548] = 18 ,
};

--local DBquetes2_patch030100 = false;
--if ( QuestWatchFrame ) then
--else
--DBquetes2_patch030100 = true;
--end

if ( GetLocale() == "frFR" ) then

--GetQuestReward(itemChoice)
local Saved_DBQS2_GetQuestReward = GetQuestReward;
function DBQS2_GetQuestReward(itemChoice)

if ( DBCS_debug and DBCS_debug > 1 ) then
TraceFrame:AddMessage("DBQS2_GetQuestReward");
end

	Saved_DBQS2_GetQuestReward(itemChoice);
	if ( DBHC_perso ) then
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_GetQuestReward , DBquetes2_inumqueteprec = "..( DBquetes2_inumqueteprec or "" ));
--end
		if ( DBquetes2_inumqueteprec ) then
			DBHC2_sauverquetefaite(DBquetes2_inumqueteprec);
		end
	end
	DBquetes2_timeprec = GetTime();

end
GetQuestReward = DBQS2_GetQuestReward;

--local Saved2_DBQS2_QuestRewardCompleteButton_OnClick = QuestRewardCompleteButton_OnClick;
--function DBQS2_QuestRewardCompleteButton_OnClick2()
--
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_QuestRewardCompleteButton_OnClick2");
--end
--
--	Saved2_DBQS2_QuestRewardCompleteButton_OnClick();
--
--end
--QuestRewardCompleteButton_OnClick = DBQS2_QuestRewardCompleteButton_OnClick2;

--if ( DBquetes2_patch030100 == true ) then

local Saved_DBQS2_WatchFrameLinkButtonTemplate_OnLeftClick = WatchFrameLinkButtonTemplate_OnLeftClick;

function DBQS2_WatchFrameLinkButtonTemplate_OnLeftClick(self)

	CloseDropDownMenus();
	if ( self.type == "QUEST" ) then

local slink;
local snumitemcourt;
local snumitemlong;
local ipos;
local inumquete;

		slink = GetQuestLink(GetQuestIndexForWatch(self.index));	--	GetQuestSortIndex( GetQuestIndexForWatch(self.index) )
		if ( slink ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("slink = "..slink);
--end
			_, snumitemcourt, snumitemlong, _, _ = DBQS2_GetMotItem(slink);
			ipos = strfind(snumitemcourt,":");
			if ( ipos ) then
				inumquete = tonumber(strsub(snumitemcourt,1,ipos-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("inumquete = "..inumquete);
--end
			--DBcorps_ListQuetes2_Reset();
				DBCORPS_QUETES2_LISTE = {};
				DBCORPS_QUETES2_LISTE = DBquetes2_Liste_ajout(DBCORPS_QUETES2_LISTE,inumquete);
				DBCORPS_QUETES2_LISTE_nb = table.getn(DBCORPS_QUETES2_LISTE);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("1DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
				_G["DBcorpsFrame_Quetes2Frame_Criteres_Elements"]:SetText(DBCORPS_QUETES2_LISTE_nb.." \195\169l\195\169ments trouv\195\169s.");
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_QuestLog_OpenToQuestIndex DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
				DBcorps_ListQuetes2_Trier();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("2DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
				DBcorps_init();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("3DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
				PanelTemplates_SetTab(DBcorpsFrame, 6);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("4DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
				DBcorps_ShowSubFrame(6);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("5DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
				FauxScrollFrame_SetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame,0);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("6DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
				DBcorps_Quetes2_Scroll_Update();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("7DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
			end
		end
		return;
	end
	Saved_DBQS2_WatchFrameLinkButtonTemplate_OnLeftClick(self);

end
WatchFrameLinkButtonTemplate_OnLeftClick = DBQS2_WatchFrameLinkButtonTemplate_OnLeftClick;



--local Saved_DBQS2_QuestLog_OpenToQuestIndex = QuestLog_OpenToQuestIndex;
--function DBQS2_QuestLog_OpenToQuestIndex(index)

--local slink;
--local snumitemcourt;
--local snumitemlong;
--local ipos;
--local inumquete;

--	slink = GetQuestLink(index);
--	if ( slink ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("slink = "..slink);
--end
--		_, snumitemcourt, snumitemlong, _, _ = DBQS2_GetMotItem(slink);
--		ipos = strfind(snumitemcourt,":");
--		if ( ipos ) then
--			inumquete = tonumber(strsub(snumitemcourt,1,ipos-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("inumquete = "..inumquete);
--end
--			--DBcorps_ListQuetes2_Reset();
--			DBCORPS_QUETES2_LISTE = {};
--			DBCORPS_QUETES2_LISTE = DBquetes2_Liste_ajout(DBCORPS_QUETES2_LISTE,inumquete);
--			DBCORPS_QUETES2_LISTE_nb = table.getn(DBCORPS_QUETES2_LISTE);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("1DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
--			_G["DBcorpsFrame_Quetes2Frame_Criteres_Elements"]:SetText(DBCORPS_QUETES2_LISTE_nb.." \195\169l\195\169ments trouv\195\169s.");
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_QuestLog_OpenToQuestIndex DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
--			DBcorps_ListQuetes2_Trier();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("2DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
--			DBcorps_init();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("3DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
--			PanelTemplates_SetTab(DBcorpsFrame, 6);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("4DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
--			DBcorps_ShowSubFrame(6);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("5DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
--			FauxScrollFrame_SetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame,0);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("6DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
--			DBcorps_Quetes2_Scroll_Update();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("7DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
--		end
--	end

--end
--QuestLog_OpenToQuestIndex = DBQS2_QuestLog_OpenToQuestIndex;

--else

--function DBQS2_QuestWatchLine_OnClick()

--local snom;
--local snum;
--local inum;
--local i,j,k,l;
--local i_index = -1;
--local i_obj = -1;
--local slink;
--local snumitemcourt;
--local snumitemlong;
--local ipos;
--local inumquete;

--	snom = this:GetName();
--	snum = strsub(snom,21);
--	inum = tonumber(snum);
--	j = 0;
--	for i = 1 , GetNumQuestWatches() do
--		k = GetQuestIndexForWatch(i);
--		if ( k and i_index == -1 ) then
--			j = j + 1;
--			l = GetNumQuestLeaderBoards(k);
--			if ( j == inum ) then
--				i_index = k;
--				i_obj = -1;
--			else
--				if ( inum <= j + l ) then
--					i_index = k;
--					i_obj = inum - j;
--				end
--			end
--			j = j + l;
--		end
--	end
--	if ( i_index > -1 ) then
--		slink = GetQuestLink(i_index);
--		_, snumitemcourt, snumitemlong, _, _ = DBQS2_GetMotItem(slink);
--		ipos = strfind(snumitemcourt,":");
--		if ( ipos ) then
--			inumquete = tonumber(strsub(snumitemcourt,1,ipos-1));
--			DBCORPS_QUETES2_LISTE = {};
--			DBCORPS_QUETES2_LISTE = DBquetes2_Liste_ajout(DBCORPS_QUETES2_LISTE,inumquete);
--			DBCORPS_QUETES2_LISTE_nb = table.getn(DBCORPS_QUETES2_LISTE);
--			_G["DBcorpsFrame_Quetes2Frame_Criteres_Elements"]:SetText(DBCORPS_QUETES2_LISTE_nb.." \195\169l\195\169ments trouv\195\169s.");
----if ( DBCS_debug > 1 ) then
----TraceFrame:AddMessage("DBQS2_QuestWatchLine_OnClick DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
----end
--			DBcorps_ListQuetes2_Trier();
--			DBcorps_init();
--			PanelTemplates_SetTab(DBcorpsFrame, 6);
--			DBcorps_ShowSubFrame(6);
--			FauxScrollFrame_SetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame,0);
----if ( DBCS_debug > 1 ) then
----TraceFrame:AddMessage("DBQS2_QuestWatchLine_OnClick DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
----end
--			DBcorps_Quetes2_Scroll_Update();
--		end
--	end

--end

--DBQS2_QuestWatch_Update_nummax = 0;

--local Saved_DBQS2_QuestWatch_Update = QuestWatch_Update;
--function DBQS2_QuestWatch_Update()

--local oorig;
--local oframe;
--local i;

--	Saved_DBQS2_QuestWatch_Update();

--	for i = 1 , 30 do
--		oorig = _G["QuestWatchLine"..i];
--		if ( oorig ) then
--			if ( i > DBQS2_QuestWatch_Update_nummax ) then
--				DBQS2_QuestWatch_Update_nummax = i;
--				oframe = CreateFrame("Button","DBQS2_QuestWatchLine"..i,QuestWatchFrame);
--				oframe:SetScript("OnClick",DBQS2_QuestWatchLine_OnClick);
--				--oframe = _G["DBQS_QuestWatchLine"..i];
--			else
--				oframe = _G["DBQS2_QuestWatchLine"..i];
--			end
--			oframe:SetWidth(oorig:GetWidth());
--			oframe:SetHeight(oorig:GetHeight());
--			oframe:SetPoint("TOPLEFT",oorig,"TOPLEFT",0,0);
--			oframe:SetFrameLevel(QuestWatchFrame:GetFrameLevel() + 1);
--			--oframe:SetFrameStrata("LOW");
--			if ( oorig:IsShown() and QuestWatchFrame:IsShown() ) then
--				oframe:Show();
--			else
--				oframe:Hide();
--			end
--		end
--	end

--end
--QuestWatch_Update = DBQS2_QuestWatch_Update;

--end

local Saved_DBQS2_AddQuestWatch = AddQuestWatch;
function DBQS2_AddQuestWatch(questIndex)

	Saved_DBQS2_AddQuestWatch(questIndex);

--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_AddQuestWatch DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
	DBcorps_Quetes2_Scroll_Update();

	if ( DBQS2_suivi_quetes_time == -1 ) then
		DBQS2_sauvegarder_suivi_quete();
	end

end
AddQuestWatch = DBQS2_AddQuestWatch;

local Saved_DBQS2_RemoveQuestWatch = RemoveQuestWatch;
function DBQS2_RemoveQuestWatch(questIndex)

	Saved_DBQS2_RemoveQuestWatch(questIndex);

--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_RemoveQuestWatch DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
	DBcorps_Quetes2_Scroll_Update();

	if ( DBQS2_suivi_quetes_time == -1 ) then
		DBQS2_sauvegarder_suivi_quete();
	end

end
RemoveQuestWatch = DBQS2_RemoveQuestWatch;

----	QuestDetailAcceptButton_OnClick()
--local Saved_DBQS2_QuestDetailAcceptButton_OnClick = QuestDetailAcceptButton_OnClick;
--function DBQS2_QuestDetailAcceptButton_OnClick()
--
--	Saved_DBQS2_QuestDetailAcceptButton_OnClick();
--	if ( DBCS_wow_2_4() == true ) then
--		DBQS2_sauvegarder_suivi_quete();
--	end
--
--end
--QuestDetailAcceptButton_OnClick = DBQS2_QuestDetailAcceptButton_OnClick;

--QuestRewardCompleteButton_OnClick()
--local Saved_DBQS2_QuestRewardCompleteButton_OnClick = QuestRewardCompleteButton_OnClick;
--function DBQS2_QuestRewardCompleteButton_OnClick()
--
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_QuestRewardCompleteButton_OnClick");
--end
--	Saved_DBQS2_QuestRewardCompleteButton_OnClick();
--	if ( DBHC_perso ) then
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_QuestRewardCompleteButton_OnClick , DBquetes2_inumqueteprec = "..( DBquetes2_inumqueteprec or "" ));
--end
--		if ( DBquetes2_inumqueteprec ) then
--			DBHC2_sauverquetefaite(DBquetes2_inumqueteprec);
--		end
--	end
--	DBquetes2_timeprec = GetTime();
--
--end
--QuestRewardCompleteButton_OnClick = DBQS2_QuestRewardCompleteButton_OnClick;

local Saved_DBQS2_QuestLog_SetSelection = QuestLog_SetSelection;
function DBQS2_QuestLog_SetSelection(questID)

local isHeader;
local isCollapsed;

	Saved_DBQS2_QuestLog_SetSelection(questID);

	_, _, _, _, isHeader, isCollapsed, _, _ = GetQuestLogTitle(questID);
	if ( isHeader ) then
		ExpandQuestHeader(questID);
	end

end
QuestLog_SetSelection = DBQS2_QuestLog_SetSelection;

end

function DBQS2_sauvegarder_suivi_quete()

local snomserveur;
local snomjoueur;
local i;
local j;

	snomserveur = GetRealmName();
	snomjoueur = UnitName("player");
	if ( DBCS_config["suivi_quetes"] == nil ) then
		DBCS_config["suivi_quetes"] = {};
	end
	if ( DBCS_config["suivi_quetes"][snomserveur] == nil ) then
		DBCS_config["suivi_quetes"][snomserveur] = {};
	end
	DBCS_config["suivi_quetes"][snomserveur][snomjoueur] = {};
	for i = 1 , GetNumQuestWatches() do
		j = GetQuestIndexForWatch(i);
		if ( j ) then
			DBCS_config["suivi_quetes"][snomserveur][snomjoueur][j] = 0;
		end
	end

end

function DBquetes2_OnUpdate()

local snomserveur;
local snomjoueur;
local tablo = {};
local iindex;

	if ( DBQS2_suivi_quetes_time > 0 ) then
		if ( (GetTime() - DBQS2_suivi_quetes_time) > 5 ) then	--	*1000	/1000
			snomserveur = GetRealmName();
			snomjoueur = UnitName("player");
			if ( DBCS_config and DBCS_config["suivi_quetes"] and DBCS_config["suivi_quetes"][snomserveur] and DBCS_config["suivi_quetes"][snomserveur][snomjoueur] ) then
				tablo = DBCS_config["suivi_quetes"][snomserveur][snomjoueur];
				for iindex, _ in pairs(tablo) do
					AddQuestWatch(iindex);
				end
				--if ( DBquetes2_patch030100 == false ) then
				--	QuestWatch_Update();
				--else
					WatchFrame_Update();
				--end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBquetes2_OnUpdate DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
				DBcorps_Quetes2_Scroll_Update();
			end
			DBQS2_suivi_quetes_time = -1;
		end
	end

end

function DBquetes2_OnLoad(self)

if ( GetLocale() == "frFR" ) then

	self:RegisterEvent("CHAT_MSG_CHANNEL");
	self:RegisterEvent("GOSSIP_SHOW");
	self:RegisterEvent("PLAYER_ENTERING_WORLD");
	self:RegisterEvent("QUEST_COMPLETE");
	self:RegisterEvent("QUEST_DETAIL");
	self:RegisterEvent("QUEST_ITEM_UPDATE");
	self:RegisterEvent("QUEST_LOG_UPDATE");
	self:RegisterEvent("QUEST_PROGRESS");
	self:RegisterEvent("QUEST_QUERY_COMPLETE");
	self:RegisterEvent("VARIABLES_LOADED");

end

	--DBquetes2 = {};
	--DBPS2 = {};
	DBquetes2_config = {};

end

function DBQS2_traitermessagecms(sjoueur,ssuite)

local ifin;
--local slangue;
--local ssuite;
local ssection;
local straitement;
local sversion;
local senreg;
local inumenreg;
local inbenreg;
local squete2suite;

	if ( sjoueur == DBCS_joueur ) then
		return;
	else
		if ( strlen(ssuite) > 5 ) then
			ifin = strfind(ssuite,"@",1);
--			slangue = strsub(ssuite,1,ifin-1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("slangue = "..slangue);
--end
			--ssuite = strsub(ssuite,ifin+1);
			ssection = strsub(ssuite,1,1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("ssection = "..ssection);
--end
			straitement = strsub(ssuite,2,2);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("straitement = "..straitement);
--end
			sversion = strsub(ssuite,3,4);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("sversion = "..sversion);
--end
			senreg = strsub(ssuite,6);
			if ( ssection == "Q" ) then
				if ( straitement == "M" ) then
					if ( sversion == "02" ) then	--	and slangue == DBCS_getlocale 
						if ( DBQS2_tempo[sjoueur] == nil ) then
							DBQS2_tempo[sjoueur] = {};
						end
						ifin = 0;
						ideb = ifin+1;
						ifin = strfind(senreg,"@",ideb);
						stime = strsub(senreg,ideb,ifin-1);
						if ( DBQS2_tempo[sjoueur][stime] == nil ) then
							DBQS2_tempo[sjoueur][stime] = {};
						end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("stime = "..stime);
--end
						ideb = ifin+1;
						ifin = strfind(senreg,"@",ideb);
						inumenreg = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("inumenreg = "..inumenreg);
--end
						ideb = ifin+1;
						--ifin = strfind(senreg,"@",ideb);
						squete2suite = strsub(senreg,ideb);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("squete2suite = "..(squete2suite or ""));
--end
						DBQS2_tempo[sjoueur][stime][inumenreg] = squete2suite;
						if ( inumenreg == 0 ) then
							ifin = 0;
							ideb = ifin+1;
							ifin = strfind(squete2suite,"@",ideb);
							inbenreg = tonumber(strsub(squete2suite,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("inbenreg = "..inbenreg);
--end
							DBQS2_tempo[sjoueur][stime][-1] = inbenreg;
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("ajout de quete2 0 par "..DBCS_lienjoueurbynom(sjoueur));
end
						end
						if ( DBQS2_tempo[sjoueur][stime][-1] ) then
							if ( DBQS2_tempo[sjoueur][stime][-1] == table.getn(DBQS2_tempo[sjoueur][stime]) ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("ajout de quete2 par "..DBCS_lienjoueurbynom(sjoueur));
end
								DBQS2_traiter_quete_cms(sjoueur,stime);
							elseif ( DBQS2_tempo[sjoueur][stime][-1] == inumenreg ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("quete2 pas complet par "..DBCS_lienjoueurbynom(sjoueur));
end
							end
						end
					end
				end
			end
		end
	end

end

function DBQS2_traiter_quete_cms(sjoueur,stime)

local i;
local j;
local tablo;
local tabloquete;
local senreg;
local ideb;
local ifin;
local itype_enreg;
local inumquete;
local i14;
local i15;
local i16;
local i22;
local i23;
local i24_quete;
local i24_date;
local i25_quete;
local i25_date;
local s5_nomdonneur;
local i5_datedonneur;
local s6_nomfinisseur;
local i6_datefinisseur;
local inumobjet;
local inbobjets;
local sfaction;

	tabloquete = {};
	tabloquete[1] = "";
	tabloquete[4] = "";
	tabloquete[9] = "";
	tabloquete[17] = "";
	tablo = DBQS2_tempo[sjoueur][stime];
	itype_enreg = -1;
	for i = 1 , tablo[-1] do
		senreg = tablo[i];
		ifin = 0;
		ideb = ifin + 1;
		if ( senreg == nil ) then
			itype_enreg = 0;
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("erreur quete cms : sjoueur = "..sjoueur.." , stime = "..stime);
end
			break;
		else
			ifin = strfind(senreg,"@",ideb);
			itype_enreg = tonumber(strsub(senreg,ideb,ifin-1));
		end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("itype_enreg = "..itype_enreg);
--end
		if ( itype_enreg == 1 ) then
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			inumquete = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("inumquete = "..inumquete);
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[-2] = tonumber(strsub(senreg,ideb,ifin-1));
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("tabloquete[-2] = "..(tabloquete[-2] or ""));
end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[2] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[2] = "..(tabloquete[2] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[3] = tonumber(strsub(senreg,ideb,ifin-1));
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("tabloquete[3] = "..(tabloquete[3] or ""));
end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[7] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[7] = "..(tabloquete[7] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[8] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[8] = "..(tabloquete[8] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[10] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[10] = "..(tabloquete[10] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[11] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[11] = "..(tabloquete[11] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[12] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[12] = "..(tabloquete[12] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[13] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[13] = "..(tabloquete[13] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			i14 = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i14 = "..i14);
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			i15 = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i15 = "..i15);
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			i16 = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i16 = "..i16);
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[18] = strsub(senreg,ideb,ifin-1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[18] = "..tabloquete[18]);
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[19] = strsub(senreg,ideb,ifin-1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[19] = "..tabloquete[19]);
--end
			sfaction, _ = UnitFactionGroup("player");
			if ( sfaction == "Alliance" ) then
				tabloquete[18] = 1;	--	alliance
			elseif ( sfaction == "Horde" ) then
				tabloquete[19] = 1;	--	horde
			end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			i22 = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i22 = "..(i22 or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			i23 = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i23 = "..(i23 or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			i24_quete = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i24_quete = "..(i24_quete or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			i24_date = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i24_date = "..(i24_date or ""));
--end
			if ( i24_quete ) then
				tabloquete[24] = {};
				tabloquete[24][i24_quete] = i24_date;
			end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			i25_quete = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i25_quete = "..(i25_quete or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			i25_date = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i25_date = "..(i25_date or ""));
--end
			if ( i25_quete ) then
				tabloquete[25] = {};
				tabloquete[25][i25_quete] = i25_date;
			end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[27] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[27] = "..(tabloquete[27] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[28] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[28] = "..(tabloquete[28] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[29] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[29] = "..(tabloquete[29] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[30] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[30] = "..(tabloquete[30] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[41] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[41] = "..(tabloquete[41] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[42] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[42] = "..(tabloquete[42] or ""));
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			if ( ifin ) then
				tabloquete[45] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[45] = "..(tabloquete[45] or ""));
--end
			end
			--DBCS_nivmax_CT
			if ( ifin ) then
				ideb = ifin + 1;
				ifin = strfind(senreg,"@",ideb);
				if ( ifin ) then
					tabloquete[48] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[48] = "..(tabloquete[48] or ""));
--end
				end
			end
			--DBCS_nivmax_MOP
			if ( ifin ) then
				ideb = ifin + 1;
				ifin = strfind(senreg,"@",ideb);
				if ( ifin ) then
					tabloquete[49] = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[49] = "..(tabloquete[49] or ""));
--end
				end
			end
		elseif ( itype_enreg == 2 ) then
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[0] = strsub(senreg,ideb,ifin-1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[0] = "..tabloquete[0]);
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[20] = strsub(senreg,ideb,ifin-1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[20] = "..tabloquete[20]);
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[21] = strsub(senreg,ideb,ifin-1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[21] = "..tabloquete[21]);
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[26] = strsub(senreg,ideb,ifin-1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[26] = "..tabloquete[26]);
--end
		elseif ( itype_enreg == 3 ) then
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[1] = tabloquete[1]..strsub(senreg,ideb,ifin-1);
		elseif ( itype_enreg == 4 ) then
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[4] = tabloquete[4]..strsub(senreg,ideb,ifin-1);
		elseif ( itype_enreg == 5 ) then
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			tabloquete[9] = tabloquete[9]..strsub(senreg,ideb,ifin-1);
		elseif ( itype_enreg == 6 ) then
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			if ( ifin ) then
				tabloquete[17] = tabloquete[17]..strsub(senreg,ideb,ifin-1);
			end
		elseif ( itype_enreg == 7 ) then
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			s5_nomdonneur = strsub(senreg,ideb,ifin-1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("s5_nomdonneur = "..s5_nomdonneur);
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			i5_datedonneur = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i5_datedonneur = "..(i5_datedonneur or ""));
--end
			tabloquete[5] = {};
			tabloquete[5][s5_nomdonneur] = i5_datedonneur;
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			s6_nomfinisseur = strsub(senreg,ideb,ifin-1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("s6_nomfinisseur = "..s6_nomfinisseur);
--end
			ideb = ifin + 1;
			ifin = strfind(senreg,"@",ideb);
			i6_datefinisseur = tonumber(strsub(senreg,ideb,ifin-1));
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i6_datefinisseur = "..(i6_datefinisseur or ""));
--end
			tabloquete[6] = {};
			tabloquete[6][s6_nomfinisseur] = i6_datefinisseur;
		elseif ( itype_enreg == 8 ) then
			tabloquete[14] = {};
			for j = 1 , i14 do
				ideb = ifin + 1;
				ifin = strfind(senreg,"@",ideb);
				inumobjet = tonumber(strsub(senreg,ideb,ifin-1));
				ideb = ifin + 1;
				ifin = strfind(senreg,"@",ideb);
				inbobjets = tonumber(strsub(senreg,ideb,ifin-1));
				tabloquete[14][inumobjet] = inbobjets;
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[14]["..inumobjet.."] = "..tabloquete[14][inumobjet]);
--end
			end
		elseif ( itype_enreg == 9 ) then
			tabloquete[15] = {};
			for j = 1 , i15 do
				ideb = ifin + 1;
				ifin = strfind(senreg,"@",ideb);
				inumobjet = tonumber(strsub(senreg,ideb,ifin-1));
				ideb = ifin + 1;
				ifin = strfind(senreg,"@",ideb);
				inbobjets = tonumber(strsub(senreg,ideb,ifin-1));
				tabloquete[15][inumobjet] = inbobjets;
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[15]["..inumobjet.."] = "..tabloquete[15][inumobjet]);
--end
			end
		elseif ( itype_enreg == 10 ) then
			tabloquete[16] = {};
			for j = 1 , i16 do
				ideb = ifin + 1;
				ifin = strfind(senreg,"@",ideb);
				inumobjet = tonumber(strsub(senreg,ideb,ifin-1));
				ideb = ifin + 1;
				ifin = strfind(senreg,"@",ideb);
				inbobjets = tonumber(strsub(senreg,ideb,ifin-1));
				tabloquete[16][inumobjet] = inbobjets;
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[16]["..inumobjet.."] = "..tabloquete[16][inumobjet]);
--end
			end
		elseif ( itype_enreg == 11 ) then
			tabloquete[23] = {};
			for j = 1 , i23 do
				ideb = ifin + 1;
				ifin = strfind(senreg,"@",ideb);
				stype = strsub(senreg,ideb,ifin-1);
				tabloquete[23][j] = stype;
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[23]["..j.."] = "..tabloquete[23][j]);
--end
			end
		else
		end
	end
	tabloquete[1] = DBQS2_ajoutersautdeligne(tabloquete[1]);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[1] = "..tabloquete[1]);
--end
	tabloquete[4] = DBQS2_ajoutersautdeligne(tabloquete[4]);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[4] = "..tabloquete[4]);
--end
	tabloquete[9] = DBQS2_ajoutersautdeligne(tabloquete[9]);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[9] = "..tabloquete[9]);
--end
	tabloquete[17] = DBQS2_ajoutersautdeligne(tabloquete[17]);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("tabloquete[17] = "..tabloquete[17]);
--end
	if ( itype_enreg == 0 ) then
	else
		DBQS2_maj_quete(inumquete,tabloquete);
	end

	DBQS2_tempo[sjoueur][stime] = nil;

end

function DBQS2_maj_quete(inumquete,tabloquete,toutinvisible)

local tablo;
local tablo2;
local tablo3;
--date :	7 journal	8 détail	41 progress	42 complete
local a7;
local a8;
local a41;
local a42;
local b7;
local b8;
local b41;
local b42;
local a_7_8;
local b_7_8;
local a_8_41;
local b_8_41;
local a_41_42;
local b_41_42;
local a_7_8_42;
local b_7_8_42;
local a_7_8_41_42;
local b_7_8_41_42;
local snomdonneur;
local snomfinisseur;
local inumobjet;
local i;
local inumqueteprec;
local inumquetesuiv;
local inumquete2;
local btrouve;
local bmodifdate0;

	if ( toutinvisible ) then
	else
		toutinvisible = false;
	end
	bmodifdate0 = false;
	if ( DBquetes2[inumquete] == nil ) then
		if ( DBCS_afficher_new_quetes == true ) then
if ( toutinvisible == false ) then
			TraceFrame:AddMessage("Nouvelle qu\195\170te : id = "..inumquete.." , nom : "..(tabloquete[0] or ""));
			TraceFrame:AddMessage("objectif : "..(tabloquete[1] or ""));
end
		end
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
TraceFrame:AddMessage("Nouvelle qu\195\170te");
end
end
		DBquetes2[inumquete] = {};
		DBquetes2[inumquete][0] = tabloquete[0];
		DBquetes2[inumquete][44] = DBCS_date().."@"..DBCS_time();
	end
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
TraceFrame:AddMessage(DBQS2_lienquetebynum_nomquete(inumquete));
end
end

	if ( DBquetes2[inumquete][7] == nil and DBquetes2[inumquete][8] == nil and DBquetes2[inumquete][41] == nil and DBquetes2[inumquete][1] == nil ) then
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
TraceFrame:AddMessage("quete louche : "..inumquete.." = "..(DBquetes2[inumquete][0] or ""));
end
end
		if ( tabloquete[26] == DBquetes2[inumquete][26] or DBquetes2[inumquete][26] == nil or DBquetes2[inumquete][26] == "" or DBquetes2[inumquete][26] == "#" ) then
		else
			tablo2 = {};
			btrouve = false;
			-- recherche des numéros de quetes avec le meme nom et objectif vide
			for inumquete2, _ in pairs(DBquetes2) do
				if ( btrouve == false and DBquetes2[inumquete2][0] == DBquetes2[inumquete][0] and DBquetes2[inumquete2][1] == nil ) then
					table.insert(tablo2,inumquete2);
					-- si la région temporaire est la meme
					if ( tabloquete[26] == DBquetes2[inumquete2][26] ) then
						btrouve = true;
						tablo2 = {};
						inumquete = inumquete2;
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
TraceFrame:AddMessage("quete existe : "..inumquete2);
end
end
					end
				end
			end
			if ( table.getn(tablo2) > 1 ) then
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
TraceFrame:AddMessage("quete louche : "..inumquete.." = "..(DBquetes2[inumquete][0] or "").." , "..table.getn(tablo2).." occurences.");
end
end
				tablo3 = {};
				-- recherche des numéros de quetes avec la meme région temporaire
				for _, inumquete2 in pairs(tablo2) do
					if ( inumquete2 == inumquete ) then
					else
						if ( DBquetes2[inumquete2][26] == DBquetes2[inumquete][26] ) then
							table.insert(tablo3,inumquete2);
						end
					end
				end
				if ( table.getn(tablo3) > 0 ) then
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
TraceFrame:AddMessage("autre quete possible en double : "..tablo3[1]);
end
end
					inumquete = tablo3[1];
				else
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
TraceFrame:AddMessage("sauter cette quete.");
end
end
					--sauter cette quete
					--bsauter = true;
					--return nil;
					return bmodifdate0;
				end
			end
		end
		--DBquetes2_tempo_complete[26]
	end

	tablo = DBquetes2[inumquete];
	a7 = tabloquete[7];
	if ( a7 == nil ) then
		a7 = 0;
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("a7 = "..a7);
--end
	a8 = tabloquete[8];
	if ( a8 == nil ) then
		a8 = 0;
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("a8 = "..a8);
--end
	a41 = tabloquete[41];
	if ( a41 == nil ) then
		a41 = 0;
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("a41 = "..a41);
--end
	a42 = tabloquete[42];
	if ( a42 == nil ) then
		a42 = 0;
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("a42 = "..a42);
--end
	b7 = tablo[7];
	if ( b7 == nil ) then
		b7 = 0;
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("b7 = "..b7);
--end
	b8 = tablo[8];
	if ( b8 == nil ) then
		b8 = 0;
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("b8 = "..b8);
--end
	b41 = tablo[41];
	if ( b41 == nil ) then
		b41 = 0;
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("b41 = "..b41);
--end
	b42 = tablo[42];
	if ( b42 == nil ) then
		b42 = 0;
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("b42 = "..b42);
--end
	a_7_8 = a7;
	if ( a8 > a_7_8 ) then
		a_7_8 = a8;
	end
	b_7_8 = b7;
	if ( b8 > b_7_8 ) then
		b_7_8 = b8;
	end
	a_8_41 = a8;
	if ( a41 > a_8_41 ) then
		a_8_41 = a41;
	end
	b_8_41 = b8;
	if ( b41 > b_8_41 ) then
		b_8_41 = b41;
	end
	a_41_42 = a41;
	if ( a42 > a_41_42 ) then
		a_41_42 = a42;
	end
	b_41_42 = b41;
	if ( b42 > b_41_42 ) then
		b_41_42 = b42;
	end
	a_7_8_42 = a7;
	if ( a8 > a_7_8_42 ) then
		a_7_8_42 = a8;
	end
	if ( a42 > a_7_8_42 ) then
		a_7_8_42 = a42;
	end
	b_7_8_42 = b7;
	if ( b8 > b_7_8_42 ) then
		b_7_8_42 = b8;
	end
	if ( b42 > b_7_8_42 ) then
		b_7_8_42 = b42;
	end
	a_7_8_41_42 = a7;
	if ( a8 > a_7_8_41_42 ) then
		a_7_8_41_42 = a8;
	end
	if ( a41 > a_7_8_41_42 ) then
		a_7_8_41_42 = a41;
	end
	if ( a42 > a_7_8_41_42 ) then
		a_7_8_41_42 = a42;
	end
	b_7_8_41_42 = b7;
	if ( b8 > b_7_8_41_42 ) then
		b_7_8_41_42 = b8;
	end
	if ( b41 > b_7_8_41_42 ) then
		b_7_8_41_42 = b41;
	end
	if ( b42 > b_7_8_41_42 ) then
		b_7_8_41_42 = b42;
	end

--	if ( a7 == 0 and a8 == 0 and a41 == 0 and a42 > 0 ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("quete louche : "..inumquete.." = "..tablo[0]);
--end
--	end
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
TraceFrame:AddMessage("a7 > b7 = "..a7.." > "..b7);
end
	if ( b7 == 0 and a7 > b7 ) then
		bmodifdate0 = true;
	end
end
	if ( a7 >= b7 ) then
		tablo[7] = a7;
--				[-2]	=	nivquete pour link
		tablo[-2] = tabloquete[-2];
--				[1]	=	objectif texte
		tablo[1] = tabloquete[1];
--				[20]	=	catégorie de la quete
		tablo[20] = tabloquete[20];
--				[21]	=	type de la quete ( tag )
		tablo[21] = tabloquete[21];
--				[23]	=	{}	type du sous objectif
--						[1] = type
--						[2] = type
		if ( tabloquete[23] ) then
			if ( tablo[23] == nil ) then
				tablo[23] = {};
			end
			for i = 1 , table.getn(tabloquete[23]) do
				tablo[23][i] = tabloquete[23][i];
			end
		end
--				[27]	=	quete partageable : nil ou 0 ou 1
		if ( tabloquete[27] ) then
			if ( tabloquete[27] == 1 ) then
				tablo[27] = 1;
			elseif ( tabloquete[27] == 0 ) then
				tablo[27] = 0;
			else
				tablo[27] = nil;
			end
		else
			tablo[27] = nil;
		end
--				[28]	=	quete journalière
		if ( tabloquete[28] ) then
			if ( tabloquete[28] == 1 ) then
				tablo[28] = 1;
			else
				if ( tablo[28] and tablo[28] == 1 ) then
				else
					tablo[28] = nil;
				end
			end
		else
			if ( tablo[28] and tablo[28] == 1 ) then
			else
				tablo[28] = nil;
			end
		end
--				[29]	=	nb joueurs conseillé
		if ( tabloquete[29] ) then
			if ( tabloquete[29] > 0 ) then
				tablo[29] = tabloquete[29];
			else
				tablo[29] = nil;
			end
		else
			tablo[29] = nil;
		end
	end
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
TraceFrame:AddMessage("a8 > b8 = "..a8.." > "..b8);
end
	if ( b8 == 0 and a8 > b8 ) then
		bmodifdate0 = true;
	end
end
	if ( a8 >= b8 ) then
		tablo[8] = a8;
--				[5]	=	{}	donneurs quete
--						[nomdonneur]	=	0
		if ( tabloquete[46] and tabloquete[46][1] ) then
			if ( tablo[46] == nil ) then
				tablo[46] = {};
			end
			if ( tablo[46][2] ) then
				if ( tabloquete[46][2] ) then
					if ( tablo[46][2] < tabloquete[46][2] ) then
						tablo[46][1] = tabloquete[46][1];
						tablo[46][2] = tabloquete[46][2];
					end
				end
			else
				tablo[46][1] = tabloquete[46][1];
				tablo[46][2] = tabloquete[46][2];
			end
			tablo[5] = nil;
		elseif ( tabloquete[5] ) then
			if ( tablo[5] == nil ) then
				tablo[5] = {};
			end
			for snomdonneur, _ in pairs(tabloquete[5]) do
				if ( tablo[5][snomdonneur] ) then
					if ( tabloquete[5][snomdonneur] > tablo[5][snomdonneur] ) then
						tablo[5][snomdonneur] = tabloquete[5][snomdonneur];
					end
				else
					tablo[5][snomdonneur] = tabloquete[5][snomdonneur];
				end
			end
		end
--				[24]	=	{}	quetes précédentes
						--	[numquete] = 0;
		if ( tabloquete[24] ) then
			if ( tablo[24] == nil ) then
				tablo[24] = {};
			end
			for inumqueteprec, _ in pairs(tabloquete[24]) do
				if ( tablo[24][inumqueteprec] ) then
					if ( tabloquete[24][inumqueteprec] > tablo[24][inumqueteprec] ) then
						tablo[24][inumqueteprec] = tabloquete[24][inumqueteprec];
					end
				else
					tablo[24][inumqueteprec] = tabloquete[24][inumqueteprec];
				end
			end
		end
	end
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
TraceFrame:AddMessage("a41 > b41 = "..a41.." > "..b41);
end
	if ( b41 == 0 and a41 > b41 ) then
		bmodifdate0 = true;
	end
end
	if ( a41 >= b41 ) then
		tablo[41] = a41;
--				[9]	=	progress texte
		tablo[9] = tabloquete[9];
	end
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
TraceFrame:AddMessage("a42 > b42 = "..a42.." > "..b42);
end
	if ( b42 == 0 and a42 > b42 ) then
		bmodifdate0 = true;
	end
end
	if ( a42 >= b42 ) then
		tablo[42] = a42;
--				[17]	=	complete texte
		tablo[17] = tabloquete[17];
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("a_7_8 > b_7_8 = "..a_7_8.." > "..b_7_8);
--end
	if ( a_7_8 >= b_7_8 ) then
--				[4]	=	description texte
		tablo[4] = tabloquete[4];
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("a_8_41 > b_8_41 = "..a_8_41.." > "..b_8_41);
--end
	if ( a_8_41 >= b_8_41 ) then
--				[10]	=	salaire requis
		tablo[10] = tabloquete[10];
--				[14]	=	{}	objets requis
--						[12038] = 3
--						[505] =1
		if ( tabloquete[14] ) then
			if ( tablo[14] == nil ) then
				tablo[14] = {};
			end
			for inumobjet, _ in pairs(tabloquete[14]) do
				tablo[14][inumobjet] = tabloquete[14][inumobjet];
			end
		end
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("a_41_42 > b_41_42 = "..a_41_42.." > "..b_41_42);
--end
	if ( a_41_42 >= b_41_42 ) then
--				[6]	=	{}	finisseurs quete
--						[nomfinisseur]	=	0
		if ( tabloquete[47] and tabloquete[47][1] ) then
			if ( tablo[47] == nil ) then
				tablo[47] = {};
			end
			if ( tablo[47][2] ) then
				if ( tabloquete[47][2] ) then
					if ( tablo[47][2] < tabloquete[47][2] ) then
						tablo[47][1] = tabloquete[47][1];
						tablo[47][2] = tabloquete[47][2];
					end
				end
			else
				tablo[47][1] = tabloquete[47][1];
				tablo[47][2] = tabloquete[47][2];
			end
			tablo[6] = nil;
		elseif ( tabloquete[6] ) then
			if ( tablo[6] == nil ) then
				tablo[6] = {};
			end
			for snomfinisseur, _ in pairs(tabloquete[6]) do
				if ( tablo[6][snomfinisseur] ) then
					if ( tabloquete[6][snomfinisseur] > tablo[6][snomfinisseur] ) then
						tablo[6][snomfinisseur] = tabloquete[6][snomfinisseur];
					end
				else
					tablo[6][snomfinisseur] = tabloquete[6][snomfinisseur];
				end
			end
		end
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("a_7_8_42 > b_7_8_42 = "..a_7_8_42.." > "..b_7_8_42);
--end
	if ( a_7_8_42 >= b_7_8_42 ) then
--				[11]	=	salaire recompense < DBCS_nivmax ( 60 ) ( 70 )
--				[12]	=	salaire recompense pour DBCS_nivmax ( 60 ) ( 70 )
		if ( tabloquete[11] and tabloquete[11] > 0 ) then
			tablo[11] = tabloquete[11];
		end
		if ( tabloquete[12] and tabloquete[12] > 0 ) then
			tablo[12] = tabloquete[12];
		end
		if ( tabloquete[45] and tabloquete[45] > 0 ) then
			tablo[45] = tabloquete[45];
		end
		--DBCS_nivmax_CT
		if ( tabloquete[48] and tabloquete[48] > 0 ) then
			tablo[48] = tabloquete[48];
		end
		--DBCS_nivmax_MOP
		if ( tabloquete[49] and tabloquete[49] > 0 ) then
			tablo[49] = tabloquete[49];
		end
--				[15]	=	{}	objets obtenus
--						[12038] = 3
--						[505] =1
		if ( tabloquete[15] ) then
			if ( tablo[15] == nil ) then
				tablo[15] = {};
			end
			for inumobjet, _ in pairs(tabloquete[15]) do
				tablo[15][inumobjet] = tabloquete[15][inumobjet];
			end
		end
--				[16]	=	{}	objets à choisir
--						[12038] = 3
--						[505] =1
		if ( tabloquete[16] ) then
			if ( tablo[16] == nil ) then
				tablo[16] = {};
			end
			for inumobjet, _ in pairs(tabloquete[16]) do
				tablo[16][inumobjet] = tabloquete[16][inumobjet];
			end
		end
	end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("a_7_8_41_42 > b_7_8_41_42 = "..a_7_8_41_42.." > "..b_7_8_41_42);
--end
	if ( a_7_8_41_42 >= b_7_8_41_42 ) then
--				[2]	=	niv min
		if ( tabloquete[2] == nil ) then
			tabloquete[2] = -1;
		end
		if ( tablo[2] ) then
			if ( tabloquete[2] > -1 ) then
				if ( tablo[2] == -1 ) then
					tablo[2] = tabloquete[2];
				else
					if ( tabloquete[2] < tablo[2] ) then
						tablo[2] = tabloquete[2];
					end
				end
			end
		else
			tablo[2] = tabloquete[2];
		end
--				[3]	=	niv conseil
		if ( tabloquete[3] == nil ) then
			tabloquete[3] = -1;
		end
		if ( tablo[3] ) then
			if ( tabloquete[3] > -1 ) then
				if ( tablo[3] == -1 ) then
					tablo[3] = tabloquete[3];
				else
					if ( tabloquete[3] < tablo[3] ) then
						tablo[3] = tabloquete[3];
					end
				end
			end
		else
			tablo[3] = tabloquete[3];
		end
		if ( tablo[2] > tablo[3] ) then
			tablo[2] = tablo[3];
		end
		if ( tablo[2] == -1 and tablo[3] > -1 ) then
			tablo[2] = tablo[3];
		end
--				[26]	=	catégorie temporaire de la quete
		if ( tablo[20] ) then
			if ( tablo[20] == "" ) then
				tablo[26] = tabloquete[26];
			else
				tablo[26] = "#";
			end
		else
			tablo[26] = tabloquete[26];
		end
	end
--				[18]	=	1	=	alliance
	if ( tabloquete[18] and tabloquete[18] == 1 ) then
		tablo[18] = 1;
	else
		--tablo[18] = nil;
	end
--				[19]	=	1	=	horde
	if ( tabloquete[19] and tabloquete[19] == 1 ) then
		tablo[19] = 1;
	else
		--tablo[19] = nil;
	end
--				[25]	=	{}	quetes suivantes
						--	[numquete] = 0;
	if ( tabloquete[25] ) then
		if ( tablo[25] == nil ) then
			tablo[25] = {};
		end
		for inumquetesuiv, _ in pairs(tabloquete[25]) do
			if ( tablo[25][inumquetesuiv] ) then
				if ( tabloquete[25][inumquetesuiv] > tablo[25][inumquetesuiv] ) then
					tablo[25][inumquetesuiv] = tabloquete[25][inumquetesuiv];
				end
			else
				tablo[25][inumquetesuiv] = tabloquete[25][inumquetesuiv];
			end
		end
	end
	
	DBquetes2[inumquete] = tablo;
	
	return bmodifdate0;

--				[13]	=	quete validée : ne plus l'envoyer tous les jours
--				[22]	=	{}	texte du sous objectif
--						[1] = texte
--						[2] = texte
--				[30]	=	nb obj link
end

function DBquetes2_OnEvent(self,event,...)

--local nomquete;
--local objectif;
local inumquete;
local inbquetes;
local i;
local j;
local nomdonneur;
local nomfinisseur;
local itypedegroupe;
local x;
local y;
local numRequiredItems;
local numQuestRewards;
local numQuestChoices;
local iniv;
local tq_activelist;
local tq_availablelist;
local nb;
local numAvailableQuests;
local numActiveQuests;
local inivmin;
--local don;
local money;
local szone;
local ival1;
local sval2;
local inumobjet;
local nbobjets;
local sitem;
local ibon;
local iindex;
local questLogTitleText;
local level;
local isHeader;
local slink;
local snumitemcourt;
local snumitemlong;
local ipos;
local isHeader;
local isCollapsed;
local sdebut;
local saddon;
local ssuite;
local sgetlocale;
local sGUID;
local snom;
local tquete_completed;
local tquete_completed_val1;
local tquete_completed_val2;
local idate;
local idateancien;
local slangue;

local arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9 = ...;

	if ( event == "" ) then
	elseif ( event == "CHAT_MSG_CHANNEL" ) then
		if ( DBCS_CMS_numcanalCMS > 0 ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBCS_CMS_numcanalCMS = "..DBCS_CMS_numcanalCMS);
--end
			if ( arg9 and strlower(arg9) == DBCS_CMS_NOMCANAL ) then
				sdebut = strsub(arg1,1,2);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("sdebut = "..(sdebut or ""));
--end
				if ( sdebut and sdebut == "@A" ) then
					ipos = strfind(arg1,"@",3);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("ipos = "..(ipos or ""));
--end
					if ( ipos ) then
						saddon = strsub(arg1,3,ipos-1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("saddon = "..(saddon or ""));
--end
						if ( saddon == "DBQS" ) then
							ssuite = strsub(arg1,ipos+1);
							ipos = strfind(ssuite,"@",1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("ipos = "..(ipos or ""));
--end
							if ( ipos ) then
								sgetlocale = strsub(ssuite,1,ipos-1);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("sgetlocale = "..(sgetlocale or ""));
--end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBCS_getlocale = "..(DBCS_getlocale or ""));
--end
								if ( sgetlocale == DBCS_getlocale ) then
									ssuite = strsub(ssuite,ipos+1);
									DBQS2_traitermessagecms(arg2,ssuite);
								end
							end
						--elseif ( saddon == "DBPS" ) then
						--	DBQS_traitermessagecms(arg2,ssuite);
						end
					end
				end
			end
		end
	elseif ( event == "GOSSIP_SHOW" ) then
		DBquetes2_liregossip();
	elseif ( event == "PLAYER_ENTERING_WORLD") then
		if ( DBQS2_bquestcompleted == false ) then
			--QueryQuestsCompleted();	--20120829
			DBQS2_bquestcompleted = true;
		end
	elseif ( event == "QUEST_COMPLETE" ) then
		DBQS2_event = event;
		DBquetes2_tempo_complete = {};
		DBquetes2_tempo_complete_numquete = 0;
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("QUEST_COMPLETE1 DBquetes2_tempo_complete_numquete = "..( DBquetes2_tempo_complete_numquete or "" ));
--end
		nomfinisseur = QuestFrameNpcNameText:GetText();
		snom = UnitName("target");
		sGUID = UnitGUID("target");
		szone = GetRealZoneText();
		if ( nomfinisseur ) then
			DBquetes2_tempo_complete[6] = nomfinisseur;
--TraceFrame:AddMessage("---DBquetes2_tempo_complete[6] : "..DBquetes2_tempo_complete[6]);
			x,y = DBCS_position100();
			DBPS2_enregpnj(nomfinisseur,DBCS_Region_liste_code_region_courante_new(),x,y,1);
			if ( snom and nomfinisseur == snom ) then
				--if ( DBCS_quetes2_wow_build > DBCS_quetes2_wow_build_live ) then
					DBquetes2_tempo_complete[47] = tonumber(strsub(sGUID,6,10),16);
				--else
				--	DBquetes2_tempo_complete[47] = tonumber(strsub(sGUID,9,12),16);
				--end
			end
		end
		DBquetes2_tempo_complete[0] = GetTitleText();
--TraceFrame:AddMessage("---DBquetes2_tempo_complete[0] : "..DBquetes2_tempo_complete[0]);
		DBquetes2_tempo_complete[2] = UnitLevel("Player");
--TraceFrame:AddMessage("---DBquetes2_tempo_complete[2] : "..DBquetes2_tempo_complete[2]);
		j = 0;
		nb, _ = GetNumQuestLogEntries();	--	nbquetes
		for i = 1 , nb do
			questLogTitleText, level, _, _, isHeader, _, _, _ = GetQuestLogTitle(i);
			if ( isHeader ) then
			else
				slink = GetQuestLink(i);
				if ( slink ) then
					_, snumitemcourt, _, _, _ = DBQS2_GetMotItem(slink);
					ipos = strfind(snumitemcourt,":");
					if ( ipos ) then
						inumquete = tonumber(strsub(snumitemcourt,1,ipos-1));
						if ( DBquetes2_tempo_complete[0] and DBquetes2 and DBquetes2[inumquete] and DBquetes2[inumquete][0] and DBquetes2[inumquete][0] == DBquetes2_tempo_complete[0] ) then
							j = j + 1;
--TraceFrame:AddMessage("---j : "..j);
							DBquetes2_tempo_complete_numquete = inumquete;
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("QUEST_COMPLETE2 DBquetes2_tempo_complete_numquete = "..( DBquetes2_tempo_complete_numquete or "" ));
--end
--TraceFrame:AddMessage("---inumquete : "..inumquete);
							DBquetes2_tempo_complete[3] = level;
--TraceFrame:AddMessage("---DBquetes2_tempo_complete[3] : "..DBquetes2_tempo_complete[3]);
						elseif ( questLogTitleText and DBquetes2_tempo_complete[0] and questLogTitleText == DBquetes2_tempo_complete[0] ) then
							j = j + 1;
--TraceFrame:AddMessage("---j : "..j);
							DBquetes2_tempo_complete_numquete = inumquete;
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("QUEST_COMPLETE3 DBquetes2_tempo_complete_numquete = "..( DBquetes2_tempo_complete_numquete or "" ));
--end
--TraceFrame:AddMessage("---inumquete : "..inumquete);
							DBquetes2_tempo_complete[3] = level;
--TraceFrame:AddMessage("---DBquetes2_tempo_complete[3] : "..DBquetes2_tempo_complete[3]);
						end
					end
				end
			end
		end
		if ( j == 1 ) then
		else
			DBquetes2_tempo_complete_numquete = 0;
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("QUEST_COMPLETE4 DBquetes2_tempo_complete_numquete = "..( DBquetes2_tempo_complete_numquete or "" ));
--end
			DBquetes2_tempo_complete[3] = nil;
		end
		--	3
		if ( DBquetes2_tempo_complete[3] == nil ) then
			tq_activelist = {GetGossipActiveQuests()};
			--nb = table.getn(tq_activelist)/3;
			nb = 0;
			for ival1, sval2 in pairs(tq_activelist) do
				if ( ival1 > nb ) then
					nb = ival1;
				end
			end
			nb = nb/3;
			if ( floor(nb) == nb ) then
			else
				nb = floor(nb) + 1;
			end
			for i = 1, nb do
				if ( tq_activelist[((i-1)*3)+1] == DBquetes2_tempo_complete[0] ) then
					DBquetes2_tempo_complete[3] = tq_activelist[((i-1)*3)+2];
--TraceFrame:AddMessage("---DBquetes2_tempo_complete[3] : "..DBquetes2_tempo_complete[3]);
				end
			end
		end
		if ( DBquetes2_tempo_complete[3] == nil ) then
			tq_availablelist = {GetGossipAvailableQuests()};
			--nb = table.getn(tq_availablelist)/3;
			nb = 0;
			for ival1, sval2 in pairs(tq_availablelist) do
				if ( ival1 > nb ) then
					nb = ival1;
				end
			end
			nb = nb/3;
			if ( floor(nb) == nb ) then
			else
				nb = floor(nb) + 1;
			end
			for i = 1, nb do
				if ( tq_availablelist[((i-1)*3)+1] == DBquetes2_tempo_complete[0] ) then
					DBquetes2_tempo_complete[3] = tq_availablelist[((i-1)*3)+2];
--TraceFrame:AddMessage("---DBquetes2_tempo_complete[3] : "..DBquetes2_tempo_complete[3]);
				end
			end
		end
		if ( DBquetes2_tempo_complete[3] == nil ) then
			numActiveQuests = GetNumActiveQuests();
			for i = 1 , numActiveQuests do
				if ( GetActiveTitle(i) == DBquetes2_tempo_complete[0] ) then
					DBquetes2_tempo_complete[3] = GetActiveLevel(i);
--TraceFrame:AddMessage("---DBquetes2_tempo_complete[3] : "..DBquetes2_tempo_complete[3]);
				end
			end
		end
		if ( DBquetes2_tempo_complete[3] == nil ) then
			numAvailableQuests = GetNumAvailableQuests();
			for i = 1 , numAvailableQuests do
				if ( GetAvailableTitle(i) == DBquetes2_tempo_complete[0] ) then
					DBquetes2_tempo_complete[3] = GetAvailableLevel(i);
--TraceFrame:AddMessage("---DBquetes2_tempo_complete[3] : "..DBquetes2_tempo_complete[3]);
				end
			end
		end
		money = GetRewardMoney();
		if ( money > 0 ) then
			--if ( DBQS2_WOTLK == false ) then
			--	if ( UnitLevel("Player") < DBCS_nivmax ) then
			--		DBquetes2_tempo_complete[11] = money;
			--	else
			--		DBquetes2_tempo_complete[12] = money;
			--	end
			--else
				--if ( UnitLevel("Player") < DBCS_nivmax_wotlk ) then
				--if ( UnitLevel("Player") < DBCS_nivmax_CT ) then
				if ( UnitLevel("Player") < DBCS_nivmax_MOP ) then
					DBquetes2_tempo_complete[11] = money;
				else
					DBquetes2_tempo_complete[49] = money;
				end
			--end
		end
		ibon = 1;
		numQuestRewards = GetNumQuestRewards();
--TraceFrame:AddMessage("---objets reward : "..numQuestRewards);
		if ( numQuestRewards > 0 ) then
			if ( DBquetes2_tempo_complete[15] == nil ) then
				DBquetes2_tempo_complete[15] = {};
			end
			for i = 1 , numQuestRewards , 1 do
				inumobjet = 0;
				_, _, nbobjets, _, _ = GetQuestItemInfo("reward", i);	--	"required" "reward" "choice" 
				sitem = GetQuestItemLink("reward", i);	--	item:12345:0:0:0
				if ( sitem and nbobjets ) then
					for a, _, _, _, _, _, _, _, _, _ in string.gmatch(sitem,"item:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)") do	-- %p?
						inumobjet = tonumber(a);
--TraceFrame:AddMessage("---inumobjet : "..inumobjet.." pour "..nbobjets.." fois.");
						if ( DBquetes2_tempo_complete[15][inumobjet] == nil ) then
							DBquetes2_tempo_complete[15][inumobjet] = nbobjets;
						end
					end
				else
					ibon = 0;
				end
				if ( inumobjet == 0 ) then
--TraceFrame:AddMessage("---manque objet i : "..i);
				end
			end
		end
		numQuestChoices = GetNumQuestChoices();
--TraceFrame:AddMessage("---objets choix : "..numQuestChoices);
		if ( numQuestChoices > 0 ) then
			if ( DBquetes2_tempo_complete[16] == nil ) then
				DBquetes2_tempo_complete[16] = {};
			end
			for i = 1 , numQuestChoices , 1 do
				inumobjet = 0;
				_, _, nbobjets, _, _ = GetQuestItemInfo("choice", i);	--	"required" "reward" "choice" 
				sitem = GetQuestItemLink("choice", i);	--	item:12345:0:0:0
				if ( sitem and nbobjets ) then
					for a, _, _, _, _, _, _, _, _, _ in string.gmatch(sitem,"item:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)") do	-- %p?
						inumobjet = tonumber(a);
--TraceFrame:AddMessage("---inumobjet : "..inumobjet.." pour "..nbobjets.." fois.");
						if ( DBquetes2_tempo_complete[16][inumobjet] == nil ) then
							DBquetes2_tempo_complete[16][inumobjet] = nbobjets;
						end
					end
				else
					ibon = 0;
				end
				if ( inumobjet == 0 ) then
--TraceFrame:AddMessage("---manque objet i : "..i);
				end
			end
		end
		DBquetes2_tempo_complete[17] = GetRewardText();
--TraceFrame:AddMessage("---DBquetes2_tempo_complete[17] : "..DBquetes2_tempo_complete[17]);
		DBquetes2_tempo_complete[18], _ = UnitFactionGroup("player");
--TraceFrame:AddMessage("---DBquetes2_tempo_complete[18] : "..DBquetes2_tempo_complete[18]);
		DBquetes2_tempo_complete[26] = szone;	-- catégorie temporaire

		--	0
		--	2
		--	3
		--	6
		--	11
		--	12
		--	15
		--	16
		--	17
		--	18
		--	19
--TraceFrame:AddMessage("---ibon : "..ibon);
		if ( ibon == 1 ) then
			DBQS2_event = nil;
			DBQS2_enreg_complete();
		end
	elseif ( event == "QUEST_DETAIL" ) then
		local questPortrait, questPortraitText = GetQuestPortraitGiver();
--TraceFrame:AddMessage("QUEST_DETAIL0 , questPortrait = "..( questPortrait or "" )..", questPortraitText = "..( questPortraitText or "" ));
		DBQS2_event = event;
		if ( DBquetes2_timeprec > 0 ) then
			if ( (GetTime() - DBquetes2_timeprec) <= 1 ) then
				DBquetes2_timeprec = 0;
			else
				DBquetes2_inumqueteprec = nil;
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("QUEST_DETAIL1 , DBquetes2_inumqueteprec = "..( DBquetes2_inumqueteprec or "" ));
--end
				DBquetes2_timeprec = 0;
			end
		else
			DBquetes2_inumqueteprec = nil;
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("QUEST_DETAIL2 , DBquetes2_inumqueteprec = "..( DBquetes2_inumqueteprec or "" ));
--end
		end
		DBquetes2_tempo_detail = {};
		DBquetes2_tempo_detail_numquete = 0;
--/script DEFAULT_CHAT_FRAME:AddMessage(GetGossipText())
		nomdonneur = QuestFrameNpcNameText:GetText();
		snom = UnitName("target");
		sGUID = UnitGUID("target");
		szone = GetRealZoneText();
		itypedegroupe = DBCS_typedegroupe();
		if ( itypedegroupe == 1 ) then
			for i = 1, GetNumSubgroupMembers() do	--GetNumPartyMembers() do
				if ( nomdonneur and UnitName("party"..i) == nomdonneur ) then
--TraceFrame:AddMessage(nomdonneur.." est un membre de mon groupe.");
					nomdonneur = nil;
				end
			end
		elseif ( itypedegroupe == 2 ) then
			for i = 1 , 40 do	--GetNumRaidMembers() do	--20120829
				sjoueur, _, _, _, _, _, _, _, _ = GetRaidRosterInfo(i);
				if ( nomdonneur and sjoueur and sjoueur == nomdonneur ) then
--TraceFrame:AddMessage(nomdonneur.." est un membre de mon raid.");
					nomdonneur = nil;
				end
			end
		end
		if ( nomdonneur ) then
			DBquetes2_tempo_detail[5] = nomdonneur;
			x,y = DBCS_position100();
			DBPS2_enregpnj(nomdonneur,DBCS_Region_liste_code_region_courante_new(),x,y,1);
			if ( snom and nomdonneur == snom ) then
				--if ( DBCS_quetes2_wow_build > DBCS_quetes2_wow_build_live ) then
					DBquetes2_tempo_detail[46] = tonumber(strsub(sGUID,6,10),16);
				--else
				--	DBquetes2_tempo_detail[46] = tonumber(strsub(sGUID,9,12),16);
				--end
			end
--		snom = MerchantNameText:GetText();
--TraceFrame:AddMessage("MERCHANT_SHOW : snom = "..(snom or ""));
--		if ( snom == UnitName("target") ) then
--			if ( sGUID and ( strsub(sGUID,1,5) == "0xF13" or strsub(sGUID,1,5) == "0xF15" or strsub(sGUID,1,5) == "0xF53" or strsub(sGUID,1,5) == "0xF55" ) ) then
--				sGUID_7_10 = strsub(sGUID,9,12);
--				iGUID_7_10 = tonumber(sGUID_7_10,16);
		end
		DBquetes2_tempo_detail[0] = GetTitleText();
		DBquetes2_tempo_detail[1] = GetObjectiveText();
		DBquetes2_tempo_detail[4] = GetQuestText();

		iniv = nil;
--/script DEFAULT_CHAT_FRAME:AddMessage(table.getn({GetGossipAvailableQuests()}));
		tq_availablelist = nil;
		tq_availablelist = {GetGossipAvailableQuests()};
		nb = 0;
		for ival1, sval2 in pairs(tq_availablelist) do
--TraceFrame:AddMessage("ival1 = "..ival1);
--TraceFrame:AddMessage("sval2 = "..sval2);
			if ( ival1 > nb ) then
				nb = ival1;
			end
		end
		nb = nb/3;
		if ( floor(nb) == nb ) then
		else
			nb = floor(nb) + 1;
		end
--TraceFrame:AddMessage("nb = "..nb);
		for i = 1, nb do
--TraceFrame:AddMessage(tq_availablelist[((i-1)*3)+1]);
			if ( tq_availablelist[((i-1)*3)+1] == DBquetes2_tempo_detail[0] ) then
				iniv = tq_availablelist[((i-1)*3)+2];
			end
		end
		if ( iniv == nil ) then
--/script DEFAULT_CHAT_FRAME:AddMessage(table.getn({GetNumAvailableQuests()}));
			numAvailableQuests = GetNumAvailableQuests();
--TraceFrame:AddMessage("numAvailableQuests = "..numAvailableQuests);
			for i = 1 , numAvailableQuests do
--TraceFrame:AddMessage(GetAvailableTitle(i));
				if ( GetAvailableTitle(i) == DBquetes2_tempo_detail[0] ) then
					iniv = GetAvailableLevel(i);
				end
			end
		end
		if ( iniv ) then
			DBquetes2_tempo_detail[3] = iniv;
		end
		inivmin = UnitLevel("Player");
		if ( iniv ) then
			if ( iniv < inivmin ) then
				inivmin = iniv;
			end
		end
		DBquetes2_tempo_detail[2] = inivmin;

		DBquetes2_tempo_detail[10] = GetQuestMoneyToGet();
--TraceFrame:AddMessage("---argent a donner : "..don);

		money = GetRewardMoney();
		if ( money > 0 ) then
			--if ( DBQS2_WOTLK == false ) then
			--	if ( UnitLevel("Player") < DBCS_nivmax ) then
			--		DBquetes2_tempo_detail[11] = money;
			--	else
			--		DBquetes2_tempo_detail[12] = money;
			--	end
			--else
				--if ( UnitLevel("Player") < DBCS_nivmax_wotlk ) then
				--if ( UnitLevel("Player") < DBCS_nivmax_CT ) then
				if ( UnitLevel("Player") < DBCS_nivmax_MOP ) then
					DBquetes2_tempo_detail[11] = money;
				else
					DBquetes2_tempo_detail[49] = money;
				end
			--end
		end

		DBquetes2_tempo_detail[26] = szone;	-- catégorie temporaire

		ibon = 1;
		numRequiredItems = GetNumQuestItems();
		numQuestRewards = GetNumQuestRewards();
		numQuestChoices = GetNumQuestChoices();
--TraceFrame:AddMessage("---objets requis : "..numRequiredItems);
		if ( numRequiredItems > 0 ) then
			if ( DBquetes2_tempo_detail[14] == nil ) then
				DBquetes2_tempo_detail[14] = {};
			end
			for i = 1 , numRequiredItems , 1 do
				inumobjet = 0;
				_, _, nbobjets, _, _ = GetQuestItemInfo("required", i);	--	"required" "reward" "choice" 
				sitem = GetQuestItemLink("required", i);	--	item:12345:0:0:0
				if ( sitem and nbobjets ) then
					for a, _, _, _, _, _, _, _, _, _ in string.gmatch(sitem,"item:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)") do	-- %p?
						inumobjet = tonumber(a);
--TraceFrame:AddMessage("---inumobjet : "..inumobjet.." pour "..nbobjets.." fois.");
						if ( DBquetes2_tempo_detail[14][inumobjet] == nil ) then
							DBquetes2_tempo_detail[14][inumobjet] = nbobjets;
						end
					end
				else
					ibon = 0;
				end
				if ( inumobjet == 0 ) then
--TraceFrame:AddMessage("---manque objet i : "..i);
				end
			end
		end
--TraceFrame:AddMessage("---objets obtenus : "..numQuestRewards);
		if ( numQuestRewards > 0 ) then
			if ( DBquetes2_tempo_detail[15] == nil ) then
				DBquetes2_tempo_detail[15] = {};
			end
			for i = 1 , numQuestRewards , 1 do
				inumobjet = 0;
				_, _, nbobjets, _, _ = GetQuestItemInfo("reward", i);	--	"required" "reward" "choice" 
				sitem = GetQuestItemLink("reward", i);	--	item:12345:0:0:0
				if ( sitem and nbobjets ) then
					for a, _, _, _, _, _, _, _, _, _ in string.gmatch(sitem,"item:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)") do
						inumobjet = tonumber(a);
--TraceFrame:AddMessage("---inumobjet : "..inumobjet.." pour "..nbobjets.." fois.");
						if ( DBquetes2_tempo_detail[15][inumobjet] == nil ) then
							DBquetes2_tempo_detail[15][inumobjet] = nbobjets;
						end
					end
				else
					ibon = 0;
				end
				if ( inumobjet == 0 ) then
--TraceFrame:AddMessage("---manque objet i : "..i);
				end
			end
		end
--TraceFrame:AddMessage("---objets a choisir : "..numQuestChoices);
		if ( numQuestChoices > 0 ) then
			if ( DBquetes2_tempo_detail[16] == nil ) then
				DBquetes2_tempo_detail[16] = {};
			end
			for i = 1 , numQuestChoices , 1 do
				inumobjet = 0;
				_, _, nbobjets, _, _ = GetQuestItemInfo("choice", i);	--	"required" "reward" "choice" 
				sitem = GetQuestItemLink("choice", i);	--	item:12345:0:0:0
				if ( sitem and nbobjets ) then
					for a, _, _, _, _, _, _, _, _, _ in string.gmatch(sitem,"item:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)") do
						inumobjet = tonumber(a);
--TraceFrame:AddMessage("---inumobjet : "..inumobjet.." pour "..nbobjets.." fois.");
						if ( DBquetes2_tempo_detail[16][inumobjet] == nil ) then
							DBquetes2_tempo_detail[16][inumobjet] = nbobjets;
						end
					end
				else
					ibon = 0;
				end
				if ( inumobjet == 0 ) then
--TraceFrame:AddMessage("---manque objet i : "..i);
				end
			end
		end
		DBquetes2_tempo_detail[18], _ = UnitFactionGroup("player");

--TraceFrame:AddMessage("DBquetes2_tempo_detail  0 = "..( DBquetes2_tempo_detail[0] or ""));
--TraceFrame:AddMessage("DBquetes2_tempo_detail  1 = "..( DBquetes2_tempo_detail[1] or ""));
--TraceFrame:AddMessage("DBquetes2_tempo_detail  2 = "..( DBquetes2_tempo_detail[2] or ""));
--TraceFrame:AddMessage("DBquetes2_tempo_detail  3 = "..( DBquetes2_tempo_detail[3] or ""));
--TraceFrame:AddMessage("DBquetes2_tempo_detail  4 = "..( DBquetes2_tempo_detail[4] or ""));
--TraceFrame:AddMessage("DBquetes2_tempo_detail  5 = "..( DBquetes2_tempo_detail[5] or ""));
--TraceFrame:AddMessage("DBquetes2_tempo_detail 10 = "..( DBquetes2_tempo_detail[10] or ""));
--TraceFrame:AddMessage("DBquetes2_tempo_detail 11 = "..( DBquetes2_tempo_detail[11] or ""));
--TraceFrame:AddMessage("DBquetes2_tempo_detail 12 = "..( DBquetes2_tempo_detail[12] or ""));
--TraceFrame:AddMessage("DBquetes2_tempo_detail 18 = "..( DBquetes2_tempo_detail[18] or ""));
--TraceFrame:AddMessage("DBquetes2_tempo_detail 19 = "..( DBquetes2_tempo_detail[19] or ""));
--TraceFrame:AddMessage("DBquetes2_tempo_detail 26 = "..( DBquetes2_tempo_detail[26] or ""));
--TraceFrame:AddMessage("----------------------------------------");
--TraceFrame:AddMessage("nom quete : "..DBquetes2_tempo_detail[0]);
		if ( DBQS2_tablo_toutesquetes_par_nometobjectif[DBquetes2_tempo_detail[0]] and DBQS2_tablo_toutesquetes_par_nometobjectif[DBquetes2_tempo_detail[0]][DBquetes2_tempo_detail[1]] ) then
			inbquetes = 0;
			for inumquete, _ in pairs(DBQS2_tablo_toutesquetes_par_nometobjectif[DBquetes2_tempo_detail[0]][DBquetes2_tempo_detail[1]]) do
--TraceFrame:AddMessage("quete : "..inumquete);
				inbquetes = inbquetes + 1;
				DBquetes2_tempo_detail_numquete = inumquete;
			end
			if ( inbquetes == 1 ) then
				if ( DBquetes2_inumqueteprec ) then
					DBquetes2_tempo_detail[24] = DBquetes2_inumqueteprec;
					if ( DBquetes2[DBquetes2_inumqueteprec][25] == nil ) then
						DBquetes2[DBquetes2_inumqueteprec][25] = {};
					end
					DBquetes2[DBquetes2_inumqueteprec][25][DBquetes2_tempo_detail_numquete] = tonumber(DBCS_date());
					DBQS2_envoyerquete(DBquetes2_inumqueteprec);
					-- envoyer quete
				end
			else
				DBquetes2_tempo_detail_numquete = 0;
			end
		else
		end
--TraceFrame:AddMessage("----------------------------------------");

		if ( DBquetes2_tempo_detail_numquete > 0 and ibon == 1 ) then
			DBQS2_event = nil;
			DBQS2_enreg_detail();
		end
	elseif ( event == "QUEST_ITEM_UPDATE" ) then
		if ( DBQS2_event ) then
			event = DBQS2_event;
			DBquetes2_OnEvent();
		end
	elseif ( event == "QUEST_LOG_UPDATE" ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("QUEST_LOG_UPDATE");
--end
		if ( DBQS2_suivi_quetes_time > -1 ) then
			DBQS2_suivi_quetes_time = GetTime();
		end
		-- force que aucunes quetes ne soient cachées
		nb, _ = GetNumQuestLogEntries();	--	nbquetes
		for i = nb , 1, -1 do
			_, _, _, _, isHeader, isCollapsed, _, _ = GetQuestLogTitle(i);
			if ( isHeader ) then
				if ( isCollapsed ) then
					ExpandQuestHeader(i);
				end
			end
		end
		if ( DBQS2_suivi_quetes_time == -1 ) then
			DBQS2_sauvegarder_suivi_quete();
		end
		if ( DBquetes2_tempo_detail ) then
			j = 0;
			nb, _ = GetNumQuestLogEntries();	--	nbquetes
			for i = 1 , nb do
				questLogTitleText, _, _, _, isHeader, _, _, _ = GetQuestLogTitle(i);
				if ( isHeader ) then
				else
					slink = GetQuestLink(i);
					if ( slink ) then
						_, snumitemcourt, _, _, _ = DBQS2_GetMotItem(slink);
						ipos = strfind(snumitemcourt,":");
						if ( ipos ) then
							inumquete = tonumber(strsub(snumitemcourt,1,ipos-1));
							if ( DBquetes2_tempo_detail[0] and DBquetes2 and DBquetes2[inumquete] and DBquetes2[inumquete][0] and DBquetes2[inumquete][0] == DBquetes2_tempo_detail[0] ) then
								j = j + 1;
								DBquetes2_tempo_detail_numquete = inumquete;
							elseif ( questLogTitleText and DBquetes2_tempo_detail[0] and questLogTitleText == DBquetes2_tempo_detail[0] ) then
								j = j + 1;
								DBquetes2_tempo_detail_numquete = inumquete;
							end
						end
					end
				end
			end
			if ( j == 1 ) then
				DBQS2_enreg_detail();
			else
				DBquetes2_tempo_detail_numquete = 0;
			end
		end
		iindex = FauxScrollFrame_GetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame);
		--DBcorps_ListQuetes2_Reset();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("1DBquetes2_OnEvent DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
		--DBcorps_ListQuetes2_Update();
		DBquetes2_quetesencours();
		if ( iindex > (DBCORPS_QUETES2_LISTE_nb-10) ) then
			iindex = DBCORPS_QUETES2_LISTE_nb - 10;
		end
		if ( iindex < 0 ) then
			iindex = 0;
		end
		FauxScrollFrame_SetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame,iindex);
		DBcorpsFrame_Quetes2Frame_Liste_ScrollFrameScrollBar:SetValue(iindex*32);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("1DBquetes2_OnEvent DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
		DBcorps_Quetes2_Scroll_Update();
	elseif ( event == "QUEST_PROGRESS" ) then
		DBQS2_event = event;
		DBquetes2_tempo_progress = {};
		DBquetes2_tempo_progress_numquete = 0;
		nomfinisseur = QuestFrameNpcNameText:GetText();
		snom = UnitName("target");
		sGUID = UnitGUID("target");
		szone = GetRealZoneText();
		if ( nomfinisseur ) then
			DBquetes2_tempo_progress[6] = nomfinisseur;
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[6] : "..DBquetes2_tempo_progress[6]);
			x,y = DBCS_position100();
			DBPS2_enregpnj(nomfinisseur,DBCS_Region_liste_code_region_courante_new(),x,y,1);
			if ( snom and nomfinisseur == snom ) then
				--if ( DBCS_quetes2_wow_build > DBCS_quetes2_wow_build_live ) then
					DBquetes2_tempo_progress[47] = tonumber(strsub(sGUID,6,10),16);
				--else
				--	DBquetes2_tempo_progress[47] = tonumber(strsub(sGUID,9,12),16);
				--end
			end
		end
		DBquetes2_tempo_progress[0] = GetTitleText();
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[0] : "..DBquetes2_tempo_progress[0]);
		DBquetes2_tempo_progress[2] = UnitLevel("Player");
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[2] : "..DBquetes2_tempo_progress[2]);
		j = 0;
		nb, _ = GetNumQuestLogEntries();	--	nbquetes
		for i = 1 , nb do
			questLogTitleText, level, _, _, isHeader, _, _, _ = GetQuestLogTitle(i);
			if ( isHeader ) then
			else
				slink = GetQuestLink(i);
				if ( slink ) then
					_, snumitemcourt, _, _, _ = DBQS2_GetMotItem(slink);
					ipos = strfind(snumitemcourt,":");
					if ( ipos ) then
						inumquete = tonumber(strsub(snumitemcourt,1,ipos-1));
						if ( DBquetes2_tempo_progress[0] and DBquetes2 and DBquetes2[inumquete] and DBquetes2[inumquete][0] and DBquetes2[inumquete][0] == DBquetes2_tempo_progress[0] ) then
							j = j + 1;
--TraceFrame:AddMessage("---j : "..j);
							DBquetes2_tempo_progress_numquete = inumquete;
--TraceFrame:AddMessage("---inumquete : "..inumquete);
							DBquetes2_tempo_progress[3] = level;
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[3] : "..DBquetes2_tempo_progress[3]);
						elseif ( questLogTitleText and DBquetes2_tempo_progress[0] and questLogTitleText == DBquetes2_tempo_progress[0] ) then
							j = j + 1;
--TraceFrame:AddMessage("---j : "..j);
							DBquetes2_tempo_progress_numquete = inumquete;
--TraceFrame:AddMessage("---inumquete : "..inumquete);
							DBquetes2_tempo_progress[3] = level;
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[3] : "..DBquetes2_tempo_progress[3]);
						end
					end
				end
			end
		end
		if ( j == 1 ) then
		else
			DBquetes2_tempo_progress_numquete = 0;
			DBquetes2_tempo_progress[3] = nil;
		end
		--	3
		if ( DBquetes2_tempo_progress[3] == nil ) then
			tq_activelist = {GetGossipActiveQuests()};
			--nb = table.getn(tq_activelist)/3;
			nb = 0;
			for ival1, sval2 in pairs(tq_activelist) do
				if ( ival1 > nb ) then
					nb = ival1;
				end
			end
			nb = nb/3;
			if ( floor(nb) == nb ) then
			else
				nb = floor(nb) + 1;
			end
			for i = 1, nb do
				if ( tq_activelist[((i-1)*3)+1] == DBquetes2_tempo_progress[0] ) then
					DBquetes2_tempo_progress[3] = tq_activelist[((i-1)*3)+2];
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[3] : "..DBquetes2_tempo_progress[3]);
				end
			end
		end
		if ( DBquetes2_tempo_progress[3] == nil ) then
			tq_availablelist = {GetGossipAvailableQuests()};
			--nb = table.getn(tq_availablelist)/3;
			nb = 0;
			for ival1, sval2 in pairs(tq_availablelist) do
				if ( ival1 > nb ) then
					nb = ival1;
				end
			end
			nb = nb/3;
			if ( floor(nb) == nb ) then
			else
				nb = floor(nb) + 1;
			end
			for i = 1, nb do
				if ( tq_availablelist[((i-1)*3)+1] == DBquetes2_tempo_progress[0] ) then
					DBquetes2_tempo_progress[3] = tq_availablelist[((i-1)*3)+2];
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[3] : "..DBquetes2_tempo_progress[3]);
				end
			end
		end
		if ( DBquetes2_tempo_progress[3] == nil ) then
			numActiveQuests = GetNumActiveQuests();
			for i = 1 , numActiveQuests do
				if ( GetActiveTitle(i) == DBquetes2_tempo_progress[0] ) then
					DBquetes2_tempo_progress[3] = GetActiveLevel(i);
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[3] : "..DBquetes2_tempo_progress[3]);
				end
			end
		end
		if ( DBquetes2_tempo_progress[3] == nil ) then
			numAvailableQuests = GetNumAvailableQuests();
			for i = 1 , numAvailableQuests do
				if ( GetAvailableTitle(i) == DBquetes2_tempo_progress[0] ) then
					DBquetes2_tempo_progress[3] = GetAvailableLevel(i);
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[3] : "..DBquetes2_tempo_progress[3]);
				end
			end
		end
		DBquetes2_tempo_progress[9] = GetProgressText();
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[9] : "..DBquetes2_tempo_progress[9]);
		DBquetes2_tempo_progress[10] = GetQuestMoneyToGet();
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[10] : "..DBquetes2_tempo_progress[10]);
		ibon = 1;
		numRequiredItems = GetNumQuestItems();
--TraceFrame:AddMessage("---objets requis : "..numRequiredItems);
		if ( numRequiredItems > 0 ) then
			if ( DBquetes2_tempo_progress[14] == nil ) then
				DBquetes2_tempo_progress[14] = {};
			end
			for i = 1 , numRequiredItems , 1 do
				inumobjet = 0;
				_, _, nbobjets, _, _ = GetQuestItemInfo("required", i);	--	"required" "reward" "choice" 
				sitem = GetQuestItemLink("required", i);	--	item:12345:0:0:0
				if ( sitem and nbobjets ) then
					for a, _, _, _, _, _, _, _, _, _ in string.gmatch(sitem,"item:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)") do	-- %p?
						inumobjet = tonumber(a);
--TraceFrame:AddMessage("---inumobjet : "..inumobjet.." pour "..nbobjets.." fois.");
						if ( DBquetes2_tempo_progress[14][inumobjet] == nil ) then
							DBquetes2_tempo_progress[14][inumobjet] = nbobjets;
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[14][inumobjet] : "..DBquetes2_tempo_progress[14][inumobjet]);
						end
					end
				else
					ibon = 0;
				end
				if ( inumobjet == 0 ) then
--TraceFrame:AddMessage("---manque objet i : "..i);
				end
			end
		end
		DBquetes2_tempo_progress[18], _ = UnitFactionGroup("player");
--TraceFrame:AddMessage("---DBquetes2_tempo_progress[18] : "..DBquetes2_tempo_progress[18]);
		DBquetes2_tempo_progress[26] = szone;	-- catégorie temporaire
		--	0
		--	2
		--	3
		--	6
		--	9
		--	10
		--	14
		--	18
		--	19
--TraceFrame:AddMessage("---ibon : "..ibon);
		if ( ibon == 1 ) then
			DBQS2_event = nil;
			DBQS2_enreg_progress();
		end
	elseif ( event == "QUEST_QUERY_COMPLETE" ) then
--TraceFrame:AddMessage("reception QUEST_QUERY_COMPLETE");
		tquete_completed = GetQuestsCompleted();
--TraceFrame:AddMessage("reception GetQuestsCompleted");
--TraceFrame:AddMessage("tquete_completed2 = "..type(tquete_completed2));
		if ( tquete_completed ) then
--TraceFrame:AddMessage("reception GetQuestsCompleted pas vide");
			--for tquete_completed_val1 in ipairs(tquete_completed2) do
			idateancien = DBHC_perso_config["GetQuestsCompleted"];
			idate = tonumber(DBCS_date());
			for tquete_completed_val1, tquete_completed_val2 in pairs(tquete_completed) do
				if ( tquete_completed_val2 == false ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("val 1 = "..tquete_completed_val1.." : false----------------------------------------------------------------------");
--end
				else
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("val 1 = "..tquete_completed_val1.." : true : "..DBQS2_lienquetebynum_nomquete(tquete_completed_val1));
--end
					if ( DBHC_perso[tquete_completed_val1] == nil ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("ajout d'une qu\195\170te termin\195\169e = "..tquete_completed_val1.." : "..DBQS2_lienquetebynum_nomquete(tquete_completed_val1));
end
						if ( idateancien == nil ) then
							DBHC_perso[tquete_completed_val1] = -1;
						else
							DBHC_perso[tquete_completed_val1] = ""..idateancien.."-"..idate;
						end
					end
				end
--TraceFrame:AddMessage("val 1 = "..tquete_completed_val1);
--TraceFrame:AddMessage("val 1 = "..tquete_completed_val1..", val2 = "..tquete_completed_val2);
			end
			DBHC_perso_config["GetQuestsCompleted"] = idate;
		end
	elseif ( event == "VARIABLES_LOADED" ) then
		if ( DBquetes2 == nil ) then
			DBquetes2 = {};
			DBPS2 = {};
			StaticPopupDialogs["DBCS_manque_base_quete"] = {
				text = "DBCS : manque la base Qu\195\170tes\nVeuillez t\195\169l\195\169charger le zip d'addons de donn\195\169es DBCS_data_"..GetLocale().."\nou cocher les addons DBCS_data_"..GetLocale(),
				button1 = TEXT(OKAY),
				timeout = 60,
				hideOnEscape = 1
			};
			StaticPopup_Show("DBCS_manque_base_quete");
		end
		--DBQS2_joueur = UnitName("player");
		if ( DBquetes2_config["numquete"] ) then
			DBquetes2_numquete = DBquetes2_config["numquete"];
		else
			DBquetes2_config["numquete"] = DBquetes2_numquete;
		end
		if ( DBquetes2_config["numquete_niv"] ) then
			DBquetes2_numquete_niv = DBquetes2_config["numquete_niv"];
		else
			DBquetes2_config["numquete_niv"] = DBquetes2_numquete_niv;
		end
		DBquetes2_Tooltip1TextLeft1:SetText(nil);
		DBQS2_toutesquetes_par_nometobjectif();
		DBcorps_ListQuetes2_Reset();
		DBcorps_ListQuetes2_Update();
		DBcorps_Quetes2_Scroll_Update();
		if ( DBHC and DBHC[DBHC_serveur] and DBHC[DBHC_serveur][DBHC_joueur] ) then
			for tquete_completed_val1, _ in pairs(DBHC[DBHC_serveur][DBHC_joueur]) do
				if ( tquete_completed_val1 > 0 ) then
					DBHC_perso[tquete_completed_val1] = DBHC[DBHC_serveur][DBHC_joueur][tquete_completed_val1];
				end
			end
			DBHC[DBHC_serveur][DBHC_joueur] = nil;
		end
		--DBQC2
		--DBquetes2
		if ( DBCS_data_Quetes_LOADED and DBCS_data_Quetes_LOADED == true ) then
		else
			slangue = GetLocale();
			if ( DBQC2 and DBQC2[slangue] ) then
				DBQS2_recup_DBQC2_vers_DBQS2(true);
				--for inumquete, _ in pairs(DBQC2[slangue]) do
				--	DBquetes2[inumquete] = DBQC2[slangue][inumquete];
				--end
			end
		end
	end

end

function DBquetes2_Liste_ajout(tablo,inumquete)

local i,j;
local nbquete;
local numquete;
local tQUETE;
local nomdonneur;
local nomfinisseur;
local inumqueteprec;
local inumquetesuiv;
local idate;

	j = 0;
	for i = 1 , table.getn(tablo) do
		if ( j == 0 and tablo[i][0] == inumquete ) then
			j = i;
		end
	end
	if ( j == 0 ) then
		if ( DBquetes2[inumquete] ) then
			tQUETE = DBquetes2[inumquete];
			i = table.getn(tablo);
			i = i + 1;
			tablo[i] = {};
			tablo[i][0] = inumquete;	-- numquete
			tablo[i][1] = tQUETE[0];	-- nomquete
			tablo[i][2] = tQUETE[1];	-- objectif
			tablo[i][3] = ( tQUETE[2] or tQUETE[3] or tQUETE[-2] );	-- nivmin
			tablo[i][4] = ( tQUETE[3] or tQUETE[-2] );	-- nivconseil
			tablo[i][5] = nil;
			if ( tQUETE[20] ) then
				tablo[i][5] = tQUETE[20];	-- catégorie
			else
				if ( tQUETE[26] ) then
					tablo[i][5] = "("..tQUETE[26]..")";	-- catégorie temporaire
				end
			end
			tablo[i][6] = tQUETE[21];	-- type
			tablo[i][7] = "";			-- début
			if ( tQUETE[46] and tQUETE[46][1] ) then
				tablo[i][7] = tQUETE[46][1];
			elseif ( tQUETE[5] ) then
				--j = 0;
				idate = -1;
				for nomdonneur, _ in pairs(tQUETE[5]) do
					--j = j + 1;
					--if ( j == 1 ) then
					--	tablo[i][7] = nomdonneur;
					--end
					if ( tQUETE[5][nomdonneur] > idate ) then
						idate = tQUETE[5][nomdonneur];
						tablo[i][7] = nomdonneur;
					end
				end
			end
			if ( type(tablo[i][7]) == "string" and strlen(tablo[i][7]) == 0 ) then
				if ( tQUETE[24] ) then
					inumqueteprec = -1;
					idate = -1;
					for j, _ in pairs(tQUETE[24]) do
						if ( tQUETE[24][j] > idate ) then
							inumqueteprec = j;
							idate = tQUETE[24][j];
						end
					end
					if ( idate > -1 and DBquetes2[inumqueteprec] and DBquetes2[inumqueteprec][0] ) then
						tablo[i][7] = DBquetes2[inumqueteprec][0];
					end
				end
				--if ( tQUETE[24] and tQUETE[24].nb and tQUETE[24].nb > 0 ) then
				--	tablo[i][7] = tQUETE[24][1][1];
				--end
			end
			tablo[i][8] = "";			-- fin
			if ( tQUETE[47] and tQUETE[47][1] ) then
				tablo[i][8] = tQUETE[47][1];
			elseif ( tQUETE[6] ) then
				--j = 0;
				idate = -1;
				for nomfinisseur, _ in pairs(tQUETE[6]) do
					--j = j + 1;
					--if ( j == 1 ) then
					--	tablo[i][8] = nomfinisseur;
					--end
					if ( tQUETE[6][nomfinisseur] > idate ) then
						idate = tQUETE[6][nomfinisseur];
						tablo[i][8] = nomfinisseur;
					end
				end
			end
			if ( type(tablo[i][8]) == "string" and strlen(tablo[i][8]) == 0 ) then
				if ( tQUETE[25] ) then
					inumquetesuiv = -1;
					idate = -1;
					for j, _ in pairs(tQUETE[25]) do
						if ( tQUETE[25][j] > idate ) then
							inumquetesuiv = j;
							idate = tQUETE[25][j];
						end
					end
					if ( idate > -1 and DBquetes2[inumquetesuiv] and DBquetes2[inumquetesuiv][0] ) then
						tablo[i][8] = DBquetes2[inumquetesuiv][0];
					end
				end
				--if ( tQUETE[25] and tQUETE[25].nb and tQUETE[25].nb > 0 ) then
				--	tablo[i][8] = tQUETE[25][1][1];
				--end
			end
		end
	end

	return tablo;

end

function DBquetes2_Liste(criteres)

local tablo;
local tQUETE;
local nomquete;
local nbquete;
local numquete;
local inumquete;
local bbon;
local i;
local j;
local k;
local ipos;
local smot;
local lg;
local inumqueteprec;
local inumquetesuiv;
local idate;
local a;

	tablo = {};
	i = 0;
	for inumquete, _ in pairs(DBquetes2) do
		bbon = 1;
		tQUETE = DBquetes2[inumquete];
		if ( bbon == 1 and criteres.nomquete and not ( criteres.nomquete == "" ) ) then
			ipos, _ = strfind(strlower(tQUETE[0]),strlower(criteres.nomquete));
			if ( not ipos ) then
				bbon = 0;
			end
		end
		if ( bbon == 1 and criteres.nivmin ) then
			if ( tQUETE[3] ) then
				if ( tQUETE[3] < criteres.nivmin ) then
					bbon = 0;
				end
			else
				if ( tQUETE[-2] ) then
					if ( tQUETE[-2] < criteres.nivmin ) then
						bbon = 0;
					end
				else
					bbon = 0;
					--if ( tQUETE[2] ) then
					--	if ( tQUETE[2] < criteres.nivmin ) then
					--		bbon = 0;
					--	end
					--else
					--	bbon = 0;
					--end
				end
			end
		end
		if ( bbon == 1 and criteres.nivmax ) then
			if ( tQUETE[3] ) then
				if ( tQUETE[3] > criteres.nivmax ) then
					bbon = 0;
				end
			else
				if ( tQUETE[-2] ) then
					if ( tQUETE[-2] > criteres.nivmax ) then
						bbon = 0;
					end
				else
					bbon = 0;
					--if ( tQUETE[2] ) then
					--	if ( tQUETE[2] > criteres.nivmax ) then
					--		bbon = 0;
					--	end
					--else
					--	bbon = 0;
					--end
				end
			end
		end
		if ( bbon == 1 and criteres.categorie and not ( criteres.categorie == "" ) ) then
			if ( tQUETE[20] ) then
				ipos, _ = strfind(strlower(tQUETE[20]),strlower(criteres.categorie));
				if ( not ipos ) then
					bbon = 0;
				end
			else
				if ( tQUETE[26] ) then
					ipos, _ = strfind(strlower(tQUETE[26]),strlower(criteres.categorie));
					if ( not ipos ) then
						bbon = 0;
					end
				else
					bbon = 0;
				end
			end
		end
		if ( bbon == 1 and criteres.type and not ( criteres.type == "" ) ) then
			if ( tQUETE[21] ) then
				ipos, _ = strfind(strlower(tQUETE[21]),strlower(criteres.type));
				if ( not ipos ) then
					bbon = 0;
				end
			else
				bbon = 0;
			end
		end
		if ( bbon == 1 and criteres.debut and not ( criteres.debut == "" ) ) then
			-- ajouter la vérif sur le nom de la première quete
			if ( tQUETE[46] and tQUETE[46][1] ) then
				bbon = 0;
				if ( DBmobs_Local and DBmobs_Local[tQUETE[46][1]] and DBmobs_Local[tQUETE[46][1]][1] and DBmobs_Local[tQUETE[46][1]][1][1] ) then
					ipos, _ = strfind(strlower(DBmobs_Local[tQUETE[46][1]][1][1]),strlower(criteres.debut));
					if ( ipos ) then
						bbon = 1;
					end
				end
			elseif ( tQUETE[5] ) then
				idate = -1;
				j = 0;
				k = 0;
				for nomdonneur, _ in pairs(tQUETE[5]) do
					j = j + 1;
					if ( tQUETE[5][nomdonneur] > idate ) then
						idate = tQUETE[5][nomdonneur];
						k = j;
					end
				end
				j = 0;
				for nomdonneur, _ in pairs(tQUETE[5]) do
					j = j + 1;
					if ( j == k ) then
						ipos, _ = strfind(strlower(nomdonneur),strlower(criteres.debut));
						if ( not ipos ) then
							bbon = 0;
						end
					end
				end
				if ( j == 0 ) then
					bbon = 0;
				end
			else
				bbon = 0;
			end
		end
		if ( bbon == 1 and criteres.fin and not ( criteres.fin == "" ) ) then
			-- ajouter la vérif sur le nom de la première quete
			if ( tQUETE[47] and tQUETE[47][1] ) then
				bbon = 0;
				if ( DBmobs_Local and DBmobs_Local[tQUETE[47][1]] and DBmobs_Local[tQUETE[47][1]][1] and DBmobs_Local[tQUETE[47][1]][1][1] ) then
					ipos, _ = strfind(strlower(DBmobs_Local[tQUETE[47][1]][1][1]),strlower(criteres.fin));
					if ( ipos ) then
						bbon = 1;
					end
				end
			elseif ( tQUETE[6] ) then
				idate = -1;
				j = 0;
				k = 0;
				for nomfinisseur, _ in pairs(tQUETE[6]) do
					j = j + 1;
					if ( tQUETE[6][nomfinisseur] > idate ) then
						idate = tQUETE[6][nomfinisseur];
						k = j;
					end
				end
				j = 0;
				for nomfinisseur, _ in pairs(tQUETE[6]) do
					j = j + 1;
					if ( j == k ) then
						ipos, _ = strfind(strlower(nomfinisseur),strlower(criteres.fin));
						if ( not ipos ) then
							bbon = 0;
						end
					end
				end
				if ( j == 0 ) then
					bbon = 0;
				end
			else
				bbon = 0;
			end
		end
		if ( bbon == 1 and criteres.encours and not ( criteres.encours == 0 ) ) then
			-- nomquete
			-- tQUETE[1]
			if ( DBQS2_tquetesencours[inumquete] ) then
				--bbon = 0;
				--for j = 1 , table.getn(DBQS_tquetesencours[nomquete]) do
				--	if ( DBQS_tquetesencours[nomquete][j][1] == tQUETE[1] ) then
				--		bbon = 1;
				--	end
				--end
			else
				bbon = 0;
			end
		end
		if ( bbon == 1 and criteres.journaliere and criteres.journaliere == 1 ) then
			if ( tQUETE[28] ) then
			else
				bbon = 0;
			end
		end
		if ( bbon == 1 and criteres.faction and criteres.faction > -1 ) then
			if ( criteres.faction == 1 and tQUETE[18] == 1 ) then
			elseif ( criteres.faction == 2 and tQUETE[19] == 1 ) then
			else
				bbon = 0;
			end
		end
		if ( bbon == 1 and criteres.terminee and criteres.terminee > -1 ) then
			if ( criteres.terminee == 1 and DBHC_perso[inumquete] == nil ) then
			elseif ( criteres.terminee == 2 and DBHC_perso[inumquete] ) then
			else
				bbon = 0;
			end
		end
		if ( bbon == 1 ) then
			i = i + 1 ;
			tablo[i] = {};
			tablo[i][0] = inumquete;
			tablo[i][1] = tQUETE[0];	-- nomquete
			tablo[i][2] = tQUETE[1];	-- objectif
			tablo[i][3] = ( tQUETE[2] or tQUETE[3] or tQUETE[-2] );	-- nivmin
			tablo[i][4] = ( tQUETE[3] or tQUETE[-2] );	-- nivconseil
			tablo[i][5] = nil;
			if ( tQUETE[20] ) then
				tablo[i][5] = tQUETE[20];	-- catégorie
			else
				if ( tQUETE[26] ) then
					tablo[i][5] = "("..tQUETE[26]..")";	-- catégorie temporaire
				end
			end
			tablo[i][6] = tQUETE[21];	-- type
			tablo[i][7] = "";			-- début
			if ( tQUETE[46] and tQUETE[46][1] ) then
				tablo[i][7] = tQUETE[46][1];
			elseif ( tQUETE[5] ) then
				--j = 0;
				idate = -1;
				for nomdonneur, _ in pairs(tQUETE[5]) do
					--j = j + 1;
					--if ( j == 1 ) then
					--	tablo[i][7] = nomdonneur;
					--end
					if ( tQUETE[5][nomdonneur] > idate ) then
						idate = tQUETE[5][nomdonneur];
						tablo[i][7] = nomdonneur;
					end
				end
				if ( idate > -1 ) then
					for nomdonneur, _ in pairs(tQUETE[5]) do
						if ( tQUETE[5][nomdonneur] == idate ) then
							if ( DBPS2[nomdonneur] ) then
								for a, _ in pairs(DBPS2[nomdonneur]) do
									if ( DB_nomregionbynum(a) == tQUETE[26] or DB_nomregionbynum(a) == tQUETE[20] ) then
										tablo[i][7] = nomdonneur;
									end
								end
							end
						end
					end
				end
			end
			if ( type(tablo[i][7]) == "string" and strlen(tablo[i][7]) == 0 ) then
				if ( tQUETE[24] ) then
					inumqueteprec = -1;
					idate = -1;
					for j, _ in pairs(tQUETE[24]) do
						if ( tQUETE[24][j] > idate ) then
							inumqueteprec = j;
							idate = tQUETE[24][j];
						end
					end
					if ( idate > -1 and DBquetes2[inumqueteprec] and DBquetes2[inumqueteprec][0] ) then
						tablo[i][7] = DBquetes2[inumqueteprec][0];
					end
				end
			end
			tablo[i][8] = "";			-- fin
			if ( tQUETE[47] and tQUETE[47][1] ) then
				tablo[i][8] = tQUETE[47][1];
			elseif ( tQUETE[6] ) then
				--j = 0;
				idate = -1;
				for nomfinisseur, _ in pairs(tQUETE[6]) do
					--j = j + 1;
					--if ( j == 1 ) then
					--	tablo[i][8] = nomfinisseur;
					--end
					if ( tQUETE[6][nomfinisseur] > idate ) then
						idate = tQUETE[6][nomfinisseur];
						tablo[i][8] = nomfinisseur;
					end
				end
				if ( idate > -1 ) then
					for nomfinisseur, _ in pairs(tQUETE[6]) do
						if ( tQUETE[6][nomfinisseur] == idate ) then
							if ( DBPS2[nomfinisseur] ) then
								for a, _ in pairs(DBPS2[nomfinisseur]) do
									if ( DB_nomregionbynum(a) == tQUETE[26] or DB_nomregionbynum(a) == tQUETE[20] ) then
										tablo[i][8] = nomfinisseur;
									end
								end
							end
						end
					end
				end
			end
			if ( type(tablo[i][8]) == "string" and strlen(tablo[i][8]) == 0 ) then
				if ( tQUETE[25] ) then
					inumquetesuiv = -1;
					idate = -1;
					for j, _ in pairs(tQUETE[25]) do
						if ( tQUETE[25][j] > idate ) then
							inumquetesuiv = j;
							idate = tQUETE[25][j];
						end
					end
					if ( idate > -1 and DBquetes2[inumquetesuiv] and DBquetes2[inumquetesuiv][0] ) then
						tablo[i][8] = DBquetes2[inumquetesuiv][0];
					end
				end
				--if ( tQUETE[25] and tQUETE[25].nb and tQUETE[25].nb > 0 ) then
				--	tablo[i][8] = tQUETE[25][1][1];
				--end
			end
		end
	end
	return tablo;

end

function DBquetes2_rechercheobjet(inumobjet)

local tablo;
local tQUETE;
local inumquete;
local i;
local j;
local k;
local bbon;
local nomdonneur;
local nomfinisseur;
local inumqueteprec;
local inumquetesuiv;
local idate;

	tablo = {};
	i = 0;
	for inumquete, _ in pairs(DBquetes2) do
		bbon = 0;
		tQUETE = DBquetes2[inumquete];
		if ( bbon == 0 and tQUETE[14] ) then
			if ( tQUETE[14][inumobjet] ) then
				bbon = 1;
			end
		end
		if ( bbon == 0 and tQUETE[15] ) then
			if ( tQUETE[15][inumobjet] ) then
				bbon = 1;
			end
		end
		if ( bbon == 0 and tQUETE[16] ) then
			if ( tQUETE[16][inumobjet] ) then
				bbon = 1;
			end
		end
		if ( bbon == 1 ) then
			i = i + 1 ;
			tablo[i] = {};
			tablo[i][0] = inumquete;	-- num quete
			tablo[i][1] = tQUETE[0];	-- nomquete
			tablo[i][2] = tQUETE[1];	-- objectif
			tablo[i][3] = ( tQUETE[2] or tQUETE[3] or tQUETE[-2] );	-- nivmin
			tablo[i][4] = ( tQUETE[3] or tQUETE[-2] );	-- nivconseil
			tablo[i][5] = nil;
			if ( tQUETE[20] ) then
				tablo[i][5] = tQUETE[20];	-- catégorie
			else
				if ( tQUETE[26] ) then
					tablo[i][5] = "("..tQUETE[26]..")";	-- catégorie temporaire
				end
			end
			tablo[i][6] = tQUETE[21];	-- type
			tablo[i][7] = "";			-- début
			if ( tQUETE[46] and tQUETE[46][1] ) then
				tablo[i][7] = tQUETE[46][1];
			elseif ( tQUETE[5] ) then
				--j = 0;
				idate = -1;
				for nomdonneur, _ in pairs(tQUETE[5]) do
					--j = j + 1;
					if ( tQUETE[5][nomdonneur] > idate ) then
						idate = tQUETE[5][nomdonneur];
						tablo[i][7] = nomdonneur;
					end
					--if ( j == 1 ) then
					--	tablo[i][7] = nomdonneur;
					--end
				end
			end
			if ( type(tablo[i][7]) == "string" and strlen(tablo[i][7]) == 0 ) then
				if ( tQUETE[24] ) then
					inumqueteprec = -1;
					idate = -1;
					for j, _ in pairs(tQUETE[24]) do
						if ( tQUETE[24][j] > idate ) then
							inumqueteprec = j;
							idate = tQUETE[24][j];
						end
					end
					if ( idate > -1 and DBquetes2[inumqueteprec] and DBquetes2[inumqueteprec][0] ) then
						tablo[i][7] = DBquetes2[inumqueteprec][0];
					end
				end
			end
			tablo[i][8] = "";			-- fin
			if ( tQUETE[47] and tQUETE[47][1] ) then
				tablo[i][8] = tQUETE[47][1];
			elseif ( tQUETE[6] ) then
				--j = 0;
				idate = -1;
				for nomfinisseur, _ in pairs(tQUETE[6]) do
					--j = j + 1;
					--if ( j == 1 ) then
					--	tablo[i][8] = nomfinisseur;
					--end
					if ( tQUETE[6][nomfinisseur] > idate ) then
						idate = tQUETE[6][nomfinisseur];
						tablo[i][8] = nomfinisseur;
					end
				end
			end
			if ( type(tablo[i][8]) == "string" and strlen(tablo[i][8]) == 0 ) then
				if ( tQUETE[25] ) then
					inumquetesuiv = -1;
					idate = -1;
					for j, _ in pairs(tQUETE[25]) do
						if ( tQUETE[25][j] > idate ) then
							inumquetesuiv = j;
							idate = tQUETE[25][j];
						end
					end
					if ( idate > -1 and DBquetes2[inumquetesuiv] and DBquetes2[inumquetesuiv][0] ) then
						tablo[i][8] = DBquetes2[inumquetesuiv][0];
					end
				end
			end
		end
	end

	return tablo;
				
end

function DBquetes2_Trier(quete1,quete2,t_ordre,niveaufonction)

	local s_champ = t_ordre[niveaufonction].champ;
	local s_sens = t_ordre[niveaufonction].sens;
	local val1,val2;

	if ( s_champ == "nomquete" ) then
		val1 = quete1[1];
		val2 = quete2[1];
	elseif ( s_champ == "numquete") then
		val1 = quete1[0];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = quete2[0];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "nivmin") then
		val1 = quete1[3];
		if ( val1 == nil ) then
			val1 = quete1[4];
		end
		if ( val1 == nil ) then
			val1 = quete1[-2];
		end
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = quete2[3];
		if ( val2 == nil ) then
			val2 = quete2[4];
		end
		if ( val2 == nil ) then
			val2 = quete2[-2];
		end
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "nivconseil") then
		val1 = quete1[4];
		if ( val1 == nil ) then
			val1 = quete1[-2];
		end
		--if ( val1 == nil ) then
		--	val1 = quete1[3];
		--end
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = quete2[4];
		if ( val2 == nil ) then
			val2 = quete2[-2];
		end
		--if ( val2 == nil ) then
		--	val2 = quete2[3];
		--end
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "categorie" ) then
		val1 = quete1[5];
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = quete2[5];
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "type" ) then
		val1 = quete1[6];
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = quete2[6];
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "debut" ) then
		val1 = quete1[7];
		if ( val1 == nil ) then
			val1 = "";
		end
		if ( type(val1) == "number" ) then
			if ( DBmobs_Local and DBmobs_Local[val1] and DBmobs_Local[val1][1] and DBmobs_Local[val1][1][1] ) then
				val1 = DBmobs_Local[val1][1][1];
			end
		end
		val2 = quete2[7];
		if ( val2 == nil ) then
			val2 = "";
		end
		if ( type(val2) == "number" ) then
			if ( DBmobs_Local and DBmobs_Local[val2] and DBmobs_Local[val2][1] and DBmobs_Local[val2][1][1] ) then
				val2 = DBmobs_Local[val2][1][1];
			end
		end
	elseif ( s_champ == "fin" ) then
		val1 = quete1[8];
		if ( val1 == nil ) then
			val1 = "";
		end
		if ( type(val1) == "number" ) then
			if ( DBmobs_Local and DBmobs_Local[val1] and DBmobs_Local[val1][1] and DBmobs_Local[val1][1][1] ) then
				val1 = DBmobs_Local[val1][1][1];
			end
		end
		val2 = quete2[8];
		if ( val2 == nil ) then
			val2 = "";
		end
		if ( type(val2) == "number" ) then
			if ( DBmobs_Local and DBmobs_Local[val2] and DBmobs_Local[val2][1] and DBmobs_Local[val2][1][1] ) then
				val2 = DBmobs_Local[val2][1][1];
			end
		end
	else
		val1 = quete1[1];
		val2 = quete2[1];
	end

	if ( s_sens == "ASC" ) then
		if ( val1 < val2 ) then
			return true;
		elseif ( val1 == val2 ) then
		else
			return false;
		end
	else
		if ( val1 > val2 ) then
			return true;
		elseif ( val1 == val2 ) then
		else
			return false;
		end
	end
	if ( val1 == val2 ) then
		if ( table.getn(t_ordre) > niveaufonction ) then
			return DBquetes2_Trier(quete1,quete2,t_ordre,niveaufonction+1);
		else
			return false;
		end
	else
		return false; -- pas normal d etre ici
	end

end

function DBQS2_Detail(inumquete)

local tablo = nil;

	if ( DBquetes2[inumquete] ) then
		tablo = DBquetes2[inumquete];
	else
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("inumquete mauvais : "..(inumquete or ""));
end
	end
	
	return tablo;

end

function DBQS2_ajout_quete(inum)

local snomquete;
local bbon;
local sobjectif;
local i;
local ipos;

	DBquetes2_Tooltip2TextLeft1:SetText(nil);
	--DBquetes2_Tooltip2:SetOwner(UIParent,"ANCHOR_CURSOR");
	DBquetes2_Tooltip2:SetHyperlink("quest:"..inum..":0");
	DBquetes2_Tooltip2:Show();

	i = 1;
	snomquete = _G["DBquetes2_Tooltip2TextLeft"..i]:GetText();
	if ( snomquete ) then
		ipos = strfind(snomquete,"<",1);
		if ( ipos == nil ) then
			ipos = strfind(snomquete,"%[",1);
		end
		if ( ipos ) then
			DBquetes2[inum] = nil;
		else
			if ( DBquetes2[inum] == nil ) then
				DBquetes2[inum] = {};
				DBquetes2[inum][44] = DBCS_date().."@"..DBCS_time();
			end
			DBquetes2[inum][0] = snomquete;
			bbon = false;
			while ( bbon == false and i < 8 ) do
				i = i + 1 ;
				sobjectif = _G["DBquetes2_Tooltip2TextLeft"..i]:GetText();
				if ( sobjectif ) then
					if ( sobjectif == "Conditions\194\160:" ) then
						bbon = true;
					elseif ( sobjectif == "Vous effectuez cette qu\195\170te" ) then
					elseif ( sobjectif == " " ) then
					else
						DBquetes2[inum][1] = sobjectif;
						bbon = true;
					end
				else
				end
			end
		end
	end
	if ( DBquetes2[inum] == nil ) then
		DBquetes2[inum] = nil;
	end

end

function DBQS2_GetMotItem(sitem)

	local ideb;
	local ipos;
	local snomitem, snumitemcourt, snumitemlong, shexcouleuritem, inumcouleuritem;
	local i;
	local r, g, b, hex;
	local stype;
	
	shexcouleuritem = strsub(sitem,3,10);

	inumcouleuritem = -1;

	stype = strsub(sitem,13,13);
	if ( stype == "i" ) then

		ideb = 18;
		ipos = strfind(sitem,"h",ideb);
		snumitemlong = strsub(sitem,ideb,ipos-2);

		ideb = ipos + 2;
		ipos = strfind(sitem,"]",ideb);
		snomitem = strsub(sitem,ideb,ipos-1);

		ipos = strfind(snumitemlong,":");
		snumitemcourt = strsub(snumitemlong,1,ipos-1);

		for i = 0, 7 do
			if ( inumcouleuritem == -1 ) then
				r, g, b, hex = GetItemQualityColor(i);
				if ( hex ) then
					if ( hex == shexcouleuritem ) then
						inumcouleuritem = i;
					end
				end
			end
		end

	elseif ( stype == "q" ) then
		ideb = 19;
		ipos = strfind(sitem,"h",ideb);
		snumitemlong = strsub(sitem,ideb,ipos-2);
		ideb = ipos + 2;
		ipos = strfind(sitem,"]",ideb);
		snomitem = strsub(sitem,ideb,ipos-1);
		snumitemcourt = snumitemlong;
		inumcouleuritem = -2;
	elseif ( stype == "s" ) then
		ideb = 19;
		ipos = strfind(sitem,"h",ideb);
		snumitemlong = strsub(sitem,ideb,ipos-2);
		ideb = ipos + 2;
		ipos = strfind(sitem,"]",ideb);
		snomitem = strsub(sitem,ideb,ipos-1);
		snumitemcourt = snumitemlong;
		inumcouleuritem = -3;
	else
		ideb = 21;
		ipos = strfind(sitem,"h",ideb);
		snumitemlong = strsub(sitem,ideb,ipos-2);
		ideb = ipos + 2;
		ipos = strfind(sitem,"]",ideb);
		snomitem = strsub(sitem,ideb,ipos-1);
		snumitemcourt = snumitemlong;
	end

	return snomitem, snumitemcourt, snumitemlong, shexcouleuritem, inumcouleuritem;

end

-- Used for quests and enemy coloration
function DBQS2_GetDifficultyColor(level)

local levelDiff = level - UnitLevel("player");

	if ( levelDiff >= 5 ) then
		color = DBQS2_color["impossible"];
	elseif ( levelDiff >= 3 ) then
		color = DBQS2_color["verydifficult"];
	elseif ( levelDiff >= -2 ) then
		color = DBQS2_color["difficult"];
	elseif ( -levelDiff <= GetQuestGreenRange() ) then
		color = DBQS2_color["standard"];
	else
		color = DBQS2_color["trivial"];
	end

	return color;

end

function DBcorpsFrame_Quetes2Frame_Criteres_Faction_OnLoad()

	UIDropDownMenu_Initialize(DBcorpsFrame_Quetes2Frame_Criteres_Faction, DBcorpsFrame_Quetes2Frame_Criteres_Faction_Initialize);

end

function DBcorpsFrame_Quetes2Frame_Criteres_Faction_Initialize()

local info;

	info = {};
	info.text = "Toutes";
	info.value = -1;
	info.func = DBcorpsFrame_Quetes2Frame_Criteres_Faction_OnClick;
	UIDropDownMenu_AddButton(info);
	info = {};
	info.text = "Alliance";
	info.value = 1;
	info.func = DBcorpsFrame_Quetes2Frame_Criteres_Faction_OnClick;
	UIDropDownMenu_AddButton(info);
	info = {};
	info.text = "Horde";
	info.value = 2;
	info.func = DBcorpsFrame_Quetes2Frame_Criteres_Faction_OnClick;
	UIDropDownMenu_AddButton(info);

end

function DBcorpsFrame_Quetes2Frame_Criteres_Faction_OnClick(self)

	UIDropDownMenu_SetSelectedValue(DBcorpsFrame_Quetes2Frame_Criteres_Faction, self.value);

end

function DBcorpsFrame_Quetes2Frame_Criteres_Terminee_OnLoad()

	UIDropDownMenu_Initialize(DBcorpsFrame_Quetes2Frame_Criteres_Terminee, DBcorpsFrame_Quetes2Frame_Criteres_Terminee_Initialize);

end

function DBcorpsFrame_Quetes2Frame_Criteres_Terminee_Initialize()

local info;

	info = {};
	info.text = "Toutes";
	info.value = -1;
	info.func = DBcorpsFrame_Quetes2Frame_Criteres_Terminee_OnClick;
	UIDropDownMenu_AddButton(info);
	info = {};
	info.text = "Non";
	info.value = 1;
	info.func = DBcorpsFrame_Quetes2Frame_Criteres_Terminee_OnClick;
	UIDropDownMenu_AddButton(info);
	info = {};
	info.text = "Oui";
	info.value = 2;
	info.func = DBcorpsFrame_Quetes2Frame_Criteres_Terminee_OnClick;
	UIDropDownMenu_AddButton(info);

end

function DBcorpsFrame_Quetes2Frame_Criteres_Terminee_OnClick(self)

	UIDropDownMenu_SetSelectedValue(DBcorpsFrame_Quetes2Frame_Criteres_Terminee, self.value);

end

function DBcorps_Quetes2_Scroll_Update()

	local i,j;
	local offset = FauxScrollFrame_GetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame);
	local button,buttonName;
	local itemChamp;
	local tablo;
	local inumquete;
	local nomquete,objectif,nivmin,nivconseil;
	local k;
	local inbmembregroupe;
	local inbonquest;
	local l;
	local bhisto;
	local bencours;
	local bencoursk;
	local bcomplete;
	local color;
	local isav;
	local itypequetejournaliere;

--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBcorps_Quetes2_Scroll_Update DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end

	isav = GetQuestLogSelection();

	FauxScrollFrame_Update(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame, DBCORPS_QUETES2_LISTE_nb, 10, 32);

	for i = 1 , 10 do
		j = offset + i;
		buttonName = "DBcorpsFrame_Quetes2Frame_Liste_Button"..i;
		button = _G[buttonName];
		button:Hide();
		if ( j > DBCORPS_QUETES2_LISTE_nb ) then
		else
			inumquete = DBCORPS_QUETES2_LISTE[j][0];
			nomquete = DBCORPS_QUETES2_LISTE[j][1];
			objectif = DBCORPS_QUETES2_LISTE[j][2];
			nivmin = DBCORPS_QUETES2_LISTE[j][3];
			nivconseil = DBCORPS_QUETES2_LISTE[j][4];
			categorie = DBCORPS_QUETES2_LISTE[j][5];
			stype = DBCORPS_QUETES2_LISTE[j][6];
			sdebut = DBCORPS_QUETES2_LISTE[j][7];
			sfin = DBCORPS_QUETES2_LISTE[j][8];
			itemChamp = _G[buttonName.."_Nomquete"];
			itemChamp:SetText(nomquete);
			bencours = 0;
			if ( DBQS2_tquetesencours[inumquete] ) then
				bencours = 1;
				bencoursk = DBQS2_tquetesencours[inumquete][3];
				bcomplete = DBQS2_tquetesencours[inumquete][2];
			end
			if ( bencours == 1 ) then
				if ( bcomplete == nil ) then
					itemChamp:SetTextColor(1,1,0);		-- jaune
				else
					if ( bcomplete < 0 ) then
						itemChamp:SetTextColor(1,0,0);		-- rouge	-- en echec
					else
						itemChamp:SetTextColor(0,0.5,1);		-- demi bleu	-- terminée
					end
				end
			else
				bhisto = 0;
				if ( DBHC_perso ) then
					if ( DBHC_perso[inumquete] ) then
						bhisto = 1;
					elseif ( DBHC_perso[0] and DBHC_perso[0][nomquete] ) then
						for k = 1 , table.getn(DBHC_perso[0][nomquete]) do
							if ( DBHC_perso[0][nomquete][k] == objectif ) then
								bhisto = 1;
							end
						end
					end
				end
				if ( bhisto == 1 ) then
					itemChamp:SetTextColor(0.5,0.5,0.5);	-- gris
				else
					--itemChamp:SetTextColor(0,1,0);		-- vert
					itemChamp:SetTextColor(1,1,1);		-- blanc
				end
			end
			itemChamp = _G[buttonName.."_Nivmin"];
			itemChamp:SetText(nivmin);
			if ( nivmin ) then
				if ( nivmin == 0 ) then
					itemChamp:SetText(nil);
				end
			end
			itemChamp = _G[buttonName.."_Nivconseil"];
			itemChamp:SetText(nivconseil);
			if ( nivconseil ) then
				if ( nivconseil == 0 ) then
					itemChamp:SetText(nil);
				else
					color = DBQS2_GetDifficultyColor(nivconseil);
					itemChamp:SetTextColor(color.r, color.g, color.b);
				end
			end
			tablo = DBQS2_Detail(inumquete);
			itemChamp = _G[buttonName.."_Categorie"];
			itemChamp:SetText(categorie);
			itemChamp:SetTextColor(1,1,1);		-- blanc
			if ( tablo[28] ) then
				--if ( quetedejafaiteauj ) then
				--	itemChamp:SetTextColor(1,0,0);		-- rouge	-- déjà faite auj
				--else
					itemChamp:SetTextColor(0,1,0);		-- vert
				--end
			end
			if ( bencours == 1 ) then
				if ( IsQuestWatched(bencoursk) ) then
					itemChamp:SetTextColor(0,0.5,1);		-- demi bleu	-- suivie
				end
			end
			itemChamp = _G[buttonName.."_Type"];
			if ( tablo[29] and tablo[29] > 0 ) then
				if ( stype and stype == "#" ) then
					itemChamp:SetText("("..tablo[29]..")");
				else
					itemChamp:SetText((stype or "").." ("..tablo[29]..")");
				end
			else
				if ( stype and stype == "#" ) then
					itemChamp:SetText(nil);
				else
					itemChamp:SetText(stype);
				end
			end
			itemChamp = _G[buttonName.."_Debut"];
			if ( type(sdebut) == "string" ) then
				itemChamp:SetText(sdebut);
			else
				if ( DBmobs_Local and DBmobs_Local[sdebut] and DBmobs_Local[sdebut][1] and DBmobs_Local[sdebut][1][1] ) then
if ( DBCS_debug and DBCS_debug > 1 ) then
					itemChamp:SetText(sdebut..":"..DBmobs_Local[sdebut][1][1]);
else
					itemChamp:SetText(DBmobs_Local[sdebut][1][1]);
end
				else
					itemChamp:SetText(sdebut);
				end
			end
			--itemChamp:SetText(inumquete);
			itemChamp = _G[buttonName.."_Fin"];
			if ( type(sfin) == "string" ) then
				itemChamp:SetText(sfin);
			else
				if ( DBmobs_Local and DBmobs_Local[sfin] and DBmobs_Local[sfin][1] and DBmobs_Local[sfin][1][1] ) then
if ( DBCS_debug and DBCS_debug > 1 ) then
					itemChamp:SetText(sfin..":"..DBmobs_Local[sfin][1][1]);
else
					itemChamp:SetText(DBmobs_Local[sfin][1][1]);
end
				else
					itemChamp:SetText(sfin);
				end
			end
			itemChamp = _G[buttonName.."_Numquete"];
			itemChamp:SetTextColor(1,1,1);		-- blanc
			if ( tablo[28] ) then
				itemChamp:SetTextColor(0,1,0);		-- vert
			end
--	DBQS2_quetes_journalieres_type_encours = DBQS2_quetes_journalieres_type;
	--DBQS2_quetes_journalieres;
--DBQS2_quetes_journalieres_type[01] = { provisoire = false, dejafait = false, encours = 0 , name = "P\195\170cheur" };
			if ( bencours == 0 ) then
				itypequetejournaliere = DBQS2_quetes_journalieres[inumquete];
				if ( itypequetejournaliere ) then
					if ( DBQS2_quetes_journalieres_type_encours[abs(itypequetejournaliere)].provisoire == false and itypequetejournaliere < 0 ) then
						itemChamp:SetTextColor(0.5,0.5,0.5);	-- gris
					elseif ( DBQS2_quetes_journalieres_type_encours[abs(itypequetejournaliere)].dejafait == true ) then
						itemChamp:SetTextColor(1,0,0);		-- rouge	-- déjà faite auj
					elseif ( DBQS2_quetes_journalieres_type_encours[abs(itypequetejournaliere)].encours > 0 ) then
						itemChamp:SetTextColor(1,0.5,0);		-- orange
					else
					end
				else
					if ( tablo[28] ) then
						if ( DBHC_perso and DBHC_perso[inumquete] and type(DBHC_perso[inumquete]) == "number" and DBHC_perso[inumquete] == tonumber(DBCS_date()) ) then
							itemChamp:SetTextColor(1,0,0);		-- rouge	-- déjà faite auj
						end
					end
				end
			end

			itemChamp:SetText(inumquete);
			_G[buttonName.."_Alliance"]:Hide();
			if ( tablo[18] ) then
				_G[buttonName.."_Alliance"]:Show();
			end
			_G[buttonName.."_Horde"]:Hide();
			if ( tablo[19] ) then
				_G[buttonName.."_Horde"]:Show();
			end
			itemChamp = _G[buttonName.."_Partage"];
			itemChamp:Hide();
			if ( tablo[27] ) then
				itemChamp:Show();
				if ( tablo[27] == 1 ) then
					itemChamp:SetText("p");
				else
					itemChamp:SetText("x");
				end
			end
			if ( bencours == 1 ) then
				SelectQuestLogEntry(bencoursk);
				if ( GetQuestLogPushable() and GetNumSubgroupMembers() > 0 ) then	--GetNumPartyMembers() > 0 ) then
					itemChamp:Show();
				else
				end
				inbmembregroupe = GetNumSubgroupMembers();	--GetNumPartyMembers();
				inbonquest = 0;
				for l = 1 , inbmembregroupe do
					if ( IsUnitOnQuest(bencoursk, "party"..l) ) then
						inbonquest = inbonquest + 1;
					end
				end
				if ( inbonquest > 0 ) then
					itemChamp:SetText(inbonquest);
				else
					if ( tablo[27] == 1 ) then
						itemChamp:SetText("0");
					end
				end
			end
			_G[buttonName.."_Abandon"]:Hide();
			if ( bencours == 1 ) then
				_G[buttonName.."_Abandon"]:Show();
			end
			_G[buttonName.."_ObjetRecquis1"]:Hide();
			_G[buttonName.."_ObjetRecquis2"]:Hide();
			_G[buttonName.."_ObjetRecquis3"]:Hide();
			_G[buttonName.."_ObjetRecquis4"]:Hide();
			_G[buttonName.."_ObjetRecquis5"]:Hide();
			_G[buttonName.."_ObjetRecquis6"]:Hide();
			_G[buttonName.."_ObjetRecquis7"]:Hide();
			_G[buttonName.."_ObjetRecquis8"]:Hide();
			_G[buttonName.."_ObjetRecquis9"]:Hide();
			_G[buttonName.."_ObjetRecquis10"]:Hide();
			_G[buttonName.."_MobRecquis1"]:Hide();
			_G[buttonName.."_MobRecquis2"]:Hide();
			_G[buttonName.."_MobRecquis3"]:Hide();
			_G[buttonName.."_MobRecquis4"]:Hide();
			_G[buttonName.."_MobRecquis5"]:Hide();
			_G[buttonName.."_MobRecquis6"]:Hide();
			_G[buttonName.."_MobRecquis7"]:Hide();
			_G[buttonName.."_MobRecquis8"]:Hide();
			_G[buttonName.."_MobRecquis9"]:Hide();
			_G[buttonName.."_MobRecquis10"]:Hide();
			_G[buttonName.."_ObjetObtenus1"]:Hide();
			_G[buttonName.."_ObjetObtenus2"]:Hide();
			_G[buttonName.."_ObjetObtenus3"]:Hide();
			_G[buttonName.."_ObjetObtenus4"]:Hide();
			_G[buttonName.."_ObjetObtenus5"]:Hide();
			_G[buttonName.."_ObjetObtenus6"]:Hide();
			_G[buttonName.."_ObjetObtenus7"]:Hide();
			_G[buttonName.."_ObjetObtenus8"]:Hide();
			_G[buttonName.."_ObjetObtenus9"]:Hide();
			_G[buttonName.."_ObjetObtenus10"]:Hide();
			_G[buttonName.."_ObjetChoix1"]:Hide();
			_G[buttonName.."_ObjetChoix2"]:Hide();
			_G[buttonName.."_ObjetChoix3"]:Hide();
			_G[buttonName.."_ObjetChoix4"]:Hide();
			_G[buttonName.."_ObjetChoix5"]:Hide();
			_G[buttonName.."_ObjetChoix6"]:Hide();
			_G[buttonName.."_ObjetChoix7"]:Hide();
			_G[buttonName.."_ObjetChoix8"]:Hide();
			_G[buttonName.."_ObjetChoix9"]:Hide();
			_G[buttonName.."_ObjetChoix10"]:Hide();
			if ( tablo[14] ) then
				j = 0;
				for numobjet, _ in pairs(tablo[14]) do
					j = j + 1;
					if ( j < 11 ) then
						tDETAILOBJET = DBOS_detail(numobjet,"0:0:0:0:0:0:0:0:0:0");
						if ( tDETAILOBJET.nomobjet ) then
							_G[buttonName.."_ObjetRecquis"..j.."_IconTexture"]:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							_G[buttonName.."_ObjetRecquis"..j.."_IconTexture"]:SetTexture(tDETAILOBJET.texture);
							_G[buttonName.."_ObjetRecquis"..j]:Show();
						else
							_G[buttonName.."_ObjetRecquis"..j.."_IconTexture"]:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							_G[buttonName.."_ObjetRecquis"..j]:Show();
						end
					end
				end
			end
			if ( tablo[22] and tablo[23] and ( table.getn(tablo[22]) == table.getn(tablo[23]) ) ) then
				j = 0;
				for k = 1 , table.getn(tablo[23]) do
					if ( tablo[23][k] == "monster" or tablo[23][k] == "object" or tablo[23][k] == "event" ) then
						j = j + 1;
						_G[buttonName.."_MobRecquis"..j.."_IconTexture"]:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
						_G[buttonName.."_MobRecquis"..j]:Show();
					end
				end
			end
			if ( tablo[15] ) then
				j = 0;
				for numobjet, _ in pairs(tablo[15]) do
					j = j + 1;
					if ( j < 11 ) then
						tDETAILOBJET = DBOS_detail(numobjet,"0:0:0:0:0:0:0:0:0:0");
						if ( tDETAILOBJET.nomobjet ) then
							_G[buttonName.."_ObjetObtenus"..j.."_IconTexture"]:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							_G[buttonName.."_ObjetObtenus"..j.."_IconTexture"]:SetTexture(tDETAILOBJET.texture);
							_G[buttonName.."_ObjetObtenus"..j]:Show();
						else
							_G[buttonName.."_ObjetObtenus"..j.."_IconTexture"]:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							_G[buttonName.."_ObjetObtenus"..j]:Show();
						end
					end
				end
			end
			if ( tablo[16] ) then
				j = 0;
				for numobjet, _ in pairs(tablo[16]) do
					j = j + 1;
					if ( j < 11 ) then
						tDETAILOBJET = DBOS_detail(numobjet,"0:0:0:0:0:0:0:0:0:0");
						if ( tDETAILOBJET.nomobjet ) then
							_G[buttonName.."_ObjetChoix"..j.."_IconTexture"]:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							_G[buttonName.."_ObjetChoix"..j.."_IconTexture"]:SetTexture(tDETAILOBJET.texture);
							_G[buttonName.."_ObjetChoix"..j]:Show();
						else
							_G[buttonName.."_ObjetChoix"..j.."_IconTexture"]:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							_G[buttonName.."_ObjetChoix"..j]:Show();
						end
					end
				end
			end
			button:Show();
		end
	end

	if ( isav ) then
		if ( isav == GetQuestLogSelection() ) then
		else
			SelectQuestLogEntry(isav);
		end
	end

end

function DBcorps_ListQuetes2_Item_Nomquete_OnEnter(self,index,ipartie)

local smessage;
local stexte;
local i;
local nb;
local tablo;
local bencours;

local isav;
local bfin;
local nomquete_log;
local isHeader;
local objectif_log;
local nbsousobjectifs;
local j;
local nomsousobj_log;
local typsousobj_log;
local inumindex;

	GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
	smessage = "Qu\195\170te : "..DBCORPS_QUETES2_LISTE[index][1];
	tablo = DBQS2_Detail(DBCORPS_QUETES2_LISTE[index][0]);
	if ( ipartie == 1 ) then
		stexte = DBCORPS_QUETES2_LISTE[index][2];
		if ( stexte == nil ) then
			stexte = "";
		end
		nb = strlen(stexte);
		if ( nb > 0 ) then
			smessage = smessage.."\n\nOBJECTIF : \n\n";
		end
		smessage = smessage..DBCS_formattext(stexte,50);
		bencours = 0;
		if ( DBQS2_tquetesencours[DBCORPS_QUETES2_LISTE[index][0]] ) then
			bencours = 1;
			inumindex = DBQS2_tquetesencours[DBCORPS_QUETES2_LISTE[index][0]][3];
			nbsousobjectifs = GetNumQuestLeaderBoards(inumindex);	--	GetNumQuestLogLeaderBoards();	--	[questID]
			if ( nbsousobjectifs > 0 ) then
				--DBquetes_lirelog(inumindex);
				smessage = smessage.."\n\nSous-Objectifs :\n";
				for j = 1, nbsousobjectifs do
					nomsousobj_log, _, _ = GetQuestLogLeaderBoard(j,inumindex);	--	, [questID]
					smessage = smessage.."\n"..(nomsousobj_log or "bug sur obj "..j);
				end
			end
		end
		if ( bencours == 0 and tablo ) then
			--end
			if ( tablo[30] ) then
				smessage = smessage.."\n\nSous-Objectifs :\n";
				for i = 1,tablo[30] do
					smessage = smessage.."\n"..(tablo[30+i] or "");
				end
			elseif ( tablo[22] ) then
				smessage = smessage.."\n\nSous-Objectifs :\n";
				for i = 1,table.getn(tablo[22]) do
					smessage = smessage.."\n"..(tablo[22][i] or "");
				end
			end
		end
		if ( tablo[7] and tablo[7] > 0 ) then
			smessage = smessage.."\n\nDerni\195\168re fois vue par DBCS dans un journal : "..tablo[7];
		end
	elseif ( ipartie == 2 ) then
		stexte = tablo[4];
		if ( stexte == nil ) then
			stexte = "";
		end
		nb = strlen(stexte);
		if ( nb > 0 ) then
			smessage = smessage.."\n\nDESCRIPTIF : \n\n";
		end
		smessage = smessage..DBCS_formattext(stexte,50);
		if ( tablo[8] and tablo[8] > 0 ) then
			smessage = smessage.."\n\nDerni\195\168re fois vue par DBCS sur un pnj : "..tablo[8];
		end
	elseif ( ipartie == 3 ) then
		stexte = tablo[9];
		if ( stexte == nil ) then
			stexte = "";
		end
		nb = strlen(stexte);
		if ( nb > 0 ) then
			smessage = smessage.."\n\nPROGRESSION : \n\n";
		end
		smessage = smessage..DBCS_formattext(stexte,50);
		if ( tablo[10] and tablo[10] > 0 ) then
			smessage = smessage.."\n\nargent requis : "..DBCS_montant_vers_chaine(tablo[10]);
		end
		if ( tablo[41] and tablo[41] > 0 ) then
			smessage = smessage.."\n\nDerni\195\168re fois vue la progression par DBCS sur un pnj : "..tablo[41];
		end
	elseif ( ipartie == 4 ) then
		stexte = tablo[17];
		if ( stexte == nil ) then
			stexte = "";
		end
		nb = strlen(stexte);
		if ( nb > 0 ) then
			smessage = smessage.."\n\nFIN : \n\n";
		end
		smessage = smessage..DBCS_formattext(stexte,50);
		if ( tablo[11] and tablo[11] > 0 ) then
			smessage = smessage.."\n\nsalaire pour les non "..DBCS_nivmax_MOP.." : "..DBCS_montant_vers_chaine(tablo[11]);
		end
		if ( tablo[12] and tablo[12] > 0 ) then
			smessage = smessage.."\n\nsalaire pour les "..DBCS_nivmax.." : "..DBCS_montant_vers_chaine(tablo[12]);
		end
		if ( tablo[45] and tablo[45] > 0 ) then
			smessage = smessage.."\n\nsalaire pour les "..DBCS_nivmax_wotlk.." : "..DBCS_montant_vers_chaine(tablo[45]);
		end
		if ( tablo[48] and tablo[48] > 0 ) then
			smessage = smessage.."\n\nsalaire pour les "..DBCS_nivmax_CT.." : "..DBCS_montant_vers_chaine(tablo[48]);
		end
		if ( tablo[49] and tablo[49] > 0 ) then
			smessage = smessage.."\n\nsalaire pour les "..DBCS_nivmax_MOP.." : "..DBCS_montant_vers_chaine(tablo[49]);
		end
		if ( tablo[42] and tablo[42] > 0 ) then
			smessage = smessage.."\n\nDerni\195\168re fois vue la fin par DBCS sur un pnj : "..tablo[42];
		end
		if ( DBHC_perso and DBHC_perso[DBCORPS_QUETES2_LISTE[index][0]] ) then
			if ( DBHC_perso[DBCORPS_QUETES2_LISTE[index][0]] == 0 or DBHC_perso[DBCORPS_QUETES2_LISTE[index][0]] == -1 ) then
				smessage = smessage.."\n\nQu\195\170te termin\195\169e le : date inconnue";
			else
				smessage = smessage.."\n\nQu\195\170te termin\195\169e le : "..DBHC_perso[DBCORPS_QUETES2_LISTE[index][0]];
			end
		end
	else
	end
	GameTooltip:AddLine(smessage);
	GameTooltip:Show();

end

function DBcorps_ListQuetes2_Item_OnClick(index)

local i;
local k;
local activewindow;

	if ( ChatEdit_GetActiveWindow ) then
		activewindow = ChatEdit_GetActiveWindow();
	else
		activewindow = ChatFrameEditBox;
	end

	if ( IsShiftKeyDown() ) then
		if ( activewindow and activewindow:IsVisible() ) then
			--if ( DBCS_wow_2_4() == true ) then
				activewindow:Insert(DBQS2_lienquetebynum_nomquete(DBCORPS_QUETES2_LISTE[index][0]));
			--else
				--ChatFrameEditBox:Insert("["..(DBCORPS_QUETES2_LISTE[index][4] or "?").."] "..DBCORPS_QUETES2_LISTE[index][1].."]");
			--end
		else
			if ( DBQS2_tquetesencours[DBCORPS_QUETES2_LISTE[index][0]] ) then
				k = DBQS2_tquetesencours[DBCORPS_QUETES2_LISTE[index][0]][3];
				if ( IsQuestWatched(k) ) then
					RemoveQuestWatch(k);
					--if ( DBquetes2_patch030100 == false ) then
					--	QuestWatch_Update();
					--else
						WatchFrame_Update();
					--end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("1DBcorps_ListQuetes2_Item_OnClick DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
					DBcorps_Quetes2_Scroll_Update();
				else
					-- Set error if no objectives
					if ( GetNumQuestLeaderBoards(k) == 0 ) then
						UIErrorsFrame:AddMessage(QUEST_WATCH_NO_OBJECTIVES, 1.0, 0.1, 0.1, 1.0, UIERRORS_HOLD_TIME);
						return;
					end
					-- Set an error message if trying to show too many quests
					if ( GetNumQuestWatches() >= MAX_WATCHABLE_QUESTS ) then
						UIErrorsFrame:AddMessage(format(QUEST_WATCH_TOO_MANY, MAX_WATCHABLE_QUESTS), 1.0, 0.1, 0.1, 1.0, UIERRORS_HOLD_TIME);
						return;
					end
					AddQuestWatch(k);
					--if ( DBquetes2_patch030100 == false ) then
					--	QuestWatch_Update();
					--else
						WatchFrame_Update();
					--end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("2DBcorps_ListQuetes2_Item_OnClick DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
					DBcorps_Quetes2_Scroll_Update();
				end
			end
		end
	end

end

function DBcorps_ListQuetes2_Item_Partage_OnEnter(self,index)

local inb_groupe;
local tablo_aquete = {};
local tablo_apasquete = {};
local k;
local l;
local snom;

	inb_groupe = GetNumSubgroupMembers();	--GetNumPartyMembers();
	if ( inb_groupe > 0 and DBQS2_tquetesencours[DBCORPS_QUETES2_LISTE[index][0]] ) then
		k = DBQS2_tquetesencours[DBCORPS_QUETES2_LISTE[index][0]][3];
		for l = 1 , inb_groupe do
			snom = UnitName("party"..l);
			if ( IsUnitOnQuest(k, "party"..l) ) then
				tablo_aquete[snom] = 1;
			else
				tablo_apasquete[snom] = 1;
			end
		end
		GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT");
		GameTooltip:AddLine("Membres du groupe n'ayant pas cette qu\195\170te : ");
		for snom, _ in pairs(tablo_apasquete) do
			GameTooltip:AddLine(snom);
		end
		GameTooltip:AddLine("\nMembres du groupe ayant cette qu\195\170te : ");
		for snom, _ in pairs(tablo_aquete) do
			GameTooltip:AddLine(snom);
		end
		GameTooltip:Show();
	else
		GameTooltip_AddNewbieTip(self,SHARE_QUEST, 1.0, 1.0, 1.0, NEWBIE_TOOLTIP_SHAREQUEST, 1);
	end

end

function DBcorps_ListQuetes2_Item_Partage_OnClick(index)

local k;

	if ( DBQS2_tquetesencours[DBCORPS_QUETES2_LISTE[index][0]] ) then
		k = DBQS2_tquetesencours[DBCORPS_QUETES2_LISTE[index][0]][3];
		SelectQuestLogEntry(k);
		QuestLogPushQuest();
	end

end

function DBcorps_ListQuetes2_Item_Abandon_OnClick(index)

local i;
local k;
local items;

	if ( DBQS2_tquetesencours[DBCORPS_QUETES2_LISTE[index][0]] ) then
		k = DBQS2_tquetesencours[DBCORPS_QUETES2_LISTE[index][0]][3];
		SelectQuestLogEntry(k);
		SetAbandonQuest();
		items = GetAbandonQuestItems();
		if ( items ) then
			StaticPopup_Hide("ABANDON_QUEST");
			StaticPopup_Show("ABANDON_QUEST_WITH_ITEMS", GetAbandonQuestName(), items);
		else
			StaticPopup_Hide("ABANDON_QUEST_WITH_ITEMS");
			StaticPopup_Show("ABANDON_QUEST", GetAbandonQuestName());
		end
	end

end

function DBcorps_ListQuetes2_Item_Objet_OnEnter(self,index,typeobjet,num,bclick)

local tablo;
local link;
local numobjet;
local inumobjetdetail;
local i,j,k;
local nommob;
local a,b;
local ia,ib;
local bexact;
local itemLink;
local activewindow;
local tobjet = nil;

	if ( ChatEdit_GetActiveWindow ) then
		activewindow = ChatEdit_GetActiveWindow();
	else
		activewindow = ChatFrameEditBox;
	end

	tablo = DBQS2_Detail(DBCORPS_QUETES2_LISTE[index][0]);
	if ( tablo ) then
		inumobjetdetail = 0;
		if ( typeobjet == "R" ) then
			if ( tablo[14] ) then
				i = 0;
				for numobjet, _ in pairs(tablo[14]) do
					i = i + 1;
					if ( i == num ) then
						inumobjetdetail = numobjet;
					end
				end
			end
		elseif ( typeobjet == "MR" ) then
			nommob = nil;
			j = 0;
			k = 0;
			bexact = true;
			for i = 1 , table.getn(tablo[23]) do
				if ( tablo[23][i] == "monster" or tablo[23][i] == "object" or tablo[23][i] == "event" ) then
					j = j + 1;
					if ( j == num ) then
						k = i;
						ia = strfind(tablo[22][k]," tu\195\169",1);
						if ( ia ) then
							nommob = strsub(tablo[22][k],1,ia-1);
						else
							ia = strfind(tablo[22][k],":",1);
							if ( ia ) then
								nommob = strsub(tablo[22][k],1,ia-3);
								bexact = false;
							else
								nommob = tablo[22][k];
							end
						end
					end
				else
					j = j + 1;
					if ( j == num ) then
						k = i;
						ia = strfind(tablo[22][k],":",1);
						if ( ia ) then
							nommob = strsub(tablo[22][k],1,ia-3);
						end
					end
				end
			end
			if ( bclick == 0 ) then
				if ( k > 0 ) then
					GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
					smessage = (nommob or "");
					GameTooltip:AddLine(smessage);
					GameTooltip:Show();
				else
					GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
					smessage = "petit bug, nom du mob introuvable";
					GameTooltip:AddLine(smessage);
					GameTooltip:Show();
				end
			else
				if ( nommob ) then
					DBcorps_ListMobs_Reset();
					-- ajout de % devant les - ds le nom du mob
					ia = 1;
					ib = 1;
					while ( ib > 0 ) do
						ib = strfind(nommob,"%-",ia);
						if ( ib ) then
							nommob = strsub(nommob,1,ib-1).."%-"..strsub(nommob,ib+1);
							ia = ib + 2;
						else
							ib = 0;
						end
					end
					if ( bexact == true ) then
						_G["DBcorpsFrame_MobsFrame_Criteres_Nommob"]:SetText("^"..nommob.."$");
					else
						_G["DBcorpsFrame_MobsFrame_Criteres_Nommob"]:SetText(nommob);
					end
					DBcorps_ListMobs_Update();
					if ( DBCORPS_MOBS_LISTE_nb == 0 ) then
						PlaySound("igQuestFailed");
					else
						PanelTemplates_SetTab(DBcorpsFrame, 1);
						DBcorps_ShowSubFrame(1);
					end
				end
			end
		elseif ( typeobjet == "O" ) then
			if ( tablo[15] ) then
				i = 0;
				for numobjet, _ in pairs(tablo[15]) do
					i = i + 1;
					if ( i == num ) then
						inumobjetdetail = numobjet;
					end
				end
			end
		elseif ( typeobjet == "C" ) then
			if ( tablo[16] ) then
				i = 0;
				for numobjet, _ in pairs(tablo[16]) do
					i = i + 1;
					if ( i == num ) then
						inumobjetdetail = numobjet;
					end
				end
			end
		end
		if ( inumobjetdetail > 0 ) then
			if ( bclick == 0 ) then
				link = DBobjets_link_dboa_OnEnter(inumobjetdetail);
				if ( GetItemInfo(link) ) then
					GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
					GameTooltip:SetHyperlink(link);
				else
					GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
					DBOS_SetHyperlink(inumobjetdetail);
				end
			else
				link = DBobjets_link_dboa_OnClick(inumobjetdetail);
				if ( IsShiftKeyDown() and activewindow and activewindow:IsVisible() ) then
					_, itemLink = GetItemInfo(link);
					if ( itemLink ) then
						activewindow:Insert(itemLink);
					else
						if ( inumobjetdetail > 50000 ) then
							tobjet = DBOS02[inumobjetdetail];
						else
							tobjet = DBOS01[inumobjetdetail];
						end
						if ( tobjet ) then
							activewindow:Insert(tobjet[1]);
						end
					end
				elseif ( IsControlKeyDown() ) then
					if ( GetItemInfo(link) ) then
						DressUpItemLink(DBobjets_GetItemLink(inumobjetdetail,"0:0:0:0:0:0:0:0:0:0",0));
					end
				elseif ( IsAltKeyDown() ) then
					GameTooltip:SetHyperlink(link);
					DBobjets_initobjet(link,0,0);
					DBcorps_Quetes_Scroll_Update();
				else
					DBCORPS_OBJET_CRITERES.numobjet = inumobjetdetail;
					DBCORPS_OBJET_CRITERES.numcourt2 = "0:0:0:0:0:0:0:0:0:0";
					DBCORPS_OBJET_CRITERES.detail = DBOS_detail(inumobjetdetail,"0:0:0:0:0:0:0:0:0:0");
					if ( DBCORPS_OBJET_CRITERES.detail.nomobjet ) then
						DBcorps_ListObjet_Criteres();
						DBCORPS_OBJET_LISTE = DBmobs_Liste_des_mobs_ayant_l_objet(DBCORPS_OBJET_CRITERES);
						DBCORPS_OBJET_LISTE_nb = table.getn(DBCORPS_OBJET_LISTE);
						_G["DBcorpsFrame_ObjetFrame_Criteres_Elements"]:SetText(DBCORPS_OBJET_LISTE_nb.." \195\169l\195\169ments trouv\195\169s.")
						DBcorps_ListObjet_Trier();
						if ( DBCORPS_OBJET_LISTE_nb > 0 ) then
							PanelTemplates_SetTab(DBcorpsFrame, 4);
							DBcorps_ShowSubFrame(4);
						else
							PlaySound("igQuestFailed");
						end
						DBcorpsFrame_ObjetFrame_Liste_ScrollFrameScrollBar:SetValue(0);
						DBcorps_Objet_Scroll_Update();
					else
						PlaySound("igQuestFailed");
					end
				end
			end
		end
	end

end

function DBcorps_ListQuetes2_Item_Debut_OnEnter(self,index)

local tablo;
local smessage;
local a;
local sregion;
local sxy;
local ipos;

local i;
local inumquete;
local idate;

local inumPNJ;
local inivcarte;

local bbon;

	tablo = DBQS2_Detail(DBCORPS_QUETES2_LISTE[index][0]);
	if ( DBCORPS_QUETES2_LISTE[index][7] and ( not ( DBCORPS_QUETES2_LISTE[index][7] == "" ) ) ) then
		GameTooltip:SetOwner(self, "ANCHOR_LEFT");
		if ( type(DBCORPS_QUETES2_LISTE[index][7]) == "string" ) then
			smessage = DBCORPS_QUETES2_LISTE[index][7];
			if ( DBPS2[DBCORPS_QUETES2_LISTE[index][7]] ) then
				bbon = false;
				for a, _ in pairs(DBPS2[DBCORPS_QUETES2_LISTE[index][7]]) do
					sregion = a;
					smessage = smessage.."\na "..DB_nomregionbynum(sregion);
					sxy = DBPS2[DBCORPS_QUETES2_LISTE[index][7]][sregion].xy;
					ipos = strfind(sxy,"@",2);
					if ( ipos ) then
						bbon = true;
						sxy = strsub(sxy,2,ipos-1);
						smessage = smessage.." en "..sxy;
					end
				end
				if ( bbon == true ) then
					smessage = smessage.."\n\nCTRL + cliquer pour voir les locs sur la carte";
				end
			end
		else
			inumPNJ = DBCORPS_QUETES2_LISTE[index][7];
			if ( DBmobs_Local and DBmobs_Local[inumPNJ] and DBmobs_Local[inumPNJ][1] and DBmobs_Local[inumPNJ][1][1] ) then
				smessage = DBmobs_Local[inumPNJ][1][1];
				if ( DBCS_mobs_locs and DBCS_mobs_locs[inumPNJ] ) then
					bbon = false;
					for sregion, _ in pairs(DBCS_mobs_locs[inumPNJ]) do
						for inivcarte, _ in pairs(DBCS_mobs_locs[inumPNJ][sregion]) do
							bbon = true;
							if ( inivcarte == 0 ) then
								smessage = smessage.."\na "..DBCS_Region_nom_region(sregion);
							else
								smessage = smessage.."\na "..DBCS_Region_nom_region(sregion)..", niveau "..inivcarte;
							end
						end
					end
					if ( bbon == true ) then
						smessage = smessage.."\n\nCTRL + cliquer pour voir les locs sur la carte";
					end
				end
				--DBCS_mobs_locs[inumpnj][sregion][inivcarte][imode] = sligne..smot..idate.."@";
			end
		end
		if ( tablo[24] ) then
			inumquete = -1;
			idate = -1;
			for i, _ in pairs(tablo[24]) do
				if ( tablo[24][i] > idate ) then
					inumquete = i;
					idate = tablo[24][i];
				end
			end
			if ( idate > -1 ) then
				smessage = smessage.."\n\nQu\195\170te pr\195\169c\195\169dente : \n\n";
				if ( DBquetes2[inumquete] ) then
					smessage = smessage..(DBquetes2[inumquete][0] or "").."\n\n";
					smessage = smessage..DBCS_formattext((DBquetes2[inumquete][1] or ""),50).."\n\n";
				else
					smessage = smessage..inumquete.."\n\n";
				end
				smessage = smessage.."\n\nCliquer pour voir la qu\195\170te pr\195\169c\195\169dente";
			end
		end
		GameTooltip:AddLine(smessage);
		GameTooltip:Show();
	end

end

function DBcorps_ListQuetes2_Item_Debut_OnClick(index)

local snomelement;
local sregion;
local i;
local a;
local sxy;

local tablo;
local j;

local inumquete;
local idate;

local inumPNJ;
local btrouve;
local inivcarte;

	if ( IsControlKeyDown() ) then
		if ( type(DBCORPS_QUETES2_LISTE[index][7]) == "string" ) then
			snomelement = DBCORPS_QUETES2_LISTE[index][7];
			if ( snomelement and ( not ( snomelement == "" ) ) ) then
				if ( DBPS2[snomelement] ) then
					sregion = nil;
					i = 0;
					for a, _ in pairs(DBPS2[snomelement]) do
						if ( a == "000" ) then
						else
							i = i + 1;
							if ( i == 1 ) then
								sregion = a;
							else
								if ( DB_nomregionbynum(a) == DBquetes2[DBCORPS_QUETES2_LISTE[index][0]][26] or DB_nomregionbynum(a) == DBquetes2[DBCORPS_QUETES2_LISTE[index][0]][20] ) then
									sregion = a;
								end
							end
						end
					end
					if ( sregion ) then
						sxy = DBPS2[snomelement][sregion].xy;
						--DBcorps_Afficherworldmap_element(sregion,snomelement,strsub(sxy,2),"@","X");
						DBCS_Region_Minimap_init_loc_hide();
						DBCS_Region_Minimap_init_loc(snomelement,sregion,0,sxy,"@","X");
					end
				end
			end
		else
			inumPNJ = DBCORPS_QUETES2_LISTE[index][7];
			if ( DBCS_mobs_locs and DBCS_mobs_locs[inumPNJ] ) then
				sregion, inivcarte = DBCS_Region_liste_code_region_courante_new();
				if ( DBCS_Region_Minimap_numregion and DBCS_Region_Minimap_nivcarte and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion] and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte] and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte][0] ) then
					DBCS_Region_Minimap_init_loc_hide();
					DBCS_Region_Minimap_init_loc(inumPNJ,DBCS_Region_Minimap_numregion,DBCS_Region_Minimap_nivcarte,DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte][0],"@","#","#");
				elseif ( DBCS_Region_Minimap_numregion and DBCS_Region_Minimap_nivcarte and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion] and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte] and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte][1] ) then
					DBCS_Region_Minimap_init_loc_hide();
					DBCS_Region_Minimap_init_loc(inumPNJ,DBCS_Region_Minimap_numregion,DBCS_Region_Minimap_nivcarte,DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte][1],"@","#","#");
				elseif ( sregion and inivcarte and DBCS_mobs_locs[inumPNJ][sregion] and DBCS_mobs_locs[inumPNJ][sregion][inivcarte] and DBCS_mobs_locs[inumPNJ][sregion][inivcarte][0] ) then
					DBCS_Region_Minimap_init_loc_hide();
					DBCS_Region_Minimap_init_loc(inumPNJ,sregion,inivcarte,DBCS_mobs_locs[inumPNJ][sregion][inivcarte][0],"@","#","#");
				elseif ( sregion and inivcarte and DBCS_mobs_locs[inumPNJ][sregion] and DBCS_mobs_locs[inumPNJ][sregion][inivcarte] and DBCS_mobs_locs[inumPNJ][sregion][inivcarte][1] ) then
					DBCS_Region_Minimap_init_loc_hide();
					DBCS_Region_Minimap_init_loc(inumPNJ,sregion,inivcarte,DBCS_mobs_locs[inumPNJ][sregion][inivcarte][1],"@","#","#");
				else
					btrouve = false;
					for sregion , _ in pairs(DBCS_mobs_locs[inumPNJ]) do
						if ( btrouve == false ) then
							for inivcarte , _ in pairs(DBCS_mobs_locs[inumPNJ][sregion]) do
								if ( btrouve == false and DBCS_mobs_locs[inumPNJ][sregion][inivcarte][0] ) then
									btrouve = true;
									--DBCS_Region_Minimap_init(sregion,inivcarte);
									DBCS_Region_Minimap_init_loc_hide();
									DBCS_Region_Minimap_init_loc(inumPNJ,sregion,inivcarte,DBCS_mobs_locs[inumPNJ][sregion][inivcarte][0],"@","#","#");
								elseif ( btrouve == false and DBCS_mobs_locs[inumPNJ][sregion][inivcarte][1] ) then
									btrouve = true;
									--DBCS_Region_Minimap_init(sregion,inivcarte);
									DBCS_Region_Minimap_init_loc_hide();
									DBCS_Region_Minimap_init_loc(inumPNJ,sregion,inivcarte,DBCS_mobs_locs[inumPNJ][sregion][inivcarte][1],"@","#","#");
								end
							end
						end
					end
				end
			end
		end
	else
		tablo = DBQS2_Detail(DBCORPS_QUETES2_LISTE[index][0]);
		if ( DBCORPS_QUETES2_LISTE[index][7] and ( not ( DBCORPS_QUETES2_LISTE[index][7] == "" ) ) ) then
			if ( tablo[24] ) then
				inumquete = -1;
				idate = -1;
				for i, _ in pairs(tablo[24]) do
					if ( tablo[24][i] > idate ) then
						inumquete = i;
						idate = tablo[24][i];
					end
				end
				if ( idate > -1 ) then
					DBCORPS_QUETES2_LISTE = DBquetes2_Liste_ajout(DBCORPS_QUETES2_LISTE,inumquete);
					j = 0;
					for i = 1 , table.getn(DBCORPS_QUETES2_LISTE) do
						if ( j == 0 and DBCORPS_QUETES2_LISTE[i][0] == inumquete ) then
							j = i;
						end
					end
					if ( j > 0 ) then
						DBCORPS_QUETES2_LISTE_nb = table.getn(DBCORPS_QUETES2_LISTE);
						_G["DBcorpsFrame_Quetes2Frame_Criteres_Elements"]:SetText(DBCORPS_QUETES2_LISTE_nb.." \195\169l\195\169ments trouv\195\169s.")
						-- refresh
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBcorps_ListQuetes2_Item_Debut_OnClick DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
						DBcorps_ListQuetes2_Trier();
						-- offset
						if ( DBCORPS_QUETES2_LISTE_nb > 10 ) then
							j = 0;
							for i = 1 , table.getn(DBCORPS_QUETES2_LISTE) do
								if ( j == 0 and DBCORPS_QUETES2_LISTE[i][0] == inumquete ) then
									j = i;
								end
							end
							if ( j == 0 ) then
								j = 1;
							end
							FauxScrollFrame_SetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame,j-1);
							DBcorpsFrame_Quetes2Frame_Liste_ScrollFrameScrollBar:SetValue((j-1)*32);
						end
						--FauxScrollFrame_OnVerticalScroll(32, DBcorps_Quetes2_Scroll_Update);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBcorps_ListQuetes2_Item_Debut_OnClick DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
						DBcorps_Quetes2_Scroll_Update();
					end
				end
			end
		end
	end

end

function DBcorps_ListQuetes2_Item_Fin_OnEnter(self,index)

local tablo;
local smessage;
local a;
local sregion;
local sxy;
local ipos;

local i;
local inumquete;
local idate;

local inumPNJ;
local inivcarte;

local bbon;

	tablo = DBQS2_Detail(DBCORPS_QUETES2_LISTE[index][0]);
	if ( DBCORPS_QUETES2_LISTE[index][8] and ( not ( DBCORPS_QUETES2_LISTE[index][8] == "" ) ) ) then
		GameTooltip:SetOwner(self, "ANCHOR_LEFT");
		if ( type(DBCORPS_QUETES2_LISTE[index][8]) == "string" ) then
			smessage = DBCORPS_QUETES2_LISTE[index][8];
			if ( DBPS2[DBCORPS_QUETES2_LISTE[index][8]] ) then
				bbon = false;
				for a, _ in pairs(DBPS2[DBCORPS_QUETES2_LISTE[index][8]]) do
					sregion = a;
					smessage = smessage.."\na "..DB_nomregionbynum(sregion);
					sxy = DBPS2[DBCORPS_QUETES2_LISTE[index][8]][sregion].xy;
					ipos = strfind(sxy,"@",2);
					if ( ipos ) then
						bbon = true;
						sxy = strsub(sxy,2,ipos-1);
						smessage = smessage.." en "..sxy;
					end
				end
				if ( bbon == true ) then
					smessage = smessage.."\n\nCTRL + cliquer pour voir les locs sur la carte";
				end
			end
		else
			inumPNJ = DBCORPS_QUETES2_LISTE[index][8];
			if ( DBmobs_Local and DBmobs_Local[inumPNJ] and DBmobs_Local[inumPNJ][1] and DBmobs_Local[inumPNJ][1][1] ) then
				smessage = DBmobs_Local[inumPNJ][1][1];
				if ( DBCS_mobs_locs and DBCS_mobs_locs[inumPNJ] ) then
					bbon = false;
					for sregion, _ in pairs(DBCS_mobs_locs[inumPNJ]) do
						for inivcarte, _ in pairs(DBCS_mobs_locs[inumPNJ][sregion]) do
							bbon = true;
							if ( inivcarte == 0 ) then
								smessage = smessage.."\na "..DBCS_Region_nom_region(sregion);
							else
								smessage = smessage.."\na "..DBCS_Region_nom_region(sregion)..", niveau "..inivcarte;
							end
						end
					end
					if ( bbon == true ) then
						smessage = smessage.."\n\nCTRL + cliquer pour voir les locs sur la carte";
					end
				end
				--DBCS_mobs_locs[inumpnj][sregion][inivcarte][imode] = sligne..smot..idate.."@";
			end
		end
		if ( tablo[25] ) then
			inumquete = -1;
			idate = -1;
			for i, _ in pairs(tablo[25]) do
				if ( tablo[25][i] > idate ) then
					inumquete = i;
					idate = tablo[25][i];
				end
			end
			if ( idate > -1 ) then
				smessage = smessage.."\n\nQu\195\170te suivante : \n\n";
				if ( DBquetes2[inumquete] ) then
					smessage = smessage..(DBquetes2[inumquete][0] or "").."\n\n";
					smessage = smessage..DBCS_formattext((DBquetes2[inumquete][1] or ""),50).."\n\n";
				else
					smessage = smessage..inumquete.."\n\n";
				end
				smessage = smessage.."\n\nCliquer pour voir la qu\195\170te suivante";
			end
		end
		GameTooltip:AddLine(smessage);
		GameTooltip:Show();
	end

end

function DBcorps_ListQuetes2_Item_Fin_OnClick(index)

local snomelement;
local sregion;
local i;
local a;
local sxy;

local tablo;
local j;

local inumquete;
local idate;

local inumPNJ;
local btrouve;
local inivcarte;

	if ( IsControlKeyDown() ) then
		if ( type(DBCORPS_QUETES2_LISTE[index][8]) == "string" ) then
			snomelement = DBCORPS_QUETES2_LISTE[index][8];
			if ( snomelement and ( not ( snomelement == "" ) ) ) then
				if ( DBPS2[snomelement] ) then
					sregion = nil;
					i = 0;
					for a, _ in pairs(DBPS2[snomelement]) do
						if ( a == "000" ) then
						else
							i = i + 1;
							if ( i == 1 ) then
								sregion = a;
							else
								if ( DB_nomregionbynum(a) == DBquetes2[DBCORPS_QUETES2_LISTE[index][0]][26] or DB_nomregionbynum(a) == DBquetes2[DBCORPS_QUETES2_LISTE[index][0]][20] ) then
									sregion = a;
								end
							end
						end
					end
					if ( sregion ) then
						sxy = DBPS2[snomelement][sregion].xy;
						--DBcorps_Afficherworldmap_element(sregion,snomelement,strsub(sxy,2),"@","X");
						DBCS_Region_Minimap_init_loc_hide();
						DBCS_Region_Minimap_init_loc(snomelement,sregion,0,sxy,"@","X");
					end
				end
			end
		else
			inumPNJ = DBCORPS_QUETES2_LISTE[index][8];
			if ( DBCS_mobs_locs and DBCS_mobs_locs[inumPNJ] ) then
				sregion, inivcarte = DBCS_Region_liste_code_region_courante_new();
				if ( DBCS_Region_Minimap_numregion and DBCS_Region_Minimap_nivcarte and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion] and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte] and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte][0] ) then
					DBCS_Region_Minimap_init_loc_hide();
					DBCS_Region_Minimap_init_loc(inumPNJ,DBCS_Region_Minimap_numregion,DBCS_Region_Minimap_nivcarte,DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte][0],"@","#","#");
				elseif ( DBCS_Region_Minimap_numregion and DBCS_Region_Minimap_nivcarte and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion] and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte] and DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte][1] ) then
					DBCS_Region_Minimap_init_loc_hide();
					DBCS_Region_Minimap_init_loc(inumPNJ,DBCS_Region_Minimap_numregion,DBCS_Region_Minimap_nivcarte,DBCS_mobs_locs[inumPNJ][DBCS_Region_Minimap_numregion][DBCS_Region_Minimap_nivcarte][1],"@","#","#");
				elseif ( sregion and inivcarte and DBCS_mobs_locs[inumPNJ][sregion] and DBCS_mobs_locs[inumPNJ][sregion][inivcarte] and DBCS_mobs_locs[inumPNJ][sregion][inivcarte][0] ) then
					DBCS_Region_Minimap_init_loc_hide();
					DBCS_Region_Minimap_init_loc(inumPNJ,sregion,inivcarte,DBCS_mobs_locs[inumPNJ][sregion][inivcarte][0],"@","#","#");
				elseif ( sregion and inivcarte and DBCS_mobs_locs[inumPNJ][sregion] and DBCS_mobs_locs[inumPNJ][sregion][inivcarte] and DBCS_mobs_locs[inumPNJ][sregion][inivcarte][1] ) then
					DBCS_Region_Minimap_init_loc_hide();
					DBCS_Region_Minimap_init_loc(inumPNJ,sregion,inivcarte,DBCS_mobs_locs[inumPNJ][sregion][inivcarte][1],"@","#","#");
				else
					btrouve = false;
					for sregion , _ in pairs(DBCS_mobs_locs[inumPNJ]) do
						if ( btrouve == false ) then
							for inivcarte , _ in pairs(DBCS_mobs_locs[inumPNJ][sregion]) do
								if ( btrouve == false and DBCS_mobs_locs[inumPNJ][sregion][inivcarte][0] ) then
									btrouve = true;
									--DBCS_Region_Minimap_init(sregion,inivcarte);
									DBCS_Region_Minimap_init_loc_hide();
									DBCS_Region_Minimap_init_loc(inumPNJ,sregion,inivcarte,DBCS_mobs_locs[inumPNJ][sregion][inivcarte][0],"@","#","#");
								elseif ( btrouve == false and DBCS_mobs_locs[inumPNJ][sregion][inivcarte][1] ) then
									btrouve = true;
									--DBCS_Region_Minimap_init(sregion,inivcarte);
									DBCS_Region_Minimap_init_loc_hide();
									DBCS_Region_Minimap_init_loc(inumPNJ,sregion,inivcarte,DBCS_mobs_locs[inumPNJ][sregion][inivcarte][1],"@","#","#");
								end
							end
						end
					end
				end
			end
		end
	else
		tablo = DBQS2_Detail(DBCORPS_QUETES2_LISTE[index][0]);
		if ( DBCORPS_QUETES2_LISTE[index][8] and ( not ( DBCORPS_QUETES2_LISTE[index][8] == "" ) ) ) then
			if ( tablo[25] ) then
				inumquete = -1;
				idate = -1;
				for i, _ in pairs(tablo[25]) do
					if ( tablo[25][i] > idate ) then
						inumquete = i;
						idate = tablo[25][i];
					end
				end
				if ( idate > -1 ) then
					DBCORPS_QUETES2_LISTE = DBquetes2_Liste_ajout(DBCORPS_QUETES2_LISTE,inumquete);
					j = 0;
					for i = 1 , table.getn(DBCORPS_QUETES2_LISTE) do
						if ( j == 0 and DBCORPS_QUETES2_LISTE[i][0] == inumquete ) then
							j = i;
						end
					end
					if ( j > 0 ) then
						DBCORPS_QUETES2_LISTE_nb = table.getn(DBCORPS_QUETES2_LISTE);
						_G["DBcorpsFrame_Quetes2Frame_Criteres_Elements"]:SetText(DBCORPS_QUETES2_LISTE_nb.." \195\169l\195\169ments trouv\195\169s.")
						-- refresh
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBcorps_ListQuetes2_Item_Fin_OnClick DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
						DBcorps_ListQuetes2_Trier();
						-- offset
						if ( DBCORPS_QUETES2_LISTE_nb > 10 ) then
							j = 0;
							for i = 1 , table.getn(DBCORPS_QUETES2_LISTE) do
								if ( j == 0 and DBCORPS_QUETES2_LISTE[i][0] == inumquete ) then
									j = i;
								end
							end
							if ( j == 0 ) then
								j = 1;
							end
							FauxScrollFrame_SetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame,j-1);
							DBcorpsFrame_Quetes2Frame_Liste_ScrollFrameScrollBar:SetValue((j-1)*32);
						end
						--FauxScrollFrame_OnVerticalScroll(32, DBcorps_Quetes2_Scroll_Update);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBcorps_ListQuetes2_Item_Fin_OnClick DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
						DBcorps_Quetes2_Scroll_Update();
					end
				end
			end
		end
	end

end

function DBcorps_ListQuetes2_Trier(sTRI,sINVERSER)

	--local t_ordre = {};
	local sSENS = DBCORPS_QUETES2_LISTE_sens;
	local sARROW = "DBcorpsFrame_Quetes2Frame_Tri_";

	if ( sTRI == nil ) then
		sTRI = DBCORPS_QUETES2_LISTE_ordre;
	end
	if ( sINVERSER == nil ) then
		sINVERSER = 0;
	end
	if ( sTRI == DBCORPS_QUETES2_LISTE_ordre ) then
		if ( sINVERSER == 1 ) then
			if ( sSENS == "ASC" ) then
				sSENS = "DESC";
			else
				sSENS = "ASC";
			end
			DBCORPS_QUETES2_LISTE_sens = sSENS;
		end
	else
		DBCORPS_QUETES2_LISTE_ordre = sTRI;
		sSENS = "ASC";
		DBCORPS_QUETES2_LISTE_sens = sSENS;
	end

	_G[sARROW.."Nomquete_Arrow"]:Hide();
	_G[sARROW.."Numquete_Arrow"]:Hide();
	_G[sARROW.."Nivmin_Arrow"]:Hide();
	_G[sARROW.."Nivconseil_Arrow"]:Hide();
	_G[sARROW.."Categorie_Arrow"]:Hide();
	_G[sARROW.."Type_Arrow"]:Hide();
	_G[sARROW.."Debut_Arrow"]:Hide();
	_G[sARROW.."Fin_Arrow"]:Hide();
	
	DBCORPS_QUETES2_TRI = {};
	if ( sTRI == "nomquete" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Nomquete_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Nomquete_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Nomquete_Arrow"]:Show();
		DBCORPS_QUETES2_TRI[1] = {};
		DBCORPS_QUETES2_TRI[1].champ = "nomquete";
		DBCORPS_QUETES2_TRI[1].sens = sSENS;
		DBCORPS_QUETES2_TRI[2] = {};
		DBCORPS_QUETES2_TRI[2].champ = "nivconseil";
		DBCORPS_QUETES2_TRI[2].sens = sSENS;
		DBCORPS_QUETES2_TRI[3] = {};
		DBCORPS_QUETES2_TRI[3].champ = "nivmin";
		DBCORPS_QUETES2_TRI[3].sens = sSENS;
	elseif ( sTRI == "numquete" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Numquete_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Numquete_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Numquete_Arrow"]:Show();
		DBCORPS_QUETES2_TRI[1] = {};
		DBCORPS_QUETES2_TRI[1].champ = "numquete";
		DBCORPS_QUETES2_TRI[1].sens = sSENS;
		DBCORPS_QUETES2_TRI[2] = {};
		DBCORPS_QUETES2_TRI[2].champ = "nomquete";
		DBCORPS_QUETES2_TRI[2].sens = sSENS;
		DBCORPS_QUETES2_TRI[3] = {};
		DBCORPS_QUETES2_TRI[3].champ = "nivconseil";
		DBCORPS_QUETES2_TRI[3].sens = sSENS;
		DBCORPS_QUETES2_TRI[4] = {};
		DBCORPS_QUETES2_TRI[4].champ = "nivmin";
		DBCORPS_QUETES2_TRI[4].sens = sSENS;
	elseif ( sTRI == "nivmin" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Nivmin_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Nivmin_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Nivmin_Arrow"]:Show();
		DBCORPS_QUETES2_TRI[1] = {};
		DBCORPS_QUETES2_TRI[1].champ = "nivmin";
		DBCORPS_QUETES2_TRI[1].sens = sSENS;
		DBCORPS_QUETES2_TRI[2] = {};
		DBCORPS_QUETES2_TRI[2].champ = "nivconseil";
		DBCORPS_QUETES2_TRI[2].sens = sSENS;
		DBCORPS_QUETES2_TRI[3] = {};
		DBCORPS_QUETES2_TRI[3].champ = "nomquete";
		DBCORPS_QUETES2_TRI[3].sens = sSENS;
	elseif ( sTRI == "nivconseil" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Nivconseil_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Nivconseil_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Nivconseil_Arrow"]:Show();
		DBCORPS_QUETES2_TRI[1] = {};
		DBCORPS_QUETES2_TRI[1].champ = "nivconseil";
		DBCORPS_QUETES2_TRI[1].sens = sSENS;
		DBCORPS_QUETES2_TRI[2] = {};
		DBCORPS_QUETES2_TRI[2].champ = "nivmin";
		DBCORPS_QUETES2_TRI[2].sens = sSENS;
		DBCORPS_QUETES2_TRI[3] = {};
		DBCORPS_QUETES2_TRI[3].champ = "nomquete";
		DBCORPS_QUETES2_TRI[3].sens = sSENS;
	elseif ( sTRI == "categorie" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Categorie_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Categorie_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Categorie_Arrow"]:Show();
		DBCORPS_QUETES2_TRI[1] = {};
		DBCORPS_QUETES2_TRI[1].champ = "categorie";
		DBCORPS_QUETES2_TRI[1].sens = sSENS;
		DBCORPS_QUETES2_TRI[2] = {};
		DBCORPS_QUETES2_TRI[2].champ = "nivconseil";
		DBCORPS_QUETES2_TRI[2].sens = sSENS;
		DBCORPS_QUETES2_TRI[3] = {};
		DBCORPS_QUETES2_TRI[3].champ = "nivmin";
		DBCORPS_QUETES2_TRI[3].sens = sSENS;
		DBCORPS_QUETES2_TRI[4] = {};
		DBCORPS_QUETES2_TRI[4].champ = "nomquete";
		DBCORPS_QUETES2_TRI[4].sens = sSENS;
	elseif ( sTRI == "type" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Type_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Type_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Type_Arrow"]:Show();
		DBCORPS_QUETES2_TRI[1] = {};
		DBCORPS_QUETES2_TRI[1].champ = "type";
		DBCORPS_QUETES2_TRI[1].sens = sSENS;
		DBCORPS_QUETES2_TRI[2] = {};
		DBCORPS_QUETES2_TRI[2].champ = "nivconseil";
		DBCORPS_QUETES2_TRI[2].sens = sSENS;
		DBCORPS_QUETES2_TRI[3] = {};
		DBCORPS_QUETES2_TRI[3].champ = "nivmin";
		DBCORPS_QUETES2_TRI[3].sens = sSENS;
		DBCORPS_QUETES2_TRI[4] = {};
		DBCORPS_QUETES2_TRI[4].champ = "nomquete";
		DBCORPS_QUETES2_TRI[4].sens = sSENS;
	elseif ( sTRI == "debut" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Debut_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Debut_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Debut_Arrow"]:Show();
		DBCORPS_QUETES2_TRI[1] = {};
		DBCORPS_QUETES2_TRI[1].champ = "debut";
		DBCORPS_QUETES2_TRI[1].sens = sSENS;
		DBCORPS_QUETES2_TRI[2] = {};
		DBCORPS_QUETES2_TRI[2].champ = "nivconseil";
		DBCORPS_QUETES2_TRI[2].sens = sSENS;
		DBCORPS_QUETES2_TRI[3] = {};
		DBCORPS_QUETES2_TRI[3].champ = "nivmin";
		DBCORPS_QUETES2_TRI[3].sens = sSENS;
		DBCORPS_QUETES2_TRI[4] = {};
		DBCORPS_QUETES2_TRI[4].champ = "nomquete";
		DBCORPS_QUETES2_TRI[4].sens = sSENS;
	elseif ( sTRI == "fin" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Fin_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Fin_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Fin_Arrow"]:Show();
		DBCORPS_QUETES2_TRI[1] = {};
		DBCORPS_QUETES2_TRI[1].champ = "fin";
		DBCORPS_QUETES2_TRI[1].sens = sSENS;
		DBCORPS_QUETES2_TRI[2] = {};
		DBCORPS_QUETES2_TRI[2].champ = "nivconseil";
		DBCORPS_QUETES2_TRI[2].sens = sSENS;
		DBCORPS_QUETES2_TRI[3] = {};
		DBCORPS_QUETES2_TRI[3].champ = "nivmin";
		DBCORPS_QUETES2_TRI[3].sens = sSENS;
		DBCORPS_QUETES2_TRI[4] = {};
		DBCORPS_QUETES2_TRI[4].champ = "nomquete";
		DBCORPS_QUETES2_TRI[4].sens = sSENS;
	else
		if ( sSENS == "ASC" ) then
			--_G[sARROW.."Nomquete_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			--_G[sARROW.."Nomquete_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		--_G[sARROW.."Nomquete_Arrow"]:Show();
		DBCORPS_QUETES2_TRI[1] = {};
		DBCORPS_QUETES2_TRI[1].champ = "nomquete";
		DBCORPS_QUETES2_TRI[1].sens = sSENS;
		DBCORPS_QUETES2_TRI[2] = {};
		DBCORPS_QUETES2_TRI[2].champ = "nivmin";
		DBCORPS_QUETES2_TRI[2].sens = sSENS;
		DBCORPS_QUETES2_TRI[3] = {};
		DBCORPS_QUETES2_TRI[3].champ = "nivconseil";
		DBCORPS_QUETES2_TRI[3].sens = sSENS;
	end

	table.sort(DBCORPS_QUETES2_LISTE,DBcorps_ListQuetes2_Trier_sort);

--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBcorps_ListQuetes2_Trier DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
	DBcorps_Quetes2_Scroll_Update();

end

function DBcorps_ListQuetes2_Trier_sort(elem1,elem2)

	return DBquetes2_Trier(elem1,elem2,DBCORPS_QUETES2_TRI,1);

end

function DBcorps_ListQuetes2_Reset()

	local item_base = "DBcorpsFrame_Quetes2Frame_Criteres_";

	_G[item_base.."Nomquete"]:SetText("");
	_G[item_base.."Nivmin"]:SetText("");
	_G[item_base.."Nivmax"]:SetText("");
	_G[item_base.."Categorie"]:SetText("");
	_G[item_base.."Type"]:SetText("");
	_G[item_base.."Debut"]:SetText("");
	_G[item_base.."Fin"]:SetText("");
	_G[item_base.."Encours"]:SetChecked(1);
	--_G[item_base.."Journaliere"]:SetChecked(0);
	DBcorpsFrame_Quetes2Frame_Criteres_Faction_OnLoad();
	UIDropDownMenu_SetSelectedValue(DBcorpsFrame_Quetes2Frame_Criteres_Faction,-1);
	DBcorpsFrame_Quetes2Frame_Criteres_Terminee_OnLoad();
	UIDropDownMenu_SetSelectedValue(DBcorpsFrame_Quetes2Frame_Criteres_Terminee,-1);

end

function DBcorps_ListQuetes2_Update()

local criteres = {};
local item_base = "DBcorpsFrame_Quetes2Frame_Criteres_";
local nbquetes;

	DBquetes2_quetesencours();

	criteres.nomquete = _G[item_base.."Nomquete"]:GetText();
	criteres.nivmin = tonumber(_G[item_base.."Nivmin"]:GetText());
	criteres.nivmax = tonumber(_G[item_base.."Nivmax"]:GetText());
	criteres.categorie = _G[item_base.."Categorie"]:GetText();
	criteres.type = _G[item_base.."Type"]:GetText();
	criteres.debut = _G[item_base.."Debut"]:GetText();
	criteres.fin = _G[item_base.."Fin"]:GetText();
	criteres.encours = _G[item_base.."Encours"]:GetChecked();
	if ( criteres.encours == nil ) then
		criteres.encours = 0;
	end
	--criteres.encours = 1;
	criteres.journaliere = _G[item_base.."Journaliere"]:GetChecked();
	if ( criteres.journaliere == nil ) then
		criteres.journaliere = 0;
	end
	criteres.faction = UIDropDownMenu_GetSelectedValue(DBcorpsFrame_Quetes2Frame_Criteres_Faction);
	criteres.terminee = UIDropDownMenu_GetSelectedValue(DBcorpsFrame_Quetes2Frame_Criteres_Terminee);

	FauxScrollFrame_SetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame,0);
	
	DBcorpsFrame_Quetes2Frame_Liste_ScrollFrameScrollBar:SetValue(0);

	DBCORPS_QUETES2_LISTE = DBquetes2_Liste(criteres);
	DBCORPS_QUETES2_LISTE_nb = table.getn(DBCORPS_QUETES2_LISTE);
	if ( criteres.encours == 1 and criteres.journaliere == 0 and ( criteres.nomquete == nil or criteres.nomquete == "" ) and criteres.nivmin == nil and criteres.nivmax == nil and ( criteres.categorie == nil or criteres.categorie == "" ) and ( criteres.type == nil or criteres.type == "" ) and ( criteres.debut == nil or criteres.debut == "" ) and ( criteres.fin == nil or criteres.fin == "" ) ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("je ne listes que les quetes en cours.");
--end
		_, nbquetes = GetNumQuestLogEntries();
		if ( nbquetes == DBCORPS_QUETES2_LISTE_nb ) then
		else
if ( DBCS_debug > 1 ) then
			--if ( DBCS_wow_2_4() == true ) then
TraceFrame:AddMessage("Certaines quetes de votre journal ne sont pas connues par DBCS.\nVeuillez cliquer sur elles dans votre journal.");
			--end
end
		end
	end
	_G["DBcorpsFrame_Quetes2Frame_Criteres_Elements"]:SetText(DBCORPS_QUETES2_LISTE_nb.." \195\169l\195\169ments trouv\195\169s.")
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBcorps_ListQuetes2_Update DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
	DBcorps_ListQuetes2_Trier();

end

--/script DBQS2_initnumquete_dsDBQS();
function DBQS2_initnumquete_dsDBQS()

local tablo;
local inumquete;
local snomquete;
local sobjectif;
local i;

	tablo = {};
	for inumquete, _ in pairs(DBquetes2) do
		snomquete = DBquetes2[inumquete][0];
		if ( snomquete == nil ) then
			snomquete = "";
		end
		if ( tablo[snomquete] == nil ) then
			tablo[snomquete] = {};
		end
		sobjectif = DBquetes2[inumquete][1];
		if ( sobjectif == nil ) then
			sobjectif = "";
		end
		if ( tablo[snomquete][sobjectif] == nil ) then
			tablo[snomquete][sobjectif] = {};
		end
		table.insert(tablo[snomquete][sobjectif],inumquete);
	end

	for inumquete, _ in pairs(DBquetes2) do
		snomquete = DBquetes2[inumquete][0];
		if ( snomquete == nil ) then
			snomquete = "";
		end
		sobjectif = DBquetes2[inumquete][1];
		if ( tablo[snomquete] and tablo[snomquete][sobjectif] ) then
			if ( table.getn(tablo[snomquete][sobjectif]) == 1 ) then
				if ( DBQS[snomquete] ) then
					for i = 1 , table.getn(DBQS[snomquete]) do
						if ( DBQS[snomquete][i][1] == sobjectif and DBQS[snomquete][i][7] == nil ) then
							DBQS[snomquete][i][7] = inumquete;
						end
					end
				end
			end
		end
	end

end

function DBQS2_lienquetebynum_nomquete(inum)

local snomquete;
local inivquete;

	if ( inum ) then
		snomquete = "blabla";
		inivquete = -1;
		if ( DBquetes2[inum] ) then
			if ( DBquetes2[inum][0] ) then
				snomquete = DBquetes2[inum][0];
			end
			if ( DBquetes2[inum][-2] ) then
				inivquete = DBquetes2[inum][-2];
			end
		end
		return "|cffffff00|Hquest:"..inum..":"..inivquete.."|h["..snomquete.."]|h|r"
	else
		return nil;
	end

end

function DBquetes2_liregossip()

local tq_activelist;
local tq_availablelist;
local nb;
local snompnj;
local snumregion;
local x,y;

	tq_activelist = {GetGossipActiveQuests()};
	tq_availablelist = {GetGossipAvailableQuests()};
	if ( table.getn(tq_activelist) > 0 or table.getn(tq_availablelist) > 0 ) then
		snompnj = UnitName("npc");
		snumregion = DBCS_Region_liste_code_region_courante_new();	--DBCS_numregionbyname(GetRealZoneText());
		x,y = DBCS_position100();
		DBPS2_enregpnj(snompnj,snumregion,x,y,1);
	end
	
end

function DBPS2_enregpnj(snompnj,snumregion,x,y,benvoyer)

local sposition,ipos;
--local slangue;
	
	if ( benvoyer == nil ) then
		benvoyer = 0;
	end

	if ( snompnj == nil ) then
		return nil;
	end
	if ( DBPS2[snompnj] == nil ) then
		DBPS2[snompnj] = {};
	end
	if ( DBPS2[snompnj][snumregion] == nil ) then
		DBPS2[snompnj][snumregion] = {};
	end
	if ( DBPS2[snompnj][snumregion].xy == nil ) then
		DBPS2[snompnj][snumregion].xy = "@";
	end
	if ( x == 0 and y == 0 ) then
	else
		sposition = x.."X"..y.."@";
		ipos = strfind(DBPS2[snompnj][snumregion].xy,"@"..sposition,1);
		if ( ipos == nil ) then
			DBPS2[snompnj][snumregion].xy = DBPS2[snompnj][snumregion].xy..sposition;
--TraceFrame:AddMessage(snompnj.." en "..x.." "..y.." dans la region "..snumregion);
		end
	end
	--DBPC = {};
	--slangue = GetLocale();
	if ( DBCS_prog_serveur == 1 ) then
	else
		if ( DBPC[DBCS_getlocale] == nil ) then
			DBPC[DBCS_getlocale] = {};
		end
		if ( DBPC[DBCS_getlocale][snompnj] == nil ) then
			DBPC[DBCS_getlocale][snompnj] = {};
		end
		if ( DBPC[DBCS_getlocale][snompnj][snumregion] == nil ) then
			DBPC[DBCS_getlocale][snompnj][snumregion] = {};
		end
		if ( DBPC[DBCS_getlocale][snompnj][snumregion].xy == nil ) then
			DBPC[DBCS_getlocale][snompnj][snumregion].xy = "";
		end
		if ( x == 0 and y == 0 ) then
		else
			sposition = x.."X"..y.."@";
			ipos = strfind(DBPC[DBCS_getlocale][snompnj][snumregion].xy,sposition,1);
			if ( ipos == nil ) then
				DBPC[DBCS_getlocale][snompnj][snumregion].xy = DBPC[DBCS_getlocale][snompnj][snumregion].xy..sposition;
			end
		end
	end
	if ( benvoyer == 1 ) then
		if ( DBCS_CMS_numcanalCMS > 0 ) then
			senreg = "@ADBQS@"..DBCS_getlocale.."@PA02@"..snompnj.."@"..snumregion.."@"..x.."@"..y.."@";
			DBCS_SendChatMessage(senreg,"CHANNEL",DBCS_language,DBCS_CMS_numcanalCMS);
		end
	end

end

DBQS2_tablo_toutesquetes_par_nometobjectif = {};

function DBQS2_toutesquetes_par_nometobjectif()

local inumquete;
local snom;
local sobjectif;

	DBQS2_tablo_toutesquetes_par_nometobjectif = {};
	for inumquete, _ in pairs(DBquetes2) do
		snom = DBquetes2[inumquete][0];
		sobjectif = DBquetes2[inumquete][1];
		DBQS2_toutesquetes_par_nometobjectif_ajout(inumquete,snom,sobjectif);
	end

end

function DBQS2_toutesquetes_par_nometobjectif_ajout(inumquete,snom,sobjectif)

	if ( inumquete == nil ) then
		inumquete = 0;
	end
	if ( snom == nil ) then
		snom = "";
	end
	if ( sobjectif == nil ) then
		sobjectif = "";
	end
	if ( DBQS2_tablo_toutesquetes_par_nometobjectif[snom] == nil ) then
		DBQS2_tablo_toutesquetes_par_nometobjectif[snom] = {};
	end
	if ( DBQS2_tablo_toutesquetes_par_nometobjectif[snom][sobjectif] == nil ) then
		DBQS2_tablo_toutesquetes_par_nometobjectif[snom][sobjectif] = {};
	end
	DBQS2_tablo_toutesquetes_par_nometobjectif[snom][sobjectif][inumquete] = 1;

end

function DBquetes2_quetesencours()

local inbquetes;
local isav;
local nb;
local i;
local j;
local scategorie;
local questLogTitleText;
local level;
local inivmin;
local questTag;
local suggestedGroup;
local isHeader;
--local isCollapsed;
local isComplete;
local isDaily;
local slink;
local snumitemcourt, snumitemlong, isComplete;
local ipos;
local ipos2;
local inumquete;
local inivquete;

local questDescription;
local questObjectives;

local numQuestLogLeaderBoards;

local sdesc;
local stype;
local bdone;
local bexist;
local rewardMoney;
local inbjcons;

local inbobj_obtenus;
local inbobj_choix;
local inb;
local inumobjet;
local sfaction;

local bpush;
local imodif;

local tablo;
local itypequetejournaliere;

	DBQS2_logdispo = 0;

	DBQS2_tquetesencours = {};

	_, inbquetes = GetNumQuestLogEntries();
	DBcorpsFrame_Quetes2Frame_Criteres_Encours_Nb:SetText(inbquetes.." / "..MAX_QUESTLOG_QUESTS);
	DBcorpsFrame_Quetes2Frame_Criteres_Journaliere_Nb:SetText("0 / 0");	--GetDailyQuestsCompleted().." / "..GetMaxDailyQuests());	--20120829
	
	DBQS2_quetes_journalieres_type_encours = DBQS2_quetes_journalieres_type;
	--DBQS2_quetes_journalieres;
--DBQS2_quetes_journalieres_type[01] = { provisoire = false, dejafait = false, encours = 0 , name = "P\195\170cheur" };
	if ( DBHC_perso ) then
		tablo = DBHC_perso;
		for inumquete, _ in pairs(tablo) do
			if ( inumquete > 0 ) then
				itypequetejournaliere = DBQS2_quetes_journalieres[inumquete];
				if ( itypequetejournaliere ) then
					if ( itypequetejournaliere > 0 ) then
						DBQS2_quetes_journalieres_type_encours[itypequetejournaliere].provisoire = false;
					end
					if ( type(tablo[inumquete]) == "number" and tablo[inumquete] == tonumber(DBCS_date()) ) then
						DBQS2_quetes_journalieres_type_encours[abs(itypequetejournaliere)].dejafait = true;
					end
				end
			end
		end
	end

	isav = GetQuestLogSelection();
	nb, _ = GetNumQuestLogEntries();	--	nbquetes
	for i = 1 , table.getn(DBQS2_quetes_journalieres_type_encours) do
		DBQS2_quetes_journalieres_type_encours[i].encours = 0;
	end
	for i = 1 , nb do
--	questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily = GetQuestLogTitle(questIndex);
		questLogTitleText, level, questTag, suggestedGroup, isHeader, _, isComplete, isDaily = GetQuestLogTitle(i);
		if ( isHeader ) then
			scategorie = questLogTitleText;
		else

			slink = GetQuestLink(i);
			_, snumitemcourt, snumitemlong, _, _ = DBQS2_GetMotItem(slink);
			ipos = strfind(snumitemcourt,":");
			if ( ipos ) then
				inumquete = tonumber(strsub(snumitemcourt,1,ipos-1));
				inivquete = tonumber(strsub(snumitemcourt,ipos+1));

				itypequetejournaliere = DBQS2_quetes_journalieres[inumquete];
				if ( itypequetejournaliere ) then
					DBQS2_quetes_journalieres_type_encours[abs(itypequetejournaliere)].encours = inumquete;
					if ( itypequetejournaliere > 0 ) then
						DBQS2_quetes_journalieres_type_encours[abs(itypequetejournaliere)].provisoire = false;
					end
				end

				--if ( DBquetes2[inumquete] == nil ) then
				--	DBQS2_ajout_quete(inumquete);
				--	--DBQS2_ajout_quete(inumquete);
				--end
				imodif = nil;
				bexist = true;
				if ( DBquetes2[inumquete] == nil ) then
					if ( DBCS_afficher_new_quetes == true ) then
						TraceFrame:AddMessage("Nouvelle qu\195\170te : id = "..inumquete);
						--TraceFrame:AddMessage("objectif : "..(DBquetes2_tempo_detail[1] or ""));
					end
					DBquetes2[inumquete] = {};
					DBquetes2[inumquete][44] = DBCS_date().."@"..DBCS_time();
					bexist = false;
				end

				if ( DBquetes2[inumquete][-2] == nil ) then
					DBquetes2[inumquete][-2] = inivquete;
					imodif = -2;
				else
					if ( DBquetes2[inumquete][-2] == inivquete ) then
					else
						DBquetes2[inumquete][-2] = inivquete;
						imodif = -2;
					end
				end

--TraceFrame:AddMessage("inumquete = "..inumquete);
				DBQS2_tquetesencours[inumquete] = {};
				DBQS2_tquetesencours[inumquete][2] = isComplete;
				DBQS2_tquetesencours[inumquete][3] = i;

				--if ( bexist == false ) then

					SelectQuestLogEntry(i);
					questDescription, questObjectives = GetQuestLogQuestText();

					--if ( bexist == false ) then
						if ( DBquetes2[inumquete][0] == nil ) then
							DBquetes2[inumquete][0] = questLogTitleText;
							imodif = 0;
						else
							--if ( DBquetes2[inumquete][0] == questLogTitleText ) then
							--else
							--	DBquetes2[inumquete][0] = questLogTitleText;
							--	imodif = 0;
							--end
						end
						if ( questObjectives ) then
							if ( DBquetes2[inumquete][1] == nil ) then
								DBquetes2[inumquete][1] = questObjectives;
								imodif = 1;
							else
								if ( DBquetes2[inumquete][1] == questObjectives ) then
								else
									DBquetes2[inumquete][1] = questObjectives;
									imodif = 1;
								end
							end
						end
					--end
					inivmin = UnitLevel("Player");
					if ( DBquetes2[inumquete][2] == nil ) then
						DBquetes2[inumquete][2] = inivmin;
						imodif = 2;
					else
						if ( inivmin < DBquetes2[inumquete][2] ) then
							DBquetes2[inumquete][2] = inivmin;
							imodif = 2;
						end
					end
					if ( DBquetes2[inumquete][3] == nil ) then
						DBquetes2[inumquete][3] = level;
						imodif = 3;
					else
						if ( DBquetes2[inumquete][3] == level ) then
						else
							DBquetes2[inumquete][3] = level;
							imodif = 3;
						end
					end
					if ( DBquetes2[inumquete][2] > DBquetes2[inumquete][3] ) then
						DBquetes2[inumquete][2] = DBquetes2[inumquete][3];
						imodif = 2;
					end
					if ( questDescription ) then
						if ( DBquetes2[inumquete][4] == nil ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("description1 : "..questDescription);
--end
							DBquetes2[inumquete][4] = questDescription;
							imodif = 4;
						else
							if ( DBquetes2[inumquete][4] == questDescription ) then
							else
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("description2 : "..questDescription);
--end
								DBquetes2[inumquete][4] = questDescription;
								imodif = 4;
							end
						end
					end
					sfaction, _ = UnitFactionGroup("player");
					if ( sfaction == "Alliance" ) then
						if ( DBquetes2[inumquete][18] == nil ) then
							DBquetes2[inumquete][18] = 1;	--	alliance
							imodif = 18;
						end
					elseif ( sfaction == "Horde" ) then
						if ( DBquetes2[inumquete][19] == nil ) then
							DBquetes2[inumquete][19] = 1;	--	horde
							imodif = 19;
						end
					end
					if ( scategorie and scategorie == DBQS2_missingheader ) then
					else
						if ( DBquetes2[inumquete][20] == nil ) then
							DBquetes2[inumquete][20] = scategorie;
							imodif = 20;
							DBquetes2[inumquete][26] = "#";
						else
							if ( DBquetes2[inumquete][20] == scategorie ) then
							else
								DBquetes2[inumquete][20] = scategorie;
								imodif = 20;
								DBquetes2[inumquete][26] = "#";
							end
						end
					end
					if ( questTag == nil or strlen(questTag) == 0 ) then
						if ( DBquetes2[inumquete][21] == nil ) then
							DBquetes2[inumquete][21] = "#";
							imodif = 21.1;
						else
							if ( DBquetes2[inumquete][21] == "#" ) then
							else
								DBquetes2[inumquete][21] = "#";
								imodif = 21.2;
							end
						end
					else
						if ( DBquetes2[inumquete][21] == nil ) then
							DBquetes2[inumquete][21] = questTag;
							imodif = 21.3;
						else
							if ( DBquetes2[inumquete][21] == questTag ) then
							else
								DBquetes2[inumquete][21] = questTag;
								imodif = 21.4;
							end
						end
					end

					numQuestLogLeaderBoards = GetNumQuestLeaderBoards(i);
			
					for j = 1 , numQuestLogLeaderBoards do
						if ( DBquetes2[inumquete][22] == nil ) then
							DBquetes2[inumquete][22] = {};
						end
						if ( DBquetes2[inumquete][23] == nil ) then
							DBquetes2[inumquete][23] = {};
						end
						sdesc, stype, bdone = GetQuestLogLeaderBoard(j,i);
						if ( DBquetes2[inumquete][22][j] == nil ) then
							DBquetes2[inumquete][22][j] = "";
							--imodif = 22;
						end
						if ( DBquetes2[inumquete][23][j] == nil ) then
							DBquetes2[inumquete][23][j] = "";
							imodif = 23;
						end
						if ( sdesc ) then
							ipos2 = strfind(sdesc,"\194\160:",1);
							if ( ipos2 ) then
								if ( ipos2 > 1 ) then
									if ( sdesc == DBquetes2[inumquete][22][j] ) then
									else
										DBquetes2[inumquete][22][j] = sdesc;
										--imodif = 22;
									end
								end
							else
								if ( sdesc == DBquetes2[inumquete][22][j] ) then
								else
									DBquetes2[inumquete][22][j] = sdesc;
									--imodif = 22;
								end
							end
--DBCS_ecrirecodedutexte(sdesc);							
							--if ( strlen(sdesc) > strlen(DBquetes2[inumquete][22][j]) ) then
							--	DBquetes2[inumquete][22][j] = sdesc;
							--	imodif = 22;
							--end
						end
						if ( stype ) then
							if ( strlen(stype) > strlen(DBquetes2[inumquete][23][j]) ) then
								DBquetes2[inumquete][23][j] = stype;
								imodif = 23;
							end
						end
					end

					SelectQuestLogEntry(i);
					rewardMoney = GetQuestLogRewardMoney();
					if ( rewardMoney and rewardMoney > 0 ) then
						--if ( DBQS2_WOTLK == false ) then
						--	if ( UnitLevel("Player") < DBCS_nivmax ) then
						--		if ( DBquetes2[inumquete][11] == nil ) then
						--			DBquetes2[inumquete][11] = rewardMoney;
						--			imodif = 11;
						--		else
						--			if ( DBquetes2[inumquete][11] == rewardMoney ) then
						--			else
						--				DBquetes2[inumquete][11] = rewardMoney;
						--				imodif = 11;
						--			end
						--		end
						--	else
						--		if ( DBquetes2[inumquete][12] == nil ) then
						--			DBquetes2[inumquete][12] = rewardMoney;
						--			imodif = 12;
						--		else
						--			if ( DBquetes2[inumquete][12] == rewardMoney ) then
						--			else
						--				DBquetes2[inumquete][12] = rewardMoney;
						--				imodif = 12;
						--			end
						--		end
						--	end
						--else
							--if ( UnitLevel("Player") < DBCS_nivmax_wotlk ) then
							--if ( UnitLevel("Player") < DBCS_nivmax_CT ) then
							if ( UnitLevel("Player") < DBCS_nivmax_MOP ) then
								if ( DBquetes2[inumquete][11] == nil ) then
									DBquetes2[inumquete][11] = rewardMoney;
									imodif = 11;
								else
									if ( DBquetes2[inumquete][11] == rewardMoney ) then
									else
										DBquetes2[inumquete][11] = rewardMoney;
										imodif = 11;
									end
								end
							else
								if ( DBquetes2[inumquete][49] == nil ) then
									DBquetes2[inumquete][49] = rewardMoney;
									imodif = 49;
								else
									if ( DBquetes2[inumquete][49] == rewardMoney ) then
									else
										DBquetes2[inumquete][49] = rewardMoney;
										imodif = 49;
									end
								end
							end
						--end
					end

					SelectQuestLogEntry(i);
					bpush = GetQuestLogPushable();
					if ( bpush ) then
						if ( DBquetes2[inumquete][27] == nil ) then
							DBquetes2[inumquete][27] = 1;
							imodif = 27;
						else
							if ( DBquetes2[inumquete][27] == 1 ) then
							else
								DBquetes2[inumquete][27] = 1;
								imodif = 27;
							end
						end
					else
						if ( DBquetes2[inumquete][27] == nil ) then
							DBquetes2[inumquete][27] = 0;
							imodif = 27;
						else
							if ( DBquetes2[inumquete][27] == 0 ) then
							else
								DBquetes2[inumquete][27] = 0;
								imodif = 27;
							end
						end
					end

					if ( isDaily ) then
						if ( DBquetes2[inumquete][28] == nil ) then
							DBquetes2[inumquete][28] = 1;
							imodif = 28;
						else
							if ( DBquetes2[inumquete][28] == 1 ) then
							else
								DBquetes2[inumquete][28] = 1;
								imodif = 28;
							end
						end
					else
						if ( DBquetes2[inumquete][28] == nil ) then
						else
							DBquetes2[inumquete][28] = nil;
							imodif = 28;
						end
					end
					
					SelectQuestLogEntry(i);
					inbjcons = GetQuestLogGroupNum();
					if ( inbjcons and inbjcons > 0 ) then
						if ( DBquetes2[inumquete][29] == nil ) then
							DBquetes2[inumquete][29] = inbjcons;
							imodif = 29;
						else
							if ( DBquetes2[inumquete][29] == inbjcons ) then
							else
								DBquetes2[inumquete][29] = inbjcons;
								imodif = 29;
							end
						end
					else
						if ( DBquetes2[inumquete][29] == nil ) then
						else
							DBquetes2[inumquete][29] = nil;
							imodif = 29;
						end
					end

--				[15]	=	{}	objets obtenus
--						[12038] = 3
--						[505] =1
					SelectQuestLogEntry(i);
					inbobj_obtenus = GetNumQuestLogRewards();
					for j = 1 , inbobj_obtenus do
						slink = GetQuestLogItemLink("reward", j);
						inumobjet = nil;
						for a, _, _, _, _, _, _, _, _, _ in string.gmatch((slink or ""),"item:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)") do
							inumobjet = tonumber(a);
						end
						if ( inumobjet ) then
							_, _, inb, _, _ = GetQuestLogRewardInfo(j);
							if ( DBquetes2[inumquete][15] == nil ) then
								DBquetes2[inumquete][15] = {};
							end
							if ( DBquetes2[inumquete][15][inumobjet] == nil ) then
								DBquetes2[inumquete][15][inumobjet] = inb;
								imodif = 15;
							else
								if ( DBquetes2[inumquete][15][inumobjet] == inb ) then
								else
									DBquetes2[inumquete][15][inumobjet] = inb;
									imodif = 15;
								end
							end
						end
					end
--				[16]	=	{}	objets à choisir
--						[12038] = 3
--						[505] =1
					SelectQuestLogEntry(i);
					inbobj_choix = GetNumQuestLogChoices();
					for j = 1 , inbobj_choix do
						slink = GetQuestLogItemLink("choice", j);
						inumobjet = nil;
						for a, _, _, _, _, _, _, _, _, _ in string.gmatch((slink or ""),"item:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)") do
							inumobjet = tonumber(a);
						end
						if ( inumobjet ) then
							_, _, inb, _, _ = GetQuestLogChoiceInfo(j);
							if ( DBquetes2[inumquete][16] == nil ) then
								DBquetes2[inumquete][16] = {};
							end
							if ( DBquetes2[inumquete][16][inumobjet] == nil ) then
								DBquetes2[inumquete][16][inumobjet] = inb;
								imodif = 16;
							else
								if ( DBquetes2[inumquete][16][inumobjet] == inb ) then
								else
									DBquetes2[inumquete][16][inumobjet] = inb;
									imodif = 16;
								end
							end
						end
					end
					
					DBquetes2[inumquete][7] = tonumber(DBCS_date());
					
					if ( DBCS_CMS_numcanalCMS > 0 ) then
						if ( DBquetes2[inumquete][43] == nil ) then
							DBquetes2[inumquete][43] = tonumber(DBCS_date());
							imodif = 43;
						else
							if ( DBquetes2[inumquete][43] == tonumber(DBCS_date()) ) then
							else
								DBquetes2[inumquete][43] = tonumber(DBCS_date());
								imodif = 43;
							end
						end
					end

					DBQS2_toutesquetes_par_nometobjectif_ajout(inumquete,DBquetes2[inumquete][0],DBquetes2[inumquete][1]);
				--end

					DBquetes2_sauvegarderquete(inumquete);

if ( DBCS_debug > 1 and imodif ) then
TraceFrame:AddMessage("inumquete : "..inumquete.." imodif = "..(imodif or "").." nomquete : "..DBquetes2[inumquete][0]);
end

					if ( imodif ) then
						DBQS2_envoyerquete(inumquete);
					end

			end
		end
	end
	
	if ( isav > 0 ) then
		SelectQuestLogEntry(isav);
	end

	DBQS2_logdispo = 1;

end

function DBQS2_enreg_detail()

local imodif = nil;

--	DBquetes2
--	DBquetes2_tempo_detail
--		DBquetes2_tempo_detail_numquete
--				[0]	=	nom de la quete
--				[1]	=	objectif texte
--				[2]	=	niv min
	if ( DBquetes2[DBquetes2_tempo_detail_numquete] == nil ) then
		if ( DBCS_afficher_new_quetes == true ) then
			TraceFrame:AddMessage("Nouvelle qu\195\170te : id = "..DBquetes2_tempo_detail_numquete.." , nom : "..(DBquetes2_tempo_detail[0] or ""));
			--TraceFrame:AddMessage("objectif : "..(DBquetes2_tempo_detail[1] or ""));
		end
		DBquetes2[DBquetes2_tempo_detail_numquete] = {};
		DBquetes2[DBquetes2_tempo_detail_numquete][0] = DBquetes2_tempo_detail[0];
		DBquetes2[DBquetes2_tempo_detail_numquete][44] = DBCS_date().."@"..DBCS_time();
		imodif = 0;
	end

	if ( DBquetes2_tempo_detail[2] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][2] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][2] = DBquetes2_tempo_detail[2];
			imodif = 2;
		else
			if ( DBquetes2_tempo_detail[2] == -1 and ( not ( DBquetes2[DBquetes2_tempo_detail_numquete][2] == -1 ) ) ) then
			else
				if ( DBquetes2_tempo_detail[2] < DBquetes2[DBquetes2_tempo_detail_numquete][2] ) then
					DBquetes2[DBquetes2_tempo_detail_numquete][2] = DBquetes2_tempo_detail[2];
					imodif = 2;
				end
			end
		end
	end
--				[3]	=	niv conseil
	if ( DBquetes2_tempo_detail[3] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][3] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][3] = DBquetes2_tempo_detail[3];
			imodif = 3;
		else
			if ( DBquetes2_tempo_detail[3] == -1 and ( not ( DBquetes2[DBquetes2_tempo_detail_numquete][3] == -1 ) ) ) then
			else
				if ( DBquetes2[DBquetes2_tempo_detail_numquete][3] == DBquetes2_tempo_detail[3] ) then
				else
					DBquetes2[DBquetes2_tempo_detail_numquete][3] = DBquetes2_tempo_detail[3];
					imodif = 3;
				end
			end
		end
	end
--				[2]	=	niv min
	if ( DBquetes2[DBquetes2_tempo_detail_numquete][2] and DBquetes2[DBquetes2_tempo_detail_numquete][3] and DBquetes2[DBquetes2_tempo_detail_numquete][2] > DBquetes2[DBquetes2_tempo_detail_numquete][3] ) then
		DBquetes2[DBquetes2_tempo_detail_numquete][2] = DBquetes2[DBquetes2_tempo_detail_numquete][3];
		imodif = 2.5;
	end
--				[4]	=	description texte
	if ( DBquetes2_tempo_detail[4] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][4] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][4] = DBquetes2_tempo_detail[4];
			imodif = 4;
		else
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][4] == DBquetes2_tempo_detail[4] ) then
			else
				DBquetes2[DBquetes2_tempo_detail_numquete][4] = DBquetes2_tempo_detail[4];
				imodif = 4;
			end
		end
	end
--				[5]	=	{}	donneurs quete
--						[nomdonneur]	=	date
	if ( DBquetes2_tempo_detail[5] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][5] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][5] = {};
		end
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][5][DBquetes2_tempo_detail[5]] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][5][DBquetes2_tempo_detail[5]] = tonumber(DBCS_date());
			imodif = 5;
		else
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][5][DBquetes2_tempo_detail[5]] == tonumber(DBCS_date()) ) then
			else
				DBquetes2[DBquetes2_tempo_detail_numquete][5][DBquetes2_tempo_detail[5]] = tonumber(DBCS_date());
				imodif = 5;
			end
		end
	end
--				[46]	=	{}	numéro pnj donneur quete
	if ( DBquetes2_tempo_detail[46] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][46] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][46] = {};
		end
		DBquetes2[DBquetes2_tempo_detail_numquete][46][1] = DBquetes2_tempo_detail[46];
		DBquetes2[DBquetes2_tempo_detail_numquete][46][2] = tonumber(DBCS_date());
		imodif = 5;
	end
--				[10]	=	salaire requis
	if ( DBquetes2_tempo_detail[10] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][10] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][10] = DBquetes2_tempo_detail[10];
			imodif = 10;
		else
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][10] == DBquetes2_tempo_detail[10] ) then
			else
				DBquetes2[DBquetes2_tempo_detail_numquete][10] = DBquetes2_tempo_detail[10];
				imodif = 10;
			end
		end
	end
--				[11]	=	salaire recompense < DBCS_nivmax ( 60 ) ( 70 )
	if ( DBquetes2_tempo_detail[11] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][11] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][11] = DBquetes2_tempo_detail[11];
			imodif = 11;
		else
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][11] == DBquetes2_tempo_detail[11] ) then
			else
				DBquetes2[DBquetes2_tempo_detail_numquete][11] = DBquetes2_tempo_detail[11];
				imodif = 11;
			end
		end
	end
--				[12]	=	salaire recompense pour DBCS_nivmax ( 60 ) ( 70 )
	if ( DBquetes2_tempo_detail[12] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][12] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][12] = DBquetes2_tempo_detail[12];
			imodif = 12;
		else
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][12] == DBquetes2_tempo_detail[12] ) then
			else
				DBquetes2[DBquetes2_tempo_detail_numquete][12] = DBquetes2_tempo_detail[12];
				imodif = 12;
			end
		end
	end
--				[45]	=	salaire recompense pour DBCS_nivmax_wotlk ( 80 )
	if ( DBquetes2_tempo_detail[45] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][45] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][45] = DBquetes2_tempo_detail[45];
			imodif = 45;
		else
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][45] == DBquetes2_tempo_detail[45] ) then
			else
				DBquetes2[DBquetes2_tempo_detail_numquete][45] = DBquetes2_tempo_detail[45];
				imodif = 45;
			end
		end
	end
--				[48]	=	salaire recompense pour DBCS_nivmax_CT ( 85 )
	if ( DBquetes2_tempo_detail[48] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][48] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][48] = DBquetes2_tempo_detail[48];
			imodif = 48;
		else
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][48] == DBquetes2_tempo_detail[48] ) then
			else
				DBquetes2[DBquetes2_tempo_detail_numquete][48] = DBquetes2_tempo_detail[48];
				imodif = 48;
			end
		end
	end
--				[49]	=	salaire recompense pour DBCS_nivmax_MOP ( 90 )
	if ( DBquetes2_tempo_detail[49] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][49] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][49] = DBquetes2_tempo_detail[49];
			imodif = 49;
		else
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][49] == DBquetes2_tempo_detail[49] ) then
			else
				DBquetes2[DBquetes2_tempo_detail_numquete][49] = DBquetes2_tempo_detail[49];
				imodif = 49;
			end
		end
	end
--				[14]	=	{}	objets requis
--						[12038] = 3
--						[505] =1
	if ( DBquetes2_tempo_detail[14] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][14] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][14] = {};
		end
		for inumobjet, _ in pairs(DBquetes2_tempo_detail[14]) do
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][14][inumobjet] == nil ) then
				DBquetes2[DBquetes2_tempo_detail_numquete][14][inumobjet] = DBquetes2_tempo_detail[14][inumobjet];
				imodif = 14;
			else
				if ( DBquetes2[DBquetes2_tempo_detail_numquete][14][inumobjet] == DBquetes2_tempo_detail[14][inumobjet] ) then
				else
					DBquetes2[DBquetes2_tempo_detail_numquete][14][inumobjet] = DBquetes2_tempo_detail[14][inumobjet];
					imodif = 14;
				end
			end
		end
	end
--				[15]	=	{}	objets obtenus
--						[12038] = 3
--						[505] =1
	if ( DBquetes2_tempo_detail[15] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][15] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][15] = {};
		end
		for inumobjet, _ in pairs(DBquetes2_tempo_detail[15]) do
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][15][inumobjet] == nil ) then
				DBquetes2[DBquetes2_tempo_detail_numquete][15][inumobjet] = DBquetes2_tempo_detail[15][inumobjet];
				imodif = 15;
			else
				if ( DBquetes2[DBquetes2_tempo_detail_numquete][15][inumobjet] == DBquetes2_tempo_detail[15][inumobjet] ) then
				else
					DBquetes2[DBquetes2_tempo_detail_numquete][15][inumobjet] = DBquetes2_tempo_detail[15][inumobjet];
					imodif = 15;
				end
			end
		end
	end
--				[16]	=	{}	objets à choisir
--						[12038] = 3
--						[505] =1
	if ( DBquetes2_tempo_detail[16] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][16] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][16] = {};
		end
		for inumobjet, _ in pairs(DBquetes2_tempo_detail[16]) do
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][16][inumobjet] == nil ) then
				DBquetes2[DBquetes2_tempo_detail_numquete][16][inumobjet] = DBquetes2_tempo_detail[16][inumobjet];
				imodif = 16;
			else
				if ( DBquetes2[DBquetes2_tempo_detail_numquete][16][inumobjet] == DBquetes2_tempo_detail[16][inumobjet] ) then
				else
					DBquetes2[DBquetes2_tempo_detail_numquete][16][inumobjet] = DBquetes2_tempo_detail[16][inumobjet];
					imodif = 16;
				end
			end
		end
	end
--				[18]	=	1	=	alliance
--				[19]	=	1	=	horde
	if ( DBquetes2_tempo_detail[18] ) then
		if ( DBquetes2_tempo_detail[18] == "Alliance" ) then
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][18] == nil ) then
				DBquetes2[DBquetes2_tempo_detail_numquete][18] = 1;	--	alliance
				imodif = 18;
			end
		elseif ( DBquetes2_tempo_detail[18] == "Horde" ) then
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][19] == nil ) then
				DBquetes2[DBquetes2_tempo_detail_numquete][19] = 1;	--	horde
				imodif = 19;
			end
		end
	end
--				[24]	= quete précédente
	if ( DBquetes2_tempo_detail[24] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][24] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][24] = {};
		end
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][24][DBquetes2_tempo_detail[24]] == nil ) then
			DBquetes2[DBquetes2_tempo_detail_numquete][24][DBquetes2_tempo_detail[24]] = tonumber(DBCS_date());
			imodif = 24;
		else
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][24][DBquetes2_tempo_detail[24]] == tonumber(DBCS_date()) ) then
			else
				DBquetes2[DBquetes2_tempo_detail_numquete][24][DBquetes2_tempo_detail[24]] = tonumber(DBCS_date());
				imodif = 24;
			end
		end
	end
--				[26]	=	catégorie temporaire de la quete
	if ( DBquetes2_tempo_detail[26] ) then
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][20] == nil or strlen(DBquetes2[DBquetes2_tempo_detail_numquete][20]) == 0 ) then
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][26] == nil ) then
				DBquetes2[DBquetes2_tempo_detail_numquete][26] = DBquetes2_tempo_detail[26];
				imodif = 26;
			else
				if ( DBquetes2[DBquetes2_tempo_detail_numquete][26] == DBquetes2_tempo_detail[26] ) then
				else
					DBquetes2[DBquetes2_tempo_detail_numquete][26] = DBquetes2_tempo_detail[26];
					imodif = 26;
				end
			end
		else
			if ( DBquetes2[DBquetes2_tempo_detail_numquete][26] and DBquetes2[DBquetes2_tempo_detail_numquete][26] == "#" ) then
			else
				DBquetes2[DBquetes2_tempo_detail_numquete][26] = "#";
				imodif = 26;
			end
		end
	end

	DBquetes2[DBquetes2_tempo_detail_numquete][8] = tonumber(DBCS_date());

	if ( DBquetes2[DBquetes2_tempo_detail_numquete][43] == nil ) then
		DBquetes2[DBquetes2_tempo_detail_numquete][43] = tonumber(DBCS_date());
		imodif = 43;
	else
		if ( DBquetes2[DBquetes2_tempo_detail_numquete][43] == tonumber(DBCS_date()) ) then
		else
			DBquetes2[DBquetes2_tempo_detail_numquete][43] = tonumber(DBCS_date());
			imodif = 43;
		end
	end

	DBquetes2_sauvegarderquete(DBquetes2_tempo_detail_numquete);

if ( DBCS_debug > 1 and imodif ) then
TraceFrame:AddMessage("inumquete : "..DBquetes2_tempo_detail_numquete.." imodif = "..(imodif or "").." nomquete : "..DBquetes2[DBquetes2_tempo_detail_numquete][0]);
end

	if ( imodif ) then
		DBQS2_envoyerquete(DBquetes2_tempo_detail_numquete);
	end

	DBquetes2_tempo_detail = nil;
	DBquetes2_tempo_detail_numquete = nil;

end

function DBQS2_enreg_progress()

local inumquete;
local tablo = {};
local iindex;
local imodif;

		--	0
		--	2
		--	3
		--	6
		--	14
		--	15
		--	16
		--	17
		--	18
		--	19
	if ( DBquetes2_tempo_progress_numquete == 0 ) then
		if ( DBQS2_tablo_toutesquetes_par_nometobjectif[DBquetes2_tempo_progress[0]] and DBQS2_tablo_toutesquetes_par_nometobjectif[DBquetes2_tempo_progress[0]][""] ) then
			for inumquete, _ in pairs(DBQS2_tablo_toutesquetes_par_nometobjectif[DBquetes2_tempo_progress[0]][""]) do
--TraceFrame:AddMessage("quete : "..inumquete);
				table.insert(tablo,inumquete);
			end
		else
		end
	else
--TraceFrame:AddMessage("quete : "..DBquetes2_tempo_progress_numquete);
		table.insert(tablo,DBquetes2_tempo_progress_numquete);
	end
	for _, inumquete in pairs(tablo) do
--TraceFrame:AddMessage("inumquete : "..inumquete);
		imodif = nil;
--				[2]	=	niv min
		if ( DBquetes2[inumquete] == nil ) then
			if ( DBCS_afficher_new_quetes == true ) then
				TraceFrame:AddMessage("Nouvelle qu\195\170te : id = "..inumquete.." , nom : "..(DBquetes2_tempo_progress[0] or ""));
				--TraceFrame:AddMessage("objectif : "..(DBquetes2_tempo_progress[1] or ""));
			end
			DBquetes2[inumquete] = {};
			DBquetes2[inumquete][0] = DBquetes2_tempo_progress[0];
			DBquetes2[inumquete][44] = DBCS_date().."@"..DBCS_time();
			imodif = 0;
		end
		if ( DBquetes2_tempo_progress[2] ) then
			if ( DBquetes2[inumquete][2] == nil ) then
				DBquetes2[inumquete][2] = DBquetes2_tempo_progress[2];
				imodif = 2;
			else
				if ( DBquetes2_tempo_progress[2] == -1 and ( not ( DBquetes2[inumquete][2] == -1 ) ) ) then
				else
					if ( DBquetes2_tempo_progress[2] < DBquetes2[inumquete][2] ) then
						DBquetes2[inumquete][2] = DBquetes2_tempo_progress[2];
						imodif = 2;
					end
				end
			end
		end
--				[3]	=	niv conseil
		if ( DBquetes2_tempo_progress[3] ) then
			if ( DBquetes2[inumquete][3] == nil ) then
				DBquetes2[inumquete][3] = DBquetes2_tempo_progress[3];
				imodif = 3;
			else
				if ( DBquetes2_tempo_progress[3] == -1 and ( not ( DBquetes2[inumquete][3] == -1 ) ) ) then
				else
					if ( DBquetes2[inumquete][3] == DBquetes2_tempo_progress[3] ) then
					else
						DBquetes2[inumquete][3] = DBquetes2_tempo_progress[3];
						imodif = 3;
					end
				end
			end
		end
--				[2]	=	niv min
		if ( DBquetes2[inumquete][2] and DBquetes2[inumquete][3] and DBquetes2[inumquete][2] > DBquetes2[inumquete][3] ) then
			DBquetes2[inumquete][2] = DBquetes2[inumquete][3];
			imodif = 2;
		end
--				[6]	=	{}	finisseurs quete
--						[nomfinisseur]	=	date
		if ( DBquetes2_tempo_progress[6] ) then
			if ( DBquetes2[inumquete][6] == nil ) then
				DBquetes2[inumquete][6] = {};
			end
			if ( DBquetes2[inumquete][6][DBquetes2_tempo_progress[6]] == nil ) then
				DBquetes2[inumquete][6][DBquetes2_tempo_progress[6]] = tonumber(DBCS_date());
				imodif = 6;
			else
				if ( DBquetes2[inumquete][6][DBquetes2_tempo_progress[6]] == tonumber(DBCS_date()) ) then
				else
					DBquetes2[inumquete][6][DBquetes2_tempo_progress[6]] = tonumber(DBCS_date());
					imodif = 6;
				end
			end
		end
--				[47]	=	{}	numéro pnj finisseur quete
		if ( DBquetes2_tempo_progress[47] ) then
			if ( DBquetes2[inumquete][47] == nil ) then
				DBquetes2[inumquete][47] = {};
			end
			DBquetes2[inumquete][47][1] = DBquetes2_tempo_progress[47];
			DBquetes2[inumquete][47][2] = tonumber(DBCS_date());
			imodif = 6;
		end
--				[9]	=	progression texte
		if ( DBquetes2_tempo_progress[9] ) then
			if ( DBquetes2[inumquete][9] == nil ) then
				DBquetes2[inumquete][9] = DBquetes2_tempo_progress[9];
				imodif = 9;
			else
				if ( DBquetes2[inumquete][9] == DBquetes2_tempo_progress[9] ) then
				else
					DBquetes2[inumquete][9] = DBquetes2_tempo_progress[9];
					imodif = 9;
				end
			end
		end
--				[10]	=	salaire requis
		if ( DBquetes2_tempo_progress[10] ) then
			if ( DBquetes2[inumquete][10] == nil ) then
				DBquetes2[inumquete][10] = DBquetes2_tempo_progress[10];
				imodif = 10;
			else
				if ( DBquetes2[inumquete][10] == DBquetes2_tempo_progress[10] ) then
				else
					DBquetes2[inumquete][10] = DBquetes2_tempo_progress[10];
					imodif = 10;
				end
			end
		end
--				[14]	=	{}	objets requis
--						[12038] = 3
--						[505] =1
		if ( DBquetes2_tempo_progress[14] ) then
			if ( DBquetes2[inumquete][14] == nil ) then
				DBquetes2[inumquete][14] = {};
			end
			for inumobjet, _ in pairs(DBquetes2_tempo_progress[14]) do
				if ( DBquetes2[inumquete][14][inumobjet] == nil ) then
					DBquetes2[inumquete][14][inumobjet] = DBquetes2_tempo_progress[14][inumobjet];
					imodif = 14;
				else
					if ( DBquetes2[inumquete][14][inumobjet] == DBquetes2_tempo_progress[14][inumobjet] ) then
					else
						DBquetes2[inumquete][14][inumobjet] = DBquetes2_tempo_progress[14][inumobjet];
						imodif = 14;
					end
				end
			end
		end
--				[18]	=	1	=	alliance
--				[19]	=	1	=	horde
		if ( DBquetes2_tempo_progress[18] ) then
			if ( DBquetes2_tempo_progress[18] == "Alliance" ) then
				if ( DBquetes2[inumquete][18] == nil ) then
					DBquetes2[inumquete][18] = 1;	--	alliance
					imodif = 18;
				end
			elseif ( DBquetes2_tempo_progress[18] == "Horde" ) then
				if ( DBquetes2[inumquete][19] == nil ) then
					DBquetes2[inumquete][19] = 1;	--	horde
					imodif = 19;
				end
			end
		end

--				[26]	=	catégorie temporaire de la quete
		if ( DBquetes2_tempo_progress[26] ) then
			if ( DBquetes2[inumquete][20] == nil or strlen(DBquetes2[inumquete][20]) == 0 ) then
				if ( DBquetes2[inumquete][26] == nil ) then
					DBquetes2[inumquete][26] = DBquetes2_tempo_progress[26];
					imodif = 26;
				else
					if ( DBquetes2[inumquete][26] == DBquetes2_tempo_progress[26] ) then
					else
						DBquetes2[inumquete][26] = DBquetes2_tempo_progress[26];
						imodif = 26;
					end
				end
			else
				if ( DBquetes2[inumquete][26] and DBquetes2[inumquete][26] == "#" ) then
				else
					DBquetes2[inumquete][26] = "#";
					imodif = 26;
				end
			end
		end

		DBquetes2[inumquete][41] = tonumber(DBCS_date());

		if ( DBquetes2[inumquete][43] == nil ) then
			DBquetes2[inumquete][43] = tonumber(DBCS_date());
			imodif = 43;
		else
			if ( DBquetes2[inumquete][43] == tonumber(DBCS_date()) ) then
			else
				DBquetes2[inumquete][43] = tonumber(DBCS_date());
				imodif = 43;
			end
		end

		DBquetes2_sauvegarderquete(inumquete);

if ( DBCS_debug > 1 and imodif ) then
TraceFrame:AddMessage("inumquete : "..inumquete.." imodif = "..(imodif or "").." nomquete : "..DBquetes2[inumquete][0]);
end

		if ( imodif ) then
			DBQS2_envoyerquete(inumquete);
		end

	end
	DBquetes2_tempo_progress = nil;
	DBquetes2_tempo_progress_numquete = nil;

	iindex = FauxScrollFrame_GetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame);
	DBcorps_ListQuetes2_Reset();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_enreg_progress DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
	DBcorps_ListQuetes2_Update();
	if ( iindex > (DBCORPS_QUETES2_LISTE_nb-10) ) then
		iindex = DBCORPS_QUETES2_LISTE_nb - 10;
	end
	if ( iindex < 0 ) then
		iindex = 0;
	end
	FauxScrollFrame_SetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame,iindex);
	DBcorpsFrame_Quetes2Frame_Liste_ScrollFrameScrollBar:SetValue(iindex*32);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_enreg_progress DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
	DBcorps_Quetes2_Scroll_Update();

end

function DBQS2_enreg_complete()

local inumquete;
local tablo = {};
local iindex;
local i;
local imodif;
local tablo2;
local inumquete2;
local tablo3;
local btrouve;
local bsauter;
		--	0
		--	2
		--	3
		--	6
		--	11
		--	12
		--	15
		--	16
		--	17
		--	18
		--	19
	i = 0;
	if ( DBquetes2_tempo_complete_numquete == 0 or DBquetes2_tempo_complete_numquete == nil ) then
		if ( DBQS2_tablo_toutesquetes_par_nometobjectif[DBquetes2_tempo_complete[0]] and DBQS2_tablo_toutesquetes_par_nometobjectif[DBquetes2_tempo_complete[0]][""] ) then
			for inumquete, _ in pairs(DBQS2_tablo_toutesquetes_par_nometobjectif[DBquetes2_tempo_complete[0]][""]) do
--TraceFrame:AddMessage("quete : "..inumquete);
				table.insert(tablo,inumquete);
				i = i + 1;
				DBquetes2_inumqueteprec = inumquete;
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_enreg_complete1 , DBquetes2_inumqueteprec = "..( DBquetes2_inumqueteprec or "" ));
--end
			end
		else
		end
	else
--TraceFrame:AddMessage("quete : "..DBquetes2_tempo_complete_numquete);
		table.insert(tablo,DBquetes2_tempo_complete_numquete);
		i = i + 1;
		DBquetes2_inumqueteprec = DBquetes2_tempo_complete_numquete;
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_enreg_complete2 , DBquetes2_inumqueteprec = "..( DBquetes2_inumqueteprec or "" ));
--end
	end
	if ( i == 1 ) then
	else
		DBquetes2_inumqueteprec = nil;
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_enreg_complete3 , DBquetes2_inumqueteprec = "..( DBquetes2_inumqueteprec or "" ));
--end
	end
	for _, inumquete in pairs(tablo) do
--TraceFrame:AddMessage("inumquete : "..inumquete);
		bsauter = false;
		imodif = nil;
--				[2]	=	niv min
		if ( DBquetes2[inumquete] == nil ) then
			if ( DBCS_afficher_new_quetes == true ) then
				TraceFrame:AddMessage("Nouvelle qu\195\170te : id = "..inumquete.." , nom : "..(DBquetes2_tempo_complete[0] or ""));
				--TraceFrame:AddMessage("objectif : "..(DBquetes2_tempo_complete[1] or ""));
			end
			DBquetes2[inumquete] = {};
			DBquetes2[inumquete][0] = DBquetes2_tempo_complete[0];
			DBquetes2[inumquete][44] = DBCS_date().."@"..DBCS_time();
			imodif = 0;
		end
		if ( DBquetes2[inumquete][7] == nil and DBquetes2[inumquete][8] == nil and DBquetes2[inumquete][41] == nil and DBquetes2[inumquete][1] == nil ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("quete louche : "..inumquete.." = "..(DBquetes2[inumquete][0] or ""));
end
			if ( DBquetes2_tempo_complete[26] == DBquetes2[inumquete][26] or DBquetes2[inumquete][26] == nil or DBquetes2[inumquete][26] == "" or DBquetes2[inumquete][26] == "#" ) then
			else
				tablo2 = {};
				btrouve = false;
				-- recherche des numéros de quetes avec le meme nom et objectif vide
				for inumquete2, _ in pairs(DBquetes2) do
					if ( btrouve == false and DBquetes2[inumquete2][0] == DBquetes2[inumquete][0] and DBquetes2[inumquete2][1] == nil ) then
						table.insert(tablo2,inumquete2);
						-- si la région temporaire est la meme
						if ( DBquetes2_tempo_complete[26] == DBquetes2[inumquete2][26] ) then
							btrouve = true;
							tablo2 = {};
							inumquete = inumquete2;
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("quete existe : "..inumquete2);
end
						end
					end
				end
				if ( table.getn(tablo2) > 1 ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("quete louche : "..inumquete.." = "..(DBquetes2[inumquete][0] or "").." , "..table.getn(tablo2).." occurences.");
end
					tablo3 = {};
					-- recherche des numéros de quetes avec la meme région temporaire
					for _, inumquete2 in pairs(tablo2) do
						if ( inumquete2 == inumquete ) then
						else
							if ( DBquetes2[inumquete2][26] == DBquetes2[inumquete][26] ) then
								table.insert(tablo3,inumquete2);
							end
						end
					end
					if ( table.getn(tablo3) > 0 ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("autre quete possible en double : "..tablo3[1]);
end
						inumquete = tablo3[1];
					else
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("sauter cette quete.");
end
						--sauter cette quete
						bsauter = true;
					end
				end
			end
			--DBquetes2_tempo_complete[26]
		end
		if ( bsauter == false ) then
			if ( DBquetes2_tempo_complete[2] ) then
				if ( DBquetes2[inumquete][2] == nil ) then
					DBquetes2[inumquete][2] = DBquetes2_tempo_complete[2];
					imodif = 2;
				else
					if ( DBquetes2_tempo_complete[2] == -1 and ( not ( DBquetes2[inumquete][2] == -1 ) ) ) then
					else
						if ( DBquetes2_tempo_complete[2] < DBquetes2[inumquete][2] ) then
							DBquetes2[inumquete][2] = DBquetes2_tempo_complete[2];
							imodif = 2;
						end
					end
				end
			end
--				[3]	=	niv conseil
			if ( DBquetes2_tempo_complete[3] ) then
				if ( DBquetes2[inumquete][3] == nil ) then
					DBquetes2[inumquete][3] = DBquetes2_tempo_complete[3];
					imodif = 3;
				else
					if ( DBquetes2_tempo_complete[3] == -1 and ( not ( DBquetes2[inumquete][3] == -1 ) ) ) then
					else
						if ( DBquetes2[inumquete][3] == DBquetes2_tempo_complete[3] ) then
						else
							DBquetes2[inumquete][3] = DBquetes2_tempo_complete[3];
							imodif = 3;
						end
					end
				end
			end
--				[2]	=	niv min
			if ( DBquetes2[inumquete][2] and DBquetes2[inumquete][3] and DBquetes2[inumquete][2] > DBquetes2[inumquete][3] ) then
				DBquetes2[inumquete][2] = DBquetes2[inumquete][3];
				imodif = 2;
			end
--				[6]	=	{}	finisseurs quete
--						[nomfinisseur]	=	date
			if ( DBquetes2_tempo_complete[6] ) then
				if ( DBquetes2[inumquete][6] == nil ) then
					DBquetes2[inumquete][6] = {};
				end
				if ( DBquetes2[inumquete][6][DBquetes2_tempo_complete[6]] == nil ) then
					DBquetes2[inumquete][6][DBquetes2_tempo_complete[6]] = tonumber(DBCS_date());
					imodif = 6;
				else
					if ( DBquetes2[inumquete][6][DBquetes2_tempo_complete[6]] == tonumber(DBCS_date()) ) then
					else
						DBquetes2[inumquete][6][DBquetes2_tempo_complete[6]] = tonumber(DBCS_date());
						imodif = 6;
					end
				end
			end
--				[47]	=	{}	numéro pnj finisseur quete
			if ( DBquetes2_tempo_complete[47] ) then
				if ( DBquetes2[inumquete][47] == nil ) then
					DBquetes2[inumquete][47] = {};
				end
				DBquetes2[inumquete][47][1] = DBquetes2_tempo_complete[47];
				DBquetes2[inumquete][47][2] = tonumber(DBCS_date());
				imodif = 6;
			end
--				[11]	=	salaire recompense < DBCS_nivmax ( 60 ) ( 70 )
			if ( DBquetes2_tempo_complete[11] ) then
				if ( DBquetes2[inumquete][11] == nil ) then
					DBquetes2[inumquete][11] = DBquetes2_tempo_complete[11];
					imodif = 11;
				else
					if ( DBquetes2[inumquete][11] == DBquetes2_tempo_complete[11] ) then
					else
						DBquetes2[inumquete][11] = DBquetes2_tempo_complete[11];
						imodif = 11;
					end
				end
			end
--				[12]	=	salaire recompense pour DBCS_nivmax ( 60 ) ( 70 )
			if ( DBquetes2_tempo_complete[12] ) then
				if ( DBquetes2[inumquete][12] == nil ) then
					DBquetes2[inumquete][12] = DBquetes2_tempo_complete[12];
					imodif = 12;
				else
					if ( DBquetes2[inumquete][12] == DBquetes2_tempo_complete[12] ) then
					else
						DBquetes2[inumquete][12] = DBquetes2_tempo_complete[12];
						imodif = 12;
					end
				end
			end
--				[45]	=	salaire recompense pour DBCS_nivmax_wotlk ( 80 )
			if ( DBquetes2_tempo_complete[45] ) then
				if ( DBquetes2[inumquete][45] == nil ) then
					DBquetes2[inumquete][45] = DBquetes2_tempo_complete[45];
					imodif = 45;
				else
					if ( DBquetes2[inumquete][45] == DBquetes2_tempo_complete[45] ) then
					else
						DBquetes2[inumquete][45] = DBquetes2_tempo_complete[45];
						imodif = 45;
					end
				end
			end
			--DBCS_nivmax_CT
--				[48]	=	salaire recompense pour DBCS_nivmax_CT ( 85 )
			if ( DBquetes2_tempo_complete[48] ) then
				if ( DBquetes2[inumquete][48] == nil ) then
					DBquetes2[inumquete][48] = DBquetes2_tempo_complete[48];
					imodif = 48;
				else
					if ( DBquetes2[inumquete][48] == DBquetes2_tempo_complete[48] ) then
					else
						DBquetes2[inumquete][48] = DBquetes2_tempo_complete[48];
						imodif = 48;
					end
				end
			end
--				[49]	=	salaire recompense pour DBCS_nivmax_MOP ( 90 )
			if ( DBquetes2_tempo_complete[49] ) then
				if ( DBquetes2[inumquete][49] == nil ) then
					DBquetes2[inumquete][49] = DBquetes2_tempo_complete[49];
					imodif = 49;
				else
					if ( DBquetes2[inumquete][49] == DBquetes2_tempo_complete[49] ) then
					else
						DBquetes2[inumquete][49] = DBquetes2_tempo_complete[49];
						imodif = 49;
					end
				end
			end
--				[15]	=	{}	objets reward
--						[12038] = 3
--						[505] =1
			if ( DBquetes2_tempo_complete[15] ) then
				if ( DBquetes2[inumquete][15] == nil ) then
					DBquetes2[inumquete][15] = {};
				end
				for inumobjet, _ in pairs(DBquetes2_tempo_complete[15]) do
					if ( DBquetes2[inumquete][15][inumobjet] == nil ) then
						DBquetes2[inumquete][15][inumobjet] = DBquetes2_tempo_complete[15][inumobjet];
						imodif = 15;
					else
						if ( DBquetes2[inumquete][15][inumobjet] == DBquetes2_tempo_complete[15][inumobjet] ) then
						else
							DBquetes2[inumquete][15][inumobjet] = DBquetes2_tempo_complete[15][inumobjet];
							imodif = 15;
						end
					end
				end
			end
--				[16]	=	{}	objets choice
--						[12038] = 3
--						[505] =1
			if ( DBquetes2_tempo_complete[16] ) then
				if ( DBquetes2[inumquete][16] == nil ) then
					DBquetes2[inumquete][16] = {};
				end
				for inumobjet, _ in pairs(DBquetes2_tempo_complete[16]) do
					if ( DBquetes2[inumquete][16][inumobjet] == nil ) then
						DBquetes2[inumquete][16][inumobjet] = DBquetes2_tempo_complete[16][inumobjet];
						imodif = 16;
					else
						if ( DBquetes2[inumquete][16][inumobjet] == DBquetes2_tempo_complete[16][inumobjet] ) then
						else
							DBquetes2[inumquete][16][inumobjet] = DBquetes2_tempo_complete[16][inumobjet];
							imodif = 16;
						end
					end
				end
			end
--				[17]	=	complete texte
			if ( DBquetes2_tempo_complete[17] ) then
				if ( DBquetes2[inumquete][17] == nil ) then
					DBquetes2[inumquete][17] = DBquetes2_tempo_complete[17];
					imodif = 17;
				else
					if ( DBquetes2[inumquete][17] == DBquetes2_tempo_complete[17] ) then
					else
						DBquetes2[inumquete][17] = DBquetes2_tempo_complete[17];
						imodif = 17;
					end
				end
			end
--				[18]	=	1	=	alliance
--				[19]	=	1	=	horde
			if ( DBquetes2_tempo_complete[18] ) then
				if ( DBquetes2_tempo_complete[18] == "Alliance" ) then
					if ( DBquetes2[inumquete][18] == nil ) then
						DBquetes2[inumquete][18] = 1;	--	alliance
						imodif = 18;
					end
				elseif ( DBquetes2_tempo_complete[18] == "Horde" ) then
					if ( DBquetes2[inumquete][19] == nil ) then
						DBquetes2[inumquete][19] = 1;	--	horde
						imodif = 19;
					end
				end
			end

--				[26]	=	catégorie temporaire de la quete
			if ( DBquetes2_tempo_complete[26] ) then
				if ( DBquetes2[inumquete][20] == nil or strlen(DBquetes2[inumquete][20]) == 0 ) then
					if ( DBquetes2[inumquete][26] == nil ) then
						DBquetes2[inumquete][26] = DBquetes2_tempo_complete[26];
						imodif = 26;
					else
						if ( DBquetes2[inumquete][26] == DBquetes2_tempo_complete[26] ) then
						else
							DBquetes2[inumquete][26] = DBquetes2_tempo_complete[26];
							imodif = 26;
						end
					end
				else
					if ( DBquetes2[inumquete][26] and DBquetes2[inumquete][26] == "#" ) then
					else
						DBquetes2[inumquete][26] = "#";
						imodif = 26;
					end
				end
			end

			DBquetes2[inumquete][42] = tonumber(DBCS_date());

			if ( DBquetes2[inumquete][43] == nil ) then
				DBquetes2[inumquete][43] = tonumber(DBCS_date());
				imodif = 43;
			else
				if ( DBquetes2[inumquete][43] == tonumber(DBCS_date()) ) then
				else
					DBquetes2[inumquete][43] = tonumber(DBCS_date());
					imodif = 43;
				end
			end

			DBquetes2_sauvegarderquete(inumquete);

if ( DBCS_debug > 1 and imodif ) then
TraceFrame:AddMessage("inumquete : "..inumquete.." imodif = "..(imodif or "").." nomquete : "..DBquetes2[inumquete][0]);
end

			if ( imodif ) then
				DBQS2_envoyerquete(inumquete);
			end
		end

	end
	DBquetes2_tempo_complete = nil;
	DBquetes2_tempo_complete_numquete = nil;
--if ( DBCS_debug and DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_enreg_complete1 DBquetes2_tempo_complete_numquete = "..( DBquetes2_tempo_complete_numquete or "" ));
--end

	iindex = FauxScrollFrame_GetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame);
	DBcorps_ListQuetes2_Reset();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_enreg_complete DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
	DBcorps_ListQuetes2_Update();
	if ( iindex > (DBCORPS_QUETES2_LISTE_nb-10) ) then
		iindex = DBCORPS_QUETES2_LISTE_nb - 10;
	end
	if ( iindex < 0 ) then
		iindex = 0;
	end
	FauxScrollFrame_SetOffset(DBcorpsFrame_Quetes2Frame_Liste_ScrollFrame,iindex);
	DBcorpsFrame_Quetes2Frame_Liste_ScrollFrameScrollBar:SetValue(iindex*32);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBQS2_enreg_complete DBCORPS_QUETES2_LISTE_nb = "..DBCORPS_QUETES2_LISTE_nb);
--end
	DBcorps_Quetes2_Scroll_Update();

end

function DBquetes2_sauvegarderquete(inumquete)

	if ( DBCS_prog_serveur == 1 ) then
		return nil;
	end
	
	if ( DBQC2[DBCS_getlocale] == nil ) then
		DBQC2[DBCS_getlocale] = {};
	end
	if ( inumquete and DBquetes2[inumquete] ) then
		DBQC2[DBCS_getlocale][inumquete] = DBquetes2[inumquete];
	end

end

function DBQS2_remplacersautdeligne(stexte)

	local snewtexte;
	local ipos;
	
	snewtexte = stexte;
	ipos = 0;
	while ( ipos ) do
		ipos = strfind(snewtexte,"\13\10",1);
		if ( ipos ) then
			snewtexte = strsub(snewtexte,1,ipos-1).."#"..strsub(snewtexte,ipos+2);
		end
	end
	ipos = 0;
	while ( ipos ) do
		ipos = strfind(snewtexte,"\10",1);	--\n
		if ( ipos ) then
			snewtexte = strsub(snewtexte,1,ipos-1).."#"..strsub(snewtexte,ipos+1);
		end
	end
	
	return snewtexte;

end

function DBQS2_ajoutersautdeligne(stexte)

	local snewtexte;
	local ipos;
	
	snewtexte = stexte;
	ipos = 0;
	while ( ipos ) do
		ipos = strfind(snewtexte,"#",1);
		if ( ipos ) then
			snewtexte = strsub(snewtexte,1,ipos-1).."\n"..strsub(snewtexte,ipos+1);
		end
	end
	
	return snewtexte;

end

--/script DBQS2_envoyerquete(7)
function DBQS2_envoyerquete(inumquete)

--	x	=	nom très long
--	y	=	nom court
--	z	=	nom très court
--	DBquetes2
--	enreg 01	=	num(5) + 1 + -2(2) + 1 2(2) + 1 + 3(2) + 1 + 7(8) + 1 + 8(8) + 1 + 10(8) + 1 + 11(8) + 1 + 12(8) + 1 + 13(1) + 1 + nb14(2) + 1 + nb15(2) + 1 + nb16(2) + 1 + 18(1) + 1 + 19(1) + 1 + nb22(2) + 1 + nb23(2) + 1 + 24(14) + 1 + 25(14) + 1 + 27(1) + 1 + 28(1) + 1 + 29(2) + 1 + 30(2) + 1 + 41(8) + 1 + 42(8) + 1
--			=	139
--	enreg 02	=	0(76) + 1 + 20(33) + 1 + 21(10) + 1 + 26(45) + 1
--			=	158
--			=	100 + 1 + 45 + 1 + 10 + 1 + 45 + 1
--			=	204
--	enreg 03	=	1(500)
--	enreg 04	=	4(500)
--	enreg 05	=	9(500)
--	enreg 06	=	17(500)
--	enreg 07	=	5(100) + 1 + 6(100) + 1
--	enreg 08	=	14( 10 * ( 5 + 1 + 3 + 1 ) )
--			=	100
--	enreg 09	=	15( 10 * ( 5 + 1 + 3 + 1 ) )
--			=	100
--	enreg 10	=	16( 10 * ( 5 + 1 + 3 + 1 ) )
--			=	100
--			[num]													5
--				[-2]	=	nivquete pour link								2
--				[-1]	=	datevalidquete;
--				[0]	=	nom de la quete								y	(76)
--				[1]	=	objectif texte								x
--				[2]	=	niv min									2
--				[3]	=	niv conseil									2
--				[4]	=	description texte								x
--				[5]	=	{}	donneurs quete							y+1+8
--						[nomdonneur]	=	0
--				[6]	=	{}	finisseurs quete							y+1+8
--						[nomfinisseur]	=	0
------------------------------------------				[7]	=	numquete
--				[7]	=	date quete ds journal							8
--				[8]	=	date quete detail ( avant cliquer bouton accepter )		8
--				[9]	=	progress texte								x
--				[10]	=	salaire requis								8
--				[11]	=	salaire recompense < DBCS_nivmax ( 60 ) ( 70 )			8
--				[12]	=	salaire recompense pour DBCS_nivmax ( 60 ) ( 70 )		8
--				[13]	=	quete validée : ne plus l'envoyer tous les jours			1
--				[14]	=	{}	objets requis							10 * ( 5 + 1 + 3 )
--						[12038] = 3
--						[505] =1
--				[15]	=	{}	objets obtenus							10 * ( 5 + 1 + 3 )
--						[12038] = 3
--						[505] =1
--				[16]	=	{}	objets à choisir							10 * ( 5 + 1 + 3 + 1 )
--						[12038] = 3
--						[505] =1
--				[17]	=	complete texte								x
--				[18]	=	1	=	alliance							1
--				[19]	=	1	=	horde								1
--				[20]	=	catégorie de la quete							y	(33)
--				[21]	=	type de la quete ( tag )							z	(10)
--				[22]	=	{}	texte du sous objectif						10 * ( z )
--						[1] = texte
--						[2] = texte
--				[23]	=	{}	type du sous objectif						10 * ( z )
--						[1] = type
--						[2] = type
--				[24]	=	{}	quetes précédentes						5 + 1 + 8
						--	[numquete] = 0;
--				[25]	=	{}	quetes suivantes							5 + 1 + 8
						--	[numquete] = 0;
--				[26]	=	catégorie temporaire de la quete					y	(45)
--				[27]	=	quete partageable : nil ou 0 ou 1					1
--				[28]	=	quete journalière								1
--				[29]	=	nb joueurs conseillé							2
--				[30]	=	nb obj link									2
--				[31]	=	objectif link 1								y
--				[32]	=	objectif link 2								y
--				[33]	=	objectif link 3								y
--				[34]	=	objectif link 4								y
--				[35]	=	objectif link 5								y
--				[36]	=	objectif link 6								y
--				[37]	=	objectif link 7								y
--				[38]	=	objectif link 8								y
--				[39]	=	objectif link 9								y
--				[40]	=	objectif link 10								y
--				[41]	=	date quete progress							8
--				[42]	=	date quete complete							8
--				[43]	=	date envoi

local tQUETE;
local tablo = {};
local inbenreg;
local i;
local j;
local lg;
local sligne;
local inumobjet;
local inbobjetrecquis;
local inbobjetobtenus;
local inbobjetchoix;
local stexte;
local i_lgmax = 200; -- marche pas avec 150 pour la quete : "quand smokey chante : je deviens violent"
--local i_lgmax = 210; -- marche pas avec 150 pour la quete : "quand smokey chante : je deviens violent"
local smorco;
local sreste;
local stest;
local imoins;
local snom;
local snomdonneur;
local idatedonneur;
local snomfinisseur;
local idatefinisseur;
local inum;
local inumprec;
local idateprec;
local inumsuiv;
local idatesuiv;

	if ( DBquetes2[inumquete] == nil ) then
		return nil;
	end
	tQUETE = DBquetes2[inumquete];
--	enreg 01	=	num(5) + 1 + -2(2) + 1 2(2) + 1 + 3(2) + 1 + 7(8) + 1 + 8(8) + 1 + 10(8) + 1 + 11(8) + 1 + 12(8) + 1 + 13(1) + 1 + nb14(2) + 1 + nb15(2) + 1 + nb16(2) + 1 + 18(1) + 1 + 19(1) + 1 + nb22(2) + 1 + nb23(2) + 1 + 24(14) + 1 + 25(14) + 1 + 27(1) + 1 + 28(1) + 1 + 29(2) + 1 + 30(2) + 1 + 41(8) + 1 + 42(8) + 1
--			=	139
--	enreg 02	=	0(76) + 1 + 20(33) + 1 + 21(10) + 1 + 26(45) + 1
--			=	158
--			=	100 + 1 + 45 + 1 + 10 + 1 + 45 + 1
--			=	204
--	enreg 03	=	1(500)
--	enreg 04	=	4(500)
--	enreg 05	=	9(500)
--	enreg 06	=	17(500)
--	enreg 07	=	5(100) + 1 + 6(100) + 1
--	enreg 08	=	14( 10 * ( 5 + 1 + 3 + 1 ) )
--			=	100
--	enreg 09	=	15( 10 * ( 5 + 1 + 3 + 1 ) )
--			=	100
--	enreg 10	=	16( 10 * ( 5 + 1 + 3 + 1 ) )
--			=	100
--	enreg 11	=	23 ( 10 * ( 10 + 1 ) )
--			=	110
	
	--	nomdelaquete + catégorie + type + catégorietemporaire
	tablo[2] = "02@"..(tQUETE[0] or "").."@"..(tQUETE[20] or "").."@"..(tQUETE[21] or "").."@"..(tQUETE[26] or "").."@";

	inbenreg = 2 ;

	-- objectif
	i = 0;
	stexte = DBQS2_remplacersautdeligne((tQUETE[1] or ""));
	lg = strlen(stexte);
	while ( i < lg ) do
		inbenreg = inbenreg + 1;
		smorco = strsub(stexte,i+1,i+i_lgmax);
		smorco,imoins = DBCS_verifderniercarac(smorco);
		tablo[inbenreg] = "03@"..smorco.."@";
		i = i + i_lgmax - imoins;
	end
	-- description
	i = 0;
--DBCS_ecrirecodedutexte((tQUETE[4] or ""));
	stexte = DBQS2_remplacersautdeligne((tQUETE[4] or ""));
	lg = strlen(stexte);
	while ( i < lg ) do
		inbenreg = inbenreg + 1;
		smorco = strsub(stexte,i+1,i+i_lgmax);
		smorco,imoins = DBCS_verifderniercarac(smorco);
		tablo[inbenreg] = "04@"..smorco.."@";
		i = i + i_lgmax - imoins;
	end
	-- progress
	i = 0;
	stexte = DBQS2_remplacersautdeligne((tQUETE[9] or ""));
	lg = strlen(stexte);
	while ( i < lg ) do
		inbenreg = inbenreg + 1;
		smorco = strsub(stexte,i+1,i+i_lgmax);
		smorco,imoins = DBCS_verifderniercarac(smorco);
		tablo[inbenreg] = "05@"..smorco.."@";
		i = i + i_lgmax - imoins;
	end
	-- complete
	i = 0;
	stexte = DBQS2_remplacersautdeligne((tQUETE[17] or ""));
	lg = strlen(stexte);
	while ( i < lg ) do
		inbenreg = inbenreg + 1;
		smorco = strsub(stexte,i+1,i+i_lgmax);
		smorco,imoins = DBCS_verifderniercarac(smorco);
		tablo[inbenreg] = "06@"..smorco.."@";
		i = i + i_lgmax - imoins;
	end
	-- donneur + finisseur
	sligne = "";
	if ( tQUETE[5] ) then
		snomdonneur = nil;
		idatedonneur = 0;
		for snom, _ in pairs(tQUETE[5]) do
			if ( idatedonneur <= tQUETE[5][snom] ) then
				snomdonneur = snom;
				idatedonneur = tQUETE[5][snom];
			end
		end
		if ( snomdonneur ) then
			sligne = sligne..snomdonneur.."@"..idatedonneur.."@";
		else
			sligne = sligne.."@@";
		end
	else
		sligne = sligne.."@@";
	end
	if ( tQUETE[6] ) then
		snomfinisseur = nil;
		idatefinisseur = 0;
		for snom, _ in pairs(tQUETE[6]) do
			if ( idatefinisseur <= tQUETE[6][snom] ) then
				snomfinisseur = snom;
				idatefinisseur = tQUETE[6][snom];
			end
		end
		if ( snomfinisseur ) then
			sligne = sligne..snomfinisseur.."@"..idatefinisseur.."@";
		else
			sligne = sligne.."@@";
		end
	else
		sligne = sligne.."@@";
	end
	inbenreg = inbenreg + 1;
	tablo[inbenreg] = "07@"..sligne;
	-- objets requis
	if ( tQUETE[14] ) then
		sligne = "";
		inbobjetrecquis = 0;
		i = 0;
		for inumobjet, _ in pairs(tQUETE[14]) do
			i = i + 1;
			if ( i <= 20 ) then
				inbobjetrecquis = inbobjetrecquis + 1;
				sligne = sligne..inumobjet.."@"..tQUETE[14][inumobjet].."@";
			end
		end
		if ( sligne == "" ) then
		else
			inbenreg = inbenreg + 1;
			tablo[inbenreg] = "08@"..sligne;
		end
	else
		inbobjetrecquis = 0;
	end
	-- objets obtenus
	if ( tQUETE[15] ) then
		sligne = "";
		inbobjetobtenus = 0;
		i = 0;
		for inumobjet, _ in pairs(tQUETE[15]) do
			i = i + 1;
			if ( i <= 20 ) then
				inbobjetobtenus = inbobjetobtenus + 1;
				sligne = sligne..inumobjet.."@"..tQUETE[15][inumobjet].."@";
			end
		end
		if ( sligne == "" ) then
		else
			inbenreg = inbenreg + 1;
			tablo[inbenreg] = "09@"..sligne;
		end
	else
		inbobjetobtenus = 0;
	end
	-- objets choix
	if ( tQUETE[16] ) then
		sligne = "";
		inbobjetchoix = 0;
		i = 0;
--DEFAULT_CHAT_FRAME:AddMessage("debut 16");
DEFAULT_CHAT_FRAME:AddMessage("numquete = "..inumquete);
		for inumobjet, _ in pairs(tQUETE[16]) do
--DEFAULT_CHAT_FRAME:AddMessage("numobjet = "..inumobjet);
--DEFAULT_CHAT_FRAME:AddMessage(tQUETE[16][inumobjet]);
			i = i + 1;
			if ( i <= 20 ) then
				inbobjetchoix = inbobjetchoix + 1;
				if ( type(tQUETE[16][inumobjet]) == "number" ) then
					sligne = sligne..inumobjet.."@"..tQUETE[16][inumobjet].."@";
				else
					sligne = sligne..inumobjet.."@".."1".."@";
				end
			end
		end
--DEFAULT_CHAT_FRAME:AddMessage("fin 16");
		if ( sligne == "" ) then
		else
			inbenreg = inbenreg + 1;
			tablo[inbenreg] = "10@"..sligne;
		end
	else
		inbobjetchoix = 0;
	end
	if ( tQUETE[23] and table.getn(tQUETE[23]) > 0 ) then
		sligne = "";
		for i = 1 , table.getn(tQUETE[23]) do
			sligne = sligne..tQUETE[23][i].."@";
		end
		inbenreg = inbenreg + 1;
		tablo[inbenreg] = "11@"..sligne;
	end
	tablo[0] = ""..inbenreg.."@";
	-- enreg 2
--	enreg 01	=	num(5) + 1 + -2(2) + 1 + 2(2) + 1 + 3(2) + 1 + 7(8) + 1 + 8(8) + 1 + 10(8) + 1 + 11(8) + 1 + 12(8) + 1 + 13(1) + 1 + nb14(2) + 1 + nb15(2) + 1 + nb16(2) + 1 + 18(1) + 1 + 19(1) + 1 + nb22(2) + 1 + nb23(2) + 1 + 24(14) + 1 + 25(14) + 1 + 27(1) + 1 + 28(1) + 1 + 29(2) + 1 + 30(2) + 1 + 41(8) + 1 + 42(8) + 1 + 45(8) + 1 + 48(8) + 1
--			=	157
	sligne = "01@";
	sligne = sligne..inumquete.."@";
	sligne = sligne..(tQUETE[-2] or "").."@";
	sligne = sligne..(tQUETE[2] or "").."@";
	sligne = sligne..(tQUETE[3] or "").."@";
	sligne = sligne..(tQUETE[7] or "").."@";
	sligne = sligne..(tQUETE[8] or "").."@";
	sligne = sligne..(tQUETE[10] or "").."@";
	sligne = sligne..(tQUETE[11] or "").."@";
	sligne = sligne..(tQUETE[12] or "").."@";
	sligne = sligne..(tQUETE[13] or "").."@";
	sligne = sligne..inbobjetrecquis.."@";
	sligne = sligne..inbobjetobtenus.."@";
	sligne = sligne..inbobjetchoix.."@";
	sligne = sligne..(tQUETE[18] or "").."@";
	sligne = sligne..(tQUETE[19] or "").."@";
	if ( tQUETE[22] ) then
		sligne = sligne..(table.getn(tQUETE[22])).."@";
	else
		sligne = sligne.."@";
	end
	if ( tQUETE[23] ) then
		sligne = sligne..(table.getn(tQUETE[23])).."@";
	else
		sligne = sligne.."@";
	end
	if ( tQUETE[24] ) then
		inumprec = nil;
		idateprec = 0;
		for inum, _ in pairs(tQUETE[24]) do
			if ( idateprec <= tQUETE[24][inum] ) then
				inumprec = inum;
				idateprec = tQUETE[24][inum];
			end
		end
		if ( inumprec ) then
			sligne = sligne..inumprec.."@"..idateprec.."@";
		else
			sligne = sligne.."@@";
		end
	else
		sligne = sligne.."@@";
	end
	if ( tQUETE[25] ) then
		inumsuiv = nil;
		idatesuiv = 0;
		for inum, _ in pairs(tQUETE[25]) do
			if ( idatesuiv <= tQUETE[25][inum] ) then
				inumsuiv = inum;
				idatesuiv = tQUETE[25][inum];
			end
		end
		if ( inumsuiv ) then
			sligne = sligne..inumsuiv.."@"..idatesuiv.."@";
		else
			sligne = sligne.."@@";
		end
	else
		sligne = sligne.."@@";
	end
	sligne = sligne..(tQUETE[27] or "").."@";
	sligne = sligne..(tQUETE[28] or "").."@";
	sligne = sligne..(tQUETE[29] or "").."@";
	sligne = sligne..(tQUETE[30] or "").."@";
	sligne = sligne..(tQUETE[41] or "").."@";
	sligne = sligne..(tQUETE[42] or "").."@";
	sligne = sligne..(tQUETE[45] or "").."@";
	--DBCS_nivmax_CT
	sligne = sligne..(tQUETE[48] or "").."@";
	--DBCS_nivmax_MOP
	sligne = sligne..(tQUETE[49] or "").."@";
	tablo[1] = sligne;

	DBquetes2_inbquetes = DBquetes2_inbquetes + 1;
	sdebut = "@ADBQS@"..DBCS_getlocale.."@QM02@"..floor(GetTime()*1000).."."..DBquetes2_inbquetes.."@";
--/script DEFAULT_CHAT_FRAME:AddMessage(86400*365)			--	31 536 000		--	8 octets
--/script DEFAULT_CHAT_FRAME:AddMessage(86400*365*10)		--	315 360 000		--	9 octets
	--	1 + 5 + 1 + 4 + 1 + 4 + 1 + 13 + 1	=	31
	--	+ 1 + 2	= nb quetes envoyées
	--	+ 2 + 1	= + numéro d'enreg
	--	+ 2 + 1	= + type d'enreg
	--	= 40
	for i = 0 , inbenreg do
--DEFAULT_CHAT_FRAME:AddMessage(sdebut..i.."@"..tablo[i]);
		if ( DBCS_CMS_numcanalCMS > 0 ) then
			DBCS_SendChatMessage(sdebut..i.."@"..tablo[i],"CHANNEL",DBCS_language,DBCS_CMS_numcanalCMS);
		end
	end

end

--					<Button name="$parent_MAJ" inherits="GameMenuButtonTemplate" text="MAJ quetes">
--						<Size>
--							<AbsDimension x="90" y="20"/>
--						</Size>
--						<Anchors>
--							<Anchor point="LEFT" relativeTo="$parent_Reset" relativePoint="RIGHT">
--								<Offset>
--									<AbsDimension x="5" y="0"/>
--								</Offset>
--							</Anchor>
--						</Anchors>
--						<Scripts>
--							<OnClick>
--								DBcorps_ListQuetes2_MAJ()
--							</OnClick>
--						</Scripts>
--					</Button>

--/script DBQS2_recup_DBQC2_vers_DBQS2();
function DBQS2_recup_DBQC2_vers_DBQS2(toutinvisible)

local slangue;
local inumquete;
local i;
local j;
local bmodifdate0;

	if ( toutinvisible ) then
	else
		toutinvisible = false;
	end
--DBQC2
	bmodifdate0 = false;
	slangue = GetLocale();
	if ( DBQC2[slangue] ) then
		i = 0;
		j = 0;
		for inumquete , _ in pairs(DBQC2[slangue]) do
			i = i + 1;
			--if ( i == 1 ) then
			if ( bmodifdate0 == false or toutinvisible == true ) then
				bmodifdate0 = DBQS2_maj_quete(inumquete,DBQC2[slangue][inumquete],toutinvisible);
if ( DBCS_debug > 1 ) then
	if ( bmodifdate0 == true and toutinvisible == false ) then
TraceFrame:AddMessage("----------------------------------------MODIF-----------------------------");
	end
end
				if ( toutinvisible == false ) then
					DBQC2[slangue][inumquete] = nil;
				end
			else
				j = j + 1;
			end
		end
if ( DBCS_debug > 1 ) then
if ( toutinvisible == false ) then
--TraceFrame:AddMessage("il reste "..(i-1).." quetes");
TraceFrame:AddMessage("il reste "..j.." quetes");
end
end
	end

end

--/script DBQS2_modifier_pnj_debut_fin_quetes2();
function DBQS2_modifier_pnj_debut_fin_quetes2()

local inumquete;
local snompnj;
local idatepnj;
local snompnj2;
local idatepnj2;
local inumpnj;

	DBmobs_Local_Init_Inverse();
	for inumquete, _ in pairs(DBquetes2) do
		if ( DBquetes2[inumquete][5] ) then	--	->46	1 = numéro		2 = date
			if ( type(DBquetes2[inumquete][5]) == "table" ) then
				idatepnj2 = -1;
				for snompnj, idatepnj in pairs(DBquetes2[inumquete][5]) do
					if ( idatepnj > idatepnj2 ) then
						snompnj2 = snompnj;
						idatepnj2 = idatepnj;
					end
				end
				if ( idatepnj2 > -1 ) then
					if ( DBmobs_Local_inverse[snompnj2] ) then
						if ( table.getn(DBmobs_Local_inverse[snompnj2]) == 1 ) then
							inumpnj = DBmobs_Local_inverse[snompnj2][1];
							DBquetes2[inumquete][46] = {};
							DBquetes2[inumquete][46][1] = inumpnj;
							DBquetes2[inumquete][46][2] = idatepnj2;
							DBquetes2[inumquete][5] = nil;
						end
					end
				end
			else
				DBquetes2[inumquete][5] = nil;
			end
		end
		if ( DBquetes2[inumquete][6] ) then	--	->47	1 = numéro		2 = date
			if ( type(DBquetes2[inumquete][6]) == "table" ) then
				idatepnj2 = -1;
				for snompnj, idatepnj in pairs(DBquetes2[inumquete][6]) do
					if ( idatepnj > idatepnj2 ) then
						snompnj2 = snompnj;
						idatepnj2 = idatepnj;
					end
				end
				if ( idatepnj2 > -1 ) then
					if ( DBmobs_Local_inverse[snompnj2] ) then
						if ( table.getn(DBmobs_Local_inverse[snompnj2]) == 1 ) then
							inumpnj = DBmobs_Local_inverse[snompnj2][1];
							DBquetes2[inumquete][47] = {};
							DBquetes2[inumquete][47][1] = inumpnj;
							DBquetes2[inumquete][47][2] = idatepnj2;
							DBquetes2[inumquete][6] = nil;
						end
					end
				end
			else
				DBquetes2[inumquete][6] = nil;
			end
		end
	end

end
