global num_of_items
set num_of_items 0
set surface .ventana.bar.maintenance.menu.element.surface
set surface2 .ventana.bar.maintenance.menu.element.surface

proc add_output2 { sv } {

   global elem_num surface surface2
   global num_of_items

   # if it is output for vehicle
   if { $sv == 0 } {

   	set addout2 .add_output2	
   	if [winfo exists $addout2] {destroy $addout2}

   	global env
   	set env(DISPLAY) :0.1
   	toplevel $addout2 -width 10c -height 5c
   	wm title $addout2 "Add Output"


   	label $addout2.title -text "Adding Output"  -relief groove -fg blue
   	
   	menubutton $addout2.anaout -text "Analog Out" -menu $addout2.anaout.menu

   	#----------------------------------------------------------#		
   	# Create the Analog Out submenu
   	#----------------------------------------------------------#

   	menu $addout2.anaout.menu

   	$addout2.anaout.menu add command -label "1 [get_element_name 1 3 1]" \
		-command { create_anaout_item2 1 }
				
	$addout2.anaout.menu add command -label "2 [get_element_name 1 3 2]" \
		-command { create_anaout_item2 2 }
	
	$addout2.anaout.menu add command -label "3 [get_element_name 1 3 3]" \
		-command { create_anaout_item2 3 }
		
	$addout2.anaout.menu add command -label "4 [get_element_name 1 3 4]" \
		-command { create_anaout_item2 4 }


   	   	
   #----------------------------------------------------------#
   # Add a Close button
   #----------------------------------------------------------#

   button $addout2.close -text Close -command {destroy .add_output2}

   #----------------------------------------------------------#
   # Pack things up
   #----------------------------------------------------------#
   pack $addout2.title -side top  -fill x -padx 3 -pady 3
   pack  $addout2.anaout -side top	
   pack $addout2.close -side bottom -pady 3m


	
   #----------------------------------------------------------#
   # else , it is output for SURFACE
   #----------------------------------------------------------#
	
   } else {

   #----------------------------------------------------------#
   # Initially the number of items in the list is 0
   #----------------------------------------------------------#

   set addout2 .add_output2


   if [winfo exists $addout2] {destroy $addout2}

   global env
   set env(DISPLAY) :0
   toplevel $addout2 -width 10c -height 5c
   wm title $addout2 "Add Output"


   label $addout2.title -text "Adding Output"  -relief groove -fg blue

   menubutton $addout2.dig -text Digital -menu $addout2.dig.menu
   menubutton $addout2.ana -text Analog -menu $addout2.ana.menu

   #----------------------------------------------------------#
   # Create the Digital submenu
   #----------------------------------------------------------#

   menu $addout2.dig.menu
   $addout2.dig.menu add cascade -label GESOUT \
	-menu $addout2.dig.menu.gesout
   $addout2.dig.menu add cascade -label MPL \
	-menu $addout2.dig.menu.mpl

   #----------------------------------------------------------#
   # Create submenu for "GESOUT"	
   #----------------------------------------------------------#

   menu $addout2.dig.menu.gesout
   $addout2.dig.menu.gesout add cascade -label "1-8" \
   	-menu $addout2.dig.menu.gesout.b1
   $addout2.dig.menu.gesout add cascade -label "9-16" \
   	-menu $addout2.dig.menu.gesout.b2
   $addout2.dig.menu.gesout add cascade -label "17-24" \
   	-menu $addout2.dig.menu.gesout.b3
   $addout2.dig.menu.gesout add cascade -label "25-32" \
   	-menu $addout2.dig.menu.gesout.b4
   $addout2.dig.menu.gesout add cascade -label "33-40" \
   	-menu $addout2.dig.menu.gesout.b5
   $addout2.dig.menu.gesout add cascade -label "41-48" \
   	-menu $addout2.dig.menu.gesout.b6
   $addout2.dig.menu.gesout add cascade -label "49-56" \
   	-menu $addout2.dig.menu.gesout.b7
   $addout2.dig.menu.gesout add cascade -label "57-64" \
   	-menu $addout2.dig.menu.gesout.b8

   	
   menu $addout2.dig.menu.gesout.b1
   $addout2.dig.menu.gesout.b1 add command -label "1" \
	-command {list_output2 "Dig Gesout 1" }
   $addout2.dig.menu.gesout.b1 add command -label "2" \
	-command {list_output2 "Dig Gesout 2" }
   $addout2.dig.menu.gesout.b1 add command -label "3" \
	-command {list_output2 "Dig Gesout 3" }
   $addout2.dig.menu.gesout.b1 add command -label "4" \
	-command {list_output2 "Dig Gesout 4" }
   $addout2.dig.menu.gesout.b1 add command -label "5" \
	-command {list_output2 "Dig Gesout 5" }
   $addout2.dig.menu.gesout.b1 add command -label "6" \
	-command {list_output2 "Dig Gesout 6" }
   $addout2.dig.menu.gesout.b1 add command -label "7" \
	-command {list_output2 "Dig Gesout 7" }
   $addout2.dig.menu.gesout.b1 add command -label "8" \
	-command {list_output2 "Dig Gesout 8" }


   menu $addout2.dig.menu.gesout.b2
   $addout2.dig.menu.gesout.b2 add command -label "9" \
	-command {list_output2 "Dig Gesout 9"}
   $addout2.dig.menu.gesout.b2 add command -label "10" \
	-command {list_output2 "Dig Gesout 10"}
   $addout2.dig.menu.gesout.b2 add command -label "11" \
	-command {list_output2 "Dig Gesout 11"}
   $addout2.dig.menu.gesout.b2 add command -label "12" \
	-command {list_output2 "Dig Gesout 12"}
   $addout2.dig.menu.gesout.b2 add command -label "13" \
	-command {list_output2 "Dig Gesout 13"}
   $addout2.dig.menu.gesout.b2 add command -label "14" \
	-command {list_output2 "Dig Gesout 14"}
   $addout2.dig.menu.gesout.b2 add command -label "15" \
	-command {list_output2 "Dig Gesout 15"}
   $addout2.dig.menu.gesout.b2 add command -label "16" \
	-command {list_output2 "Dig Gesout 16"}


   menu $addout2.dig.menu.gesout.b3
   $addout2.dig.menu.gesout.b3 add command -label "17" \
	-command {list_output2 "Dig Gesout 17"}
   $addout2.dig.menu.gesout.b3 add command -label "18" \
	-command {list_output2 "Dig Gesout 18"}
   $addout2.dig.menu.gesout.b3 add command -label "19" \
	-command {list_output2 "Dig Gesout 19"}
   $addout2.dig.menu.gesout.b3 add command -label "20" \
	-command {list_output2 "Dig Gesout 20"}
   $addout2.dig.menu.gesout.b3 add command -label "21" \
	-command {list_output2 "Dig Gesout 21"}
   $addout2.dig.menu.gesout.b3 add command -label "22" \
	-command {list_output2 "Dig Gesout 22"}
   $addout2.dig.menu.gesout.b3 add command -label "23" \
	-command {list_output2 "Dig Gesout 23"}
   $addout2.dig.menu.gesout.b3 add command -label "24" \
	-command {list_output2 "Dig Gesout 24"}


   menu $addout2.dig.menu.gesout.b4
   $addout2.dig.menu.gesout.b4 add command -label "25" \
	-command {list_output2 "Dig Gesout 25"}
   $addout2.dig.menu.gesout.b4 add command -label "26" \
	-command {list_output2 "Dig Gesout 26"}
   $addout2.dig.menu.gesout.b4 add command -label "27" \
	-command {list_output2 "Dig Gesout 27"}
   $addout2.dig.menu.gesout.b4 add command -label "28" \
	-command {list_output2 "Dig Gesout 28"}
   $addout2.dig.menu.gesout.b4 add command -label "29" \
	-command {list_output2 "Dig Gesout 29"}
   $addout2.dig.menu.gesout.b4 add command -label "30" \
	-command {list_output2 "Dig Gesout 30"}
   $addout2.dig.menu.gesout.b4 add command -label "31" \
	-command {list_output2 "Dig Gesout 31"}
   $addout2.dig.menu.gesout.b4 add command -label "32" \
	-command {list_output2 "Dig Gesout 32"}

	

	

   menu $addout2.dig.menu.gesout.b5
   $addout2.dig.menu.gesout.b5 add command -label "33" \
	-command {list_output2 "Dig Gesout 33"}
   $addout2.dig.menu.gesout.b5 add command -label "34" \
	-command {list_output2 "Dig Gesout 34"}
   $addout2.dig.menu.gesout.b5 add command -label "35" \
	-command {list_output2 "Dig Gesout 35"}
   $addout2.dig.menu.gesout.b5 add command -label "36" \
	-command {list_output2 "Dig Gesout 36"}
   $addout2.dig.menu.gesout.b5 add command -label "37" \
	-command {list_output2 "Dig Gesout 37"}
   $addout2.dig.menu.gesout.b5 add command -label "38" \
	-command {list_output2 "Dig Gesout 38"}
   $addout2.dig.menu.gesout.b5 add command -label "39" \
	-command {list_output2 "Dig Gesout 39"}
   $addout2.dig.menu.gesout.b5 add command -label "40" \
	-command {list_output2 "Dig Gesout 40"}
	
   menu $addout2.dig.menu.gesout.b6
   $addout2.dig.menu.gesout.b6 add command -label "41" \
	-command {list_output2 "Dig Gesout 41"}
   $addout2.dig.menu.gesout.b6 add command -label "42" \
	-command {list_output2 "Dig Gesout 42"}
   $addout2.dig.menu.gesout.b6 add command -label "43" \
	-command {list_output2 "Dig Gesout 43"}
   $addout2.dig.menu.gesout.b6 add command -label "44" \
	-command {list_output2 "Dig Gesout 44"}
   $addout2.dig.menu.gesout.b6 add command -label "45" \
	-command {list_output2 "Dig Gesout 45"}
   $addout2.dig.menu.gesout.b6 add command -label "46" \
	-command {list_output2 "Dig Gesout 46"}
   $addout2.dig.menu.gesout.b6 add command -label "47" \
	-command {list_output2 "Dig Gesout 47"}
   $addout2.dig.menu.gesout.b6 add command -label "48" \
	-command {list_output2 "Dig Gesout 48"}

   menu $addout2.dig.menu.gesout.b7
   $addout2.dig.menu.gesout.b7 add command -label "49" \
	-command {list_output2 "Dig Gesout 49"}
   $addout2.dig.menu.gesout.b7 add command -label "50" \
	-command {list_output2 "Dig Gesout 50"}
   $addout2.dig.menu.gesout.b7 add command -label "51" \
	-command {list_output2 "Dig Gesout 51"}
   $addout2.dig.menu.gesout.b7 add command -label "52" \
	-command {list_output2 "Dig Gesout 52"}
   $addout2.dig.menu.gesout.b7 add command -label "53" \
	-command {list_output2 "Dig Gesout 53"}
   $addout2.dig.menu.gesout.b7 add command -label "54" \
	-command {list_output2 "Dig Gesout 54"}
   $addout2.dig.menu.gesout.b7 add command -label "55" \
	-command {list_output2 "Dig Gesout 55"}
   $addout2.dig.menu.gesout.b7 add command -label "56" \
	-command {list_output2 "Dig Gesout 56"}
	
   menu $addout2.dig.menu.gesout.b8
   $addout2.dig.menu.gesout.b8 add command -label "57" \
	-command {list_output2 "Dig Gesout 57"}
   $addout2.dig.menu.gesout.b8 add command -label "58" \
	-command {list_output2 "Dig Gesout 58"}
   $addout2.dig.menu.gesout.b8 add command -label "59" \
	-command {list_output2 "Dig Gesout 59"}
   $addout2.dig.menu.gesout.b8 add command -label "60" \
	-command {list_output2 "Dig Gesout 60"}
   $addout2.dig.menu.gesout.b8 add command -label "61" \
	-command {list_output2 "Dig Gesout 61"}
   $addout2.dig.menu.gesout.b8 add command -label "62" \
	-command {list_output2 "Dig Gesout 62"}
   $addout2.dig.menu.gesout.b8 add command -label "63" \
	-command {list_output2 "Dig Gesout 63"}
   $addout2.dig.menu.gesout.b8 add command -label "64" \
	-command {list_output2 "Dig Gesout 64"}

  	

   #----------------------------------------------------------#
   # Create submenu for "MPL"
   #----------------------------------------------------------#

   menu $addout2.dig.menu.mpl
   $addout2.dig.menu.mpl add cascade -label "1-8" \
   	-menu $addout2.dig.menu.mpl.b1
   $addout2.dig.menu.mpl add cascade -label "9-16" \
   	-menu $addout2.dig.menu.mpl.b2
   $addout2.dig.menu.mpl add cascade -label "17-24" \
   	-menu $addout2.dig.menu.mpl.b3
   $addout2.dig.menu.mpl add cascade -label "25-32" \
   	-menu $addout2.dig.menu.mpl.b4
   $addout2.dig.menu.mpl add cascade -label "33-40" \
   	-menu $addout2.dig.menu.mpl.b5
   $addout2.dig.menu.mpl add cascade -label "41-48" \
   	-menu $addout2.dig.menu.mpl.b6
   	

   menu $addout2.dig.menu.mpl.b1
   $addout2.dig.menu.mpl.b1 add command -label "1" \
	-command {list_output2 "Dig MPL 1"}
   $addout2.dig.menu.mpl.b1 add command -label "2" \
	-command {list_output2 "Dig MPL 2"}
   $addout2.dig.menu.mpl.b1 add command -label "3" \
	-command {list_output2 "Dig MPL 3"}
   $addout2.dig.menu.mpl.b1 add command -label "4" \
	-command {list_output2 "Dig MPL 4"}
   $addout2.dig.menu.mpl.b1 add command -label "5" \
	-command {list_output2 "Dig MPL 5"}
   $addout2.dig.menu.mpl.b1 add command -label "6" \
	-command {list_output2 "Dig MPL 6"}
   $addout2.dig.menu.mpl.b1 add command -label "7" \
	-command {list_output2 "Dig MPL 7"}
   $addout2.dig.menu.mpl.b1 add command -label "8" \
	-command {list_output2 "Dig MPL 8"}


   menu $addout2.dig.menu.mpl.b2	
   $addout2.dig.menu.mpl.b2 add command -label "9" \
	-command {list_output2 "Dig MPL 9"}
   $addout2.dig.menu.mpl.b2 add command -label "10" \
	-command {list_output2 "Dig MPL 10"}
   $addout2.dig.menu.mpl.b2 add command -label "11" \
	-command {list_output2 "Dig MPL 11"}
   $addout2.dig.menu.mpl.b2 add command -label "12" \
	-command {list_output2 "Dig MPL 12"}
   $addout2.dig.menu.mpl.b2 add command -label "13" \
	-command {list_output2 "Dig MPL 13"}
   $addout2.dig.menu.mpl.b2 add command -label "14" \
	-command {list_output2 "Dig MPL 14"}
   $addout2.dig.menu.mpl.b2 add command -label "15" \
	-command {list_output2 "Dig MPL 15"}
   $addout2.dig.menu.mpl.b2 add command -label "16" \
	-command {list_output2 "Dig MPL 16"}

   menu $addout2.dig.menu.mpl.b3	
   $addout2.dig.menu.mpl.b3 add command -label "17" \
	-command {list_output2 "Dig MPL 17"}
   $addout2.dig.menu.mpl.b3 add command -label "18" \
	-command {list_output2 "Dig MPL 18"}
   $addout2.dig.menu.mpl.b3 add command -label "19" \
	-command {list_output2 "Dig MPL 19"}
   $addout2.dig.menu.mpl.b3 add command -label "20" \
	-command {list_output2 "Dig MPL 20"}
   $addout2.dig.menu.mpl.b3 add command -label "21" \
	-command {list_output2 "Dig MPL 21"}
   $addout2.dig.menu.mpl.b3 add command -label "22" \
	-command {list_output2 "Dig MPL 22"}
   $addout2.dig.menu.mpl.b3 add command -label "23" \
	-command {list_output2 "Dig MPL 23"}
   $addout2.dig.menu.mpl.b3 add command -label "24" \
	-command {list_output2 "Dig MPL 24"}

   menu $addout2.dig.menu.mpl.b4	
   $addout2.dig.menu.mpl.b4 add command -label "25" \
	-command {list_output2 "Dig MPL 25"}
   $addout2.dig.menu.mpl.b4 add command -label "26" \
	-command {list_output2 "Dig MPL 26"}
   $addout2.dig.menu.mpl.b4 add command -label "27" \
	-command {list_output2 "Dig MPL 27"}
   $addout2.dig.menu.mpl.b4 add command -label "28" \
	-command {list_output2 "Dig MPL 28"}
   $addout2.dig.menu.mpl.b4 add command -label "29" \
	-command {list_output2 "Dig MPL 29"}
   $addout2.dig.menu.mpl.b4 add command -label "30" \
	-command {list_output2 "Dig MPL 30"}
   $addout2.dig.menu.mpl.b4 add command -label "31" \
	-command {list_output2 "Dig MPL 31"}
   $addout2.dig.menu.mpl.b4 add command -label "32" \
	-command {list_output2 "Dig MPL 32"}
	
	
	
   #----------------------------------------------------------#
   # Create the Analog submenu
   #----------------------------------------------------------#

   menu $addout2.ana.menu
   $addout2.ana.menu add cascade -label GESDAC \
	-menu $addout2.ana.menu.gesdac

   	
   #----------------------------------------------------------#
   # Create the "GESDAC" submenu
   #----------------------------------------------------------#

   menu $addout2.ana.menu.gesdac
   $addout2.ana.menu.gesdac add cascade -label "1-8" \
	-menu $addout2.ana.menu.gesdac.b1
   $addout2.ana.menu.gesdac add cascade -label "9-16" \
	-menu $addout2.ana.menu.gesdac.b2
   $addout2.ana.menu.gesdac add cascade -label "17-24" \
	-menu $addout2.ana.menu.gesdac.b3
   $addout2.ana.menu.gesdac add cascade -label "25-32" \
	-menu $addout2.ana.menu.gesdac.b4

   #----------------------------------------------------------#
   # adding element to the "GESDAC"	
   #----------------------------------------------------------#

   menu $addout2.ana.menu.gesdac.b1
   $addout2.ana.menu.gesdac.b1 add command -label "1" \
	-command {list_output2 "Ana Gesdac 1"}
   $addout2.ana.menu.gesdac.b1 add command -label "2" \
	-command {list_output2 "Ana Gesdac 2"}
   $addout2.ana.menu.gesdac.b1 add command -label "3" \
	-command {list_output2 "Ana Gesdac 3"}
   $addout2.ana.menu.gesdac.b1 add command -label "4" \
	-command {list_output2 "Ana Gesdac 4"}
   $addout2.ana.menu.gesdac.b1 add command -label "5" \
	-command {list_output2 "Ana Gesdac 5"}
   $addout2.ana.menu.gesdac.b1 add command -label "6" \
	-command {list_output2 "Ana Gesdac 6"}
   $addout2.ana.menu.gesdac.b1 add command -label "7" \
	-command {list_output2 "Ana Gesdac 7"}
   $addout2.ana.menu.gesdac.b1 add command -label "8" \
	-command {list_output2 "Ana Gesdac 8"}


   menu $addout2.ana.menu.gesdac.b2
   $addout2.ana.menu.gesdac.b2 add command -label "9" \
	-command {list_output2 "Ana Gesdac 9"}
   $addout2.ana.menu.gesdac.b2 add command -label "10" \
	-command {list_output2 "Ana Gesdac 10"}
   $addout2.ana.menu.gesdac.b2 add command -label "11" \
	-command {list_output2 "Ana Gesdac 11"}
   $addout2.ana.menu.gesdac.b2 add command -label "12" \
	-command {list_output2 "Ana Gesdac 12"}
   $addout2.ana.menu.gesdac.b2 add command -label "13" \
	-command {list_output2 "Ana Gesdac 13"}
   $addout2.ana.menu.gesdac.b2 add command -label "14" \
	-command {list_output2 "Ana Gesdac 14"}
   $addout2.ana.menu.gesdac.b2 add command -label "15" \
	-command {list_output2 "Ana Gesdac 15"}
   $addout2.ana.menu.gesdac.b2 add command -label "16" \
	-command {list_output2 "Ana Gesdac 16"}


   menu $addout2.ana.menu.gesdac.b3
   $addout2.ana.menu.gesdac.b3 add command -label "17" \
	-command {list_output2 "Ana Gesdac 17"}
   $addout2.ana.menu.gesdac.b3 add command -label "18" \
	-command {list_output2 "Ana Gesdac 18"}
   $addout2.ana.menu.gesdac.b3 add command -label "19" \
	-command {list_output2 "Ana Gesdac 19"}
   $addout2.ana.menu.gesdac.b3 add command -label "20" \
	-command {list_output2 "Ana Gesdac 20"}
   $addout2.ana.menu.gesdac.b3 add command -label "21" \
	-command {list_output2 "Ana Gesdac 21"}
   $addout2.ana.menu.gesdac.b3 add command -label "22" \
	-command {list_output2 "Ana Gesdac 22"}
   $addout2.ana.menu.gesdac.b3 add command -label "23" \
	-command {list_output2 "Ana Gesdac 23"}
   $addout2.ana.menu.gesdac.b3 add command -label "24" \
	-command {list_output2 "Ana Gesdac 24"}


   menu $addout2.ana.menu.gesdac.b4
   $addout2.ana.menu.gesdac.b4 add command -label "25" \
	-command {list_output2 "Ana Gesdac 25"}
   $addout2.ana.menu.gesdac.b4 add command -label "26" \
	-command {list_output2 "Ana Gesdac 26"}
   $addout2.ana.menu.gesdac.b4 add command -label "27" \
	-command {list_output2 "Ana Gesdac 27"}
   $addout2.ana.menu.gesdac.b4 add command -label "28" \
	-command {list_output2 "Ana Gesdac 28"}   	
   $addout2.ana.menu.gesdac.b4 add command -label "29" \
	-command {list_output2 "Ana Gesdac 29"}
   $addout2.ana.menu.gesdac.b4 add command -label "30" \
	-command {list_output2 "Ana Gesdac 30"}
   $addout2.ana.menu.gesdac.b4 add command -label "31" \
	-command {list_output2 "Ana Gesdac 31"}
   $addout2.ana.menu.gesdac.b4 add command -label "32" \
	-command {list_output2 "Ana Gesdac 32"}
	
   menu $addout2.dig.menu.mpl.b5	
   $addout2.dig.menu.mpl.b5 add command -label "33" \
	-command {list_output2 "Dig MPL 33"}
   $addout2.dig.menu.mpl.b5 add command -label "34" \
	-command {list_output2 "Dig MPL 34"}
   $addout2.dig.menu.mpl.b5 add command -label "35" \
	-command {list_output2 "Dig MPL 35"}
   $addout2.dig.menu.mpl.b5 add command -label "36" \
	-command {list_output2 "Dig MPL 36"}
   $addout2.dig.menu.mpl.b5 add command -label "37" \
	-command {list_output2 "Dig MPL 37"}
   $addout2.dig.menu.mpl.b5 add command -label "38" \
	-command {list_output2 "Dig MPL 38"}
   $addout2.dig.menu.mpl.b5 add command -label "39" \
	-command {list_output2 "Dig MPL 39"}
   $addout2.dig.menu.mpl.b5 add command -label "40" \
	-command {list_output2 "Dig MPL 40"}
	
   menu $addout2.dig.menu.mpl.b6	
   $addout2.dig.menu.mpl.b6 add command -label "41" \
	-command {list_output2 "Dig MPL 41"}
   $addout2.dig.menu.mpl.b6 add command -label "42" \
	-command {list_output2 "Dig MPL 42"}
   $addout2.dig.menu.mpl.b6 add command -label "43" \
	-command {list_output2 "Dig MPL 43"}
   $addout2.dig.menu.mpl.b6 add command -label "44" \
	-command {list_output2 "Dig MPL 44"}
   $addout2.dig.menu.mpl.b6 add command -label "45" \
	-command {list_output2 "Dig MPL 45"}
   $addout2.dig.menu.mpl.b6 add command -label "46" \
	-command {list_output2 "Dig MPL 46"}
   $addout2.dig.menu.mpl.b6 add command -label "47" \
	-command {list_output2 "Dig MPL 47"}
   $addout2.dig.menu.mpl.b6 add command -label "48" \
	-command {list_output2 "Dig MPL 48"}
	
	


   #----------------------------------------------------------#
   # Add a Close button
   #----------------------------------------------------------#

   button $addout2.close -text Close -command {destroy .add_output2}

   #----------------------------------------------------------#
   # Pack things up
   #----------------------------------------------------------#

   pack $addout2.title -side top  -fill x -padx 3 -pady 3
   pack $addout2.dig $addout2.ana -side top	
   pack $addout2.close -side bottom -pady 3m






   # end else
   }




# end  of procedure add_output2   	
}



proc list_output2 { out } {

      global num_of_items

      #----------------------------------------------------------#
      # It does not matter what the name is since the adding button proc
      # will also check for the connection that exists in db already
      #----------------------------------------------------------#

      set name "some_name"

      set out_val [ split $out " " ]
      set temp_elem_num [lindex $out_val 2]



      if {[lindex $out_val 1] == "Gesout" } {
      	set board 0
      }

      if {[lindex $out_val 1] == "MPL" } {
      	set board 1
      	
      }

      if {[lindex $out_val 1] == "Gesdac" } {
      	set board 2
      	
      }  else {

      	set board 3
     }

      #puts "board is : $board"	
	


      if { [check_out_db $name $board $temp_elem_num] > 0} {
      	puts "output2.tcl: The output connection exists in other database "
      	
      	set status [tk_dialog  .warning  {  }  {The Output Connection has already been used / mapped before. Please remove the old connection first. } \
             		warning 0 {Close} ]
       		
       		switch $status {
 			0 {return}
		}	            	
      	
      }


      for {set i 0} {$i <= $num_of_items} {incr i} {
         set curline [.bpm2.output_text get $i]

         if {[string compare $curline $out ] == 0 } {
            puts "the button $curline has already been selected before"
            return
         }

      # end for loop
      }

      #----------------------------------------------------------#
      # Insert output selected to the BPM listbox
      #----------------------------------------------------------#

      global surveh diganal elem_num elem_name calc default_type enable_channel enable_auto enable_graphic dig_value ana_value ana_raw offset gainvalue maxautocalibrate minautocalibrate graph_type color xpos ypos vga			

      .bpm2.output_text insert end $out
      incr num_of_items

      #puts "output2.tcl: what is the element here : $surveh $diganal $elem_num"

      #----------------------------------------------------------#
      # Send Input to IO database -> this will update the element in database
      #----------------------------------------------------------#

      send_io_elem_info $surveh $diganal $elem_num $elem_name $calc $default_type $enable_channel $enable_auto $enable_graphic $dig_value $ana_value $ana_raw $offset $gainvalue $maxautocalibrate $minautocalibrate $graph_type $color $xpos $ypos $vga			

      #----------------------------------------------------------#
      # Send the Output list to IO database
      #----------------------------------------------------------#

      send_out_list_info $surveh $diganal $elem_num [get_output2]
		

   # end proc list_output2
   }




#----------------------------------------------------------#
# This procedure delete the selected item in the output listbox
# if the delete button is pressed without selecting anything, then by
# default the last item in the list will be deleted
#----------------------------------------------------------#

proc delete_output2  { selected } {

   global surveh , elem_num
   set count [.bpm2.output_text index end]

   if {$count == 0} {

      puts "output2.tcl: there's no more items to delete here"
      return

   } else {

      if {$selected == ""} { set selected end }
      set curline [.bpm2.output_text get $selected]

      .bpm2.output_text delete $selected


      #----------------------------------------------------------#
      # UPDATING THE INPUT CONNECTION FOR ANALOG OUTPUT ELEMENT
      #
      # First, we have to get the input information our Analog Out is connected to
      #----------------------------------------------------------#

      set type [lindex $selected 1]

      #----------------------------------------------------------#
      # If type is an Analog Out type
      #----------------------------------------------------------#

      if { $type != "Gesout" && $type != "MPL" && $type != "Gesdac" } {
              	set io_conn [get_io_connection $curline]
              	set elnum [lindex $io_conn 1]

              	#----------------------------------------------------------#        	
              	# Delete the element from Analog Out input list
              	#----------------------------------------------------------#
              	
              	delete_single_input $elnum
              	
      }


   }


}





proc get_output2 { } {

   	global surveh
   	set output ""
   	set count_output [.bpm2.output_text index end]
   	
   		
           for {set i 0} {$i < $count_output} {incr i} {
        	
        	#----------------------------------------------------------#
        	# get the string "Dig Gesout 1" or something and then parse and append
        	#----------------------------------------------------------#
        	
        	set out [.bpm2.output_text get $i]
        	set out1 [lindex $out 1]
        	
        	if {[lindex $out 1] == "Gesout"} {
        	 	append output "0|"
        	 	append output "[lindex $out 2]|"
        	}	
        	if {[lindex $out 1] == "MPL"} {
        	 	append output "1|"
        	 	append output "[lindex $out 2]|"
        	}
        	if {[lindex $out 1] == "Gesdac"} {
        	 	append output "2|"
        	 	append output "[lindex $out 2]|"
        	} else {
        		
        		#----------------------------------------------------------#
        	 	# Get the analog output connection using the name
        	 	#----------------------------------------------------------#
        	
        	  	set io_conn [get_io_connection $out]
        	
        	   	#puts "output2.tcl : io_conn : $io_conn"
        	    	append output "3|"
        	     	append output "[lindex $io_conn 1]|"
        	 	
        	}        	

    # end for loop
    }

    return $output

}



#------------------------------------------------------------------------------------#
# This procedure will create the Analog Out selections 
# Here, we also do some error checking to see if the analog out has already
# exist or not and whether it has already assigned an input or not
#------------------------------------------------------------------------------------#
 
proc create_anaout_item2 { index } {

	global surface surface2 surveh elem_num
	
		set name [get_element_name 1 3 $index]

		#------------------------------------------------------------------------------------#	
		# if the Analog Output element does not exist
		#------------------------------------------------------------------------------------#
		if { $name == ""} {
	             	
	            #------------------------------------------------------------------------------------#
			# Create the analog output element first
			#------------------------------------------------------------------------------------#
			
	           	send_io_elem_info 1 3 $index "Ana Out $index" 0 0:0:0:0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1			
			#------------------------------------------------------------------------------------#
			# Update the name in the Analog Out selection menu
			#------------------------------------------------------------------------------------#
			
	  		$surface.anaout  entryconfigure $index -label "$index Ana Out $index"
	
	  		if [winfo exists $surface2] {
		  		$surface2.anaout  entryconfigure $index -label "$index Ana Out $index"
	               }
		  	
			set name "Ana Out $index"
	
		}
		
		set elnum [lindex [split [display_output 1 3 $index] |] 1]
		
		#------------------------------------------------------------------------------------#
		# This means that the analog output we selected has already have 1 INPUT associated 
		# Therefore, do not add it to the output list -> RETURN
		#------------------------------------------------------------------------------------#
		
		if {$elnum != ""} {
		
			set status [tk_dialog  .warning  {}  {The Output Connection has already been used / mapped before.Please remove the old connection first. } warning 0 {Close} ]
       		
       			switch $status { 0 {return} }	    
			return
		}
		
		#------------------------------------------------------------------------------------#
		# This means that the sub analog has already have 1 OUTPUT 
		# Therefore, do not add it to the output list -> RETURN
		#------------------------------------------------------------------------------------#
		
		if {[.bpm2.output_text index end] != 0 } {
				return
       		}

		list_output2 $name	
		
		#------------------------------------------------------------------------------------#
		# Add this input element from Analog Output in the Input list			
		#------------------------------------------------------------------------------------#
	        send_out_list_info  1 3 $index "$surveh|$elem_num|"
		
		
# end proc
}
