local TraceFrame = DEFAULT_CHAT_FRAME;

DBCS_HDV_exist = true;

--/script DBcorps_ListHDV_Scan_debut();
--/script DBCS_HDV_toutlire();

--/script CreateFrame("Button","AuctionFrameTab4",AuctionFrame,AuctionTabTemplate)

--	DBCS_HDV
--		inumrech			=	1 à 2 000 000 000
--			inumsession		=	1 à 2 000 000 000
--			inumordre		=	1 à 15 000+
--				inumobjet	=	1 à 36 000+
--				snumlong	=	"36000:0:0:0:0:0:0:124365"

--    CalculateAuctionDeposit(runTime)   - Returns the required deposit for the current selling item given the specified duration (minutes). 
--    CanSendAuctionQuery()   - Return 1 if auction search button would be active, nil otherwise. 
--    CancelAuction(index)   - Cancel the specified auction (on the "owner" list). 
--    ClickAuctionSellItemButton()   - Puts the currently 'picked up' item into the 'create auction' slot. 
--    CloseAuctionHouse()   - Will close the AuctionFrame if opened. 
--    GetAuctionHouseDepositRate()   - Returns the deposit rate (percentage) for the currently open auction house (Possibly out-dated by CalculateAuctionDeposit). 
--    GetAuctionInvTypes(classIndex, subclassIndex)   - Returns types of subcategories items. 
--    GetAuctionItemClasses()   - Returns major auction item categories. 
--    GetAuctionItemInfo("type", index)   - Returns details about the specified auction item. 
--    GetAuctionItemLink("type", index)   - Returns an itemLink for the specified auction item. 
--    GetAuctionItemSubClasses(classIndex)   - Returns subcategories in the nth auction category. 
--    GetAuctionItemTimeLeft("type", index)   - Returns the time left status of the specified auction item. 
--    GetAuctionSellItemInfo()   - Returns information about the current selling item (or nil if none selected). 
--    GetBidderAuctionItems([page])   - ?. 
--    GetNumAuctionItems("type")   - Returns the size of the specified auction item list. 
--    GetOwnerAuctionItems([page])   - ?. 
--    GetSelectedAuctionItem("type")   - Returns the index (1-50) of the selected auction item or 0 if none is selected. 
--    IsAuctionSortReversed("type", "sort")   - Returns 1 if the specified auction list and sort is reversed, nil otherwise. 
--    PlaceAuctionBid("type", index, bid)   - Place a bid on the selected auction item. 
--    QueryAuctionItems("name", minLevel, maxLevel, invTypeIndex, classIndex, subclassIndex, page, isUsable, qualityIndex)   - ?. 
--    SetSelectedAuctionItem("type", index)   - ?. 
--    SortAuctionItems("type", "sort")   - Request that the specified auction list be sorted by a specific column. 
--    StartAuction(minBid, buyoutPrice, runTime)   - Starts the auction you have created in the Create Auction panel. 
--    UI AuctionFrameAuctions.duration - Set the amount of time the auction will run for in minutes.

--QueryAuctionItems("name"		, "minLevel"	, "maxLevel", invTypeIndex	, classIndex, subclassIndex	, page	, isUsable	, qualityIndex	, getAll		)

--"AUCTION_HOUSE_SHOW"
--"AUCTION_HOUSE_CLOSED"

--"AUCTION_ITEM_LIST_UPDATE"
--	This event is fired when the Auction list is updated. Note that this is not only the case, if the list is completely changed but also if it is sorted (i.e. SortAuctionItems() is called).
--"AUCTION_BIDDER_LIST_UPDATE"
--"AUCTION_OWNED_LIST_UPDATE"

--"NEW_AUCTION_UPDATE"

DBCS_HDV_b_scan_continuel = true;
--/script DBCS_HDV_b_scan_continuel = true;
--/script DBCS_HDV_b_scan_continuel = false;
local DBCS_HDV_btoutlire = false;
local DBCS_HDV_inumrech = 0;
local DBCS_HDV_bnumrech = false;
local DBCS_HDV_inumordre = 0;

local DBCS_HDV_etape = 0;

--	DBCS_serveur
DBCS_HDV_faction = -1;
--	0 = hdv double
--	1 = alliance
--	2 = horde

local DBCS_HDV_time_30min = 30*60;
local DBCS_HDV_time_2heures = 2*60*60;
local DBCS_HDV_time_12heures = 12*60*60;
local DBCS_HDV_time_48heures = 48*60*60;

local DBCS_HDV_time_debut = 0;

local DBCS_HDV_AUCTION_ITEM_LIST_UPDATE_time = 0;

local DBCS_HDV_tQueryAuctionItems = {};
local DBCS_HDV_tQueryAuctionItems_name = "";
local DBCS_HDV_tQueryAuctionItems_minLevel = "";
local DBCS_HDV_tQueryAuctionItems_maxLevel = "";
local DBCS_HDV_tQueryAuctionItems_invTypeIndex = nil;
local DBCS_HDV_tQueryAuctionItems_classIndex = nil;
local DBCS_HDV_tQueryAuctionItems_subclassIndex = nil;
local DBCS_HDV_tQueryAuctionItems_page = 0;
local DBCS_HDV_tQueryAuctionItems_isUsable = nil;
local DBCS_HDV_tQueryAuctionItems_qualityIndex = nil;
local DBCS_HDV_tQueryAuctionItems_getAll = nil;
local DBCS_HDV_tQueryAuctionItems_OnUpdate = false;
local DBCS_HDV_tQueryAuctionItems_OnUpdate_inb = 0;
local DBCS_HDV_tQueryAuctionItems_OnUpdate_imax = 0;
local DBCS_HDV_tQueryAuctionItems_OnUpdate_timedebut = 0;
local DBCS_HDV_tQueryAuctionItems_OnUpdate_timefin = DBCS_HDV_time_48heures;
local DBCS_HDV_tQueryAuctionItems_OnUpdate_uniquedernier = nil;
local DBCS_HDV_tQueryAuctionItems_OnUpdate_buniquedernier = false;
local DBCS_HDV_tQueryAuctionItems_OnUpdate_uniquedernier_time = nil;

local DBCS_HDV_tQueryAuctionItems_unique = {};

local DBCS_HDV_tobjets_stats = {};

local Saved_DBCS_HDV_QueryAuctionItems_a;
local Saved_DBCS_HDV_QueryAuctionItems_b;
local Saved_DBCS_HDV_QueryAuctionItems_c;
local Saved_DBCS_HDV_QueryAuctionItems_d;
local Saved_DBCS_HDV_QueryAuctionItems_e;
local Saved_DBCS_HDV_QueryAuctionItems_f;
local Saved_DBCS_HDV_QueryAuctionItems_g;
local Saved_DBCS_HDV_QueryAuctionItems_h;
local Saved_DBCS_HDV_QueryAuctionItems_i;
local Saved_DBCS_HDV_QueryAuctionItems_j;

local DBCS_HDV_bappel = false;

DBCORPS_HDV_LISTE = {};
DBCORPS_HDV_LISTE_nb = 0;
DBCORPS_HDV_LISTE_ordre = "prixachat";
DBCORPS_HDV_LISTE_sens = "ASC";
DBCORPS_HDV_TRI = nil;
DBCORPS_HDV_CRITERES = {};
DBCORPS_HDV_CRITERES_numobjet = nil;
DBCORPS_HDV_LISTE_OnUpdate_time = 0;

Saved_DBCS_HDV_QueryAuctionItems = QueryAuctionItems;
function QueryAuctionItems(a,b,c,d,e,f,g,h,i,j)

	--DBCS_HDV_bnumrech = false;
	--DBCS_HDV_bappel = false;
	--DBCS_HDV_tQueryAuctionItems_OnUpdate = false;
	--DBCS_HDV_AUCTION_ITEM_LIST_UPDATE_time = 0;
	Saved_DBCS_HDV_QueryAuctionItems(a,b,c,d,e,f,g,h,i,j);

end

--CloseAuctionHouse
Saved_DBCS_HDV_CloseAuctionHouse = CloseAuctionHouse;
function CloseAuctionHouse()

	DBcorps_ListHDV_Scan_fin();
	--DBcorpsFrame_HDVFrame_Criteres_SCAN:Hide();
	Saved_DBCS_HDV_CloseAuctionHouse();

end

--Saved_DBCS_HDV_AuctionFrame_OnShow = AuctionFrame_OnShow;
--function AuctionFrame_OnShow()
--
--	--DBcorpsFrame_HDVFrame_Criteres_SCAN:Show();
--	Saved_DBCS_HDV_AuctionFrame_OnShow();
--
--end

--local Saved_DBCS_HDV_AuctionFrame_OnShow = AuctionFrame:GetScript("OnShow");
--function DBCS_HDV_AuctionFrame_OnShow()
--
--	DBcorpsFrame_HDVFrame_Criteres_SCAN:Show();
--	Saved_DBCS_HDV_AuctionFrame_OnShow();
--
--end
--AuctionFrame:SetScript("OnShow",DBCS_HDV_AuctionFrame_OnShow);

function DBCS_HDV_OnLoad(self)

	self:RegisterEvent("AUCTION_HOUSE_SHOW");
	self:RegisterEvent("AUCTION_HOUSE_CLOSED");
	self:RegisterEvent("AUCTION_ITEM_LIST_UPDATE");
	self:RegisterEvent("AUCTION_BIDDER_LIST_UPDATE");
	self:RegisterEvent("AUCTION_OWNED_LIST_UPDATE");
	self:RegisterEvent("NEW_AUCTION_UPDATE");
	self:RegisterEvent("VARIABLES_LOADED");

	DBCS_HDV = {};

	DBcorpsFrame_HDVFrame_Criteres_Bar:SetMinMaxValues(0,100);
	DBcorpsFrame_HDV_stats_Frame_Criteres_Bar:SetMinMaxValues(0,100);
	DBcorps_ListHDV_Scan_fin();
	--DBcorpsFrame_HDVFrame_Criteres_SCAN:Hide();

end

function DBCS_HDV_OnEvent(self,event,...)

local i,j;
local name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner, sold, inumobjet, btruc;
local timeleft;
local itemlink;
local inb, imax;
local itime;
local sunique;
local sb,sc,sd,se,sf,sg,sh,si,sj,sk,sl;
local sfaction;

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

	if ( event == "" ) then
	elseif ( event == "AUCTION_HOUSE_SHOW" ) then
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end
	elseif ( event == "AUCTION_HOUSE_CLOSED" ) then
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end
	elseif ( event == "AUCTION_ITEM_LIST_UPDATE" ) then
--if ( DBCS_debug > 1 ) then
--DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
--end
		if ( DBCS_HDV_etape == 5 ) then
			DBCS_HDV_tQueryAuctionItems_OnUpdate_inb = 0;
			DBCS_HDV_tQueryAuctionItems_OnUpdate_imax = 0;
			if ( DBCS_HDV_bappel == true ) then
				inb, imax = GetNumAuctionItems("list");
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("inb = "..inb..", imax = "..imax);
--end
				DBCS_HDV_tQueryAuctionItems_OnUpdate_inb = inb;
				DBCS_HDV_tQueryAuctionItems_OnUpdate_imax = imax;
				--DBCS_HDV_tQueryAuctionItems_OnUpdate_imax = 500;
				--for i = 1 , 50 do
				--	--DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i] = nil;
				--	DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i] = {};
				--end
				for i = 1 , inb do
--					name, texture, count, quality, canUse, level, levelColHeader, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner, saleStatus, itemId, hasAllInfo =  GetAuctionItemInfo("list", offset + i);
					name, texture, count, quality, canUse, level, _, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner, sold, inumobjet, btruc  = GetAuctionItemInfo("list", i);
--if ( DBCS_debug > 1 ) then
	--if ( type(inumobjet) == "number" ) then
	--else
--TraceFrame:AddMessage("name = "..name..", texture = "..(texture or "")..", DBCS_HDV_inumordre = "..(DBCS_HDV_inumordre+i));
	--end
--end
					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i] = {};
					if ( name ) then
						timeleft = GetAuctionItemTimeLeft("list", i);
						if ( timeleft == nil ) then
							timeleft = 1;
						end
						itemlink = GetAuctionItemLink("list", i);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("inumobjet = "..(inumobjet or "")..", itemlink : "..(itemlink or "")..", DBCS_HDV_inumordre = "..(DBCS_HDV_inumordre+i));
--end
						itime = GetTime();
						--DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i] = {};
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][1] = name;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][2] = texture;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][3] = count;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][4] = quality;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][5] = canUse;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][6] = level;
						--if ( type(minBid) == "string" ) then
						--	DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][7] = 0;
						--else
							DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][7] = minBid;
						--end
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][8] = minIncrement;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][9] = buyoutPrice;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][10] = bidAmount;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][11] = highBidder;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][12] = owner;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][13] = timeleft;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][14] = itemlink;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][15] = itime;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][19] = inumobjet;	--nil;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][20] = nil;
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][21] = nil;
						--DBCS_message_item = "(.+)%|%Hitem:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)%|%h%[(.+)%]%|%h%|%r$";
						if ( itemlink ) then
							for _,sb,sc,sd,se,sf,sg,sh,si,sj,sk,sl in string.gmatch(itemlink,DBCS_message_item) do
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("sb : "..sb);
--end
								--DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][19] = tonumber(sb);
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][20] = ""..sc..":"..sd..":"..se..":"..sf..":"..sg..":"..sh..":"..si..":"..sj..":"..sk..":"..sl;
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][21] = "i";
							end
							--battlepet:157:1:2:151:10:10:0
							if ( inumobjet == 82800 ) then
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][21] = "b";
							end
							if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][21] == nil ) then
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][21] = "b";
							end
						else
							DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][21] = "b";
						end
						--if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][19] == nil ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("itemlink vide pour enreg : "..(DBCS_HDV_inumordre+i));
--end
						--end
					else
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("itemlink vide pour enreg : "..(DBCS_HDV_inumordre+i));
end
						--if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i] == nil ) then
							--DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i] = {};
						--end
					end
				end
				--DBCS_HDV_inumordre = DBCS_HDV_inumordre + 50;	--	inb;
				DBCS_HDV_bnumrech = false;
				--j = 0;
				--for i = 1 , inb do
				--	if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i] == nil or DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][12] == nil ) then
				--		j = j + 1;
				--	end
				--end
				--if ( j > 0 ) then
				--	DBCS_HDV_AUCTION_ITEM_LIST_UPDATE_time = GetTime();
				--	--DBCS_HDV_tQueryAuctionItems_OnUpdate_inb = inb;
				--	--DBCS_HDV_tQueryAuctionItems_OnUpdate_imax = imax;
				--else
					--DBCS_HDV_verif_compare_enreg();
					DBCS_HDV_AUCTION_ITEM_LIST_UPDATE_time = 0;
					--if ( inb == imax ) then
					--else
						--itime = GetTime();
						DBCS_HDV_tQueryAuctionItems_OnUpdate = true;
						--DBCS_HDV_tQueryAuctionItems_OnUpdate_inb = inb;
						--DBCS_HDV_tQueryAuctionItems_OnUpdate_imax = imax;
					--end
				--end
			end
		end
	elseif ( event == "AUCTION_BIDDER_LIST_UPDATE" ) then
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end
	elseif ( event == "AUCTION_OWNED_LIST_UPDATE" ) then
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end
	elseif ( event == "NEW_AUCTION_UPDATE" ) then
if ( DBCS_debug > 1 ) then
DBCS_afficherevent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
end
	elseif ( event == "VARIABLES_LOADED" ) then
		sfaction, _ = UnitFactionGroup("player");
		if ( sfaction == "Alliance" ) then
			DBCS_HDV_faction = 1;
		elseif ( sfaction == "Horde" ) then
			DBCS_HDV_faction = 2;
		end
		DBcorpsFrame_HDVFrame_Tri_UnSeul:SetChecked(1);
		DBcorpsFrame_HDV_stats_Frame_Criteres_DernierScan:SetChecked(1);
		DBcorpsFrame_HDV_stats_Frame_Criteres_SousAlerte:SetChecked(1);
	end

end

--/script DBCS_HDV_toutlire();
function DBCS_HDV_toutlire()

local canQuery, canQueryAll;
local itime;

	if ( DBCS_HDV_etape == 0 ) then
		DBCS_HDV_etape = 1;
	end

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

	canQuery, canQueryAll = CanSendAuctionQuery();
	if ( ( 1 == 0 ) and ( canQueryAll == 1 ) ) then
		DBCS_HDV_btoutlire = true;
		DBCS_HDV_bappel = false;
		SortAuctionItems("list", "quality");
		SortAuctionItems("list", "duration");
		DBCS_HDV_inumordre = 0;
		DBCS_HDV_tQueryAuctionItems_name = "";
		DBCS_HDV_tQueryAuctionItems_minLevel = "";
		DBCS_HDV_tQueryAuctionItems_maxLevel = "";
		DBCS_HDV_tQueryAuctionItems_invTypeIndex = nil;
		DBCS_HDV_tQueryAuctionItems_classIndex = nil;
		DBCS_HDV_tQueryAuctionItems_subclassIndex = nil;
		DBCS_HDV_tQueryAuctionItems_page = 0;
		DBCS_HDV_tQueryAuctionItems_isUsable = nil;
		DBCS_HDV_tQueryAuctionItems_qualityIndex = nil;
		DBCS_HDV_tQueryAuctionItems_getAll = getAll;
		itime = GetTime();
		QueryAuctionItems(DBCS_HDV_tQueryAuctionItems_name,DBCS_HDV_tQueryAuctionItems_minLevel,DBCS_HDV_tQueryAuctionItems_maxLevel,DBCS_HDV_tQueryAuctionItems_invTypeIndex,DBCS_HDV_tQueryAuctionItems_classIndex,DBCS_HDV_tQueryAuctionItems_subclassIndex,DBCS_HDV_tQueryAuctionItems_page,DBCS_HDV_tQueryAuctionItems_isUsable,DBCS_HDV_tQueryAuctionItems_qualityIndex,DBCS_HDV_tQueryAuctionItems_getAll);
		DBCS_HDV_bnumrech = true;
		DBCS_HDV_bappel = true;
	elseif ( canQuery == 1 ) then
		DBCS_HDV_btoutlire = true;
		if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech] == nil ) then
		else
			--	faire code
			--DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech-1] = nil;
		end
		DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1] = {};
		DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1] = {};
		DBCS_HDV_bappel = false;
		SortAuctionItems("list", "quality");
		SortAuctionItems("list", "duration");
		DBCS_HDV_inumordre = 0;
		--DBCS_HDV_tQueryAuctionItems_OnUpdate_timedebut = 0;
		DBCS_HDV_tQueryAuctionItems_OnUpdate_timefin = DBCS_HDV_time_48heures;
		DBCS_HDV_tQueryAuctionItems_name = "";
		DBCS_HDV_tQueryAuctionItems_minLevel = "";
		DBCS_HDV_tQueryAuctionItems_maxLevel = "";
		DBCS_HDV_tQueryAuctionItems_invTypeIndex = nil;
		DBCS_HDV_tQueryAuctionItems_classIndex = nil;
		DBCS_HDV_tQueryAuctionItems_subclassIndex = nil;
		DBCS_HDV_tQueryAuctionItems_page = 0;
		DBCS_HDV_tQueryAuctionItems_isUsable = nil;
		DBCS_HDV_tQueryAuctionItems_qualityIndex = nil;
		DBCS_HDV_tQueryAuctionItems_getAll = nil;
		--DBCS_HDV_tQueryAuctionItems_OnUpdate_uniquedernier = nil;
		DBCS_HDV_tQueryAuctionItems_OnUpdate_buniquedernier = false;
		itime = GetTime();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("premier appel de la recherche = "..itime);
--end
		QueryAuctionItems(DBCS_HDV_tQueryAuctionItems_name,DBCS_HDV_tQueryAuctionItems_minLevel,DBCS_HDV_tQueryAuctionItems_maxLevel,DBCS_HDV_tQueryAuctionItems_invTypeIndex,DBCS_HDV_tQueryAuctionItems_classIndex,DBCS_HDV_tQueryAuctionItems_subclassIndex,DBCS_HDV_tQueryAuctionItems_page,DBCS_HDV_tQueryAuctionItems_isUsable,DBCS_HDV_tQueryAuctionItems_qualityIndex,DBCS_HDV_tQueryAuctionItems_getAll);
		DBCS_HDV_bnumrech = true;
		DBCS_HDV_bappel = true;
	end

end

function DBCS_HDV_OnUpdate()

local canQuery, canQueryAll;
local itime;
local bsuite = false;
local i;
local itimeleft;
local sunique;
local iunique_nb;
local offset;

	itime = GetTime();
	if ( DBCS_HDV_etape == 0 ) then
	elseif ( DBCS_HDV_etape == 1 ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBCS_HDV_etape = "..DBCS_HDV_etape.." a "..itime);
--end
		canQuery, canQueryAll = CanSendAuctionQuery();
		if ( canQuery == 1 ) then
			SortAuctionItems("list", "quality");
			DBCS_HDV_etape = 2;
		end
	elseif ( DBCS_HDV_etape == 2 ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBCS_HDV_etape = "..DBCS_HDV_etape.." a "..itime);
--end
		canQuery, canQueryAll = CanSendAuctionQuery();
		if ( canQuery == 1 ) then
			SortAuctionItems("list", "duration");
			DBCS_HDV_etape = 3;
		end
	elseif ( DBCS_HDV_etape == 3 ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBCS_HDV_etape = "..DBCS_HDV_etape.." a "..itime);
--end
		canQuery, canQueryAll = CanSendAuctionQuery();
		if ( canQuery == 1 ) then
			DBCS_HDV_tQueryAuctionItems_name = "";
			DBCS_HDV_tQueryAuctionItems_minLevel = "";
			DBCS_HDV_tQueryAuctionItems_maxLevel = "";
			DBCS_HDV_tQueryAuctionItems_invTypeIndex = nil;
			DBCS_HDV_tQueryAuctionItems_classIndex = nil;
			DBCS_HDV_tQueryAuctionItems_subclassIndex = nil;
			DBCS_HDV_tQueryAuctionItems_page = 0;
			DBCS_HDV_tQueryAuctionItems_isUsable = nil;
			DBCS_HDV_tQueryAuctionItems_qualityIndex = nil;
			DBCS_HDV_tQueryAuctionItems_getAll = nil;
			QueryAuctionItems(DBCS_HDV_tQueryAuctionItems_name,DBCS_HDV_tQueryAuctionItems_minLevel,DBCS_HDV_tQueryAuctionItems_maxLevel,DBCS_HDV_tQueryAuctionItems_invTypeIndex,DBCS_HDV_tQueryAuctionItems_classIndex,DBCS_HDV_tQueryAuctionItems_subclassIndex,DBCS_HDV_tQueryAuctionItems_page,DBCS_HDV_tQueryAuctionItems_isUsable,DBCS_HDV_tQueryAuctionItems_qualityIndex,DBCS_HDV_tQueryAuctionItems_getAll);
			DBCS_HDV_etape = 4;
		end
	elseif ( DBCS_HDV_etape == 4 ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBCS_HDV_etape = "..DBCS_HDV_etape.." a "..itime);
--end
		canQuery, canQueryAll = CanSendAuctionQuery();
		if ( canQuery == 1 ) then
			DBCS_HDV_btoutlire = true;
			if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech] == nil ) then
			else
				--	faire code
				--DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech-1] = nil;
			end
			DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1] = {};
			DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1] = {};
			DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1] = {};
			DBCS_HDV_bappel = false;
			DBCS_HDV_inumordre = 0;
			--DBCS_HDV_tQueryAuctionItems_OnUpdate_timedebut = 0;
			DBCS_HDV_tQueryAuctionItems_OnUpdate_timefin = DBCS_HDV_time_48heures;
			DBCS_HDV_tQueryAuctionItems_OnUpdate_buniquedernier = false;
			itime = GetTime();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("premier appel de la recherche = "..itime);
--end
			QueryAuctionItems(DBCS_HDV_tQueryAuctionItems_name,DBCS_HDV_tQueryAuctionItems_minLevel,DBCS_HDV_tQueryAuctionItems_maxLevel,DBCS_HDV_tQueryAuctionItems_invTypeIndex,DBCS_HDV_tQueryAuctionItems_classIndex,DBCS_HDV_tQueryAuctionItems_subclassIndex,DBCS_HDV_tQueryAuctionItems_page,DBCS_HDV_tQueryAuctionItems_isUsable,DBCS_HDV_tQueryAuctionItems_qualityIndex,DBCS_HDV_tQueryAuctionItems_getAll);
			DBCS_HDV_bnumrech = true;
			DBCS_HDV_bappel = true;
			DBCS_HDV_etape = 5;
		end
	elseif ( DBCS_HDV_etape == 5 ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBCS_HDV_etape = "..DBCS_HDV_etape.." a "..itime);
--end
		if ( DBCS_HDV_b_scan_continuel == true ) then
			if ( DBCS_HDV_tQueryAuctionItems_OnUpdate == true ) then
--TraceFrame:AddMessage("DBCS_HDV_tQueryAuctionItems_OnUpdate = true");
				bsuite = true;
			else
--TraceFrame:AddMessage("DBCS_HDV_AUCTION_ITEM_LIST_UPDATE_time = "..DBCS_HDV_AUCTION_ITEM_LIST_UPDATE_time);
				if ( DBCS_HDV_AUCTION_ITEM_LIST_UPDATE_time > 0 and ( ( itime - DBCS_HDV_AUCTION_ITEM_LIST_UPDATE_time ) > 0.3 ) ) then
					bsuite = true;
					--DBCS_HDV_verif_compare_enreg();
				else
				end
			end
		end
		if ( bsuite == true or 1 == 1 ) then
			canQuery, canQueryAll = CanSendAuctionQuery();	--	CanSendAuctionQuery("list");
--TraceFrame:AddMessage("canQuery = "..(canQuery or "nil")..", canQueryAll = "..(canQueryAll or "nil"));
			if ( canQuery == 1 ) then
				--DBCS_HDV_verif_compare_enreg();
				DBCS_HDV_tQueryAuctionItems_OnUpdate = false;
				DBCS_HDV_AUCTION_ITEM_LIST_UPDATE_time = 0;
				if ( (DBCS_HDV_inumordre + DBCS_HDV_tQueryAuctionItems_OnUpdate_inb) < DBCS_HDV_tQueryAuctionItems_OnUpdate_imax ) then
					DBCS_HDV_tQueryAuctionItems_page = DBCS_HDV_tQueryAuctionItems_page + 1;
					DBcorpsFrame_HDVFrame_Criteres_Bar:SetValue((DBCS_HDV_tQueryAuctionItems_page/(DBCS_HDV_tQueryAuctionItems_OnUpdate_imax/50))*100);
					DBcorpsFrame_HDV_stats_Frame_Criteres_Bar:SetValue((DBCS_HDV_tQueryAuctionItems_page/(DBCS_HDV_tQueryAuctionItems_OnUpdate_imax/50))*100);
					DBCS_HDV_inumordre = DBCS_HDV_inumordre + 50;	--	DBCS_HDV_tQueryAuctionItems_OnUpdate_inb;
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("lancement de la suite de la recherche = "..itime.." , page "..(DBCS_HDV_tQueryAuctionItems_page+1).." sur "..DBCS_HDV_tQueryAuctionItems_OnUpdate_imax.." enregistrements.");
--end
					QueryAuctionItems(DBCS_HDV_tQueryAuctionItems_name,DBCS_HDV_tQueryAuctionItems_minLevel,DBCS_HDV_tQueryAuctionItems_maxLevel,DBCS_HDV_tQueryAuctionItems_invTypeIndex,DBCS_HDV_tQueryAuctionItems_classIndex,DBCS_HDV_tQueryAuctionItems_subclassIndex,DBCS_HDV_tQueryAuctionItems_page,DBCS_HDV_tQueryAuctionItems_isUsable,DBCS_HDV_tQueryAuctionItems_qualityIndex,DBCS_HDV_tQueryAuctionItems_getAll);
					DBCS_HDV_bnumrech = true;
					DBCS_HDV_bappel = true;
				else
					DBCS_HDV_verif_compare_enreg();
					--if ( DBCS_HDV_verif_compare_enreg() == true ) then
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech] = nil;
						DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech] = nil;
						DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech] = {};
						DBCS_HDV_inumrech = DBCS_HDV_inumrech + 1;
						offset = FauxScrollFrame_GetOffset(DBcorpsFrame_HDVFrame_Liste_ScrollFrame);
						DBcorps_ListHDV_Update();
						if ( offset < DBCORPS_HDV_LISTE_nb ) then
							FauxScrollFrame_SetOffset(DBcorpsFrame_HDVFrame_Liste_ScrollFrame,offset);
							DBcorpsFrame_HDVFrame_Liste_ScrollFrameScrollBar:SetValue(offset*32);
						end
						offset = FauxScrollFrame_GetOffset(DBcorpsFrame_HDV_stats_Frame_Liste_ScrollFrame);
						DBcorps_ListHDV_stats_Update();
						if ( offset < DBCORPS_HDV_stats_LISTE_nb ) then
							FauxScrollFrame_SetOffset(DBcorpsFrame_HDV_stats_Frame_Liste_ScrollFrame,offset);
							DBcorpsFrame_HDV_stats_Frame_Liste_ScrollFrameScrollBar:SetValue(offset*32);
						end
					--else
					--end
					DBCORPS_HDV_LISTE_OnUpdate_time = GetTime();
					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1] = {};
					DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1] = {};
					DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1] = {};
					DBCS_HDV_etape = 0;
					DBcorps_ListHDV_Scan_debut();
					--DBCS_HDV_toutlire();
				end
			end
		else
		end
	end
	if ( DBCORPS_HDV_LISTE_OnUpdate_time > 0 ) then
		if ( ( itime - DBCORPS_HDV_LISTE_OnUpdate_time ) > 1 ) then
			DBCORPS_HDV_LISTE_OnUpdate_time = itime;
			if ( DBcorpsFrame:IsShown() ) then
				DBCS_HDV_Scroll_Update();
			end
		end
	end

end

function DBCS_HDV_verif_compare_enreg()

local i;
local sunique;
local iunique_nb;
local itimeleft;
local itimediff;
local itime;
local bordre_bon;
local irang;
local inumobjet;
local imontant_7;
local imontant_9;
local imontant_10;
local inb;
local sDBCS_HDV_stats;
local idate;
local sdate;
local sheure;
local svendeur;
local itaillepile;

	itime = GetTime();
	bordre_bon = true;
	--	DBCS_HDV_stats
	--	DBCS_serveur
	--	DBCS_HDV_faction
	sDBCS_HDV_stats = DBCS_serveur.."@"..DBCS_HDV_faction.."@";
	if ( DBCS_HDV_stats[sDBCS_HDV_stats] == nil ) then
		DBCS_HDV_stats[sDBCS_HDV_stats] = {};
	end
	idate = tonumber(DBCS_date());
	sdate = ""..idate;
	if ( DBCS_HDV_histo_config ) then
		if ( DBCS_HDV_histo_config["FACTION"] and DBCS_HDV_histo_config["FACTION"] == DBCS_HDV_faction ) then
		else
			DBCS_HDV_histo = {};
			DBCS_HDV_histo_config["FACTION"] = DBCS_HDV_faction;
			DBCS_HDV_histo_config["DATE"] = nil;
		end
		if ( DBCS_HDV_histo_config["DATE"] == nil ) then
			DBCS_HDV_histo_config["DATE"] = {};
		end
		if ( DBCS_HDV_histo_config["DATE"][sdate] == nil ) then
			DBCS_HDV_histo_config["DATE"][sdate] = 0;
		end
		DBCS_HDV_histo_config["DATE"][sdate] = DBCS_HDV_histo_config["DATE"][sdate] + 1;
	end
	for i = 1 , DBCS_HDV_tQueryAuctionItems_OnUpdate_imax do
		if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i] ) then
			if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][21] == "i" ) then
				inumobjet = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][19];
			else
				inumobjet = nil;
			end
		else
			inumobjet = nil;
		end
		if ( inumobjet ) then
			if ( DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet] == nil ) then
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet] = {};
			end
			if ( DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][11] == nil ) then
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][11] = 0;
			end
			if ( DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][12] == nil ) then
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][12] = 0;
			end
			DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][13] = 0;
			DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][14] = 0;
			DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][15] = -1;
			DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][16] = 5;
			if ( DBCS_HDV_histo ) then
				if ( DBCS_HDV_histo[inumobjet] == nil ) then
					DBCS_HDV_histo[inumobjet] = {};
				end
				if ( DBCS_HDV_histo[inumobjet][sdate] == nil ) then
					DBCS_HDV_histo[inumobjet][sdate] = {};
				end
			end
		end
	end
	irang = 0;
	for i = 1 , DBCS_HDV_tQueryAuctionItems_OnUpdate_imax do
		if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i] ) then
			if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][21] == "i" ) then
				inumobjet = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][19];
			else
				inumobjet = nil;
			end
		else
			inumobjet = nil;
		end
--		if ( type(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7]) == "string" ) then
		if ( inumobjet ) then
			-- nb objets ds la pile
			inb = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][3];
			-- en po
			-- enchère de base
			--if ( type(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7]) == "string" ) then
			--	TraceFrame:AddMessage(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7]);
			--end
			imontant_7 = ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7] / 10000 ) / inb;
			-- prix achat direct
			imontant_9 = ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][9] / 10000 ) / inb;
			-- enchère encours
			imontant_10 = ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][10] / 10000 ) / inb;
			-- vendeur
			svendeur = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][12];
			if ( svendeur == nil ) then
				svendeur = "";
			end

			if ( DBCS_HDV_histo ) then
				if ( imontant_9 and imontant_9 > 0 ) then
					if ( strlen(svendeur) > 0 ) then
						if ( DBCS_HDV_histo[inumobjet][sdate][1] ) then
							if ( imontant_9 < DBCS_HDV_histo[inumobjet][sdate][1] ) then
								DBCS_HDV_histo[inumobjet][sdate][1] = imontant_9;
								DBCS_HDV_histo[inumobjet][sdate][2] = svendeur;
								DBCS_HDV_histo[inumobjet][sdate][3] = 1;
							elseif ( ( imontant_9 == DBCS_HDV_histo[inumobjet][sdate][1] ) and ( svendeur == DBCS_HDV_histo[inumobjet][sdate][2] ) ) then
								DBCS_HDV_histo[inumobjet][sdate][3] = DBCS_HDV_histo[inumobjet][sdate][3] + 1;
							end
						else
							DBCS_HDV_histo[inumobjet][sdate][1] = imontant_9;
							DBCS_HDV_histo[inumobjet][sdate][2] = svendeur;
							DBCS_HDV_histo[inumobjet][sdate][3] = 1;
						end
					end
				end
				if ( imontant_10 and imontant_10 > 0 ) then
					if ( DBCS_HDV_histo[inumobjet][sdate][4] ) then
						if ( imontant_10 > DBCS_HDV_histo[inumobjet][sdate][4] ) then
							DBCS_HDV_histo[inumobjet][sdate][4] = imontant_10;
						end
					else
						DBCS_HDV_histo[inumobjet][sdate][4] = imontant_10;
					end
				end
			end
			if ( DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet] == nil ) then
				DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet] = {};
				if ( imontant_9 > 0 ) then
					DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][6] = imontant_9;
				end
				if ( imontant_9 > 0 ) then
					DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][8] = imontant_9;
				end
				if ( imontant_10 > 0 ) then
					DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][10] = imontant_10;
				end
			end
			if ( imontant_9 > 0 ) then
				if ( DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][6] ) then
					if ( imontant_9 < DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][6] ) then
						DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][6] = imontant_9;
					end
				else
					DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][6] = imontant_9;
				end
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][11] = DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][11] + ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][9] / 10000 ) ;
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][12] = DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][12] + inb;
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][13] = DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][13] + ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][9] / 10000 ) ;
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][14] = DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][14] + inb;
			end
			if ( imontant_9 > 0 ) then
				if ( DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][8] ) then
					DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][8] = ( DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][8] + imontant_9 ) / 2;
				else
					DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][8] = imontant_9;
				end
			end
			if ( imontant_10 > 0 ) then
				if ( DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][10] ) then
					if ( imontant_10 > DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][10] ) then
						DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][10] = imontant_10;
					end
				else
					DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][10] = imontant_10;
				end
			end
			if ( DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][1] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][15] <= DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][16] and imontant_7 <= DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][1] and imontant_10 <= DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][1] ) then
				if ( imontant_10 > 0 or imontant_7 > 0 ) then
					DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][16] = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][15];
					if ( DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][15] == -1 ) then
						if ( imontant_10 > 0 ) then
							DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][15] = imontant_10;
						else
							DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][15] = imontant_7;
						end
					else
						if ( imontant_10 > 0 and imontant_10 < DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][15] ) then
							DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][15] = imontant_10;
						else
							if ( imontant_7 < DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][15] ) then
								DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][15] = imontant_7;
							end
						end
					end
				end
			end
		end
		
	--	clé	=	19 + @ + 20 + @ + 3 + @ + 12 + @ + 7 + @ + 9 + @

--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][1] = name;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][2] = texture;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][3] = count;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][4] = quality;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][5] = canUse;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][6] = level;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7] = minBid;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][8] = minIncrement;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][9] = buyoutPrice;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][10] = bidAmount;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][11] = highBidder;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][12] = owner;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][13] = timeleft;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][14] = itemlink;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][15] = itime;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = tempsmini;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = tempsmax;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][18] = nbunique;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][19] = inumobjet;
--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][20] = snumcourt2;

		if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i] ) then
			itimeleft = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][13];
			if ( itimeleft and itimeleft >= irang ) then
				irang = itimeleft;
			else
				if ( itimeleft == nil ) then
					itimeleft = irang;
				end
				irang = itimeleft;
				bordre_bon = false;
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("Ordre dans les temps restants incorrect , enreg : "..i);
end
			end
	--	clé	=	19 + @ + 20 + @ + 3 + @ + 12 + @ + 7 + @ + 9 + @
			if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][21] == "i" ) then
				sunique = ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][19] or "").."@"..( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][20] or "").."@"..( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][3] or "").."@"..( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][12] or "").."@"..( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7] or "").."@"..( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][9] or "").."@";
			else
				sunique = ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][14] or "").."@"..( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][20] or "").."@"..( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][3] or "").."@"..( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][12] or "").."@"..( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7] or "").."@"..( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][9] or "").."@";
			end
			if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique] == nil ) then
				DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique] = {};
			end
			iunique_nb = table.getn(DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique]);
			iunique_nb = iunique_nb + 1;
			DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][18] = iunique_nb;
			DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][-1] = 0;
			DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][0] = iunique_nb;
			DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb] = {};
			DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb][0] = i;
			DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb][10] = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][10];
			DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb][13] = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][13];
			DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb][15] = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][15];
		end
	end
	if ( DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1] ) then
		sheure = date("%H%M%S");
		--sdateheure = DBCS_date().."@"..date("%H%M%S");
		if ( DBCS_HDV_stats_config["dernierscan"] == nil ) then
			DBCS_HDV_stats_config["dernierscan"] = {};
		end
		if ( DBCS_HDV_stats_config["dernierscan"][sDBCS_HDV_stats] == nil ) then
			DBCS_HDV_stats_config["dernierscan"][sDBCS_HDV_stats] = {};
		end
		DBCS_HDV_stats_config["dernierscan"][sDBCS_HDV_stats]["date"] = idate;
		DBCS_HDV_stats_config["dernierscan"][sDBCS_HDV_stats]["heure"] = sheure;
		for inumobjet, _ in pairs(DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1]) do
			if ( DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet] == nil ) then
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet] = {};
			end
			-- date dernier scan
			DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][3] = idate;
			-- heure dernier scan
			DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][4] = sheure;
			if ( DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][6] ) then
				-- achat direct le + bas
				if ( DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][5] ) then
					if ( DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][6] < DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][5] ) then
						DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][5] = DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][6];
					end
				else
					DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][5] = DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][6];
				end
				-- achat direct le + bas, dernier scan
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][6] = DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][6];
			else
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][6] = nil;
			end
			if ( DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][8] ) then
				--achat direct prix moyen
				if ( DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][7] ) then
					DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][7] = ( DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][7] + DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][8] ) / 2;
				else
					DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][7] = DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][8];
				end
				--achat direct prix moyen, dernier scan
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][8] = DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][8];
			else
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][8] = nil;
			end
			if ( DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][10] ) then
				-- montant enchère validée la + haute
				if ( DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][9] ) then
					if ( DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][10] > DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][9] ) then
						DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][9] = DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][10];
					end
				else
					DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][9] = DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][10];
				end
				-- montant enchère validée la + haute, dernier scan
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][10] = DBCS_HDV_tobjets_stats[DBCS_HDV_inumrech+1][inumobjet][10];
			else
				DBCS_HDV_stats[sDBCS_HDV_stats][inumobjet][10] = nil;
			end
		end
	end
	if ( bordre_bon == false ) then
		return bordre_bon;
	end
	for i = 1 , DBCS_HDV_tQueryAuctionItems_OnUpdate_imax do
		if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i] ) then
		itimeleft = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][13];
		-- fixe les bornes de l'enreg en fonction de son rang de temps restant
		if ( itimeleft == 1 ) then
			DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = 0;
			DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_30min;
		elseif ( itimeleft == 2 ) then
			DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_30min;
			DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_2heures;
		elseif ( itimeleft == 3 ) then
			DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_2heures;
			DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_12heures;
		elseif ( itimeleft == 4 ) then
			--if ( DBCS_HDV_tQueryAuctionItems_OnUpdate_buniquedernier == true ) then
			--	DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][16] = DBCS_HDV_time_48heures - ( itime - DBCS_HDV_tQueryAuctionItems_OnUpdate_uniquedernier_time );
			--else
				DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_12heures;
			--end
			DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_48heures;
		end
	--	clé	=	19 + @ + 20 + @ + 3 + @ + 12 + @ + 7 + @ + 9 + @
		if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][21] == "i" ) then
			sunique = (DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][19] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][20] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][3] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][12] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][9] or i).."@";
		else
			sunique = (DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][14] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][20] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][3] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][12] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][9] or i).."@";
		end
		---- si on a dépassé le dernier enreg récup du scan précédent
		--if ( DBCS_HDV_tQueryAuctionItems_OnUpdate_uniquedernier == sunique ) then
		--	DBCS_HDV_tQueryAuctionItems_OnUpdate_buniquedernier = true;
		--end
		---- enreg la clé du dernier enreg récup ds ce scan
		--if ( ( DBCS_HDV_inumordre + i ) == DBCS_HDV_tQueryAuctionItems_OnUpdate_imax ) then
		--	--DBCS_HDV_tQueryAuctionItems_OnUpdate_buniquedernier = true;
		--	DBCS_HDV_tQueryAuctionItems_OnUpdate_uniquedernier = sunique;
		--	DBCS_HDV_tQueryAuctionItems_OnUpdate_uniquedernier_time = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][15];
		--end
		if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1] and DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique] and DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][-1] ) then
		iunique_nb = DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][-1];
		iunique_nb = iunique_nb + 1;
		DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][-1] = iunique_nb;
		-- si l'ancienne recherche existe
		if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech] and DBCS_HDV_inumrech > 2 ) then
			-- si l'unique existait et unique
			if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique] and DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][0] == 1 and DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][0] == 1 ) then
				itimediff = DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][1][15] - DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][1][15];
				-- si l'objet est toujours ds la meme plage
				if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][1][13] == DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][13] ) then
					-- si le montant courant de l'enchère est toujours le meme
					--if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][1][10] == DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][10] ) then
					if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][1][10] == DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][10] and DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][1][16] ) then
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][1][16] - itimediff;
						if ( itimeleft == 1 ) then
							if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] < 0 ) then
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = 0;
							end
						elseif ( itimeleft == 2 ) then
							if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] < DBCS_HDV_time_30min ) then
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_30min;
							end
						elseif ( itimeleft == 3 ) then
							if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] < DBCS_HDV_time_2heures ) then
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_2heures;
							end
						elseif ( itimeleft == 4 ) then
							if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] < DBCS_HDV_time_12heures ) then
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_12heures;
							end
						end
						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][1][17] - itimediff;
					else
					end
				else
					-- si le montant courant de l'enchère est toujours le meme
					if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][10] == DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][1][10] ) then
						if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][1][13] == ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][13] + 1 ) ) then
							--DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][iunique_nb][16] - itimediff;
							if ( itimeleft == 1 ) then
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_30min - itimediff;
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_30min;
							elseif ( itimeleft == 2 ) then
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_2heures - itimediff;
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_2heures;
							elseif ( itimeleft == 3 ) then
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_12heures - itimediff;
								DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_12heures;
							--elseif ( itimeleft == 4 ) then
							--	DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][17] = DBCS_HDV_time_48heures;
							end
						end
					else
					end
				end
				
				---- si l'unique est ds le tableau
				--if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][iunique_nb] ) then
				--	itimediff = DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb][15] - DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][iunique_nb][15];
				--	-- si le tablo d'unique est non unique
				--	if ( table.getn(DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique]) > 1 ) then
				--	else
				--		-- si le montant courant de l'enchère est toujours le meme
				--		if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][10] == DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][iunique_nb][10] ) then
				--			DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][16] = DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][iunique_nb][16] - itimediff;
				--			if ( itimeleft == 1 ) then
				--				if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] < 0 ) then
				--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = 0;
				--				end
				--			elseif ( itimeleft == 2 ) then
				--				if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] < DBCS_HDV_time_30min ) then
				--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_30min;
				--				end
				--			elseif ( itimeleft == 3 ) then
				--				if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] < DBCS_HDV_time_2heures ) then
				--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_2heures;
				--				end
				--			elseif ( itimeleft == 4 ) then
				--				if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] < DBCS_HDV_time_12heures ) then
				--					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_12heures;
				--				end
				--			end
				--			DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][iunique_nb][17] - itimediff;
				--		else
				--		end
				--	end
				--	-- si l'objet est toujours ds la meme plage
				--	if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][iunique_nb][13] == DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][13] ) then
				--	else
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("sunique = "..sunique..", iunique_nb = "..iunique_nb.." change de plage horaire : "..( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][iunique_nb][13] or "").." vers "..DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][13]);
--end
				--		if ( table.getn(DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique]) > 1 ) then
				--		else
				--			if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][10] == DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][iunique_nb][10] ) then
				--				if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][iunique_nb][13] == ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][13] + 1 ) ) then
				--					--DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech][sunique][iunique_nb][16] - itimediff;
				--					if ( itimeleft == 1 ) then
				--						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_30min - itimediff;
				--						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_30min;
				--					elseif ( itimeleft == 2 ) then
				--						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_2heures - itimediff;
				--						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_2heures;
				--					elseif ( itimeleft == 3 ) then
				--						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_time_12heures - itimediff;
				--						DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_12heures;
				--					--elseif ( itimeleft == 4 ) then
				--					--	DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][DBCS_HDV_inumordre+i][17] = DBCS_HDV_time_48heures;
				--					end
				--				end
				--			end
				--		end
				--	end
				--else
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("sunique = "..sunique.." introuvable. iunique_nb = "..iunique_nb);
--end
				--end
			--else
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("sunique = "..sunique.." introuvable.");
--end
			end
		else
		end
		end
		--if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] < DBCS_HDV_tQueryAuctionItems_OnUpdate_timedebut ) then
		--	DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_tQueryAuctionItems_OnUpdate_timedebut;
		--	--if ( itimeleft == 1 ) then
		--	--	DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_30min;
		--	--elseif ( itimeleft == 2 ) then
		--	--	DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_2heures;
		--	--elseif ( itimeleft == 3 ) then
		--	--	DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_12heures;
		--	--elseif ( itimeleft == 4 ) then
		--	--	DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_48heures;
		--	--end
		--end
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("sunique = "..sunique..", time debut = "..DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16]..", time fin = "..DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17]);
--end
		if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1] and DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique] and DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb] and i and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i] ) then
			DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb][16] = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16];
			DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb][17] = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17];
		end
		--DBCS_HDV_tQueryAuctionItems_OnUpdate_timedebut = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16];
		--DBCS_HDV_tQueryAuctionItems_OnUpdate_timefin = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17];
		end
	end
	DBCS_HDV_tQueryAuctionItems_OnUpdate_timedebut = 0;
	for i = 1 , DBCS_HDV_tQueryAuctionItems_OnUpdate_imax do
		if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i] ) then
			if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] < DBCS_HDV_tQueryAuctionItems_OnUpdate_timedebut ) then
				DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] = DBCS_HDV_tQueryAuctionItems_OnUpdate_timedebut;
				itimeleft = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][13];
				if ( itimeleft == 1 ) then
					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_30min;
				elseif ( itimeleft == 2 ) then
					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_2heures;
				elseif ( itimeleft == 3 ) then
					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_12heures;
				elseif ( itimeleft == 4 ) then
					DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_time_48heures;
				end
			end
			if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i] ) then
				--	clé	=	19 + @ + 20 + @ + 3 + @ + 12 + @ + 7 + @ + 9 + @
				if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][21] == "i" ) then
					sunique = (DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][19] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][20] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][3] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][12] or "").."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][9] or i).."@";
				else
					sunique = (DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][14] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][20] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][3] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][12] or "").."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][9] or i).."@";
				end
				if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique] ) then
					iunique_nb = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][18];
					DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb][16] = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16];
					DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb][17] = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17];
				end
				DBCS_HDV_tQueryAuctionItems_OnUpdate_timedebut = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16];
				DBCS_HDV_tQueryAuctionItems_OnUpdate_timefin = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17];
			end
		end
	end
	for i = DBCS_HDV_tQueryAuctionItems_OnUpdate_imax , 1 , -1 do
		if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i] ) then
			if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] > DBCS_HDV_tQueryAuctionItems_OnUpdate_timefin ) then 	--and DBCS_HDV_tQueryAuctionItems_OnUpdate_timefin > DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][16] ) then
				DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17] = DBCS_HDV_tQueryAuctionItems_OnUpdate_timefin;
			end
			sunique = (DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][14] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][12] or "").."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][7] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][9] or i).."@"..(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][3] or i).."@";
			if ( DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique] ) then
				iunique_nb = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][18];
				DBCS_HDV_tQueryAuctionItems_unique[DBCS_HDV_inumrech+1][sunique][iunique_nb][17] = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17];
			end
			DBCS_HDV_tQueryAuctionItems_OnUpdate_timefin = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech+1][i][17];
		end
	end
	return bordre_bon;

end

function DBcorps_ListHDV_UnSeul_OnClick()

	DBCS_HDV_Scroll_Update();

end

	--	unique =	14 ( itemlink )	+	12 ( owner )		+	3 ( count )		+	7 ( minBID )	+	9 ( buyoutPrice )
	--	10 ( bidAmount )	+	13 ( timeleft )

function DBCS_HDV_Scroll_Update()

local i,j;
local offset = FauxScrollFrame_GetOffset(DBcorpsFrame_HDVFrame_Liste_ScrollFrame);
local button,buttonName;
local itemChamp;
local snomobjet;
local inum;
local svendeur;
local itimeleft;
local itempsmini;
local itempsmax;
local itime;
local itimei;
local itimeecart;
local i09;
local i10;
local inumobjet;
local snumcourt2;
local iniv;
local ienv;
local tablo;
local r,g,b,hex;
local inb;
local a;
local i_un_seul;
local stexture;

	i_un_seul = _G["DBcorpsFrame_HDVFrame_Tri_UnSeul"]:GetChecked();
	if ( i_un_seul == nil ) then
		i_un_seul = 0;
	end

	FauxScrollFrame_Update(DBcorpsFrame_HDVFrame_Liste_ScrollFrame, DBCORPS_HDV_LISTE_nb, 10, 32);

	itime = GetTime();
	for i = 1 , 10 do
		j = offset + i;
		buttonName = "DBcorpsFrame_HDVFrame_Liste_Button"..i;
		button = _G[buttonName];
		button:Hide();
		if ( j > DBCORPS_HDV_LISTE_nb ) then
		else
			if ( DBCORPS_HDV_LISTE and DBCORPS_HDV_LISTE[j] and DBCORPS_HDV_LISTE[j][1] ) then
				inum = DBCORPS_HDV_LISTE[j][1];
			else
				inum = 0;
			end
			snomobjet = "";
			svendeur = "";
			itimeleft = nil;
			itempsmini = nil;
			itempsmax = nil;
			itimei = nil;
			i09 = nil;
			i10 = nil;
			inumobjet = nil;
			snumcourt2 = nil;
			iniv = nil;
			ienv = nil;
			inb = nil;
			stexture = nil;
			tablo = {};
			if ( inum and DBCS_HDV_tQueryAuctionItems and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum] ) then
				snomobjet = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][1];
				stexture = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][2];
				i09 = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][9];
				i10 = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][10];
				if ( i10 == 0 ) then
					i10 = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][7];
				end
				svendeur = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][12];
				itimeleft = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][13];
				itempsmini = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][16];
				itempsmax = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][17];
				itimei = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][15];
				inb = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][3];
				if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][21] == "i" ) then
					inumobjet = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][19];
				else
					inumobjet = nil;
				end
				snumcourt2 = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][20];
				if ( inumobjet and snumcourt2 ) then
					tablo = DBOS_detail(inumobjet,snumcourt2);
					if ( tablo.nomobjet ) then
					end
				end
			end
			if ( inumobjet == nil ) then
				inumobjet = 0;
			end
			itemChamp = _G[buttonName.."_Item_IconTexture"];
			itemChamp:Hide();
			itemChamp:SetTexture("Interface/Icons/INV_Misc_QuestionMark");
			itemChamp:SetTexture(tablo.texture);
			itemChamp:SetTexture(stexture);
			itemChamp:Show();
			itemChamp = _G[buttonName.."_Nomobjet"];
			itemChamp:SetText(snomobjet);
			if ( tablo.rarity ) then
				r,g,b,hex = GetItemQualityColor(tablo.rarity);
				itemChamp:SetTextColor(r, g, b);
			end
			itemChamp = _G[buttonName.."_Niveau"];
			itemChamp:SetText(tablo.minlevel);
			itemChamp = _G[buttonName.."_Nivreel"];
			itemChamp:SetText(tablo.level);
			a, _, _, _, _, _, _, _, _, _ = GetItemInfo(inumobjet);
			if ( a ) then
				if ( DBOT_linkable ) then
					--if ( DBOT_linkable[DBCS_serveur] and DBOT_linkable[DBCS_serveur]["objets"] and DBOT_linkable[DBCS_serveur]["objets"][inumobjet] == 0 ) then
					if ( DBOT_linkable_objet_linkable(inumobjet) == true ) then
						itemChamp:SetTextColor(1,1,1);		-- blanc
					else
						itemChamp:SetTextColor(1,0.5,0);	-- orange
					end
				else
					itemChamp:SetTextColor(1,1,1);			-- blanc
				end
			else
				itemChamp:SetTextColor(1,0,0);				-- rouge
			end
			itemChamp = _G[buttonName.."_Numobjet"];
			itemChamp:SetText(inum);
			itemChamp = _G[buttonName.."_Vendeur"];
			itemChamp:SetText(svendeur);
			itemChamp = _G[buttonName.."_Tempsmini"];
			if ( itimei ) then
				itimeecart = itime - itimei;
			else
				itimeecart = 0;
			end
			if ( itempsmini ) then
				itemChamp:SetText(DBCS_HDV_heure_vers_string(DBCS_HDV_time_vers_heure(itempsmini-itimeecart)));
			else
				if ( itimeleft ) then
					itemChamp:SetText(AuctionFrame_GetTimeLeftText(itimeleft));
				else
					itemChamp:SetText(nil);
				end
			end
			itemChamp = _G[buttonName.."_Tempsmax"];
			if ( itempsmax ) then
				itemChamp:SetText(DBCS_HDV_heure_vers_string(DBCS_HDV_time_vers_heure(itempsmax-itimeecart)));
			else
				itemChamp:SetText(nil);
			end
			itemChamp = _G[buttonName.."_NB"];
			itemChamp:SetText(inb);
			itemChamp = _G[buttonName.."_PrixEnchereMoney"];
			if ( i10 == nil or i10 == 0 ) then
				itemChamp:Hide();
			else
				if ( i_un_seul == 1 ) then
					i10 = i10 / inb;
				end
				itemChamp:Show();
				DBCS_MoneyFrame_Update(itemChamp:GetName(), floor(i10+.5));
			end
			itemChamp = _G[buttonName.."_PrixAchatMoney"];
			if ( i09 == nil or i09 == 0 ) then
				itemChamp:Hide();
			else
				if ( i_un_seul == 1 ) then
					i09 = i09 / inb;
				end
				itemChamp:Show();
				DBCS_MoneyFrame_Update(itemChamp:GetName(), floor(i09+.5));
			end
			button:Show();
		end
	end

end

function DBcorps_ListHDV_Trier(sTRI,sINVERSER)

	--local t_ordre = {};
	local sSENS = DBCORPS_HDV_LISTE_sens;
	local sARROW = "DBcorpsFrame_HDVFrame_Tri_";

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

	_G[sARROW.."Rarity_Arrow"]:Hide();
	_G[sARROW.."Nomobjet_Arrow"]:Hide();
	_G[sARROW.."Nivmin_Arrow"]:Hide();
	_G[sARROW.."Niveau_Arrow"]:Hide();
	_G[sARROW.."Numobjet_Arrow"]:Hide();
	_G[sARROW.."Vendeur_Arrow"]:Hide();
	_G[sARROW.."Tempsrestant_Arrow"]:Hide();
	_G[sARROW.."PrixEnchere_Arrow"]:Hide();
	_G[sARROW.."PrixAchat_Arrow"]:Hide();
	
	DBCORPS_HDV_TRI = {};
	if ( sTRI == "rarity") then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Rarity_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Rarity_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Rarity_Arrow"]:Show();
		DBCORPS_HDV_TRI[1] = {};
		DBCORPS_HDV_TRI[1].champ = "rarity";
		DBCORPS_HDV_TRI[1].sens = sSENS;
		DBCORPS_HDV_TRI[2] = {};
		DBCORPS_HDV_TRI[2].champ = "nomobjet";
		DBCORPS_HDV_TRI[2].sens = "ASC";
		DBCORPS_HDV_TRI[3] = {};
		DBCORPS_HDV_TRI[3].champ = "prixachat";
		DBCORPS_HDV_TRI[3].sens = "ASC";
		DBCORPS_HDV_TRI[4] = {};
		DBCORPS_HDV_TRI[4].champ = "prixenchere";
		DBCORPS_HDV_TRI[4].sens = "ASC";
		DBCORPS_HDV_TRI[5] = {};
		DBCORPS_HDV_TRI[5].champ = "tempsrestant";
		DBCORPS_HDV_TRI[5].sens = "ASC";
	elseif ( sTRI == "nomobjet") then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Nomobjet_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Nomobjet_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Nomobjet_Arrow"]:Show();
		DBCORPS_HDV_TRI[1] = {};
		DBCORPS_HDV_TRI[1].champ = "nomobjet";
		DBCORPS_HDV_TRI[1].sens = sSENS;
		DBCORPS_HDV_TRI[2] = {};
		DBCORPS_HDV_TRI[2].champ = "rarity";
		DBCORPS_HDV_TRI[2].sens = "DESC";
		DBCORPS_HDV_TRI[3] = {};
		DBCORPS_HDV_TRI[3].champ = "prixachat";
		DBCORPS_HDV_TRI[3].sens = "ASC";
		DBCORPS_HDV_TRI[4] = {};
		DBCORPS_HDV_TRI[4].champ = "prixenchere";
		DBCORPS_HDV_TRI[4].sens = "ASC";
		DBCORPS_HDV_TRI[5] = {};
		DBCORPS_HDV_TRI[5].champ = "tempsrestant";
		DBCORPS_HDV_TRI[5].sens = "ASC";
	elseif ( sTRI == "nivmin" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Nivmin_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Nivmin_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Nivmin_Arrow"]:Show();
		DBCORPS_HDV_TRI[1] = {};
		DBCORPS_HDV_TRI[1].champ = "nivmin";
		DBCORPS_HDV_TRI[1].sens = sSENS;
		DBCORPS_HDV_TRI[2] = {};
		DBCORPS_HDV_TRI[2].champ = "rarity";
		DBCORPS_HDV_TRI[2].sens = "DESC";
		DBCORPS_HDV_TRI[3] = {};
		DBCORPS_HDV_TRI[3].champ = "nomobjet";
		DBCORPS_HDV_TRI[3].sens = "ASC";
		DBCORPS_HDV_TRI[4] = {};
		DBCORPS_HDV_TRI[4].champ = "prixachat";
		DBCORPS_HDV_TRI[4].sens = "ASC";
		DBCORPS_HDV_TRI[5] = {};
		DBCORPS_HDV_TRI[5].champ = "prixenchere";
		DBCORPS_HDV_TRI[5].sens = "ASC";
		DBCORPS_HDV_TRI[6] = {};
		DBCORPS_HDV_TRI[6].champ = "tempsrestant";
		DBCORPS_HDV_TRI[6].sens = "ASC";
	elseif ( sTRI == "niveau" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Niveau_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Niveau_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Niveau_Arrow"]:Show();
		DBCORPS_HDV_TRI[1] = {};
		DBCORPS_HDV_TRI[1].champ = "niveau";
		DBCORPS_HDV_TRI[1].sens = sSENS;
		DBCORPS_HDV_TRI[2] = {};
		DBCORPS_HDV_TRI[2].champ = "rarity";
		DBCORPS_HDV_TRI[2].sens = "DESC";
		DBCORPS_HDV_TRI[3] = {};
		DBCORPS_HDV_TRI[3].champ = "nomobjet";
		DBCORPS_HDV_TRI[3].sens = "ASC";
		DBCORPS_HDV_TRI[4] = {};
		DBCORPS_HDV_TRI[4].champ = "prixachat";
		DBCORPS_HDV_TRI[4].sens = "ASC";
		DBCORPS_HDV_TRI[5] = {};
		DBCORPS_HDV_TRI[5].champ = "prixenchere";
		DBCORPS_HDV_TRI[5].sens = "ASC";
		DBCORPS_HDV_TRI[6] = {};
		DBCORPS_HDV_TRI[6].champ = "tempsrestant";
		DBCORPS_HDV_TRI[6].sens = "ASC";
	elseif ( sTRI == "numobjet" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Numobjet_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Numobjet_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Numobjet_Arrow"]:Show();
		DBCORPS_HDV_TRI[1] = {};
		DBCORPS_HDV_TRI[1].champ = "tempsrestant";
		DBCORPS_HDV_TRI[1].sens = sSENS;
	elseif ( sTRI == "vendeur" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Vendeur_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Vendeur_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Vendeur_Arrow"]:Show();
		DBCORPS_HDV_TRI[1] = {};
		DBCORPS_HDV_TRI[1].champ = "vendeur";
		DBCORPS_HDV_TRI[1].sens = sSENS;
		DBCORPS_HDV_TRI[2] = {};
		DBCORPS_HDV_TRI[2].champ = "rarity";
		DBCORPS_HDV_TRI[2].sens = "DESC";
		DBCORPS_HDV_TRI[3] = {};
		DBCORPS_HDV_TRI[3].champ = "nomobjet";
		DBCORPS_HDV_TRI[3].sens = "ASC";
		DBCORPS_HDV_TRI[4] = {};
		DBCORPS_HDV_TRI[4].champ = "prixachat";
		DBCORPS_HDV_TRI[4].sens = "ASC";
		DBCORPS_HDV_TRI[5] = {};
		DBCORPS_HDV_TRI[5].champ = "prixenchere";
		DBCORPS_HDV_TRI[5].sens = "ASC";
		DBCORPS_HDV_TRI[6] = {};
		DBCORPS_HDV_TRI[6].champ = "tempsrestant";
		DBCORPS_HDV_TRI[6].sens = "ASC";
	elseif ( sTRI == "tempsrestant" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Tempsrestant_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Tempsrestant_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Tempsrestant_Arrow"]:Show();
		DBCORPS_HDV_TRI[1] = {};
		DBCORPS_HDV_TRI[1].champ = "tempsrestant";
		DBCORPS_HDV_TRI[1].sens = sSENS;
	elseif ( sTRI == "prixenchere" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."PrixEnchere_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."PrixEnchere_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."PrixEnchere_Arrow"]:Show();
		DBCORPS_HDV_TRI[1] = {};
		DBCORPS_HDV_TRI[1].champ = "prixenchere";
		DBCORPS_HDV_TRI[1].sens = sSENS;
		DBCORPS_HDV_TRI[2] = {};
		DBCORPS_HDV_TRI[2].champ = "prixachat";
		DBCORPS_HDV_TRI[2].sens = sSENS;
		DBCORPS_HDV_TRI[3] = {};
		DBCORPS_HDV_TRI[3].champ = "rarity";
		DBCORPS_HDV_TRI[3].sens = "DESC";
		DBCORPS_HDV_TRI[4] = {};
		DBCORPS_HDV_TRI[4].champ = "nomobjet";
		DBCORPS_HDV_TRI[4].sens = "ASC";
		DBCORPS_HDV_TRI[5] = {};
		DBCORPS_HDV_TRI[5].champ = "tempsrestant";
		DBCORPS_HDV_TRI[5].sens = "ASC";
	elseif ( sTRI == "prixachat" ) then
		if ( sSENS == "ASC" ) then
			_G[sARROW.."PrixAchat_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."PrixAchat_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."PrixAchat_Arrow"]:Show();
		DBCORPS_HDV_TRI[1] = {};
		DBCORPS_HDV_TRI[1].champ = "prixachat";
		DBCORPS_HDV_TRI[1].sens = sSENS;
		DBCORPS_HDV_TRI[2] = {};
		DBCORPS_HDV_TRI[2].champ = "prixenchere";
		DBCORPS_HDV_TRI[2].sens = sSENS;
		DBCORPS_HDV_TRI[3] = {};
		DBCORPS_HDV_TRI[3].champ = "rarity";
		DBCORPS_HDV_TRI[3].sens = "DESC";
		DBCORPS_HDV_TRI[4] = {};
		DBCORPS_HDV_TRI[4].champ = "nomobjet";
		DBCORPS_HDV_TRI[4].sens = "ASC";
		DBCORPS_HDV_TRI[5] = {};
		DBCORPS_HDV_TRI[5].champ = "tempsrestant";
		DBCORPS_HDV_TRI[5].sens = "ASC";
	else
		if ( sSENS == "ASC" ) then
			_G[sARROW.."Tempsrestant_Arrow"]:SetTexCoord(0, 0.5625, 0, 1.0);
		else
			_G[sARROW.."Tempsrestant_Arrow"]:SetTexCoord(0, 0.5625, 1.0, 0);
		end
		_G[sARROW.."Tempsrestant_Arrow"]:Show();
		DBCORPS_HDV_TRI[1] = {};
		DBCORPS_HDV_TRI[1].champ = "tempsrestant";
		DBCORPS_HDV_TRI[1].sens = sSENS;
	end

	table.sort(DBCORPS_HDV_LISTE,DBcorps_ListHDV_Trier_sort);

	DBCS_HDV_Scroll_Update();

end

function DBcorps_ListHDV_Trier_sort(elem1,elem2)

	return DBCS_HDV_Trier(elem1,elem2,DBCORPS_HDV_TRI,1);

end

function DBCS_HDV_Trier(HDV1,HDV2,t_ordre,niveaufonction)

local s_champ = t_ordre[niveaufonction].champ;
local s_sens = t_ordre[niveaufonction].sens;
local val1,val2;
local inum1;
local inum2;
local inumobjet1 = nil;
local inumobjet2 = nil;
local tablo1;
local tablo2;
local tenreg1 = {};
local tenreg2 = {};
local tobjet;

	inum1 = HDV1[1];
	if ( inum1 and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum1] ) then
		tenreg1 = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum1];
	end
	if ( tenreg1[21] == "i" ) then
		inumobjet1 = tenreg1[19];
	else
		inumobjet1 = 0;
	end
	tobjet = DBobjets_numobjet_tableau_lire(inumobjet1);
	if ( inumobjet1 and tobjet ) then
		tablo1 = tobjet;
	else
		tablo1 = {};
	end
	inum2 = HDV2[1];
	if ( inum2 and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum2] ) then
		tenreg2 = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum2];
	end
	if ( tenreg2[21] == "i" ) then
		inumobjet2 = tenreg2[19];
	else
		inumobjet2 = 0;
	end
	tobjet = DBobjets_numobjet_tableau_lire(inumobjet2);
	if ( inumobjet2 and tobjet ) then
		tablo2 = tobjet;
	else
		tablo2 = {};
	end

	if ( s_champ == "rarity") then
		val1 = tablo1[2];
		if ( val1 == nil ) then
			val1 = -1;
		end
		val2 = tablo2[2];
		if ( val2 == nil ) then
			val2 = -1;
		end
	elseif ( s_champ == "nomobjet" ) then
		val1 = tenreg1[1];
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = tenreg2[1];
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "nivmin") then
		val1 = tablo1[3];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = tablo2[3];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "niveau") then
		val1 = tablo1[11];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = tablo2[11];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "vendeur" ) then
		val1 = tenreg1[12];
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = tenreg2[12];
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "tempsrestant" ) then
		val1 = (HDV1[1] or 0);
		if ( HDV2 ) then
			val2 = (HDV2[1] or 0);
		else
			val2 = 0;
		end
	elseif ( s_champ == "prixenchere" ) then
		val1 = tenreg1[10];
		if ( val1 == nil ) then
			val1 = 0;
		else
			val1 = val1 / tenreg1[3];
		end
		if ( val1 == 0 ) then
			val1 = tenreg1[7];
			if ( val1 == nil ) then
				val1 = 0;
			else
				val1 = val1 / tenreg1[3];
			end
		end
		val2 = tenreg2[10];
		if ( val2 == nil ) then
			val2 = 0;
		else
			val2 = val2 / tenreg2[3];
		end
		if ( val2 == 0 ) then
			val2 = tenreg2[7];
			if ( val2 == nil ) then
				val2 = 0;
			else
				val2 = val2 / tenreg2[3];
			end
		end
	elseif ( s_champ == "prixachat" ) then
		val1 = tenreg1[9];
		if ( val1 == nil ) then
			val1 = 0;
		else
			val1 = val1 / tenreg1[3];
		end
		if ( val1 == 0 ) then
			val1 = tenreg1[10];
			if ( val1 == nil ) then
				val1 = 0;
			else
				val1 = val1 / tenreg1[3];
			end
			if ( val1 == 0 ) then
				val1 = tenreg1[7];
				if ( val1 == nil ) then
					val1 = 0;
				else
					val1 = val1 / tenreg1[3];
				end
			end
		end
		val2 = tenreg2[9];
		if ( val2 == nil ) then
			val2 = 0;
		else
			val2 = val2 / tenreg2[3];
		end
		if ( val2 == 0 ) then
			val2 = tenreg2[10];
			if ( val2 == nil ) then
				val2 = 0;
			else
				val2 = val2 / tenreg2[3];
			end
			if ( val2 == 0 ) then
				val2 = tenreg2[7];
				if ( val2 == nil ) then
					val2 = 0;
				else
					val2 = val2 / tenreg2[3];
				end
			end
		end
	else
		val1 = (HDV1[1] or 0);
		val2 = (HDV2[1] or 0);
	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 DBCS_HDV_Trier(HDV1,HDV2,t_ordre,niveaufonction+1);
		else
			return false;
		end
	else
		return false; -- pas normal d etre ici
	end

end

function DBcorps_ListHDV_Update()

local criteres = {};
local item_base = "DBcorpsFrame_HDVFrame_Criteres_";
local tablo;
local itemChamp;

	criteres.rarity = UIDropDownMenu_GetSelectedValue(DBcorpsFrame_HDVFrame_Criteres_Rarity);
	criteres.nomobjet = _G[item_base.."Nomobjet"]:GetText();
	criteres.nivmin = tonumber(_G[item_base.."Nivmin"]:GetText());
	criteres.nivmax = tonumber(_G[item_base.."Nivmax"]:GetText());
	criteres.type = UIDropDownMenu_GetSelectedValue(DBcorpsFrame_HDVFrame_Criteres_Type);
	criteres.subtype = UIDropDownMenu_GetSelectedValue(DBcorpsFrame_HDVFrame_Criteres_SubType);
	criteres.equiploc = UIDropDownMenu_GetSelectedValue(DBcorpsFrame_HDVFrame_Criteres_Equiploc);
	criteres.vendeur = _G[item_base.."Vendeur"]:GetText();
	criteres.utilisable = _G[item_base.."Utilisable"]:GetChecked();
	if ( criteres.utilisable == nil ) then
		criteres.utilisable = 0;
	end
	criteres.numobjet = DBCORPS_HDV_CRITERES_numobjet;
	itemChamp = _G["DBcorpsFrame_HDVFrame_Criteres_Item_IconTexture"];
	if ( DBCORPS_HDV_CRITERES_numobjet == nil ) then
		itemChamp:Hide();
	else
		tablo = DBOS_detail(DBCORPS_HDV_CRITERES_numobjet,"0:0:0:0:0:0:0:0:0:0");
		itemChamp:SetTexture("Interface/Icons/INV_Misc_QuestionMark");
		itemChamp:SetTexture(tablo.texture);
		itemChamp:Show();
	end

	DBCORPS_HDV_LISTE = {};
	DBCORPS_HDV_LISTE = DBCS_HDV_Liste(criteres);
	DBCORPS_HDV_LISTE_nb = table.getn(DBCORPS_HDV_LISTE);
	
	FauxScrollFrame_SetOffset(DBcorpsFrame_HDVFrame_Liste_ScrollFrame,0);
	
	DBcorpsFrame_HDVFrame_Liste_ScrollFrameScrollBar:SetValue(0);

	if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech] ) then
		_G["DBcorpsFrame_HDVFrame_Criteres_Elements"]:SetText(DBCORPS_HDV_LISTE_nb.." trouv\195\169s sur "..table.getn(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech]).." \195\169l\195\169ments.")
	else
		_G["DBcorpsFrame_HDVFrame_Criteres_Elements"]:SetText(DBCORPS_HDV_LISTE_nb.." trouv\195\169s sur 0 \195\169l\195\169ments.")
	end
	DBcorps_ListHDV_Trier();

end

function DBCS_HDV_Liste(criteres)

local tablo;
local i;
local j;
local ibon;
local inumobjet;
local tOBJET;
local ivaleur;
local tablo1;

	tablo = {};
	j = 0;

	--	DBCS_HDV_inumrech
	--	DBCS_HDV_tQueryAuctionItems
	if ( DBCS_HDV_tQueryAuctionItems and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech] ) then
		for i = 1 , table.getn(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech]) do
			if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][i] ) then
				ibon = 1;
				if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][i][21] == "i" ) then
					inumobjet = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][i][19];
					if ( type(inumobjet) == "number" ) then
						if ( inumobjet == 82800 ) then
							tOBJET = nil;
						else
							tOBJET = DBobjets_numobjet_tableau_lire(inumobjet);
						end
					else
						tOBJET = nil;
					end
				else
					tOBJET = nil;
				end
				if ( tOBJET ) then
--TraceFrame:AddMessage("DBcorpsFrame_HDVFrame_Criteres_Item_OnEnter inumobjet = "..inumobjet);
					if ( ibon == 1 and criteres.rarity > -1 ) then
						if ( tOBJET[2] and not ( tOBJET[2] >= criteres.rarity ) ) then
							ibon = 0;
						end
					end
					if ( ibon == 1 and criteres.nomobjet and not ( criteres.nomobjet == "" ) ) then
						if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][i][1] ) then
							ipos, _ = strfind(strlower(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][i][1]),strlower(criteres.nomobjet));
							if ( not ipos ) then
								ibon = 0;
							end
						else
							ibon = 0;
						end
					end
					if ( ibon == 1 and criteres.nivmin ) then
						if ( tOBJET[3] == nil or tOBJET[3] < criteres.nivmin ) then
							ibon = 0;
						end
					end
					if ( ibon == 1 and criteres.nivmax ) then
						if ( tOBJET[3] and tOBJET[3] > criteres.nivmax ) then
							ibon = 0;
						end
					end
					if ( ibon == 1 and criteres.type > -1 ) then
						ivaleur = DBCS_objet_type_index[tOBJET[4]];
						if ( ivaleur ) then
						else
							ivaleur = tOBJET[4];
						end
						if ( criteres.type == 0 ) then
							if ( DBCS_objet_type_name[ivaleur] ) then
								ibon = 0;
							end
						else
							if not ( DBCS_objet_type_name[ivaleur] == criteres.type ) then
								ibon = 0;
							end
						end
					end
					if ( ibon == 1 and criteres.subtype > -1 ) then
						ivaleur = DBCS_objet_subtype_index[tOBJET[5]];
						if ( ivaleur ) then
						else
							ivaleur = tOBJET[5];
						end
						if ( criteres.subtype == 0 ) then
							tablo1 = DBCS_objet_type_subtype_index[criteres.type];
							if ( tablo1 and tablo1[DBCS_objet_subtype_name[ivaleur]] ) then
								ibon = 0;
							end
							--if ( DBCS_objet_subtype_name[ivaleur] ) then
							--	ibon = 0;
							--end
						else
							if not ( DBCS_objet_subtype_name[ivaleur] == criteres.subtype ) then
								ibon = 0;
							end
						end
					end
					if ( ibon == 1 and criteres.equiploc > -1 ) then
						ivaleur = DBCS_objet_equiploc_index_name[tOBJET[7]];
						if ( ivaleur ) then
						else
							ivaleur = tOBJET[7];
						end
						if ( criteres.equiploc == 0 ) then
							if ( ivaleur == "" or DBCS_objet_equiploc_name[ivaleur] ) then
								ibon = 0;
							end
						else
							if not ( DBCS_objet_equiploc_name[ivaleur] == criteres.equiploc ) then
								ibon = 0;
							end
						end
					end
					if ( ibon == 1 and criteres.vendeur and not ( criteres.vendeur == "" ) ) then
						if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][i][12] ) then
							ipos, _ = strfind(strlower(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][i][12]),strlower(criteres.vendeur));
							if ( not ipos ) then
								ibon = 0;
							end
						else
							ibon = 0;
						end
					end
					if ( ibon == 1 and criteres.utilisable and criteres.utilisable == 1 ) then
						if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][i][5] ) then
						else
							ibon = 0;
						end
					end
					if ( ibon == 1 and criteres.numobjet ) then
						if ( inumobjet == criteres.numobjet ) then
						else
							ibon = 0;
						end
					end
				else
					ibon = 0;
				end
				if ( ibon == 1 ) then
					j = j + 1 ;
					tablo[j] = {};
					tablo[j][1] = i;
				end
			else
				j = j + 1 ;
				tablo[j] = {};
				tablo[j][1] = i;
			end
		end
	end
	return tablo;

end

function DBCS_HDV_time_vers_heure(itime)

local inbh;
local inbm;
local inbs;
local inbmilli;
local bnegatif;

	if ( itime < 0 ) then
		bnegatif = true;
		itime = itime * -1;
	else
		bnegatif = false;
	end
	inbh = floor( itime / 3600 );
	itime = itime - ( inbh * 3600 );
	inbm = floor( itime / 60 );
	itime = itime - ( inbm * 60 );
	inbs = floor( itime );
	itime = itime - ( inbs );
	inbmilli = itime;
	
	return bnegatif,inbh,inbm,inbs,inbmilli;

end

function DBCS_HDV_heure_vers_string(bnegatif,inbh,inbm,inbs,inbmilli)

local svaleur;

	svaleur = "";
	if ( bnegatif == true ) then
		svaleur = svaleur.."-";
	end
	if ( inbh < 10 ) then
		svaleur = svaleur.."0";
	end
	svaleur = svaleur..inbh.."h";
	if ( inbm < 10 ) then
		svaleur = svaleur.."0";
	end
	svaleur = svaleur..inbm.."m";
	if ( inbs < 10 ) then
		svaleur = svaleur.."0";
	end
	svaleur = svaleur..inbs.."s";
	
	return svaleur;

end

function DBcorps_ListHDV_Reset()

local item_base = "DBcorpsFrame_HDVFrame_Criteres_";
local itemChamp;

	DBcorpsFrame_HDVFrame_Criteres_Rarity_OnLoad();
	UIDropDownMenu_SetSelectedValue(DBcorpsFrame_HDVFrame_Criteres_Rarity,-1);
	_G[item_base.."Nomobjet"]:SetText("");
	_G[item_base.."Nivmin"]:SetText("");
	_G[item_base.."Nivmax"]:SetText("");
	DBcorpsFrame_HDVFrame_Criteres_Type_OnLoad();
	UIDropDownMenu_SetSelectedValue(DBcorpsFrame_HDVFrame_Criteres_Type,-1);
	DBcorpsFrame_HDVFrame_Criteres_SubType_OnLoad();
	UIDropDownMenu_SetSelectedValue(DBcorpsFrame_HDVFrame_Criteres_SubType,-1);
	DBcorpsFrame_HDVFrame_Criteres_Equiploc_OnLoad();
	UIDropDownMenu_SetSelectedValue(DBcorpsFrame_HDVFrame_Criteres_Equiploc,-1);
	_G[item_base.."Vendeur"]:SetText("");
	DBCORPS_HDV_CRITERES_numobjet = nil;
	itemChamp = _G["DBcorpsFrame_HDVFrame_Criteres_Item_IconTexture"];
	itemChamp:Hide();

end

function DBcorpsFrame_HDVFrame_Criteres_Item_OnEnter(self)

local link = nil;
local itemName;

	if ( DBCORPS_HDV_CRITERES_numobjet == nil ) then
	else
		link = "item:"..DBCORPS_HDV_CRITERES_numobjet..":0:0:0:0:0:0:0:0:0:0";
--TraceFrame:AddMessage("DBcorpsFrame_HDVFrame_Criteres_Item_OnEnter link = "..link);
		if ( link ) then
			GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
			itemName = GetItemInfo(link);
			if ( itemName ) then
				GameTooltip:SetHyperlink(link);
			else
				DBOS_SetHyperlink(DBCORPS_HDV_CRITERES_numobjet);
			end
		end
	end

end

function DBcorps_ListHDV_Item_OnEnter(self,index)

local inum = nil;
local link = nil;
local itemName;

	GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
	if ( DBCORPS_HDV_LISTE and DBCORPS_HDV_LISTE[index] and DBCORPS_HDV_LISTE[index][1] ) then
		inum = DBCORPS_HDV_LISTE[index][1];
	end
	if ( inum and DBCS_HDV_tQueryAuctionItems and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][19] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][20] ) then
		if ( DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][21] == "i" ) then
			link = "item:"..DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][19]..":"..DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][20];
		else
			link = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][14];
		end
	end
	if ( link ) then
		itemName = GetItemInfo(link);
		if ( itemName ) then
			GameTooltip:SetHyperlink(link);
		else
			DBOS_SetHyperlink(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][19]);
		end
	end

end

function DBcorpsFrame_HDVFrame_Criteres_Item_OnClick(self,button)

local link = nil;
local itemName, itemLink;
local tablo;
local activewindow;

	if ( DBCORPS_HDV_CRITERES_numobjet == nil ) then
	else
		if ( ChatEdit_GetActiveWindow ) then
			activewindow = ChatEdit_GetActiveWindow();
		else
			activewindow = ChatFrameEditBox;
		end
		link = "item:"..DBCORPS_HDV_CRITERES_numobjet..":0:0:0:0:0:0:0:0:0:0";
		itemName, itemLink, _, _, _, _, _, _, _, _ = GetItemInfo(link);
		if ( itemName ) then
			if( button == "LeftButton" ) then
				if ( IsShiftKeyDown() and activewindow and activewindow:IsVisible() ) then
					activewindow:Insert(itemLink);
				elseif ( IsControlKeyDown() ) then
					DressUpItemLink(link);
				end
			elseif( button == "RightButton" ) then
			end
		else
			if ( button == "LeftButton" ) then
				if ( IsShiftKeyDown() and activewindow and activewindow:IsVisible() ) then
					tablo = DBOS_detail(DBCORPS_HDV_CRITERES_numobjet,"0:0:0:0:0:0:0:0:0:0");
					if ( tablo and tablo.nomobjet ) then
						activewindow:Insert(tablo.nomobjet);
					end
				end
			end
		end
	end

end

function DBcorps_ListHDV_Item_OnClick(self,button)

local index = self:GetParent():GetID() + FauxScrollFrame_GetOffset(DBcorpsFrame_HDVFrame_Liste_ScrollFrame);
local inum = nil;
local link = nil;
local itemName, itemLink;
local tablo;
local activewindow;

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

	if ( DBCORPS_HDV_LISTE and DBCORPS_HDV_LISTE[index] and DBCORPS_HDV_LISTE[index][1] ) then
		inum = DBCORPS_HDV_LISTE[index][1];
	end
	if ( inum and DBCS_HDV_tQueryAuctionItems and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][19] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][20] ) then
		link = "item:"..DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][19]..":"..DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][20];
	end
	if ( link ) then
		itemName, itemLink, _, _, _, _, _, _, _, _ = GetItemInfo(link);
		if ( itemName ) then
			if( button == "LeftButton" ) then
				if ( IsShiftKeyDown() and activewindow and activewindow:IsVisible() ) then
					activewindow:Insert(itemLink);
				elseif ( IsControlKeyDown() ) then
					DressUpItemLink(link);
				end
			elseif( button == "RightButton" ) then
			end
		else
			if ( button == "LeftButton" ) then
				if ( IsShiftKeyDown() and activewindow and activewindow:IsVisible() ) then
					tablo = DBOS_detail(DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][19],DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][20]);
					if ( tablo and tablo.nomobjet ) then
						activewindow:Insert(tablo.nomobjet);
					end
				end
			end
		end
	end

end

function DBcorps_ListHDV_Scan_debut()

local snumregion;

	snumregion = DBCS_numregionbyname(GetRealZoneText());
	if ( snumregion == "" ) then
	elseif ( snumregion == "104" ) then	-- darnassus
		DBCS_HDV_faction = 1;
	elseif ( snumregion == "125" ) then	-- exodar
		DBCS_HDV_faction = 1;
	elseif ( snumregion == "212" ) then	-- forgefer
		DBCS_HDV_faction = 1;
	elseif ( snumregion == "217" ) then	-- hurlevent
		DBCS_HDV_faction = 1;
	elseif ( snumregion == "119" ) then	-- pitons du tonnerre
		DBCS_HDV_faction = 2;
	elseif ( snumregion == "112" ) then	-- orgrimmar
		DBCS_HDV_faction = 2;
	elseif ( snumregion == "222" ) then	-- fossoyeuse
		DBCS_HDV_faction = 2;
	elseif ( snumregion == "230" ) then	-- lune d'argent
		DBCS_HDV_faction = 2;
	elseif ( snumregion == "117" ) then	-- les tarides
		DBCS_HDV_faction = 0;
	elseif ( snumregion == "115" ) then	-- tanaris
		DBCS_HDV_faction = 0;
	elseif ( snumregion == "218" ) then -- vallée de strangleronce
		DBCS_HDV_faction = 0;
	end

	DBcorpsFrame_HDVFrame_Criteres_SCAN:Hide();
	DBcorpsFrame_HDVFrame_Criteres_Bar:SetValue(0);
	DBcorpsFrame_HDVFrame_Criteres_Bar:Show();
	DBcorpsFrame_HDV_stats_Frame_Criteres_Bar:SetValue(0);
	DBcorpsFrame_HDV_stats_Frame_Criteres_Bar:Show();
	DBcorpsFrame_HDVFrame_Criteres_STOP:Show();
	DBCS_HDV_etape = 0;
	DBCS_HDV_toutlire();

end

function DBcorps_ListHDV_Scan_fin()

	DBcorpsFrame_HDVFrame_Criteres_STOP:Hide();
	DBcorpsFrame_HDVFrame_Criteres_Bar:Hide();
	DBcorpsFrame_HDVFrame_Criteres_Bar:SetValue(0);
	DBcorpsFrame_HDV_stats_Frame_Criteres_Bar:Hide();
	DBcorpsFrame_HDV_stats_Frame_Criteres_Bar:SetValue(0);
	DBcorpsFrame_HDVFrame_Criteres_SCAN:Show();
	DBCS_HDV_AUCTION_ITEM_LIST_UPDATE_time = 0;
	DBCS_HDV_etape = 0;

end

function DBcorps_ListHDV_Select(self)

local i;
local inum = nil;
local inumobjet = nil;

	i = self:GetID() + FauxScrollFrame_GetOffset(DBcorpsFrame_HDVFrame_Liste_ScrollFrame);
	if ( DBCORPS_HDV_LISTE and DBCORPS_HDV_LISTE[i] and DBCORPS_HDV_LISTE[i][1] ) then
		inum = DBCORPS_HDV_LISTE[i][1];
	end
	if ( inum and DBCS_HDV_tQueryAuctionItems and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][19] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][20] ) then
		inumobjet = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][19];
	end
	if ( inumobjet and IsControlKeyDown() and IsAltKeyDown() ) then
		DBcorps_AfficherObjet(inumobjet,"0:0:0:0:0:0:0:0:0:0");
	else
		--DBcorps_ListHDV_Reset();
		--DBCORPS_HDV_CRITERES_numobjet = inumobjet;
		--DBcorps_ListHDV_Update();
		--if ( DBCORPS_HDV_LISTE_nb > 0 ) then
		--	PanelTemplates_SetTab(DBcorpsFrame, 9);
		--	DBcorps_ShowSubFrame(9);
		--else
		--	PlaySound("igQuestFailed");
		--end
	end

end

--/script DBCS_HDV_AuctionFrameBrowse_Reset();
function DBCS_HDV_AuctionFrameBrowse_Reset()

	BrowseName:SetText("");
	BrowseMinLevel:SetText("");
	BrowseMaxLevel:SetText("");
	IsUsableCheckButton:SetChecked(0);
	UIDropDownMenu_SetSelectedValue(BrowseDropDown,-1);

	-- reset the filters
	OPEN_FILTER_LIST = {};
	AuctionFrameBrowse.selectedClass = nil;
	AuctionFrameBrowse.selectedClassIndex = nil;
	AuctionFrameBrowse.selectedSubclass = nil;
	AuctionFrameBrowse.selectedSubclassIndex = nil;
	AuctionFrameBrowse.selectedInvtype = nil;
	AuctionFrameBrowse.selectedInvtypeIndex = nil;

	AuctionFrameFilters_Update();
	BrowseResetButton:Disable();

end

--/script DBCS_HDV_afficher_Auction("oeil de nuit");
function DBCS_HDV_afficher_Auction(snomobjet)

	DBCS_HDV_AuctionFrameBrowse_Reset();

	DBcorps_ListHDV_Scan_fin();

	BrowseName:SetText(snomobjet);

	AuctionFrameBrowse_Search();
	SortAuctionItems("list", "quality");
	SortAuctionItems("list", "bid");

end

--/script i = 0;
--/script i = i +1;DEFAULT_CHAT_FRAME:AddMessage(GetMacroIconInfo(i));
--/script i = 26;DEFAULT_CHAT_FRAME:AddMessage(GetMacroIconInfo(i));

--interface/icons/ability_druid_balanceofpower

function DBCS_HDV_afficher_Auction_HDV(self)

local i = self:GetParent():GetID();
local inum;
local inumobjet = nil;
local snomobjet;
local tobjet;

	i = i + FauxScrollFrame_GetOffset(DBcorpsFrame_HDVFrame_Liste_ScrollFrame);
	if ( DBCORPS_HDV_LISTE and DBCORPS_HDV_LISTE[i] and DBCORPS_HDV_LISTE[i][1] ) then
		inum = DBCORPS_HDV_LISTE[i][1];
	end
	if ( inum and DBCS_HDV_tQueryAuctionItems and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][19] and DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][20] ) then
		inumobjet = DBCS_HDV_tQueryAuctionItems[DBCS_HDV_inumrech][inum][19];
	end
	if ( inumobjet and DBOS01 and DBOS02 ) then
		tobjet = DBobjets_numobjet_tableau_lire(inumobjet);
		if ( tobjet ) then
			snomobjet = tobjet[1];
			DBCS_HDV_afficher_Auction(snomobjet);
		end
	end

end

function DBCS_HDV_Auction_OnEnter(self)

	GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT");
	--GameTooltip:AddLine("Acc\195\168s aux occurrences de cet objet pour en acheter");
	GameTooltip:AddLine("Acc\195\168s \195\160 l'HDV pour cet objet");
	GameTooltip:Show();

end

--			MoneyInputFrame_SetCopper(StartPrice, max(100, floor(price * 1.5)));
--			MoneyInputFrame_SetCopper(BuyoutPrice, 0);

--local Saved_DBCS_HDV_AuctionsFrameAuctions_ValidateAuction = AuctionsFrameAuctions_ValidateAuction;
--function DBCS_HDV_AuctionsFrameAuctions_ValidateAuction()
--
--	Saved_DBCS_HDV_AuctionsFrameAuctions_ValidateAuction();
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBCS_HDV_AuctionsFrameAuctions_ValidateAuction");
--end
--
--end
--AuctionsFrameAuctions_ValidateAuction = DBCS_HDV_AuctionsFrameAuctions_ValidateAuction;
