# alarmclock

if $ARGS[0] = 'start':
	menu_off = 1
	gs 'stat'
	'<center><img <<$set_imgh>> src="images/shared/home/bedroom/bed2.jpg"></center>'
	'<center><h4>Enter the time using the number pad and click on set to change alarm times, don''t forget to turn your alarm on.</h></center>'
	*nl
	gs 'alarmclock', 'build_table'

	act 'Finish':
		bud1 = 0
		bud2 = 0
		bud3 = 0
		bud4 = 0
		numbud = 0
		gt 'alarmclock', 'fin'
	end
	act 'Clear time display':
		bud1 = 0
		bud2 = 0
		bud3 = 0
		bud4 = 0
		numbud = 0
		gt 'alarmclock', 'start'
	end
end

if $ARGS[0] = 'alarm_display':
	!! func('alarmclock', 'alarm_display', hour, minutes)
	$result = '<b><<$mid(100 + ARGS[1], 2, 2)>>:<<$mid(100 + ARGS[2], 2, 2)>></b>'
end

if $ARGS[0] = 'clear':
	cla
	bud1 = 0
	bud2 = 0
	bud3 = 0
	bud4 = 0
	numbud = 0
	gt 'alarmclock', 'start'
end

if $ARGS[0] = 'Time':
	alarmVars['alarmOn'] = 1

	if bud_weekend = 1:
		alarmVars['timerEndH'] = bud1 * 10 + bud2
		alarmVars['timerEndM'] = bud3 * 10 + bud4

		if alarmVars['timerEndH'] > 23: alarmVars['timerEndH'] = 0
		if alarmVars['timerEndM'] > 60: alarmVars['timerEndM'] = 0
	else
		alarmVars['timerH'] = bud1 * 10 + bud2
		alarmVars['timerM'] = bud3 * 10 + bud4

		if alarmVars['timerH'] > 23: alarmVars['timerH'] = 0
		if alarmVars['timerM'] > 60: alarmVars['timerM'] = 0
	end

	gt 'alarmclock', 'start'
end

if $ARGS[0] = '1':
	!!if numbud = 4:end
	if numbud = 3: bud4 = 1 & numbud = 4
	if numbud = 2: bud3 = 1 & numbud = 3
	if numbud = 1: bud2 = 1 & numbud = 2
	if numbud = 0: bud1 = 1 & numbud = 1

	gt 'alarmclock', 'start'
end

if $ARGS[0] = '2':
	!!if numbud = 4:end
	if numbud = 3: bud4 = 2 & numbud = 4
	if numbud = 2: bud3 = 2 & numbud = 3
	if numbud = 1: bud2 = 2 & numbud = 2
	if numbud = 0: bud1 = 2 & numbud = 1

	gt 'alarmclock', 'start'
end

if $ARGS[0] = '3':
	!!if numbud = 4:end
	if numbud = 3: bud4 = 3 & numbud = 4
	if numbud = 2: bud3 = 3 & numbud = 3
	if numbud = 1: bud2 = 3 & numbud = 2
	if numbud = 0: bud1 = 3 & numbud = 1

	gt 'alarmclock', 'start'
end

if $ARGS[0] = '4':
	!!if numbud = 4:end
	if numbud = 3: bud4 = 4 & numbud = 4
	if numbud = 2: bud3 = 4 & numbud = 3
	if numbud = 1: bud2 = 4 & numbud = 2
	if numbud = 0: bud1 = 4 & numbud = 1

	gt 'alarmclock', 'start'
end

if $ARGS[0] = '5':
	!!if numbud = 4:end
	if numbud = 3: bud4 = 5 & numbud = 4
	if numbud = 2: bud3 = 5 & numbud = 3
	if numbud = 1: bud2 = 5 & numbud = 2
	if numbud = 0: bud1 = 5 & numbud = 1

	gt 'alarmclock', 'start'
end

if $ARGS[0] = '6':
	!!if numbud = 4:end
	if numbud = 3: bud4 = 6 & numbud = 4
	if numbud = 2: bud3 = 6 & numbud = 3
	if numbud = 1: bud2 = 6 & numbud = 2
	if numbud = 0: bud1 = 6 & numbud = 1

	gt 'alarmclock', 'start'
end

if $ARGS[0] = '7':
	!!if numbud = 4:end
	if numbud = 3: bud4 = 7 & numbud = 4
	if numbud = 2: bud3 = 7 & numbud = 3
	if numbud = 1: bud2 = 7 & numbud = 2
	if numbud = 0: bud1 = 7 & numbud = 1

	gt 'alarmclock', 'start'
end

if $ARGS[0] = '8':
	!!if numbud = 4:end
	if numbud = 3: bud4 = 8 & numbud = 4
	if numbud = 2: bud3 = 8 & numbud = 3
	if numbud = 1: bud2 = 8 & numbud = 2
	if numbud = 0: bud1 = 8 & numbud = 1

	gt 'alarmclock', 'start'
end

if $ARGS[0] = '9':
	!!if numbud = 4:end
	if numbud = 3: bud4 = 9 & numbud = 4
	if numbud = 2: bud3 = 9 & numbud = 3
	if numbud = 1: bud2 = 9 & numbud = 2
	if numbud = 0: bud1 = 9 & numbud = 1

	gt 'alarmclock', 'start'
end

if $ARGS[0] = '0':
	!!if numbud = 4:end
	if numbud = 3: bud4 = 0 & numbud = 4
	if numbud = 2: bud3 = 0 & numbud = 3
	if numbud = 1: bud2 = 0 & numbud = 2
	if numbud = 0: bud1 = 0 & numbud = 1

	gt 'alarmclock', 'start'
end

if $ARGS[0] = 'Reset':
	if bud_weekend = 1:
		alarmVars['timerEndH'] = 0
		alarmVars['timerEndM'] = 0
	else
		alarmVars['timerH'] = 0
		alarmVars['timerM'] = 0
	end
	bud1 = 0
	bud2 = 0
	bud3 = 0
	bud4 = 0
	numbud = 0

	gt 'alarmclock', 'start'
end

if $ARGS[0] = 'fin':gt $loc, $loc_arg


if $ARGS[0] = 'build_table':

	$num_html = '<td align="center"><b><font size="+2">'
	$html_num = '</a></font></b></td>'
	$more_html = '<center><table width="20%" cellspacing=0 cellpadding=3 align="center" border=1><tr align="center"><th COLSPAN=3 align="center"><font size="+3">'
	$even_more_html = '</font></th></tr>'
	if numbud = 4:$alarm_html = '<<bud1>><<bud2>> : <<bud3>><<bud4>>'
	if numbud = 3:$alarm_html = '<<bud1>><<bud2>> : <<bud3>><U><<bud4>></U>'
	if numbud = 2:$alarm_html = '<<bud1>><<bud2>> : <U><<bud3>></U><<bud4>>'
	if numbud = 1:$alarm_html = '<<bud1>><U><<bud2>></U> : <<bud3>><<bud4>>'
	if numbud = 0:$alarm_html = '<U><<bud1>></U><<bud2>> : <<bud3>><<bud4>>'

	$numbud_table='<tr><td colspan=3 align="center"><b><font size="+2"><a href="exec:gt ''alarmclock'', ''clear''">Clear</a></font></b></td></tr>'
	$numbud_table+='<tr><<$num_html>><a href="exec:gt ''alarmclock'', ''1''">1<<$html_num>>'
	$numbud_table+='<<$num_html>><a href="exec:gt ''alarmclock'', ''2''">2<<$html_num>>'
	$numbud_table+='<<$num_html>><a href="exec:gt ''alarmclock'', ''3''">3<<$html_num>></tr>'
	$numbud_table+='<tr><<$num_html>><a href="exec:gt ''alarmclock'', ''4''">4<<$html_num>>'
	$numbud_table+='<<$num_html>><a href="exec:gt ''alarmclock'', ''5''">5<<$html_num>>'
	$numbud_table+='<<$num_html>><a href="exec:gt ''alarmclock'', ''6''">6<<$html_num>></tr>'
	$numbud_table+='<tr><<$num_html>><a href="exec:gt ''alarmclock'', ''7''">7<<$html_num>>'
	$numbud_table+='<<$num_html>><a href="exec:gt ''alarmclock'', ''8''">8<<$html_num>>'
	$numbud_table+='<<$num_html>><a href="exec:gt ''alarmclock'', ''9''">9<<$html_num>></tr>'
	$numbud_table+='<tr><td colspan=3 align="center"><b><font size="+2"><a href="exec:gt ''alarmclock'', ''0''">0</a></font></b></td></tr></table></center>'

	$alarmVars_table='<center><table border=0 cellpadding=0 cellspacing=5><font size="+1"<b>'
	$alarmVars_table+='<tr><td><b><a href="exec: bud_weekend = 0 & gt ''alarmclock'', ''Reset''">Reset weekday alarm</a></b></td>'
	$alarmVars_table+='<td><b><a href="exec: bud_weekend = 0 & gt ''alarmclock'', ''Time''">Set weekday alarm</a></b></td>'
	$alarmVars_table+='<td><b>Currently set for <<func(''alarmclock'', ''alarm_display'', alarmVars[''timerH''], alarmVars[''timerM''])>></b></td></tr>'
	
	$alarmVars_table+='<tr><td><b><a href="exec: bud_weekend = 1 & gt ''alarmclock'', ''Reset''">Reset weekend alarm</a></b></td>'
	$alarmVars_table+='<td><b><a href="exec: bud_weekend = 1 & gt ''alarmclock'', ''Time''">Set weekend alarm</a></b></td>'
	$alarmVars_table+='<td><b>Currently set for <<func(''alarmclock'', ''alarm_display'', alarmVars[''timerEndH''], alarmVars[''timerEndM''])>></b></td></tr>'

	if mid($start_type,1,2) = 'sg':
		$alarmVars_table+='<tr><td colspan="3"><b>Use weekend alarm for holidays - ' + iif(alarmVars['alarm_holiday'] = 0, '<a href="exec: alarmVars[''alarm_holiday''] = 1 & gt ''alarmclock'', ''start''">OFF</a>', '<a href="exec:  alarmVars[''alarm_holiday''] = 0 & gt ''alarmclock'', ''start''">ON</a>') + '</b></td></tr>'
	end

	$alarmVars_table+='<tr><td colspan="3"><b>Your alarm is currently turned ' + iif(alarmVars['alarmOn'] = 0, '<a href="exec: alarmVars[''alarmOn''] = 1 & gt ''alarmclock'', ''start''">OFF</a>', '<a href="exec: alarmVars[''alarmOn''] = 0 & gt ''alarmclock'', ''start''">ON</a>') + '.</b></td></tr>'

	if alarmVars['alarmOn'] = 1:
		$alarmVars_table+='</table></center><center><table border=0 cellpadding=0 cellspacing=10><tr><td><b>Your Alarm is ' + iif(alarmVars['timerH'] <= 0 and alarmVars['timerM'] <= 0, 'not set', 'set to ' + func('alarmclock', 'alarm_display', alarmVars['timerH'], alarmVars['timerM'])) + ' for the weekdays ' + iif(alarmVars['timerEndH'] <= 0 and alarmVars['timerEndM'] <= 0, 'and not set', 'and set to ' + func('alarmclock', 'alarm_display', alarmVars['timerEndH'], alarmVars['timerEndM'])) + ' for the weekend' + iif(alarmVars['alarm_holiday'] = 1, ' and holidays', '') + '.</b></td></tr>'
	end
	$alarmVars_table+='</b></font></table></center>'

	'<<$more_html>><<$alarm_html>><<$even_more_html>><<$numbud_table>>'
	'<<$alarmVars_table>>'

	killvar '$num_html'
	killvar '$html_num'
	killvar '$alarm_html'
	killvar '$numbud_table'
	killvar '$more_html'
	killvar '$even_more_html'
	killvar '$alarmVars_table'

end




--- alarmclock ---------------------------------
