'##############
'EMAR105 Script
'##############

'(c) 15.04.2009 Rüdiger Hülsmann
'(c) 17.01.2011 Marcel Kuhnt
'(c) 04.07.2015 NightHauler

'Script Version: 1.0
'Omsi release: 1.0

'Needs:
'- ?

'Revision History:

'- NightHauler	04.07.2015		File created based on IBIS.osc (last revision 05.01.2011)

'--------------------------------------------------------------------------------




'----------------------
'	Trigger
'----------------------


{trigger:emar_btn1}
	1 (M.L.emar_input)
	1 (S.L.emar_btn1) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn1_off}
	0 (S.L.emar_btn1) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn2}
	2 (M.L.emar_input)
	1 (S.L.emar_btn2) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn2_off}
	0 (S.L.emar_btn2) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn3}
	3 (M.L.emar_input)
	1 (S.L.emar_btn3) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn3_off}
	0 (S.L.emar_btn3) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn4}
	4 (M.L.emar_input)
	1 (S.L.emar_btn4) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn4_off}
	0 (S.L.emar_btn4) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn5}
	5 (M.L.emar_input)
	1 (S.L.emar_btn5) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn5_off}
	0 (S.L.emar_btn5) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn6}
	6 (M.L.emar_input)
	1 (S.L.emar_btn6) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn6_off}
	0 (S.L.emar_btn6) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn7}
	7 (M.L.emar_input)
	1 (S.L.emar_btn7) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn7_off}
	0 (S.L.emar_btn7) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn8}
	8 (M.L.emar_input)
	1 (S.L.emar_btn8) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn8_off}
	0 (S.L.emar_btn8) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn9}
	9 (M.L.emar_input)
	1 (S.L.emar_btn9) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn9_off}
	0 (S.L.emar_btn9) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn0}
	0 (M.L.emar_input)
	1 (S.L.emar_btn0) s5
	(M.L.emar_button)
{end}

{trigger:emar_btn0_off}
	0 (S.L.emar_btn0) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnok}
	(M.L.emar_confirm)
	1 (S.L.emar_btnok) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnok_off}
	0 (S.L.emar_btnok) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnb}
	1 (S.L.emar_btnb) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnb_off}
	0 (S.L.emar_btnb) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnc}
	(L.L.emar_mode) 6 =
	{if}		
		5 (M.L.emar_modeselect)
	{else}
		(L.L.emar_mode) 7 =
		{if}
			(L.L.emar_menu_level) 1 =
			{if}
				0 (S.L.emar_menu_level)
				0 (S.L.emar_menu_selector2)
				0 (S.L.emar_menu_selector3)
			{else}
				(L.L.emar_menu_level) 2 =
				{if}
					1 (S.L.emar_menu_level)	
					0 (S.L.emar_menu_selector3)
					0 (S.L.emar_input) (S.L.emar_input_count)
				{else}
					0 (S.L.emar_menu_selector)
					0 (S.L.emar_menu_selector2)
					0 (S.L.emar_menu_selector3)
					(L.L.emar_ziel_mode)
					{if}
						3 (S.L.emar_mode)
					{else}
						(L.L.emar_mode_last) 2 =
						{if}
							2 (S.L.emar_mode)
						{else}
							(L.L.emar_mode_last) 3 =
							{if}
								3 (S.L.emar_mode)
							{else}
								5 (S.L.emar_mode)
							{endif}
						{endif}
					{endif}
					(M.L.emar_reset_display)
				{endif}
			{endif}
		{else}
			(L.L.emar_mode) 5 =
			{if}
				(L.L.emar_ticket_select) 0 >
				(L.L.emar_ticket_zonal) ! &&
				(L.L.emar_ticket_moneychange) ! &&
				(L.L.emar_ticket_sum) 0 > &&
				{if}
					-1 (S.L.emar_ticket_select)
				{else}
					(L.L.emar_ticket_moneychange) !
					(L.L.emar_ticket_zonal) ! &&
					(L.L.emar_ticket_sum) 0 > &&
					{if}
						0 (S.L.emar_ticket_sum)
					{endif}
				{endif}
			{endif}
			(M.L.emar_clear)
		{endif}
	{endif}
	1 (S.L.emar_btnc) s5
	(M.L.emar_button)
	
{end}

{trigger:emar_btnc_off}
	0 (S.L.emar_btnc) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnd}
	(L.L.emar_mode) 4 =
	(L.L.emar_mode) 5 = ||
	(L.L.emar_ziel_mode) ! &&
	{if}
		1 (S.L.emar_dest_change)
		0 (S.L.emar_from_change)
		(L.L.emar_input) (L.L.emar_RouteIndex) (M.V.GetBusstopCount) <=
		(L.L.emar_input) 0 > &&
		{if}
			(L.L.emar_input) 1 - (S.L.emar_terminus)
			(L.L.emar_busstop) (L.L.emar_terminus) >
			{if}
				(L.L.emar_terminus) (S.L.emar_busstop)
			{endif}
			0 (S.L.emar_input) (S.L.emar_input_count)
			0 (S.L.emar_ticket_sum)
		{else}
			0 (S.L.emar_input) (S.L.emar_input_count)
		{endif}
	{endif}
	1 (S.L.emar_btnd) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnd_off}
	0 (S.L.emar_btnd) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnk}
	(L.L.emar_mode) 3 =
	{if}
	(M.L.emar_SetRoute)
	"" (S.$.emar_t) (S.$.emar_s)
	(M.L.emar_reset_display)
	{else}
		(L.L.emar_mode) 4 =
		(L.L.emar_mode) 5 = ||
		{if}
			6 (M.L.emar_modeselect)
		{endif}
	{endif}
	1 (S.L.emar_btnk) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnk_off}
	0 (S.L.emar_btnk) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnm}
	(L.L.emar_mode) 7 = !
	{if}
		7 (M.L.emar_modeselect)
	{else}
		(L.L.emar_menu_level) 0 =
		{if}
			1 (S.L.emar_menu_level)
			0 (S.L.emar_menu_selector2)
		{else}
			2 (S.L.emar_menu_level)
			(M.L.emar_clear_disp)
		{endif}
	{endif}
	1 (S.L.emar_btnm) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnm_off}
	0 (S.L.emar_btnm) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnn}
	(L.L.emar_ticket_moneychange)
	{if}
		0 (S.L.emar_ticket_moneychange)
		0 (S.L.emar_input) (S.L.emar_input_count)
	{else}
		(L.L.emar_ticket_zonal)
		{if}
			0 (S.L.emar_ticket_zonal)
			-1 (M.L.emar_ticket_select)
		{else}
			0 (M.L.emar_ticket_select)
		{endif}
	{endif}
	1 (S.L.emar_btnn) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnn_off}
	0 (S.L.emar_btnn) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnu}
	3 (M.L.emar_ticket_select)
	1 (S.L.emar_btnu) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnu_off}
	0 (S.L.emar_btnu) s5
	(M.L.emar_button)
{end}

{trigger:emar_btns}
	(L.L.emar_mode) 6 =
	{if}
		"" (S.$.emar_t) (S.$.emar_s) (S.$.act_busstop) (S.$.emar_initial_name) (S.$.emar_terminus_name)
		0 (S.L.emar_RouteIndex) (S.L.emar_busstop_index) (S.L.emar_TerminusIndex) (S.L.emar_LinieKurs) 
		0 (S.L.emar_display_timer) (S.L.emar_display_counter)
		
		0 (S.L.emar_route_search) (S.L.emar_route_search_last)
		2 (M.L.emar_modeselect)
		1 (S.L.emar_route_operation)
		
		0 (S.L.emar_ticket_sum)
		
		0 (S.L.emar_ziel_mode) (S.L.emar_ziel)
		
		0 (S.L.emar_display_gen_mode)
		
		-1 (S.L.emar_TTbusstop)
	{else}
		(L.L.emar_mode) 4 =
		(L.L.emar_mode) 5 = ||
		(L.L.emar_ziel_mode) ! &&
		{if}
			1 (S.L.emar_from_change)
			(L.L.emar_input) (L.L.emar_RouteIndex) (M.V.GetBusstopCount) <=
			(L.L.emar_input) 0 > &&
			{if}
				(L.L.emar_input) 1 - (S.L.emar_busstop)
				(L.L.emar_busstop) (L.L.emar_terminus) >
				{if}
					(L.L.emar_busstop) (S.L.emar_terminus)
				{endif}
				0 (S.L.emar_input) (S.L.emar_input_count)
				0 (S.L.emar_ticket_sum)
			{else}
				0 (S.L.emar_input) (S.L.emar_input_count)
			{endif}
		{endif}
	{endif}
'	3 (M.L.emar_modeselect)
	1 (S.L.emar_btns) s5
	(M.L.emar_button)
{end}

{trigger:emar_btns_off}
	0 (S.L.emar_btns) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnz}
	(L.L.emar_mode) 5 =
	(L.L.emar_ticket_sum) 0 > &&
	{if}
		0 (S.L.emar_input) (S.L.emar_input_count)
		1 (S.L.emar_ticket_moneychange)
	{endif}
	1 (S.L.emar_btnz) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnz_off}
	0 (S.L.emar_btnz) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnx}
	(L.L.emar_mode) 5 =
	(L.L.emar_ticket_moneychange) ! &&
	{if}
		1 (S.L.emar_ticket_zonal)
		0 (S.L.emar_input) (S.L.emar_input_count)
	{endif}
	1 (S.L.emar_btnx) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnx_off}
	0 (S.L.emar_btnx) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnup}
	(L.L.emar_mode) 7 =
	{if}
		(L.L.emar_menu_level) 0 =
		{if}
			(L.L.emar_menu_selector) 0 >
			{if}
				(L.L.emar_menu_selector) 1 - (S.L.emar_menu_selector)
			{else}
				3 (S.L.emar_menu_selector)
			{endif}
		{else}	
			(L.L.emar_menu_level) 1 = 
			{if}
				(L.L.emar_menu_selector2) 0 >
				{if}
					(L.L.emar_menu_selector2) 1 - (S.L.emar_menu_selector2)
				{endif}
			{else}
				(L.L.emar_menu_selector3) 0 >
				{if}
					(L.L.emar_menu_selector3) 1 - (S.L.emar_menu_selector3)
				{endif}
			{endif}
		{endif}
	{else}
		(L.L.emar_mode) 2 =
		(L.L.emar_mode) 3 = ||
		{if}
			(L.L.emar_route_operation) -1 = !
			{if}
				(L.L.emar_route_search_last) (S.L.emar_route_search)
			{endif}
			2 (M.L.emar_modeselect)
			-1 (S.L.emar_route_operation)
		{else}
			(L.L.emar_from_change)
			{if}
				(L.L.emar_busstop) 0 >
				{if}
					(L.L.emar_busstop) 1 - (S.L.emar_busstop)
					0 (S.L.emar_ticket_sum)
				{else}
					(T.L.ev_emar_errorpiep)
				{endif}
			{else}
				(L.L.emar_dest_change)
				{if}
					(L.L.emar_terminus) 0 >
					{if}
						(L.L.emar_terminus) 1 - (S.L.emar_terminus)
						(L.L.emar_terminus) (L.L.emar_busstop) < 
						{if}
							(L.L.emar_terminus) (S.L.emar_busstop)
						{endif}
					{endif}
				{endif}
			{endif}
		{endif}
	{endif}
	1 (S.L.emar_btnup) s5
	(M.L.emar_button)
{end}

{trigger:emar_btnup_off}
	0 (S.L.emar_btnup) s5
	(M.L.emar_button)
{end}

{trigger:emar_btndown}
	(L.L.emar_mode) 7 =
	{if}
		(L.L.emar_menu_level) 0 =
		{if}
			(L.L.emar_menu_selector) 3 <
			{if}
				(L.L.emar_menu_selector) 1 + (S.L.emar_menu_selector)
			{else}
				0 (S.L.emar_menu_selector)
			{endif}
		{else}
			(L.L.emar_menu_level) 1 =
			{if}
				(L.L.emar_menu_selector) s0 0 =
				{if}
					5
				{else}
					l0 1 =
					{if}
						7
					{else}
						l0 2 =
						{if}
							8
						{else}
							l0 3 =
							{if}
								8
							{endif}
						{endif}
					{endif}
				{endif} s1
				
				(L.L.emar_menu_selector2) l1 <
				{if}
					(L.L.emar_menu_selector2) 1 + (S.L.emar_menu_selector2)
				{endif}
			{else}
				(L.L.emar_menu_selector3) 2 <
				{if}
					(L.L.emar_menu_selector3) 1 + (S.L.emar_menu_selector3)
				{endif}
			{endif}
		{endif}
	{else}
		(L.L.emar_mode) 2 =
		(L.L.emar_mode) 3 = ||
		{if}
			(L.L.emar_route_operation) 1 = !
			{if}
				(L.L.emar_route_search_last) (S.L.emar_route_search)
			{endif}
			2 (M.L.emar_modeselect)
			1 (S.L.emar_route_operation)
		{else}
			(L.L.emar_from_change)
			{if}
				(L.L.emar_busstop) (L.L.emar_RouteIndex) (M.V.GetBusstopCount) 1 - <
				(L.L.emar_busstop) (L.L.emar_terminus) < &&
				{if}
					(L.L.emar_busstop) 1 + (S.L.emar_busstop)
					0 (S.L.emar_ticket_sum)
				{else}
					(T.L.ev_emar_errorpiep)
				{endif}
			{else}
				(L.L.emar_dest_change)
				{if}
					(L.L.emar_terminus) (L.L.emar_RouteIndex) (M.V.GetBusstopCount) 1 - <
					{if}
						(L.L.emar_terminus) 1 + (S.L.emar_terminus)
					{else}
						(T.L.ev_emar_errorpiep)
					{endif}
				{endif}
			{endif}
		{endif}
	{endif}
	1 (S.L.emar_btndown) s5
	(M.L.emar_button)
{end}

{trigger:emar_btndown_off}
	0 (S.L.emar_btndown) s5
	(M.L.emar_button)
{end}

{trigger:emar_ticket}
	(T.L.ev_ticketsale_giveticket)
	-1 (S.L.GivenTicket) (S.L.emar_ticket_select)
	0 (S.L.emar_ticket_pos) (S.L.emar_ticket_drucked) 
	-1 (S.L.emar_ticket_drucking)
{end}

{trigger:cp_emar_key_btm}
	(L.L.cp_emar_key_btm_rot) ! (S.L.cp_emar_key_btm_rot)
	{if}
		(T.L.ev_emar_kluczykSTART)
	{else}
		(T.L.ev_emar_kluczykSTOP)
	{endif}
{end}

{trigger:cp_emar_key_top}
	(L.L.cp_emar_key_top_rot) ! (S.L.cp_emar_key_top_rot)
	{if}
		(T.L.ev_emar_kluczykSTART)
	{else}
		(T.L.ev_emar_kluczykSTOP)
	{endif}
	(M.L.emar_reset_display)
{end}

{trigger:cp_emar_drawer}
	(L.L.cp_emar_drawer_target) ! (L.L.cp_emar_key_btm_rot) && (S.L.cp_emar_drawer_target)
	{if}
		(T.L.ev_emar_szuflada_open)
	{else}
		(L.L.cp_emar_key_btm_rot)
		{if}
			(T.L.ev_emar_szuflada_close)
		{endif}
	{endif}
{end}

'----------------------
'	Init
'----------------------

{macro:emar_init}
	4320 (S.L.emar_pin)
	-1 (S.L.emar_ticket_select) (S.L.emar_ticket_drucking)
	1 (S.L.emar_route_operation)
	-1 (S.L.emar_route_search) (S.L.emar_route_search_last)
	0 (S.L.emar_valid_hof)
	2 (S.L.emar_time_on_stop)
{end}


'----------------------
'	Frame
'----------------------

{macro:emar_frame}


'MODES
'0: off
'1: pin
'2: route search
'3: display routes
'4: currently unused
'5: on-route mode
'6: end route
'7: menu

	(L.L.cp_emar_key_top_rot) (L.L.emar_mode) 0 = &&
	{if}
		(L.L.emar_startpiep_norepeat) (L.L.emar_init_timer) 1 < &&
		{if}
			0 (S.L.emar_startpiep_norepeat)
		{endif}
		
		(L.L.emar_init_timer) 1 >
		(L.L.emar_startpiep_norepeat) ! &&
		{if}
			(T.L.ev_emar_startpiep)
			1 (S.L.emar_startpiep_norepeat)
		{endif}
	
		(L.L.emar_init_timer) (L.S.Timegap) + (S.L.emar_init_timer) 5 >
		{if}
			1 (S.L.emar_mode)
			0 (S.L.emar_init_timer)
		{endif}
	{else}
		0 (S.L.emar_init_timer)
	{endif}

	(L.L.emar_mode)
	(L.L.emar_init_timer) 0 > ||
	{if}
		1 (S.L.emar_on)
	{else}
		0 (S.L.emar_on)
	{endif}
	
	(L.L.cp_emar_key_top_rot)
	(L.L.AI) ||
	{if}
		(L.L.AI)
		{if}			
			(L.L.AI_target_index) 5 (M.V.GetTerminusString) s1
			$length 12 >
			{if}
				l1 11 $SetLengthL "." $+
			{else}
				l1
			{endif}
			(S.$.emar_terminus_name) (S.$.emar_t)
		{endif}
	
	
	
	
'		TIME
'		(L.S.Time) 3600 / s0 trunc s1 "02" $IntToStrEnh ":" $+
'		l0 l1 - 60 * trunc "02" $IntToStrEnh $+ (S.$.emar_time)

		(L.L.schedule_active)
		(L.L.emar_mode) 4 >= &&
		(L.L.emar_mode) 6 <= && 
		{if}
			(L.L.emar_mode) 4 =
			(L.L.emar_mode) 5 = ||
			(L.L.emar_ziel_mode) ! &&
			{if}
				(L.L.emar_busstop_index) s3
			{else}
				(M.V.GetTTBusstopIndex) s3
			{endif}
			
			
'			CZAS DO ODJAZDU: 0: ROZNICA 1: ROZKLADOWY 2: ZEGAROWY
			(L.L.emar_time_on_stop) 0 =
			{if}
				l3 (M.V.GetTTBusstopDep) (L.S.Time) - s2 0 <
				{if}
					"-"
				{else}
					" "
				{endif}
				l2 abs 3600 / s0 trunc s1 "01" $IntToStrEnh $+ ":" $+
				l0 l1 - 60 * trunc "02" $IntToStrEnh $+
			{else}
				(L.L.emar_time_on_stop) 1 =
				{if}
					l3 (M.V.GetTTBusstopDep) 3600 / s0 trunc s1 24 % "02" $IntToStrEnh ":" $+
					l0 l1 - 60 * trunc "02" $IntToStrEnh $+ 
				{else}
					(L.S.Time) 3600 / s0 trunc s1 "02" $IntToStrEnh ":" $+
					l0 l1 - 60 * trunc "02" $IntToStrEnh $+
				{endif}
			{endif}
			(S.$.emar_time)
		{else}
			(L.S.Time) 3600 / s0 trunc s1 "02" $IntToStrEnh ":" $+
			l0 l1 - 60 * trunc "02" $IntToStrEnh $+ (S.$.emar_time)
		{endif}
		
'		RESET
		(L.L.emar_mode) 5 = (L.L.emar_mode) 4 = || (L.L.emar_from_change) && (S.L.emar_from_change)
		(L.L.emar_mode) 5 = (L.L.emar_mode) 4 = || (L.L.emar_dest_change) && (S.L.emar_dest_change)


'		EKRAN LOGOWANIA
		(L.L.emar_mode) 1 =
		{if}
		"@@@DRIVER@NAME@NUMER KARTY:	 	 	 	 	117762@	 	 	 PODAJ PIN KARTY:@	 	 	 	 	 	 " 
		" " 4 (L.L.emar_input_count) - $* $+ "*" (L.L.emar_input_count) $* $+ (S.$.emar_display_init)
		"" (S.$.emar_display_pointer) (S.$.emar_display_left) (S.$.emar_display_left_hover) (S.$.emar_display_thin)
		"EMAR-105@@@" (S.$.emar_display)
		{else}
		"" (S.$.emar_display_init)
		{endif}
		
		
		(L.L.AI_target_index) 0 >
		{if}
			
			(L.$.SetLineTo) "" $= !
			{if}
				(L.$.SetLineTo) $StrToFloat 100 * (L.L.AI_target_index) + (S.L.emar_LinieKurs)
			{else}
				(L.L.AI_target_index) (S.L.emar_LinieKurs)
			{endif}
			
			1 (S.L.emar_route_menuset)
			1 (S.L.emar_ziel_mode)
			(L.L.AI_target_index) (S.L.emar_TerminusIndex)
				
			(L.L.AI_target_index) (L.L.AI_target_index_last) = !
			(L.L.emar_mode) 5 < ||
			(L.L.emar_mode) 1 >  &&	
			{if}
				(L.L.AI_target_index) (S.L.AI_target_index_last)
				1 (S.L.emar_display_gen_mode)
				5 (S.L.emar_mode)
			{endif}
		{else}
			0 (S.L.emar_route_menuset)
		{endif}
		
		(L.L.emar_mode) 2 =
		(L.L.emar_mode) 3 = ||
		(L.L.schedule_active) &&
		{if}
			(L.L.emar_ziel_mode)
			{if}
				(L.L.emar_ziel) s0 (M.V.GetTerminusIndex) s1 0 >=
				{if}
					l0 (S.L.emar_TerminusCode)
					l1 (S.L.emar_TerminusIndex)
					1 (S.L.emar_valid_hof)
				{else}
					0 (S.L.emar_valid_hof)
				{endif}
				1 (S.L.emar_display_gen_mode)
				5 (S.L.emar_mode)
			{endif}
		{endif}
		
		(L.L.emar_mode) 2 =
		{if}
			(L.L.schedule_active)
			{if}
				(M.V.GetTTLineString) "" $= !
				{if}
					(M.V.GetTTLineString) $StrToFloat 100 * (S.L.emar_LinieKurs)
				{else}
					0 (S.L.emar_LinieKurs)
				{endif}
				
				(L.L.emar_route_search) (L.L.emar_route_operation) + s0 0 >=
				{if}
					l0 (S.L.emar_route_search)
					(L.L.emar_route_search_last) -1 =
					{if}
						0 (S.L.emar_route_search_complete)
					{endif}
				{endif}
				
				
				(L.L.emar_LinieKurs) (L.L.emar_route_search) + (M.V.GetRouteIndex) s1
				0 >=
				{if}
					1 (S.L.emar_route_search_complete)
					1 (S.L.emar_valid_hof)
					0 (S.L.emar_route_operation)
					(L.L.emar_route_search) (S.L.emar_route_search_last)
					3 (M.L.emar_modeselect)
				{else}
					(L.L.emar_route_search) 100 >=
					(L.L.emar_route_search) -1 <= ||
					{if}
						1 (S.L.emar_route_search_complete)
					
						(L.L.emar_route_search_last) -1 =
						(L.L.emar_ziel_mode) ! &&
						{if}
							0 (S.L.emar_valid_hof)
						{else}
							1 (S.L.emar_valid_hof)
							(L.L.emar_route_search_last) (S.L.emar_route_search)
						{endif}
						3 (M.L.emar_modeselect)
					{else}
						
					{endif}
				{endif}
				
			{else}
			0 (S.L.emar_route_search) (S.L.emar_route_search_last)
			{endif}
			

		
'		(S.$.emar_display_left_hover) 		
		{endif}
		
		(L.L.emar_mode) 2 =
		(L.L.emar_mode) 3 = ||
		(L.L.emar_route_search_complete)
		(L.L.schedule_active) ! || &&
		{if}
			(L.L.schedule_active)
			(L.L.emar_valid_hof) &&
			{if}
				(M.V.GetTTLineString) "" $= !
				{if}
					(M.V.GetTTLineString) $StrToFloat 100 * (S.L.emar_LinieKurs)
				{else}
					0 (S.L.emar_LinieKurs)
				{endif} 
			
				(L.L.emar_LinieKurs) (L.L.emar_route_search_last) + (M.V.GetRouteIndex) s1
				
				"TRYB KURSÓW@@@        " 	
				(L.L.emar_input) 0 >
				{if}
					(L.L.emar_input) "02" $IntToStrEnh $+
				{endif} 
				(S.$.emar_display_centered)
				"@Z:  "
				
				l1 0 (M.V.GetRouteBusstopIdent) (S.$.act_busstop)
				(M.V.GetBusstopIndex) (S.L.emar_busstop_index) 3 (M.V.GetBusstopString) s2
				$length 10 >
				{if}
					l2 9 $SetLengthL "." $+
				{else}
					l2 10 $SetLengthL
				{endif}
				
				$+ "@DO: " $+
				
				l1 (M.V.GetRouteTerminusIndex) 5 (M.V.GetTerminusString) s2
				$length 10 >
				{if}
					l2 9 $SetLengthL "." $+
				{else}
					l2 10 $SetLengthL
				{endif}
				$+ "@" $+ (S.$.emar_display_thin)
				
'				"@@@@@@ " (L.$.emar_time) $+ (S.$.emar_display_thin2)
				
				
				(L.L.emar_route_search_last) 0 >=
				{if}
					"@@@@@@@@	              KURS ->  "
					(L.L.emar_route_search_last) "03" $IntToStrEnh $+
					(S.$.emar_display_init)
				{endif} 
			
				
				"" (S.$.emar_display_left) (S.$.emar_display_left_hover) (S.$.emar_display_pointer) 
			{else}
				(L.L.emar_valid_hof) !
				{if}
					"@       KARTA@  NIEZAPROGRAMOW.@" (S.$.emar_display_thin)
				{else}
					"@BRAK WA¯NYCH ZADAÑ@@" (S.$.emar_display_thin)
				{endif}
			2 (S.L.emar_mode)
			"" (S.$.emar_display) (S.$.emar_display_thin2) (S.$.emar_display_left) (S.$.emar_display_left_hover) (S.$.emar_display_pointer) (S.$.emar_display_thin2) (S.$.emar_display_centered)
			1 (S.L.emar_route_operation)
			-1 (S.L.emar_route_search) (S.L.emar_route_search_last)
			{endif}
		{endif}
		
		(L.L.emar_display_gen_mode)
		{if}
			(M.L.emar_display_gen)
		{endif}
		
		(L.L.emar_mode) 4 =
		(L.L.emar_mode) 5 = ||
		{if}
			(L.L.emar_ziel_mode)
			{if}
				(M.V.GetTTBusstopIndex) (L.L.emar_TTbusstop) = !
				(L.L.emar_ticket_moneychange) ! &&
				{if}
					(M.V.GetTTBusstopIndex) (S.L.emar_TTbusstop)
					0 (S.L.emar_ticket_sum)
				{endif}
			{endif}
		
			(L.L.emar_ziel_mode) !
			{if}
				(L.L.emar_from_change)
				{if}
					(L.L.emar_busstop) 1 + "02" $IntToStrEnh "@@@" $+ (S.$.emar_display_left_hover)
					"@" (L.L.emar_terminus) 1 + 99 min "02" $IntToStrEnh $+ "@@" $+ (S.$.emar_display_left)
				{else}
					(L.L.emar_busstop) 1 + "02" $IntToStrEnh "@@@" $+ (S.$.emar_display_left)
					"@" (L.L.emar_terminus) 1 + 99 min "02" $IntToStrEnh $+ "@@" $+ (S.$.emar_display_left_hover)
					
					1 (S.L.emar_dest_change)
				{endif}
			{else}
				"--@@@" (S.$.emar_display_left)
				"@" (M.V.GetTTBusstopCount) 99 min "02" $IntToStrEnh $+ "@@" $+ (S.$.emar_display_left_hover)
			
			{endif}
			
			(L.L.emar_from_change)
			{if}
				">@@@" (S.$.emar_display_pointer)
			{else}
				"@>@@" (S.$.emar_display_pointer)
			{endif}
			
			"@@" (L.$.emar_time) $+ "@" $+  (S.$.emar_display_thin)
		
			(L.L.emar_ziel_mode) !
			{if}
				(L.L.emar_RouteIndex) (L.L.emar_busstop) (M.V.GetRouteBusstopIdent) (S.$.act_busstop)
				(M.V.GetBusstopIndex) (S.L.emar_busstop_index) 3 (M.V.GetBusstopString) s2 (S.$.emar_ticket_s)
				$length 10 >
				{if}
					l2 9 $SetLengthL "." $+
				{else}
					l2 10 $SetLengthL
				{endif}
			{else}
				(M.V.GetTTBusstopIndex) (M.V.GetTTBusstopName) s2 (S.$.emar_ticket_s)
				$length 10 >
				{if}
					l2 9 $SetLengthL "." $+
				{else}
					l2 10 $SetLengthL
				{endif}
			{endif}
			
			"@" $+
			
			(L.L.emar_ziel_mode) !
			{if}
				(L.L.emar_terminus) (L.L.emar_RouteIndex) (M.V.GetBusstopCount) =
				{if}
					(L.L.emar_RouteIndex) (M.V.GetRouteTerminusIndex) (S.L.emar_TerminusIndex) 5 (M.V.GetTerminusString) s2
				{else}
					(L.L.emar_RouteIndex) (L.L.emar_terminus) (M.V.GetRouteBusstopIdent)
					(M.V.GetBusstopIndex) 3 (M.V.GetBusstopString) s2
				{endif}
				(S.$.emar_ticket_t)
'				(S.$.emar_terminus_name)
				$length 10 >
				{if}
					l2 9 $SetLengthL "." $+
				{else}
					l2 10 $SetLengthL
				{endif}
			{else}
				(L.L.emar_TerminusIndex) 5 (M.V.GetTerminusString) s2 (S.$.emar_ticket_t)
				$length 10 >
				{if}
					l2 9 $SetLengthL "." $+
				{else}
					l2 10 $SetLengthL
				{endif}
			
			{endif}
			
			$+ "@@     " $+ s0
			
				(L.L.emar_ticket_select) -1 > ! &&
				(L.L.emar_ticket_zonal) ! &&
				{if}
					(L.L.emar_ticket_moneychange)
					{if}
						l0 (L.L.emar_input) "04" $IntToStrEnh 2 $SetLengthL $+ "," $+ (L.L.emar_input) "04" $IntToStrEnh 2 $cutBegin $+
					{else}
						(L.L.emar_ticket_sum) 999 >
						{if}
							(L.L.emar_ticket_sum) $IntToStr 2 $cutEnd $+ "," $+ (L.L.emar_ticket_sum) "04" $IntToStrEnh 2 $cutBegin $+
						{else}
							" " $+ (L.L.emar_ticket_sum)  "03" $IntToStrEnh 2 $cutEnd $+ "," $+ (L.L.emar_ticket_sum) "04" $IntToStrEnh 2 $cutBegin $+
						{endif}
					{endif}
				{else}
					(L.L.emar_ticket_select) -1 >
					(L.L.emar_ticket_zonal) ||
					{if}
						"     " $+
					{else}
						(L.L.emar_input) 0 > 
						{if}
							"   " $+ (L.L.emar_input) "02" $IntToStrEnh $+
						{else}
							" 0,00" $+
						{endif}
					{endif}
				{endif}
			(S.$.emar_display) 
			
			(L.L.emar_ticket_zonal)
			{if}
				(L.L.emar_input) 1 - (S.L.emar_ticket_select)
			{endif}
			
			
			(L.L.emar_ticket_select) -1 >
			(L.L.emar_ticket_zonal) ||
			{if}
				(L.L.emar_ticket_zonal)
				{if}
					"@@@@      BIL. STREFOWY@ " 
					(L.L.emar_ticket_select) 1 + "02" $IntToStrEnh $+ ". " $+
					(L.L.emar_ticket_select) (M.V.GetTicketName) "" $=
					{if}
					"-"
					{else}
					(L.L.emar_ticket_select) (M.V.GetTicketName) 14 $SetLengthL
					{endif}
					$+
					"@ " $+
				{else}
					(L.L.emar_ticket_select) 0 =
					{if}
						"@@@@      BN@@ " 
					{else}
						"@@@@      BU@ UCZEN/STUDENT@ " 
					{endif}
				{endif}
				(L.$.emar_time) $+ "        " $+
				(L.L.emar_ticket_select) (M.V.GetTicketValue) s0 trunc s1
				l1 " 2" $IntToStrEnh $+ "," $+ l0 l1 - 100 * "02" $IntToStrEnh $+
				(S.$.emar_display_thin2)
				"" (S.$.emar_display_thin)
			{else}
				(L.L.emar_busstop) (L.L.emar_terminus) =
				(L.L.emar_ziel_mode) ! &&
				{if}
					"@@@@       KURS -> " (L.L.emar_route_search_last) "03" $IntToStrEnh $+ "@@ " $+  
				{else}
					""
				{endif}
				(S.$.emar_display_thin2)
				"@@" (L.$.emar_time) $+ "@" $+  (S.$.emar_display_thin)
			{endif}
			
		{endif}
		
		
		(L.L.emar_mode) 6 =
		{if}
			"   ZAKOÑCZYÆ KURS@        (S/C)@@" (S.$.emar_display_thin)
			"@@@@@@ " (L.$.emar_time) $+ (S.$.emar_display_thin2)
		{endif}
		
		(L.L.emar_mode) 7 =
		(L.L.emar_menu_level) 2 = ! &&
		{if}
			(L.L.emar_menu_selector) s0
			(L.L.emar_menu_selector2) s1
			
			(L.L.emar_menu_level) 0 =
			{if}
				"@>@@" (S.$.emar_display_pointer)
				"MENU BILETERKI@@@" (S.$.emar_display_centered)
			{else}
				">@@@" (S.$.emar_display_pointer)
				"" (S.$.emar_display_centered)
			{endif}
			
			(L.L.emar_menu_level) 0 =
			{if}
				"@ "
			{else}
				" " 
			{endif}
			
			(L.L.emar_menu_level) 0 =
			{if}
				l0 0 =
				{if}
					"FUNKCJE FISKALNE@"
				{else}
					l0 1 =
					{if}
					"FUNKCJE ZADANIOWE@"
					{else}
						l0 2 = 
						{if}
						"FUNKCJE SERWISOWE@"
						{else}
							l0 3 =
							{if}
							"FUNKCJE DODATKOWE@"
							{endif}
						{endif}				
					{endif}
				{endif}
			{else}
				l0 0 =
				{if}
					l1 0 =
					{if}
						"raport dobowy@"
					{else}
						l1 1 =
						{if}
						"raport miesieczny@"
						{else}
							l1 2 =
							{if}
							"raport okresowy wg@ dat"
							{else}
								l1 3 =
								{if}
								"raport okresowy wg@ nr"
								{else}
									l1 4 =
									{if}
									"raport sprzedazy@"
									{else}
										l1 5 =
										{if}
										"raport niezerujacy@"
										{endif}
									{endif}
								{endif}
							{endif}
						{endif}
					{endif}
				{endif}
				
				l0 1 =
				{if}
					l1 0 =
					{if}
						"oplata dodatkowa@"
					{else}
						l1 1 =
						{if}
						"wydruk kontrolny@"
						{else}
							l1 2 =
							{if}
							"wpisanie numeru@ bocznego"
							{else}
								l1 3 =
								{if}
								"wybor kursu poza@ kalendarzem"
								{else}
									l1 4 =
									{if}
									"wybor kursu poza@ zadaniem"
									{else}
										l1 5 =
										{if}
										"raport kursow@"
										{else}
											l1 6 =
											{if}
											"raport zadaniowy@"
											{else}
												l1 7 =
												{if}
												"stan utargu@"									
												{endif}
											{endif}
										{endif}
									{endif}
								{endif}
							{endif}
						{endif}
					{endif}
				{endif}
						
				l0 2 =
				{if}
					l1 0 =
					{if}
						"fiskalizacja@"
					{else}
						l1 1 =
						{if}
						"raport niefiskalny@"
						{else}
							l1 2 =
							{if}
							"ustawianie zegara@"
							{else}
								l1 3 =
								{if}
								"zerowanie RAM@"
								{else}
									l1 4 =
									{if}
									"zerowanie pamieci@ kursow"
									{else}
										l1 5 =
										{if}
										"raport@ rozliczeniowy wg dat"
										{else}
											l1 6 =
											{if}
											"raport@ rozliczeniowy wg nr"
											{else}
												l1 7 =
												{if}
												"wpis numeru@ unikatowego"
												{else}
													l1 8 =
													{if}
													"wpis klucza pamieci@ fiskalnej"
													{endif}
												{endif}
											{endif}
										{endif}
									{endif}
								{endif}
							{endif}
						{endif}
					{endif}
				{endif}
				
				l0 3 =
				{if}
					l1 0 =
					{if}
						"data i czas@"
					{else}
						l1 1 =
						{if}
						"zmiana PIN-u menu@"
						{else}
							l1 2 =
							{if}
							"czas na@ przystankach"
							{else}
								l1 3 =
								{if}
								"regulacja@ podswietlenia"
								{else}
									l1 4 =
									{if}
									"regulacja kontrastu@"
									{else}
										l1 5 =
										{if}
										"sprawdzenie@ EM-karty"
										{else}
											l1 6 =
											{if}
											"spr. numeru@ kontrol."
											{else}
												l1 7 =
												{if}
												"korekta czasu@"
												{else}
													l1 8 =
													{if}
													"raport informacyjny@"
													{endif}
												{endif}
											{endif}
										{endif}
									{endif}
								{endif}
							{endif}
						{endif}
					{endif}
				{endif}
				
			{endif}
			
			(L.L.emar_menu_level) 0 =
			{if}
			""
			{else}
			"@" 
			{endif}
			$+
			
			"      @" $+ $+ (S.$.emar_display_thin)
			"@@@@@@ " (L.$.emar_time) $+ "         0,00" $+ (S.$.emar_display_thin2)
		{endif}
		
		(L.L.emar_mode) 7 =
		(L.L.emar_menu_level) 2 =
		{if}
			(L.L.emar_menu_selector) 3 =
			(L.L.emar_menu_selector2) 0 = &&
			{if}
				"@     " (L.S.Day) "02" $IntToStrEnh $+ "-" $+ (L.S.Month) "02" $IntToStrEnh $+ "-" $+ (L.S.Year) "04" $IntToStrEnh $+ "@        " $+ 
				(L.S.Time) 3600 / s0 trunc s1 "02" $IntToStrEnh $+ ":" $+
				l0 l1 - 60 * trunc "02" $IntToStrEnh $+
				"@" $+ (S.$.emar_display_thin)
			{else}
				(L.L.emar_menu_selector) 3 =
				(L.L.emar_menu_selector2) 2 = &&
				{if}
					" ROZNICA@ ROZKLADOWY@ ZEGAROWY@" (S.$.emar_display_thin)
					"@" (L.L.emar_menu_selector3) $* ">" $+ "@" 3 (L.L.emar_menu_selector3) - $* $+ (S.$.emar_display_pointer)
				{else}
					(L.L.emar_menu_selector) 1 =
					(L.L.emar_menu_selector2) 4 = &&
					{if}
					"@  PODAJ NR KURSU@       "
					(L.L.emar_input) 0 >
					{if}
					(L.L.emar_input) " 3" $IntToStrEnh $+ 
					{endif}
					"@" $+
					(S.$.emar_display_thin)
					{else}
						(L.L.emar_menu_selector) 2 =
						{if}
						"@ FUNKCJA ZABRONIONA@@" (S.$.emar_display_thin)
						{else}
						"@FUNKCJA NIEDOSTEPNA@@" (S.$.emar_display_thin)
						{endif}
					{endif}
				{endif}
			{endif}
		{endif}

	(L.L.emar_ticket_drucking) 0 >=
	{if}
		(L.L.Cabinair_Temp) 5 < 
		{if}
			(L.L.emar_ticket_pos) (L.S.Timegap) 0.2 * + (S.L.emar_ticket_pos)
		{else}
			(L.L.emar_ticket_pos) (L.S.Timegap) 1 * + (S.L.emar_ticket_pos)
		{endif}
		1 >=
		{if}
			1 (S.L.emar_ticket_drucked)
			1 (S.L.emar_ticket_pos)
			(L.L.emar_ticket_drucking) (S.L.GivenTicket)
			-1 (S.L.emar_ticket_drucking)
		{endif}
	{endif}
	
	(L.L.emar_ticket_drucked)
	(L.L.GivenTicket) 0 < &&
	{if}
		(T.L.ev_ticketsale_giveticket)
		-1 (S.L.emar_ticket_select)
		-1 (S.L.emar_ticket_drucking)
		0 (S.L.emar_ticket_drucked)
		0 (S.L.emar_ticket_pos)
	{endif}

		
	(L.L.emar_valid_hof) ! (S.L.emar_error)
	(L.L.emar_error_norepeat) ! &&
	{if}
		(T.L.ev_emar_errorpiep)
		1 (S.L.emar_error_norepeat)
	{endif}
		
	(L.L.emar_error) !
	(L.L.emar_error_norepeat) &&
		{if}
		0 (S.L.emar_error_norepeat)
	{endif}
		
		
	{else}
		0 (S.L.emar_mode) (S.L.emar_mode_last) (S.L.emar_input_count) (S.L.emar_input) (S.L.emar_error)
		(M.L.emar_reset_display)
		-1 (S.L.emar_ticket_select) (S.L.emar_ticket_drucking)
		
		1 (S.L.emar_route_operation)
		-1 (S.L.emar_route_search) (S.L.emar_route_search_last)
		-1 (S.L.emar_ticket_drucking)
		
		0 (S.L.emar_display_counter)
		(S.L.emar_input)
		(S.L.emar_input_count)
		(S.L.emar_select_count)
		(S.L.emar_menu_selector)
		(S.L.emar_menu_selector2)
		(S.L.emar_menu_level)

		(S.L.emar_from_change)
		(S.L.emar_dest_change)
		(S.L.emar_ticket_sum)
		(S.L.emar_ticket_moneychange)
		(S.L.emar_ticket_givechange)
		(S.L.emar_ticket_zonal)
		
		(S.L.emar_TerminusCode)
		(S.L.emar_TerminusIndex)
		(S.L.emar_LinieKurs)
		(S.L.emar_Route)
		(S.L.emar_RouteIndex)
		(S.L.emar_busstop)
		(S.L.emar_terminus)
		(S.L.emar_busstop_index)

		(S.L.emar_ziel_mode)
		(S.L.emar_ziel)
		
		(S.L.emar_display_gen_mode)
		
		-1 (S.L.emar_TTbusstop)
		
		1 (S.L.emar_valid_hof)
		
		"" (S.$.emar_s) (S.$.emar_t)
	{endif}
	
	
	1 (S.L.Refresh_Strings)
	
	(L.L.cp_emar_drawer_target)
	{if}
		(L.L.cp_emar_drawer_pos) (L.S.Timegap) 1.2 * + 1 min (S.L.cp_emar_drawer_pos) 
	{else}
		(L.L.cp_emar_drawer_pos) (L.S.Timegap) 1.2 * - 0 max (S.L.cp_emar_drawer_pos) 
	{endif}
	
{end}

'----------------------
'	Macros
'----------------------

{macro:IBIS_RefreshBusstop}

	(L.L.IBIS_RouteIndex) 0 <
	{if}
		"" (S.$.act_busstop)
	{else}
	(L.L.IBIS_RouteIndex) (M.V.GetBusstopCount) (L.L.IBIS_busstop) <=
	{if}
'Wenn der Bushaltestellenindex größer oder gleich der Anzahl ist und somit zu groß (der Bushaltestellenindex ist wie alle Indizes nullbasiert), 
'dann wechsele automatisch auf die Gegenroute, sofern der Index 01 oder 02 ist und der jeweilige andere Index existiert. Sonst belasse die Route.
		0 (S.L.IBIS_busstop)
' Entwerter umstellen:
		(T.L.ev_IBIS_entwerter)
		(L.L.IBIS_busstop_entwerter_soll) (S.L.IBIS_busstop_entwerter_ist)

		(L.L.IBIS_Route) s5
		2 % 0.5 >
		{if}
			l5 1 + s6
		{else}
			l5 1 - s6
		{endif}

'Suche den Routeindex:

		(L.L.IBIS_LinieKurs) 100 * l6 + (M.V.GetRouteIndex) s1
		0 >=
		{if}
'Wenn gültig, dann wechsele:
'			(M.L.IBIS_SetRoute)
			l6 (S.L.IBIS_Route)
		{endif}
	{else}
		0 (S.L.IBIS_mode)
	{endif}
	{endif}

'Setzen der String-Variable "act_busstop" für die OMSI-interne Berechnung und daraus Ableitung des "globalen" Haltestellenindexes:

	(L.L.IBIS_RouteIndex) (L.L.IBIS_busstop) (M.V.GetRouteBusstopIdent) (S.$.act_busstop)
	(M.V.GetBusstopIndex) (S.L.IBIS_busstop_index)


'Sonst zeige die Bushaltestelle
	(L.L.IBIS_busstop_index) 3 (M.V.GetBusstopString)
	(S.$.IBIS_busstop_name)

'Ausrechnen der neuen Entwerterposition:
	(L.L.IBIS_busstop_offset) (L.L.IBIS_busstop) + (S.L.IBIS_busstop_entwerter_soll)


{end}

{macro:IBIS_PlayAnnouncement}

	(L.L.IBIS_busstop) 0 >
	{if}

		"Ansagen\" (L.$.act_busstop) $+

		(L.L.IBIS_RouteIndex) (M.V.GetBusstopCount) 1 - (L.L.IBIS_busstop) <=
		{if}
			"_#terminus" $+
		{endif}

		".wav" $+
		$msg
		(T.F.ev_IBIS_Ansagen)
	{endif}
{end}

{macro:emar_modeselect}
	s0
	(L.L.emar_mode) 1 >
	{if}
		(L.L.emar_mode) l0 = !
		{if}
		(M.L.emar_reset_display)
		(L.L.emar_mode) (S.L.emar_mode_last)
		l0 (S.L.emar_mode)
		0 (S.L.emar_input) (S.L.emar_input_count)
		{endif}
	{endif}
{end}

{macro:emar_input}
	s0
	(L.L.emar_on)
	{if}
		(L.L.emar_mode) 1 = (L.L.emar_input_count) 4 < &&
		(L.L.emar_mode) 3 = (L.L.emar_mode) 2 = || (L.L.emar_input_count) 2 < && ||
		(L.L.emar_ticket_moneychange) (L.L.emar_input_count) 4 < && ||
		(L.L.emar_mode) 5 = (L.L.emar_ticket_moneychange) ! && (L.L.emar_ticket_zonal) && (L.L.emar_input_count) 2 < && ||
		(L.L.emar_mode) 5 = (L.L.emar_ticket_moneychange) ! && (L.L.emar_ticket_zonal) ! && (L.L.emar_input_count) 2 < && ||
		(L.L.emar_mode) 7 = (L.L.emar_menu_selector) 1 = && (L.L.emar_menu_selector2) 4 = && (L.L.emar_menu_level) 2 = && (L.L.emar_input_count) 3 < && ||
		{if}
			(L.L.emar_input) 10 * l0 + (S.L.emar_input)
			(L.L.emar_input_count) 1 + (S.L.emar_input_count)
		{endif}
	{endif}
{end}

{macro:emar_clear}
	(L.L.emar_mode) 1 = 
	(L.L.emar_mode) 3 = ||
	(L.L.emar_mode) 5 = ||
	(L.L.emar_input_count) 0 > &&
	{if}
		(L.L.emar_input) 10 / trunc (S.L.emar_input)
		(L.L.emar_input_count) 1 - (S.L.emar_input_count)
	{endif}
{end}

{macro:emar_clear_disp}
	"" (S.$.emar_display) (S.$.emar_display_pointer) (S.$.emar_display_left) (S.$.emar_display_left_hover) (S.$.emar_display_thin) (S.$.emar_display_thin2)
{end}

{macro:emar_confirm}
	(L.L.emar_mode) 1 =
	{if}
		(L.L.emar_input) (L.L.emar_pin) =
		{if}
		2 (S.L.emar_mode)
		(M.L.emar_reset_display)
		0 (S.L.emar_input) (S.L.emar_input_count)
		{endif}		
	{endif}
	
	(L.L.emar_mode) 5 =
	{if}
		(L.L.emar_ticket_moneychange)
		{if}
		(L.L.emar_input) (L.L.emar_ticket_sum) - 0 max (S.L.emar_input) 
		(L.L.emar_input) $IntToStr $length (S.L.emar_input_count)
		
		{else}
		
			(L.L.emar_ticket_select) -1 >
			(L.L.emar_ticket_select) (M.V.GetTicketValue) 0 > &&
			{if}
				(L.L.emar_ticket_sum) (L.L.emar_ticket_select) (M.V.GetTicketValue) 100 * + (S.L.emar_ticket_sum)
				
				
				
				0 (S.L.emar_ticket_zonal) (S.L.emar_input) (S.L.emar_input_count) 
				
				(L.$.emar_ticket_s) s0 $length 10 >
				{if}
					l0 9 $SetLengthL "." $+
				{else}
					l0 10 $SetLengthL
				{endif} 
				
				"@" $+
				
				(L.$.emar_ticket_t) s1 $length 10 >
				{if}
					l1 9 $SetLengthL "." $+
				{else}
					l1 10 $SetLengthL
				{endif} 
				
				$+ (S.$.emar_ticket_1)
				
				(L.L.emar_ticket_select) (M.V.GetTicketValue) s0 trunc s1
				l1 " 2" $IntToStrEnh "," $+ l0 l1 - 100 * "02" $IntToStrEnh $+ (S.$.emar_ticket_2)
				(L.L.emar_ticket_select) (S.L.emar_ticket_drucking)
				-1 (S.L.emar_ticket_select)
				0 (S.L.emar_ticket_drucked)
				0 (S.L.emar_ticket_pos)
			{endif}
		{endif}
	{endif}
		
	(L.L.emar_mode) 7 =
	(L.L.emar_menu_level) 2 = &&
	{if}
		(M.L.emar_setting_confirm)
	{endif}
	
{end}

{macro:emar_SetRoute}
	(L.L.emar_mode) 2 =
	(L.L.emar_mode) 3 = ||
	(L.L.emar_mode) 5 = ||
	{if}
		
		(L.L.emar_input) 0 >
		{if}
			(L.L.emar_LinieKurs) (L.L.emar_input) + (M.V.GetRouteIndex) s1
			-1 >
			{if}
				l1 (S.L.emar_RouteIndex)
			{else}
				(L.L.emar_LinieKurs) (L.L.emar_route_search_last)  + (M.V.GetRouteIndex) (S.L.emar_RouteIndex)
			{endif}
		{else}
			(L.L.emar_LinieKurs) (L.L.emar_route_search_last) + (M.V.GetRouteIndex) (S.L.emar_RouteIndex)
		{endif}
		
		(L.L.emar_mode) 5 = !
		{if}
			(L.L.emar_RouteIndex) (M.V.GetBusstopCount) 1 - (S.L.emar_terminus)
			0 (S.L.emar_busstop)
		{endif}

		
		(L.L.emar_RouteIndex) (L.L.emar_busstop) (M.V.GetRouteBusstopIdent)
		(M.V.GetBusstopIndex) (S.L.emar_busstop_index) 3 (M.V.GetBusstopString) s1
		$length 18 >
		{if}
			l1 17 $SetLengthL "." $+
		{else}
			l1
		{endif}
		(S.$.emar_initial_name)
		
		
		(L.L.emar_RouteIndex) (M.V.GetRouteTerminusIndex) (S.L.emar_TerminusIndex) 5 (M.V.GetTerminusString) s1
		$length 12 >
		{if}
			l1 11 $SetLengthL "." $+
		{else}
			l1
		{endif}
		(S.$.emar_terminus_name)
		
		1 (S.L.emar_display_gen_mode)
		5 (S.L.emar_mode)
		(L.L.emar_TerminusIndex) (S.L.target_index_int)
	{endif}
{end}

{macro:emar_display_gen} 
	(L.L.emar_display_counter) 0 =
	{if}
		"" (S.$.emar_s) (S.$.emar_t)
	{endif}
	
	(L.L.emar_display_counter) 30 <
	{if}
		(L.L.emar_display_timer) (L.S.Timegap) + (S.L.emar_display_timer) 
		0.3 >
		{if}
		(L.L.emar_display_counter) 1 + (S.L.emar_display_counter)
		
		(L.L.emar_display_counter) 19 <
		{if}
			(L.L.emar_ziel_mode) ! &&
			{if}
				(L.$.emar_initial_name) (L.L.emar_display_counter) $SetLengthL
			{else}
				"" 
			{endif}
			(S.$.emar_s)
		{else}
			(L.L.emar_ziel_mode)
			{if}
				(L.L.emar_route_menuset)
				{if}
					(L.L.AI_target_index) 5 (M.V.GetTerminusString) s1
				{else}
					(L.L.emar_TerminusIndex) 5 (M.V.GetTerminusString) (L.L.AI_target_index) s1
				{endif}
						
				l1 $length 12 >
				{if}
					l1 11 $SetLengthL "." $+
				{else}
					l1
				{endif}
				(S.$.emar_terminus_name)
			{endif}
				(L.$.emar_terminus_name) $length s1
				(L.$.emar_terminus_name) (L.L.emar_display_counter) 18 - (L.$.emar_terminus_name) $length min $SetLengthL
				" " l1 18 + (L.L.emar_display_counter) - $* $+ (S.$.emar_t)
		{endif}
		0 (S.L.emar_display_timer)
		{endif}	
	{else}
		0 (S.L.emar_display_gen_mode)
		0 (S.L.emar_display_counter)
	{endif}
	
{end}

{macro:emar_ticket_select}
	s0
	(L.L.emar_mode) 5 =
	{if}
	l0 (S.L.emar_ticket_select)
	0 (S.L.emar_ticket_moneychange)
	{endif}
{end}

{macro:emar_reset_display}
	"" (S.$.emar_display)
	(S.$.emar_display_centered)
	(S.$.emar_display_thin)
	(S.$.emar_display_pointer)
	(S.$.emar_display_left)
	(S.$.emar_display_left_hover)
	(S.$.emar_display_init)
	(S.$.emar_display_thin2)
{end}

{macro:emar_button}
	l5 
	{if}
		(T.L.ev_emar_klawisz_in)
	{else}
		(T.L.ev_emar_klawisz_out)
	{endif}
{end}

{macro:emar_setting_confirm}
	(L.L.emar_menu_selector) 3 =
	(L.L.emar_menu_selector2) 2 = &&
	{if}
		(L.L.emar_menu_selector3) (S.L.emar_time_on_stop)
	{endif}

	(L.L.emar_menu_selector) 1 =
	(L.L.emar_menu_selector2) 4 = &&
	{if}
		(L.L.emar_input) (S.L.emar_ziel)
		1 (S.L.emar_ziel_mode)
	{endif}
	
	1 (S.L.emar_menu_level)	
	0 (S.L.emar_menu_selector3)
	0 (S.L.emar_input) (S.L.emar_input_count)
{end}