proc Sdialog {} {
  
  #name the dialog box
  toplevel .sd -class Sdialog
  wm title .sd "Switch Edit Box"
  
  #create the toplevel window and then divide it into two
  frame .sd.top
  frame .sd.bot -relief raised -bd 1
  pack .sd.top .sd.bot -fill both
  
  #split the top half of the box into 2 columns
    frame .sd.top.c1 
    frame .sd.top.c2
    pack .sd.top.c1 -side left
    pack .sd.top.c2 -side left -expand 1 -anchor nw -fill both
    
    #column 1 is a listbox that contains the available choices
    #this listbox can be scrollable
    listbox .sd.top.c1.lbox -relief sunken -width 15 -height 5 -setgrid yes -selectmode single
    pack .sd.top.c1.lbox -side left
    
    
    #column 2 contains the current value to be edited, and value of the selected element
    
      #this column contains 2 rows. one for the old value and other for the new value
      
      #row1 for the old value
      frame .sd.top.c2.old
      pack .sd.top.c2.old -fill x -pady 1m
      
      label .sd.top.c2.old.value -text "Old Value:"
      label .sd.top.c2.old.valuename -textvariable OldValue -width 15 -relief groove -bd 2
      pack .sd.top.c2.old.value -side left
      pack .sd.top.c2.old.valuename -side left -fill x -expand 1
      
      #row2 for the new value
      frame .sd.top.c2.new
      pack .sd.top.c2.new -fill x -pady 1m
      
      label .sd.top.c2.new.value -text "New Value:"
      label .sd.top.c2.new.newvalue -textvariable NewValue -width 15 -relief groove -bd 2
      pack .sd.top.c2.new.value -side left
      pack .sd.top.c2.new.newvalue -side left -fill x -expand 1
      
    #contents of the bottom half of the dialod box
    #contains 2 buttons, one for cancel and the other is ok
    button .sd.bot.cancel -text "Cancel" -command {sok}
    button .sd.bot.ok -text "Ok" -command {switch}
    pack .sd.bot.cancel .sd.bot.ok -side left -fill x -padx 2 -pady 2 -expand 1

#call the function to fill in the listbox
fillSbox

  bind .sd.top.c1.lbox <ButtonRelease> {
   set y %y
   set val [.sd.top.c1.lbox nearest $y]
   set NewValue [.sd.top.c1.lbox get $val]
  }
}

#function that changes the switch value and stores in temporary memory
proc switch {} {
  global ArrayName point NewValue
  set Arr $ArrayName
  set len [llength $Arr]
  set arglist [lrange $Arr 1 $len]
  set Arr "$arglist $point $NewValue"
  eval pdbSetSwitch $Arr
  sok
  regsub -all " " $ArrayName {\&} Arr2
  __pdbFillList $Arr2
}


#fill in the listbox with the available options and the current value
proc fillSbox {} {
  global ArrayName point ValueName
  regsub -all " " $ArrayName {\&} Arr
  global $Arr
  
  set tmp [lindex [array get $Arr $point] 1]
  set tmp2 [lindex $tmp 2]
  
  set len [llength $tmp2]
  set count 0
  while {$len !=$count} {
    set tmp3 [lindex $tmp2 $count]
    .sd.top.c1.lbox insert end $tmp3
    incr count
  }
  


}


#function to remove the dialog box and clear the contents of the NewValue
proc sok {} {
  global NewValue
  set NewValue ""
  destroy .sd
}

