tournamentSureQuit_options = {"YES", "NO"}
tournamentSureQuit_numOptions = 2
tournamentSureQuit_alreadyPressed = 0

tournamentSureQuit_restart = 0


function tournamentSureQuit_onAfterDestroyPopup()
	if tournamentSureQuit_restart == 1 then
		cfunction("exitScriptSystem",UIReturnCodes["TOURNAMENT_RESTART"])
	else
		cfunction("exitScriptSystem",UIReturnCodes["TOURNAMENT_EXIT"])
	end
end

function tournamentSureQuit_afterPopupClosed()
	if tournamentSureQuit_curSel == 1 then
		destroyPopup("tournamentSureQuit_onAfterDestroyPopup", PopupOptions["FADETOLOADING"])
		cfunction("callCPPFunction", "fadeSound", "0", 0)
	elseif tournamentSureQuit_curSel == 2 then
		cfunction("transitionToState", "tournamentProceedQuestion")	
	end
end
	
function tournamentSureQuit_onSubmitPressed()
	if tournamentSureQuit_alreadyPressed == 0  then
		cfunction("showFontOverlay", "menu_content", 0, 100, 0, 100)
		closePopupWindow("tournamentSureQuit_afterPopupClosed")
		tournamentSureQuit_alreadyPressed = 1
	end
end

function tournamentSureQuit_onCancelPressed()
	if tournamentSureQuit_alreadyPressed == 0  then
		cfunction("showFontOverlay", "menu_content", 0, 100, 0, 100)
		closePopupWindow("tournamentSureQuit_afterPopupClosed")
		tournamentSureQuit_alreadyPressed = 1
		tournamentSureQuit_curSel = 2
	end
end


function tournamentSureQuit_onLeaveState()	
end

function tournamentSureQuit_onEnterState()
	--cfunction("debugPrintF", "tournamentSureQuit_onEnterState", 0)
	cfunction("enableInput", 0)
	tournamentSureQuit_curSel = 1
	tournamentSureQuit_alreadyPressed = 0	
	openPopupWindow("tournamentSureQuit_showContentAfterOpening", 2.5)	
end

function tournamentSureQuit_showContentAfterOpening()
	--cfunction("showBitmapOverlay", "EndOfGameOptions", 1, 100, 240-32, 136-16)	
	cfunction("showFontOverlay", "menu_content", 1, 100, 0, 100)
	cfunction("enableInput", 1)
	tournamentSureQuit_setSelectionCursor()
end


function tournamentSureQuit_onDownPressed()
	if tournamentSureQuit_alreadyPressed == 0  then
		tournamentSureQuit_curSel = tournamentSureQuit_curSel +1
		if tournamentSureQuit_curSel ==3 then 
			tournamentSureQuit_curSel =1
		end
		tournamentSureQuit_setSelectionCursor()
	end
end

function tournamentSureQuit_onUpPressed()
	if tournamentSureQuit_alreadyPressed == 0  then
		tournamentSureQuit_curSel = tournamentSureQuit_curSel -1
		if tournamentSureQuit_curSel ==0 then 
			tournamentSureQuit_curSel = 2
		end
		tournamentSureQuit_setSelectionCursor()
	end		
end

function tournamentSureQuit_setSelectionCursor()
	xText = ""
	for i = 1, tournamentSureQuit_numOptions do
		xText = xText .. '\05'
		if tournamentSureQuit_curSel == i then
			xText = xText .. "@  "
		end
		xText = xText .. tournamentSureQuit_options[i]
		if tournamentSureQuit_curSel == i then
			xText = xText .. "  @"
		end
		xText = xText .. "\n"
	end
	
	addText = ""
	if tournamentSureQuit_restart == 1 then
		addText = "ARE YOU SURE YOU WANT TO RESTART THIS TOURNAMENT\n\n"
	else
        addText = "ARE YOU SURE YOU WANT TO EXIT THIS TOURNAMENT\n\n"
	end
	
	xText = addText..xText
	
	xText = xText.."\n\nYOUR PROGRESS\nIN THIS TOURNAMENT WILL BE LOST"
	
	cfunction("setFontOverlayText", "menu_content", xText)
end
