local TraceFrame = DEFAULT_CHAT_FRAME;

-- erreur en 747

--/script MAX_WATCHABLE_QUESTS = 8
--/script DEFAULT_CHAT_FRAME:AddMessage(" |cffffff00|Hquest:9279:1|h[Vous avez survecu\194\160!]|h|r")
--/script DEFAULT_CHAT_FRAME:AddMessage("|Hquest:9279:1|h[Vous avez survecu\194\160!]|h")
--		return "|Hquest:9279:1|h[bla]|h"
--		return "|Hplayer:"..nom.."|h["..nom.."]|h"
--/script DEFAULT_CHAT_FRAME:AddMessage(CMS_lienjoueurbynom("bla"))
--/script CMS_lienjoueurbynom("bla")
--/script DEFAULT_CHAT_FRAME:AddMessage("|Hplayer:bla|h[bla]|h");
--/script DEFAULT_CHAT_FRAME:AddMessage("|Hquest:9279:1|h[bla]|h")
--/script DEFAULT_CHAT_FRAME:AddMessage(UnitFactionGroup("player"))
--/script DEFAULT_CHAT_FRAME:AddMessage(UnitFactionGroup("player"))
--/script DEFAULT_CHAT_FRAME:AddMessage(UnitLevel("Player"));
--/script DEFAULT_CHAT_FRAME:AddMessage(GetQuestLink(2))
--/script DBCS_ecrirecodedutexte(GetQuestLink(2));
--	UnitFactionGroup("unitid");		Alliance	Horde
--		Used to retrieve the UnitID faction (Horde or Alliance), this can be called at PLAYER_ENTERING_WORLD with a player UnitID

local DBQS_event = nil;

DBQS_NUMVERSION1 = "00";
DBQS_NUMVERSION2 = "00";
DBQS_NUMVERSION3 = "05";

--	DBQS = {}
--		[nomquete] = {}
--			nb = 0 -> n
--			[1]	= {}
--				[1]	=	objectif texte
--				[2]	=	niv min
--				[3]	=	niv conseil
--				[4]	=	description texte
--				[5]	=	{}	donneurs quete
--						[nomdonneur]	=	0
--				[6]	=	{}	finisseurs quete
--						[nomfinisseur]	=	0
--				[7]	=	numquete
--				[8]	=	date envoi
--				[9]	=	progress texte
--				[10]	=	salaire recquis
--				[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 recquis
--						[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
--						nb précédentes
--						[1]	=	{}
--								[1] = nomquete
--								[2] = objectif
--				[25]	=	{}	quetes suivantes
--						nb suivantes
--						[1]	=	{}
--								[1] = nomquete
--								[2] = objectif
--				[26]	=	catégorie temporaire de la quete
--				[28]	=	quete journalière
--				[29]	=	nb joueurs conseillé

--	sur cms :
--		enreg 01	:	nomquete	+	20	+	21	( + 26 )
--		enreg 02	:	2	+	3	+	7	+	8	+	10	+	11	+	12	+	13	+	n objets recquis	+	n objets obtenus	+	n objets choix	+	18	+	19
--		enreg 03	:	n objectifs
--		enreg 04	:	n description
--		enreg 05	:	n progress
--		enreg 06	:	n complete
--		enreg 07	:	n sous-objectifs
--		enreg 08	:	n objets recquis
--		enreg 09	:	n objets obtenus
--		enreg 10	:	n objets choix
--		enreg 11	:	quete prec
--		enreg 12	:	quete suiv
--		enreg 13	:	n donneurs
--		enreg 14	:	n finisseurs

local nomqueteprec = nil;
local objectifprec = nil;
local timeprec = 0;

local DBQS_joueur = UnitName("Player");
local DBQS_quetes_tempo = {};

local DBQS_logdispo = 0;

local DBQS_suivi_quetes_time = 0;

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

--local DBQS_questTitle = nil;
--local DBQS_level = nil;
--local DBQS_questTag = nil;
--local DBQS_suggestedGroup = nil;
--local DBQS_isHeader = nil;
--local DBQS_isCollapsed = nil;
--local DBQS_isComplete = nil;

DBQS_tquetesencours = {};

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

--	nomquete
--	nivreelquete
--	nivminquete
--	description
--	objectif

-- sous objectifs
--local numQuestLogLeaderBoards = GetNumQuestLogLeaderBoards([questID])
--local desc, type, done = GetQuestLogLeaderBoard(i, [questID])

----	local questLogTitleText, level, questTag, _, isHeader, isCollapsed, isComplete, _ = GetQuestLogTitle(questIndex);
--	questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily = GetQuestLogTitle(questIndex);
--	questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete = GetQuestLogTitle(questID);

--QuestTimerFrame_Update(GetQuestTimers());
--function QuestTimerFrame_Update(...)
--	for i=1, arg.n, 1 do
--		SecondsToTime(arg[i]);
--	end
--end
--Result 
--"300", "240", "100"

--	local sTexture, sName = GetRewardSpell(); 

--	SelectQuestLogEntry(questID);


--/script 
--/script DEFAULT_CHAT_FRAME:AddMessage(GetNumQuestLeaderBoards())
--/script DEFAULT_CHAT_FRAME:AddMessage(GetNumQuestLogChoices())
--/script DEFAULT_CHAT_FRAME:AddMessage(GetNumQuestLogEntries())
--/script DEFAULT_CHAT_FRAME:AddMessage(GetNumQuestLogRewards())
--/script DEFAULT_CHAT_FRAME:AddMessage()
--/script DEFAULT_CHAT_FRAME:AddMessage(GetNumQuestWatches())
--/script DEFAULT_CHAT_FRAME:AddMessage(GetQuestLogTitle(2))
--/script DEFAULT_CHAT_FRAME:AddMessage()
--/script DEFAULT_CHAT_FRAME:AddMessage(GetNumQuestChoices())
--/script DEFAULT_CHAT_FRAME:AddMessage(GetNumQuestItems())
--/script DEFAULT_CHAT_FRAME:AddMessage(GetObjectiveText())
--/script DEFAULT_CHAT_FRAME:AddMessage(GetProgressText())
--/script DEFAULT_CHAT_FRAME:AddMessage(strsub(GetQuestBackgroundMaterial(),1,100))
--/script DEFAULT_CHAT_FRAME:AddMessage(GetTitleText())
--/script DEFAULT_CHAT_FRAME:AddMessage(GetRewardText())
--/script DEFAULT_CHAT_FRAME:AddMessage()
--/script DEFAULT_CHAT_FRAME:AddMessage(GetQuestLogQuestText())

--/script DEFAULT_CHAT_FRAME:AddMessage(GetGreetingText())
--/script DEFAULT_CHAT_FRAME:AddMessage(GetQuestText())


--	title1, level1, basniveau1, title2, level2, basniveau2 = GetGossipActiveQuests()
--	title1, level1, basniveau1, title2, level2, basniveau2 = GetGossipAvailableQuests()

--	AbandonQuest - Abandon the specified quest. 
--	AcceptQuest - Accept the specified quest. 
--	AddQuestWatch(x) - Add a quest to the watch list. 
--	CloseQuest - ?. 
--	CollapseQuestHeader - Collapses a quest header. 
--	CompleteQuest - Complete the specified quest. 
--	ConfirmAcceptQuest - Accept the quest. Yes. Really accept it. 
--	DeclineQuest - Declines the currently offered quest. 
--	ExpandQuestHeader - Expands a quest header. 
--	GetAbandonQuestName - Gets the name of a quest while it is being abandoned. 
--	GetGossipActiveQuests - Retrieves a list of the active (?) quests on the NPC you are talking to. 
--	GetGossipAvailableQuests - Retrieves a list of the available (!) quests on the NPC you are talking to. 
--	GetGreetingText() 
--	GetNumQuestChoices - Returns the number of rewards for a completed quest. 
--	GetNumQuestItems - Returns the number of items nessecary to complete a particular quest. 
--	GetNumQuestLeaderBoards({questIndex}) - Returns the number of available quest objectives. 
--	GetNumQuestLogChoices - Returns the number of options someone has when getting a quest item. 
--	GetNumQuestLogEntries - Returns the number of entries in the quest log. 
--	GetNumQuestLogRewards - Returns the count of the rewards for a particular quest. 
--	GetNumQuestRewards - ?. 
--	GetNumQuestWatches() - Returns the number of quest watches active. 
--	GetObjectiveText()
--	GetProgressText()
--	GetQuestBackgroundMaterial - Returns the material string associated with the particular quest. 
--	GetQuestGreenRange - ?. 
--	GetQuestIndexForTimer - ?. 
--	GetQuestIndexForWatch(watchIndx) - Return the quest index for the specified watch 
--	GetQuestItemInfo - Returns basic information about the quest items. 
--	GetQuestItemLink - ?. 
--	GetQuestLogChoiceInfo - Returns a bunch of data about a quest reward choice from the quest log. 
--	GetQuestLogItemLink - ?. 
--	GetQuestLogLeaderBoard(ldrIndex{,questIndex}) - Gets information about the objectives for a quest. 
--	GetQuestLogPushable - Returns true if the currently loaded quest in the quest window can be shared. 
--	GetQuestLogQuestText - Returns the description and objectives required for the specified quest. 
--	GetQuestLogRequiredMoney - ?. 
--	GetQuestLogRewardInfo - Returns a pile of reward item info. 
--	GetQuestLogRewardMoney - Returns a number representing the amount of copper returned by a particular quest. 
--	GetQuestLogRewardSpell - ?. 
--	GetQuestLogSelection - Returns a number associated with the QuestLogSelection index. 
--	GetQuestLogTimeLeft - ?. 
--	GetQuestLogTitle - Returns the string which is associated with the specific QuestLog Title in the game. 
--	GetQuestMoneyToGet - ?. 
--	GetQuestReward - Gets the quest reward specified. 
--	GetQuestText - ?. 
--	GetQuestTimers - Returns all of the quest timers currently in progress. 
--	GetRewardMoney - ?. 
--	GetRewardSpell - ?. 
--	GetRewardText - ?. 
--	GetTitleText - Retrieves the title of the quest while talking to the NPC about it. 
--	IsCurrentQuestFailed - ?. 
--	IsQuestCompletable - Returns true if a quest is possible to complete. 
--	IsQuestWatched(questIndex) - Determine if the specified quest is watched. 
--	IsUnitOnQuest(questIndex, "unit") - Determine if the a specific unit is on a given quest. 
--	QuestChooseRewardError - Throws an error when the quest choose reward method doesn't work. 
--	QuestLogPushQuest - Initiates the sharing of the currently viewed quest in the quest log. 
--	RemoveQuestWatch(index) - Remove a quest watch {Is the index a quest or watch index?). 
--	SelectGossipActiveQuest - Selects an active quest. 
--	SelectGossipAvailableQuest - Selects an available quest. 
--	SelectQuestLogEntry - ?. 
--	SetAbandonQuest - Called before AbandonQuest. 
--	UI ToggleQuestLog - Opens/closes the quest log. 

--hooksecurefunc("UseContainerItem", DBCS_UseContainerItem);
	--questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete = GetQuestLogTitle(questID);
--	questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily = GetQuestLogTitle(questIndex);
--function DBQS_GetQuestLogTitle_save(questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete)
--function DBQS_GetQuestLogTitle_save(questID)
--	DBQS_questTitle = questTitle;
--	DBQS_level = level;
--	DBQS_questTag = questTag;
--	DBQS_suggestedGroup = suggestedGroup;
--	DBQS_isHeader = isHeader;
--	DBQS_isCollapsed = isCollapsed;
--	DBQS_isComplete = isComplete;
--end
--hooksecurefunc("GetQuestLogTitle", DBQS_GetQuestLogTitle_save);

--function DBQS_GetQuestLogTitle();
--end

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

--function DBQS_QuestWatchLine_OnClick()
--
--local snom;
--local snum;
--local inum;
--local i,j,k,l;
--local i_index = -1;
--local i_obj = -1;
--local nomquete;
--local objectifquete;
--local isav;
--
--if ( DBCS_wow_2_4() == true ) then
--	return nil;
--end
--
--	--	DBQS_QuestWatchLine
--	snom = this:GetName();
--	snum = strsub(snom,20);
--	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
--		nomquete, _, _, _, _, _, _, _ = GetQuestLogTitle(i_index);
--		isav = GetQuestLogSelection();
--		SelectQuestLogEntry(i_index);
--		_, objectifquete = GetQuestLogQuestText();
--		if ( isav > 0 ) then
--			SelectQuestLogEntry(isav);
--		end
--		DBCORPS_QUETES_LISTE = {};
--		DBCORPS_QUETES_LISTE = DBquetes_Liste_ajout(DBCORPS_QUETES_LISTE,nomquete,objectifquete);
--		DBCORPS_QUETES_LISTE_nb = table.getn(DBCORPS_QUETES_LISTE);
--		getglobal("DBcorpsFrame_QuetesFrame_Criteres_Elements"):SetText(DBCORPS_QUETES_LISTE_nb.." \195\169l\195\169ments trouv\195\169s.")
--		DBcorps_ListQuetes_Trier();
--		DBcorps_init();
--		PanelTemplates_SetTab(DBcorpsFrame, 5);
--		DBcorps_ShowSubFrame(5);
--		FauxScrollFrame_SetOffset(DBcorpsFrame_QuetesFrame_Liste_ScrollFrame,0);
--		DBcorps_Quetes_Scroll_Update();
--	end
--
--end

--DBQS_QuestWatch_Update_nummax = 0;
--
--local Saved_DBQS_QuestWatch_Update = QuestWatch_Update;
--function DBQS_QuestWatch_Update()
--
--local oorig;
--local oframe;
--local i;
--
--	Saved_DBQS_QuestWatch_Update();
--
--if ( DBCS_wow_2_4() == true ) then
--	return nil;
--end
--
--	for i = 1 , 30 do
--		oorig = getglobal("QuestWatchLine"..i);
--		if ( oorig ) then
--			if ( i > DBQS_QuestWatch_Update_nummax ) then
--				DBQS_QuestWatch_Update_nummax = i;
--				oframe = CreateFrame("Button","DBQS_QuestWatchLine"..i,QuestWatchFrame);
--				oframe:SetScript("OnClick",DBQS_QuestWatchLine_OnClick);
--				--oframe = getglobal("DBQS_QuestWatchLine"..i);
--			else
--				oframe = getglobal("DBQS_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 = DBQS_QuestWatch_Update;

--local Saved_DBQS_AddQuestWatch = AddQuestWatch;
--function DBQS_AddQuestWatch(questIndex)
--
--	Saved_DBQS_AddQuestWatch(questIndex);
--
--if ( DBCS_wow_2_4() == true ) then
--	return nil;
--end
--
--	DBcorps_Quetes_Scroll_Update();
--
--	DBQS_sauvegarder_suivi_quete();
--
--end
--AddQuestWatch = DBQS_AddQuestWatch;

--local Saved_DBQS_RemoveQuestWatch = RemoveQuestWatch;
--function DBQS_RemoveQuestWatch(questIndex)
--
--	Saved_DBQS_RemoveQuestWatch(questIndex);
--
--if ( DBCS_wow_2_4() == true ) then
--	return nil;
--end
--
--	DBcorps_Quetes_Scroll_Update();
--
--	DBQS_sauvegarder_suivi_quete();
--
--end
--RemoveQuestWatch = DBQS_RemoveQuestWatch;

----	QuestDetailAcceptButton_OnClick()
--local Saved_DBQS_QuestDetailAcceptButton_OnClick = QuestDetailAcceptButton_OnClick;
--function DBQS_QuestDetailAcceptButton_OnClick()
--
--	Saved_DBQS_QuestDetailAcceptButton_OnClick();
--
--if ( DBCS_wow_2_4() == true ) then
--	return nil;
--end
--
--	DBquetes_quetesencours();
--	DBQS_sauvegarder_suivi_quete();
--
--end
--QuestDetailAcceptButton_OnClick = DBQS_QuestDetailAcceptButton_OnClick;

----QuestRewardCompleteButton_OnClick()
--local Saved_DBQS_QuestRewardCompleteButton_OnClick = QuestRewardCompleteButton_OnClick;
--function DBQS_QuestRewardCompleteButton_OnClick()
--
--	Saved_DBQS_QuestRewardCompleteButton_OnClick();
--
--if ( DBCS_wow_2_4() == true ) then
--	return nil;
--end
--
--	if ( DBHC ) then
--		if ( nomqueteprec and objectifprec ) then
--			DBHC_sauverquetefaite(nomqueteprec,objectifprec);
--		end
--	end
--	DBquetes_quetesencours();
--	timeprec = GetTime();
----if ( DBCS_debug > 1 ) then
----TraceFrame:AddMessage("timeprec : "..timeprec);
----end
--
--	DBQS_sauvegarder_suivi_quete();
--
--end
--QuestRewardCompleteButton_OnClick = DBQS_QuestRewardCompleteButton_OnClick;

----	QuestLog_SetSelection(questID)
----ChatFrame_OnHyperlinkShow(arg1, arg2, arg3);
--local Saved_DBQS_QuestLog_SetSelection = QuestLog_SetSelection;
--function DBQS_QuestLog_SetSelection(questID)
--
--local isHeader;
--local isCollapsed;
--
--	Saved_DBQS_QuestLog_SetSelection(questID);
--
--if ( DBCS_wow_2_4() == true ) then
--	return nil;
--end
--
----if ( DBCS_debug > 1 ) then
----TraceFrame:AddMessage("questID : "..questID);
----end
--	if ( DBCS_wow_2_4() == false ) then
--		if ( DBQS_logdispo == 1 ) then
--			DBquetes_lirelog(questID);
--		end
--		local _, _, _, _, isHeader, isCollapsed, _, _ = GetQuestLogTitle(questID);
--		if ( isHeader ) then
--			ExpandQuestHeader(questID);
--		end
--	end
--
--end
--QuestLog_SetSelection = DBQS_QuestLog_SetSelection;

end

--function DBQS_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

----toplevel="true" enableMouse="true" movable="true" 
----/script DBquetes_OnUpdate()
--function DBquetes_OnUpdate()
--
--local snomserveur;
--local snomjoueur;
--local tablo = {};
--local iindex;
--
--	if ( DBQS_suivi_quetes_time > 0 ) then
----if ( DBCS_debug > 1 ) then
----TraceFrame:AddMessage("DBQS_suivi_quetes_time : "..DBQS_suivi_quetes_time);
----end
--		if ( (GetTime() - DBQS_suivi_quetes_time) > 5 ) then	--	*1000	/1000
--			--DBCS_config["suivi_quetes"][snomserveur][snomjoueur][j] = 0;
--			snomserveur = GetRealmName();
----if ( DBCS_debug > 1 ) then
----TraceFrame:AddMessage("snomserveur : "..snomserveur);
----end
--			snomjoueur = UnitName("player");
----if ( DBCS_debug > 1 ) then
----TraceFrame:AddMessage("snomjoueur : "..snomjoueur);
----end
--			if ( DBCS_config and DBCS_config["suivi_quetes"] and DBCS_config["suivi_quetes"][snomserveur] and DBCS_config["suivi_quetes"][snomserveur][snomjoueur] ) then
----if ( DBCS_debug > 1 ) then
----TraceFrame:AddMessage("DBCS_config : ".."bon");
----end
--				tablo = DBCS_config["suivi_quetes"][snomserveur][snomjoueur];
--				for iindex, _ in pairs(tablo) do
----if ( DBCS_debug > 1 ) then
----TraceFrame:AddMessage("iindex : "..iindex);
----end
--					AddQuestWatch(iindex);
--				end
--				QuestWatch_Update();
--				DBcorps_Quetes_Scroll_Update();
--			end
--			DBQS_suivi_quetes_time = -1;
--		end
--	end
--
--end

function DBquetes_OnLoad()

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

	--if ( DBCS_wow_2_4() == false ) then
		--this:RegisterEvent("GOSSIP_SHOW");
		--this:RegisterEvent("QUEST_ACCEPT_CONFIRM");
		--this:RegisterEvent("QUEST_COMPLETE");
		--this:RegisterEvent("QUEST_DETAIL");
		--this:RegisterEvent("QUEST_FINISHED");
		--this:RegisterEvent("QUEST_GREETING");
		--this:RegisterEvent("QUEST_ITEM_UPDATE");
		--this:RegisterEvent("QUEST_LOG_UPDATE");
		--this:RegisterEvent("QUEST_PROGRESS");
		--this:RegisterEvent("UNIT_QUEST_LOG_CHANGED");
		--this:RegisterEvent("VARIABLES_LOADED");
	--end

end

	DBQS = {};
	DBPS = {};
	DBQS_config = {};

end

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

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

	if ( DBPS[snompnj] == nil ) then
		DBPS[snompnj] = {};
	end
	if ( DBPS[snompnj][snumregion] == nil ) then
		DBPS[snompnj][snumregion] = {};
	end
	if ( DBPS[snompnj][snumregion].xy == nil ) then
		DBPS[snompnj][snumregion].xy = "";
	end
	if ( x == 0 and y == 0 ) then
	else
		sposition = x.."X"..y.."@";
		ipos = strfind(DBPS[snompnj][snumregion].xy,sposition,1);
		if ( ipos == nil ) then
			DBPS[snompnj][snumregion].xy = DBPS[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.."@PA01@"..snompnj.."@"..snumregion.."@"..x.."@"..y.."@";
			if ( DBCS_wow_2_4() == false ) then
				DBCS_SendChatMessage(senreg,"CHANNEL",this.language,DBCS_CMS_numcanalCMS);
			end
		end
	end

end

function DBQS_traiterquete(sjoueur,stime)

local tablo = nil;
local tabloquete = nil;
local i;
local j;
local k;
local senreg;
local ideb;
local ifin;
local itypeenreg;
local snomquete,scategorie,stype;
local scategorietempo;
local inumobjectif;
local inivmin,inivconseil,inumquete,idateenvoi,iargentrecquis,isalairenon60,isalaire60,iquetevalidee,inbobjetsrecquis,inbobjetsobtenus,inbobjetschoix,ialliance,ihorde;
local sobjectif = "";
local sdescription = "";
local sprogress = "";
local scomplete = "";
local sligne;
local inumobjet,inbobjet;
local inumqueteprec,inumquetesuiv;
local inumqueteprec_new = 0;
local inumquetesuiv_new = 0;
local stexteobjprec,stexteobjsuiv;
local snomqueteprec,snomquetesuiv;
local bexist;
local bmessagedebug = 0;
local bmessagedebug2 = 0;
local slink,hex;

--/script DEFAULT_CHAT_FRAME:AddMessage(tonumber(strsub("abcdef",3,2)));
--TraceFrame:AddMessage("je traite la quete de "..sjoueur.." cree en "..stime);

	tablo = DBQS_quetes_tempo[sjoueur][stime];
	inumqueteprec = 0;
	inumquetesuiv = 0;
	stexteobjprec = "";
	stexteobjsuiv = "";
--TraceFrame:AddMessage("tablo[0] "..tablo[0]);
	for i = 1 , tablo[0] do
		senreg = tablo[i];
--TraceFrame:AddMessage("enreg "..i.." : "..senreg);
		ifin = 0;
		ideb = ifin+1;
		ifin = strfind(senreg,"@",ideb);
		itypeenreg = tonumber(strsub(senreg,ideb,ifin-1));
--TraceFrame:AddMessage("itypeenreg "..itypeenreg);
		if ( itypeenreg > 3 ) then
if ( DBCS_debug > 1 ) then
if ( bmessagedebug == 0 ) then
TraceFrame:AddMessage(DBCS_lienjoueurbynom(sjoueur).." a envoye la quete : "..snomquete);
TraceFrame:AddMessage("objectif : "..sobjectif);
bmessagedebug = 1;
end
end
			if ( DBQS[snomquete] == nil ) then
				DBQS[snomquete] = {};
				DBQS[snomquete].nb = 0;
			end
			inumobjectif = 0;
			for j = 1 , DBQS[snomquete].nb do
				if ( inumobjectif == 0 and DBQS[snomquete][j][1] == sobjectif ) then
					inumobjectif = j;
				end
			end
			if ( inumobjectif == 0 ) then
				inumobjectif = DBQS[snomquete].nb + 1;
				DBQS[snomquete][inumobjectif] = {};
				DBQS[snomquete].nb = inumobjectif;
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("c'est une nouvelle quete.");
end
				if ( DBCS_afficher_new_quetes == true ) then
					if ( bmessagedebug2 == 0 ) then
						TraceFrame:AddMessage(DBCS_lienjoueurbynom(sjoueur).." a envoy\195\169 une qu\195\170te que DBCS ne connaissait pas : "..snomquete);
						TraceFrame:AddMessage("objectif : "..sobjectif);
						bmessagedebug2 = 1;
					end
				end
			end
			tabloquete = DBQS[snomquete][inumobjectif];
			if ( tabloquete[1] == nil ) then
				tabloquete[1] = sobjectif;
			end
			if ( tabloquete[2] == nil ) then
				tabloquete[2] = inivmin;
			else
				if ( inivmin and inivmin < tabloquete[2] ) then
					tabloquete[2] = inivmin;
				end
			end
			if ( tabloquete[3] == nil ) then
				tabloquete[3] = inivconseil;
			end
			if ( tabloquete[7] == nil ) then
				tabloquete[7] = inumquete;
			end
			if ( tabloquete[8] == nil ) then
				tabloquete[8] = idateenvoi;
			end
			if ( tabloquete[10] == nil ) then
				tabloquete[10] = iargentrecquis;
			end
			if ( tabloquete[11] == nil ) then
				tabloquete[11] = isalairenon60;
			end
			if ( tabloquete[12] == nil ) then
				tabloquete[12] = isalaire60;
			end
			if ( tabloquete[13] == nil ) then
				tabloquete[13] = iquetevalidee;
			end
			if ( tabloquete[18] == nil ) then
				tabloquete[18] = ialliance;
			end
			if ( tabloquete[19] == nil ) then
				tabloquete[19] = ihorde;
			end
			if ( tabloquete[20] == nil ) then
				tabloquete[20] = scategorie;
			else
				if ( tabloquete[20] == scategorie or scategorie == "" or scategorie == DBQS_missingheader ) then
				else
					tabloquete[20] = scategorie;
				end
			end
			if ( tabloquete[21] == nil or tabloquete[21] == "" ) then
				tabloquete[21] = stype;
			end
			if ( tabloquete[26] == nil ) then
				tabloquete[26] = scategorietempo;
			else
				if ( tabloquete[26] == scategorietempo or scategorietempo == "" ) then
				else
					tabloquete[26] = scategorietempo;
				end
			end
			if ( itypeenreg > 4 ) then
				if ( tabloquete[4] == nil or strlen(tabloquete[4]) < strlen(sdescription) ) then
					tabloquete[4] = sdescription;
				end
				if ( itypeenreg > 5 ) then
					if ( tabloquete[9] == nil or strlen(tabloquete[9]) < strlen(sprogress) ) then
						tabloquete[9] = sprogress;
					end
					if ( itypeenreg > 6 ) then
						if ( tabloquete[17] == nil or strlen(tabloquete[17]) < strlen(scomplete) ) then
							tabloquete[17] = scomplete;
						end
						if ( itypeenreg > 11 ) then
							if ( inumqueteprec_new > 0 ) then
								if ( DBQS[snomqueteprec] == nil ) then
									DBQS[snomqueteprec] = {};
									DBQS[snomqueteprec].nb = 0;
								end
								k = 0;
								for j = 1 , DBQS[snomqueteprec].nb do
									if ( k == 0 and DBQS[snomqueteprec][j][1] == stexteobjprec ) then
										k = j;
									end
								end
								if ( k == 0 ) then
									k = DBQS[snomqueteprec].nb + 1;
									DBQS[snomqueteprec][k] = {};
									DBQS[snomqueteprec][k][1] = stexteobjprec;
									DBQS[snomqueteprec].nb = k;
								end
								if ( type(DBQS[snomqueteprec][k][25]) == "table" ) then
								else
									DBQS[snomqueteprec][k][25] = {};
								end
								bexist = 0;
								for j = 1 , table.getn(DBQS[snomqueteprec][k][25]) do
									if ( DBQS[snomqueteprec][k][25][j][1] == snomquete and DBQS[snomqueteprec][k][25][j][2] == sobjectif ) then
										bexist = 1;
									end
								end
								if ( bexist == 0 ) then
									j = table.getn(DBQS[snomqueteprec][k][25]) + 1;
									DBQS[snomqueteprec][k][25][j] = {};
									DBQS[snomqueteprec][k][25][j][1] = snomquete;
									DBQS[snomqueteprec][k][25][j][2] = sobjectif;
									DBQS[snomqueteprec][k][25].nb = j;
								end
								if ( type(tabloquete[24]) == "table" ) then
								else
									tabloquete[24] = {};
								end
								bexist = 0;
								for j = 1 , table.getn(tabloquete[24]) do
									if ( tabloquete[24][j][1] == snomqueteprec and tabloquete[24][j][2] == stexteobjprec ) then
										bexist = 1;
									end
								end
								if ( bexist == 0 ) then
									j = table.getn(tabloquete[24]) + 1;
									tabloquete[24][j] = {};
									tabloquete[24][j][1] = snomqueteprec;
									tabloquete[24][j][2] = stexteobjprec;
									tabloquete[24].nb = j;
								end
								stexteobjprec = "";
								inumqueteprec_new = 0;
							end
							if ( itypeenreg > 12 ) then
								if ( inumquetesuiv_new > 0 ) then
									if ( DBQS[snomquetesuiv] == nil ) then
										DBQS[snomquetesuiv] = {};
										DBQS[snomquetesuiv].nb = 0;
									end
									k = 0;
									for j = 1 , DBQS[snomquetesuiv].nb do
										if ( k == 0 and DBQS[snomquetesuiv][j][1] == stexteobjsuiv ) then
											k = j;
										end
									end
									if ( k == 0 ) then
										k = DBQS[snomquetesuiv].nb + 1;
										DBQS[snomquetesuiv][k] = {};
										DBQS[snomquetesuiv][k][1] = stexteobjsuiv;
										DBQS[snomquetesuiv].nb = k;
									end
									if ( type(DBQS[snomquetesuiv][k][24]) == "table" ) then
									else
										DBQS[snomquetesuiv][k][24] = {};
									end
									bexist = 0;
									for j = 1 , table.getn(DBQS[snomquetesuiv][k][24]) do
										if ( DBQS[snomquetesuiv][k][24][j][1] == snomquete and DBQS[snomquetesuiv][k][24][j][2] == sobjectif ) then
											bexist = 1;
										end
									end
									if ( bexist == 0 ) then
										j = table.getn(DBQS[snomquetesuiv][k][24]) + 1;
										DBQS[snomquetesuiv][k][24][j] = {};
										DBQS[snomquetesuiv][k][24][j][1] = snomquete;
										DBQS[snomquetesuiv][k][24][j][2] = sobjectif;
										DBQS[snomquetesuiv][k][24].nb = j;
									end
									if ( type(tabloquete[25]) == "table" ) then
									else
										tabloquete[25] = {};
									end
									bexist = 0;
									for j = 1 , table.getn(tabloquete[25]) do
										if ( tabloquete[25][j][1] == snomquetesuiv and tabloquete[25][j][2] == stexteobjsuiv ) then
											bexist = 1;
										end
									end
									if ( bexist == 0 ) then
										j = table.getn(tabloquete[25]) + 1;
										tabloquete[25][j] = {};
										tabloquete[25][j][1] = snomquetesuiv;
										tabloquete[25][j][2] = stexteobjsuiv;
										tabloquete[25].nb = j;
									end
									stexteobjsuiv = "";
									inumquetesuiv_new = 0;
								end
							end
						end
					end
				end
			end
		end
		if ( itypeenreg == 1 ) then
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			snomquete = strsub(senreg,ideb,ifin-1);
			iposdeb = strfind(snomquete,"%[");
			iposfin = strfind(snomquete,"%]");
			while ( iposdeb and iposfin ) do
				snomquete = strsub(snomquete,1,iposdeb-1)..strsub(snomquete,iposfin+1);
				iposdeb = strfind(snomquete,"%[");
				iposfin = strfind(snomquete,"%]");
			end
			iposdeb = 0;
			while ( iposdeb ) do
				if ( strsub(snomquete,1,1) == " " ) then
					snomquete = strsub(snomquete,2);
				else
					iposdeb = nil;
				end
			end
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			scategorie = strsub(senreg,ideb,ifin-1);
			if ( scategorie == "" ) then
				scategorie = nil;
			end
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			stype = strsub(senreg,ideb,ifin-1);
			if ( stype == "" ) then
				stype = nil;
			end
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			if ( ifin ) then
				scategorietempo = strsub(senreg,ideb,ifin-1);
				if ( scategorietempo == "" ) then
					scategorietempo = nil;
				end
			end
		elseif ( itypeenreg == 2 ) then
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			inivmin = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			inivconseil = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			inumquete = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			idateenvoi = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			iargentrecquis = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			isalairenon60 = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			isalaire60 = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			iquetevalidee = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			inbobjetsrecquis = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			inbobjetsobtenus = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			inbobjetschoix = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			ialliance = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			ihorde = tonumber(strsub(senreg,ideb,ifin-1));
		elseif ( itypeenreg == 3 ) then
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			sligne = strsub(senreg,ideb,strlen(senreg)-1);	--	,ifin-1
			sligne = DBQS_ajoutersautdeligne(sligne);
			sobjectif = sobjectif..sligne;
		elseif ( itypeenreg == 4 ) then
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			sligne = strsub(senreg,ideb,strlen(senreg)-1);	--	,ifin-1
			sligne = DBQS_ajoutersautdeligne(sligne);
			sdescription = sdescription..sligne;
		elseif ( itypeenreg == 5 ) then
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			sligne = strsub(senreg,ideb,strlen(senreg)-1);	--	,ifin-1
			sligne = DBQS_ajoutersautdeligne(sligne);
			sprogress = sprogress..sligne;
		elseif ( itypeenreg == 6 ) then
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			sligne = strsub(senreg,ideb,strlen(senreg)-1);	--	,ifin-1
			sligne = DBQS_ajoutersautdeligne(sligne);
			scomplete = scomplete..sligne;
		elseif ( itypeenreg == 7 ) then
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			inumsousobj = tonumber(strsub(senreg,ideb,ifin-1));
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			stexteobj = strsub(senreg,ideb,ifin-1);
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			stypeobj = strsub(senreg,ideb,ifin-1);
			if ( tabloquete[22] == nil ) then
				tabloquete[22] = {};
			end
			if ( tabloquete[22][inumsousobj] == nil ) then
				tabloquete[22][inumsousobj] = stexteobj;
			else
				if ( strlen(stexteobj) > strlen(tabloquete[22][inumsousobj]) ) then
					tabloquete[22][inumsousobj] = stexteobj;
				end
			end
			if ( tabloquete[23] == nil ) then
				tabloquete[23] = {};
			end
			if ( tabloquete[23][inumsousobj] == nil ) then
				tabloquete[23][inumsousobj] = stypeobj;
			end
		elseif ( itypeenreg == 8 ) then
			if ( tabloquete[14] == nil ) then
				tabloquete[14] = {};
			end
			for j = 1 , inbobjetsrecquis do
				ideb = ifin+1;
				ifin = strfind(senreg,"@",ideb);
				inumobjet = tonumber(strsub(senreg,ideb,ifin-1));
				ideb = ifin+1;
				ifin = strfind(senreg,"@",ideb);
				inbobjet = tonumber(strsub(senreg,ideb,ifin-1));
				tabloquete[14][inumobjet] = inbobjet;
				if ( DBOS[inumobjet] == nil and not ( inumobjet == 0 ) ) then
					-- ajouter un message de confirmation
					--SetItemRef("item:"..inumobjet..":"..snumcourt2);
					--GameTooltip:SetOwner(DBCS_Minimap_Button, "ANCHOR_TOPLEFT");
					--GameTooltip:SetHyperlink("item:"..inumobjet..":"..snumcourt2)
					DBcorpsFrame_Tooltip:SetOwner(WorldFrame,"ANCHOR_NONE");
					DBcorpsFrame_Tooltip:SetHyperlink("item:"..inumobjet..":0:0:0:0:0:0:0:0");
					DBobjets_initobjet("item:"..inumobjet..":0:0:0:0:0:0:0:0");
				end
if ( DBCS_debug > 1 ) then
	slink = DBobjets_GetItemLink(inumobjet,"0:0:0:0:0:0:0:0");
	if ( slink ) then
		TraceFrame:AddMessage("ajout de loot : "..inbobjet.." fois l'objet "..inumobjet..":0:0:0:0:0:0:0:0 "..slink);
	else
		_, _, _, hex = GetItemQualityColor(6);
		slink = hex.."|Hitem:"..inumobjet..":0:0:0:0:0:0:0:0|h[oula oula oula]|h|r";
		TraceFrame:AddMessage("ajout de loot : "..inbobjet.." fois l'objet "..inumobjet..":0:0:0:0:0:0:0:0 "..slink);
	end
end
			end
		elseif ( itypeenreg == 9 ) then
			if ( tabloquete[15] == nil ) then
				tabloquete[15] = {};
			end
			for j = 1 , inbobjetsobtenus do
				ideb = ifin+1;
				ifin = strfind(senreg,"@",ideb);
				inumobjet = tonumber(strsub(senreg,ideb,ifin-1));
				ideb = ifin+1;
				ifin = strfind(senreg,"@",ideb);
				inbobjet = tonumber(strsub(senreg,ideb,ifin-1));
				tabloquete[15][inumobjet] = inbobjet;
				if ( DBOS[inumobjet] == nil and not ( inumobjet == 0 ) ) then
					-- ajouter un message de confirmation
					--SetItemRef("item:"..inumobjet..":"..snumcourt2);
					--GameTooltip:SetOwner(DBCS_Minimap_Button, "ANCHOR_TOPLEFT");
					--GameTooltip:SetHyperlink("item:"..inumobjet..":"..snumcourt2)
					DBcorpsFrame_Tooltip:SetOwner(WorldFrame,"ANCHOR_NONE");
					DBcorpsFrame_Tooltip:SetHyperlink("item:"..inumobjet..":0:0:0:0:0:0:0:0");
					DBobjets_initobjet("item:"..inumobjet..":0:0:0:0:0:0:0:0");
				end
if ( DBCS_debug > 1 ) then
	slink = DBobjets_GetItemLink(inumobjet,"0:0:0:0:0:0:0:0");
	if ( slink ) then
		TraceFrame:AddMessage("ajout de loot : "..inbobjet.." fois l'objet "..inumobjet..":0:0:0:0:0:0:0:0 "..slink);
	else
		_, _, _, hex = GetItemQualityColor(6);
		slink = hex.."|Hitem:"..inumobjet..":0:0:0:0:0:0:0:0|h[oula oula oula]|h|r";
		TraceFrame:AddMessage("ajout de loot : "..inbobjet.." fois l'objet "..inumobjet..":0:0:0:0:0:0:0:0 "..slink);
	end
end
			end
		elseif ( itypeenreg == 10 ) then
			if ( tabloquete[16] == nil ) then
				tabloquete[16] = {};
			end
			for j = 1 , inbobjetschoix do
				ideb = ifin+1;
				ifin = strfind(senreg,"@",ideb);
				inumobjet = tonumber(strsub(senreg,ideb,ifin-1));
				ideb = ifin+1;
				ifin = strfind(senreg,"@",ideb);
				inbobjet = tonumber(strsub(senreg,ideb,ifin-1));
				tabloquete[16][inumobjet] = inbobjet;
				if ( DBOS[inumobjet] == nil and not ( inumobjet == 0 ) ) then
					-- ajouter un message de confirmation
					--SetItemRef("item:"..inumobjet..":"..snumcourt2);
					--GameTooltip:SetOwner(DBCS_Minimap_Button, "ANCHOR_TOPLEFT");
					--GameTooltip:SetHyperlink("item:"..inumobjet..":"..snumcourt2)
					DBcorpsFrame_Tooltip:SetOwner(WorldFrame,"ANCHOR_NONE");
					DBcorpsFrame_Tooltip:SetHyperlink("item:"..inumobjet..":0:0:0:0:0:0:0:0");
					DBobjets_initobjet("item:"..inumobjet..":0:0:0:0:0:0:0:0");
				end
if ( DBCS_debug > 1 ) then
	slink = DBobjets_GetItemLink(inumobjet,"0:0:0:0:0:0:0:0");
	if ( slink ) then
		TraceFrame:AddMessage("ajout de loot : "..inbobjet.." fois l'objet "..inumobjet..":0:0:0:0:0:0:0:0 "..slink);
	else
		_, _, _, hex = GetItemQualityColor(6);
		slink = hex.."|Hitem:"..inumobjet..":0:0:0:0:0:0:0:0|h[oula oula oula]|h|r";
		TraceFrame:AddMessage("ajout de loot : "..inbobjet.." fois l'objet "..inumobjet..":0:0:0:0:0:0:0:0 "..slink);
	end
end
			end
		elseif ( itypeenreg == 11 ) then
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			inumqueteprec_new = tonumber(strsub(senreg,ideb,ifin-1));
--TraceFrame:AddMessage("inumqueteprec_new : "..inumqueteprec_new);
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			sligne = strsub(senreg,ideb,strlen(senreg)-1);	--	,ifin-1
--TraceFrame:AddMessage("sligne : "..sligne);
			sligne = DBQS_ajoutersautdeligne(sligne);
			if ( inumqueteprec_new == inumqueteprec ) then
				stexteobjprec = stexteobjprec..sligne;
--TraceFrame:AddMessage("stexteobjprec : "..stexteobjprec);
			else
				if ( inumqueteprec > 1 ) then
					if ( DBQS[snomqueteprec] == nil ) then
						DBQS[snomqueteprec] = {};
						DBQS[snomqueteprec].nb = 0;
					end
					k = 0;
					for j = 1 , DBQS[snomqueteprec].nb do
						if ( k == 0 and DBQS[snomqueteprec][j][1] == stexteobjprec ) then
							k = j;
						end
					end
					if ( k == 0 ) then
						k = DBQS[snomqueteprec].nb + 1;
						DBQS[snomqueteprec][k] = {};
						DBQS[snomqueteprec][k][1] = stexteobjprec;
						DBQS[snomqueteprec].nb = k;
					end
					if ( type(DBQS[snomqueteprec][k][25]) == "table" ) then
					else
						DBQS[snomqueteprec][k][25] = {};
					end
					bexist = 0;
					for j = 1 , table.getn(DBQS[snomqueteprec][k][25]) do
						if ( DBQS[snomqueteprec][k][25][j][1] == snomquete and DBQS[snomqueteprec][k][25][j][2] == sobjectif ) then
							bexist = 1;
						end
					end
					if ( bexist == 0 ) then
						j = table.getn(DBQS[snomqueteprec][k][25]) + 1;
						DBQS[snomqueteprec][k][25][j] = {};
						DBQS[snomqueteprec][k][25][j][1] = snomquete;
						DBQS[snomqueteprec][k][25][j][2] = sobjectif;
						DBQS[snomqueteprec][k][25].nb = j;
					end
					if ( type(tabloquete[24]) == "table" ) then
					else
						tabloquete[24] = {};
					end
					bexist = 0;
					for j = 1 , table.getn(tabloquete[24]) do
						if ( tabloquete[24][j][1] == snomqueteprec and tabloquete[24][j][2] == stexteobjprec ) then
							bexist = 1;
						end
					end
					if ( bexist == 0 ) then
						j = table.getn(tabloquete[24]) + 1;
						tabloquete[24][j] = {};
						tabloquete[24][j][1] = snomqueteprec;
						tabloquete[24][j][2] = stexteobjprec;
						tabloquete[24] = j;
					end
					stexteobjprec = "";
				end
				snomqueteprec = sligne;
--TraceFrame:AddMessage("snomqueteprec : "..snomqueteprec);
			end
			inumqueteprec = inumqueteprec_new;
--TraceFrame:AddMessage("inumqueteprec : "..inumqueteprec);
		elseif ( itypeenreg == 12 ) then
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			inumquetesuiv_new = tonumber(strsub(senreg,ideb,ifin-1));
--TraceFrame:AddMessage("inumquetesuiv_new : "..inumquetesuiv_new);
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			sligne = strsub(senreg,ideb,strlen(senreg)-1);	--	,ifin-1
--TraceFrame:AddMessage("sligne : "..sligne);
			sligne = DBQS_ajoutersautdeligne(sligne);
			if ( inumquetesuiv_new == inumquetesuiv ) then
				stexteobjsuiv = stexteobjsuiv..sligne;
--TraceFrame:AddMessage("stexteobjsuiv : "..stexteobjsuiv);
			else
				if ( inumquetesuiv > 1 ) then
					if ( DBQS[snomquetesuiv] == nil ) then
						DBQS[snomquetesuiv] = {};
						DBQS[snomquetesuiv].nb = 0;
					end
					k = 0;
					for j = 1 , DBQS[snomquetesuiv].nb do
						if ( k == 0 and DBQS[snomquetesuiv][j][1] == stexteobjsuiv ) then
							k = j;
						end
					end
					if ( k == 0 ) then
						k = DBQS[snomquetesuiv].nb + 1;
						DBQS[snomquetesuiv][k] = {};
						DBQS[snomquetesuiv][k][1] = stexteobjsuiv;
						DBQS[snomquetesuiv].nb = k;
					end
					if ( type(DBQS[snomquetesuiv][k][24]) == "table" ) then
					else
						DBQS[snomquetesuiv][k][24] = {};
					end
					bexist = 0;
					for j = 1 , table.getn(DBQS[snomquetesuiv][k][24]) do
						if ( DBQS[snomquetesuiv][k][24][j][1] == snomquete and DBQS[snomquetesuiv][k][24][j][2] == sobjectif ) then
							bexist = 1;
						end
					end
					if ( bexist == 0 ) then
						j = table.getn(DBQS[snomquetesuiv][k][24]) + 1;
						DBQS[snomquetesuiv][k][24][j] = {};
						DBQS[snomquetesuiv][k][24][j][1] = snomquete;
						DBQS[snomquetesuiv][k][24][j][2] = sobjectif;
						DBQS[snomquetesuiv][k][24].nb = j;
					end
					if ( type(tabloquete[25]) == "table" ) then
					else
						tabloquete[25] = {};
					end
					bexist = 0;
					for j = 1 , table.getn(tabloquete[25]) do
						if ( tabloquete[25][j][1] == snomquetesuiv and tabloquete[25][j][2] == stexteobjsuiv ) then
							bexist = 1;
						end
					end
					if ( bexist == 0 ) then
						j = table.getn(tabloquete[25]) + 1;
						tabloquete[25][j] = {};
						tabloquete[25][j][1] = snomquetesuiv;
						tabloquete[25][j][2] = stexteobjsuiv;
						tabloquete[25].nb = j;
					end
					stexteobjsuiv = "";
				end
				snomquetesuiv = sligne;
--TraceFrame:AddMessage("snomquetesuiv : "..snomquetesuiv);
			end
			inumquetesuiv = inumquetesuiv_new;
--TraceFrame:AddMessage("inumquetesuiv : "..inumquetesuiv);
		elseif ( itypeenreg == 13 ) then
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			snomdonneur = strsub(senreg,ideb,ifin-1);
			if ( tabloquete[5] == nil ) then
				tabloquete[5] = {};
			end
			tabloquete[5][snomdonneur] = 0;
		elseif ( itypeenreg == 14 ) then
			ideb = ifin+1;
			ifin = strfind(senreg,"@",ideb);
			snomfinisseur = strsub(senreg,ideb,ifin-1);
			if ( tabloquete[6] == nil ) then
				tabloquete[6] = {};
			end
			tabloquete[6][snomfinisseur] = 0;
		end
	end
	DBquetes_sauvegarderquete(snomquete,inumobjectif);
	DBQS_quetes_tempo[sjoueur][stime] = nil;

end

function DBQS_traitermessagecms(sjoueur,ssuite)

	if ( sjoueur == DBQS_joueur ) then
		return;
	else
		if ( strlen(ssuite) > 5 ) then
			ssection = strsub(ssuite,1,1);
			straitement = strsub(ssuite,2,2);
			sversion = strsub(ssuite,3,4);
			senreg = strsub(ssuite,6);
			if ( ssection == "Q" ) then
				if ( straitement == "M" ) then
					if ( sversion == "01" ) then
--TraceFrame:AddMessage("senreg "..senreg);
						if ( DBQS_quetes_tempo[sjoueur] == nil ) then
							DBQS_quetes_tempo[sjoueur] = {};
						end
						ifin = 0;
						ideb = ifin+1;
						ifin = strfind(senreg,"@",ideb);
						stime = strsub(senreg,ideb,ifin-1);
						if ( DBQS_quetes_tempo[sjoueur][stime] == nil ) then
							DBQS_quetes_tempo[sjoueur][stime] = {};
						end
						ideb = ifin+1;
						ifin = strfind(senreg,"@",ideb);
						inumenreg = tonumber(strsub(senreg,ideb,ifin-1));
						ideb = ifin+1;
						if ( inumenreg == 0 ) then
							ifin = strfind(senreg,"@",ideb);
							inbenreg = tonumber(strsub(senreg,ideb,ifin-1));
							DBQS_quetes_tempo[sjoueur][stime][inumenreg] = inbenreg;
						else
							DBQS_quetes_tempo[sjoueur][stime][inumenreg] = strsub(senreg,ideb);
						end
						if ( DBQS_quetes_tempo[sjoueur][stime][0] and table.getn(DBQS_quetes_tempo[sjoueur][stime]) == DBQS_quetes_tempo[sjoueur][stime][0] ) then
							DBQS_traiterquete(sjoueur,stime);
						end
					end
				end
			elseif ( ssection == "P" ) then
				if ( straitement == "A" ) then
					if ( sversion == "01" ) then
						ifin = 0;
						ideb = ifin+1;
						ifin = strfind(senreg,"@",ideb);
						snomdonneur = strsub(senreg,ideb,ifin-1);
						ideb = ifin+1;
						ifin = strfind(senreg,"@",ideb);
						snumregiondonneur = strsub(senreg,ideb,ifin-1);
						ideb = ifin+1;
						ifin = strfind(senreg,"@",ideb);
						x = tonumber(strsub(senreg,ideb,ifin-1));
						ideb = ifin+1;
						ifin = strfind(senreg,"@",ideb);
						y = tonumber(strsub(senreg,ideb,ifin-1));
						DBPS_enregpnj(snomdonneur,snumregiondonneur,x,y,0);
					end
				end
			end
		end
	end

end

function DBquetes_OnEvent(self,event,...)

--	questDescription, questObjectives = GetQuestLogQuestText();

local offset;
local sdebut;
local ipos;
local saddon;
local ssuite;
local sgetlocale;

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

--	if ( DBCS_wow_2_4() == true ) then
--		return nil;
--	end
	if ( event == "" ) then
	elseif ( event == "CHAT_MSG_CHANNEL" ) then
		if ( DBCS_CMS_numcanalCMS > 0 ) then
			if ( arg9 and strlower(arg9) == DBCS_CMS_NOMCANAL ) then
				sdebut = strsub(arg1,1,2);
				if ( sdebut and sdebut == "@A" ) then
					ipos = strfind(arg1,"@",3);
					if ( ipos ) then
						saddon = strsub(arg1,3,ipos-1);
						if ( saddon == "DBQS" ) then
							ssuite = strsub(arg1,ipos+1);
							ipos = strfind(ssuite,"@",1);
							if ( ipos ) then
								sgetlocale = strsub(ssuite,1,ipos-1);
								if ( sgetlocale == DBCS_getlocale ) then
									ssuite = strsub(ssuite,ipos+1);
									DBQS_traitermessagecms(arg2,ssuite);
								end
							end
						--elseif ( saddon == "DBPS" ) then
						--	DBQS_traitermessagecms(arg2,ssuite);
						end
					end
				end
			end
		end
	elseif ( event == "GOSSIP_SHOW" ) then	--	or event == "QUEST_GREETING" 
--if ( DBCS_debug > 1 ) then
--DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
--end

		DBquetes_liregossip();

	elseif ( event == "QUEST_ACCEPT_CONFIRM" ) then
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end
--	elseif ( event == "QUEST_COMPLETE" ) then
--if ( DBCS_debug > 1 ) then
--DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
--end
	elseif ( event == "QUEST_DETAIL" ) then
		DBQS_event = event;
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end

		local nomquete,description,objectif,nomdonneur,numregiondonneur;
		local i,j;
		local iniv;
		local nb;
		local don,money;
		local ibon;
		local bmodif = 0;
		local ideb,ifin;

		if ( timeprec > 0 ) then
			if ( (GetTime() - timeprec) <= 1 ) then
--TraceFrame:AddMessage("le temps est de - de 1 seconde. "..(GetTime() - timeprec));
				timeprec = 0;
			else
--TraceFrame:AddMessage("le temps est de "..(GetTime() - timeprec).." secondes.");
				nomqueteprec = nil;
				objectifprec = nil;
				timeprec = 0;
			end
		else
			nomqueteprec = nil;
			objectifprec = nil;
		end

		ibon = 1;

		--TraceFrame:AddMessage("---PNJ : "..QuestFrameNpcNameText:GetText());
		nomdonneur = QuestFrameNpcNameText:GetText();
		itypedegroupe = DBCS_typedegroupe();
		if ( itypedegroupe == 1 ) then
			for i = 1, 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 , GetNumRaidMembers() do
				sjoueur, _, _, _, _, _, _, _, _ = GetRaidRosterInfo(i);
				if ( nomdonneur and sjoueur == nomdonneur ) then
--TraceFrame:AddMessage(nomdonneur.." est un membre de mon raid.");
					nomdonneur = nil;
				end
			end
		end
		if ( nomdonneur ) then
			x,y = DBCS_position100();
			if ( arg9 and arg9 == "QUEST_ITEM_UPDATE" ) then
				--DBPS_enregpnj(nomdonneur,DBCS_numregionbyname(GetRealZoneText()),x,y,1);
			else
				DBPS_enregpnj(nomdonneur,DBCS_Region_liste_code_region_courante_new(),x,y,1);
			end
		end
		--if ( UnitExists(nomdonneur) ) then
		--	-- sauvegarder la position du pnj
		--else
		--	-- vérifier que le dernier objet clické ds l inventaire porte le nom de ce donneur de quete
		--end
--TraceFrame:AddMessage("---nomdonneur : "..nomdonneur);
		numregiondonneur = DBCS_Region_liste_code_region_courante_new();	--DBCS_numregionbyname(GetRealZoneText());
--TraceFrame:AddMessage("---numregiondonneur : "..numregiondonneur);
		--snumregion = DBCS_Region_liste_code_region_courante_new();	--DBCS_numregionbyname(GetRealZoneText());
		local nomquete = GetTitleText();
		ideb = strfind(nomquete,"%[");
		ifin = strfind(nomquete,"%]");
		while ( ideb and ifin ) do
			nomquete = strsub(nomquete,1,ideb-1)..strsub(nomquete,ifin+1);
			ideb = strfind(nomquete,"%[");
			ifin = strfind(nomquete,"%]");
		end
--TraceFrame:AddMessage("---nomquete : "..nomquete);
--TraceFrame:AddMessage(nomquete);
		local description = GetQuestText();
--TraceFrame:AddMessage("---description : ");
--TraceFrame:AddMessage(description);
		local objectif = GetObjectiveText();
		objectif = DBQS_remplacerjoueurdanstexte(nomquete,0,objectif);
--TraceFrame:AddMessage("---objectif : ");
--TraceFrame:AddMessage(objectif);
		numRequiredItems = GetNumQuestItems();
		numQuestRewards = GetNumQuestRewards();
		numQuestChoices = GetNumQuestChoices();
		iniv = nil;
--/script DEFAULT_CHAT_FRAME:AddMessage(table.getn({GetGossipAvailableQuests()}));
		tq_availablelist = {GetGossipAvailableQuests()};
		--nb = table.getn(tq_availablelist)/3;
local ival1;
local sval2;
		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
		for i = 1, nb do
			if ( tq_availablelist[((i-1)*3)+1] == nomquete ) then
				iniv = tq_availablelist[((i-1)*3)+2];
			end
		end
		if ( iniv == nil ) then
--/script DEFAULT_CHAT_FRAME:AddMessage(table.getn({GetNumAvailableQuests()}));
			numAvailableQuests = GetNumAvailableQuests();
			for i = 1 , numAvailableQuests do
				if ( GetAvailableTitle(i) == nomquete ) then
					iniv = GetAvailableLevel(i);
				end
			end
		end
		inivmin = UnitLevel("Player");
		if ( iniv ) then
			if ( iniv < inivmin ) then
				inivmin = iniv;
			end
		end
--TraceFrame:AddMessage("---niv conseil : "..(iniv or ""));
		don = GetQuestMoneyToGet();
--TraceFrame:AddMessage("---argent a donner : "..don);
		money = GetRewardMoney();
--TraceFrame:AddMessage("---salaire : "..money);

		--recherche si cette quete et cet  objectif existe déjà, si cest le cas, on modifiera cette quete
		if ( DBQS[nomquete] == nil ) then
			DBQS[nomquete] = {};
			DBQS[nomquete].nb = 0;
			bmodif = 1;
		end
		j = 0;
		for i = 1 , DBQS[nomquete].nb do
			if ( DBQS[nomquete][i][1] == objectif ) then
				j = i;
			end
		end
		if ( j == 0 ) then
			j = DBQS[nomquete].nb + 1;
			DBQS[nomquete][j] = {};
			DBQS[nomquete].nb = j;
			bmodif = 2;
			if ( DBCS_afficher_new_quetes == true ) then
				TraceFrame:AddMessage("DBCS ne connaissait pas la qu\195\170te : "..nomquete);
				TraceFrame:AddMessage("objectif : "..objectif);
			end
		end

		if ( DBQS[nomquete][j][1] == nil ) then
			DBQS[nomquete][j][1] = objectif;
			bmodif = 3;
		end
		if ( DBQS[nomquete][j][2] == nil ) then
			DBQS[nomquete][j][2] = inivmin;
			bmodif = 4;
		end
		if ( inivmin < DBQS[nomquete][j][2] ) then
			DBQS[nomquete][j][2] = inivmin;
			bmodif = 5;
		end
		if ( DBQS[nomquete][j][3] == nil and iniv ) then
			DBQS[nomquete][j][3] = iniv;	-- niveau conseillé
			bmodif = 6;
		end
		if ( DBQS[nomquete][j][4] == nil or strlen(DBQS[nomquete][j][4]) < strlen(description) ) then
			DBQS[nomquete][j][4] = description;
			bmodif = 7;
		end
		if ( type(DBQS[nomquete][j][5]) == "table" ) then
		else
			DBQS[nomquete][j][5] = {};
		end
		if ( nomdonneur ) then
			if ( DBQS[nomquete][j][5][nomdonneur] == nil ) then
				DBQS[nomquete][j][5][nomdonneur] = 0;
				bmodif = 8;
			end
		end
		if ( type(DBQS[nomquete][j][6]) == "table" ) then
		else
			DBQS[nomquete][j][6] = {};
		end
		--DBQS[nomquete][j][7] = nil;
		--DBQS[nomquete][j][8] = nil;
		if ( DBQS[nomquete][j][10] == nil ) then
			if ( don > 0 ) then
				DBQS[nomquete][j][10] = don;
				bmodif = 9;
			end
		end
		if ( UnitLevel("Player") < DBCS_nivmax ) then
			if ( DBQS[nomquete][j][11] == nil ) then
				if ( money > 0 ) then
					DBQS[nomquete][j][11] = money;
					bmodif = 10;
				end
			end
		else
			if ( DBQS[nomquete][j][12] == nil ) then
				if ( money > 0 ) then
					DBQS[nomquete][j][12] = money;
					bmodif = 11;
				end
			end
		end
		if ( numRequiredItems > 0 ) then
--TraceFrame:AddMessage("---objets recquis : "..numRequiredItems);
			if ( DBQS[nomquete][j][14] == nil ) then
				DBQS[nomquete][j][14] = {};
			end
			for i=1, numRequiredItems, 1 do
				_, _, 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+)") do	-- %p?
						inumobjet = tonumber(a);
						if ( DBQS[nomquete][j][14][inumobjet] == nil ) then
							DBQS[nomquete][j][14][inumobjet] = nbobjets;
							bmodif = 12;
						end
					end
				else
					ibon = 0;
				end
			end
		end
		if ( numQuestRewards > 0 ) then
--TraceFrame:AddMessage("---objets obtenus : "..numQuestRewards);
			if ( DBQS[nomquete][j][15] == nil ) then
				DBQS[nomquete][j][15] = {};
			end
			for i=1, numQuestRewards, 1 do
				_, _, 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+)") do
						inumobjet = tonumber(a);
						if ( DBQS[nomquete][j][15][inumobjet] == nil ) then
							DBQS[nomquete][j][15][inumobjet] = nbobjets;
							bmodif = 13;
						end
					end
				else
					ibon = 0;
				end
			end
		end
		if ( numQuestChoices > 0 ) then
--TraceFrame:AddMessage("---objets a choisir : "..numQuestChoices);
			if ( DBQS[nomquete][j][16] == nil ) then
				DBQS[nomquete][j][16] = {};
			end
			for i=1, numQuestChoices, 1 do
				_, _, 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+)") do
						inumobjet = tonumber(a);
						if ( DBQS[nomquete][j][16][inumobjet] == nil ) then
							DBQS[nomquete][j][16][inumobjet] = nbobjets;
							bmodif = 14;
						end
					end
				else
					ibon = 0;
				end
			end
		end
		if ( UnitFactionGroup("player")	== "Alliance" ) then
		--DBQS[nomquete][j][18] = 1;	--	alliance
			if ( DBQS[nomquete][j][18] == nil ) then
				DBQS[nomquete][j][18] = 1;	--	alliance
				bmodif = 15;
			end
		elseif ( UnitFactionGroup("player") == "Horde" ) then
		--DBQS[nomquete][j][19] = 1;	--	horde
			if ( DBQS[nomquete][j][19] == nil ) then
				DBQS[nomquete][j][19] = 1;	--	horde
				bmodif = 16;
			end
		end

		if ( DBQS[nomquete][j][26] == nil ) then
			DBQS[nomquete][j][26] = GetRealZoneText();	-- catégorie temporaire
			bmodif = 17;
		else
			if ( DBQS[nomquete][j][26] == GetRealZoneText() ) then
			else
				DBQS[nomquete][j][26] = GetRealZoneText();	-- catégorie temporaire
				bmodif = 18;
			end
		end
		
		if ( nomqueteprec and objectifprec ) then
			if ( DBQS[nomquete][j][24] == nil ) then
				DBQS[nomquete][j][24] = {};
				DBQS[nomquete][j][24].nb = 0;
			end
			nb = DBQS[nomquete][j][24].nb;
			i = 0;
			bfin = 0;
			while ( i < nb and bfin == 0 ) do
				i = i + 1;
				if ( DBQS[nomquete][j][24][i][1] == nomqueteprec and DBQS[nomquete][j][24][i][2] == objectifprec ) then
					bfin = 1;
				end
			end
			if ( bfin == 0 ) then
				i = nb + 1;
				DBQS[nomquete][j][24][i] = {};
				DBQS[nomquete][j][24][i][1] = nomqueteprec;
				DBQS[nomquete][j][24][i][2] = objectifprec;
				DBQS[nomquete][j][24].nb = i;
				bmodif = 19;
			end
			if ( DBQS[nomqueteprec] == nil ) then
				DBQS[nomqueteprec] = {};
				DBQS[nomqueteprec].nb = 0;
			end
			if ( DBQS[nomqueteprec] ) then
				nb = DBQS[nomqueteprec].nb;
				k = 0;
				bfin = 0;
				while ( k < nb and bfin == 0 ) do
					k = k + 1;
					if ( DBQS[nomqueteprec][k][1] == objectifprec ) then
						bfin = 1;
					end
				end
				if ( bfin == 0 ) then
					k = DBQS[nomqueteprec].nb + 1;
					DBQS[nomqueteprec][k] = {};
					DBQS[nomqueteprec][k][1] = objectifprec;
					DBQS[nomqueteprec].nb = k;
					bfin = 1;
				end
				if ( bfin == 1 ) then
					if ( DBQS[nomqueteprec][k][25] == nil ) then
						DBQS[nomqueteprec][k][25] = {};
						DBQS[nomqueteprec][k][25].nb = 0;
					end
					nb = DBQS[nomqueteprec][k][25].nb;
					i = 0;
					bfin = 0;
					while ( i < nb and bfin == 0 ) do
						i = i + 1;
						if ( DBQS[nomqueteprec][k][25][i][1] == nomquete and DBQS[nomqueteprec][k][25][i][2] == objectif ) then
							bfin = 1;
						end
					end
					if ( bfin == 0 ) then
						i = nb + 1;
						DBQS[nomqueteprec][k][25][i] = {};
						DBQS[nomqueteprec][k][25][i][1] = nomquete;
						DBQS[nomqueteprec][k][25][i][2] = objectif;
						DBQS[nomqueteprec][k][25].nb = i;
						if ( DBCS_CMS_numcanalCMS > 0 ) then
							DBQS_envoyerquete(nomqueteprec,k);
						end
					end
				end
			end
		end
		
		if ( bmodif == 0 ) then
			if ( DBQS[nomquete][j][13] == nil or DBQS[nomquete][j][13] == 0 ) then
				if ( DBQS[nomquete][j][8] == nil or DBQS[nomquete][j][8] < tonumber(DBCS_date()) ) then
					bmodif = 20;
					DBQS[nomquete][j][8] = tonumber(DBCS_date());
				end
			end
		else
			DBQS[nomquete][j][8] = tonumber(DBCS_date());
		end

		DBquetes_sauvegarderquete(nomquete,j);
		
		if ( ibon == 0 ) then
--TraceFrame:AddMessage("DBQS n'a pas pu lire certaines infos de la quete : "..nomquete..", veuillez la re-ouvrir.");
--message("DBQS n'a pas pu lire certaines infos de cette quete, veuillez la re-ouvrir.");
			--HideUIPanel(QuestFrame);
		else
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("DBQS a bien lu les infos de la quete : "..nomquete..".");
end
		end

		if ( bmodif > 0 and ibon == 1 ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("bmodif = "..bmodif);
end
			DBQS_event = nil;
			if ( DBCS_CMS_numcanalCMS > 0 ) then
				DBQS_envoyerquete(nomquete,j);
			end
		end

	elseif ( ( event == "QUEST_PROGRESS" ) or ( event == "QUEST_COMPLETE" ) ) then
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end
DBQS_event = event;

local ival1;
local sval2;

		DBQS_logdispo = 0;

		local bmodif = 0;
		local ibon;
		local ideb,ifin;

		nomqueteprec = nil;
		objectifprec = nil;

		nomfinisseur = QuestFrameNpcNameText:GetText();
		x,y = DBCS_position100();
		if ( arg9 and arg9 == "QUEST_ITEM_UPDATE" ) then
			--DBPS_enregpnj(nomfinisseur,DBCS_numregionbyname(GetRealZoneText()),x,y,1);
		else
			DBPS_enregpnj(nomfinisseur,DBCS_Region_liste_code_region_courante_new(),x,y,1);
		end
		--DBPS_enregpnj(nomfinisseur,DBCS_numregionbyname(GetRealZoneText()),x,y,1);
--TraceFrame:AddMessage("---nomfinisseur : "..nomfinisseur);
		numregionfinisseur = DBCS_Region_liste_code_region_courante_new();	--DBCS_numregionbyname(GetRealZoneText());
--TraceFrame:AddMessage("---numregionfinisseur : "..numregionfinisseur);
		nomquete = GetTitleText();
		iposdeb = strfind(nomquete,"%[");
		iposfin = strfind(nomquete,"%]");
		while ( iposdeb and iposfin ) do
			nomquete = strsub(nomquete,1,iposdeb-1)..strsub(nomquete,iposfin+1);
			iposdeb = strfind(nomquete,"%[");
			iposfin = strfind(nomquete,"%]");
		end
		iposdeb = 0;
		while ( iposdeb ) do
			if ( strbyte(strsub(nomquete,1,1)) == 32 ) then
				nomquete = strsub(nomquete,2);
			else
				iposdeb = nil;
			end
		end
--TraceFrame:AddMessage("---nomquete : "..nomquete);

		if ( DBQS[nomquete] == nil ) then
			DBQS[nomquete] = {};
			DBQS[nomquete].nb = 0;
			bmodif = 1;
		end

		ibon = 1;
		objectif = "";
		nomcateg = nil;
		typequete = nil;
		iniv = nil;
		i = 0;
		j = 0;
		nb, nbquetes = GetNumQuestLogEntries();
		ifin = 0;
		while ( nb > 0 and i < nb and ifin == 0 ) do
			i = i + 1;
			nomquetelog, nivquetelog, typequetelog, _, isHeader, isCollapsed, isComplete, _ = GetQuestLogTitle(i);
			--questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily = GetQuestLogTitle(questIndex);
			--questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete = GetQuestLogTitle(questID);
			iposdeb = strfind(nomquetelog,"%[");
			iposfin = strfind(nomquetelog,"%]");
			while ( iposdeb and iposfin ) do
				nomquetelog = strsub(nomquetelog,1,iposdeb-1)..strsub(nomquetelog,iposfin+1);
				iposdeb = strfind(nomquetelog,"%[");
				iposfin = strfind(nomquetelog,"%]");
			end
			iposdeb = 0;
			while ( iposdeb ) do
				if ( strsub(nomquetelog,1,1) == " " ) then
					nomquetelog = strsub(nomquetelog,2);
				else
					iposdeb = nil;
				end
			end
			if ( isHeader ) then
				nomcateg = nomquetelog;
			end
			--if ( isCollapsed ) then
			--	ExpandQuestHeader(i);
			--	nb, _ = GetNumQuestLogEntries();
			--end
			if ( nomquetelog == nomquete ) then
				typequete = typequetelog;
				iniv = nivquetelog;
				isav = GetQuestLogSelection();
				
				SelectQuestLogEntry(i);
				description , objectif = GetQuestLogQuestText();
				objectif = DBQS_remplacerjoueurdanstexte(nomquete,0,objectif);
--TraceFrame:AddMessage("---objectif : "..objectif);
				j = 0;
				for i = 1 , DBQS[nomquete].nb do
					if ( DBQS[nomquete][i][1] == objectif ) then
						j = i;
					end
				end
				if ( j == 0 ) then
					j = DBQS[nomquete].nb + 1;
					DBQS[nomquete][j] = {};
					DBQS[nomquete].nb = j;
					bmodif = 1;
					if ( DBCS_afficher_new_quetes == true ) then
						TraceFrame:AddMessage("DBCS ne connaissait pas la qu\195\170te : "..nomquete);
						TraceFrame:AddMessage("objectif : "..objectif);
					end
				end

				--	1
				if ( DBQS[nomquete][j][1] == nil ) then
					DBQS[nomquete][j][1] = objectif;
					bmodif = 1;
				end
				--	3
				if ( DBQS[nomquete][j][3] == nil and iniv ) then
					DBQS[nomquete][j][3] = iniv;
					bmodif = 1;
				end
				--	2
				if ( DBQS[nomquete][j][2] == nil and iniv ) then
					DBQS[nomquete][j][2] = iniv;
					bmodif = 1;
				end
				if ( DBQS[nomquete][j][2] > UnitLevel("Player") ) then
					DBQS[nomquete][j][2] = UnitLevel("Player");
					bmodif = 1;
				end
				--	4
				if ( DBQS[nomquete][j][4] == nil or strlen(DBQS[nomquete][j][4]) < strlen(description) ) then
					DBQS[nomquete][j][4] = description;
					bmodif = 1;
				end
				--	10
				if ( DBQS[nomquete][j][10] == nil ) then
					don = GetQuestLogRequiredMoney();
					if ( don > 0 ) then
						DBQS[nomquete][j][10] = don;
						bmodif = 1;
					end
				end
				--	11	12
				if ( UnitLevel("Player") < DBCS_nivmax ) then
					if ( DBQS[nomquete][j][11] == nil ) then
						money = GetQuestLogRewardMoney();
						if ( money > 0 ) then
							DBQS[nomquete][j][11] = money;
							bmodif = 1;
						end
					end
				else
					if ( DBQS[nomquete][j][12] == nil ) then
						money = GetQuestLogRewardMoney();
						if ( money > 0 ) then
							DBQS[nomquete][j][12] = money;
							bmodif = 1;
						end
					end
				end
				--	15
				--nbitemreward = GetNumQuestLogRewards();
				--local name, texture, numItems, quality, isUsable = GetQuestLogRewardInfo(requiredItem.type, i);
				--	16
				--nbitemchoix = GetNumQuestLogChoices();
				--local name, texture, numItems, quality, isUsable = GetQuestLogChoiceInfo(requiredItem.type, i);
				--	20
				if ( DBQS[nomquete][j][20] == nil ) then
					DBQS[nomquete][j][20] = nomcateg;
					bmodif = 1;
				else
					if ( DBQS[nomquete][j][20] == nomcateg or nomcateg == "" or nomcateg == DBQS_missingheader ) then
					else
						DBQS[nomquete][j][20] = nomcateg;
						bmodif = 1;
					end
				end
				--	21
				if ( DBQS[nomquete][j][21] == nil and typequete ) then
					DBQS[nomquete][j][21] = typequete;
					bmodif = 1;
				end
				--	22	23
				nbsousobjectifs = GetNumQuestLeaderBoards();	--	GetNumQuestLogLeaderBoards();	--	[questID]
				if ( nbsousobjectifs > 0 ) then
					if ( DBQS[nomquete][j][22] == nil ) then
						DBQS[nomquete][j][22] = {};
						bmodif = 1;
					end
					if ( DBQS[nomquete][j][23] == nil ) then
						DBQS[nomquete][j][23] = {};
						bmodif = 1;
					end
				end
				for k = 1, nbsousobjectifs do
					nomsousobj, typsousobj, finsousobj = GetQuestLogLeaderBoard(k);	--	, [questID]
					if ( nomsousobj ) then
						if ( DBQS[nomquete][j][22][k] == nil ) then
							DBQS[nomquete][j][22][k] = nomsousobj;
							bmodif = 1;
						else
							if ( strlen(DBQS[nomquete][j][22][k]) < strlen(nomsousobj) ) then
								DBQS[nomquete][j][22][k] = nomsousobj;
								bmodif = 1;
							end
							---- si on le trouve, mémoriser et garder le texte de base : monstres tués : 0/4
							--ipos = strfind(nomsousobj,"0/",1);
							--if ( ipos ) then
							--	if ( DBQS[nomquete][j][22][k] == nomsousobj ) then
							--	else
							--		DBQS[nomquete][j][22][k] = nomsousobj;
							--		bmodif = 1;
							--	end
							--end
						end
						if ( DBQS[nomquete][j][23][k] == nil ) then
							DBQS[nomquete][j][23][k] = typsousobj;
							bmodif = 1;
						end
					else
						ibon = 0;
					end
				end
				
				SelectQuestLogEntry(isav);
				
				ifin = 1;
			end
		end
		if ( j == 0 ) then
			for i = 1 , DBQS[nomquete].nb do
				if ( DBQS[nomquete][i][1] == objectif ) then
					j = i;
				end
			end
			if ( j == 0 ) then
				j = DBQS[nomquete].nb + 1;
				DBQS[nomquete][j] = {};
				DBQS[nomquete][j][1] = "";
				DBQS[nomquete].nb = j;
				bmodif = 1;
				if ( DBCS_afficher_new_quetes == true ) then
					TraceFrame:AddMessage("DBCS ne connaissait pas la qu\195\170te : "..nomquete);
					TraceFrame:AddMessage("objectif : "..objectif);
				end
			end
		end
		--	3
		if ( iniv == 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] == nomquete ) then
					iniv = tq_activelist[((i-1)*3)+2];
				end
			end
		end
		if ( iniv == 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] == nomquete ) then
					iniv = tq_availablelist[((i-1)*3)+2];
				end
			end
		end
		if ( iniv == nil ) then
			numActiveQuests = GetNumActiveQuests();
			for i = 1 , numActiveQuests do
				if ( GetActiveTitle(i) == nomquete ) then
					iniv = GetActiveLevel(i);
				end
			end
		end
		if ( iniv == nil ) then
			numAvailableQuests = GetNumAvailableQuests();
			for i = 1 , numAvailableQuests do
				if ( GetAvailableTitle(i) == nomquete ) then
					iniv = GetAvailableLevel(i);
				end
			end
		end
		if ( iniv ) then
			if ( DBQS[nomquete][j][3] == nil ) then
				DBQS[nomquete][j][3] = iniv;
				bmodif = 1;
			end
		end
--TraceFrame:AddMessage("---niv conseil : "..(iniv or ""));
		--	2
		inivmin = UnitLevel("Player");
		if ( iniv ) then
			if ( iniv < inivmin ) then
				inivmin = iniv;
			end
		end
		if ( DBQS[nomquete][j][2] == nil ) then
			DBQS[nomquete][j][2] = inivmin;
			bmodif = 1;
		end
		if ( DBQS[nomquete][j][2] > inivmin ) then
			DBQS[nomquete][j][2] = inivmin;
			bmodif = 1;
		end
		--	5
		if ( type(DBQS[nomquete][j][5]) == "table" ) then
		else
			DBQS[nomquete][j][5] = {};
		end
		--	6
		if ( type(DBQS[nomquete][j][6]) == "table" ) then
		else
			DBQS[nomquete][j][6] = {};
		end
		if ( DBQS[nomquete][j][6][nomfinisseur] == nil ) then
			DBQS[nomquete][j][6][nomfinisseur] = 0;
			bmodif = 1;
		end
		--DBQS[nomquete][j][7] = nil;
		--DBQS[nomquete][j][8] = nil;
		if ( event == "QUEST_PROGRESS" ) then
			--	9
			progress = GetProgressText();
			if ( DBQS[nomquete][j][9] == nil or strlen(DBQS[nomquete][j][9]) < strlen(progress) ) then
				DBQS[nomquete][j][9] = progress;
				bmodif = 1;
			end
--TraceFrame:AddMessage("---progress : "..progress);
			--	10
			don = GetQuestMoneyToGet();
			if ( DBQS[nomquete][j][10] == nil or DBQS[nomquete][j][10] == 0 ) then
				if ( don > 0 ) then
					DBQS[nomquete][j][10] = don;
					bmodif = 1;
				end
			end
--TraceFrame:AddMessage("---don : "..don);
			--	14
			nbobjetsrecquis = GetNumQuestItems();
			if ( nbobjetsrecquis > 0 ) then
				if ( DBQS[nomquete][j][14] == nil ) then
					DBQS[nomquete][j][14] = {};
					bmodif = 1;
				end
			end
			for k = 1 , nbobjetsrecquis do	
				_, _, nbobjets, _, _ = GetQuestItemInfo("required", k);	--	"required" "reward" "choice" 
--TraceFrame:AddMessage("------ "..i.." "..name.." "..texture.." "..numItems.." "..quality);	--	.." "..isUsable);
				sitem = GetQuestItemLink("required", k);	--	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+)") do	-- %p?
						inumobjet = tonumber(a);
						--snumobjet2 = tonumber(b)..":"..tonumber(c)..":"..tonumber(d);
						if ( DBQS[nomquete][j][14][inumobjet] == nil ) then
							DBQS[nomquete][j][14][inumobjet] = nbobjets;
							bmodif = 1;
						end
					end
					--TraceFrame:AddMessage("--------- "..numItems.." "..DBobjets_GetItemLink(inumobjet,snumobjet2));
				else
					ibon = 0;
					-- faire quelque chose, relire la quete ?
				end
			end
--TraceFrame:AddMessage("---numRequiredItems : "..numRequiredItems);
		elseif ( event == "QUEST_COMPLETE" ) then
			--	11	12
			money = GetRewardMoney();
			if ( UnitLevel("Player") < DBCS_nivmax ) then
				if ( DBQS[nomquete][j][11] == nil or DBQS[nomquete][j][11] == 0 ) then
					if ( money > 0 ) then
						DBQS[nomquete][j][11] = money;
						bmodif = 1;
					end
				end
			else
				if ( DBQS[nomquete][j][12] == nil or DBQS[nomquete][j][12] == 0 ) then
					if ( money > 0 ) then
						DBQS[nomquete][j][12] = money;
						bmodif = 1;
					end
				end
			end
			--	15
			nbreward = GetNumQuestRewards();
			if ( nbreward > 0 ) then
--TraceFrame:AddMessage("---objets obtenus : "..numQuestRewards);
				if ( DBQS[nomquete][j][15] == nil ) then
					DBQS[nomquete][j][15] = {};
					bmodif = 1;
				end
				for k = 1 , nbreward do
					_, _, nbobjets, _, _ = GetQuestItemInfo("reward", k);	--	"required" "reward" "choice" 
					sitem = GetQuestItemLink("reward", k);	--	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+)") do	-- %p?
							inumobjet = tonumber(a);
							if ( DBQS[nomquete][j][15][inumobjet] == nil ) then
								DBQS[nomquete][j][15][inumobjet] = nbobjets;
								bmodif = 1;
							end
						end
					else
						ibon = 0;
					end
				end
			end
			--	16
			nbchoice = GetNumQuestChoices();
			if ( nbchoice > 0 ) then
--TraceFrame:AddMessage("---objets a choisir : "..numQuestChoices);
				if ( DBQS[nomquete][j][16] == nil ) then
					DBQS[nomquete][j][16] = {};
					bmodif = 1;
				end
				for k = 1 , nbchoice do
					_, _, nbobjets, _, _ = GetQuestItemInfo("choice", k);	--	"required" "reward" "choice" 
					sitem = GetQuestItemLink("choice", k);	--	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+)") do	--	%p?
							inumobjet = tonumber(a);
							if ( DBQS[nomquete][j][16][inumobjet] == nil ) then
								DBQS[nomquete][j][16][inumobjet] = nbobjets;
								bmodif = 1;
							end
						end
					else
						ibon = 0;
					end
				end
			end
			--	17
			reward = GetRewardText();
			if ( DBQS[nomquete][j][17] == nil or strlen(DBQS[nomquete][j][17]) < strlen(reward) ) then
				DBQS[nomquete][j][17] = reward;
				bmodif = 1;
			end
			nomqueteprec = nomquete;
--TraceFrame:AddMessage("nomqueteprec : "..nomqueteprec);
			objectifprec = objectif;
--TraceFrame:AddMessage("objectifprec : "..objectifprec);
		end

		if ( UnitFactionGroup("player")	== "Alliance" ) then
		--DBQS[nomquete][j][18] = 1;	--	alliance
			if ( DBQS[nomquete][j][18] == nil ) then
				DBQS[nomquete][j][18] = 1;	--	alliance
				bmodif = 1;
			end
		elseif ( UnitFactionGroup("player") == "Horde" ) then
		--DBQS[nomquete][j][19] = 1;	--	horde
			if ( DBQS[nomquete][j][19] == nil ) then
				DBQS[nomquete][j][19] = 1;	--	horde
				bmodif = 1;
			end
		end

		if ( DBQS[nomquete][j][26] == nil ) then
			DBQS[nomquete][j][26] = GetRealZoneText();	-- catégorie temporaire
			bmodif = 1;
		else
			if ( DBQS[nomquete][j][26] == GetRealZoneText() ) then
			else
				DBQS[nomquete][j][26] = GetRealZoneText();
				bmodif = 1;
			end
		end
		
		if ( bmodif == 0 ) then
			if ( DBQS[nomquete][j][13] == nil or DBQS[nomquete][j][13] == 0 ) then
				if ( DBQS[nomquete][j][8] == nil or DBQS[nomquete][j][8] < tonumber(DBCS_date()) ) then
					bmodif = 1;
					DBQS[nomquete][j][8] = tonumber(DBCS_date());
				end
			end
		else
			DBQS[nomquete][j][8] = tonumber(DBCS_date());
		end

		DBquetes_sauvegarderquete(nomquete,j);

		if ( ibon == 0 ) then
--TraceFrame:AddMessage("DBQS n'a pas pu lire certaines infos de la quete : "..nomquete..", veuillez la re-ouvrir.");
--message("DBQS n'a pas pu lire certaines infos de cette quete, veuillez la re-ouvrir.");
			--HideUIPanel(QuestFrame);
		else
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("DBQS a bien lu les infos de la quete : "..nomquete..".");
end
		end

		if ( bmodif == 1 and ibon == 1 ) then
			DBQS_event = nil;
			if ( DBCS_CMS_numcanalCMS > 0 ) then
				DBQS_envoyerquete(nomquete,j);
			end
		end
		
		DBQS_logdispo = 1;

	elseif ( event == "QUEST_FINISHED" ) then
DBQS_event = nil;
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end
	elseif ( event == "QUEST_GREETING" ) then
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end

		--numActiveQuests = GetNumActiveQuests();
--TraceFrame:AddMessage("---actives : "..numActiveQuests);
		--for i = 1, numActiveQuests do
--TraceFrame:AddMessage("---active "..i.." niv : "..GetActiveLevel(i).." nom : "..GetActiveTitle(i));
		--		local questTitleButton = getglobal("QuestTitleButton"..i);
		--		questTitleButton:SetText(GetActiveTitle(i));
		--		GetActiveLevel 
		--end
		--numAvailableQuests = GetNumAvailableQuests();
--TraceFrame:AddMessage("---availables : "..numAvailableQuests);
		--for i = 1 , numAvailableQuests do
--TraceFrame:AddMessage("---available "..i.." niv : "..GetAvailableLevel(i).." nom : "..GetAvailableTitle(i));
		--for i=(numActiveQuests + 1), (numActiveQuests + numAvailableQuests), 1 do
		--		local questTitleButton = getglobal("QuestTitleButton"..i);
		--		questTitleButton:SetText(GetAvailableTitle(i - numActiveQuests));
		--		GetAvailableLevel
		--end

	elseif ( event == "QUEST_ITEM_UPDATE" ) then
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end
		if ( DBQS_event ) then
			event = DBQS_event;
			arg9 = "QUEST_ITEM_UPDATE";
			DBquetes_OnEvent();
			arg9 = nil;
		end
	elseif ( event == "QUEST_LOG_UPDATE" ) then

local i;
local nb;

		if ( getglobal("DBcorpsFrame_QuetesFrame_Criteres_Encours"):GetChecked() ) then
			-- retenir la ligne de quete ou l on était
			offset = FauxScrollFrame_GetOffset(DBcorpsFrame_QuetesFrame_Liste_ScrollFrame);
			DBcorps_ListQuetes_Update();
			FauxScrollFrame_SetOffset(DBcorpsFrame_QuetesFrame_Liste_ScrollFrame,offset);
			DBcorps_Quetes_Scroll_Update();
			-- se remettre sur la ligne de quete ou on était
		end
		if ( DBQS_suivi_quetes_time > -1 ) then
			DBQS_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 ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end
--	elseif ( event == "QUEST_PROGRESS" ) then
--if ( DBCS_debug > 1 ) then
--DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
--end
	elseif ( event == "UNIT_QUEST_LOG_CHANGED" ) then
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end
	elseif ( event == "VARIABLES_LOADED" ) then
		if ( DBcorps_recupenreg_ON ) then
			DBCS_prog_serveur = 1;
			DBCS_debug = 2;
		end
		if ( DBCS_prog_serveur == 1 ) then
			self:RegisterEvent("CHAT_MSG_CHANNEL");
		end
		if ( DBQS_config.numversion == nil ) then
			DBQS_config.numversion = {};
		end
		numversion1 = (DBQS_config.numversion[1] or "00");
		numversion2 = (DBQS_config.numversion[2] or "00");
		numversion3 = (DBQS_config.numversion[3] or "00");
		if ( tonumber(numversion1..numversion2..numversion3) < tonumber(DBQS_NUMVERSION1..DBQS_NUMVERSION2..DBQS_NUMVERSION3) ) then
		end
		DBQS_config.numversion[1] = DBQS_NUMVERSION1;
		DBQS_config.numversion[2] = DBQS_NUMVERSION2;
		DBQS_config.numversion[3] = DBQS_NUMVERSION3;
		DBQS_logdispo = 1;
		if ( DBCS_prog_serveur == 0 ) then
			DBquetes_init_numquete_ds_historique();
		end
	end

end

function DBquetes_lirelog(questID)

local nomquete;
local nivquete;
local typequete;
local isHeader;
local isCollapsed;
local isComplete;
local i;
local j;
local k;
local nb;
local nomcateg;
local description;
local objectif;
local iniv;
local don;
local money;
local nbsousobjectifs;
local nomsousobj;
local typsousobj;
local ibon;
local bmodif;

	_, nivquete, typequete, _, isHeader, _, _, _ = GetQuestLogTitle(questID);
	--questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily = GetQuestLogTitle(questIndex);
	--questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete = GetQuestLogTitle(questID);
	if ( isHeader or questID == 0 ) then
		return nil;
	end
	i = 0;
	nb = questID;
	while ( i < nb ) do
		i = i + 1;
		nomquete, _, _, _, isHeader, _, _, _ = GetQuestLogTitle(i);
		--questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily = GetQuestLogTitle(questIndex);
		--questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete = GetQuestLogTitle(questID);
		iposdeb = strfind(nomquete,"%[");
		iposfin = strfind(nomquete,"%]");
		while ( iposdeb and iposfin ) do
			nomquete = strsub(nomquete,1,iposdeb-1)..strsub(nomquete,iposfin+1);
			iposdeb = strfind(nomquete,"%[");
			iposfin = strfind(nomquete,"%]");
		end
		iposdeb = 0;
		while ( iposdeb ) do
			if ( strsub(nomquete,1,1) == " " ) then
				nomquete = strsub(nomquete,2);
			else
				iposdeb = nil;
			end
		end
		if ( isHeader ) then
			nomcateg = nomquete;
		end
	end
	description , objectif = GetQuestLogQuestText();
	iniv = nivquete;
	objectif = DBQS_remplacerjoueurdanstexte(nomquete,0,objectif);

	bmodif = 0;
	ibon = 1;

--TraceFrame:AddMessage("nomquete : "..nomquete);
	if ( DBQS[nomquete] == nil ) then
		DBQS[nomquete] = {};
		DBQS[nomquete].nb = 0;
		bmodif = 1;
--TraceFrame:AddMessage("modif : 01");
	end
	j = 0;
	for i = 1 , DBQS[nomquete].nb do
		if ( DBQS[nomquete][i][1] == objectif ) then
			j = i;
		end
	end

	if ( j == 0 ) then
		j = DBQS[nomquete].nb + 1;
		DBQS[nomquete][j] = {};
		DBQS[nomquete].nb = j;
		bmodif = 1;
--TraceFrame:AddMessage("modif : 02");
	end

	--	1
	if ( DBQS[nomquete][j][1] == nil ) then
		DBQS[nomquete][j][1] = objectif;
		bmodif = 1;
--TraceFrame:AddMessage("modif : 03");
	end
	--	3
	if ( DBQS[nomquete][j][3] == nil ) then
		DBQS[nomquete][j][3] = iniv;
		bmodif = 1;
--TraceFrame:AddMessage("modif : 04");
	end
	--	2
	if ( DBQS[nomquete][j][2] == nil ) then
		DBQS[nomquete][j][2] = iniv;
		bmodif = 1;
--TraceFrame:AddMessage("modif : 05");
	end
	if ( DBQS[nomquete][j][2] > UnitLevel("Player") ) then
		DBQS[nomquete][j][2] = UnitLevel("Player");
		bmodif = 1;
--TraceFrame:AddMessage("modif : 06");
	end
	--	4
	if ( DBQS[nomquete][j][4] == nil ) then
		DBQS[nomquete][j][4] = description;
		bmodif = 1;
--TraceFrame:AddMessage("modif : 07");
	end
	--	10
	if ( DBQS[nomquete][j][10] == nil ) then
		don = GetQuestLogRequiredMoney();
		if ( don > 0 ) then
			DBQS[nomquete][j][10] = don;
			bmodif = 1;
--TraceFrame:AddMessage("modif : 08");
		end
	end
	--	11	12
	if ( UnitLevel("Player") < DBCS_nivmax ) then
		if ( DBQS[nomquete][j][11] == nil ) then
			money = GetQuestLogRewardMoney();
			if ( money > 0 ) then
				DBQS[nomquete][j][11] = money;
				bmodif = 1;
--TraceFrame:AddMessage("modif : 09");
			end
		end
	else
		if ( DBQS[nomquete][j][12] == nil ) then
			money = GetQuestLogRewardMoney();
			if ( money > 0 ) then
				DBQS[nomquete][j][12] = money;
				bmodif = 1;
--TraceFrame:AddMessage("modif : 10");
			end
		end
	end
	--	15
	--nbitemreward = GetNumQuestLogRewards();
	--local name, texture, numItems, quality, isUsable = GetQuestLogRewardInfo(requiredItem.type, i);
	--	16
	--nbitemchoix = GetNumQuestLogChoices();
	--local name, texture, numItems, quality, isUsable = GetQuestLogChoiceInfo(requiredItem.type, i);
	if ( UnitFactionGroup("player")	== "Alliance" ) then
	--DBQS[nomquete][j][18] = 1;	--	alliance
		if ( DBQS[nomquete][j][18] == nil ) then
			DBQS[nomquete][j][18] = 1;	--	alliance
			bmodif = 1;
		end
	elseif ( UnitFactionGroup("player") == "Horde" ) then
	--DBQS[nomquete][j][19] = 1;	--	horde
		if ( DBQS[nomquete][j][19] == nil ) then
			DBQS[nomquete][j][19] = 1;	--	horde
			bmodif = 1;
		end
	end

	--	20
	if ( DBQS[nomquete][j][20] == nil ) then
		DBQS[nomquete][j][20] = nomcateg;
		bmodif = 1;
--TraceFrame:AddMessage("modif : 11");
	else
		if ( DBQS[nomquete][j][20] == nomcateg or nomcateg == "" or nomcateg == DBQS_missingheader ) then
		else
			DBQS[nomquete][j][20] = nomcateg;
			bmodif = 1;
		end
	end
	--	21
	if ( DBQS[nomquete][j][21] == nil and typequete ) then
		DBQS[nomquete][j][21] = typequete;
		bmodif = 1;
--TraceFrame:AddMessage("modif : 12");
	end
	--	22	23
	nbsousobjectifs = GetNumQuestLeaderBoards();	--	GetNumQuestLogLeaderBoards();	--	[questID]
	if ( nbsousobjectifs > 0 ) then
		if ( DBQS[nomquete][j][22] == nil ) then
			DBQS[nomquete][j][22] = {};
			bmodif = 1;
--TraceFrame:AddMessage("modif : 13");
		end
		if ( DBQS[nomquete][j][23] == nil ) then
			DBQS[nomquete][j][23] = {};
			bmodif = 1;
--TraceFrame:AddMessage("modif : 14");
		end
	end
	for k = 1, nbsousobjectifs do
		nomsousobj, typsousobj, _ = GetQuestLogLeaderBoard(k);	--	, [questID]
		if ( nomsousobj ) then
			if ( DBQS[nomquete][j][22][k] == nil ) then
				DBQS[nomquete][j][22][k] = nomsousobj;
				bmodif = 1;
--TraceFrame:AddMessage("modif : 15");
			else
				if ( strlen(DBQS[nomquete][j][22][k]) < strlen(nomsousobj) ) then
					DBQS[nomquete][j][22][k] = nomsousobj;
					bmodif = 1;
--TraceFrame:AddMessage("modif : 16");
				end
			end
			if ( DBQS[nomquete][j][23][k] == nil ) then
				DBQS[nomquete][j][23][k] = typsousobj;
				bmodif = 1;
--TraceFrame:AddMessage("modif : 17");
			end
		else
			ibon = 0;
		end
	end
	-- pas de 26 à renseigner puisqu on lit le journal des quetes qui lui connait la vraie catégorie
	----	26
	--if ( DBQS[nomquete][j][26] == nil ) then
	--	DBQS[nomquete][j][26] = GetRealZoneText();	-- catégorie temporaire
	--	bmodif = 1;
	--else
	--	--if ( DBQS[nomquete][j][26] == GetRealZoneText() ) then
	--	--else
	--	--	DBQS[nomquete][j][26] = GetRealZoneText();	-- catégorie temporaire
	--	--	bmodif = 1;
	--	--end
	--end

	if ( bmodif == 0 ) then
		if ( DBQS[nomquete][j][13] == nil or DBQS[nomquete][j][13] == 0 ) then
--TraceFrame:AddMessage("nomquete : "..nomquete.." , j : "..j);
--TraceFrame:AddMessage("DBQS[nomquete][j][8] : "..(DBQS[nomquete][j][8] or "").." , tonumber(DBCS_date()) : "..tonumber(DBCS_date()));
			if ( DBQS[nomquete][j][8] == nil or DBQS[nomquete][j][8] < tonumber(DBCS_date()) ) then
				bmodif = 1;
--TraceFrame:AddMessage("modif : 18");
				DBQS[nomquete][j][8] = tonumber(DBCS_date());
			end
		end
	else
		DBQS[nomquete][j][8] = tonumber(DBCS_date());
	end

	DBquetes_sauvegarderquete(nomquete,j);
		
	if ( ibon == 0 ) then
TraceFrame:AddMessage("DBQS n'a pas pu lire certaines infos de la quete : "..nomquete..", veuillez la re-ouvrir.");
--message("DBQS n'a pas pu lire certaines infos de cette quete, veuillez la re-ouvrir.");
		--HideUIPanel(QuestFrame);
	end

	if ( ( 1 == 0 or bmodif == 1 ) and ibon == 1 ) then
		DBQS_event = nil;
		if ( DBCS_CMS_numcanalCMS > 0 ) then
			DBQS_envoyerquete(nomquete,j);
		end
	end

end

function DBquetes_liregossip()

	local tq_activelist;
	local tq_availablelist;
	local nb;
	local snompnj;
	local snumregion;
	local x,y;
	--local nom,level;

	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();
		DBPS_enregpnj(snompnj,snumregion,x,y,1);
	end
	
end

function DBquetes_Liste_ajout(tablo,nomquete,objectifquete)

local i,j;
local nbquete;
local numquete;
local tQUETE;
local nomdonneur;
local nomfinisseur;

	j = 0;
	for i = 1 , table.getn(tablo) do
		if ( j == 0 and tablo[i][1] == nomquete and tablo[i][2] == objectifquete ) then
			j = i;
		end
	end
	if ( j == 0 ) then
		if ( DBQS[nomquete] ) then
			nbquete = DBQS[nomquete].nb;
			numquete = 0;
			tQUETE = nil;
			while ( numquete < nbquete ) do
				numquete = numquete + 1;
				if ( DBQS[nomquete][numquete][1] == objectifquete ) then
					tQUETE = DBQS[nomquete][numquete];
				end
			end
			if ( tQUETE == nil ) then
			else
				i = table.getn(tablo);
				i = i + 1;
				tablo[i] = {};
				tablo[i][1] = nomquete;		-- nomquete
				tablo[i][2] = tQUETE[1];	-- objectif
				tablo[i][3] = tQUETE[2];	-- nivmin
				tablo[i][4] = tQUETE[3];	-- 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[5] ) then
					j = 0;
					for nomdonneur, _ in pairs(tQUETE[5]) do
						j = j + 1;
						if ( j == 1 ) then
							tablo[i][7] = nomdonneur;
						end
					end
				end
				if ( strlen(tablo[i][7]) == 0 ) then
					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[6] ) then
					j = 0;
					for nomfinisseur, _ in pairs(tQUETE[6]) do
						j = j + 1;
						if ( j == 1 ) then
							tablo[i][8] = nomfinisseur;
						end
					end
				end
				if ( strlen(tablo[i][8]) == 0 ) then
					if ( tQUETE[25] and tQUETE[25].nb and tQUETE[25].nb > 0 ) then
						tablo[i][8] = tQUETE[25][1][1];
					end
				end
				tablo[i][9] = tQUETE[7];	-- num quete
			end
		end
	end

	return tablo;

end

function DBquetes_Liste(criteres)

local tablo;
local tQUETE;
local nomquete;
local nbquete;
local numquete;
local bbon;
local i;
local j;
local ipos;
local smot;
local lg;

	tablo = {};
	i = 0;
	for nomquete, _ in pairs(DBQS) do
		bbon = 1;
		if ( bbon == 1 and criteres.nomquete and not ( criteres.nomquete == "" ) ) then
			ipos, _ = strfind(strlower(nomquete),strlower(criteres.nomquete));
			if ( not ipos ) then
				bbon = 0;
			end
		end
		if ( bbon == 1 ) then
			nbquete = DBQS[nomquete].nb;
			numquete = 0;
			while ( numquete < nbquete ) do
				numquete = numquete + 1;
				tQUETE = DBQS[nomquete][numquete];
				tQUETE[1] = DBQS_remplacerjoueurdanstexte(nomquete,numquete,tQUETE[1]);
				--tQUETE[4] = DBQS_remplacerjoueurdanstexte(nomquete,numquete,tQUETE[4]);
				--tQUETE[9] = DBQS_remplacerjoueurdanstexte(nomquete,numquete,tQUETE[9]);
				--tQUETE[17] = DBQS_remplacerjoueurdanstexte(nomquete,numquete,tQUETE[17]);
--TraceFrame:AddMessage("nomquete : "..nomquete);
				if ( tQUETE[24] ) then
					if ( type(tQUETE[24]) == "table" ) then
					else
						tQUETE[24] = nil;
					end
				end
				if ( tQUETE[24] and tQUETE[24].nb and tQUETE[24].nb > 0 ) then
					for j = 1, tQUETE[24].nb do
						tQUETE[24][j][2] = DBQS_remplacerjoueurdanstexte(nomquete,numquete,tQUETE[24][j][2]);
					end
				end
				if ( tQUETE[25] and tQUETE[25].nb and tQUETE[25].nb > 0 ) then
					for j = 1, tQUETE[25].nb do
						tQUETE[25][j][2] = DBQS_remplacerjoueurdanstexte(nomquete,numquete,tQUETE[25][j][2]);
					end
				end
				bbon = 1;
				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;
						end
					end
					--if ( tQUETE[2] == nil and tQUETE[3] == nil ) then
					--	bbon = 0;
					--else
					--	if ( ( not ( tQUETE[2] == nil ) ) and (tQUETE[3] or tQUETE[2]) and ( (tQUETE[3] or tQUETE[2]) < criteres.nivmin ) ) then
					--		bbon = 0;
					--	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;
						end
					end
					--if ( tQUETE[2] == nil and tQUETE[3] == nil ) then
					--	bbon = 0;
					--else
					--	if ( ( not ( tQUETE[2] == nil ) ) and (tQUETE[3] or tQUETE[2]) and ( (tQUETE[3]  or tQUETE[2])> criteres.nivmax ) ) then
					--		bbon = 0;
					--	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[5] ) then
						j = 0;
						for nomdonneur, _ in pairs(tQUETE[5]) do
							j = j + 1;
							if ( j == 1 ) 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[6] ) then
						j = 0;
						for nomfinisseur, _ in pairs(tQUETE[6]) do
							j = j + 1;
							if ( j == 1 ) 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 ( DBQS_tquetesencours[nomquete] ) 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 ) then
					i = i + 1 ;
					tablo[i] = {};
					tablo[i][1] = nomquete;		-- nomquete
					tablo[i][2] = tQUETE[1];	-- objectif
					tablo[i][3] = tQUETE[2];	-- nivmin
					tablo[i][4] = tQUETE[3];	-- 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[5] ) then
						j = 0;
						for nomdonneur, _ in pairs(tQUETE[5]) do
							j = j + 1;
							if ( j == 1 ) then
								tablo[i][7] = nomdonneur;
							end
						end
					end
					if ( strlen(tablo[i][7]) == 0 ) then
						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[6] ) then
						j = 0;
						for nomfinisseur, _ in pairs(tQUETE[6]) do
							j = j + 1;
							if ( j == 1 ) then
								tablo[i][8] = nomfinisseur;
							end
						end
					end
					if ( strlen(tablo[i][8]) == 0 ) then
						if ( tQUETE[25] and tQUETE[25].nb and tQUETE[25].nb > 0 ) then
							tablo[i][8] = tQUETE[25][1][1];
						end
					end
					tablo[i][9] = tQUETE[7];	-- num quete
				end
			end
		end
	end
	return tablo;

end

function DBquetes_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[9];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = quete2[9];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "nivmin") then
		val1 = quete1[3];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = quete2[3];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "nivconseil") then
		val1 = quete1[4];
		if ( val1 == nil ) then
			val1 = quete1[3];
		end
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = quete2[4];
		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
		val2 = quete2[7];
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "fin" ) then
		val1 = quete1[8];
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = quete2[8];
		if ( val2 == nil ) then
			val2 = "";
		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 DBquetes_Trier(quete1,quete2,t_ordre,niveaufonction+1);
		else
			return false;
		end
	else
		return false; -- pas normal d etre ici
	end

end

function DBQS_Detail(nomquete,objectif)

local tablo = nil;
local i;
local nb;
local bfin;

	if ( DBQS[nomquete] ) then
		nb = DBQS[nomquete].nb;
		bfin = 0;
		i = 0;
		while ( i < nb and bfin == 0 ) do
			i = i + 1;
			if ( DBQS[nomquete][i][1] == objectif ) then
				tablo = DBQS[nomquete][i];
				bfin = 1;
			end
		end
	end
	
	return tablo;

end

function DBQS_remplacerjoueurdanstexte(nomquete,numquete,stexte)

local snewtexte;
local ipos;
local smot;
local lg;
local bmodif;

	snewtexte = stexte;
	
	if ( stexte == nil ) then
		return nil;
	end

	bmodif = 0;
	ipos = 0;
	smot = UnitName("Player");
	lg = strlen(smot);
	while ( ipos ) do
		ipos = strfind(snewtexte,smot,1);
		if ( ipos ) then
			snewtexte = strsub(snewtexte,1,ipos-1).."[nomdujoueur]"..strsub(snewtexte,ipos+lg);
			bmodif = 1;
		end
	end
	--ipos = 0;
	--smot = UnitClass("Player");
	--lg = strlen(smot);
	--while ( ipos ) do
	--	ipos = strfind(snewtexte,smot,1);
	--	if ( ipos ) then
	--		snewtexte = strsub(snewtexte,1,ipos-1).."[classedujoueur]"..strsub(snewtexte,ipos+lg);
	--		bmodif = 1;
	--	end
	--end
	--ipos = 0;
	--smot = UnitRace("Player");
	--lg = strlen(smot);
	--while ( ipos ) do
	--	ipos = strfind(snewtexte,smot,1);
	--	if ( ipos ) then
	--		snewtexte = strsub(snewtexte,1,ipos-1).."[racedujoueur]"..strsub(snewtexte,ipos+lg);
	--		bmodif = 1;
	--	end
	--end
	
	--if ( bmodif == 1 ) then
--TraceFrame:AddMessage("quete modifiee : "..nomquete.." num : "..numquete);
	--end

	return snewtexte;

end

----/script DBCS_enumcarac();
--function DBCS_enumcarac()
--
--	for i = 1, 255 do
--		TraceFrame:AddMessage(i.." =@"..strchar(i).."@");
--	end
--
--end

function DBQS_envoyerquete(nomquete,numquete)

local tQUETE;
local tablo = {};
local inbenreg = 2;
local i;
local j;
local lg;
local sligne;
local inumobjet;
local inbobjetrecquis;
local inbobjetobtenus;
local inbobjetchoix;
local stexte;
local i_lgmax = 220; -- marche pas avec 150 pour la quete : "quand smokey chante : je deviens violent"
local smorco;
local sreste;
local stest;
local imoins;

	if ( DBCS_wow_2_4() == true ) then
		return nil;
	end

	if ( DBQS[nomquete] == nil or DBQS[nomquete][numquete] == nil ) then
		return nil;
	end
	tQUETE = DBQS[nomquete][numquete];
	tablo[1] = "1@"..nomquete.."@"..(tQUETE[20] or "").."@"..(tQUETE[21] or "").."@"..(tQUETE[26] or "").."@";
	-- objectif
	--sreste = DBQS_remplacersautdeligne((tQUETE[1] or ""));
	--lg = strlen(sreste);
--TraceFrame:AddMessage(sreste);
		--smorco = nil;
		--if ( i_lgmax > strlen(sreste) ) then
		--	smorco = strsub(sreste,1);
		--else
		--	smorco = strsub(sreste,1,i_lgmax);
		--	sreste = strsub(sreste,i_lgmax+1);
		--end
--TraceFrame:AddMessage(strconcat(smorco,"abcdefghij",strlen(smorco)));
--TraceFrame:AddMessage(sreste);
--		imoins = 0;
--TraceFrame:AddMessage(smorco);
--		itest = strbyte(smorco,-1);
--TraceFrame:AddMessage("dernier carac = "..itest);
--		while ( itest == 195 and strlen(smorco) > 1 ) do
--			smorco = strsub(smorco,1,strlen(smorco)-1);
--			imoins = imoins - 1;
--			itest = strbyte(smorco,-1);
--TraceFrame:AddMessage("dernier carac = "..itest);
--		end
--TraceFrame:AddMessage(imoins);
--TraceFrame:AddMessage(smorco);
--TraceFrame:AddMessage("dernier carac = "..itest);
		--tablo[inbenreg] = "3@"..smorco.."@";
--		itest = strbyte(tablo[inbenreg],-2);
--TraceFrame:AddMessage(tablo[inbenreg]);
--TraceFrame:AddMessage("dernier carac = "..itest);
	i = 0;
	stexte = DBQS_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] = "3@"..smorco.."@";
		i = i + i_lgmax - imoins;
	end
	-- description
	i = 0;
	stexte = DBQS_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] = "4@"..smorco.."@";
		i = i + i_lgmax - imoins;
	end
	-- progress
	i = 0;
	stexte = DBQS_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] = "5@"..smorco.."@";
		i = i + i_lgmax - imoins;
	end
	-- complete
	i = 0;
	stexte = DBQS_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] = "6@"..smorco.."@";
		i = i + i_lgmax - imoins;
	end
	---- sous-objectif
	--if ( tQUETE[22] and tQUETE[23] ) then
	--	for i = 1 , table.getn(tQUETE[22]) do
	--		inbenreg = inbenreg + 1;
	--		tablo[inbenreg] = "7@"..i.."@"..(tQUETE[22][i] or "").."@"..(tQUETE[23][i] or "").."@";
	--	end
	--end
	-- objets recquis
	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] = "8@"..sligne;
		end
	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] = "9@"..sligne;
		end
	end
	-- objets choix
	if ( tQUETE[16] ) then
		sligne = "";
		inbobjetchoix = 0;
		i = 0;
		for inumobjet, _ in pairs(tQUETE[16]) do
			i = i + 1;
			if ( i <= 20 ) then
				inbobjetchoix = inbobjetchoix + 1;
				sligne = sligne..inumobjet.."@"..tQUETE[16][inumobjet].."@";
			end
		end
		if ( sligne == "" ) then
		else
			inbenreg = inbenreg + 1;
			tablo[inbenreg] = "10@"..sligne;
		end
	end
	-- quetes prec
	if ( tQUETE[24] ) then
		for i = 1 , tQUETE[24].nb do
			inbenreg = inbenreg + 1;
			tablo[inbenreg] = "11@"..i.."@"..tQUETE[24][i][1].."@";
			j = 0;
			stexte = DBQS_remplacersautdeligne((tQUETE[24][i][2] or ""));
			lg = strlen(stexte);
			while ( j < lg ) do
				inbenreg = inbenreg + 1;
				smorco = strsub(stexte,j+1,j+i_lgmax);
				smorco,imoins = DBCS_verifderniercarac(smorco);
				tablo[inbenreg] = "11@"..i.."@"..smorco.."@";
				j = j + i_lgmax - imoins;
			end
			
		end
	end
	-- quetes suiv
	if ( tQUETE[25] ) then
		for i = 1 , tQUETE[25].nb do
			inbenreg = inbenreg + 1;
			tablo[inbenreg] = "12@"..i.."@"..tQUETE[25][i][1].."@";
			j = 0;
			stexte = DBQS_remplacersautdeligne((tQUETE[25][i][2] or ""));
			lg = strlen(stexte);
			while ( j < lg ) do
				inbenreg = inbenreg + 1;
				smorco = strsub(stexte,j+1,j+i_lgmax);
				smorco,imoins = DBCS_verifderniercarac(smorco);
				tablo[inbenreg] = "12@"..i.."@"..smorco.."@";
				j = j + i_lgmax - imoins;
			end
			
		end
	end
	-- donneurs
	if ( tQUETE[5] ) then
		for nomdonneur, _ in pairs(tQUETE[5]) do
			inbenreg = inbenreg + 1;
			tablo[inbenreg] = "13@"..nomdonneur.."@";
		end
	end
	-- finisseur
	if ( tQUETE[6] ) then
		for nomfinisseur, _ in pairs(tQUETE[6]) do
			inbenreg = inbenreg + 1;
			tablo[inbenreg] = "14@"..nomfinisseur.."@";
		end
	end
	-- enreg 0
	tablo[0] = ""..inbenreg.."@";
	-- enreg 2
	sligne = "2@";
	sligne = sligne..(tQUETE[2] or "").."@"..(tQUETE[3] or "").."@"..(tQUETE[7] or "").."@"..(tQUETE[8] or "").."@"..(tQUETE[10] or "").."@";
	sligne = sligne..(tQUETE[11] or "").."@"..(tQUETE[12] or "").."@"..(tQUETE[13] or "").."@";
	sligne = sligne..(inbobjetrecquis or 0).."@"..(inbobjetobtenus or 0).."@"..(inbobjetchoix or 0).."@";
	sligne = sligne..(tQUETE[18] or "").."@"..(tQUETE[19] or "").."@";
	tablo[2] = sligne;
	
	sdebut = "@ADBQS@"..DBCS_getlocale.."@QM01@"..floor(GetTime()*1000).."@";
	for i = 0 , inbenreg do
		--TraceFrame:AddMessage(sdebut..i.."@"..tablo[i]);
		--for j = 1 , strlen(tablo[i]) do
		--	TraceFrame:AddMessage(strbyte(tablo[i],j)..":"..strsub(tablo[i],j,1));
		--end
		DBCS_SendChatMessage(sdebut..i.."@"..tablo[i],"CHANNEL",this.language,DBCS_CMS_numcanalCMS);
	end

end

function DBQS_remplacersautdeligne(stexte)

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

end

function DBQS_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

function DBquetes_rechercheobjet(inumobjet)

local tablo;
local tQUETE;
local nomquete;
local i;
local j;
local k;
local bbon;
local nomdonneur;
local nomfinisseur;

	tablo = {};
	i = 0;
	for nomquete, _ in pairs(DBQS) do
		for k = 1 , DBQS[nomquete].nb do
			bbon = 0;
			tQUETE = DBQS[nomquete][k];
			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][1] = nomquete;		-- nomquete
				tablo[i][2] = tQUETE[1];	-- objectif
				tablo[i][3] = tQUETE[2];	-- nivmin
				tablo[i][4] = tQUETE[3];	-- 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[5] ) then
					j = 0;
					for nomdonneur, _ in pairs(tQUETE[5]) do
						j = j + 1;
						if ( j == 1 ) then
							tablo[i][7] = nomdonneur;
						end
					end
				end
				if ( strlen(tablo[i][7]) == 0 ) then
					if ( tQUETE[24] and tQUETE[24].nb > 0 ) then
						tablo[i][7] = tQUETE[24][1][1];
					end
				end
				tablo[i][8] = "";			-- fin
				if ( tQUETE[6] ) then
					j = 0;
					for nomfinisseur, _ in pairs(tQUETE[6]) do
						j = j + 1;
						if ( j == 1 ) then
							tablo[i][8] = nomfinisseur;
						end
					end
				end
				if ( strlen(tablo[i][8]) == 0 ) then
					if ( tQUETE[25] and tQUETE[25].nb > 0 ) then
						tablo[i][8] = tQUETE[25][1][1];
					end
				end
				tablo[i][9] = tQUETE[7];	-- num quete
			end
		end
	end

	return tablo;
				
end

function DBquetes_sauvegarderquete(nomquete,numenreg)

--TraceFrame:AddMessage("nom sauvegarde : "..nomquete..", num : "..numenreg);

local tablo;
--local slangue;

	--DBQC = {};
	if ( DBCS_prog_serveur == 1 ) then
		return nil;
	end
	
	tablo = DBQS[nomquete][numenreg];
	--slangue = GetLocale();
	if ( DBQC[DBCS_getlocale] == nil ) then
		DBQC[DBCS_getlocale] = {};
	end
	if ( DBQC[DBCS_getlocale][nomquete] == nil ) then
		DBQC[DBCS_getlocale][nomquete] = {};
		DBQC[DBCS_getlocale][nomquete].nb = 0;
	end
	i = 0;
	for j = 1 , DBQC[DBCS_getlocale][nomquete].nb do
		if ( DBQC[DBCS_getlocale][nomquete][j][1] == tablo[1] ) then
			i = j;
		end
	end
	if ( i == 0 ) then
		i = DBQC[DBCS_getlocale][nomquete].nb + 1;
		DBQC[DBCS_getlocale][nomquete][i] = {};
		DBQC[DBCS_getlocale][nomquete].nb = i;
	end
	DBQC[DBCS_getlocale][nomquete][i] = tablo;

end

--/script DBquetes_copiersauvegardedsDBQS();
function DBquetes_copiersauvegardedsDBQS()

local slangue;
local snomquete;
local i;
local inb;
local bbon;
local sobjectif;
local j;
local k;
local l;

	slangue = GetLocale();
	if ( DBQC and DBQC[slangue] ) then
		for snomquete, _ in pairs(DBQC[slangue]) do
			inb = DBQC[slangue][snomquete].nb;
			for i = inb , 1 , -1 do
				bbon = true;
				sobjectif = DBQC[slangue][snomquete][i][1];
				k = 0;
				if ( DBQS[snomquete] ) then
					for j = 1 , DBQS[snomquete].nb do
						if ( DBQS[snomquete][j][1] == sobjectif ) then
							k = j;
							bbon = false;
						end
					end
				end
				if ( bbon == true ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("nouvelle quete : "..snomquete);
TraceFrame:AddMessage("objectif : "..sobjectif);
end
					if ( DBQS[snomquete] ) then
					else
						DBQS[snomquete] = {};
						DBQS[snomquete].nb = 0;
					end
					DBQS[snomquete].nb = DBQS[snomquete].nb + 1;
					j = DBQS[snomquete].nb;
					DBQS[snomquete][j] = DBQC[slangue][snomquete][i];
					DBQC[slangue][snomquete][i] = nil;
					DBQC[slangue][snomquete].nb = DBQC[slangue][snomquete].nb - 1;
				else
--				[1]	=	objectif texte
					--l = 1;
					--DBQC[slangue][snomquete][i][l] = nil;
--				[2]	=	niv min
					l = 2;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[3]	=	niv conseil
					l = 3;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[4]	=	description texte
					l = 4;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[5]	=	{}	donneurs quete
--						[nomdonneur]	=	0
					l = 5;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[6]	=	{}	finisseurs quete
--						[nomfinisseur]	=	0
					l = 6;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[7]	=	numquete
					l = 7;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[8]	=	date envoi
--				[9]	=	progress texte
					l = 9;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[10]	=	salaire recquis
					l = 10;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[11]	=	salaire recompense < DBCS_nivmax ( 60 ) ( 70 )
					l = 11;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[12]	=	salaire recompense pour DBCS_nivmax ( 60 ) ( 70 )
					l = 12;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[13]	=	quete validée : ne plus l'envoyer tous les jours
--				[14]	=	{}	objets recquis
--						[12038] = 3
--						[505] =1
					l = 14;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[15]	=	{}	objets obtenus
--						[12038] = 3
--						[505] =1
					l = 15;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[16]	=	{}	objets à choisir
--						[12038] = 3
--						[505] =1
					l = 16;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[17]	=	complete texte
					l = 17;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[18]	=	1	=	alliance
					l = 18;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[19]	=	1	=	horde
					l = 19;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[20]	=	catégorie de la quete
					l = 20;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[21]	=	type de la quete ( tag )
					l = 21;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[22]	=	{}	texte du sous objectif
--						[1] = texte
--						[2] = texte
					l = 22;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[23]	=	{}	type du sous objectif
--						[1] = type
--						[2] = type
					l = 23;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[24]	=	{}	quetes précédentes
--						nb précédentes
--						[1]	=	{}
--								[1] = nomquete
--								[2] = objectif
					l = 24;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[25]	=	{}	quetes suivantes
--						nb suivantes
--						[1]	=	{}
--								[1] = nomquete
--								[2] = objectif
					l = 25;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
--				[26]	=	catégorie temporaire de la quete
					l = 26;
					if ( DBQS[snomquete][k][l] == nil ) then
						DBQS[snomquete][k][l] = DBQC[slangue][snomquete][i][l];
					end
					DBQC[slangue][snomquete][i][l] = nil;
					
					DBQC[slangue][snomquete][i] = nil;
					DBQC[slangue][snomquete].nb = DBQC[slangue][snomquete].nb - 1;
				end
			end
			--if ( DBQC[slangue][snomquete].nb == 0 ) then
			DBQC[slangue][snomquete] = nil;
			--end
		end
	end

--	DBQS = {}
--		[nomquete] = {}
--			nb = 0 -> n
--			[1]	= {}
--				[1]	=	objectif texte
end

--/script DBquetes_copiersauvegardedsDBPS();
function DBquetes_copiersauvegardedsDBPS()

local slangue;
local snompnj;
local snomregion;
local ideb;
local ipos;
local ipos2;
local sloc;

	slangue = GetLocale();
	if ( DBPC and DBPC[slangue] ) then
		for snompnj, _ in pairs(DBPC[slangue]) do
--			if ( DBPS[snompnj] == nil ) then
--				DBPS[snompnj] = {};
--			end
--			for snomregion, _ in pairs(DBPC[slangue][snompnj]) do
--				if ( DBPS[snompnj][snomregion] == nil ) then
--					--DBPS[snompnj][snomregion] = DBPC[slangue][snompnj][snomregion];
--					--DBPC[slangue][snompnj][snomregion] = nil;
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("ajout du pnj "..snompnj.." dans la region "..snomregion);
--end
--				end
--			end
			if ( DBPS2[snompnj] == nil ) then
				DBPS2[snompnj] = {};
			end
			for snomregion, _ in pairs(DBPC[slangue][snompnj]) do
				if ( DBPS2[snompnj][snomregion] == nil ) then
					DBPS2[snompnj][snomregion] = {};
					DBPS2[snompnj][snomregion]["xy"] = "@"..DBPC[slangue][snompnj][snomregion]["xy"];
					--DBPC[slangue][snompnj][snomregion] = nil;
				else
					ipos = 0;
					while ( ipos ) do
						ideb = ipos + 1;
						ipos = strfind(DBPC[slangue][snompnj][snomregion]["xy"],"@",ideb,true);
						if ( ipos ) then
							sloc = strsub(DBPC[slangue][snompnj][snomregion]["xy"],ideb,ipos);
							ipos2 = strfind(DBPS2[snompnj][snomregion]["xy"],"@"..sloc,1,true);
							if ( ipos2 ) then
							else
								DBPS2[snompnj][snomregion]["xy"] = DBPS2[snompnj][snomregion]["xy"]..sloc;
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("ajout d'une loc au pnj "..snompnj.." dans la region "..snomregion);
end
							end
						end
					end
				end
			end
			DBPC[slangue][snompnj] = nil;
		end
	end

end

--/script DBquetes_copiehistoriquedssauvegarde();
function DBquetes_copiehistoriquedssauvegarde()

local sserveur;
local sjoueur;
local snomquete;
local i;
local j;
local sobjectif;

	if ( DBHC ) then
		for sserveur, _ in pairs(DBHC) do
			for sjoueur, _ in pairs(DBHC[sserveur]) do
				if ( DBHC[sserveur][sjoueur][0] ) then
					for snomquete, _ in pairs(DBHC[sserveur][sjoueur][0]) do
						for i = 1 , table.getn(DBHC[sserveur][sjoueur][0][snomquete]) do
							sobjectif = DBHC[sserveur][sjoueur][0][snomquete][i];
							if ( DBQS[snomquete] ) then
								for j = 1 , DBQS[snomquete].nb do
									if ( DBQS[snomquete][j][1] == sobjectif ) then
										DBquetes_sauvegarderquete(snomquete,j);
--										break do;
									end
								end
							end
						end
					end
				end
			end
		end
	end


end

--/script DEFAULT_CHAT_FRAME:AddMessage(UnitClass("Player"));

function DBquetes_quetesencours()

local isav;
local nb;
--local nbquetes;
local i;
local nomquete_log;
local isHeader;
local isComplete;
--local description_log;
local objectif_log;
local j;
local bexist;

	DBQS_logdispo = 0;

	DBQS_tquetesencours = {};

	isav = GetQuestLogSelection();
	nb, _ = GetNumQuestLogEntries();	--	nbquetes
	for i = 1 , nb do
		nomquete_log, _, _, _, isHeader, _, isComplete, _ = GetQuestLogTitle(i);
		--questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily = GetQuestLogTitle(questIndex);
		--questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete = GetQuestLogTitle(questID);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("nomquete_log : "..nomquete_log);
--end
		if ( isHeader ) then
		else
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("i : "..i);
--end
			SelectQuestLogEntry(i);
			_ , objectif_log = GetQuestLogQuestText();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("objectif_log : "..objectif_log);
--end
			objectif_log = DBQS_remplacerjoueurdanstexte(nomquete_log,0,objectif_log);
			if ( DBQS_tquetesencours[nomquete_log] == nil ) then
				DBQS_tquetesencours[nomquete_log] = {};
			end
			nb = table.getn(DBQS_tquetesencours[nomquete_log]);
			bexist = 0;
			for j = 1 , nb do
				if ( DBQS_tquetesencours[nomquete_log][j][1] == objectif_log ) then
					bexist = 1;
				end
			end
			if ( bexist == 0 ) then
				DBQS_tquetesencours[nomquete_log][nb+1] = {};
				DBQS_tquetesencours[nomquete_log][nb+1][1] = objectif_log;
				DBQS_tquetesencours[nomquete_log][nb+1][2] = isComplete;
				DBQS_tquetesencours[nomquete_log][nb+1][3] = i;
				--table.insert(DBQS_tquetesencours[nomquete_log],objectif_log);
				--if ( DBQS[nomquete_log] ) then
				--else
				--	DBquetes_lirelog(i);
				--end
			end
		end
	end
	if ( isav > 0 ) then
		SelectQuestLogEntry(isav);
	end
	
	DBQS_logdispo = 1;

end

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

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

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

	return color;

end

function DBcorps_ListQuetes_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 = "quete : "..DBCORPS_QUETES_LISTE[index][1];
	tablo = DBQS_Detail(DBCORPS_QUETES_LISTE[index][1],DBCORPS_QUETES_LISTE[index][2]);
	if ( ipartie == 1 ) then
		stexte = DBCORPS_QUETES_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 ( DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]] ) then
			inumindex = 0;
			for i = 1 , table.getn(DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]]) do
				if ( DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][i][1] == stexte ) then
					bencours = 1;
					inumindex = DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][i][3];
				end
			end
			if ( bencours == 1 ) then
				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;
					end
				end
				--DBQS_logdispo = 0;
				--isav = GetQuestLogSelection();
				--nb, _ = GetNumQuestLogEntries();	--	nbquetes
				--i = 0;
				--bfin = 0;
				--while ( i < nb and bfin == 0 ) do
				--	i = i + 1;
				--	nomquete_log, _, _, isHeader, _, _ = GetQuestLogTitle(i);
				--	if ( isHeader ) then
				--	else
				--		if ( nomquete_log == DBCORPS_QUETES_LISTE[index][1] ) then
				--			SelectQuestLogEntry(i);
				--			_ , objectif_log = GetQuestLogQuestText();
				--			objectif_log = DBQS_remplacerjoueurdanstexte(nomquete_log,0,objectif_log);
				--			if ( objectif_log == stexte ) then
				--				bfin = 1;
				--				nbsousobjectifs = GetNumQuestLeaderBoards();	--	GetNumQuestLogLeaderBoards();	--	[questID]
				--				if ( nbsousobjectifs > 0 ) then
				--					smessage = smessage.."\n\nSous-Objectifs :\n";
				--					for j = 1, nbsousobjectifs do
				--						nomsousobj_log, typsousobj_log, _ = GetQuestLogLeaderBoard(j);	--	, [questID]
				--						smessage = smessage.."\n"..nomsousobj_log;
				--					end
				--				end
				--			end
				--		end
				--	end
				--end
				--if ( isav > 0 ) then
				--	SelectQuestLogEntry(isav);
				--end
				--DBQS_logdispo = 1;
			end
		end
		if ( bencours == 0 and tablo ) then
			if ( tablo[22] ) then
				smessage = smessage.."\n\nSous-Objectifs :\n";
				for i = 1,table.getn(tablo[22]) do
					smessage = smessage.."\n"..tablo[22][i];
				end
			end
		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);
	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 recquis : "..tablo[10].." pc.";
		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.." : "..tablo[11].." pc.";
		end
		if ( tablo[12] and tablo[12] > 0 ) then
			smessage = smessage.."\n\nsalaire pour les "..DBCS_nivmax.." : "..tablo[12].." pc.";
		end
	else
	end
	GameTooltip:AddLine(smessage);
	GameTooltip:Show();

end

function DBcorps_ListQuetes_Item_OnClick(index)

local i;
local j;
local k;
local activewindow;

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

	if ( IsShiftKeyDown() ) then
		if ( activewindow and activewindow:IsVisible() ) then
			activewindow:Insert("["..DBCORPS_QUETES_LISTE[index][4].."] "..DBCORPS_QUETES_LISTE[index][1].."]");
		else
			--AddQuestWatch(questIndex);
--TraceFrame:AddMessage("DBCORPS_QUETES_LISTE[index][1] : "..DBCORPS_QUETES_LISTE[index][1]);
			if ( DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]] ) then
				j = 0;
				for i = 1 , table.getn(DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]]) do
--TraceFrame:AddMessage("DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][i][1] : "..DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][i][1]);
--TraceFrame:AddMessage("DBCORPS_QUETES_LISTE[index][2] : "..DBCORPS_QUETES_LISTE[index][2]);
					if ( DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][i][1] == DBCORPS_QUETES_LISTE[index][2] ) then
						j = i;
					end
				end
				if ( j > 0 ) then
--TraceFrame:AddMessage("DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][j][3] : "..DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][j][3]);
					k = DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][j][3];
					--AddQuestWatch(k);
					--QuestWatch_Update();
					-- Shift-click toggles quest-watch on this quest.
					if ( IsQuestWatched(k) ) then
						RemoveQuestWatch(k);
						QuestWatch_Update();
						--DBcorps_Quetes_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);
						QuestWatch_Update();
						--DBcorps_Quetes_Scroll_Update();
					end
				end
			end
		end
	end

end

function DBcorps_ListQuetes_Item_Partage_OnEnter(self,index)

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

	j = 0;
	for i = 1 , table.getn(DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]]) do
		if ( DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][i][1] == DBCORPS_QUETES_LISTE[index][2] ) then
			j = i;
		end
	end
	if ( j > 0 ) then
		k = DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][j][3];
		inb_groupe = GetNumPartyMembers();
		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(GameTooltip,SHARE_QUEST, 1.0, 1.0, 1.0, NEWBIE_TOOLTIP_SHAREQUEST, 1);
	end

end

function DBcorps_ListQuetes_Item_Partage_OnClick(index)

local i;
local j;
local k;

	if ( DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]] ) then
		j = 0;
		for i = 1 , table.getn(DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]]) do
			if ( DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][i][1] == DBCORPS_QUETES_LISTE[index][2] ) then
				j = i;
			end
		end
		if ( j > 0 ) then
			k = DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][j][3];
			SelectQuestLogEntry(k);
			QuestLogPushQuest();
		end
	end

end

function DBcorps_ListQuetes_Item_Abandon_OnClick(index)

local i;
local j;
local k;
local items;

	if ( DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]] ) then
		j = 0;
		for i = 1 , table.getn(DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]]) do
			if ( DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][i][1] == DBCORPS_QUETES_LISTE[index][2] ) then
				j = i;
			end
		end
		if ( j > 0 ) then
			k = DBQS_tquetesencours[DBCORPS_QUETES_LISTE[index][1]][j][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

end

function DBcorps_ListQuetes_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;

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

	tablo = DBQS_Detail(DBCORPS_QUETES_LISTE[index][1],DBCORPS_QUETES_LISTE[index][2]);
	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
						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
						getglobal("DBcorpsFrame_MobsFrame_Criteres_Nommob"):SetText("^"..nommob.."$");
					else
						getglobal("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);
					end
				elseif ( IsControlKeyDown() ) then
					if ( GetItemInfo(link) ) then
						DressUpItemLink(DBobjets_GetItemLink(inumobjetdetail,"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";
					DBCORPS_OBJET_CRITERES.detail = DBOS_detail(inumobjetdetail,"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);
						getglobal("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_ListQuetes_Item_Debut_OnEnter(self,index)

local smessage;
local i;
local nb;
local tablo;
local sregion;
local sxy;
local ipos;

	tablo = DBQS_Detail(DBCORPS_QUETES_LISTE[index][1],DBCORPS_QUETES_LISTE[index][2]);
	if ( DBCORPS_QUETES_LISTE[index][7] and ( not ( DBCORPS_QUETES_LISTE[index][7] == "" ) ) ) then
		GameTooltip:SetOwner(self, "ANCHOR_LEFT");
		smessage = DBCORPS_QUETES_LISTE[index][7];
		if ( DBPS[DBCORPS_QUETES_LISTE[index][7]] ) then
			for a, _ in pairs(DBPS[DBCORPS_QUETES_LISTE[index][7]]) do
				sregion = a;
				smessage = smessage.."\na "..DB_nomregionbynum(sregion);
				sxy = DBPS[DBCORPS_QUETES_LISTE[index][7]][sregion].xy;
				ipos = strfind(sxy,"@",1);
				if ( ipos ) then
					sxy = strsub(sxy,1,ipos-1);
					smessage = smessage.." en "..sxy;
				end
			end
		end
		if ( tablo[24] and tablo[24].nb and tablo[24].nb > 0 ) then
			smessage = smessage.."\n\nQuete precedente : \n\n";
			smessage = smessage..tablo[24][1][1].."\n\n";
			smessage = smessage..DBCS_formattext(tablo[24][1][2],50);
		end
		GameTooltip:AddLine(smessage);
		GameTooltip:Show();
	end

end

function DBcorps_ListQuetes_Item_Debut_OnClick(index)

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

local tablo;
local nomquete;
local objectifquete;
local j;

	if ( IsControlKeyDown() ) then
		snomelement = DBCORPS_QUETES_LISTE[index][7];
		if ( snomelement and ( not ( snomelement == "" ) ) ) then
			if ( DBPS[snomelement] ) then
				sregion = nil;
				i = 0;
				for a, _ in pairs(DBPS[snomelement]) do
					i = i + 1;
					if ( i == 1 ) then
						sregion = a;
					end
				end
				if ( sregion ) then
					sxy = DBPS[snomelement][sregion].xy;
					DBcorps_Afficherworldmap_element(sregion,snomelement,sxy,"@","X");
				end
			end
		end
	else
		tablo = DBQS_Detail(DBCORPS_QUETES_LISTE[index][1],DBCORPS_QUETES_LISTE[index][2]);
		if ( DBCORPS_QUETES_LISTE[index][7] and ( not ( DBCORPS_QUETES_LISTE[index][7] == "" ) ) ) then
			if ( tablo[24] and tablo[24].nb and tablo[24].nb > 0 ) then
				nomquete = tablo[24][1][1];
				objectifquete = tablo[24][1][2];
				DBCORPS_QUETES_LISTE = DBquetes_Liste_ajout(DBCORPS_QUETES_LISTE,nomquete,objectifquete);
				j = 0;
				for i = 1 , table.getn(DBCORPS_QUETES_LISTE) do
					if ( j == 0 and DBCORPS_QUETES_LISTE[i][1] == nomquete and DBCORPS_QUETES_LISTE[i][2] == objectifquete ) then
						j = i;
					end
				end
				if ( j > 0 ) then
					DBCORPS_QUETES_LISTE_nb = table.getn(DBCORPS_QUETES_LISTE);
					getglobal("DBcorpsFrame_QuetesFrame_Criteres_Elements"):SetText(DBCORPS_QUETES_LISTE_nb.." \195\169l\195\169ments trouv\195\169s.")
					-- refresh
					DBcorps_ListQuetes_Trier();
					-- offset
					if ( DBCORPS_QUETES_LISTE_nb > 10 ) then
						j = 0;
						for i = 1 , table.getn(DBCORPS_QUETES_LISTE) do
							if ( j == 0 and DBCORPS_QUETES_LISTE[i][1] == nomquete and DBCORPS_QUETES_LISTE[i][2] == objectifquete ) then
								j = i;
							end
						end
						FauxScrollFrame_SetOffset(DBcorpsFrame_QuetesFrame_Liste_ScrollFrame,j-1);
					end
					--FauxScrollFrame_OnVerticalScroll(32, DBcorps_Quetes_Scroll_Update);
					DBcorps_Quetes_Scroll_Update();
				end
			end
		end
	end


end

function DBcorps_ListQuetes_Item_Fin_OnEnter(self,index)

local smessage;
local i;
local nb;
local tablo;
local sregion;
local sxy;
local ipos;

	tablo = DBQS_Detail(DBCORPS_QUETES_LISTE[index][1],DBCORPS_QUETES_LISTE[index][2]);
	if ( DBCORPS_QUETES_LISTE[index][8] and ( not ( DBCORPS_QUETES_LISTE[index][8] == "" ) ) ) then
			GameTooltip:SetOwner(self, "ANCHOR_LEFT");
			smessage = DBCORPS_QUETES_LISTE[index][8];
			if ( DBPS[DBCORPS_QUETES_LISTE[index][8]] ) then
				for a, _ in pairs(DBPS[DBCORPS_QUETES_LISTE[index][8]]) do
					sregion = a;
					smessage = smessage.."\na "..DB_nomregionbynum(sregion);
					sxy = DBPS[DBCORPS_QUETES_LISTE[index][8]][sregion].xy;
					ipos = strfind(sxy,"@",1);
					if ( ipos ) then
						sxy = strsub(sxy,1,ipos-1);
						smessage = smessage.." en "..sxy;
					end
				end
			end
			if ( tablo[25] and tablo[25] and tablo[25].nb > 0 ) then
				smessage = smessage.."\n\nQuete suivante : \n\n";
				smessage = smessage..tablo[25][1][1].."\n\n";
				smessage = smessage..DBCS_formattext(tablo[25][1][2],50);
			end
			GameTooltip:AddLine(smessage);
			GameTooltip:Show();
	end

end

function DBcorps_ListQuetes_Item_Fin_OnClick(index)

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

local tablo;
local nomquete;
local objectifquete;
local j;

	if ( IsControlKeyDown() ) then
		snomelement = DBCORPS_QUETES_LISTE[index][8];
		if ( snomelement and ( not ( snomelement == "" ) ) ) then
			if ( DBPS[snomelement] ) then
				sregion = nil;
				i = 0;
				for a, _ in pairs(DBPS[snomelement]) do
					i = i + 1;
					if ( i == 1 ) then
						sregion = a;
					end
				end
				if ( sregion ) then
					sxy = DBPS[snomelement][sregion].xy;
					DBcorps_Afficherworldmap_element(sregion,snomelement,sxy,"@","X");
				end
			end
		end
	else
		tablo = DBQS_Detail(DBCORPS_QUETES_LISTE[index][1],DBCORPS_QUETES_LISTE[index][2]);
		if ( DBCORPS_QUETES_LISTE[index][8] and ( not ( DBCORPS_QUETES_LISTE[index][8] == "" ) ) ) then
			if ( tablo[25] and tablo[25].nb and tablo[25].nb > 0 ) then
				nomquete = tablo[25][1][1];
				objectifquete = tablo[25][1][2];
				DBCORPS_QUETES_LISTE = DBquetes_Liste_ajout(DBCORPS_QUETES_LISTE,nomquete,objectifquete);
				j = 0;
				for i = 1 , table.getn(DBCORPS_QUETES_LISTE) do
					if ( j == 0 and DBCORPS_QUETES_LISTE[i][1] == nomquete and DBCORPS_QUETES_LISTE[i][2] == objectifquete ) then
						j = i;
					end
				end
				if ( j > 0 ) then
					DBCORPS_QUETES_LISTE_nb = table.getn(DBCORPS_QUETES_LISTE);
					getglobal("DBcorpsFrame_QuetesFrame_Criteres_Elements"):SetText(DBCORPS_QUETES_LISTE_nb.." \195\169l\195\169ments trouv\195\169s.")
					-- refresh
					DBcorps_ListQuetes_Trier();
					-- offset
					if ( DBCORPS_QUETES_LISTE_nb > 10 ) then
						j = 0;
						for i = 1 , table.getn(DBCORPS_QUETES_LISTE) do
							if ( j == 0 and DBCORPS_QUETES_LISTE[i][1] == nomquete and DBCORPS_QUETES_LISTE[i][2] == objectifquete ) then
								j = i;
							end
						end
						FauxScrollFrame_SetOffset(DBcorpsFrame_QuetesFrame_Liste_ScrollFrame,j-1);
					end
					--FauxScrollFrame_OnVerticalScroll(32, DBcorps_Quetes_Scroll_Update);
					DBcorps_Quetes_Scroll_Update();
				end
			end
		end
	end


end

function DBcorps_Quetes_Scroll_Update()

	local i,j;
	local offset = FauxScrollFrame_GetOffset(DBcorpsFrame_QuetesFrame_Liste_ScrollFrame);
	local button,buttonName;
	local itemChamp;
	local tablo;
	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 inumquete;

	isav = GetQuestLogSelection();

	FauxScrollFrame_Update(DBcorpsFrame_QuetesFrame_Liste_ScrollFrame, DBCORPS_QUETES_LISTE_nb, 10, 32);

	for i = 1 , 10 do
		j = offset + i;
		buttonName = "DBcorpsFrame_QuetesFrame_Liste_Button"..i;
		button = getglobal(buttonName);
		button:Hide();
		itemChamp = getglobal(buttonName.."_EditNumquete");
		if ( DBCS_prog_serveur == 1 ) then
			itemChamp:Show();
		else
			itemChamp:Hide();
		end
		itemChamp = getglobal(buttonName.."_EditCategorie");
		if ( DBCS_prog_serveur == 1 ) then
			itemChamp:Show();
		else
			itemChamp:Hide();
		end
		if ( j > DBCORPS_QUETES_LISTE_nb ) then
			button:Hide();
		else
			nomquete = DBCORPS_QUETES_LISTE[j][1];
			objectif = DBCORPS_QUETES_LISTE[j][2];
			tablo = DBQS_Detail(nomquete,objectif);
			inumquete = tablo[7];
			if ( inumquete and inumquete == 99999 ) then
				inumquete = nil;
			end
			nivmin = DBCORPS_QUETES_LISTE[j][3];
			nivconseil = DBCORPS_QUETES_LISTE[j][4];
			--categorie = DBCORPS_QUETES_LISTE[j][5];
			if ( tablo[20] ) then
				categorie = tablo[20];
			else
				if ( tablo[26] ) then
					categorie = "("..tablo[26]..")";
				else
					categorie = "";
				end
			end
			stype = DBCORPS_QUETES_LISTE[j][6];
			sdebut = DBCORPS_QUETES_LISTE[j][7];
			sfin = DBCORPS_QUETES_LISTE[j][8];
			itemChamp = getglobal(buttonName.."_Nomquete");
			itemChamp:SetText(nomquete);
			bencours = 0;
			if ( DBQS_tquetesencours[nomquete] ) then
				bencoursk = 0;
				for k = 1 , table.getn(DBQS_tquetesencours[nomquete]) do
					if ( DBQS_tquetesencours[nomquete][k][1] == objectif ) then
						bencours = 1;
						bencoursk = DBQS_tquetesencours[nomquete][k][3];
						bcomplete = DBQS_tquetesencours[nomquete][k][2];
					end
				end
			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 ) then
					if ( DBHC[DBHC_serveur] and DBHC[DBHC_serveur][DBHC_joueur] ) then
						if ( inumquete and DBHC[DBHC_serveur][DBHC_joueur][inumquete] ) then
							bhisto = 1;
						else
							if ( DBHC[DBHC_serveur][DBHC_joueur][0] and DBHC[DBHC_serveur][DBHC_joueur][0][nomquete] ) then
								for k = 1 , table.getn(DBHC[DBHC_serveur][DBHC_joueur][0][nomquete]) do
									if ( DBHC[DBHC_serveur][DBHC_joueur][0][nomquete][k] == objectif ) then
										bhisto = 1;
									end
								end
							end
						end
					end
				end
				if ( bhisto == 1 ) then
					itemChamp:SetTextColor(0.5,0.5,0.5);	-- gris
				else
					itemChamp:SetTextColor(0,1,0);		-- vert
				end
			end
			itemChamp = getglobal(buttonName.."_Nivmin");
			itemChamp:SetText(nivmin);
			if ( nivmin ) then
				if ( nivmin == 0 ) then
					itemChamp:SetText(nil);
				end
			end
			itemChamp = getglobal(buttonName.."_Nivconseil");
			itemChamp:SetText(nivconseil);
			if ( nivconseil ) then
				if ( nivconseil == 0 ) then
					itemChamp:SetText(nil);
				else
					color = DBQS_GetDifficultyColor(nivconseil);
					itemChamp:SetTextColor(color.r, color.g, color.b);
				end
			end
			itemChamp = getglobal(buttonName.."_Categorie");
			itemChamp:SetText(categorie);
			if ( bencours == 1 ) then
				if ( IsQuestWatched(bencoursk) ) then
					itemChamp:SetTextColor(0,0.5,1);		-- demi-bleu	-- suivie
				else
					itemChamp:SetTextColor(1,1,1);		-- blanc
				end
			else
				itemChamp:SetTextColor(1,1,1);		-- blanc
			end
			itemChamp = getglobal(buttonName.."_Type");
			itemChamp:SetText(stype);
			itemChamp = getglobal(buttonName.."_Debut");
			itemChamp:SetText(sdebut);
			itemChamp = getglobal(buttonName.."_Fin");
			itemChamp:SetText(sfin);
			itemChamp = getglobal(buttonName.."_Numquete");
			itemChamp:SetText(tablo[7]);
			getglobal(buttonName.."_Alliance"):Hide();
			if ( tablo[18] ) then
				getglobal(buttonName.."_Alliance"):Show();
			end
			getglobal(buttonName.."_Horde"):Hide();
			if ( tablo[19] ) then
				getglobal(buttonName.."_Horde"):Show();
			end
			getglobal(buttonName.."_Partage"):Hide();
			if ( bencours == 1 ) then
				SelectQuestLogEntry(bencoursk);
				if ( GetQuestLogPushable() and GetNumPartyMembers() > 0 ) then
					getglobal(buttonName.."_Partage"):Show();
				else
				end
				inbmembregroupe = GetNumPartyMembers();
				inbonquest = 0;
				for l = 1 , inbmembregroupe do
					if ( IsUnitOnQuest(bencoursk, "party"..l) ) then
						inbonquest = inbonquest + 1;
					end
				end
				if ( inbonquest > 0 ) then
					getglobal(buttonName.."_Partage"):SetText("p"..inbonquest);
				else
					getglobal(buttonName.."_Partage"):SetText("p");
				end
			end
			getglobal(buttonName.."_Abandon"):Hide();
			if ( bencours == 1 ) then
				getglobal(buttonName.."_Abandon"):Show();
			end
			getglobal(buttonName.."_ObjetRecquis1"):Hide();
			getglobal(buttonName.."_ObjetRecquis2"):Hide();
			getglobal(buttonName.."_ObjetRecquis3"):Hide();
			getglobal(buttonName.."_ObjetRecquis4"):Hide();
			getglobal(buttonName.."_ObjetRecquis5"):Hide();
			getglobal(buttonName.."_ObjetRecquis6"):Hide();
			getglobal(buttonName.."_ObjetRecquis7"):Hide();
			getglobal(buttonName.."_ObjetRecquis8"):Hide();
			getglobal(buttonName.."_ObjetRecquis9"):Hide();
			getglobal(buttonName.."_ObjetRecquis10"):Hide();
			getglobal(buttonName.."_MobRecquis1"):Hide();
			getglobal(buttonName.."_MobRecquis2"):Hide();
			getglobal(buttonName.."_MobRecquis3"):Hide();
			getglobal(buttonName.."_MobRecquis4"):Hide();
			getglobal(buttonName.."_MobRecquis5"):Hide();
			getglobal(buttonName.."_MobRecquis6"):Hide();
			getglobal(buttonName.."_MobRecquis7"):Hide();
			getglobal(buttonName.."_MobRecquis8"):Hide();
			getglobal(buttonName.."_MobRecquis9"):Hide();
			getglobal(buttonName.."_MobRecquis10"):Hide();
			getglobal(buttonName.."_ObjetObtenus1"):Hide();
			getglobal(buttonName.."_ObjetObtenus2"):Hide();
			getglobal(buttonName.."_ObjetObtenus3"):Hide();
			getglobal(buttonName.."_ObjetObtenus4"):Hide();
			getglobal(buttonName.."_ObjetObtenus5"):Hide();
			getglobal(buttonName.."_ObjetObtenus6"):Hide();
			getglobal(buttonName.."_ObjetObtenus7"):Hide();
			getglobal(buttonName.."_ObjetObtenus8"):Hide();
			getglobal(buttonName.."_ObjetObtenus9"):Hide();
			getglobal(buttonName.."_ObjetObtenus10"):Hide();
			getglobal(buttonName.."_ObjetChoix1"):Hide();
			getglobal(buttonName.."_ObjetChoix2"):Hide();
			getglobal(buttonName.."_ObjetChoix3"):Hide();
			getglobal(buttonName.."_ObjetChoix4"):Hide();
			getglobal(buttonName.."_ObjetChoix5"):Hide();
			getglobal(buttonName.."_ObjetChoix6"):Hide();
			getglobal(buttonName.."_ObjetChoix7"):Hide();
			getglobal(buttonName.."_ObjetChoix8"):Hide();
			getglobal(buttonName.."_ObjetChoix9"):Hide();
			getglobal(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");
						if ( tDETAILOBJET.nomobjet ) then
							getglobal(buttonName.."_ObjetRecquis"..j.."_IconTexture"):SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							getglobal(buttonName.."_ObjetRecquis"..j.."_IconTexture"):SetTexture(tDETAILOBJET.texture);
							getglobal(buttonName.."_ObjetRecquis"..j):Show();
						else
							getglobal(buttonName.."_ObjetRecquis"..j.."_IconTexture"):SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							getglobal(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;
						getglobal(buttonName.."_MobRecquis"..j.."_IconTexture"):SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
						getglobal(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");
						if ( tDETAILOBJET.nomobjet ) then
							getglobal(buttonName.."_ObjetObtenus"..j.."_IconTexture"):SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							getglobal(buttonName.."_ObjetObtenus"..j.."_IconTexture"):SetTexture(tDETAILOBJET.texture);
							getglobal(buttonName.."_ObjetObtenus"..j):Show();
						else
							--	"Interface\\Icons\\INV_Misc_QuestionMark"
							getglobal(buttonName.."_ObjetObtenus"..j.."_IconTexture"):SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							getglobal(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");
						if ( tDETAILOBJET.nomobjet ) then
							getglobal(buttonName.."_ObjetChoix"..j.."_IconTexture"):SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							getglobal(buttonName.."_ObjetChoix"..j.."_IconTexture"):SetTexture(tDETAILOBJET.texture);
							getglobal(buttonName.."_ObjetChoix"..j):Show();
						else
							getglobal(buttonName.."_ObjetChoix"..j.."_IconTexture"):SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
							getglobal(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_ListQuetes_Trier(sTRI,sINVERSER)

	--local t_ordre = {};
	local sSENS = DBCORPS_QUETES_LISTE_sens;
	local sARROW = "DBcorpsFrame_QuetesFrame_Tri_";

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

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

	table.sort(DBCORPS_QUETES_LISTE,DBcorps_ListQuetes_Trier_sort);

	DBcorps_Quetes_Scroll_Update();

end

function DBcorps_ListQuetes_Trier_sort(elem1,elem2)

	return DBquetes_Trier(elem1,elem2,DBCORPS_QUETES_TRI,1);

end

function DBcorps_ListQuetes_Reset()

	local item_base = "DBcorpsFrame_QuetesFrame_Criteres_";

	getglobal(item_base.."Nomquete"):SetText("");
	getglobal(item_base.."Nivmin"):SetText("");
	getglobal(item_base.."Nivmax"):SetText("");
	getglobal(item_base.."Categorie"):SetText("");
	getglobal(item_base.."Type"):SetText("");
	getglobal(item_base.."Debut"):SetText("");
	getglobal(item_base.."Fin"):SetText("");
	getglobal(item_base.."Encours"):SetChecked(1);

end

function DBcorps_ListQuetes_MAJ()

end

function DBcorps_ListQuetes_Update()

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

	DBquetes_quetesencours();

	criteres.nomquete = getglobal(item_base.."Nomquete"):GetText();
	criteres.nivmin = tonumber(getglobal(item_base.."Nivmin"):GetText());
	criteres.nivmax = tonumber(getglobal(item_base.."Nivmax"):GetText());
	criteres.categorie = getglobal(item_base.."Categorie"):GetText();
	criteres.type = getglobal(item_base.."Type"):GetText();
	criteres.debut = getglobal(item_base.."Debut"):GetText();
	criteres.fin = getglobal(item_base.."Fin"):GetText();
	criteres.encours = getglobal(item_base.."Encours"):GetChecked();
	if ( criteres.encours == nil ) then
		criteres.encours = 0;
	end
	--criteres.encours = 1;

	FauxScrollFrame_SetOffset(DBcorpsFrame_QuetesFrame_Liste_ScrollFrame,0);
	
	DBcorpsFrame_QuetesFrame_Liste_ScrollFrameScrollBar:SetValue(0);

	DBCORPS_QUETES_LISTE = DBquetes_Liste(criteres);
	DBCORPS_QUETES_LISTE_nb = table.getn(DBCORPS_QUETES_LISTE);
	if ( criteres.encours == 1 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_QUETES_LISTE_nb ) then
		else
			--TraceFrame:AddMessage("Certaines qu\195\170tes de votre journal ne sont pas connues par DBCS.\nVeuillez cliquer sur elles dans votre journal.");
		end
	end
	getglobal("DBcorpsFrame_QuetesFrame_Criteres_Elements"):SetText(DBCORPS_QUETES_LISTE_nb.." \195\169l\195\169ments trouv\195\169s.")
	DBcorps_ListQuetes_Trier();

end

function DBcorps_ListQuetes_ModifNumquete(self,index)

local snommob;
local snumregion;
local snum;
local ilen;

	snomquete = DBCORPS_QUETES_LISTE[index][1];
	sobjectif = DBCORPS_QUETES_LISTE[index][2];

	StaticPopupDialogs["DBCS_STATICPOPUPDIALOG_MODIFNUMQUETE"] = {
		text = "Indiquez le nouveau num\195\169ro de la qu\195\170te ["..snomquete.."] ?",
		button1 = TEXT(OKAY),
		button2 = TEXT(CANCEL),
		OnShow = function()
			snum = getglobal(self:GetName().."EditBox"):GetText();
			if ( snum ) then
				ilen = strlen(snum);
				getglobal(self:GetName().."EditBox"):HighlightText(0,ilen);
			end
		end,
		OnAccept = function()
			snum = getglobal(self:GetParent():GetName().."EditBox"):GetText();
			--getglobal(self:GetParent():GetName().."EditBox"):SetText("");
			if ( snum ) then
				inum = tonumber(snum);
				--if ( inum ) then
					if ( DBQS[snomquete] ) then
						for i = 1 , DBQS[snomquete].nb do
							if ( DBQS[snomquete][i][1] == sobjectif ) then
								DBQS[snomquete][i][7] = inum;
								DBcorps_Quetes_Scroll_Update();
							end
						end
					end
				--else
				--end
			else
				if ( DBQS[snomquete] ) then
					for i = 1 , DBQS[snomquete].nb do
						if ( DBQS[snomquete][i][1] == sobjectif ) then
							DBQS[snomquete][i][7] = nil;
							DBcorps_Quetes_Scroll_Update();
						end
					end
				end
			end
		end,
		hasEditBox = 1,
		timeout = 60,
		hideOnEscape = 1
	};
	StaticPopup_Show("DBCS_STATICPOPUPDIALOG_MODIFNUMQUETE");

end

function DBcorps_ListQuetes_ModifCategorie(self,index)

local snommob;
local snumregion;
local scategorie;
local ilen;

	snomquete = DBCORPS_QUETES_LISTE[index][1];
	sobjectif = DBCORPS_QUETES_LISTE[index][2];

	StaticPopupDialogs["DBCS_STATICPOPUPDIALOG_MODIFCATEGORIE"] = {
		text = "Indiquez la nouvelle cat\195\169gorie de la qu\195\170te ["..snomquete.."] ?",
		button1 = TEXT(OKAY),
		button2 = TEXT(CANCEL),
		OnShow = function()
			scategorie = getglobal(self:GetName().."EditBox"):GetText();
			if ( scategorie ) then
				ilen = strlen(scategorie);
				getglobal(self:GetName().."EditBox"):HighlightText(0,ilen);
			end
		end,
		OnAccept = function()
			scategorie = getglobal(self:GetParent():GetName().."EditBox"):GetText();
			if ( scategorie ) then
				if ( DBQS[snomquete] ) then
					for i = 1 , DBQS[snomquete].nb do
						if ( DBQS[snomquete][i][1] == sobjectif ) then
							DBQS[snomquete][i][20] = scategorie;
							DBcorps_Quetes_Scroll_Update();
						end
					end
				end
			else
				if ( DBQS[snomquete] ) then
					for i = 1 , DBQS[snomquete].nb do
						if ( DBQS[snomquete][i][1] == sobjectif ) then
							DBQS[snomquete][i][20] = nil;
							DBcorps_Quetes_Scroll_Update();
						end
					end
				end
			end
		end,
		hasEditBox = 1,
		timeout = 60,
		hideOnEscape = 1
	};
	StaticPopup_Show("DBCS_STATICPOPUPDIALOG_MODIFCATEGORIE");

end

function DBcorps_ListQuetes_InitCategorie(self,index)

local snommob;
local snumregion;
local scategorie;
local ilen;

	snomquete = DBCORPS_QUETES_LISTE[index][1];
	sobjectif = DBCORPS_QUETES_LISTE[index][2];

	StaticPopupDialogs["DBCS_STATICPOPUPDIALOG_MODIFCATEGORIE"] = {
		text = "Initialisation de la nouvelle cat\195\169gorie de la qu\195\170te ["..snomquete.."]",
		button1 = TEXT(OKAY),
		button2 = TEXT(CANCEL),
		OnShow = function()
			if ( DBQS[snomquete] ) then
				for i = 1 , DBQS[snomquete].nb do
					if ( DBQS[snomquete][i][1] == sobjectif ) then
						scategorie = DBQS[snomquete][i][20];
						if ( scategorie ) then
							getglobal(self:GetName().."EditBox"):SetText(scategorie);
						end
					end
				end
			end
			scategorie = getglobal(self:GetName().."EditBox"):GetText();
			if ( scategorie ) then
				ilen = strlen(scategorie);
				getglobal(self:GetName().."EditBox"):HighlightText(0,ilen);
			end
		end,
		hasEditBox = 1,
		timeout = 60,
		hideOnEscape = 1
	};
	StaticPopup_Show("DBCS_STATICPOPUPDIALOG_MODIFCATEGORIE");

end

--/script DBquetes_compter_nb_numquete();
function DBquetes_compter_nb_numquete()

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

	tablo = {};
	for snomquete, _ in pairs(DBQS) do
		for i = 1 , DBQS[snomquete].nb do
			inumquete = DBQS[snomquete][i][7];
			if ( inumquete ) then
				tablo[inumquete] = 0;
			end
		end
	end
	i = 0;
	for inumquete, _ in pairs(tablo) do
		i = i + 1;
	end
TraceFrame:AddMessage("nb quete : "..i);	--	3817

end

--/script DBquetes_nettoyer_categorie_temporaire();
function DBquetes_nettoyer_categorie_temporaire()

local tablo;
local snomquete;
local i;
local scategorie;

	tablo = {};
	for snomquete, _ in pairs(DBQS) do
		for i = 1 , DBQS[snomquete].nb do
			scategorie = DBQS[snomquete][i][20];
			if ( scategorie and strlen(scategorie) > 0 ) then
				DBQS[snomquete][i][26] = nil;
			end
		end
	end

end

--/script DBquetes_init_numquete_ds_historique();
function DBquetes_init_numquete_ds_historique()

local snomserveur;
local snomjoueur;
local snomquete;
local i;
local sobjectif;
local j;
local inumquete;
local bfait;
local k;
local l;

	for snomserveur, _ in pairs(DBHC) do
		for snomjoueur, _ in pairs(DBHC[snomserveur]) do
			if ( DBHC[snomserveur][snomjoueur][0] ) then
				for snomquete, _ in pairs(DBHC[snomserveur][snomjoueur][0]) do
					for i = table.getn(DBHC[snomserveur][snomjoueur][0][snomquete]) , 1 , -1 do
						sobjectif = DBHC[snomserveur][snomjoueur][0][snomquete][i];
						bfait = 0;
						if ( DBQS and DBQS[snomquete] ) then
							for j = 1 , DBQS[snomquete].nb do
								if ( bfait == 0 and DBQS[snomquete][j][1] and DBQS[snomquete][j][1] == sobjectif ) then
									bfait = 1;
									inumquete = DBQS[snomquete][j][7];
									if ( inumquete ) then
										if ( inumquete == 99999 ) then
										else
											if ( DBHC[snomserveur][snomjoueur][inumquete] ) then
											else
												DBHC[snomserveur][snomjoueur][inumquete] = 0;
											end
											table.remove(DBHC[snomserveur][snomjoueur][0][snomquete],i);
										end
									else
									end
								end
							end
						end
						if ( bfait == 0 ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("quete inconnue : "..snomquete);
end
							if ( DBQC[DBCS_getlocale] == nil ) then
								DBQC[DBCS_getlocale] = {};
							end
							if ( DBQC[DBCS_getlocale][snomquete] == nil ) then
								DBQC[DBCS_getlocale][snomquete] = {};
								DBQC[DBCS_getlocale][snomquete].nb = 0;
							end
							k = 0;
							for l = 1 , DBQC[DBCS_getlocale][snomquete].nb do
								if ( DBQC[DBCS_getlocale][snomquete][k] and DBQC[DBCS_getlocale][snomquete][k][1] and DBQC[DBCS_getlocale][snomquete][k][1] == sobjectif ) then
									k = l;
								end
							end
							if ( k == 0 ) then
								k = DBQC[DBCS_getlocale][snomquete].nb + 1;
								DBQC[DBCS_getlocale][snomquete][k] = {};
								DBQC[DBCS_getlocale][snomquete].nb = k;
							end
							DBQC[DBCS_getlocale][snomquete][k] = {};
							DBQC[DBCS_getlocale][snomquete][k][1] = sobjectif;
						end
					end
					if ( table.getn(DBHC[snomserveur][snomjoueur][0][snomquete]) == 0 ) then
						DBHC[snomserveur][snomjoueur][0][snomquete] = nil;
					end
				end
			end
		end
	end
	if ( DBCS_prog_serveur == 0 ) then
		DBQS = {};
		DBPS = {};
	end

end

--/script DBquetes_copier_quetes_ds_quetes2();
function DBquetes_copier_quetes_ds_quetes2()

local snomquete;
local i;
local j;
local inumquete;
local tablo;
local tablo2;
local inumobjet;
local snompnj;
local inumqueteprec;
local inumquetesuiv;

	for snomquete, _ in pairs(DBQS) do
		for i = 1 , DBQS[snomquete].nb do
			tablo = DBQS[snomquete][i];
			inumquete = tablo[7];
			if ( inumquete ) then
				if ( inumquete == 99999 ) then
				else
					if ( DBquetes2[inumquete] ) then
						tablo2 = DBquetes2[inumquete];
						if ( tablo2[2] == nil ) then
							if ( tablo[2] and tablo[2] > 0 ) then
								tablo2[2] = tablo[2];
							end
						else
							if ( tablo[2] and tablo[2] < tablo2[2] and tablo[2] > 0 ) then
								tablo2[2] = tablo[2];
							end
						end
						if ( tablo2[3] == nil ) then
							tablo2[3] = tablo[3];
						end
						if ( tablo2[2] and tablo2[3] ) then
							if ( tablo2[2] > tablo2[3] ) then
								tablo2[2] = tablo2[3];
							end
						end
						if ( tablo2[4] == nil ) then
							tablo2[4] = tablo[4];
						end
						if ( tablo[5] ) then
							if ( tablo2[5] == nil ) then
								tablo2[5] = {};
							end
							for snompnj, _ in pairs(tablo[5]) do
								if ( tablo2[5][snompnj] == nil ) then
									tablo2[5][snompnj] = tablo[5][snompnj];
								end
							end
						end
						if ( tablo[6] ) then
							if ( tablo2[6] == nil ) then
								tablo2[6] = {};
							end
							for snompnj, _ in pairs(tablo[6]) do
								if ( tablo2[6][snompnj] == nil ) then
									tablo2[6][snompnj] = tablo[6][snompnj];
								end
							end
						end
						if ( tablo2[9] == nil ) then
							tablo2[9] = tablo[9];
						end
						if ( tablo2[10] == nil ) then
							tablo2[10] = tablo[10];
						end
						if ( tablo2[11] == nil ) then
							tablo2[11] = tablo[11];
						end
						if ( tablo2[12] == nil ) then
							tablo2[12] = tablo[12];
						end
						if ( tablo[14] ) then
							if ( tablo2[14] == nil ) then
								tablo2[14] = {};
							end
							for inumobjet, _ in pairs(tablo[14]) do
								if ( tablo2[14][inumobjet] == nil ) then
									tablo2[14][inumobjet] = tablo[14][inumobjet];
								end
							end
						end
						if ( tablo[15] ) then
							if ( tablo2[15] == nil ) then
								tablo2[15] = {};
							end
							for inumobjet, _ in pairs(tablo[15]) do
								if ( tablo2[15][inumobjet] == nil ) then
									tablo2[15][inumobjet] = tablo[15][inumobjet];
								end
							end
						end
						if ( tablo[16] ) then
							if ( tablo2[16] == nil ) then
								tablo2[16] = {};
							end
							for inumobjet, _ in pairs(tablo[16]) do
								if ( tablo2[16][inumobjet] == nil ) then
									tablo2[16][inumobjet] = tablo[16][inumobjet];
								end
							end
						end
						if ( tablo2[17] == nil ) then
							tablo2[17] = tablo[17];
						end
						if ( tablo2[18] == nil ) then
							tablo2[18] = tablo[18];
						end
						if ( tablo2[19] == nil ) then
							tablo2[19] = tablo[19];
						end
						if ( tablo2[20] == nil ) then
							tablo2[20] = tablo[20];
						end
						if ( tablo2[21] == nil ) then
							tablo2[21] = tablo[21];
						end
						if ( tablo[22] ) then
							if ( tablo2[22] == nil ) then
								tablo2[22] = {};
							end
							for j = 1 , table.getn(tablo[22]) do
								if ( tablo2[22][j] == nil ) then
									tablo2[22][j] = tablo[22][j];
								end
							end
						end
						if ( tablo[23] ) then
							if ( tablo2[23] == nil ) then
								tablo2[23] = {};
							end
							for j = 1 , table.getn(tablo[23]) do
								if ( tablo2[23][j] == nil ) then
									tablo2[23][j] = tablo[23][j];
								end
							end
						end
--				[24]	=	{}	quetes précédentes
--						nb précédentes
--						[1]	=	{}
--								[1] = nomquete
--								[2] = objectif
						if ( tablo[24] ) then
							if ( tablo2[24] == nil ) then
								tablo2[24] = {};
							end
							if ( tablo[24].nb == nil ) then
TraceFrame:AddMessage("quete mauvaise 24 nb : "..snomquete);
							else
								for j = 1 , tablo[24].nb do
									if ( DBQS[tablo[24][j][1]] ) then
										for k = 1 , DBQS[tablo[24][j][1]].nb do
											if ( DBQS[tablo[24][j][1]][k][1] == tablo[24][j][2] ) then
												inumqueteprec = DBQS[tablo[24][j][1]][k][7];
												if ( inumqueteprec and inumqueteprec < 99999 ) then
													if ( tablo2[24][inumqueteprec] == nil ) then
														tablo2[24][inumqueteprec] = 0;
													end
													if ( DBquetes2[inumqueteprec] ) then
														if ( DBquetes2[inumqueteprec][25] == nil ) then
															DBquetes2[inumqueteprec][25] = {};
														end
														if ( DBquetes2[inumqueteprec][25][inumquete] == nil ) then
															DBquetes2[inumqueteprec][25][inumquete] = 0;
														end
													end
												end
											end
										end
									end
								end
							end
						end
						if ( tablo[25] ) then
							if ( tablo2[25] == nil ) then
								tablo2[25] = {};
							end
							if ( tablo[25].nb == nil ) then
TraceFrame:AddMessage("quete mauvaise 25 nb : "..snomquete);
							else
								for j = 1 , tablo[25].nb do
									if ( DBQS[tablo[25][j][1]] ) then
										for k = 1 , DBQS[tablo[25][j][1]].nb do
											if ( DBQS[tablo[25][j][1]][k][1] == tablo[25][j][2] ) then
												inumquetesuiv = DBQS[tablo[25][j][1]][k][7];
												if ( inumquetesuiv and inumquetesuiv < 99999 ) then
													if ( tablo2[25][inumquetesuiv] == nil ) then
														tablo2[25][inumquetesuiv] = 0;
													end
													if ( DBquetes2[inumquetesuiv] ) then
														if ( DBquetes2[inumquetesuiv][24] == nil ) then
															DBquetes2[inumquetesuiv][24] = {};
														end
														if ( DBquetes2[inumquetesuiv][24][inumquete] == nil ) then
															DBquetes2[inumquetesuiv][24][inumquete] = 0;
														end
													end
												end
											end
										end
									end
								end
							end
						end
						if ( tablo2[26] == nil ) then
							if ( tablo2[20] == nil ) then
								tablo2[26] = tablo[26];
							end
						else
							if ( tablo2[20] == nil ) then
							else
								tablo2[26] = "#";
							end
						end
						DBquetes2[inumquete] = tablo2;
					end
				end
			end
		end
	end

end

--/script DBquetes_copier_DBPS_ds_DBPS2();
function DBquetes_copier_DBPS_ds_DBPS2()

local snompnj;
local snumregion;

--		DBPS2[snompnj][snumregion].xy = "@";

	for snompnj, _ in pairs(DBPS) do
		if ( DBPS2[snompnj] == nil ) then
			DBPS2[snompnj] = {};
		end
		for snumregion, _ in pairs(DBPS[snompnj]) do
			if ( DBPS2[snompnj][snumregion] == nil ) then
				DBPS2[snompnj][snumregion] = {};
			end
			DBPS2[snompnj][snumregion].xy = "@"..DBPS[snompnj][snumregion].xy;
		end
	end

end
