MAX_NUM_GLUE_DIALOG_BUTTONS = 3;

GlueDialogTypes = { };

GlueDialogTypes["SYSTEM_INCOMPATIBLE_SSE"] = {
	text = SYSTEM_INCOMPATIBLE_SSE,
	button1 = OKAY,
	html = 1,
	showAlert = 1,
	escapeHides = true,
	OnAccept = function ()
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["CANCEL_RESET_SETTINGS"] = {
	text = CANCEL_RESET_SETTINGS,
	button1 = OKAY,
	button2 = CANCEL,
	escapeHides = true,
	OnAccept = function ()
		AccountLoginUIResetFrame:Hide();
		-- Switch the reset settings button back to reset mode
		OptionsSelectResetSettingsButton:SetText(RESET_SETTINGS);
		OptionsSelectResetSettingsButton:SetScript("OnClick", OptionsSelectResetSettingsButton_OnClick_Reset);
		SetClearConfigData(false);
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["RESET_SERVER_SETTINGS"] = {
	text = RESET_SERVER_SETTINGS,
	button1 = OKAY,
	button2 = CANCEL,
	escapeHides = true,
	OnAccept = function ()
		AccountLoginUIResetFrame:Show();
		-- Switch the reset settings button to cancel mode
		OptionsSelectResetSettingsButton:SetText(CANCEL_RESET);
		OptionsSelectResetSettingsButton:SetScript("OnClick", OptionsSelectResetSettingsButton_OnClick_Cancel);
		SetClearConfigData(true);
	end,
	OnCancel = function ()
	end,
}

GlueDialogTypes["CONFIRM_RESET_VIDEO_SETTINGS"] = { 
	text = CONFIRM_RESET_SETTINGS,
	button1 = ALL_SETTINGS,
	button2 = CURRENT_SETTINGS,
	button3 = CANCEL,
	showAlert = 1,
	OnAccept = function ()
		VideoOptionsFrame_SetAllToDefaults();
	end,
	OnCancel = function ()
		VideoOptionsFrame_SetCurrentToDefaults();
	end,
	OnAlt = function() end,
	escapeHides = true,
}

GlueDialogTypes["CONFIRM_RESET_AUDIO_SETTINGS"] = { 
	text = CONFIRM_RESET_SETTINGS,
	button1 = ALL_SETTINGS,
	button2 = CURRENT_SETTINGS,
	button3 = CANCEL,
	showAlert = 1,
	OnAccept = function ()
		AudioOptionsFrame_SetAllToDefaults();
	end,
	OnCancel = function ()
		AudioOptionsFrame_SetCurrentToDefaults();
	end,
	OnAlt = function() end,
	escapeHides = true,
}

GlueDialogTypes["CLIENT_RESTART_ALERT"] = {
	text = CLIENT_RESTART_ALERT,
	button1 = OKAY,
	showAlert = 1,
}

GlueDialogTypes["REALM_IS_FULL"] = {
	text = REALM_IS_FULL_WARNING,
	button1 = YES,
	button2 = NO,
	showAlert = 1,
	OnAccept = function()
		SetGlueScreen("charselect");
		ChangeRealm(RealmList.selectedCategory , RealmList.currentRealm);
	end,
	OnCancel = function()
		CharacterSelect_ChangeRealm();
	end,
}

GlueDialogTypes["SUGGEST_REALM"] = {
	text = format(SUGGESTED_REALM_TEXT,"UNKNOWN REALM"),
	button1 = ACCEPT,
	button2 = VIEW_ALL_REALMS,
	OnShow = function()
		GlueDialogText:SetFormattedText(SUGGESTED_REALM_TEXT, RealmWizard.suggestedRealmName);
	end,
	OnAccept = function()
		SetGlueScreen("charselect");
		ChangeRealm(RealmWizard.suggestedCategory, RealmWizard.suggestedID);
	end,
	OnCancel = function()
		SetGlueScreen("charselect");
		CharacterSelect_ChangeRealm();
	end,
}

GlueDialogTypes["DISCONNECTED"] = {
	text = "The server has been restarted. Log back in, in 30 seconds.",
	button1 = OKAY,
	button2 = nil,
	OnShow = function()
		RealmList:Hide();
		SecurityMatrixLoginFrame:Hide();
		StatusDialogClick();
	end,
	OnAccept = function()
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["PARENTAL_CONTROL"] = {
	text = AUTH_PARENTAL_CONTROL,
	button1 = MANAGE_ACCOUNT,
	button2 = OKAY,
	OnShow = function()
		RealmList:Hide();
		SecurityMatrixLoginFrame:Hide();
		StatusDialogClick();
	end,
	OnAccept = function()
		LaunchURL(AUTH_NO_TIME_URL);
	end,
	OnCancel = function()
		StatusDialogClick();
	end,
}

GlueDialogTypes["INVALID_NAME"] = {
	text = CHAR_CREATE_INVALID_NAME,
	button1 = OKAY,
	button2 = nil,
	OnAccept = function()
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["CANCEL"] = {
	text = "",
	button1 = CANCEL,
	button2 = nil,
	OnAccept = function()
		if VX_SOUNDBG then
			SetCVar("Sound_EnableSoundWhenGameIsInBG", VX_SOUNDBG);
			VX_SOUNDBG = nil;
		end
		StatusDialogClick();
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["QUEUED_WITH_FCM"] = {
	text = "",
	button1 = CANCEL,
	button2 = QUEUE_FCM_BUTTON,
	OnAccept = function()
		StatusDialogClick();
	end,
	OnCancel = function()
		LaunchURL(QUEUE_FCM_URL)
	end,
}

GlueDialogTypes["OKAY"] = {
	text = "",
	button1 = OKAY,
	button2 = nil,
	OnShow = function()
		CancelLogin();
	end,
	OnAccept = function()
		StatusDialogClick();
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["OKAY_HTML"] = {
	text = "",
	button1 = OKAY,
	button2 = nil,
	html = 1,
	OnAccept = function()
		StatusDialogClick();
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["OKAY_HTML_EXIT"] = {
	text = "",
	button1 = OKAY,
	button2 = EXIT_GAME,
	html = 1,
	OnShow = function()
		CancelLogin();
	end,
	OnAccept = function()
		StatusDialogClick();
	end,
	OnCancel = function()
		AccountLogin_Exit();
	end,
}

GlueDialogTypes["CONFIRM_PAID_SERVICE"] = {
	text = CONFIRM_PAID_SERVICE,
	button1 = DONE,
	button2 = CANCEL,
	OnAccept = function()
		CreateCharacter(CharacterCreateNameEdit:GetText());
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["OKAY_WITH_URL"] = {
	text = "",
	button1 = HELP,
	button2 = OKAY,
	OnAccept = function()
		LaunchURL(_G[GlueDialog.data]);
	end,
	OnCancel = function()
		StatusDialogClick();
	end,
}

GlueDialogTypes["CONNECTION_HELP"] = {
	text = "",
	button1 = HELP,
	button2 = OKAY,
	OnShow = function()
		StatusDialogClick();
	end,
	OnAccept = function()
		AccountLoginUI:Hide();
		ConnectionHelpFrame:Show();
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["CONNECTION_HELP_HTML"] = {
	text = "",
	button1 = HELP,
	button2 = OKAY,
	html = 1,
	OnShow = function()
		StatusDialogClick();
	end,
	OnAccept = function()
		AccountLoginUI:Hide();
		ConnectionHelpFrame:Show();
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["CLIENT_ACCOUNT_MISMATCH"] = {
	button1 = RETURN_TO_LOGIN,
	button2 = EXIT_GAME,
	html = 1,
	OnAccept = function()
		SetGlueScreen("login");
	end,
	OnCancel = function()
		PlaySound("gsTitleQuit");
		QuitGame();
	end,
}

GlueDialogTypes["CLIENT_TRIAL"] = {
	text = CLIENT_TRIAL,
	button1 = RETURN_TO_LOGIN,
	button2 = EXIT_GAME,
	html = 1,
	OnAccept = function()
		SetGlueScreen("login");
	end,
	OnCancel = function()
		PlaySound("gsTitleQuit");
		QuitGame();
	end,
}


GlueDialogTypes["SCANDLL_DOWNLOAD"] = {
	text = "",
	button1 = QUIT,
	button2 = nil,
	OnAccept = function()
		AccountLogin_Exit();
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["SCANDLL_ERROR"] = {
	text = "",
	button1 = SCANDLL_BUTTON_CONTINUEANYWAY,
	button2 = QUIT,
	OnAccept = function()
		GlueDialog:Hide();
		ScanDLLContinueAnyway();
		AccountLoginUI:Show();
	end,
	OnCancel = function()
		-- Opposite semantics
		AccountLogin_Exit();
	end,
}

GlueDialogTypes["SCANDLL_HACKFOUND"] = {
	text = "",
	button1 = SCANDLL_BUTTON_CONTINUEANYWAY,
	button2 = QUIT,
	html = 1,
	showAlert = 1,
	OnAccept = function()
		local formatString = _G["SCANDLL_MESSAGE_"..AccountLogin.hackType.."FOUND_CONFIRM"];
		GlueDialog_Show("SCANDLL_HACKFOUND_CONFIRM", format(formatString, AccountLogin.hackName, AccountLogin.hackURL));
	end,
	OnCancel = function()
		AccountLogin_Exit();
	end,
}

GlueDialogTypes["SCANDLL_HACKFOUND_NOCONTINUE"] = {
	text = "",
	button1 = QUIT,
	button2 = nil,
	html = 1,
	showAlert = 1,
	OnAccept = function()
		AccountLogin_Exit();
	end,
	OnCancel = function()
		AccountLogin_Exit();
	end,
}

GlueDialogTypes["SCANDLL_HACKFOUND_CONFIRM"] = {
	text = "",
	button1 = SCANDLL_BUTTON_CONTINUEANYWAY,
	button2 = QUIT,
	html = 1,
	showAlert = 1,
	OnAccept = function()
		GlueDialog:Hide();
		ScanDLLContinueAnyway();
		AccountLoginUI:Show();
	end,
	OnCancel = function()
		AccountLogin_Exit();
	end,
}

GlueDialogTypes["SERVER_SPLIT"] = {
	text = SERVER_SPLIT,
	button1 = SERVER_SPLIT_SERVER_ONE,
	button2 = SERVER_SPLIT_SERVER_TWO,
	button3 = SERVER_SPLIT_NOT_NOW,
	escapeHides = true;

	OnAccept = function()
		SetStateRequestInfo( 1 );
	end,
	OnCancel = function()
		SetStateRequestInfo( 2 );
	end,
	OnAlt = function()
		SetStateRequestInfo( 0 );
	end,
}

GlueDialogTypes["SERVER_SPLIT_WITH_CHOICE"] = {
	text = SERVER_SPLIT,
	button1 = SERVER_SPLIT_SERVER_ONE,
	button2 = SERVER_SPLIT_SERVER_TWO,
	button3 = SERVER_SPLIT_DONT_CHANGE,
	escapeHides = true;

	OnAccept = function()
		SetStateRequestInfo( 1 );
	end,
	OnCancel = function()
		SetStateRequestInfo( 2 );
	end,
	OnAlt = function()
		SetStateRequestInfo( 0 );
	end,
}

GlueDialogTypes["ACCOUNT_MSG"] = {
	text = "",
	button1 = OKAY,
	button2 = ACCOUNT_MESSAGE_BUTTON_READ,
	html = 1,
	escapeHides = true,

	OnShow = function()
		StatusDialogClick();
	end,
	OnAccept = function()
		ACCOUNT_MSG_NUM_AVAILABLE = ACCOUNT_MSG_NUM_AVAILABLE - 1;
		if ( ACCOUNT_MSG_NUM_AVAILABLE > 0 ) then
			ACCOUNT_MSG_CURRENT_INDEX = AccountMsg_GetIndexNextUnreadMsg(ACCOUNT_MSG_CURRENT_INDEX);
			ACCOUNT_MSG_BODY_LOADED = false;
			AccountMsg_LoadBody( ACCOUNT_MSG_CURRENT_INDEX );
		end
		StatusDialogClick();
	end,
	OnCancel = function()
		AccountMsg_SetMsgRead(ACCOUNT_MSG_CURRENT_INDEX);
		ACCOUNT_MSG_NUM_AVAILABLE = ACCOUNT_MSG_NUM_AVAILABLE - 1;
		if ( ACCOUNT_MSG_NUM_AVAILABLE > 0 ) then
			ACCOUNT_MSG_CURRENT_INDEX = AccountMsg_GetIndexNextUnreadMsg(ACCOUNT_MSG_CURRENT_INDEX);
			ACCOUNT_MSG_BODY_LOADED = false;
			AccountMsg_LoadBody( ACCOUNT_MSG_CURRENT_INDEX );
		end
		StatusDialogClick();
	end,
}

GlueDialogTypes["DECLINE_FAILED"] = {
	text = "",
	button1 = OKAY,
	button2 = nil,
	OnAccept = function()
		DeclensionFrame:Show();
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["REALM_LOCALE_WARNING"] = {
	text = REALM_TYPE_LOCALE_WARNING,
	button1 = OKAY,
	button2 = nil,
	OnAccept = function()
	end,
	OnCancel = function()
	end,
}

GlueDialogTypes["REALM_TOURNAMENT_WARNING"] = {
	text = REALM_TYPE_TOURNAMENT_WARNING,
	button1 = OKAY,
	button2 = nil,
	OnAccept = function()
	end,
	OnCancel = function()
	end,
}

function GlueDialog_Show(which, text, data)
	local dialogInfo = GlueDialogTypes[which];
	-- Pick a free dialog to use
	if ( GlueDialog:IsShown() ) then
		if ( GlueDialog.which ~= which ) then -- We don't actually want to hide, we just want to redisplay?
			if ( GlueDialogTypes[GlueDialog.which].OnHide ) then
				GlueDialogTypes[GlueDialog.which].OnHide();	
			end
			
			GlueDialog:Hide();
		end
	end

	GlueDialog.data = data;
	local glueText;
	if ( dialogInfo.html ) then
		glueText = GlueDialogHTML;
		GlueDialogHTML:Show();
		GlueDialogText:Hide();
	else
		glueText = GlueDialogText;
		GlueDialogHTML:Hide();
		GlueDialogText:Show();
	end
	
	-- Set the text of the dialog
	if ( text ) then
		glueText:SetText(text);
	else
		glueText:SetText(dialogInfo.text);
	end

	-- Set the miscellaneous variables for the dialog
	GlueDialog.which = which;
	GlueDialog.data = data;

	GlueDialogText:SetWidth(GlueDialogText.origWidth);

	--------------------------------------------------------------------------------------
	--/ Vars
	local bText;
	local bHSpace = 0;
	local bVSpace = 0;
	local bSideTextField = 50;
	local dHBorderSpace = 32;
	local dVBorderSpace = 16;
	local bMaxWidth = 256;
	local dWidth;
	local dHeight;
	local textHeight, _;
	local textWidth, _;
	--\

	--/ Set width of the dialog buttons +editbox
	if ( dialogInfo.button3 ) then
		GlueDialogButton1:ClearAllPoints();
		GlueDialogButton2:ClearAllPoints();
		GlueDialogButton3:ClearAllPoints();

		GlueDialogButton2:SetText(dialogInfo.button2);
		bText = _G[GlueDialogButton2:GetName().."Text"];
		GlueDialogButton2:SetWidth(bText:GetWidth() + bSideTextField*2);
		if bMaxWidth < GlueDialogButton2:GetWidth() then
			bMaxWidth = GlueDialogButton2:GetWidth();
		end

		GlueDialogButton3:SetText(dialogInfo.button3);
		bText = _G[GlueDialogButton3:GetName().."Text"];
		GlueDialogButton3:SetWidth(bText:GetWidth() + bSideTextField*2);
		if bMaxWidth < GlueDialogButton3:GetWidth() then
			bMaxWidth = GlueDialogButton3:GetWidth();
		end

	elseif ( dialogInfo.button2 ) then
		GlueDialogButton1:ClearAllPoints();
		GlueDialogButton2:ClearAllPoints();
	
		GlueDialogButton2:SetText(dialogInfo.button2);
		bText = _G[GlueDialogButton2:GetName().."Text"];
		GlueDialogButton2:SetWidth(bText:GetWidth() + bSideTextField*2);
		if bMaxWidth < GlueDialogButton2:GetWidth() then
			bMaxWidth = GlueDialogButton2:GetWidth();
		end

	else
		GlueDialogButton1:ClearAllPoints();
	end

	GlueDialogButton1:SetText(dialogInfo.button1);
	bText = _G[GlueDialogButton1:GetName().."Text"];
	GlueDialogButton1:SetWidth(bText:GetWidth() + bSideTextField*2);
	if bMaxWidth < GlueDialogButton1:GetWidth() then
		bMaxWidth = GlueDialogButton1:GetWidth();
	end

	-- Editbox setup
	if ( dialogInfo.hasEditBox ) then
		GlueDialogEditBox:Show();
		if ( dialogInfo.maxLetters ) then
			GlueDialogEditBox:SetMaxLetters(dialogInfo.maxLetters);
		end
		if ( dialogInfo.maxBytes ) then
			GlueDialogEditBox:SetMaxBytes(dialogInfo.maxBytes);
		end
		if bMaxWidth < GlueDialogEditBox:GetWidth() then
			bMaxWidth = GlueDialogEditBox:GetWidth();
		end
	else
		GlueDialogEditBox:Hide();
	end
	--\

	--/ Text & background formatting
	-- size the width first
	dWidth = bMaxWidth + dHBorderSpace*2;
	if ( dialogInfo.displayVertical ) then
		-- dWidth = bMaxWidth + dHBorderSpace*2;
	elseif ( dialogInfo.button3 ) then
		dWidth = GlueDialogButton1:GetWidth() + GlueDialogButton2:GetWidth() + GlueDialogButton3:GetWidth() + bHSpace*2 + dHBorderSpace*2;
	elseif ( dialogInfo.button2 ) then
		dWidth = GlueDialogButton1:GetWidth() + GlueDialogButton2:GetWidth() + bHSpace + dHBorderSpace*2;
	end
	GlueDialogText:SetWidth( dWidth - 32 );
	-- Get the height of the string
	if ( dialogInfo.html ) then
		_,_,textWidth,textHeight = GlueDialogHTML:GetBoundsRect();
	else
		textHeight = GlueDialogText:GetHeight();
		textWidth = GlueDialogText:GetWidth();
	end
	-- check text form
	if ( textWidth < textHeight * 3 ) then
		if textHeight * 3 > 2 * GetScreenWidth() / 3 then
			GlueDialogText:SetWidth( 2 * GetScreenWidth() / 3 );
		else
			GlueDialogText:SetWidth( textHeight * 3 );
		end
		-- recheck height
		if ( dialogInfo.html ) then
			_,_,textWidth,textHeight = GlueDialogHTML:GetBoundsRect();
		else
			textHeight = GlueDialogText:GetHeight();
			textWidth = GlueDialogText:GetWidth();
		end
	end
	GlueDialogBackground:SetWidth( textWidth + 32 );
	-- Correct text width 4 alert
	if ( dialogInfo.showAlert ) then
		GlueDialogText:SetWidth( GlueDialogBackground:GetWidth() - GlueDialogAlertIcon:GetWidth() - 16 );
	end

	-- now size the dialog box height
	if ( dialogInfo.hasEditBox ) then
		dHeight = dVBorderSpace + textHeight + bVSpace + GlueDialogEditBox:GetHeight() + dVBorderSpace + GlueDialogButton1:GetHeight() + dVBorderSpace;
	elseif ( dialogInfo.displayVertical ) then
		dHeight = dVBorderSpace + textHeight + dVBorderSpace + GlueDialogButton1:GetHeight() + dVBorderSpace;
		if ( dialogInfo.button2 ) then
			dHeight = dHeight + bVSpace + GlueDialogButton2:GetHeight();
		end
		if ( dialogInfo.button3 ) then
			dHeight = dHeight + bVSpace + GlueDialogButton3:GetHeight();
		end
	else
		dHeight = dVBorderSpace + textHeight + dVBorderSpace + GlueDialogButton1:GetHeight() + dVBorderSpace;
	end
	GlueDialogBackground:SetHeight(dHeight);
	--/

	--/ Set Buttons & alert positions
	-- Set positions of the dialog buttons
	if ( dialogInfo.button3 ) then
		GlueDialogButton2:Show();
		GlueDialogButton3:Show();
		if ( dialogInfo.displayVertical ) then
			GlueDialogButton3:SetPoint("BOTTOM", "GlueDialogBackground", "BOTTOM", 0, dVBorderSpace);
			GlueDialogButton2:SetPoint("BOTTOM", "GlueDialogButton3", "TOP", 0, bVSpace);
			GlueDialogButton1:SetPoint("BOTTOM", "GlueDialogButton2", "TOP", 0, bVSpace);
		else
			dHBorderSpace = (GlueDialogBackground:GetWidth() - GlueDialogButton1:GetWidth() - GlueDialogButton2:GetWidth() - GlueDialogButton3:GetWidth() - bHSpace*2) / 2;
			GlueDialogButton3:SetPoint("BOTTOMRIGHT", "GlueDialogBackground", "BOTTOMRIGHT", -dHBorderSpace, dVBorderSpace);
			GlueDialogButton2:SetPoint("RIGHT", "GlueDialogButton3", "LEFT", -bHSpace, 0);
			GlueDialogButton1:SetPoint("RIGHT", "GlueDialogButton2", "LEFT", -bHSpace, 0);
		end
	elseif ( dialogInfo.button2 ) then
		GlueDialogButton2:Show();
		GlueDialogButton3:Hide();

		if ( dialogInfo.displayVertical ) then
			GlueDialogButton2:SetPoint("BOTTOM", "GlueDialogBackground", "BOTTOM", 0, dVBorderSpace);
			GlueDialogButton1:SetPoint("BOTTOM", "GlueDialogButton2", "TOP", 0, bVSpace);
		else
			dHBorderSpace = (GlueDialogBackground:GetWidth() - GlueDialogButton1:GetWidth() - GlueDialogButton2:GetWidth() - bHSpace) / 2;
			GlueDialogButton2:SetPoint("BOTTOMRIGHT", "GlueDialogBackground", "BOTTOMRIGHT", -dHBorderSpace, dVBorderSpace);
			GlueDialogButton1:SetPoint("RIGHT", "GlueDialogButton2", "LEFT", -bHSpace, 0);
		end
	else
		GlueDialogButton1:SetPoint("BOTTOM", "GlueDialogBackground", "BOTTOM", 0, dVBorderSpace);
		GlueDialogButton2:Hide();
		GlueDialogButton3:Hide();
	end

	-- Show or hide the alert icon
	-- GlueDialogAlertIcon:SetPoint("TOPLEFT", "GlueDialogBackground", "TOPLEFT", 16, ( -textHeight + GlueDialogAlertIcon:GetHeight()) / 2 - 16);
	if ( dialogInfo.showAlert ) then
		GlueDialogText:SetPoint("TOPRIGHT", "GlueDialogBackground", "TOPRIGHT", -16, -16);
		GlueDialogAlertIcon:Show();
		GlueDialogAlertIcon:SetPoint("TOPLEFT", "GlueDialogBackground", "TOPLEFT", 16, ( -textHeight + GlueDialogAlertIcon:GetHeight()) / 2 - 16);
	else
		GlueDialogText:SetPoint("TOP", "GlueDialogBackground", "TOP", 0, -16);
		GlueDialogAlertIcon:Hide();
	end

	GlueFrameFadeIn(GlueDialog, VX_FADE_REFRESH, GlueDialog:Show());
end

function GlueDialog_OnLoad(self)
	self:RegisterEvent("OPEN_STATUS_DIALOG");
	self:RegisterEvent("UPDATE_STATUS_DIALOG");
	self:RegisterEvent("CLOSE_STATUS_DIALOG");
	GlueDialogText.origWidth = GlueDialogText:GetWidth();
	GlueDialogBackground.origWidth = GlueDialogBackground:GetWidth();
	GlueDialogBackground.alertWidth = 64;
	hooksecurefunc(GlueDialogHTML, "SetText", function(self, txt) vx_HTMLText = txt end);
end

function GlueDialog_OnShow(self)
	local OnShow = GlueDialogTypes[self.which].OnShow;
	if ( OnShow ) then
		OnShow();
	end
end

function GlueDialog_OnUpdate(self, elapsed)
	for i=1, MAX_NUM_GLUE_DIALOG_BUTTONS do
		button = _G[ "GlueDialogButton"..i ];
		--if ( button and (CURRENT_GLUE_SCREEN == "login") or (CURRENT_GLUE_SCREEN == "realmwizard") or CURRENT_GLUE_SCREEN == "movie" ) then
		--	button:SetNormalTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Up-Blue");
		--	button:SetPushedTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Down-Blue");
		--	button:SetHighlightTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Highlight-Blue");
		--else
		--	button:SetNormalTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Up");
		--	button:SetPushedTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Down");
		--	button:SetHighlightTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Highlight");
		--end
	end
end

function GlueDialog_OnEvent(self, event, arg1, arg2, arg3)
	if ( event == "OPEN_STATUS_DIALOG" ) then
		GlueDialog_Show(arg1, arg2, arg3);
	elseif ( event == "UPDATE_STATUS_DIALOG" and arg1 and (strlen(arg1) > 0) ) then
		GlueDialogText:SetText(arg1);
		local buttonText = nil;
		if ( arg2 ) then
			buttonText = arg2;
		elseif ( GlueDialogTypes[GlueDialog.which] ) then
			buttonText = GlueDialogTypes[GlueDialog.which].button1;
		end
		if ( buttonText ) then
			GlueDialogButton1:SetText(buttonText);
		end
		GlueDialogBackground:SetHeight(32 + GlueDialogText:GetHeight() + 8 + GlueDialogButton1:GetHeight() + 16);
		-- GlueDialogBackground:SetWidth(GlueDialogText:GetWidth()+32)
	elseif ( event == "CLOSE_STATUS_DIALOG" ) then
		GlueFrameFadeOut(GlueDialog, VX_FADE_REFRESH, "HIDE");
		--GlueDialog:Hide();
	end
end

function GlueDialog_OnHide()
	GlueFrameFadeOut(GlueDialog, VX_FADE_REFRESH, "HIDE");
--	PlaySound("igMainMenuClose");
end

function GlueDialog_OnClick(index)
	--GlueDialog:Hide();
	if ( index == 1 ) then
		local OnAccept = GlueDialogTypes[GlueDialog.which].OnAccept;
		if ( OnAccept ) then
			OnAccept();
		end
	elseif ( index == 2 ) then
		local OnCancel = GlueDialogTypes[GlueDialog.which].OnCancel;
		if ( OnCancel ) then
			--GlueFrameFadeIn(GlueDialog, 0.55, OnCancel());
			OnCancel();
		end
	elseif ( index == 3 ) then
		local OnAlt = GlueDialogTypes[GlueDialog.which].OnAlt;
		if ( OnAlt ) then
			OnAlt();
		end
	end
	GlueFrameFadeOut(GlueDialog, VX_FADE_REFRESH, "HIDE");
	PlaySound("gsTitleOptionOK");
end

function GlueDialog_OnKeyDown(key)
	if ( key == "PRINTSCREEN" ) then
		Screenshot();
		return;
	end

	local info = GlueDialogTypes[GlueDialog.which];
	if ( not info or info.ignoreKeys ) then
		return;
	end

	if ( info and info.escapeHides ) then
		if ( info.hideSound ) then
			PlaySound(info.hideSound);
		end
		GlueFrameFadeOut(GlueDialog, VX_FADE_REFRESH, "HIDE");
		--GlueDialog:Hide();
	elseif ( key == "ESCAPE" ) then
		if ( GlueDialogButton2:IsShown() ) then
			GlueDialogButton2:Click();
		else
			GlueDialogButton1:Click();
		end
		if ( info.hideSound ) then
			PlaySound(info.hideSound);
		end
	elseif (key == "ENTER" ) then
		GlueDialogButton1:Click();
		if ( info.hideSound ) then
			PlaySound(info.hideSound);
		end
	end
end
