function OkDialog(modalDialog, y, resourceName, msgReceiver, okMsg)
	SendMessage(modalDialog, "template OkDialogTemplate")
	SendMessage(modalDialog, "defineText [dialogY] "..y)
	SendMessage(modalDialog, "defineText [resourceName] "..resourceName)
	SendMessage(modalDialog, "defineText [dialogMessageReceiver] "..msgReceiver)
	SendMessage(modalDialog, "defineText [dialogMessage] "..okMsg)
	SendMessage(modalDialog, "create instance")
end

function YesNoDialog(modalDialog, resourceName, msgReceiver, yesMsg, noMsg)
	SendMessage(modalDialog, "template YesNoDialogTemplate")
	SendMessage(modalDialog, "defineText [resourceName] "..resourceName)
	SendMessage(modalDialog, "defineText [dialogMessageReceiver] "..msgReceiver)
	SendMessage(modalDialog, "defineText [yesMessage] "..yesMsg)
	SendMessage(modalDialog, "defineText [noMessage] "..noMsg)
	SendMessage(modalDialog, "create instance")
end

function EditBoxDialog(modalDialog, editName, resourceName, width, msgReceiver, okMsg, cancelMsg)
	SendMessage(modalDialog, "template TwoButtonsEditDialogTemplate")
	SendMessage(modalDialog, "defineText [editName] "..editName)
	SendMessage(modalDialog, "defineText [resourceName] "..resourceName)
	SendMessage(modalDialog, "defineText [editWidth] "..width)
	SendMessage(modalDialog, "defineText [dialogMessageReceiver] "..msgReceiver)
	SendMessage(modalDialog, "defineText [okMessage] "..okMsg)
	SendMessage(modalDialog, "defineText [cancelMessage] "..cancelMsg)
	SendMessage(modalDialog, "create instance")
end

function ChooseTankOkDialog(resourceName)
	local modalDialog = getModalDialog()
	SendMessage(modalDialog, "template OkDialogTemplate")
	SendMessage(modalDialog, "defineText [dialogY] 160")
	SendMessage(modalDialog, "defineText [resourceName] "..resourceName)
	SendMessage(modalDialog, "defineText [dialogMessageReceiver] lua:ChooseTankFunc")
	SendMessage(modalDialog, "defineText [dialogMessage] Message box ok button pressed")
	SendMessage(modalDialog, "create instance")
end

function ChooseTankYesNoDialog(resourceName, yesMsg, noMsg)
	local modalDialog = getModalDialog()
	SendMessage(modalDialog, "template YesNoDialogTemplate")
	SendMessage(modalDialog, "defineText [resourceName] "..resourceName)
	SendMessage(modalDialog, "defineText [dialogMessageReceiver] lua:ChooseTankFunc")
	SendMessage(modalDialog, "defineText [yesMessage] "..yesMsg)
	SendMessage(modalDialog, "defineText [noMessage] "..noMsg)
	SendMessage(modalDialog, "create instance")
	Sound:PlaySample("window_moving")
end

function BuyTankYesNoDialog(yesMsg, noMsg)
	local modalDialog = "Choose tank new"
	SendMessage(modalDialog, "template YesNoDialogTemplate")
	SendMessage(modalDialog, "defineText [resourceName] AreYouRealyWant")
	SendMessage(modalDialog, "defineText [dialogMessageReceiver] lua:ChooseTankFunc")
	SendMessage(modalDialog, "defineText [yesMessage] "..yesMsg)
	SendMessage(modalDialog, "defineText [noMessage] "..noMsg)
	SendMessage(modalDialog, "create instance")
	Sound:PlaySample("window_moving")
end

function TwoButtonCupDialog(headerResource, cupTextureId, textResource)
	local tankId   = PermanentStorage.GetLocalString("Current Tank")
	local tankType = PermanentStorage.GetLocalString(tankId.." Tank Type")
	local modalDialog = "Shop modal dialog"
	SendMessage(modalDialog, "template TwoButtonsWonCupTemplate")
	SendMessage(modalDialog, "defineText [headerResource] "..headerResource)
	SendMessage(modalDialog, "defineText [cupTextureId] tank"..tankType.."_"..cupTextureId)
	SendMessage(modalDialog, "defineText [textResource] "..textResource)
	SendMessage(modalDialog, "create instance")
	SendMessage("Cup panel mover", "move to in")
	--если показывается какая-либо подсказка, ее нужно убить
	if IsReceiver("ShopTips")       then SendMessage("ShopTips", "hide") end
	if IsReceiver("SpecialMessage") then SendMessage("SpecialMessage", "hide") end
end

function OptionsDialog(modalDialog, y, creditsMessage, creditsReceiver)
	SendMessage(modalDialog, "template OptionsDialogTemplate")
	SendMessage(modalDialog, "defineText [y] "..y)
	SendMessage(modalDialog, "defineText [creditsMessage] "..creditsMessage)
	SendMessage(modalDialog, "defineText [creditsReceiver] "..creditsReceiver)
	local tankType = PermanentStorage.GetLocalString(PermanentStorage.GetLocalString("Current Tank").." Tank Type")
	if     tankType == "1" then 
		SendMessage(modalDialog, "defineText [options_panel_background] ".."helloween_panel_background")		
		SendMessage(modalDialog, "defineText [Fish1] ".."Fish1")
		SendMessage(modalDialog, "defineText [Fish2] ".."Fish3")
		
	elseif tankType == "2" then
		SendMessage(modalDialog, "defineText [options_panel_background] ".."thanksgiving_panel_background")		
		SendMessage(modalDialog, "defineText [Fish1] ".."Fish2")
		SendMessage(modalDialog, "defineText [Fish2] ".."Fish3")
		
	elseif tankType == "3" then
		SendMessage(modalDialog, "defineText [options_panel_background] ".."christmas_panel_background")		
		SendMessage(modalDialog, "defineText [Fish1] ".."Fish1")
		SendMessage(modalDialog, "defineText [Fish2] ".."Fish6")
	end
	
	SendMessage(modalDialog, "create instance")
end

-- окно для редактора уровней
function EditorEditBoxDialog(modalDialog, editName, text, okMsg, cancelMsg)
	SendMessage(modalDialog, "template TwoButtonsEditDialogTemplate")
	SendMessage(modalDialog, "defineText [editName] "..editName)
	SendMessage(modalDialog, "defineText [resourceName] hack:"..text)
	SendMessage(modalDialog, "defineText [editWidth] 184")
	SendMessage(modalDialog, "defineText [dialogMessageReceiver] GameField")
	SendMessage(modalDialog, "defineText [okMessage] "..okMsg)
	SendMessage(modalDialog, "defineText [cancelMessage] "..cancelMsg)
	SendMessage(modalDialog, "create instance")
end

function ShowHelpSmall(textX, textY, textId, arrowX, arrowY, angle, visibleTime)
	local modalDialog = "SmallHelp layer"
	if type(textX) == "string" then
	    --используем функцию как приемник сообщений
	    local message = textX
	    if message == "remove ShowHelpSmall" then
	    	SendMessage(modalDialog, "clear children list")
	    	PermanentStorage.SetLocalBool("temp:NoContextHelp", false)  -- включили тултипы
		end
	else
	    PermanentStorage.SetLocalBool("temp:NoContextHelp", true) -- временно отключили тултипы
		local arrow       = "left"
		if not visibleTime then
		    visibleTime = 0
		end
		if -45 < angle and angle <= 45 then
			arrow = "right"
		elseif 45 < angle and angle <= 135 then
			arrow = "up"
		elseif 135 < angle and angle <= 225 then
			arrow = "left"
		else
			arrow = "down";
		end
		SendMessage(modalDialog, "clear children list")
		SendMessage(modalDialog, "template HelpSmallTemplate")
		SendMessage(modalDialog, "defineText [textX] "..textX)
		SendMessage(modalDialog, "defineText [textY] "..textY)
		SendMessage(modalDialog, "defineText [textId] "..textId)
		SendMessage(modalDialog, "defineText [arrowX] "..arrowX)
		SendMessage(modalDialog, "defineText [arrowY] "..arrowY)
		SendMessage(modalDialog, "defineText [angle] "..angle)
		SendMessage(modalDialog, "defineText [arrow] "..arrow)
		SendMessage(modalDialog, "defineText [visibleTime] "..visibleTime)
		SendMessage(modalDialog, "defineText [receiver] post:lua:ShowHelpSmall") --удалим шаблон HelpSmallTemplate
		SendMessage(modalDialog, "defineText [message] remove ShowHelpSmall")
		SendMessage(modalDialog, "create top instance")
		SendMessage("HelpSmall", "show")
	end
end