function MoveChooseTankPanels(where, reportArrivalTo, arrivalMessage)
	SendMessage("Choose tank mover", "report arrival to "..reportArrivalTo)
	SendMessage("Choose tank mover", "set arrival message "..arrivalMessage)
	SendMessage("Choose tank mover", "move to "..where)
end

function MoveMainScreenPanels(where)
	SendMessage("Right top panel mover", "move to "..where)
	SendMessage("Left top panel mover", "move to "..where)
	SendMessage("Play panel mover", "move to "..where)
	
	if IsReceiver("Main screen shop_thoose panel mover") then
		SendMessage("Main screen shop_thoose panel mover", "move to "..where)
	elseif IsReceiver("Shop mover") then
		SendMessage("Shop mover", "move to "..where)
	end
end

function ChooseTankFunc(message)
	if "Choose tank tank pressed " == string.sub(message, 1, 25) then
	    local coma = string.find(message,',')
		local newTank = string.sub(message, 26, coma-1)
		newPositionTank = string.sub(message, coma+1) --глобальная переменная в Lua
		local currentTank = PermanentStorage.GetLocalString("Current Tank")

		SendMessage("Choose tank mover", "move to out")
		SendMessage("PlayPanel modal dialog", "hide")
		SendMessage("Screen", "template ZGlassTemplate")
		SendMessage("Screen", "create top instance")

		SendMessage("post:lua:ChooseTankFunc", "create enter effect")

		if(newTank ~= currentTank) then
			PermanentStorage.SetLocalString("Current Tank", newTank)
			SendMessage("Aquarium bottom", "Change Aquarium")
			SendMessage("CupRenderElement", "Reset")
			SwitchTrack()
			changeTank = true --глобальная переменная в Lua
		end

	elseif message == "create enter effect" then
		SendMessage("CSVSTATISTICS", "switch tank")
		SendMessage("Screen", "clear children list")
		SendMessage("Screen", "template EnterEffectTemplate")
		local param = {
		--{X1,  Y1} { X2,  Y2}
	    {{179, 384},{415, 370},},  -- from 1 window
		{{397, 384},{400, 400},},  -- from 2 window
		{{615, 384},{385, 370},}, }-- from 3 window
		for i,point in ipairs(param[newPositionTank+1]) do
		    SendMessage("Screen", "defineText [x"..i.."] "..point[1])
		    SendMessage("Screen", "defineText [y"..i.."] "..point[2])
		end
		
		param = {-1, 1000, -439}
		if changeTank then
		    SendMessage("Screen", "defineText [xTexturePanel] -100")
		    SendMessage("Screen", "defineText [texturePanel] choose_tank_item_back_normal")
		    SendMessage("Screen", "defineText [xTexturePanelShadow] "..param[newPositionTank+1])
		    changeTank = nil --уничтожаем глобальную переменную
		else
		    SendMessage("Screen", "defineText [xTexturePanel] 1000")
			SendMessage("Screen", "defineText [texturePanel] choose_tank_item_back_active")
			SendMessage("Screen", "defineText [xTexturePanelShadow] "..param[2])
		end
		
		newPositionTank = nil --уничтожаем глобальную переменную

		SendMessage("Screen", "create top instance")

	elseif message == "End enter effect" then
		MainScreenFunc("Enter main screen")

	elseif message == "Choose tank cancel button pressed" then

		SendMessage("Choose tank mover", "move to out")
		SendMessage("PlayPanel modal dialog", "hide")
		SendMessage("TimedSMS", "lua:ChooseTankFunc, Choose tank cancel button pressed continue, 0.25")
		LockScreen()
	
	elseif message == "Choose tank cancel button pressed continue" then

		PostUnlockScreen()
		SendMessage("Cup alpha changer", "change alpha to 1.0")
		MoveMainScreenPanels("in")
	
	elseif  message == "ChooseTank delete tank button pressed" then	
		
		local image = PermanentStorage.GetLocalIntOrDef("ChooseTank preview", -1)
		if (image ~= -1) then
			local currentTank = PermanentStorage.GetLocalString("Current Tank")
			local full_ver = PermanentStorage.GetGlobalStringOrDef("temp:Ver", "Full") == "Full"
			if (image <= 3 or image == tonumber(currentTank)) then
			    if full_ver then
					ChooseTankOkDialog("YouCannotDeleteThis")
				else
				    ChooseTankOkDialog("YouCannotDeleteThis") --заменить текст
				end
			else
				ChooseTankYesNoDialog("DeleteTank", "Tank delete confirm", "Tank delete reject")
			end
		end		
	
	elseif  message == "Tank delete confirm" then	
		
		local image = PermanentStorage.GetLocalIntOrDef("ChooseTank preview", -1)		
		if (image ~= -1) then
			SendMessage("ChooseTank scroll", "Delete tank "..image);
		end
		SendMessage(getModalDialog(), "hide")
	
	elseif  message == "Tank delete reject" then
		
		SendMessage(getModalDialog(), "hide")
	
	--
	-- Изменение имени аквариума
	--
	elseif message == "ChooseTank rename tank button pressed" then
		local currentTank = PermanentStorage.GetLocalIntOrDef("ChooseTank preview", -1)
		if (currentTank ~= -1) then
			local oldTankName = PermanentStorage.GetLocalStringOrDef("Tank "..currentTank.." name", "")
			if (oldTankName == "") then
				oldTankName = ResourceManager.GetString("Tank"..currentTank.."DefaultName");
			end
			if (oldTankName ~= "") then
				EditBoxDialog(getModalDialog(), "Tank name edit"
						, "EnterTankName"
						, 130
						, "lua:ChooseTankFunc" 
						, "Enter tank name dialog ok pressed"
						, "Enter tank name dialog cancel pressed" )
				SendMessage("EditBoxDialogMover", "move to in")
				SendMessage("Tank name edit", "set value "..oldTankName)
			end
		end
	
	--
	-- Подтверждение изменения имени
	--
	elseif message == "Enter tank name dialog ok pressed" then
		local currentTank = PermanentStorage.GetLocalIntOrDef("ChooseTank preview", -1)
		if (currentTank ~= -1) then
			local newTankName = SendMessageReply("Tank name edit", "get value")
			-- Если в строке нет ни одного непустого символа, выйти
			if string.find(newTankName, "[%S]") == nil then
				return
			end
			PermanentStorage.SetLocalString("Tank "..currentTank.." name", newTankName);
			SendMessage("ChooseTank scroll", "Reset titles");
		end
		SendMessage("EditBoxDialogMover", "move to out")
		SendMessage(getModalDialog(), "hide")
	
	--
	-- Отмена изменения имени
	--
	elseif message == "Enter tank name dialog cancel pressed" then
		SendMessage("EditBoxDialogMover", "move to out")
		SendMessage(getModalDialog(), "hide")
	
	--
	-- Вызов окна покупки аквариума
	--
	elseif message == "ChooseTank buy button pressed" then
	
		local cup
		local full_ver = PermanentStorage.GetGlobalStringOrDef("temp:Ver", "Full") == "Full"
		if full_ver then
			cup = PermanentStorage.GetLocalStringOrDef("1 Cup", "None") == "Gold" and
			      PermanentStorage.GetLocalStringOrDef("2 Cup", "None") == "Gold" and
			      PermanentStorage.GetLocalStringOrDef("3 Cup", "None") == "Gold"
		else
			local tankId = PermanentStorage.GetGlobalString("temp:Ver")
			assert(tankId == "1" or tankId == "2" or tankId == "3")
			cup = PermanentStorage.GetLocalStringOrDef(tankId.." Cup", "None") ~= "None"
		end
		
		if (cup == true) then
			SendMessage("Left top panel mover", "move to out")
			SendMessage("Choose tank mover", "report arrival to lua:ChooseTankFunc")
			SendMessage("Choose tank mover", "set arrival message ChooseTank buy button pressed continue")
			SendMessage("Choose tank mover", "move to out")
			LockScreen()
		else
		    ChooseTankOkDialog("YouNeedHaveThreeCups")
		end
	
	elseif message == "ChooseTank buy button pressed continue" then
	
		PostUnlockScreen()
		local type = PermanentStorage.GetGlobalStringOrDef("temp:Ver", "Full")
		if type == "Full" then
			SendMessage("NewTankModalDialog", "instantiate BuyTankTemplate")
			SendMessage("Choose tank done panel mover", "move to in")
		else
		    local modalDialog = getModalDialog()
			PermanentStorage.SetLocalString("temp:BuyTankName", PermanentStorage.GetLocalString("Tank "..type.." name"))
			SendMessage(modalDialog, "template BuyTankHolidayTemplate")
			SendMessage(modalDialog, "defineText [price] hack:"..ResourceManager.GetString("MoneyPrefix")..getPriceTank()..ResourceManager.GetString("MoneySuffix"))
			SendMessage(modalDialog, "create instance")
		end
	
	--
	-- Покупка аквариума
	--
	elseif message == "Buy tank button pressed" then
		
		SendMessage("CSVSTATISTICS", "buy tank pressed")
	
		local tankId = PermanentStorage.GetLocalInt("temp:BuyTank current tank")
		assert(tankId >= 1 and tankId <= 4)
		
		local moneyAmount = PermanentStorage.GetLocalInt("Money")
		local tankPrice = PermanentStorage.GetLocalInt(tankId.." Tank Price")
		
		-- Проверить, достаточно ли денег на счёте
		if (moneyAmount < tankPrice) then
   			OkDialog(getModalDialog(),
   						210, 
   						"YouHaveNoSuchMoney",
   						getModalDialog(),
   						"hide")
		else
			PermanentStorage.SetLocalString("temp:BuyTankName", ResourceManager.GetString("Tank"..tankId.."DefaultName"))
			PermanentStorage.SetLocalString("temp:BuyTankPrice", ResourceManager.GetString("MoneyPrefix")..tankPrice..ResourceManager.GetString("MoneySuffix"))
			BuyTankYesNoDialog("BuyTank confirm buy", "BuyTank reject buy")
		end
	
	--
	-- Подтверждение покупки аквариума
	--
	elseif message == "BuyTank confirm buy" then
	
		SendMessage("Choose tank new", "hide")
		
		local tankId = PermanentStorage.GetLocalInt("temp:BuyTank current tank")
		local moneyAmount = PermanentStorage.GetLocalInt("Money")
		local tankPrice = PermanentStorage.GetLocalInt(tankId.." Tank Price")

		-- Списать деньги
		PermanentStorage.SetLocalInt("Money", moneyAmount - tankPrice)
		-- Послать сообщение окну выбора аквариума для добавления аквариума
		SendMessage("ChooseTank scroll", "Add tank "..tankId)
		
		SendMessage("lua:ChooseTankFunc", "BuyTank exit")
	
	--
	-- Отказ от покупки аквариума
	--
	elseif message == "BuyTank reject buy" then
	
		SendMessage("Choose tank new", "hide")
	
	--
	-- Выход из окна покупки аквариума
	--
	elseif message == "BuyTank exit" then

		if PermanentStorage.GetGlobalStringOrDef("temp:Ver", "Full") == "Full" then
			SendMessage("Choose tank done panel mover", "move to out")
			SendMessage("NewTankModalDialog", "hide")
		else
			SendMessage(getModalDialog(), "hide")
		end
		SendMessage("TimedSMS", "lua:ChooseTankFunc, BuyTank exit continue, 0.5")
		LockScreen()
	
	elseif message == "BuyTank exit continue" then
	
		PostUnlockScreen()
		SendMessage("Left top panel mover", "move to in")
		SendMessage("Choose tank mover", "move to in")
	
	elseif PermanentStorage.GetGlobalBool("temp:dev") and message == "All Tank Unlock" then
	
		PermanentStorage.SetLocalString("1 Cup", "Gold")
		PermanentStorage.SetLocalString("2 Cup", "Gold")
		PermanentStorage.SetLocalString("3 Cup", "Gold")

	--
	-- Подтверждения покупки (для неполной версии)
	--
	elseif message == "BuyTank from HolidayTemplate" then

	    if PermanentStorage.GetLocalInt("Money") < getPriceTank() then
   			OkDialog("BuyTankModalDialog", 
   						210, 
   						"YouHaveNoSuchMoney",
   						"BuyTankModalDialog",
   						"hide")
   			return
		end
		local tankId = PermanentStorage.GetGlobalString("temp:Ver")
		assert(tankId == "1" or tankId == "2" or tankId == "3")
		local moneyAmount = PermanentStorage.GetLocalInt("Money")
		-- Списать деньги
		PermanentStorage.SetLocalInt("Money", moneyAmount - getPriceTank())
		-- Послать сообщение окну выбора аквариума для добавления аквариума
		SendMessage("ChooseTank scroll", "Add tank "..tankId)
		SendMessage("lua:ChooseTankFunc", "BuyTank exit")
	--
	-- Кликнули по заблокированному аквариуму
	--
	elseif message == "ChooseTank tank is locked" then
		
		ChooseTankOkDialog("ThisTankIsLocked")
	
	--
	-- Закрытие любого окна с сообщением
	--
	elseif message == "Message box ok button pressed" then
		
		SendMessage(getModalDialog(), "hide")
	
	elseif message == "Effect started" then
	
		LockScreen()
		SendMessage("TimedSMS", "lua:ChooseTankFunc, Effect started continue, 2.0")
	
	elseif message == "Effect started continue" then
	
		PostUnlockScreen()
		
	else
		assert(false, "Unknown message "..message)
	end
end

function getPriceTank(idTank)
	if not idTank then
	    return 2000
	else
	    if idTank == 1 then return 2000 end
	    if idTank == 2 then return 2100 end
	    if idTank == 3 then return 2200 end
		assert(false)
	end
end