/*
    gr_lfitci_options.dlg
    
*!  VERSION 1.0.0  29oct2006 

*/

VERSION 10

INCLUDE _std_large
INCLUDE header_gr_child

DEFINE _clwd 15

HELP hlp1, view("help twoway_lfitci")
RESET res1

SCRIPT main_PREINIT
BEGIN
	create STRING lineResults
	create STRING markerResults
	create STRING rareaResults
	create STRING rbarResults
	create STRING rspikeResults
	create STRING rlineResults
END

SCRIPT main_POSTINIT
BEGIN
	program checkLineResults
	program checkMarkerResults
	program checkRangeAreaResults
	program checkRangeBarResults
	program checkRangeSpikeResults
	program checkRangeLineResults
END

DIALOG main, label("Linear prediction options") tabtitle("Main")
BEGIN
  GROUPBOX gb_basis		_lft	_top	_iwd	_ht6,	///
	label("Basis for confidence intervals")
  RADIO    rb_stdp		_ilft	_ss	_inwd	.,	///
	first							///
	label("Confidence interval of the mean")
  RADIO	   rb_stdf		@	_ss	@	.,	///
	option(stdf)						///
	label("Confidence interval for an individual forecast")
  RADIO    rb_stdr		@	_ss	@	.,	///
	last							///
	option(stdr)						///
	label("Confidence interval based only on the standard error of the residual")

  DEFINE _x _lft
  DEFINE _y +45
  DEFINE _cx 200
  INCLUDE _sp_level
  
  GROUPBOX gb_plot		_lft	+35	_iwd	_ht11,	///
	label("Plots")

  TEXT     tx_plot		_ilft	_ss	120	.,	///
	label("Plot type of fit:")
DEFINE y @y
  COMBOBOX cb_plot		@	_ss	@	.,	///
	dropdownlist						///
	contents(fit_plot_list)					///
	values(fit_plot_list_values)				///
	onselchangelist(fit_plot_actions)			///
	option(fitplot) default(line)
  BUTTON   bu_line_opts		@	+35	@	.,	///
	label("Line properties  ")				///
	onpush(script line_options_show)			///
	tooltip("Line properties for linear prediction plot")
  BUTTON   bu_marker_opts	@	_ls	@	.,	///
	label("Marker options  ")				///
	onpush(script marker_options_show)			///
	tooltip("Marker properties for linear prediction plot")

  TEXT     tx_ciplot		+160	y	140	.,	///
	label("Plot type of CI:")
  COMBOBOX cb_ciplot		@	_ss	@	.,	///
	dropdownlist						///
	contents(fit_ciplot_list)				///
	values(fit_ciplot_list_values)				///
	onselchangelist(fit_ciplot_actions)			///
	option(ciplot) default(rarea)
	
  BUTTON   bu_rarea_opts	@	+35	@	.,	///
	label("Area properties  ")				///
	onpush(script rarea_options_show)			///
	tooltip("Area properties for confidence interval plot")
  BUTTON   bu_rbar_opts		@	@	@	.,	///
	label("Bar properties  ")				///
	onpush(script rbar_options_show)			///
	tooltip("Bar properties for confidence interval plot")
  BUTTON   bu_rspike_opts	@	@	@	.,	///
	label("Spike properties  ")				///
	onpush(script rspike_options_show)			///
	tooltip("Spike properties for confidence interval plot")
  BUTTON   bu_rline_opts	@	@	@	.,	///
	label("Line properties  ")				///
	onpush(script rline_options_show)			///
	tooltip("Line properties for confidence interval plot")
  
  TEXT     tx_cap_size		+175	-20	120	.,	///
	label("Cap size:") 
  COMBOBOX cb_cap_size		@	+20	100	.,	///
	dropdown 						///
	contents(symbolsizes) option(msize)
END

LIST fit_plot_list
BEGIN
	Line
	Connected
	Scatter
END
LIST fit_plot_list_values
BEGIN
	line
	connected
	scatter
END
LIST fit_plot_actions
BEGIN
	script line_on
	script connected_on
	script scatter_on
END

SCRIPT line_on
BEGIN
	main.bu_line_opts.enable
	main.bu_marker_opts.disable
END
SCRIPT connected_on
BEGIN
	main.bu_line_opts.enable
	main.bu_marker_opts.enable
END
SCRIPT scatter_on
BEGIN
	main.bu_line_opts.disable
	main.bu_marker_opts.enable
END

LIST fit_ciplot_list
BEGIN
	Range area
	Range bar
	Range spike
	Range spike w/cap
	Range line
END
LIST fit_ciplot_list_values
BEGIN
	rarea
	rbar
	rspike
	rcap
	rline
END
LIST fit_ciplot_actions
BEGIN
	script rarea_on
	script rbar_on
	script rspike_on
	script rcap_on
	script rline_on
END

SCRIPT rarea_on
BEGIN
	main.bu_rarea_opts.show
	main.bu_rbar_opts.hide
	main.bu_rspike_opts.hide
	main.bu_rline_opts.hide
	main.cb_cap_size.hide
	main.tx_cap_size.hide
END
SCRIPT rbar_on
BEGIN
	main.bu_rarea_opts.hide
	main.bu_rbar_opts.show
	main.bu_rspike_opts.hide
	main.bu_rline_opts.hide
	main.cb_cap_size.hide
	main.tx_cap_size.hide
END
SCRIPT rspike_on
BEGIN
	main.bu_rarea_opts.hide
	main.bu_rbar_opts.hide
	main.bu_rspike_opts.show
	main.bu_rline_opts.hide
	main.cb_cap_size.hide
	main.tx_cap_size.hide
END
SCRIPT rcap_on
BEGIN
	main.bu_rarea_opts.hide
	main.bu_rbar_opts.hide
	main.bu_rspike_opts.show
	main.bu_rline_opts.hide
	main.cb_cap_size.show
	main.tx_cap_size.show
END
SCRIPT rline_on
BEGIN
	main.bu_rarea_opts.hide
	main.bu_rbar_opts.hide
	main.bu_rspike_opts.hide
	main.bu_rline_opts.show
	main.cb_cap_size.hide
	main.tx_cap_size.hide
END

SCRIPT line_options_show
BEGIN
	create CHILD gr_line_options AS lineOptions, allowsubmit
	lineOptions.setExitString lineResults
	lineOptions.settitle "Line properties for linear prediction"
	lineOptions.setExitAction "program checkLineResults"
	lineOptions.setSubmitAction "script lineSubmit"
	lineOptions.callthru "script gr_line_setOptionsTo_cl"
END
PROGRAM checkLineResults
BEGIN
	if lineResults.iseq("") {
		call main.bu_line_opts.setlabel "Line properties  "
	}
	if lineResults.isneq("") {
		call main.bu_line_opts.setlabel "Line properties *"
	}
END
SCRIPT lineSubmit
BEGIN
	program checkLineResults
	Submit
END

SCRIPT marker_options_show
BEGIN
	create CHILD gr_marker_options AS markerOptions, allowsubmit
	markerOptions.setExitString markerResults
	markerOptions.settitle "Marker properties for linear prediction"
	markerOptions.setExitAction "program checkMarkerResults"
	markerOptions.setSubmitAction "script markerSubmit"
END
PROGRAM checkMarkerResults
BEGIN
	if markerResults.iseq("") {
		call main.bu_marker_opts.setlabel "Marker properties  "
	}
	if markerResults.isneq("") {
		call main.bu_marker_opts.setlabel "Marker properties *"
	}
END
SCRIPT markerSubmit
BEGIN
	program checkMarkerResults
	Submit
END

SCRIPT rarea_options_show
BEGIN
	create CHILD gr_rarea_options AS rareaOptions, allowsubmit
	rareaOptions.setExitString rareaResults
	rareaOptions.settitle "Area properties for linear prediction CI's"
	rareaOptions.setExitAction "program checkRangeAreaResults"
	rareaOptions.setSubmitAction "script rareaSubmit"
	rareaOptions.callthru "script gr_rarea_setOptionsTo_bl"
	rareaOptions.callthru "script gr_rarea_setOrientationOff"
END
PROGRAM checkRangeAreaResults
BEGIN
	if rareaResults.iseq("") {
		call main.bu_rarea_opts.setlabel "Area properties  "
	}
	if rareaResults.isneq("") {
		call main.bu_rarea_opts.setlabel "Area properties *"
	}
END
SCRIPT rareaSubmit
BEGIN
	program checkRangeAreaResults
	Submit
END

SCRIPT rbar_options_show
BEGIN
	create CHILD gr_rbar_options AS rbarOptions, allowsubmit
	rbarOptions.setExitString rbarResults
	rbarOptions.settitle "Bar properties for linear prediction CI's"
	rbarOptions.setExitAction "program checkRangeBarResults"
	rbarOptions.setSubmitAction "script rbarSubmit"
	rbarOptions.callthru "script gr_rbar_setOptionsTo_bl"
	rbarOptions.callthru "script gr_rbar_setOrientationOff"
	rbarOptions.callthru "script gr_rbar_setBarWidthOff"
END
PROGRAM checkRangeBarResults
BEGIN
	if rbarResults.iseq("") {
		call main.bu_rbar_opts.setlabel "Bar properties  "
	}
	if rbarResults.isneq("") {
		call main.bu_rbar_opts.setlabel "Bar properties *"
	}
END
SCRIPT rbarSubmit
BEGIN
	program checkRangeBarResults
	Submit
END

SCRIPT rspike_options_show
BEGIN
	create CHILD gr_rspike_options AS rspikeOptions, allowsubmit
	rspikeOptions.setExitString rspikeResults
	rspikeOptions.settitle "Spike properties for linear prediction CI's"
	rspikeOptions.setExitAction "program checkRangeSpikeResults"
	rspikeOptions.setSubmitAction "script rspikeSubmit"
	rspikeOptions.callthru "script gr_rspike_setOptionsTo_bl"
	rspikeOptions.callthru "script gr_rspike_setOrientationOff"
END
PROGRAM checkRangeSpikeResults
BEGIN
	if rspikeResults.iseq("") {
		call main.bu_rspike_opts.setlabel "Spike properties  "
	}
	if rspikeResults.isneq("") {
		call main.bu_rspike_opts.setlabel "Spike properties *"
	}
END
SCRIPT rspikeSubmit
BEGIN
	program checkRangeSpikeResults
	Submit
END

SCRIPT rline_options_show
BEGIN
	create CHILD gr_line_options AS rlineOptions, allowsubmit
	rlineOptions.setExitString rlineResults
	rlineOptions.settitle "Line properties for linear prediction CI's"
	rlineOptions.setExitAction "program checkRangeLineResults"
	rlineOptions.setSubmitAction "script rlineSubmit"
	rlineOptions.callthru "script gr_line_setOptionsTo_bl"
END
PROGRAM checkRangeLineResults
BEGIN
	if rlineResults.iseq("") {
		call main.bu_rline_opts.setlabel "Line properties  "
	}
	if rlineResults.isneq("") {
		call main.bu_rline_opts.setlabel "Line properties *"
	}
END
SCRIPT rlineSubmit
BEGIN
	program checkRangeLineResults
	Submit
END
//--

//**
DIALOG xrange, tabtitle("X Range")
BEGIN
  CHECKBOX ck_range		_lft	_top	_iwd	_ht4,	///
	groupbox						///
	onclickon(script range_on) onclickoff(script range_off)	///
	label("Override range of X for which predictions are to be calculated")
  TEXT     tx_min		_ilft	_ss	120	.,	///
	label("Minimum value:")
  DEFINE y @y
  EDIT     ed_min		@	_ss	85	.,	///
	numonly label("Minimum value")
  TEXT     tx_max		140	y	120	.,	///
	label("Maximum value:")
  EDIT     ed_max		@	_ss	85	.,	///
	numonly label("Maximum value")

  CHECKBOX ck_points		_lft	+45	_iwd	_ht5,	///
	groupbox						///
	onclickon(program points_on)				///
	onclickoff(script points_off)				///
	label("Override the number of prediction points (default 100)")
  RADIO    rb_n			_ilft	_ms	15	.,	///
	first							///
	onclickon(program check_rb_n)
  SPINNER  sp_n			+20	@	_spwd	.,	///
	min(1) max(100000) default(100) option(n)
  TEXT     tx_n			_spsep	@	200	.,	///
	label("Prediction points")
  RADIO    rb_atobs		_ilft	_ms	_cwd1	.,	///
	last label("Predict at X values") option(atobs)		///
	onclickon(xrange.sp_n.disable)
END

PROGRAM check_rb_n
BEGIN
	if xrange.rb_n.isenabled() {
		call xrange.sp_n.enable
	}
END

SCRIPT range_on
BEGIN
	xrange.ed_min.enable
	xrange.tx_min.enable
	xrange.ed_max.enable
	xrange.tx_max.enable
END
SCRIPT range_off
BEGIN
	xrange.ed_min.disable
	xrange.tx_min.disable
	xrange.ed_max.disable
	xrange.tx_max.disable
END

PROGRAM points_on
BEGIN
	call xrange.rb_n.enable
	if xrange.rb_n {
		call xrange.sp_n.enable
	}
	call xrange.tx_n.enable
	call xrange.rb_atobs.enable
END
SCRIPT points_off
BEGIN
	xrange.rb_n.disable
	xrange.sp_n.disable
	xrange.tx_n.disable
	xrange.rb_atobs.disable
END
//--

//**
DIALOG adv, tabtitle("Advanced")
BEGIN
  TEXT     tx_regress		_lft	_top	_vlwd	.,	///
	label("Regress options:")
  EDIT	   ed_regress		@	_ss	@	.,	///
	option(estopts)
  BUTTON   bu_regress		_vlsep	@	_clwd	.,	///
	label("?") tooltip("Help - regress") 			///
	onpush(view help regress##|_new)
	
  TEXT     tx_predict		_lft	_ls	_vlwd	.,	///
	label("Predict options:")
  EDIT	   ed_predict		@	_ss	@	.,	///
	option(predopts)	
  BUTTON   bu_predict		_vlsep	@	_clwd	.,	///
	label("?") tooltip("Help - predict after regress")	///
	onpush(view help regress postestimation##predict|_new)
END
//--

PROGRAM range_output
BEGIN
	put range.ed_min
	put " " range.ed_max
END

PROGRAM command
BEGIN
	option main.rb_stdf
	option main.rb_stdr
	optionarg /hidedefault main.sp_level
	
	optionarg /hidedefault main.cb_plot
	if ! D(main.bu_line_opts) {
		put " " lineResults " "
	}
	if ! D(main.bu_marker_opts) {
		put " " markerResults " "
	}
	
	optionarg /hidedefault main.cb_ciplot
	if ! H(main.bu_rarea_opts) {
		put " " rareaResults " "
	}
	if ! H(main.bu_rbar_opts) {
		put " " rbarResults " "
	}
	if ! H(main.bu_rspike_opts) {
		put " " rspikeResults " "
	}
	if ! H(main.bu_rline_opts) {
		put " " rlineResults " "
	}
	optionarg /hidedefault main.cb_cap_size
	
	if xrange.ck_range {
		require xrange.ed_min
		require xrange.ed_max
		put " range("
		put /program range_output
		put ") "
	}
	optionarg xrange.sp_n
	option xrange.rb_atobs
	
	optionarg adv.ed_regress
	optionarg adv.ed_predict
END

