#####################################################
# Create the list menu for the "Alarm" button                               #
#####################################################


proc display_alarm_list2 { } {

	global alframe2
	global aldescr2
	
	set alframe2 .alarm_list2
	set aldescr2 $alframe2.descr

	if [winfo exists $alframe2] {destroy $alframe2}
		
	global env
	set env(DISPLAY) :0.1
	toplevel $alframe2
	wm title $alframe2 "Alarm List"
	
	text $aldescr2 -width 35 -height 10
	
	scrollbar $alframe2.scroll -command {$alframe2.lb yview}
        listbox $alframe2.lb -width 25 -height 10 -yscroll "$alframe2.scroll set"

        # Analog
        for {set i 1} {$i <= 48} {incr i} {

        	if { [check_ana_status $i] == 1 } {
        		set str [get_ana_alarm_name $i]
        	 	$alframe2.lb insert end $str        	
        	}
        }

        # Digital
        for {set i 1} {$i <= 32} {incr i} {
        	
        	if { [check_dig_status $i] == 1 } {
        		set str [get_dig_alarm_name $i]
        	 	$alframe2.lb insert end $str        	
        	}
        	
        }
	
        # Other
        for {set i 1} {$i <= 99} {incr i} {
        	
        	if { [check_other_status $i] == 1 } {
        		set str [get_other_alarm_name $i]
        	 	$alframe2.lb insert end $str        	
        	}
        }

	
        bind $alframe2.lb <ButtonRelease-1> {
        	
        	#destroy $aldescr2
        	
        	# deleting the first line up to the 10th line (height of text widget)
        	$aldescr2 delete 1.0 10.0
        	set name [selection get]
        	set descr [get_alarm_descr $name]
        	$aldescr2 insert end $descr
	}

	# Create frame to contains buttons on the bottom of list
	frame $alframe2.frame
	
	# Creating a Close button
	button $alframe2.frame.close -text "Close" \
		-command {destroy $alframe2; destroy $aldescr2}
	
	# Creating a Clear list
	button $alframe2.frame.clear -text "Clear List" \
		-command {
				# Call c++ function to set all alarm status to be 0 again
			   	clear_alarm_list
			   	
			   	# Set the "Alarm List" button (from "test.tcl") back to grey
			   	if [winfo exists .ventana.bar.alarm] {
			   		.ventana.bar.alarm configure -bg #d9d9d9
			   	}
			   	
			   	.ventana2.bar.alarm configure -bg #d9d9d9
			
			   	# Traverse the list and delete it one by one
			   	set count [$alframe2.lb index end]
			   	for {set i 0} {$i < $count} {incr i} {
			   		$alframe2.lb delete $i
			   	}
			   	
			   	# Tell the sub that we clear up the alarm list here
			   	send_clear_list_to_bottom
			   	
			   	# clean up the description box
			   	$aldescr2 delete 1.0 10.0	 }
	   		
			
	#------------------#
	# Pack things up   #	
	#------------------#
	
	pack $alframe2.frame -side bottom
	pack $alframe2.frame.close $alframe2.frame.clear -side left
        pack $alframe2.lb $alframe2.scroll $aldescr2 -side left -fill y -expand 1



}