function textInputMenu(originalBGImage, message, defaultText)
	local ovImg={}
	ovImg["main"]=Image.load("images/menus/text_input.png")
	ovImg["bg_grey"]=Image.load("images/menus/text_input_letter_bg_grey.png")
	ovImg["bg_white"]=Image.load("images/menus/text_input_letter_bg_white.png")
	
	if defaultText==nil then
		defaultText=""
	end
	
	local lines=cutString(defaultText, "\n")
	local textTable={}
	
	local cursorLine=1
	local cursorCol=1
	
	
	for l=1,2 do
		local i=1
		textTable[l]={}
		while lines[l]~="" and lines[l]~=nil do
			textTable[l][i]=string.byte(string.sub(lines[l], 1, 1))
			lines[l]=string.sub(lines[l],2)
			i=i+1
		end
		
		--padding up to 10
		for j=i,10 do
			textTable[l][j]=string.byte(" ")
		end
	end
	
	drawTextInputMenu(screen, originalBGImage, ovImg, message, textTable, cursorLine, cursorCol)
	
	while true do
		updateInputs(Controls.read())
		
		if inputFirstPress("left") or inputIsRepeating("left") then
			if cursorCol>1 then
				cursorCol=cursorCol-1
			elseif cursorLine==2 then
				cursorLine=1
				cursorCol=10
			end
			drawTextInputMenu(screen, originalBGImage, ovImg, message, textTable, cursorLine, cursorCol)
		elseif inputFirstPress("right") or inputIsRepeating("right") then
			if cursorCol<10 then
				cursorCol=cursorCol+1
			elseif cursorLine==1 then
				cursorLine=2
				cursorCol=1
			end
			drawTextInputMenu(screen, originalBGImage, ovImg, message, textTable, cursorLine, cursorCol)
		elseif inputFirstPress("up") or inputIsRepeating("up") then
			if textTable[cursorLine][cursorCol]==46 then
				--textTable[cursorLine][cursorCol]=48 STOP
			elseif textTable[cursorLine][cursorCol]==91 then
				textTable[cursorLine][cursorCol]=93
			elseif textTable[cursorLine][cursorCol]==93 then
				textTable[cursorLine][cursorCol]=32
			elseif textTable[cursorLine][cursorCol]==122 then
				textTable[cursorLine][cursorCol]=65
			elseif textTable[cursorLine][cursorCol]==57 then
				textTable[cursorLine][cursorCol]=97
			else
				textTable[cursorLine][cursorCol]=textTable[cursorLine][cursorCol]+1
			end
			drawTextInputMenu(screen, originalBGImage, ovImg, message, textTable, cursorLine, cursorCol)
		elseif inputFirstPress("down") or inputIsRepeating("down") then
			if textTable[cursorLine][cursorCol]==97 then
				textTable[cursorLine][cursorCol]=57
			elseif textTable[cursorLine][cursorCol]==65 then
				textTable[cursorLine][cursorCol]=122
			elseif textTable[cursorLine][cursorCol]==93 then
				textTable[cursorLine][cursorCol]=91
			elseif textTable[cursorLine][cursorCol]==48 then
				--textTable[cursorLine][cursorCol]=46 STOP
			elseif textTable[cursorLine][cursorCol]==32 then
				textTable[cursorLine][cursorCol]=93
			else
				textTable[cursorLine][cursorCol]=textTable[cursorLine][cursorCol]-1
			end
			drawTextInputMenu(screen, originalBGImage, ovImg, message, textTable, cursorLine, cursorCol)
		elseif inputFirstPress("triangle") then
			if textTable[cursorLine][cursorCol]>=65 and textTable[cursorLine][cursorCol]<=90 then -- A-Z
				textTable[cursorLine][cursorCol]=textTable[cursorLine][cursorCol]+32
			elseif textTable[cursorLine][cursorCol]>=97 and textTable[cursorLine][cursorCol]<=122 then -- a-z
				textTable[cursorLine][cursorCol]=textTable[cursorLine][cursorCol]-32
			end
			drawTextInputMenu(screen, originalBGImage, ovImg, message, textTable, cursorLine, cursorCol)
		elseif inputFirstPress("square") or inputIsRepeating("square") then
			textTable[cursorLine][cursorCol]=32 --space
			if cursorCol>1 then
				cursorCol=cursorCol-1
			else --cursorCol=1
				if cursorLine==2 then
					cursorLine=1
					cursorCol=10
				end
			end
			drawTextInputMenu(screen, originalBGImage, ovImg, message, textTable, cursorLine, cursorCol)
		elseif inputFirstPress("cross") or inputIsRepeating("cross") then
			local n=textTable[cursorLine][cursorCol]
			if cursorCol<10 then
				cursorCol=cursorCol+1
			else --cursorCol=10
				if cursorLine==1 then
					cursorLine=2
					cursorCol=1
				end
			end
			textTable[cursorLine][cursorCol]=n
			drawTextInputMenu(screen, originalBGImage, ovImg, message, textTable, cursorLine, cursorCol)
		elseif inputFirstPress("circle") then
			--screen.waitVblankStart(20)
			local ret1=""
			local ret2=""
			for i=1,10 do
				ret1=ret1..string.char(textTable[1][i])
				ret2=ret2..string.char(textTable[2][i])
			end
			ret1=trim(ret1)
			ret2=trim(ret2)
			return ret1.."\n"..ret2
		end
		
	end
	
end

function drawTextInputMenu(target, originalBGImage, ovImg, message, textTable, cursorLine, cursorCol)
	local x=138+10
	local y=74+10
	
	target:blit(0, 0, originalBGImage, true)
	target:blit(0, 0, ovImg["main"], true)
	
	for i=1,10 do
		--line 1
		if cursorLine==1 and cursorCol==i then
			target:blit(x+(i-1)*14+20, y+50, ovImg["bg_white"], true)
		else
			target:blit(x+(i-1)*14+20, y+50, ovImg["bg_grey"], true)
		end
		printU(target, x+(i-1)*14+2+20, y+10+50, string.char(textTable[1][i]), white, false, "default", 11, 11, 14, black)
		
		--line 2
		if cursorLine==2 and cursorCol==i then
			target:blit(x+(i-1)*14+20, y+18+50, ovImg["bg_white"], true)
		else
			target:blit(x+(i-1)*14+20, y+18+50, ovImg["bg_grey"], true)
		end
		printU(target, x+(i-1)*14+2+20, y+28+50, string.char(textTable[2][i]), white, false, "default", 11, 11, 14, black)
	end
	
	--target:print(x, y+100, textTable[1][1], white)
	printWithCR(target, x, y, message, white, 8, black)
	
	screen.flip()
	screen.waitVblankStart()
end

























