class WorldExchangeRegiWnd extends UICommonAPI;

const MAXRegiItemNum = 10;
const MINRegiBundlePrice = 10;
const ADENA_CLASSID = 57;
const LCOIN_CLASSID = 91663;
const MAXITEMNUM = 1000;
const INSERT_ONCE_LIST_NUM = 10;
const LOAD_ONCE_LIST_NUM = 100;
const REFRESHLIMIT = 1000;
const REFRESHLIMITMIN = 500;

enum E_WORLD_EXCHANGE_SORT_TYPE 
{
	EWEST_NONE,
	EWEST_ITEM_NAME,
	EWEST_ENCHANT_ASCE,
	EWEST_ENCHANT_DESC,
	EWEST_PRICE_ASCE,
	EWEST_PRICE_DESC,
	EWEST_AMOUNT_ASCE,
	EWEST_AMOUNT_DESC,
	EWEST_PRICE_PER_PIECE_ASCE,
	EWEST_PRICE_PER_PIECE_DESC
};

var int refreshMinCount;
var int lastLoadedPage;
var int nMaxPage;
var bool bRQ_C_EX_WORLD_EXCHANGE_ITEM_LIST;
var bool bRQ_C_EX_WORLD_EXCHANGE_AVERAGE_PRICE;
var array<UIPacket._WorldExchangeItemData> _itemDatas;
var WindowHandle FindDisable_Wnd;
var WindowHandle WindowDisable_Wnd;
var L2UITimerObject tObject;
var L2UITimerObject tObjectListAdd;
var RichListCtrlHandle ExchangeFind_RichList;
var ItemInfo sellItemInfo;
var ItemInfo readySellItemInfo;
var int scrollPos;
var int _regieditemNum;
var int sortHeaderIndex;
var float nAveragePrice;
var UIControlNumberInput itemSell_NumberInputScr;
var UIControlNumberInput bundlePrice_NumberInputScr;
var WorldExchangeRegiWndItemHistoryTabWnd historyScr;

static function WorldExchangeRegiWnd Inst()
{
	return WorldExchangeRegiWnd(GetScript("WorldExchangeRegiWnd"));
}

event OnRegisterEvent()
{
	RegisterEvent(EV_PacketID(class'UIPacket'.const.S_EX_WORLD_EXCHANGE_ITEM_LIST));
	RegisterEvent(EV_PacketID(class'UIPacket'.const.S_EX_WORLD_EXCHANGE_REGI_ITEM));
	RegisterEvent(EV_PacketID(class'UIPacket'.const.S_EX_WORLD_EXCHANGE_AVERAGE_PRICE));
}

event OnLoad()
{
	SetClosingOnESC();
	ExchangeFind_RichList = GetRichListCtrlHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ExchangeFind_RichList");
	ExchangeFind_RichList.SetSelectedSelTooltip(false);
	ExchangeFind_RichList.SetAppearTooltipAtMouseX(true);
	ExchangeFind_RichList.SetSortable(false);
	itemSell_NumberInputScr = class'UIControlNumberInput'.static.InitScript(GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.ItemSell_NumberInput"));
	bundlePrice_NumberInputScr = class'UIControlNumberInput'.static.InitScript(GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.BundlePrice_NumberInput"));
	bundlePrice_NumberInputScr._SetMinCountCanBuy(0);
	itemSell_NumberInputScr.DelegateGetCountCanBuy = DelegateGetCanSellItemNum;
	bundlePrice_NumberInputScr.DelegateGetCountCanBuy = GetCanLcoinPriceItemNum;
	itemSell_NumberInputScr.DelegateOnClickInput = HandleOnItemCountEditBtonClicked;
	bundlePrice_NumberInputScr.DelegateOnClickInput = HandleOnPriceCountEditBtonClicked;
	itemSell_NumberInputScr._SetUseCaculator(true);
	bundlePrice_NumberInputScr._SetUseCaculator(true);
	itemSell_NumberInputScr._SetForceDisable(true);
	bundlePrice_NumberInputScr._SetForceDisable(true);
	itemSell_NumberInputScr.DelegateESCKey = OnReceivedCloseUI;
	bundlePrice_NumberInputScr.DelegateESCKey = OnReceivedCloseUI;
	itemSell_NumberInputScr.DelegateOnItemCountEdited = HandleOnitemCountEdited;
	bundlePrice_NumberInputScr.DelegateOnItemCountEdited = HandleOnPriceCountEdited;
	bundlePrice_NumberInputScr.DelegateOnOverInput = HandleOnOverInput;
	AddItemListenerSimple(57, 0, 57).DelegateOnUpdateItem = HandleMyItemChanged;
	AddItemListenerSimple(91663, 0, 91663).DelegateOnUpdateItem = HandleMyItemChanged;
	tObject = class'L2UITimer'.static.Inst()._AddNewTimerObject(1000);
	tObject._DelegateOnEnd = SetEnableRefresh;
	SetTimerObject();
	SetScriptHistory();
	FindDisable_Wnd = GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.FindDisable_Wnd");
	FindDisable_Wnd.ShowWindow();
	WindowDisable_Wnd = GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".WindowDisable_Wnd");
	Get_MyAdenaCount_Txt().SetText("0" @ GetSystemString(469));
	Get_MyLcoinCount_Txt().SetText("0" @ GetSystemString(3931));
	GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.SellTime_txt").SetText("-");
	SetSortType(E_WORLD_EXCHANGE_SORT_TYPE.EWEST_PRICE_PER_PIECE_ASCE/*8*/);
}

function SetTimerObject()
{
	local int Time, Count;

	Count = 100 / 10;
	Time = 1000 / Count;
	tObjectListAdd = class'L2UITimer'.static.Inst()._AddNewTimerObject(Time, Count);
	tObjectListAdd._DelegateOnStart = TInsertRecord;
	tObjectListAdd._DelegateOnTime = TInsertRecordOnTime;
	tObjectListAdd._DelegateOnEnd = TInserDelayCheck;
	refreshMinCount = 500 / Time;	
}

function SetScriptHistory()
{
	local WindowHandle historyWnd;

	historyWnd = GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".ItemHistoryTabWnd");
	historyWnd.SetScript("WorldExchangeRegiWndItemHistoryTabWnd");
	historyScr = WorldExchangeRegiWndItemHistoryTabWnd(historyWnd.GetScript());
	historyScr.m_hOwnerWnd = historyWnd;
}

event OnEvent(int EventID, string param)
{
	switch(EventID)
	{
		case EV_PacketID(class'UIPacket'.const.S_EX_WORLD_EXCHANGE_ITEM_LIST):
			RT_S_EX_WORLD_EXCHANGE_ITEM_LIST();
			break;
		case EV_PacketID(class'UIPacket'.const.S_EX_WORLD_EXCHANGE_REGI_ITEM):
			RT_S_EX_WORLD_EXCHANGE_REGI_ITEM();
			break;
		case EV_PacketID(class'UIPacket'.const.S_EX_WORLD_EXCHANGE_AVERAGE_PRICE):
			RT_S_EX_WORLD_EXCHANGE_AVERAGE_PRICE();
			break;
	}
}

event OnScrollMove(string strID, int pos)
{
	switch(strID)
	{
		case "ExchangeFind_RichList":
			HandleScrollMove(pos);
			break;
	}
}

event OnShow()
{
	SetMyInfos();
	historyScr.RQ_C_EX_WORLD_EXCHANGE_SETTLE_LIST();
	CheckWorldExchangeRegiSubWnd();
	class'WorldExchangeBuyWnd'.static.Inst()._Hide();
	getInstanceL2Util().ItemRelationWindowHide(getCurrentWindowName(string(self)));
	DelItemInfo();
	GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".ItemRegiDialog_Wnd.Dialog_Wnd.TaxRateTitle_txt").SetText(GetSystemString(1608) $ ":" @ string(API_GetWorldExchangeData().SellFee) $ "%");
	GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.TaxRateTitle_txt").SetText(GetSystemString(1608) $ ":" @ string(API_GetWorldExchangeData().SellFee) $ "%");
	if(bRQ_C_EX_WORLD_EXCHANGE_ITEM_LIST)
	{
		tObjectListAdd._Reset();
		tObject._Reset();
	}
	SetHideSellDialogWindow();
	if(getInstanceUIData().getIsLiveServer())
	{
		SideBar(GetScript("SideBar")).ToggleByWindowName("WorldExchangeBuyWnd", true);
	}	
}

event OnHide()
{
	if((DialogIsMine()) && class'DialogBox'.static.Inst().m_hOwnerWnd.IsShowWindow())
	{
		DialogHide();
	}
	if(getInstanceUIData().getIsLiveServer())
	{
		SideBar(GetScript("SideBar")).ToggleByWindowName("WorldExchangeBuyWnd", false);
	}	
}

event OnClickButton(string strID)
{
	switch(strID)
	{
		case "GetReward_Btn":
			HandleGetRewardBtn();
			break;
		case "WndClose_BTN":
			_Hide();
			break;
		case "Refresh_btn":
			HandleRefresh();
			break;
		case "MoveWnd_Btn":
			handleSwap();
			break;
		case "Cancel_Btn":
			SetHideSellDialogWindow();
			break;
		case "Ok_Btn":
			HandleClickOK_Btn();
			break;
		case "Cancel_Ok_Btn":
			HandleCancelOK();
			break;
		case "Cancel_Cancel_Btn":
			HandleCancelCancel();
			break;
		case "RegiList_Tab0":
		case "RegiList_Tab1":
			CheckWorldExchangeRegiSubWnd();
			break;
	}
}

event OnDBClickItemWithHandle(ItemWindowHandle a_hItemWindow, int a_Index)
{
	local ItemInfo iInfo;

	if(a_hItemWindow.GetParentWindowName() == "Dialog_Wnd")
	{
		return;
	}
	a_hItemWindow.GetItem(a_Index, iInfo);
	ItemDrop(iInfo);
}

event OnRClickItemWithHandle(ItemWindowHandle a_hItemWindow, int a_Index)
{
	local ItemInfo iInfo;

	if(a_hItemWindow.GetParentWindowName() == "Dialog_Wnd")
	{
		return;
	}
	a_hItemWindow.GetItem(a_Index, iInfo);
	ItemDrop(iInfo);
}

event OnDropItemSource(string strTarget, ItemInfo Info)
{
	if(bRQ_C_EX_WORLD_EXCHANGE_ITEM_LIST)
	{
		return;
	}
	if(strTarget == "Item_ItemWnd")
	{
		return;
	}
	if(Info.DragSrcName != "Item_ItemWnd")
	{
		return;
	}
	ItemDrop(Info);
}

function ItemDrop(ItemInfo Info)
{
	if(class'InputAPI'.static.IsAltPressed() || ! IsStackableItem(Info.ConsumeType) || Info.ItemNum == 1)
	{
		DelItemInfo();		
	}
	else
	{
		if(IsAdena(Info.Id))
		{
			class'DialogBox'.static.Inst().SetDefaultAction(EDefaultOK);
			DialogShow(DialogModalType_Modalless, DialogType_NumberPadAdena, MakeFullSystemMsg(GetSystemMessage(1833), sellItemInfo.Name, ""), string(self));
			class'DialogBox'.static.Inst().AnchorToOwner();
			class'DialogBox'.static.Inst().DelegateOnOK = HandleDialogOKSource;
			DialogSetInputlimit(Min64(sellItemInfo.ItemNum / class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT, class'WorldExchangeBuyWnd'.static.Inst().ADENA_MAX / class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT));
			DialogSetParamInt64(Min64(sellItemInfo.ItemNum / class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT, class'WorldExchangeBuyWnd'.static.Inst().ADENA_MAX / class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT));			
		}
		else
		{
			class'DialogBox'.static.Inst().SetDefaultAction(EDefaultOK);
			DialogShow(DialogModalType_Modalless, DialogType_NumberPad, MakeFullSystemMsg(GetSystemMessage(1833), sellItemInfo.Name, ""), string(self));
			class'DialogBox'.static.Inst().AnchorToOwner();
			class'DialogBox'.static.Inst().DelegateOnOK = HandleDialogOKSource;
			DialogSetInputlimit(sellItemInfo.ItemNum);
			DialogSetParamInt64(sellItemInfo.ItemNum);
		}
	}
}

event OnDropItem(string strTarget, ItemInfo iInfo, int X, int Y)
{
	if(bRQ_C_EX_WORLD_EXCHANGE_ITEM_LIST)
	{
		return;
	}
	if(_regieditemNum == 10)
	{
		getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(13688));
		return;
	}
	if(iInfo.DragSrcName != "itemEnchantSubWndItemWnd")
	{
		return;
	}
	if(class'InputAPI'.static.IsAltPressed() || ! IsStackableItem(iInfo.ConsumeType) || iInfo.ItemNum == 1)
	{
		SetSortType(E_WORLD_EXCHANGE_SORT_TYPE.EWEST_PRICE_PER_PIECE_ASCE/*8*/);
		sellItemInfo = iInfo;
		sellItemInfo.ItemNum = GetSellItemInfoNum(iInfo.Id.ServerID);
		SetItemInfo();
		RQ_C_EX_WORLD_EXCHANGE_AVERAGE_PRICE();		
	}
	else
	{
		readySellItemInfo = iInfo;
		class'DialogBox'.static.Inst().SetDefaultAction(EDefaultOK);
		if(IsAdena(iInfo.Id))
		{
			if(iInfo.ItemNum < class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT)
			{
				getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(13750));
				return;
			}
			if(class'WorldExchangeBuyWnd'.static.Inst()._IsNewServer())
			{
				DialogShow(DialogModalType_Modalless, DialogType_NumberPadAdena, GetSystemString(14423), string(self));				
			}
			else
			{
				DialogShow(DialogModalType_Modalless, DialogType_NumberPadAdena, GetSystemString(14193), string(self));
			}
			DialogSetInputlimit(Min64(iInfo.ItemNum / class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT, class'WorldExchangeBuyWnd'.static.Inst().ADENA_MAX / class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT));
			DialogSetParamInt64(Min64(iInfo.ItemNum / class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT, class'WorldExchangeBuyWnd'.static.Inst().ADENA_MAX / class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT));			
		}
		else
		{
			DialogShow(DialogModalType_Modalless, DialogType_NumberPad, MakeFullSystemMsg(GetSystemMessage(72), iInfo.Name, ""), string(self));
			DialogSetInputlimit(Min64(1000, iInfo.ItemNum));
			DialogSetParamInt64(Min64(1000, iInfo.ItemNum));
		}
		class'DialogBox'.static.Inst().AnchorToOwner();
		class'DialogBox'.static.Inst().DelegateOnOK = HandleDialogOKDrop;
	}
}

event OnClickHeaderCtrl(string strID, int Index)
{
	if(bRQ_C_EX_WORLD_EXCHANGE_ITEM_LIST)
	{
		return;
	}
	SetSortByHeaderIndex(Index);
	RQ_C_EX_WORLD_EXCHANGE_ITEM_LIST();
}

function WorldExchangeUIData API_GetWorldExchangeData()
{
	return GetWorldExchangeData();
}

function int API_GetServerPrivateStoreSearchItemSubType(int a_ClassID)
{
	return GetServerPrivateStoreSearchItemSubType(a_ClassID);
}

function RQ_C_EX_WORLD_EXCHANGE_ITEM_LIST(optional int Page)
{
	local array<byte> stream;
	local UIPacket._C_EX_WORLD_EXCHANGE_ITEM_LIST packet;

	if(bRQ_C_EX_WORLD_EXCHANGE_ITEM_LIST)
	{
		return;
	}
	if(_itemDatas.Length > 0)
	{
		return;
	}
	if(Page > 0)
	{
		if(nMaxPage < Page)
		{
			return;
		}
	}
	if(IsAdena(sellItemInfo.Id))
	{
		if(class'WorldExchangeBuyWnd'.static.Inst()._IsNewServer())
		{
			ExchangeFind_RichList.SetColumnString(2, 14424);
		}
		else
		{
			ExchangeFind_RichList.SetColumnString(2, 14192);
		}
		bundlePrice_NumberInputScr.SetCount(bundlePrice_NumberInputScr.GetCount());		
	}
	else
	{
		ExchangeFind_RichList.SetColumnString(2, 2511);
	}
	SetDisablbRefresh();
	lastLoadedPage = Page;
	packet.nCategory = API_GetServerPrivateStoreSearchItemSubType(sellItemInfo.Id.ClassID);
	packet.cSortType = GetSortType();
	packet.nPage = Page;
	packet.vItemIDList[0] = sellItemInfo.Id.ClassID;
	if(! class'UIPacket'.static.Encode_C_EX_WORLD_EXCHANGE_ITEM_LIST(stream, packet))
	{
		return;
	}
	class'UIPacket'.static.RequestUIPacket(class'UIPacket'.const.C_EX_WORLD_EXCHANGE_ITEM_LIST, stream);
}

function RT_S_EX_WORLD_EXCHANGE_ITEM_LIST()
{
	local UIPacket._S_EX_WORLD_EXCHANGE_ITEM_LIST packet;

	if(! m_hOwnerWnd.IsShowWindow())
	{
		return;
	}
	if(! class'UIPacket'.static.Decode_S_EX_WORLD_EXCHANGE_ITEM_LIST(packet))
	{
		return;
	}
	Debug("Handle_S_EX_WORLD_EXCHANGE_ITEM_LIST" @ string(_itemDatas.Length));
	if(lastLoadedPage == 0)
	{
		_itemDatas.Length = 0;
		ExchangeFind_RichList.DeleteAllItem();
		FindDisable_Wnd.ShowWindow();
		nMaxPage = 0;
	}
	if(packet.vItemDataList.Length == 100)
	{
		++ nMaxPage;		
	}
	else
	{
		nMaxPage = lastLoadedPage;
	}
	Handle_S_EX_WORLD_EXCHANGE_ITEM_LIST(packet);
}

function Handle_S_EX_WORLD_EXCHANGE_ITEM_LIST(UIPacket._S_EX_WORLD_EXCHANGE_ITEM_LIST packet)
{
	local int i;

	tObjectListAdd._Reset();
	if(packet.vItemDataList.Length == 0)
	{
		SetEnableRefresh();
		return;
	}
	FindDisable_Wnd.HideWindow();

	for(i = 0; i < packet.vItemDataList.Length; i++)
	{
		_itemDatas[_itemDatas.Length] = packet.vItemDataList[i];
	}
}

function RQ_C_EX_WORLD_EXCHANGE_REGI_ITEM()
{
	local array<byte> stream;
	local UIPacket._C_EX_WORLD_EXCHANGE_REGI_ITEM packet;

	packet.nItemSid = sellItemInfo.Id.ServerID;
	packet.nAmount = itemSell_NumberInputScr.GetCount();
	packet.nPrice = bundlePrice_NumberInputScr.GetCount();
	if(! class'UIPacket'.static.Encode_C_EX_WORLD_EXCHANGE_REGI_ITEM(stream, packet))
	{
		return;
	}
	Debug("RQ_C_EX_WORLD_EXCHANGE_REGI_ITEM" @ string(packet.nItemSid) @ string(packet.nAmount) @ string(packet.nPrice));
	class'UIPacket'.static.RequestUIPacket(class'UIPacket'.const.C_EX_WORLD_EXCHANGE_REGI_ITEM, stream);
}

private function RT_S_EX_WORLD_EXCHANGE_REGI_ITEM()
{
	local UIPacket._S_EX_WORLD_EXCHANGE_REGI_ITEM packet;

	if(! class'UIPacket'.static.Decode_S_EX_WORLD_EXCHANGE_REGI_ITEM(packet))
	{
		return;
	}
	if(packet.cSuccess == 1)
	{
		DelItemInfo();
		historyScr.RQ_C_EX_WORLD_EXCHANGE_SETTLE_LIST();		
	}
	else
	{
		getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(4334));
	}
}

private function RQ_C_EX_WORLD_EXCHANGE_AVERAGE_PRICE()
{
	local array<byte> stream;
	local UIPacket._C_EX_WORLD_EXCHANGE_AVERAGE_PRICE packet;

	nAveragePrice = 0.0f;
	packet.nItemID = sellItemInfo.Id.ClassID;
	if(! class'UIPacket'.static.Encode_C_EX_WORLD_EXCHANGE_AVERAGE_PRICE(stream, packet))
	{
		return;
	}
	Debug("RQ_C_EX_WORLD_EXCHANGE_AVERAGE_PRICE" @ string(packet.nItemID));
	class'UIPacket'.static.RequestUIPacket(class'UIPacket'.const.C_EX_WORLD_EXCHANGE_AVERAGE_PRICE, stream);
	bRQ_C_EX_WORLD_EXCHANGE_AVERAGE_PRICE = true;	
}

private function RT_S_EX_WORLD_EXCHANGE_AVERAGE_PRICE()
{
	local UIPacket._S_EX_WORLD_EXCHANGE_AVERAGE_PRICE packet;

	bRQ_C_EX_WORLD_EXCHANGE_AVERAGE_PRICE = false;
	if(! class'UIPacket'.static.Decode_S_EX_WORLD_EXCHANGE_AVERAGE_PRICE(packet))
	{
		return;
	}
	Debug("RT_S_EX_WORLD_EXCHANGE_AVERAGE_PRICE" @ string(packet.nItemID) @ string(sellItemInfo.Id.ClassID) @ string(packet.nAveragePrice));
	if(packet.nItemID == sellItemInfo.Id.ClassID)
	{
		nAveragePrice = float(packet.nAveragePrice) / 100;
	}	
}

function _ShowDisableWIndow()
{
	WindowDisable_Wnd.ShowWindow();
	WindowDisable_Wnd.SetFocus();
}

function _HideDisableWindow()
{
	WindowDisable_Wnd.HideWindow();
}

function SetDisablbRefresh()
{
	bRQ_C_EX_WORLD_EXCHANGE_ITEM_LIST = true;
	_ShowDisableWIndow();
	tObject._Reset();
}

function SetEnableRefresh()
{
	bRQ_C_EX_WORLD_EXCHANGE_ITEM_LIST = false;
	WindowDisable_Wnd.HideWindow();
}

function SetItemInfo()
{
	local ItemWindowHandle Item_ItemWnd;

	Item_ItemWnd = GetItemWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.Item_ItemWnd");
	Item_ItemWnd.Clear();
	sellItemInfo.bShowCount = IsStackableItem(sellItemInfo.ConsumeType);
	Item_ItemWnd.AddItem(sellItemInfo);
	if(IsAdena(sellItemInfo.Id))
	{
		itemSell_NumberInputScr._SetMinCountCanBuy(class'WorldExchangeBuyWnd'.static.Inst().ADENA_MIN);
		itemSell_NumberInputScr._SetPlusBasicUnit(class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT);		
	}
	else
	{
		itemSell_NumberInputScr._SetMinCountCanBuy(1);
		itemSell_NumberInputScr._SetPlusBasicUnit(1);
	}
	itemSell_NumberInputScr.SetCount(sellItemInfo.ItemNum);
	itemSell_NumberInputScr._SetForceDisable(false);
	bundlePrice_NumberInputScr._SetForceDisable(false);
	GetButtonHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".Refresh_btn").EnableWindow();
	RQ_C_EX_WORLD_EXCHANGE_ITEM_LIST(0);
	GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.SellTime_txt").SetText(GetSystemString(14084));
}

function DelItemInfo()
{
	local ItemInfo emptyInfo;

	GetItemWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.Item_ItemWnd").Clear();
	itemSell_NumberInputScr._SetForceDisable(true);
	bundlePrice_NumberInputScr._SetForceDisable(true);
	if(itemSell_NumberInputScr.GetCount() != 0)
	{
		itemSell_NumberInputScr.SetCount(0);
	}
	if(bundlePrice_NumberInputScr.GetCount() != 0)
	{
		bundlePrice_NumberInputScr.SetCount(0);
	}
	Get_UnitPriceCount_Txt().SetText("0");
	Get_RegiFeePiceCount_Txt().SetText("0" @ GetSystemString(469));
	Get_RegiFeePiceCount_TxtUnit_Txt().SetText("");
	Get_SellFeePiceCount_Txt().SetText("0" @ GetSystemString(3931));
	Get_UnitPriceCount_Txt().SetText("0");
	GetButtonHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.GetReward_Btn").DisableWindow();
	sellItemInfo = emptyInfo;
	lastLoadedPage = 0;
	ExchangeFind_RichList.DeleteAllItem();
	FindDisable_Wnd.ShowWindow();
	tObjectListAdd._Stop();
	GetButtonHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".Refresh_btn").DisableWindow();
	GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.SellTime_txt").SetText("-");
}

function INT64 DelegateGetCanSellItemNum()
{
	return GetSellItemInfoNum(sellItemInfo.Id.ServerID);
}

function INT64 GetSellItemInfoNum(int sererID)
{
	local ItemInfo iInfo;

	if(class'UIDATA_INVENTORY'.static.FindItem(sellItemInfo.Id.ServerID, iInfo))
	{
		if(IsAdena(iInfo.Id))
		{
			return Min64((iInfo.ItemNum / class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT) * class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT, class'WorldExchangeBuyWnd'.static.Inst().ADENA_MAX);			
		}
		else
		{
			return Min64(1000, iInfo.ItemNum);
		}
	}
	return 0;
}

function INT64 GetCanLcoinPriceItemNum()
{
	local INT64 Adena;
	local WorldExchangeUIData tmpWorldExchangeUIData;

	tmpWorldExchangeUIData = API_GetWorldExchangeData();
	Adena = GetAdena();
	if(IsAdena(sellItemInfo.Id))
	{
		Adena = Adena - itemSell_NumberInputScr.GetCount();
	}
	return Adena / tmpWorldExchangeUIData.RegistFee;
}

function INT64 GetCommitionRegist()
{
	local WorldExchangeUIData tmpWorldExchangeUIData;

	tmpWorldExchangeUIData = API_GetWorldExchangeData();
	return bundlePrice_NumberInputScr.GetCount() * tmpWorldExchangeUIData.RegistFee;	
}

function int GetCommitionSell()
{
	local WorldExchangeUIData tmpWorldExchangeUIData;

	tmpWorldExchangeUIData = API_GetWorldExchangeData();
	return Min(tmpWorldExchangeUIData.MaxSellFee, int(float(bundlePrice_NumberInputScr.GetCount()) * (float(tmpWorldExchangeUIData.SellFee) / 100)));	
}

function _GetSellItemInfo(out ItemInfo ItemInfo)
{
	ItemInfo = sellItemInfo;
}

function HandleScrollMove(optional int pos)
{
	scrollPos = pos;
	if(bRQ_C_EX_WORLD_EXCHANGE_ITEM_LIST)
	{
		return;
	}
	if(pos == (ExchangeFind_RichList.GetRecordCount() - ExchangeFind_RichList.GetShowRow()))
	{
		RQ_C_EX_WORLD_EXCHANGE_ITEM_LIST(lastLoadedPage + 1);
	}
}

function TInsertRecordOnTime(int Count)
{
	TInsertRecord();
}

function TInsertRecord()
{
	local int i, Cnt;
	local RichListCtrlRowData rowData;

	if(_itemDatas.Length == 0)
	{
		if(tObjectListAdd._curCount >= refreshMinCount)
		{
			tObjectListAdd._Stop();
			tObject._Stop();
			TInserDelayCheck();
			SetEnableRefresh();
		}
		return;
	}
	Cnt = Min(10, _itemDatas.Length);
	if(IsAdena(sellItemInfo.Id))
	{
		for(i = 0; i < Cnt; i++)
		{
			if(class'WorldExchangeBuyWnd'.static.Inst()._MakeRowDataAdena(_itemDatas[i], rowData))
			{
				ExchangeFind_RichList.InsertRecord(rowData);
			}
		}		
	}
	else
	{
		for(i = 0; i < Cnt; i++)
		{
			if(MakeRowData(_itemDatas[i], rowData))
			{
				ExchangeFind_RichList.InsertRecord(rowData);
			}
		}
	}
	_itemDatas.Remove(0, Cnt);
}

function TInserDelayCheck()
{
	HandleScrollMove(scrollPos);
}

function bool MakeRowData(UIPacket._WorldExchangeItemData _itemData, out RichListCtrlRowData outRowData)
{
	local RichListCtrlRowData rowData;
	local ItemInfo iInfo;
	local string strcom, itemParam;
	local float unitPrice;

	rowData.cellDataList.Length = 3;
	if(_itemData.nItemClassID < 1)
	{
		return false;
	}
	if(! class'UIDATA_ITEM'.static.GetItemInfo(GetItemID(_itemData.nItemClassID), iInfo))
	{
		return false;
	}
	rowData.nReserved1 = _itemData.nWEIndex;
	rowData.nReserved2 = ExchangeFind_RichList.GetRecordCount();
	iInfo.ItemNum = _itemData.nAmount;
	iInfo.bShowCount = IsStackableItem(iInfo.ConsumeType);
	iInfo.Enchanted = _itemData.nEnchant;
	iInfo.RefineryOp1 = _itemData.nVariationOpt1;
	iInfo.RefineryOp2 = _itemData.nVariationOpt2;
	iInfo.AttackAttributeType = _itemData.nBaseAttributeAttackType;
	iInfo.AttackAttributeValue = _itemData.nBaseAttributeAttackValue;
	iInfo.DefenseAttributeValueFire = _itemData.nBaseAttributeDefendValue[0];
	iInfo.DefenseAttributeValueWater = _itemData.nBaseAttributeDefendValue[1];
	iInfo.DefenseAttributeValueWind = _itemData.nBaseAttributeDefendValue[2];
	iInfo.DefenseAttributeValueEarth = _itemData.nBaseAttributeDefendValue[3];
	iInfo.DefenseAttributeValueHoly = _itemData.nBaseAttributeDefendValue[4];
	iInfo.DefenseAttributeValueUnholy = _itemData.nBaseAttributeDefendValue[5];
	iInfo.LookChangeItemID = _itemData.nShapeShiftingClassId;
	iInfo.LookChangeItemName = class'UIDATA_ITEM'.static.GetItemName(GetItemID(_itemData.nShapeShiftingClassId));
	if(_itemData.nShapeShiftingClassId > 0)
	{
		iInfo.LookChangeIconPanel = "BranchSys3.Icon.pannel_lookChange";
	}
	iInfo.EnsoulOption[1 - 1].OptionArray[0] = _itemData.nEsoulOption[0];
	iInfo.EnsoulOption[1 - 1].OptionArray[1] = _itemData.nEsoulOption[1];
	iInfo.EnsoulOption[2 - 1].OptionArray[0] = _itemData.nEsoulOption[2];
	iInfo.IsBlessedItem = _itemData.nBlessOption == 1;
	addRichListCtrlTexture(rowData.cellDataList[0].drawitems, "l2ui_ct1.ItemWindow_DF_SlotBox_Default", 36, 36, 0, 1);
	AddRichListCtrlItem(rowData.cellDataList[0].drawitems, iInfo, 32, 32, -34, 2);
	addRichListCtrlString(rowData.cellDataList[0].drawitems, GetItemNameAll(iInfo), GTColor().White, false, 4, 2);
	addRichListCtrlString(rowData.cellDataList[0].drawitems, "x" $ string(_itemData.nAmount), GTColor().White, true, 39, 3);
	iInfo.Price = _itemData.nPrice;
	strcom = MakeCostStringINT64(iInfo.Price);
	addRichListCtrlString(rowData.cellDataList[1].drawitems, GetSystemString(3931), GetColor(147, 136, 112, 255), false, 18, 0);
	addRichListCtrlString(rowData.cellDataList[1].drawitems, strcom, GetNumericColor(strcom), false, 5, 0);
	unitPrice = float(iInfo.Price) / float(iInfo.ItemNum);
	strcom = MakeCostStringINT64(iInfo.Price / iInfo.ItemNum);
	addRichListCtrlString(rowData.cellDataList[2].drawitems, "." $ class'WorldExchangeBuyWnd'.static.Inst().GetDecimalNnmStr(unitPrice), GetColor(123, 123, 123, 255), false, 0, 1, "hs7");
	addRichListCtrlString(rowData.cellDataList[2].drawitems, strcom, GetNumericColor(strcom), false, 0, -2);
	ItemInfoToParam(iInfo, itemParam);
	rowData.szReserved = itemParam;
	outRowData = rowData;
	return true;
}

function HandleDialogOKSource()
{
	local INT64 ItemNum;

	ItemNum = MAX64(0, int64(DialogGetString()));
	if(IsAdena(sellItemInfo.Id))
	{
		ItemNum = ItemNum * class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT;
	}
	sellItemInfo.ItemNum = sellItemInfo.ItemNum - (MAX64(Min64(ItemNum, sellItemInfo.ItemNum), 0));
	if(sellItemInfo.ItemNum == 0)
	{
		DelItemInfo();		
	}
	else
	{
		SetItemInfo();
	}
}

function HandleDialogOKDrop()
{
	local INT64 ItemNum;

	ItemNum = MAX64(0, int64(DialogGetString()));
	if(ItemNum == 0)
	{
		return;
	}
	if(IsAdena(readySellItemInfo.Id))
	{
		ItemNum = ItemNum * class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT;
	}
	if(sellItemInfo.Id == readySellItemInfo.Id)
	{
		sellItemInfo.ItemNum = sellItemInfo.ItemNum + ItemNum;		
	}
	else
	{
		SetSortType(E_WORLD_EXCHANGE_SORT_TYPE.EWEST_PRICE_PER_PIECE_ASCE/*8*/);
		readySellItemInfo.ItemNum = ItemNum;
		sellItemInfo = readySellItemInfo;
		RQ_C_EX_WORLD_EXCHANGE_AVERAGE_PRICE();
	}
	SetItemInfo();	
}

function HandleDialogOkEdit()
{
	local INT64 ItemNum;

	ItemNum = MAX64(0, int64(DialogGetString()));
	if(IsAdena(readySellItemInfo.Id))
	{
		ItemNum = ItemNum * class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT;
	}
	if(ItemNum == 0)
	{
		return;
	}
	sellItemInfo.ItemNum = ItemNum;
	SetItemInfo();
}

function HandleDialogOKPrice()
{
	local INT64 ItemNum;

	ItemNum = MAX64(0, int64(DialogGetString()));
	if(ItemNum == 0)
	{
		return;
	}
	bundlePrice_NumberInputScr.SetCount(ItemNum);
}

function HandleGetRewardBtn()
{
	SetSellPopupInfos();
}

function SetSellPopupInfos()
{
	local string popupPath;

	popupPath = m_hOwnerWnd.m_WindowNameWithFullPath $ ".ItemRegiDialog_Wnd";
	GetWindowHandle(popupPath).ShowWindow();
	GetItemWindowHandle(popupPath $ ".Dialog_Wnd.Item_ItemWnd").Clear();
	if(IsAdena(sellItemInfo.Id))
	{
		GetTextBoxHandle(popupPath $ ".ItemName_Txt").SetTextColor(GetNumericColor(string(sellItemInfo.ItemNum)));
		GetTextBoxHandle(popupPath $ ".ItemName_Txt").SetText(string(sellItemInfo.ItemNum) $ GetSystemString(469));
		GetTextBoxHandle(popupPath $ ".ItemNum_Txt").SetText("x1");
		if(class'WorldExchangeBuyWnd'.static.Inst()._IsNewServer())
		{
			GetTextBoxHandle(popupPath $ ".UnitPriceTitle_Txt").SetText(GetSystemString(14424));
		}
		else
		{
			GetTextBoxHandle(popupPath $ ".UnitPriceTitle_Txt").SetText(GetSystemString(14192));
		}
	}
	else
	{
		GetTextBoxHandle(popupPath $ ".ItemName_Txt").SetTextColor(GetColor(153, 153, 153, 255));
		GetTextBoxHandle(popupPath $ ".Dialog_Wnd.ItemName_Txt").SetText(GetItemNameAll(sellItemInfo));
		GetTextBoxHandle(popupPath $ ".Dialog_Wnd.ItemNum_Txt").SetText("x" $ string(sellItemInfo.ItemNum));
		GetTextBoxHandle(popupPath $ ".UnitPriceTitle_Txt").SetText(GetSystemString(14088));
	}
	GetItemWindowHandle(popupPath $ ".Dialog_Wnd.Item_ItemWnd").AddItem(sellItemInfo);
	GetTextBoxHandle(popupPath $ ".Dialog_Wnd.TotalPiceCount_txt").SetText(MakeCostString(string(bundlePrice_NumberInputScr.GetCount())) @ GetSystemString(3931));
	GetTextBoxHandle(popupPath $ ".Dialog_Wnd.TotalPiceCount_txt").SetTextColor(GetColor(255, 255, 255, 255));
	GetTextBoxHandle(popupPath $ ".Dialog_Wnd.RegiFeePiceCount_txt").SetText(Get_RegiFeePiceCount_Txt().GetText());
	GetTextBoxHandle(popupPath $ ".Dialog_Wnd.SellFeePiceCount_txt").SetText(Get_SellFeePiceCount_Txt().GetText());
	GetTextBoxHandle(popupPath $ ".Dialog_Wnd.UnitPriceCount_txt").SetText(Get_UnitPriceCount_Txt().GetText());
	GetTextBoxHandle(popupPath $ ".Dialog_Wnd.UnitPricePrimeNumber_txt").SetText(Get_UnitPricePrimeNumber_txt().GetText());	
}

function SetHideSellDialogWindow()
{
	local string popupPath;

	TweenCancel();
	popupPath = m_hOwnerWnd.m_WindowNameWithFullPath $ ".ItemRegiDialog_Wnd";
	GetWindowHandle(popupPath).HideWindow();
}

function _Show()
{
	m_hOwnerWnd.ShowWindow();
	m_hOwnerWnd.SetFocus();
}

function _Hide()
{
	m_hOwnerWnd.HideWindow();
}

function handleSwap()
{
	Debug("HandleSwap");
	class'WorldExchangeBuyWnd'.static.Inst()._Show();
	getInstanceL2Util().syncWindowLoc(m_hOwnerWnd.m_WindowNameWithFullPath, "WorldExchangeBuyWnd");
}

function HandleRefresh()
{
	RQ_C_EX_WORLD_EXCHANGE_ITEM_LIST();
}

function CheckWorldExchangeRegiSubWnd()
{
	if(GetTabHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiList_Tab").GetTopIndex() == 0)
	{
		class'WorldExchangeRegiSubWnd'.static.Inst()._Show();		
	}
	else
	{
		class'WorldExchangeRegiSubWnd'.static.Inst()._Hide();
	}
}

function SetMyInfos()
{
	local array<ItemInfo> iInfos;

	Get_MyAdenaCount_Txt().SetText(MakeCostString(string(GetAdena())) @ GetSystemString(469));
	if(class'UIDATA_INVENTORY'.static.FindItemByClassID(91663, iInfos) > 0)
	{
		Get_MyLcoinCount_Txt().SetText(MakeCostString(string(iInfos[0].ItemNum)) @ GetSystemString(3931));		
	}
	else
	{
		Get_MyLcoinCount_Txt().SetText("0" @ GetSystemString(3931));
	}
}

function HandleMyItemChanged(optional array<ItemInfo> iInfos, optional int Index)
{
	SetMyInfos();
}

function HandleOnitemCountEdited(INT64 changedNum)
{
	local ItemWindowHandle Item_ItemWnd;
	local string commitionRegist;

	commitionRegist = string(GetCommitionRegist());
	sellItemInfo.ItemNum = itemSell_NumberInputScr.GetCount();
	Item_ItemWnd = GetItemWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.Item_ItemWnd");
	Item_ItemWnd.SetItem(0, sellItemInfo);
	class'WorldExchangeRegiSubWnd'.static.Inst()._ResetSellItem();
	_SetUnity(bundlePrice_NumberInputScr.GetCount(), itemSell_NumberInputScr.GetCount());
	Get_RegiFeePiceCount_Txt().SetText(MakeCostString(commitionRegist) @ GetSystemString(469));
	Get_RegiFeePiceCount_TxtUnit_Txt().SetText(ConvertNumToText(commitionRegist));
	Get_RegiFeePiceCount_TxtUnit_Txt().SetTextColor(GetNumericColor(commitionRegist));
	if(IsAdena(sellItemInfo.Id))
	{
		itemSell_NumberInputScr._SetEditBoxFontColor(GetNumericColor(string(sellItemInfo.ItemNum)));
		itemSell_NumberInputScr._SetEditBoxDisable(true);
		bundlePrice_NumberInputScr.SetCount(bundlePrice_NumberInputScr.GetCount());		
	}
	else
	{
		itemSell_NumberInputScr._SetEditBoxFontColor(getInstanceL2Util().BrightWhite);
		itemSell_NumberInputScr._SetEditBoxDisable(false);
	}
	CheckGetRewardBtn();	
}

function HandleOnPriceCountEdited(INT64 changedNum)
{
	local string commitionRegist;

	commitionRegist = string(GetCommitionRegist());
	_SetUnity(bundlePrice_NumberInputScr.GetCount(), itemSell_NumberInputScr.GetCount());
	Get_RegiFeePiceCount_Txt().SetText(MakeCostString(commitionRegist) @ GetSystemString(469));
	Get_RegiFeePiceCount_TxtUnit_Txt().SetText(ConvertNumToText(commitionRegist));
	Get_RegiFeePiceCount_TxtUnit_Txt().SetTextColor(GetNumericColor(commitionRegist));
	Get_SellFeePiceCount_Txt().SetText(MakeCostString(string(GetCommitionSell())) @ GetSystemString(3931));
	CheckGetRewardBtn();
}

function HandleOnOverInput()
{
	getInstanceL2Util().showGfxScreenMessage(GetSystemString(13448));
}

function HandleOnItemCountEditBtonClicked()
{
	local INT64 maxItemNum64;

	maxItemNum64 = GetSellItemInfoNum(readySellItemInfo.Id.ServerID);
	if(IsAdena(sellItemInfo.Id))
	{
		DialogShow(DialogModalType_Modalless, DialogType_NumberPadAdena, GetSystemString(14193), string(self));
		maxItemNum64 = maxItemNum64 / class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT;		
	}
	else
	{
		DialogShow(DialogModalType_Modalless, DialogType_NumberPad, MakeFullSystemMsg(GetSystemMessage(72), sellItemInfo.Name, ""), string(self));
	}
	DialogSetInputlimit(maxItemNum64);
	DialogSetParamInt64(maxItemNum64);
	class'DialogBox'.static.Inst().AnchorToOwner();
	class'DialogBox'.static.Inst().DelegateOnOK = HandleDialogOkEdit;	
}

function HandleOnPriceCountEditBtonClicked()
{
	DialogShow(DialogModalType_Modalless, DialogType_NumberPad, GetSystemMessage(322), string(self));
	DialogSetInputlimit(GetCanLcoinPriceItemNum());
	DialogSetParamInt64(5221615900385345559);
	class'DialogBox'.static.Inst().AnchorToOwner();
	class'DialogBox'.static.Inst().DelegateOnOK = HandleDialogOKPrice;
}

function CheckGetRewardBtn()
{
	if(itemSell_NumberInputScr.GetCount() == 0 || (GetCommitionSell()) == 0)
	{
		GetButtonHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.GetReward_Btn").DisableWindow();		
	}
	else
	{
		GetButtonHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.GetReward_Btn").EnableWindow();
	}
}

function _SetShowCancelDialog(string itemReservedString)
{
	local ItemInfo iInfo;
	local string CancelSaleDialogPath;

	GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".CancelSaleDialog_Wnd").ShowWindow();
	CancelSaleDialogPath = m_hOwnerWnd.m_WindowNameWithFullPath $ ".CancelSaleDialog_Wnd.CancelSalePopUp_Wnd";
	ParamToItemInfo(itemReservedString, iInfo);
	GetTextBoxHandle(CancelSaleDialogPath $ ".ItemName_Txt").SetText(GetItemNameAll(iInfo));
	GetItemWindowHandle(CancelSaleDialogPath $ ".Result_ItemWnd").Clear();
	GetItemWindowHandle(CancelSaleDialogPath $ ".Result_ItemWnd").AddItem(iInfo);
}

function _SetCurrentRigedItemNum(int Num)
{
	_regieditemNum = Num;
	GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.RegiItemNumTxt_Apply").SetText(string(Num));
	GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.RegiItemNumTxt_Total").SetText("/" $ string(10));
	if(Num == 10)
	{
		GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.ItemFullDisable_Wnd").ShowWindow();		
	}
	else
	{
		GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.ItemFullDisable_Wnd").HideWindow();
	}
}

private function HandleClickOK_Btn()
{
	local float perPrice;

	perPrice = float(bundlePrice_NumberInputScr.GetCount()) / float(itemSell_NumberInputScr.GetCount());
	if(IsAdena(sellItemInfo.Id))
	{
		perPrice = perPrice * float(class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT);
	}
	if(bRQ_C_EX_WORLD_EXCHANGE_AVERAGE_PRICE)
	{
		return;
	}
	Debug("HandleClickOK_Btn" @ string(perPrice) @ string(nAveragePrice * 0.90f));
	if(perPrice < (nAveragePrice * 0.90f))
	{
		class'DialogBox'.static.Inst().SetDefaultAction(EDefaultCancel);
		DialogShow(DialogModalType_Modalless, DialogType_OKCancel, GetSystemString(14204), string(self), 410, 109);
		class'DialogBox'.static.Inst().AnchorToOwner(-7, 144);
		class'DialogBox'.static.Inst().DelegateOnOK = HandleOK;
		class'DialogBox'.static.Inst().DelegateOnCancel = SetHideSellDialogWindow;
		TweenAdd();		
	}
	else
	{
		HandleOK();
	}	
}

private function TweenAdd()
{
	class'L2UITween'.static.Inst()._AddTweenTwinlkle(GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".ItemRegiDialog_Wnd.Dialog_Wnd.UnitPriceCount_txt"), -1.0f);
	class'L2UITween'.static.Inst()._AddTweenTwinlkle(GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".ItemRegiDialog_Wnd.Dialog_Wnd.UnitPricePrimeNumber_txt"), -1.0f);	
}

private function TweenCancel()
{
	Debug("TweenCancel 취소 ~~~ ");
	class'L2UITween'.static.Inst()._KillTwinkleWithWnd(GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".ItemRegiDialog_Wnd.Dialog_Wnd.UnitPriceCount_txt"));
	class'L2UITween'.static.Inst()._KillTwinkleWithWnd(GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".ItemRegiDialog_Wnd.Dialog_Wnd.UnitPricePrimeNumber_txt"));
	GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".ItemRegiDialog_Wnd.Dialog_Wnd.UnitPriceCount_txt").SetAlpha(255);
	GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".ItemRegiDialog_Wnd.Dialog_Wnd.UnitPricePrimeNumber_txt").SetAlpha(255);	
}

private function HandleOK()
{
	SetHideSellDialogWindow();
	RQ_C_EX_WORLD_EXCHANGE_REGI_ITEM();	
}

function HandleCancelOK()
{
	historyScr._RQ_C_EX_WORLD_EXCHANGE_SETTLE_RECV_RESULT();
}

function HandleCancelCancel()
{
	GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".CancelSaleDialog_Wnd").HideWindow();
}

function bool IsShowHistory()
{
	local TabHandle regilistTab;

	regilistTab = GetTabHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiList_Tab");
	return m_hOwnerWnd.IsShowWindow() && regilistTab.GetTopIndex() == 1;
}

function _CheckOnClickNoticeBtn()
{
	local TabHandle regilistTab;

	regilistTab = GetTabHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiList_Tab");
	if(IsShowHistory())
	{
		m_hOwnerWnd.HideWindow();		
	}
	else
	{
		_Show();
		regilistTab.SetTopOrder(1, true);
	}
	CheckWorldExchangeRegiSubWnd();
}

function int GetSortType()
{
	switch(sortHeaderIndex)
	{
		case 0:
			if(ExchangeFind_RichList.IsAscending(sortHeaderIndex))
			{
				return 2;				
			}
			else
			{
				return 3;
			}
		case 1:
			if(ExchangeFind_RichList.IsAscending(sortHeaderIndex))
			{
				return 4;				
			}
			else
			{
				return 5;
			}
		case 2:
			if(ExchangeFind_RichList.IsAscending(sortHeaderIndex))
			{
				return 8;				
			}
			else
			{
				return 9;
			}
		default:
			return 2;
	}
}

function SetSortByHeaderIndex(int Index)
{
	Debug("SetSortByHeaderIndex" @ string(Index));
	switch(Index)
	{
		case 0:
			if(ExchangeFind_RichList.IsAscending(Index))
			{
				SetSortType(E_WORLD_EXCHANGE_SORT_TYPE.EWEST_ENCHANT_DESC/*3*/);				
			}
			else
			{
				SetSortType(E_WORLD_EXCHANGE_SORT_TYPE.EWEST_ENCHANT_ASCE/*2*/);
			}
			break;
		case 1:
			if(ExchangeFind_RichList.IsAscending(Index))
			{
				SetSortType(E_WORLD_EXCHANGE_SORT_TYPE.EWEST_PRICE_DESC/*5*/);				
			}
			else
			{
				SetSortType(E_WORLD_EXCHANGE_SORT_TYPE.EWEST_PRICE_ASCE/*4*/);
			}
			break;
		case 2:
			if(ExchangeFind_RichList.IsAscending(Index))
			{
				SetSortType(E_WORLD_EXCHANGE_SORT_TYPE.EWEST_PRICE_PER_PIECE_DESC/*9*/);				
			}
			else
			{
				SetSortType(E_WORLD_EXCHANGE_SORT_TYPE.EWEST_PRICE_PER_PIECE_ASCE/*8*/);
			}
			break;
		default:
			SetSortType(E_WORLD_EXCHANGE_SORT_TYPE.EWEST_ENCHANT_ASCE/*2*/);
			break;
	}
}

function SetSortType(WorldExchangeRegiWnd.E_WORLD_EXCHANGE_SORT_TYPE sortType)
{
	local bool bAscend;

	Debug("SetSortType" @ string(sortType));
	switch(sortType)
	{
		case E_WORLD_EXCHANGE_SORT_TYPE.EWEST_ENCHANT_ASCE:
			sortHeaderIndex = 0;
			bAscend = true;
			break;
		case E_WORLD_EXCHANGE_SORT_TYPE.EWEST_ENCHANT_DESC:
			sortHeaderIndex = 0;
			bAscend = false;
			break;
		case E_WORLD_EXCHANGE_SORT_TYPE.EWEST_PRICE_ASCE:
			sortHeaderIndex = 1;
			bAscend = true;
			break;
		case E_WORLD_EXCHANGE_SORT_TYPE.EWEST_PRICE_DESC:
			sortHeaderIndex = 1;
			bAscend = false;
			break;
		case E_WORLD_EXCHANGE_SORT_TYPE.EWEST_PRICE_PER_PIECE_ASCE/*8*/:
			sortHeaderIndex = 2;
			bAscend = true;
			break;
		case E_WORLD_EXCHANGE_SORT_TYPE.EWEST_PRICE_PER_PIECE_DESC/*9*/:
			sortHeaderIndex = 2;
			bAscend = false;
			break;
		default:
			sortHeaderIndex = 0;
			bAscend = true;
			break;
	}
	ExchangeFind_RichList.SetAscend(sortHeaderIndex, bAscend);
	ExchangeFind_RichList.ShowSortIcon(sortHeaderIndex);
}

function _SetUnity(INT64 bundlePrice, INT64 ItemNum)
{
	local float unitPrice;
	local string strcom;

	if(IsAdena(sellItemInfo.Id))
	{
		bundlePrice = bundlePrice * class'WorldExchangeBuyWnd'.static.Inst().ADENA_BASIC_UNIT;
		if(class'WorldExchangeBuyWnd'.static.Inst()._IsNewServer())
		{
			GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.UnitPriceTitle_Txt").SetText(GetSystemString(14424));
		}
		else
		{
			GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.UnitPriceTitle_Txt").SetText(GetSystemString(14192));
		}	
	}
	else
	{
		GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.UnitPriceTitle_Txt").SetText(GetSystemString(14088));
	}
	unitPrice = float(bundlePrice) / float(ItemNum);
	strcom = MakeCostStringINT64(bundlePrice / ItemNum);
	Debug("_SetUnity --- " @ string(bundlePrice) @ string(ItemNum) @ string(unitPrice) @ strcom);
	Get_UnitPriceCount_Txt().SetText(strcom);
	Get_UnitPricePrimeNumber_txt().SetText("." $ class'WorldExchangeBuyWnd'.static.Inst().GetDecimalNnmStr(unitPrice));
}

function TextBoxHandle Get_UnitPriceCount_Txt()
{
	return GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.UnitPriceCount_Txt");	
}

function TextBoxHandle Get_UnitPricePrimeNumber_txt()
{
	return GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.UnitPricePrimeNumber_txt");	
}

function TextBoxHandle Get_RegiFeePiceCount_Txt()
{
	return GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.RegiFeePiceCount_Txt");
}

function TextBoxHandle Get_RegiFeePiceCount_TxtUnit_Txt()
{
	return GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.RegiFeePiceCount_TxtUnit_Txt");
}

function TextBoxHandle Get_SellFeePiceCount_Txt()
{
	return GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.SellFeePiceCount_Txt");
}

function TextBoxHandle Get_MyAdenaCount_Txt()
{
	return GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.MyAdenaCount_Txt");
}

function TextBoxHandle Get_MyLcoinCount_Txt()
{
	return GetTextBoxHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.MyLcoinCount_Txt");
}

function _OnLoadEachServer()
{
	if(class'WorldExchangeBuyWnd'.static.Inst()._IsNewServer())
	{
		GetButtonHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.GetHelp_Btn").SetTooltipCustomType(MakeTooltipSimpleText(GetSystemString(14425)));		
	}
	else
	{
		GetButtonHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".RegiTabWnd.ItemRegi_Wnd.GetHelp_Btn").SetTooltipCustomType(MakeTooltipSimpleText(GetSystemString(14089)));
	}
	GetMeTexture("ItemRegiDialog_Wnd.Dialog_Wnd.TotalPiceIcon_Tex").SetTexture("L2UI_CT1.LCoinShopWnd.LCoinShopWnd_Icon_Lcoin");
	GetMeTexture("ItemRegiDialog_Wnd.Dialog_Wnd.SellFeeIcon_Tex").SetTexture("L2UI_CT1.LCoinShopWnd.LCoinShopWnd_Icon_Lcoin");
	GetMeTexture("RegiTabWnd.ItemRegi_Wnd.BundlePrice_NumberInput.BundlePriceIcon_Tex").SetTexture("L2UI_CT1.LCoinShopWnd.LCoinShopWnd_Icon_Lcoin");
	GetMeTexture("RegiTabWnd.ItemRegi_Wnd.SellIcon_Tex").SetTexture("L2UI_CT1.LCoinShopWnd.LCoinShopWnd_Icon_Lcoin");
	GetMeTexture("RegiTabWnd.ItemRegi_Wnd.MyLcoinIcon_Tex").SetTexture("L2UI_CT1.LCoinShopWnd.LCoinShopWnd_Icon_Lcoin");	
}

event OnReceivedCloseUI()
{
	local string popupPath;

	popupPath = m_hOwnerWnd.m_WindowNameWithFullPath $ ".ItemRegiDialog_Wnd";
	if(GetWindowHandle(popupPath).IsShowWindow())
	{
		SetHideSellDialogWindow();		
	}
	else
	{
		PlayConsoleSound(IFST_WINDOW_CLOSE);
		_Hide();
	}
}
