PRO cactus_date_event, ev

COMMON date_block,  ibm, ibd, iby, iem, ied, iey, cancel_flag  ;year, mon, day,

WIDGET_CONTROL, ev.id, GET_UVALUE=dlval
WIDGET_CONTROL, ev.top, GET_UVALUE=uv

CASE dlval OF
	"CANCEL": BEGIN
	PRINT,'Canceling ...'
	cancel_flag = 1
	WIDGET_CONTROL, ev.TOP, /DESTROY
			END
	"FIND": BEGIN
	PRINT,'Finding Data ...'	
	WIDGET_CONTROL, ev.TOP, /DESTROY
			END
	"BY": BEGIN
		iby = ev.index
			END
	"BM": BEGIN
		ibm = ev.index
			END
	"BD": BEGIN
		ibd = ev.index
			END
	"EY": BEGIN
		iey = ev.index
			END
	"EM": BEGIN
		iem  = ev.index
			END
	"ED": BEGIN
		ied = ev.index
			END
	"SB": BEGIN
	print,'Same Begin Date'
          WIDGET_CONTROL,uv.b_year, SET_DROPLIST_SELECT=iey
	  WIDGET_CONTROL,uv.b_month,SET_DROPLIST_SELECT=iem
	  WIDGET_CONTROL,uv.b_day,  SET_DROPLIST_SELECT=ied
           ibd = ied
           ibm = iem
           iby = iey
			END
	"SE": BEGIN
	print,'Same End Date'
          WIDGET_CONTROL,uv.e_year, SET_DROPLIST_SELECT=iby
	  WIDGET_CONTROL,uv.e_month,SET_DROPLIST_SELECT=ibm
	  WIDGET_CONTROL,uv.e_day,  SET_DROPLIST_SELECT=ibd
          ied = ibd
          iem = ibm
          iey = iby
			END

ENDCASE
END

PRO cactus_date,outdatestruc

COMMON date_block, ibm, ibd, iby, iem, ied, iey, cancel_flag  ;year, mon, day,

cancel_flag = 0

year=[" 1995", " 1996", " 1997", " 1998", " 1999", " 2000", " 2001", " 2002", $
	    " 2003", " 2004", " 2005", " 2006", " 2007", " 2008", " 2009", " 2010"]

mon=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]

mond=[" 01", " 02", " 03", " 04", " 05", " 06", " 07", " 08", " 09", " 10", " 11", " 12"]

day=[" 01", " 02", " 03", " 04", " 05", " 06", " 07", " 08", " 09", " 10", " 11", " 12", " 13", " 14", " 15", $
     	  " 16", " 17", " 18", " 19", " 20", " 21", " 22", " 23", " 24", " 25", " 26", " 27", " 28", " 29", " 30", " 31"]

iby=' 1996'
ibm='Jan'
ibd=' 01'

iey=' 2010'
iem='Dec'
ied=' 31'

iby = WHERE(iby EQ year)
ibm = WHERE(ibm EQ mon)
ibd = WHERE(ibd EQ day)

iey = WHERE(iey EQ year)
iem = WHERE(iem EQ mon)
ied = WHERE(ied EQ day)

cac_dte = WIDGET_BASE (title='CACTUS date chooser', /col, /frame)
to_from  = WIDGET_BASE(cac_dte, /FRAME,/COLUMN)

to_row  = WIDGET_BASE(to_from, /ROW)
fr_butt  = WIDGET_LABEL(to_row,VALUE="From   : ")
w_m_b = WIDGET_DROPLIST(to_row, VALUE=mon, UVALUE="BM")
w_d_b = WIDGET_DROPLIST(to_row, VALUE=day,   UVALUE="BD")
w_y_b = WIDGET_DROPLIST(to_row, VALUE=year,  UVALUE="BY")
w_s_e = WIDGET_BUTTON(to_row, VALUE='Same  end  date', UVALUE="SE")

fr_row  = WIDGET_BASE(to_from, /ROW)
to_butt  = WIDGET_LABEL(fr_row,VALUE="To     : ")
w_m_e = WIDGET_DROPLIST(fr_row, VALUE=mon, UVALUE="EM")
w_d_e = WIDGET_DROPLIST(fr_row, VALUE=day,   UVALUE="ED") 
w_y_e = WIDGET_DROPLIST(fr_row, VALUE=year,  UVALUE="EY")
w_s_b = WIDGET_BUTTON(fr_row, VALUE='Same begin date', UVALUE="SB")

ctrl = WIDGET_BASE(cac_dte,/ROW)
ctrl_can  = WIDGET_BUTTON(ctrl,VALUE=' Cancel ',UVALUE='CANCEL', /ALIGN_LEFT)
ctrl_go    = WIDGET_BUTTON(ctrl,VALUE='   Go ',UVALUE='FIND', /ALIGN_RIGHT, /FRAME)

cac_uv = {b_day:w_d_b,		$  
          	   b_month:w_m_b,	$  
           	   b_year:w_y_b,		$  
           	   e_day:w_d_e,		$
           	   e_month:w_m_e,	$
           	   e_year:w_y_e} 

	WIDGET_CONTROL, cac_dte, /REALIZE
	WIDGET_CONTROL, cac_dte, SET_UVALUE=cac_uv

	WIDGET_CONTROL,w_d_b,SET_DROPLIST_SELECT=ibd
	WIDGET_CONTROL,w_d_e,SET_DROPLIST_SELECT=ied
	WIDGET_CONTROL,w_m_b,SET_DROPLIST_SELECT=ibm
	WIDGET_CONTROL,w_m_e,SET_DROPLIST_SELECT=iem
	WIDGET_CONTROL,w_y_b,SET_DROPLIST_SELECT=iby
	WIDGET_CONTROL,w_y_e,SET_DROPLIST_SELECT=iey

	XMANAGER,'cactus_date', cac_dte

IF cancel_flag EQ 0 THEN BEGIN
bstr = strtrim(day(ibd),2)+'-'+strtrim(mon(ibm),2)+'-'+strtrim(year(iby),2)
estr = strtrim(day(ied),2)+'-'+strtrim(mon(iem),2)+'-'+strtrim(year(iey),2)
blas = strmid(year(iby),3,2)+strtrim(mond(ibm),2)+strtrim(day(ibd),2)
elas = strmid(year(iey),3,2)+strtrim(mond(iem),2)+strtrim(day(ied),2)
PRINT, 'Start Date is '+bstr+' and End Date is '+estr+', ( '+blas+' - '+elas+' )'

outdatestruc = {beg_date:blas,end_date:elas}
END

END