function standard_generic_handler(window, action, widget)
	if action=='over' then
		play_sound("sound_gui_over")
	elseif action=='disabled' then
		play_sound("sound_gui_disabled")
	elseif action=='pressed' then
		play_sound("sound_gui_click")
	elseif action=="checked" then
		play_sound("sound_gui_click")
	end
end

-------------------------------------------------------------------------------------------------

function on_switch_screen_mode()
	if not g_State then return end

	default_state_init(g_State)
end

-------------------------------------------------------------------------------------------------

function default_state_generic_handler(window, action, widget)
	standard_generic_handler(window, action, widget)

	if action=="pressed" then
		if widget:GetId()=="close" then
			quit_game()
		elseif widget:GetId()=="windowed" then
			g_App:SwitchScreenMode(true, g_App:Is3DAccelerated(), false)
		elseif widget:GetId()=="minimize" then
			g_App:Minimize()
		end
	end

end

-------------------------------------------------------------------------------------------------

function default_state_init(window)
	local ids = {"close", "minimize", "windowed"}
	local i = table.getn(ids)
	while i>=1 do
		local w = window:GetWidget(ids[i])
		w:Hide(g_App.mIsWindowed)
		w:Disable(g_App.mIsWindowed)

		if ids[i]=="windowed" and g_App.mForceWindowed then ConvertToCButtonWidget(w):DisableButton(true) end
		i = i - 1
	end
end

-------------------------------------------------------------------------------------------------

function nag_window_generic_handler(window, action, widget)
	standard_generic_handler(window, action, widget)
	if action=="pressed" then
		if widget:GetId()=="later" then
			quit_game()
		elseif widget:GetId()=="buy" then
			ShellExecute("registrator.exe", "0 3")
			quit_game()
		end
	end
end

-------------------------------------------------------------------------------------------------

function bubble_help_generic_handler(hint, action, widget)
	standard_generic_handler(hint, action, widget)

	if action=='pressed' and widget:GetId()=="close" then
		hint:Close()
		pause_game(false)
	end
end

-------------------------------------------------------------------------------------------------

function level_travel_generic_handler(window, action, widget)
	if action=="pressed" then
		if widget:GetId()=="ok" then
			local edit = ConvertToCEditWidget(window:GetWidget("edit"))
			if edit then
				local level = tonumber(edit:GetText())
				if not level then return end
				g_Player:SetLevel(level)
				init_level(g_Player:GetLevel())
				window:Close()
			end
		elseif widget:GetId()=="cancel" then
			window:Close()
		end
	end
end

-------------------------------------------------------------------------------------------------

function level_travel_on_key(window, key, state)
	if key==27 then
		window:Close()
	elseif key==13 then
		local edit = ConvertToCEditWidget(window:GetWidget("edit"))
		if edit then
			local level = tonumber(edit:GetText())
			if not level then return end
			g_Player:SetLevel(level)
			init_level(g_Player:GetLevel())
			window:Close()
		end
	end
end