:: emp_functions
<<set $here = 'emp_functions'>>
<<set $ARGS = $location_var[$here]>>
<!-- !! Employmnent and Event Systems-->
<!-- !! 2023-02-12-->
<!-- !! Author: Hooded Silence-->
<!-- !!-->
<!-- !! v.01 - Initial code base-->
<!-- !! v.02 - Event generator partially integrated-->
<!-- !! v.03 - Job management system integrated-->
<!-- !! v.04 - Start of event generation code integration-->
<!-- !! v.05 - Date suffix modification-->
<!-- !! --------------------- UI Interface for Journal-->
<<if $location_var[$here][0] == 'gen_schedule'>>
	<<if getvar("$night_mode") == 1 or getvar("$night_mode") == 2>>
		<<set $header_theme = '#91B0B4'>>
		<<set $pc.body_theme = '#303030'>>
		<<set $pc.body_theme_alt = '#474747'>>
		<<set $font_theme = '#000000'>>
	<<else>>
		<<set $header_theme = '#e27c00'>>
		<<set $pc.body_theme = '#E0DED4'>>
		<<set $pc.body_theme_alt = '#D58B32'>>
		<<set $font_theme = '#FFFFFF'>>
	<</if>>
	<<if getvar("$function_sw") == 1>>
		<center><h2>' + <<=$npc('A'+$mod_npc_id).firstname>> + ' ' + <<=$npc('A'+$mod_npc_id).lastname>> + '</h2></center>

	<</if>>
	<<if getvar("$function_sw") == 2>>
		<<gs 'journal' 'journalmenu'>>
		<center><h2>Work</h2></center>
	<</if>>
	<!-- !! Enable selector if attending school or Uni by NPC group type or by character and set default to School-->
	<<if ($npc('A' + $mod_npc_id).grupTipe >= 1 and $npc('A' + $mod_npc_id).grupTipe <= 5) or getvar("$mod_npc_id") == 34 and getvar("$function_sw") <= 1>>
		<<if getvar("$flag_schedule") == 0>>
			<<set $flag_schedule = 1>>

		<</if>>
		<<set $school_group = 1>>
		<center>Change to: <<link "School">><<set $flag_schedule = 1>> <<gs 'emp_functions' 'gen_schedule'>><</link>> | <<link "University">><<set $flag_schedule = 2>> <<gs 'emp_functions' 'gen_schedule'>><</link>> | <<link "Holiday">><<set $flag_schedule = 3>> <<gs 'emp_functions' 'gen_schedule'>><</link>> </center>
	<<else>>
		<!-- !! Set schedule to holiday / non-edu NPCs-->
		<<set $flag_schedule = 3>>
	<</if>>
	<!-- !! Initiate loop variables-->
	<<set $i_day = 1>>
	<<set $mod_max_day = 7>>
	<<set $i_hour = $larg(1)>>
	<<set $mod_max_hour = $larg(1) + 8>>
	<<set $header_switch = 1>>
	<<set $tablebody to null>>
	<<set $tableheader to null>>
	<!-- !! create header, using header switch to fill in :00 or :30 automatically using mod to determine odd/even and set display hour automatically.-->
	<<set $tableheader = '<tr border="1" align="center"  bgcolor="$header_theme"><th style="padding: 10px;"></th>'>>
	<<warn 'JUMP MARKER ENCOUNTERED: :jmp_header_create'>>
	<<if ($i_hour % 2) == 0>>
		<<set $display_hour = $i_hour / 2>>
	<</if>>
	<<if getvar("$display_hour") == 24>>
		<<set $Display_hour = 0>>

	<</if>>
	<<if getvar("$header_switch") == 1>>
		<<set $header_switch += 1>>
		<<set $tableheader += '<th style="padding: 10px;"><font color="$font_theme">' + iif(display_hour < 10, '0display_hour ', display_hour) + ':00</font></th>'>>
	<<elseif getvar("$header_switch") == 2>>
		<<set $header_switch = 1>>
		<<set $tableheader += '<th style="padding: 10px;"><font color="$font_theme">' + iif(display_hour < 10, '0 display_hour', display_hour) + ':30</font></th>'>>
	<</if>>
	<<set $i_hour += 1>>
	<<if $i_hour <= $mod_max_hour>>
		<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_header_create'>>

	<</if>>
	<!-- ! Reset i_hour for next loop-->
	<<set $display_hour to null>>
	<<set $header_switch to null>>
	<<set $i_hour = $larg(1)>>
	<<set $header_switch = 1>>
	<!-- !! Close out table header-->
	<<set $tableheader += '</tr>'>>
	<!-- !! Create table body, with alternating colour rows for legibility-->
	<<warn 'JUMP MARKER ENCOUNTERED: :jmp_day_create'>>
	<!-- !Set day-->
	<<if getvar("$i_day") == 1 or getvar("$i_day") == 3 or getvar("$i_day") == 5 or getvar("$i_day") == 7>>
		<<set $tablebody += '<tr><td  style="padding: 10px;" bgcolor="$header_theme"><b><font color="$font_theme">' + $time.weekday_name[$i_day] + '</font></b></td>'>>
	<<else>>
		<<set $tablebody += '<tr bgcolor="$pc.body_theme_alt"><td  style="padding: 10px;" bgcolor="$header_theme"><b><font color="$font_theme">' + $time.weekday_name[$i_day] + '</font></b></td>'>>
	<</if>>
	<!-- !! fill the slots from the NPC schedule-->
	<<warn 'JUMP MARKER ENCOUNTERED: :jmp_hour_create'>>
	<<if getvar("$i_day") >= 1>>
		<!-- !! Create function switcher:-->
		<!-- !! 1: NPC tracker-->
		<!-- !! 2: Job tracker-->
		<!-- !! 3: Event Tracker-->
		<<if getvar("$function_sw") == 1 or getvar("$function_sw") == 0>>
			<<schedule_tracker>>
		<<elseif getvar("$function_sw") == 2>>
			<<set $flag_active = 1>>
			<<set $j_id = $emp_rota_week[$i_day + '_' + $i_hour]>>
			<<if $emp_rota_week[$i_day + '_' + $i_hour] != 0>>
				<<set $transient_tb = '<a  href="exec:gs 'emp_functions', 'job_info', j_id">' + $emp_job_title[$j_id] + '</a>'>>
			<<else>>
				<<set $transient_tb = 'Free'>>
			<</if>>
		<<elseif getvar("$function_sw") == 3>>
		<<else>>
			<<msg 'Error - Failed to create body. Please set content switch.'>>
		<</if>>
		<<if getvar("$flag_active") == 0>>
			<<set $tablebody += '<td style="padding: 10px;">Slot: ' + i_hour +'</td>'>>
		<<else>>
			<<set $tablebody += '<td style="padding: 10px;">' + $transient_tb +'</td>'>>
			<<set $flag_active = 0>>
			<<set $transient_tb to null>>
		<</if>>
	<<else>>
		<<set $i_day += 1>>
		<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_day_create'>>
	<</if>>
	<<set $i_hour += 1>>
	<<if $i_hour <= $mod_max_hour>>
		<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_hour_create'>>

	<</if>>
	<<set $tablebody += '</tr>'>>
	<<set $i_day += 1>>
	<<set $i_hour = $larg(1)>>
	<<if $i_day <= $mod_max_day>>
		<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_day_create'>>

	<</if>>
	<!-- !! Create navigaton bars-->
	<<if ($mod_max_hour + 8) <= 48>>
		<<set $set_hour = $larg(1) + 8>>
		<<set $msg_forward = '<a  href="exec:gs 'emp_functions', 'gen_schedule', set_hour"><b>Forward 4 hours</b></a>'>>
	<<else>>
		<<set $msg_forward = 'End of Day'>>
	<</if>>
	<<if ($mod_max_hour - 8) > 0>>
		<<set $set_hour = $larg(1) - 8>>
		<<set $msg_back = '<a  href="exec:gs 'emp_functions', 'gen_schedule', set_hour"><b>Back 4 hours</b></a>'>>
	<<else>>
		<<set $msg_back = 'Start of day'>>
	<</if>>
	<!-- !! Start the table constuction-->
	<center><table border=0 cellpadding=1 bgcolor="<<$pc.body_theme>>" width="95%" align="center"><<$tableheader>><<$tablebody>></table>
	<<$msg_back>> | <<$msg_forward>>
	<<if getvar("$function_sw") == 1>>
		<b>Note:</b> Times are approximate, some characters will appear at quarter past or quarter to the hour.</center>
	<</if>>
	<<if getvar("$function_sw") == 2>>
		<b>Note:</b> Times are approximate, some jobs may extend past the allotted time or have flexi-starts.</center>
	<</if>>
	<<actCLA 'Back'>>
		<<set $flag_schedule to null>>
		<<set $school_group to null>>
		<<set $j_id to null>>
		<<gt $location>>
	<</actCLA>>
<</if>>
<!-- !! Job Info popup-->
<<if $location_var[$here][0] == 'job_info'>>
	<<set $j_id = $larg(1)>>
	<<set $msg_body to null>>
	<<set $msg_body += '<p>Job Title: ' + $emp_job_title[$j_id] + '</p>'>>
	<<set $msg_body += '<p>Location: ' + $emp_job_loc[$j_id] + '</p>'>>
	<<set $msg_body += '<p>Notes: ' + $emp_job_notes[$j_id]+ '</p>'>>
	<<set $msg_body += '<p>Wages: ' + setup.func('agentned', 'format_price_string', emp_job_wages[$j_id]) + '<b>₽</b></p>'>>
	<<msg '<<$msg_body>>'>>
<</if>>
<!-- !! --------------------- Event Generator-->
<!-- !! Author - Hooded Silence-->
<!-- !! Date created - 26 Aug 22-->
<!-- !! Event Generator - filler content only for one off events or recurring work from NPCs-->
<!-- !!-->
<!-- !! v. 01 - Initial code base-->
<!-- !! v. 02 - UI improvements and feature feedback-->
<!-- !! V. 03 - Initial integration into mainline code-->
<<if $location_var[$here][0] == 'evt_init'>>
	<!-- !! Placeholder, pending integration-->
	<<gt $location>>
<</if>>
<<if $location_var[$here][0] == 'disp_evt'>>
	<<if $location_var[$here][1] == 1>>
		<<gs 'emp_functions' 'evt_day_suffix'>>
		<p>I have this job for you do you want to acccept it?</p>
		'Event Scheduled for: ' + $transient_evt_day + $evt_suffix + ', ' + $time.monthName[$transient_evt_month] + ' ' + '20' + $transient_evt_year
		'Job: ' + $evt_job[$transient_evt_type]
		'Pay: ' + setup.func('agentned', 'format_price_string', transient_evt_wages)
		<!-- FAILED TO CONVERT
			'Time: ' + transient_evt_hour + ':' +  iif(transient_evt_minutes  >= 0 and transient_evt_minutes <= 4, '00',  '30')
		-----
			<<set 'Time: ' + $transient_evt_hour + ':' + ERROR: FAILED TO CONVERT LITERAL: """iif(transient_evt_minutes  >""" = 0 and transient_evt_minutes <= 4, '00',  '30')>>

		-->
		<<warn "CONVERSION ERROR 10cc9638923bf609f113af2db6ca10f4">>
		<<set 'Duration: ' + $transient_evt_duration + iif(transient_evt_duration = 1, ' hour',  ' hours')>>
		'Location: ' + $transient_journal
		'Job Details: ' + $transient_desc
		<<actCLA 'Accept the job'>>
			<<gs 'emp_functions' 'cat_evt'>>
		<</actCLA>>
		<<actCLA 'Decline the job'>>
			<<gs 'emp_functions' 'del_evt' 1>>
			<<gt 'emp_functions' 'evt_init'>>
		<</actCLA>>
	<</if>>
	<!-- !! create table for all jobs:-->
	<<if $location_var[$here][1] == 2>>
		<<if arrsize('evt_event') > 0>>
			<<set $evtbody to null>>
			<<set $job_idx = 0>>
			<<warn 'JUMP MARKER ENCOUNTERED: :jmp_list_create'>>
			<<if getvar("$evt_silent["+$job_idx+"]") == 1>>
				<<gs 'emp_functions' 'evt_day_suffix' $evt_day[$job_idx]>>
			<<set $evtbody += '<tr><td>' +$time.weekday_name[$evt_dow[$job_idx]]+' '+ evt_day[$job_idx] + $evt_suffix + ', '+ $time.monthName[$evt_month[$job_idx]] +' 20'+ evt_year[$job_idx] + '</td><td>' + $evt_job[$evt_event[$job_idx]] + '</td>'>>
			<<set $evtbody += '<td>' + setup.func('agentned', 'format_price_string', evt_wages[$job_idx]) + '₽</td><td>' + evt_hour[$job_idx] + ':' +  iif(evt_minutes[$job_idx] >= 0 and evt_minutes[$job_idx] <= 4, '00', '30') + '</td>'>>
				<<set $evtbody += '<td>' + evt_duration[$job_idx] + iif(evt_duration[$job_idx]  = 1, ' hour',  ' hours') + '</td><td>' + $evt_journal[$job_idx] + '</td>'>>
			<<set $evtbody += '<td><a  href="exec: gs 'emp_functions','del_evt', 2, job_idx"><<image 'images\system\icons\evt_del.png'>></a></a></td></tr>'>>
			<</if>>
			<<set $job_idx += 1>>
			<<if $job_idx < arrsize('evt_event')>>
				<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_list_create'>>

			<</if>>
			<<if $evtbody != ''>>
			<center><h2>Current Task List</h2></center>
			<<set $evtheader = '<tr><th>Date</th><th>Task</th><th>Pay</th><th>Time</th><th>Duration</th><th>Location</th><th>Cancel Job</th></tr>'>>
			<center><table width="90%" align="center" width="90%" cellspacing="5" cellpadding="5" valign="top"><tr><<$evtheader>><<$evtbody>></tr></table></center>
			<<set $evtbody to null>>
			<<set $evtheader to null>>
		<<else>>
			You haven''t taken on any jobs yet.
		<</if>>
	<</if>>
	<</if>>
	<!-- !! Display the location acts-->
	<<if $location_var[$here][1] == 3 and getvar("$evt_chk") == 1>>
		<<set $act_idx = 0>>
		<<set $act_tracker = 0>>
		<<set $act_found = 0>>
		<<warn 'JUMP MARKER ENCOUNTERED: :jmp_act_create'>>
		<<if $evt_hour[$act_tracker] == $time.hour or $evt_hour[$act_tracker] == (hour -1)>>
			<<set $act_found = 1>>
			<<set $act_idx = $act_tracker>>
		<</if>>
		<<set $act_tracker += 1>>
		<<if getvar("$act_found") == 0>>
			<<if $act_tracker < arrsize('evt_event')>>
				<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_act_create'>>

			<</if>>
		<</if>>
		<<if (($evt_hour[$act_idx] == $time.hour and $evt_minutes[$act_idx] <= $time.minutes) or $evt_hour[$act_idx] == (hour - 1)) and $loc == $evt_loc[$act_idx]>>
			<<actCLA 'Attend your ' + $evt_job[$evt_event['+$act_idx]+'] + ' event'>>
				<<gs 'emp_functions' 'array_init'>>
				<<if getvar("$evt_event") == 1>>
					<<gt 'photography_work' 'evt_stage'>>
				<<elseif $evt_trigger_exec != ''>>
					<<gt $evt_trigger_exec[$act_idx] $evt_trigger[$act_idx]>>
				<<else>>
					<<gt $evt_loc[$act_idx] $evt_loc_arg[$act_idx]>>
				<</if>>
				<<set $act_tracker to null>>
				<<set $act_found to null>>
			<</actCLA>>
		<</if>>
	<</if>>
<</if>>
<<if $location_var[$here][0] == 'gen_evt'>>
	<!-- !! Get the current year - remove 2000 to get the right year for search function.-->
	<<set $transient_evt_year = $time.year - 2000>>
	<!-- !! Figure out the month for the seed and ensure it rolls over into new calendar year.-->
	<<if $time.month == 12>>
		<<set $evt_mseed = 1>>
		<<set $transient_evt_year += 1>>
	<<else>>
		<<set $evt_mseed = $time.month + 1>>
	<</if>>
	<!-- !! randomise the month and month + 1-->
	<<set $transient_evt_month = rand(month,  evt_mseed)>>
	<<warn 'JUMP MARKER ENCOUNTERED: :jmp_job_create'>>
	<<if $transient_evt_month == $time.month>>
		<<if ($time.day + 7) > $time.monthsend[$transient_evt_month]>>
			<<set $transient_evt_month += 1>>
			<<set $evt_dseed = 1>>
		<</if>>
	<<else>>
		<<set $evt_dseed = $time.day + 1>>
	<</if>>
	<<set $rnd_day = rand(evt_dseed, monthsend[$transient_evt_month])>>
	<<if $transient_evt_month == $time.month and $rnd_day <= $time.day>>
		<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_job_create'>>

	<</if>>
	<!-- !! Set event transients - will be deleted upon completion-->
	<<set $transient_evt_hour = rand(9, 20)>>
	<!-- !! For simplicity sake make minutes on the hour or at half hour intervals, store as a single int.-->
	<<set $transient_evt_minutes = rand(0, 9)>>
	<!-- !! Set as multiples of 60-->
	<<if $transient_evt_duration == ''>>
	<<set $transient_evt_duration = rand(1,8)>>
	<</if>>
	<!-- !! logic check for when randomising event duration-->
	<<if $transient_evt_duration + getvar("$transient_evt_hour") >= 22>>
		<<set $transient_evt_hour = 22 - $transient_evt_duration>>
	<</if>>
	<!-- !! find a suitable date-->
	<<set $srch_day_u = $rnd_day + 7>>
	<<if $srch_day_u >= $time.monthsend[$transient_evt_month]>>
		<<set $srch_day_u = $time.monthsend[$transient_evt_month]>>
		<<set $srch_day_l = monthsend[$transient_evt_month]  - rand(7,14)>>
	<<else>>
		<<set $srch_day_l = $rnd_day>>
	<</if>>
	<<warn 'JUMP MARKER ENCOUNTERED: :setdayloop'>>
	<<gs 'shortgs' 'dow' $transient_evt_year $transient_evt_month $srch_day_l>>
	<<if $result == $transient_evt_dow>>
		<<set $transient_evt_day = $srch_day_l>>
		<<set $srch_day_l = 99>>
	<<else>>
		<<set $srch_day_l += 1>>
	<</if>>
	<<if $srch_day_l <= $srch_day_u>>
		<<warn 'JUMP COMMAND ENCOUNTERED: jump setdayloop'>>

	<</if>>
<</if>>
<!-- ! ------ Helper Functions -------->
<<if $location_var[$here][0] == 'job_evt'>>
	<!-- !! Jobs ID list-->
	<<setinit $evt_job[1] = 'Photography'>>
	<<setinit $evt_job[2] = 'Modelling'>>
	<<setinit $evt_job[3] = 'Music Gig'>>
	<<setinit $evt_job[4] = 'Dance Show'>>
	<<setinit $evt_job[5] = 'Ballet Performance'>>
	<<setinit $evt_job[6] = 'Acting'>>
	<<setinit $evt_job[50] = 'Sport'>>
<</if>>
<<if $location_var[$here][0] == 'wage_evt'>>
	<!-- !! calculate wages-->
	<!-- !! Assume you'll never earn less than 100 roubles-->
	<!-- !! 0 for none, 1 - for a small payment (100-500),  2 - moderate payment (500-1000), 3 - large payment (1000-2000),  4 - huge payment (2000-4000)-->
	<!-- !! 5 is for custom payments-->
	<<if $location_var[$here][1] == 0>>
		<<set $transient_evt_wages = 0>>
	<<elseif $location_var[$here][1] == 1>>
		<<set $transient_evt_wages = setup.func('shortgs','round_tool',rand(100,500), 50)>>
	<<elseif $location_var[$here][1] == 2>>
		<<set $transient_evt_wages = setup.func('shortgs','round_tool',rand(500,1000), 50)>>
	<<elseif $location_var[$here][1] == 3>>
		<<set $transient_evt_wages = setup.func('shortgs','round_tool',rand(1000,2000), 50)>>
	<<elseif $location_var[$here][1] == 4>>
		<<set $transient_evt_wages = setup.func('shortgs','round_tool',rand(2000,4000), 50)>>
	<<elseif $location_var[$here][1] == 5>>
		<<set $transient_evt_wages = $larg(2)>>
	<</if>>
<</if>>
<<if $location_var[$here][0] == 'cat_evt'>>
	<!-- !! Construct Array Table  and clear transients when an event is created and accepted.-->
	<!-- !! Create global variables for the current live event.-->
	<!-- !! Use 0 to create hidden events, 1 to show in journal-->
	<<setinitpush "$evt_silent" $transient_evt_silent>>
	<!-- !! Event job descriptor used in Journal-->
	<<setinitpush "$evt_event" $transient_evt>>
	<!-- !! Additional job ID if required-->
	<<setinitpush "$evt_event_sub" $transient_evt_sub>>
	<!-- !! Day of Week used in Journal and content areas-->
	<<setinitpush "$evt_dow" $transient_evt_dow>>
	<!-- !! Event Date to check against current date & used in Journal and content areas-->
	<<setinitpush "$evt_day" $transient_evt_day>>
	<!-- !! Event month to check against current month & used in Journal and content areas-->
	<<setinitpush "$evt_month" $transient_evt_month>>
	<!-- !! Event Year to check against year & used in Journal and content areas-->
	<<setinitpush "$evt_year" $transient_evt_year>>
	<!-- !! Event hour to check against hour & used in Journal and content areas-->
	<<setinitpush "$evt_hour" $transient_evt_hour>>
	<!-- !! Event minutes to check against minut & used in Journal and content areas-->
	<<setinitpush "$evt_minutes" $transient_evt_minutes>>
	<!-- !! How long the event is to last-->
	<<setinitpush "$evt_duration" $transient_evt_duration>>
	<!-- !! How much wages, generated or manual using function-->
	<<setinitpush "$evt_wages" $transient_evt_wages>>
	<!-- !! Journal location as reminder-->
	<<setinitpush "$evt_journal" $transient_journal>>
	<!-- !! The following are event location triggers to allow the content to appear in areas such as community centre but host their content elsewhere such as Photography shop-->
	<!-- !! 	Event area triggers such as city_residential-->
	<<setinitpush "$evt_loc" $transient_loc>>
	<<setinitpush "$evt_loc_arg" $transient_arg>>
	<!-- !! Content location - optional-->
	<<set $evt_trigger_exec = $transient_evt_exec>>
	<<setinitpush "$evt_trigger" $transient_trigger>>
	<!-- !! Journal and event description-->
	<<setinitpush "$evt_desc" $transient_desc>>
	<<if getvar("$transient_evt_silent") == 1>>
		<p>Job accepted, you currently have ' + arrsize('evt_event') + ' jobs assigned to you. Please look at your journal for more information.</p>
		<<gs 'emp_functions' 'del_evt' 1>>
		<<act 'Return'>>
			<<gt 'emp_functions' 'evt_init'>>
		<</act>>
	<</if>>
<</if>>
<!-- !! delete event after firing or cancelled-->
<<if $location_var[$here][0] == 'del_evt'>>
	<!-- !! Delete transients-->
	<<if $location_var[$here][1] == 1>>
		<<set $transient_evt_silent to null>>
		<<set $transient_event_type to null>>
		<<set $transient_evt_year to null>>
		<<set $transient_evt_month to null>>
		<<set $transient_evt_hour to null>>
		<<set $transient_evt_minutes to null>>
		<<set $transient_evt_duration to null>>
		<<set $transient_evt_wages to null>>
		<<set $transient_loc  = 0>>
		<<set $transient_arg to null>>
		<<set $transient_trigger to null>>
		<<set $transient_img to null>>
		<<set $transient_desc to null>>
		<<set $rnd_min to null>>
		<<set $mseed to null>>
		<<set $dseed to null>>
	<</if>>
	<!-- ! Delete array entry-->
	<<if $location_var[$here][1] == 2>>
		<!-- !! delete event after firing or cancelled.-->
		<!-- !! killvar 'arr_name', index-->
		<<if $location_var[$here][2] >= 0>>
			<<set $evt_idx = $larg(2)>>
			You're about to delete this job: 
			'Delete: ' + $evt_event
			'Index: ' + $evt_idx
			<<actCLA 'Confirm?'>>
				<p>Are you sure?</p>
				<<actCLA 'Deleting'>>
					<<set $evt_silent[$evt_idx] to null>>
					<<set $evt_event[$evt_idx] to null>>
					<<set $evt_dow[$evt_idx] to null>>
					<<set $evt_day[$evt_idx] to null>>
					<<set $evt_month[$evt_idx] to null>>
					<<set $evt_year[$evt_idx] to null>>
					<<set $evt_hour[$evt_idx] to null>>
					<<set $evt_minutes[$evt_idx] to null>>
					<<set $evt_duration[$evt_idx] to null>>
					<<set $evt_wages[$evt_idx] to null>>
					<<set $evt_mc_locat[$evt_idx] to null>>
					<<set $evt_loc[$evt_idx] to null>>
					<<set $evt_loc_arg[$evt_idx] to null>>
					<<set $evt_exec[$evt_idx] to null>>
					<<set $evt_media[$evt_idx] to null>>
					<<set $evt_desc[$evt_idx] to null>>
					<<actCLA 'Return'>>
						<<gs 'journal_work' 'start'>>
					<</actCLA>>
				<</actCLA>>
				<<actCLA 'Cancel'>>
					<<gs 'journal_work' 'start'>>
				<</actCLA>>
			<</actCLA>>
		<<else>>
			<p>evt_idx - Invalid record - please check your index</p>
		<</if>>
	<</if>>
<</if>>
<<if $location_var[$here][0] == 'evt_day_suffix'>>
	<<if $location_var[$here][1] != ''>>
		<<set $query_day = $larg(1)>>
	<<else>>
		<<set $query_day = $transient_evt_day>>
	<</if>>
	<<if getvar("$query_day") >= 20 and getvar("$query_day") < 30>>
		<<set $test_day = $query_day - 20>>
	<<else>>
		<<set $test_day = $query_day>>
	<</if>>
	<<if $transient_evt_day != ''>>
		<<if getvar("$test_day") >= 4 and getvar("$test_day") <= 10>>
		<<set $evt_suffix = 'th'>>
		<<elseif getvar("$test_day") == 1 or getvar("$test_day") == 31>>
		<<set $evt_suffix = 'st'>>
		<<elseif getvar("$test_day") == 2>>
		<<set $evt_suffix = 'nd'>>
	<<elseif getvar("$test_day") == 3>>
		<<set $evt_suffix = 'rd'>>
	<<else>>
		<<set $evt_suffix = 'th'>>
	<</if>>
	<</if>>
	<<if $time.day >= 4 and $time.day <= 10>>
		<<set $date_suffix = 'th'>>
	<<elseif $time.day == 1 or $time.day == 21 or $time.day == 31>>
		<<set $date_suffix = 'st'>>
	<<elseif $time.day == 2 or $time.day == 22>>
		<<set $date_suffix = 'nd'>>
	<<elseif getvar("$test_day") == 3>>
		<<set $date_suffix = 'rd'>>
	<<else>>
		<<set $date_suffix = 'th'>>
	<</if>>
	<<set $test_day to null>>
	<<set $query_day to null>>
<</if>>
<<if $location_var[$here][0] == 'evt_day_chk'>>
	<!-- !! Daily event trigger to check if there is an event at currently location to reduce calls/overheads-->
	<<set $evt_chk = 0>>
	<<if $evt_daily_chk != $time.daystart>>
		<<set $evt_daily_chk = $time.daystart>>
		<<set $job_idx = 0>>
		<<warn 'JUMP MARKER ENCOUNTERED: :evt_day_chk'>>
		<<if $time.month == $evt_month and $time.day == $evt_day>>
			<<set $evt_chk = 1>>

		<</if>>
		<<set $job_idx += 1>>
		<<if $job_idx < arrsize('evt_event')>>
			<<warn 'JUMP COMMAND ENCOUNTERED: jump evt_day_chk'>>

		<</if>>
	<</if>>
<</if>>
<!-- !! --------------------- End Event Generator-->
<!-- !! --------------------- Job management system-->
<!-- !! book role, creates a time slot for emp_rota_week in format day_hour to be used in schedule mode.-->
<<if $location_var[$here][0] == 'emp_booking'>>
	<<gs 'emp_functions' 'emp_chk_clk'>>
	<<if getvar("$emp_rota_fail") == 0>>
		<<gs 'emp_functions' 'loop_configure'>>
		<<set $j_finish = $emp_job_end[$j_id]>>
		<<warn 'JUMP MARKER ENCOUNTERED: :jmp_daily_book'>>
		<<set $j_idx = $emp_job_start[$j_id]>>
		<<warn 'JUMP MARKER ENCOUNTERED: :jmp_hour_book'>>
		<<setinit $emp_rota_week[$d_idx + '_' + $j_idx] = $j_id>>
		<<set $j_idx += 1>>
		<<if $j_idx <= $j_finish>>
			<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_hour_book'>>

		<</if>>
		<<set $d_idx += 1>>
		<<if $d_idx <= $d_end>>
			<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_daily_book'>>

		<</if>>
		<<setinit $emp_job_status[$j_id] = 1>>
		<<setinit $emp_job[$active] += 1>>
		<<set $j_idx to null>>
		<<set $j_finish to null>>
		<<set $d_idx to null>>
		<<set $d_end to null>>
	<<else>>
		<<msg 'Sorry, you""ve already got a job for this time period.'>>
	<</if>>
	<<set $emp_rota_fail to null>>
<</if>>
<!-- !! check if time slots are avaialble for this role.-->
<<if $location_var[$here][0] == 'emp_chk_clk'>>
	<<gs 'emp_functions' 'loop_configure'>>
	<<set $j_finish = $emp_job_end[$j_id]>>
	<<warn 'JUMP MARKER ENCOUNTERED: :jmp_daily_chk'>>
	<<set $j_idx = $emp_job_start[$j_id]>>
	<<warn 'JUMP MARKER ENCOUNTERED: :jmp_job_chk'>>
	<<if $emp_rota_week[$d_idx + '_' + $j_idx] > 0>>
		<!-- !! booking failed-->
		<<set $emp_rota_fail = 1>>
	<<else>>
		<!-- !! booking passed-->
		<<set $emp_rota_fail = 0>>
	<</if>>
	<<set $j_idx += 1>>
	<<if $j_idx <= $j_finish and getvar("$emp_rota_fail") == 0>>
		<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_job_chk'>>

	<</if>>
	<<set $d_idx += 1>>
	<<if $d_idx <= $d_end and getvar("$emp_rota_fail") == 0>>
		<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_daily_chk'>>

	<</if>>
<</if>>
<<if $location_var[$here][0] == 'emp_terminate'>>
	<<if $location_var[$here][1] >= 4>>
		<<gs 'emp_functions' 'loop_configure'>>
		<<set $j_finish = $emp_job_end[$j_id]>>
		<<warn 'JUMP MARKER ENCOUNTERED: :jmp_daily_book'>>
		<<set $j_idx = $emp_job_start[$j_id]>>
		<<warn 'JUMP MARKER ENCOUNTERED: :jmp_hour_book'>>
		<<setinit $emp_rota_week[$d_idx + '_' + $j_idx] = 0>>
		<<set $j_idx += 1>>
		<<if $j_idx <= $j_finish>>
			<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_hour_book'>>

		<</if>>
		<<set $d_idx += 1>>
		<<if $d_idx <= $d_end>>
			<<warn 'JUMP COMMAND ENCOUNTERED: jump jmp_daily_book'>>

		<</if>>
		<!-- !! Set the termination value-->
		<<setinit $emp_job_status[$j_id] = $larg(1)>>
		<<setinit $emp_job[$active] -= 1>>
	<<else>>
		<<msg 'Job termination failed. Please ensure you set to  4 - Terminated or 5 - Fired'>>
	<</if>>
	<<set $j_idx to null>>
	<<set $j_finish to null>>
	<<set $d_idx to null>>
	<<set $d_end to null>>
<</if>>
<<if $location_var[$here][0] == 'loop_configure'>>
	<<if getvar("$j_day") == 0 or getvar("$j_day") == 1 or getvar("$j_day") == 2>>
		<<set $d_idx = 1>>
	<<else>>
		<<set $d_idx = 6>>
	<</if>>
	<<if getvar("$j_day") <= 1>>
		<<set $d_end = 5>>
	<<else>>
		<<set $d_end = 7>>
	<</if>>
<</if>>
