/*
  nlsur

*!  VERSION 1.0.6  23aug2010

  keyword:  eclass

*/

VERSION 12.0

INCLUDE _std_xlarge
DEFINE _dlght 420
INCLUDE header

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

SCRIPT PREINIT
BEGIN
	script initialize_eq_list
	create BOOLEAN main_isUserType
	script se_createAsNLSUR
	program svy_check_title
END

SCRIPT POSTINIT
BEGIN
	script sub_set_by_on
	program se_setFinalInitState
END

///////////////////////////////////////////////////////////////////////////

SCRIPT initialize_eq_list
BEGIN
	create STRING tmp
	create BOOLEAN hasEquation
	create DOUBLE eq_counter

	create STRING eq_result1
	create STRING eq_result2
	create STRING eq_result3
	create STRING eq_result4
	create STRING eq_result5
	create STRING eq_result6
	create STRING eq_result7
	create STRING eq_result8
	create STRING eq_result9
	create STRING eq_result10
	create STRING eq_result11
	create STRING eq_result12
	create STRING eq_result13
	create STRING eq_result14
	create STRING eq_result15
	create STRING eq_result16

	create STRING eq_status1
	create STRING eq_status2
	create STRING eq_status3
	create STRING eq_status4
	create STRING eq_status5
	create STRING eq_status6
	create STRING eq_status7
	create STRING eq_status8
	create STRING eq_status9
	create STRING eq_status10
	create STRING eq_status11
	create STRING eq_status12
	create STRING eq_status13
	create STRING eq_status14
	create STRING eq_status15
	create STRING eq_status16

	create LIST eq_list_labels
	create LIST eq_list_values

	main.bu_expEdit.disable
	main.bu_expEnable.disable
	main.bu_expDisable.disable

	program process_eq_list
END

PROGRAM create_new_equation
BEGIN
	if eq_counter.iseq(0) {
		call script create_eq1
	}
	if eq_counter.iseq(1) {
		call script create_eq2
	}
	if eq_counter.iseq(2) {
		call script create_eq3
	}
	if eq_counter.iseq(3) {
		call script create_eq4
	}
	if eq_counter.iseq(4) {
		call script create_eq5
	}
	if eq_counter.iseq(5) {
		call script create_eq6
	}
	if eq_counter.iseq(6) {
		call script create_eq7
	}
	if eq_counter.iseq(7) {
		call script create_eq8
	}
	if eq_counter.iseq(8) {
		call script create_eq9
	}
	if eq_counter.iseq(9) {
		call script create_eq10
	}
	if eq_counter.iseq(10) {
		call script create_eq11
	}
	if eq_counter.iseq(11) {
		call script create_eq12
	}
	if eq_counter.iseq(12) {
		call script create_eq13
	}
	if eq_counter.iseq(13) {
		call script create_eq14
	}
	if eq_counter.iseq(14) {
		call script create_eq15
	}
	if eq_counter.iseq(15) {
		call script create_eq16
	}
	if eq_counter.iseq(16) {
		stopbox stop "Equation limit exceeded."	///
			"Only 16 equations may be defined with this dialog."
	}
END

SCRIPT create_eq1
BEGIN
	create CHILD nlsur_new_eq AS new_eq1
	new_eq1.setExitString "eq_result1"
	new_eq1.setOkAction "program done_eq1"
	new_eq1.settitle "Equation 1"
END
PROGRAM done_eq1
BEGIN
	if eq_counter.iseq(0) {
		call eq_status1.setstring "active"
		call eq_counter.setvalue 1
	}
	call program process_eq_list
END

SCRIPT create_eq2
BEGIN
	create CHILD nlsur_new_eq AS new_eq2
	new_eq2.setExitString "eq_result2"
	new_eq2.setOkAction "program done_eq2"
	new_eq2.settitle "Equation 2"
END
PROGRAM done_eq2
BEGIN
	if eq_counter.iseq(1) {
		call eq_status2.setstring "active"
		call eq_counter.setvalue 2
	}
	call program process_eq_list
END

SCRIPT create_eq3
BEGIN
	create CHILD nlsur_new_eq AS new_eq3
	new_eq3.setExitString "eq_result3"
	new_eq3.setOkAction "program done_eq3"
	new_eq3.settitle "Equation 3"
END
PROGRAM done_eq3
BEGIN
	if eq_counter.iseq(2) {
		call eq_status3.setstring "active"
		call eq_counter.setvalue 3
	}
	call program process_eq_list
END

SCRIPT create_eq4
BEGIN
	create CHILD nlsur_new_eq AS new_eq4
	new_eq4.setExitString "eq_result4"
	new_eq4.setOkAction "program done_eq4"
	new_eq4.settitle "Equation 4"
END
PROGRAM done_eq4
BEGIN
	if eq_counter.iseq(3) {
		call eq_status4.setstring "active"
		call eq_counter.setvalue 4
	}
	call program process_eq_list
END

SCRIPT create_eq5
BEGIN
	create CHILD nlsur_new_eq AS new_eq5
	new_eq5.setExitString "eq_result5"
	new_eq5.setOkAction "program done_eq5"
	new_eq5.settitle "Equation 5"
END
PROGRAM done_eq5
BEGIN
	if eq_counter.iseq(4) {
		call eq_status5.setstring "active"
		call eq_counter.setvalue 5
	}
	call program process_eq_list
END

SCRIPT create_eq6
BEGIN
	create CHILD nlsur_new_eq AS new_eq6
	new_eq6.setExitString "eq_result6"
	new_eq6.setOkAction "program done_eq6"
	new_eq6.settitle "Equation 6"
END
PROGRAM done_eq6
BEGIN
	if eq_counter.iseq(5) {
		call eq_status6.setstring "active"
		call eq_counter.setvalue 6
	}
	call program process_eq_list
END

SCRIPT create_eq7
BEGIN
	create CHILD nlsur_new_eq AS new_eq7
	new_eq7.setExitString "eq_result7"
	new_eq7.setOkAction "program done_eq7"
	new_eq7.settitle "Equation 7"
END
PROGRAM done_eq7
BEGIN
	if eq_counter.iseq(6) {
		call eq_status7.setstring "active"
		call eq_counter.setvalue 7
	}
	call program process_eq_list
END

SCRIPT create_eq8
BEGIN
	create CHILD nlsur_new_eq AS new_eq8
	new_eq8.setExitString "eq_result8"
	new_eq8.setOkAction "program done_eq8"
	new_eq8.settitle "Equation 8"
END
PROGRAM done_eq8
BEGIN
	if eq_counter.iseq(7) {
		call eq_status8.setstring "active"
		call eq_counter.setvalue 8
	}
	call program process_eq_list
END

SCRIPT create_eq9
BEGIN
	create CHILD nlsur_new_eq AS new_eq9
	new_eq9.setExitString "eq_result9"
	new_eq9.setOkAction "program done_eq9"
	new_eq9.settitle "Equation 9"
END
PROGRAM done_eq9
BEGIN
	if eq_counter.iseq(8) {
		call eq_status9.setstring "active"
		call eq_counter.setvalue 9
	}
	call program process_eq_list
END

SCRIPT create_eq10
BEGIN
	create CHILD nlsur_new_eq AS new_eq10
	new_eq10.setExitString "eq_result10"
	new_eq10.setOkAction "program done_eq10"
	new_eq10.settitle "Equation 10"
END
PROGRAM done_eq10
BEGIN
	if eq_counter.iseq(9) {
		call eq_status10.setstring "active"
		call eq_counter.setvalue 10
	}
	call program process_eq_list
END

SCRIPT create_eq11
BEGIN
	create CHILD nlsur_new_eq AS new_eq11
	new_eq11.setExitString "eq_result11"
	new_eq11.setOkAction "program done_eq11"
	new_eq11.settitle "Equation 11"
END
PROGRAM done_eq11
BEGIN
	if eq_counter.iseq(10) {
		call eq_status11.setstring "active"
		call eq_counter.setvalue 11
	}
	call program process_eq_list
END

SCRIPT create_eq12
BEGIN
	create CHILD nlsur_new_eq AS new_eq12
	new_eq12.setExitString "eq_result12"
	new_eq12.setOkAction "program done_eq12"
	new_eq12.settitle "Equation 12"
END
PROGRAM done_eq12
BEGIN
	if eq_counter.iseq(11) {
		call eq_status12.setstring "active"
		call eq_counter.setvalue 12
	}
	call program process_eq_list
END

SCRIPT create_eq13
BEGIN
	create CHILD nlsur_new_eq AS new_eq13
	new_eq13.setExitString "eq_result13"
	new_eq13.setOkAction "program done_eq13"
	new_eq13.settitle "Equation 13"
END
PROGRAM done_eq13
BEGIN
	if eq_counter.iseq(12) {
		call eq_status13.setstring "active"
		call eq_counter.setvalue 13
	}
	call program process_eq_list
END

SCRIPT create_eq14
BEGIN
	create CHILD nlsur_new_eq AS new_eq14
	new_eq14.setExitString "eq_result14"
	new_eq14.setOkAction "program done_eq14"
	new_eq14.settitle "Equation 14"
END
PROGRAM done_eq14
BEGIN
	if eq_counter.iseq(13) {
		call eq_status14.setstring "active"
		call eq_counter.setvalue 14
	}
	call program process_eq_list
END

SCRIPT create_eq15
BEGIN
	create CHILD nlsur_new_eq AS new_eq15
	new_eq15.setExitString "eq_result15"
	new_eq15.setOkAction "program done_eq15"
	new_eq15.settitle "Equation 15"
END
PROGRAM done_eq15
BEGIN
	if eq_counter.iseq(14) {
		call eq_status15.setstring "active"
		call eq_counter.setvalue 15
	}
	call program process_eq_list
END

SCRIPT create_eq16
BEGIN
	create CHILD nlsur_new_eq AS new_eq16
	new_eq16.setExitString "eq_result16"
	new_eq16.setOkAction "program done_eq16"
	new_eq16.settitle "Equation 16"
END
PROGRAM done_eq16
BEGIN
	if eq_counter.iseq(15) {
		call eq_status16.setstring "active"
		call eq_counter.setvalue 16
	}
	call program process_eq_list
END

SCRIPT clear_eq_list
BEGIN
	eq_list_labels.Arrdropall
	eq_list_values.Arrdropall
END

PROGRAM process_eq_list
BEGIN	
	call script clear_eq_list
	if eq_counter.isge(1) {
		call eq_list_values.Arrpush "1"
		if eq_status1.iseq("active") {
			call eq_result1.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status1.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result1.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(2) {
		call eq_list_values.Arrpush "2"
		if eq_status2.iseq("active") {
			call eq_result2.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status2.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result2.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(3) {
		call eq_list_values.Arrpush "3"
		if eq_status3.iseq("active") {
			call eq_result3.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status3.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result3.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(4) {
		call eq_list_values.Arrpush "4"
		if eq_status4.iseq("active") {
			call eq_result4.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status4.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result4.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(5) {
		call eq_list_values.Arrpush "5"
		if eq_status5.iseq("active") {
			call eq_result5.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status5.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result5.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(6) {
		call eq_list_values.Arrpush "6"
		if eq_status6.iseq("active") {
			call eq_result6.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status6.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result6.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(7) {
		call eq_list_values.Arrpush "7"
		if eq_status7.iseq("active") {
			call eq_result7.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status7.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result7.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(8) {
		call eq_list_values.Arrpush "8"
		if eq_status8.iseq("active") {
			call eq_result8.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status8.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result8.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(9) {
		call eq_list_values.Arrpush "9"
		if eq_status9.iseq("active") {
			call eq_result9.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status9.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result9.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(10) {
		call eq_list_values.Arrpush "10"
		if eq_status10.iseq("active") {
			call eq_result10.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status10.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result10.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(11) {
		call eq_list_values.Arrpush "11"
		if eq_status11.iseq("active") {
			call eq_result11.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status11.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result11.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(12) {
		call eq_list_values.Arrpush "12"
		if eq_status12.iseq("active") {
			call eq_result12.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status12.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result12.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(13) {
		call eq_list_values.Arrpush "13"
		if eq_status13.iseq("active") {
			call eq_result13.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status13.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result13.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(14) {
		call eq_list_values.Arrpush "14"
		if eq_status14.iseq("active") {
			call eq_result14.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status14.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result14.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(15) {
		call eq_list_values.Arrpush "15"
		if eq_status15.iseq("active") {
			call eq_result15.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status15.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result15.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}
	if eq_counter.isge(16) {
		call eq_list_values.Arrpush "16"
		if eq_status16.iseq("active") {
			call eq_result16.withvalue eq_list_labels.Arrpush "@"
		}
		if eq_status16.iseq("disabled") {
			call tmp.setvalue "<disabled> "
			call eq_result16.withvalue tmp.append "@"
			call tmp.withvalue eq_list_labels.Arrpush "@"
		}
		call main.bu_expEdit.enable
	}

	call main.lb_expBuild.repopulate
END

LIST eq_list_selection
BEGIN
	program eq1_sel
	program eq2_sel
	program eq3_sel
	program eq4_sel
	program eq5_sel
	program eq6_sel
	program eq7_sel
	program eq8_sel	
	program eq9_sel
	program eq10_sel
	program eq11_sel
	program eq12_sel
	program eq13_sel
	program eq14_sel
	program eq15_sel
	program eq16_sel	
END

PROGRAM eq1_sel
BEGIN
	if eq_status1.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status1.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq2_sel
BEGIN
	if eq_status2.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status2.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq3_sel
BEGIN
	if eq_status3.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status3.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq4_sel
BEGIN
	if eq_status4.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status4.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq5_sel
BEGIN
	if eq_status5.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status5.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq6_sel
BEGIN
	if eq_status6.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status6.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq7_sel
BEGIN
	if eq_status7.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status7.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq8_sel
BEGIN
	if eq_status8.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status8.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq9_sel
BEGIN
	if eq_status9.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status9.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq10_sel
BEGIN
	if eq_status10.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status10.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq11_sel
BEGIN
	if eq_status11.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status11.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq12_sel
BEGIN
	if eq_status12.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status12.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq13_sel
BEGIN
	if eq_status13.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status13.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq14_sel
BEGIN
	if eq_status14.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status14.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq15_sel
BEGIN
	if eq_status15.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status15.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END
PROGRAM eq16_sel
BEGIN
	if eq_status16.iseq("active") {
		call main.bu_expEnable.disable
		call main.bu_expDisable.enable
	}
	if eq_status16.iseq("disabled") {
		call main.bu_expEnable.enable
		call main.bu_expDisable.disable
	}
END

PROGRAM eq_disable_selection
BEGIN
	if main.lb_expBuild.iseq("1") {
		call eq_status1.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("2") {
		call eq_status2.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("3") {
		call eq_status3.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("4") {
		call eq_status4.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("5") {
		call eq_status5.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("6") {
		call eq_status6.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("7") {
		call eq_status7.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("8") {
		call eq_status8.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("9") {
		call eq_status9.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("10") {
		call eq_status10.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("11") {
		call eq_status11.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("12") {
		call eq_status12.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("13") {
		call eq_status13.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("14") {
		call eq_status14.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("15") {
		call eq_status15.setvalue "disabled"
	}
	if main.lb_expBuild.iseq("16") {
		call eq_status16.setvalue "disabled"
	}
	call program process_eq_list
END

PROGRAM eq_enable_selection
BEGIN
	if main.lb_expBuild.iseq("1") {
		call eq_status1.setvalue "active"
	}
	if main.lb_expBuild.iseq("2") {
		call eq_status2.setvalue "active"
	}
	if main.lb_expBuild.iseq("3") {
		call eq_status3.setvalue "active"
	}
	if main.lb_expBuild.iseq("4") {
		call eq_status4.setvalue "active"
	}
	if main.lb_expBuild.iseq("5") {
		call eq_status5.setvalue "active"
	}
	if main.lb_expBuild.iseq("6") {
		call eq_status6.setvalue "active"
	}
	if main.lb_expBuild.iseq("7") {
		call eq_status7.setvalue "active"
	}
	if main.lb_expBuild.iseq("8") {
		call eq_status8.setvalue "active"
	}
	if main.lb_expBuild.iseq("9") {
		call eq_status9.setvalue "active"
	}
	if main.lb_expBuild.iseq("10") {
		call eq_status10.setvalue "active"
	}
	if main.lb_expBuild.iseq("11") {
		call eq_status11.setvalue "active"
	}
	if main.lb_expBuild.iseq("12") {
		call eq_status12.setvalue "active"
	}
	if main.lb_expBuild.iseq("13") {
		call eq_status13.setvalue "active"
	}
	if main.lb_expBuild.iseq("14") {
		call eq_status14.setvalue "active"
	}
	if main.lb_expBuild.iseq("15") {
		call eq_status15.setvalue "active"
	}
	if main.lb_expBuild.iseq("16") {
		call eq_status16.setvalue "active"
	}
	call program process_eq_list
END

PROGRAM eq_edit_selection
BEGIN
	if main.lb_expBuild.iseq("1") {
		call script create_eq1
	}
	if main.lb_expBuild.iseq("2") {
		call script create_eq2
	}
	if main.lb_expBuild.iseq("3") {
		call script create_eq3
	}
	if main.lb_expBuild.iseq("4") {
		call script create_eq4
	}
	if main.lb_expBuild.iseq("5") {
		call script create_eq5
	}
	if main.lb_expBuild.iseq("6") {
		call script create_eq6
	}
	if main.lb_expBuild.iseq("7") {
		call script create_eq7
	}
	if main.lb_expBuild.iseq("8") {
		call script create_eq8
	}
	if main.lb_expBuild.iseq("9") {
		call script create_eq9
	}
	if main.lb_expBuild.iseq("10") {
		call script create_eq10
	}
	if main.lb_expBuild.iseq("11") {
		call script create_eq11
	}
	if main.lb_expBuild.iseq("12") {
		call script create_eq12
	}
	if main.lb_expBuild.iseq("13") {
		call script create_eq13
	}
	if main.lb_expBuild.iseq("14") {
		call script create_eq14
	}
	if main.lb_expBuild.iseq("15") {
		call script create_eq15
	}
	if main.lb_expBuild.iseq("16") {
		call script create_eq16
	}
END

///////////////////////////////////////////////////////////////////////////

DIALOG main, tabtitle("Model")						///
	title("nlsur - Estimation of nonlinear systems of equations")
BEGIN

  RADIO    rb_subexp	_lft	_top	_iwd	., first		///
	onclickon(program subexp)					///
	label("Enter system of equations")
  RADIO    rb_preprog	@	_ss	@	.,			///
	onclickon(program preprog)					///
	label("Use a preprogrammed substitutable expression")
  RADIO    rb_evaluator	@	_ss	@	., last			///
	onclickon(program eval)						///
	label("Use a function evaluator program")

  TEXT     tx_dv	_lft	+35	_cwd1	.,			///
  	label("Dependent variables:")
  TEXT     tx_expBuild	@	@	@	.,			///
	label("System of equations:")
  DEFINE holdy @y
  VARLIST  vn_dv	@	_ss	@	.,			///
  	label("Dependent variables")
  LISTBOX  lb_expBuild	@	@	_rj100	95,			///
	contents(eq_list_labels) values(eq_list_values)			///
	onselchangelist(eq_list_selection)				///
	ondblclick(program eq_edit_selection)

  BUTTON   bu_expBuild	_rj80	@	80	.,			///
	label("Create...")						///
	tooltip("Create equation")					///
	onpush(program create_new_equation)
  BUTTON   bu_expEdit	@	_ms	@	.,			///
	label("Edit")							///
	tooltip("Edit equation")					///
	onpush(program eq_edit_selection)
  BUTTON   bu_expDisable @	_ms	@	.,			///
	label("Disable")						///
	tooltip("Disable equation")					///
	onpush(program eq_disable_selection)
  BUTTON   bu_expEnable	@	_ms	@	.,			///
	label("Enable")							///
	tooltip("Enable equation")					///
	onpush(program eq_enable_selection)

  TEXT     tx_iv	_lft2	holdy	_cwd1	.,			///
  	label("Independent variables:")
  VARLIST  vl_iv	@	_ss	@	.,			///
  	label("Independent variables") allowcat

  TEXT     tx_funcprog	_lft	135	_cwd1	.,			///
	label("Function evaluator program:")
  EDIT     ed_funcprog	@	_ss	@	.,			///
	label("Function evaluator program")
  TEXT     tx_fpopts    _lft2	135	_cwd1	.,			///
	label("Program options:")
  EDIT     ed_fpopts    @	_ss	@	.,			///
	  label("Program options")

  SPINNER  sp_nequation	_lft	+35	_spwd	.,			///
	min(2) default(2) max(100) option(nequations)
  TEXT     tx_nequation _spsep	@	250	.,			///
	label("Number of equations in model")

  TEXT     tx_param	_lft	_ls	_cwd1	.,			///
	label("Parameters:")
  DEFINE holdy @y
  EDIT     ed_param	@	_ss	@	.,			///
	option(parameters) label("Parameters")
  EDIT     ed_paramnum	_lft2	@	_spwd	.,			///
	option(nparameters) numonly
  TEXT     tx_paramnum	_spsep	@	200	.,			///
	label("Number of parameters")


  TEXT     tx_variables	_lft	+145	_cwd1	.,			///
  	label("Variables: (optional)")
  DEFINE holdy @y
  VARLIST  vl_variables	@	_ss	@	.,			///
  	option(variables) label("Variables")

  TEXT     tx_initial	_lft2	holdy	_cwd1	.,			///
	label("Initial values: (optional)")
  EDIT     ed_initial	@	_ss	@	.,			///
	option(initial) label("Initial values")

  TEXT     tx_user	_lft	135	_cwd1	.,			///
	label("Substitutable expression program:")
  EDIT     ed_user	@	_ss	@	.,			///
	label("Substitutable expression program")
  TEXT     tx_useropts	_lft2	135	_cwd1	.,			///
	label("Program options:")
  EDIT     ed_useropts	@	_ss	@ 	.,			///
	label("Program options")

  GROUPBOX gb_estimator	_lft	240	_iwd	_ht6,			///
	label("Estimator")
  RADIO    rb_fgnls	_ilft	_ss	_ibwd	.,			///
	first								///
	label("FGNLS estimator")					///
	option(fgnls)							///
	onclickon(program check_estimator)
  RADIO    rb_ifgnls	@	_ss	@	.,			///
	label("Iterative feasible GNLS estimator")			///
	option(ifgnls)							///
	onclickon(program check_estimator)
  RADIO    rb_nls	@	_ss	@	.,			///
	last								///
	label("NLS estimator")						///
	option(nls)							///
	onclickon(program check_estimator)
END

PROGRAM check_estimator
BEGIN
	if main.rb_ifgnls {
		call max.sp_ifgnlsiter.enable
		call max.tx_ifgnlsiter.enable
		call max.en_ifgnlseps.enable
		call max.tx_ifgnlseps.enable
	}
	else {
		call max.sp_ifgnlsiter.disable
		call max.tx_ifgnlsiter.disable
		call max.en_ifgnlseps.disable
		call max.tx_ifgnlseps.disable
	}
END

INCLUDE byifin
INCLUDE weights_fpai
INCLUDE se

SCRIPT rpt_POSTINIT
BEGIN
	create STRING rpt_bu_fmtcoefResults
	program rpt_bu_fmtcoef_ckResults
END

DIALOG rpt, tabtitle("Reporting")
BEGIN
  DEFINE   _x  _lft
  DEFINE   _cx _spr
  DEFINE   _y  _top
  INCLUDE  _sp_level

  TEXT     tx_title	_lft	+35	60	.,			///
	label("Title:")
  DEFINE holdy @y
  EDIT     ed_title	@	_ss	_cwd1	.,			///
	option(title) label("title")
  TEXT     tx_title2	@	_ls	60	.,			///
	label("Subtitle:")
  DEFINE holdy @y
  EDIT     ed_title2	@	_ss	_cwd1	.,			///
	  option(title2) label("subtitle")

  DEFINE _x _lft
  DEFINE _y _ls
  INCLUDE _bu_coef_table_reporting
END

INCLUDE fmt_coef_table_reporting_pr

PROGRAM subexp
BEGIN
	call script subexp_on
	call script eval_off
END

PROGRAM preprog
BEGIN
	call script preprog_on
	call script eval_off
END

PROGRAM eval
BEGIN
	call script eval_on
END

SCRIPT subexp_on
BEGIN
	main.tx_variables.setposition . 220
	main.vl_variables.setposition . 240
	main.tx_initial.setposition . 220
	main.ed_initial.setposition . 240
	main.gb_estimator.setposition . 275
	main.rb_fgnls.setposition . 295
	main.rb_nls.setposition . 315
	main.rb_ifgnls.setposition . 335
	main.tx_dv.hide
	main.vn_dv.hide
	main.tx_expBuild.show
	main.lb_expBuild.show
	main.bu_expBuild.show
	main.bu_expEdit.show
	main.bu_expDisable.show
	main.bu_expEnable.show
	main.tx_iv.hide
	main.vl_iv.hide
	main.tx_user.hide
	main.ed_user.hide
	main.tx_useropts.hide
	main.ed_useropts.hide
END

SCRIPT preprog_on
BEGIN
	main.tx_variables.setposition . 185
	main.vl_variables.setposition . 205
	main.tx_initial.setposition . 185
	main.ed_initial.setposition . 205
	main.gb_estimator.setposition . 240
	main.rb_fgnls.setposition . 260
	main.rb_nls.setposition . 280
	main.rb_ifgnls.setposition . 300
	main.tx_dv.show
	main.vn_dv.show
	main.tx_expBuild.hide
	main.lb_expBuild.hide
	main.bu_expBuild.hide
	main.bu_expEdit.hide
	main.bu_expDisable.hide
	main.bu_expEnable.hide
	main.tx_iv.show
	main.vl_iv.show
	main.tx_user.show
	main.ed_user.show
	main.tx_useropts.show
	main.ed_useropts.show
END

SCRIPT eval_on
BEGIN
	main.tx_variables.setposition . 270
	main.vl_variables.setposition . 290
	main.tx_initial.setposition . 270
	main.ed_initial.setposition . 290
	main.gb_estimator.setposition . 325
	main.rb_fgnls.setposition . 345
	main.rb_nls.setposition . 365
	main.rb_ifgnls.setposition . 385
	main.tx_dv.show
	main.vn_dv.show
	main.tx_expBuild.hide
	main.lb_expBuild.hide
	main.bu_expBuild.hide
	main.bu_expEdit.hide
	main.bu_expDisable.hide
	main.bu_expEnable.hide
	main.tx_funcprog.show
	main.ed_funcprog.show
	main.sp_nequation.show
	main.tx_nequation.show
	main.tx_fpopts.show
	main.ed_fpopts.show
	main.tx_param.show
	main.ed_param.show
	main.tx_paramnum.show
	main.ed_paramnum.show
	main.tx_iv.show
	main.vl_iv.show
	main.tx_user.hide
	main.ed_user.hide
	main.tx_useropts.hide
	main.ed_useropts.hide
END

SCRIPT eval_off
BEGIN
	main.tx_funcprog.hide
	main.ed_funcprog.hide
	main.sp_nequation.hide
	main.tx_nequation.hide
	main.tx_fpopts.hide
	main.ed_fpopts.hide
	main.tx_param.hide
	main.ed_param.hide
	main.tx_paramnum.hide
	main.ed_paramnum.hide
END

DIALOG max, tabtitle("Optimization")
BEGIN

  SPINNER  sp_iterate		_lft	_top	_spwd	.,		///
	option(iterate)							///
	min(1) max(1000000) default(10000)				///
	label("Maximum iterations")
  TEXT     tx_iterate		_spsep	@	_ckspr	.,		///
	label("Maximum iterations")

  EDIT     en_eps		_lft	_ls	_en7wd	., 		///
	option(eps) default(1e-5)					///
	label("Convergence criterion")
  TEXT     tx_eps		_en7sep	@	_rbvnr	.,		///
	label("Convergence criterion (default: 1e-5)")

  SPINNER  sp_ifgnlsiter		_lft	_ls	_spwd	.,	///
	label("Max number of FGNLS iterations") option(ifgnlsiterate)	///
	min(0) max(16000) default(c(maxiter))
  TEXT     tx_ifgnlsiter		_en7sep	@	_rbvnr	.,	///
	label("Max number of FGNLS iterations")


  EDIT     en_ifgnlseps		_lft	_ls	_en7wd	., 		///
	option(ifgnlseps) default(1e-10)				///
	label("FGNLS convergence criterion")
  TEXT     tx_ifgnlseps		_en7sep	@	_rbvnr	.,		///
	label("FGNLS convergence criterion (default: 1e-10)")

  EDIT     en_delta		_lft	_ls	_en7wd	.,  		///
	option(delta) default(4e-7)					///
	label("Delta for computing derivatives")
  TEXT     tx_delta		_en7sep	@	_rbvnr	.,		///
	label("Delta for computing derivatives (default: 4e-7)")

  CHECKBOX ck_nocons		_lft	_ls	_iwd	.,		///
	option(noconstants)						///
	onclickon(program has_constants_check)				///
	onclickoff(program has_constants_check)				///
	label("None of the equations in the system include constant terms")

  TEXT     tx_hascons		_lft	_ms	_vlwd	.,		///
	label("Constant terms:")
  EDIT     ed_hascons		@	_ss	@	., 		///
	option(hasconstants) 						///
	label("Constant terms")

  GROUPBOX gb_log		_lft	+35	@	_ht6,		///
	label("Iteration log")
  RADIO    rb_log		_indent	_ss	_inwd	., first	///
	option(log) label("Show log")
  RADIO    rb_trace		@	_ss	@	., 		///
	option(trace) label("Detailed log")
  RADIO    rb_nolog		@	_ss	@	.,		///
	option(nolog) label("Suppress log") last
END

PROGRAM has_constants_check
BEGIN
	if max.ck_nocons {
		call max.tx_hascons.disable
		call max.ed_hascons.disable
	}
	else {
		call max.tx_hascons.enable
		call max.ed_hascons.enable
	}
END

PROGRAM nl_equation_output
BEGIN
	call hasEquation.setfalse

	if eq_status1.iseq("active") & eq_result1 {
		put "(" eq_result1 ") "
		call hasEquation.settrue
	}
	if eq_status2.iseq("active") & eq_result2 {
		put "(" eq_result2 ") "
		call hasEquation.settrue
	}
	if eq_status3.iseq("active") & eq_result3 {
		put "(" eq_result3 ") "
		call hasEquation.settrue
	}
	if eq_status4.iseq("active") & eq_result4 {
		put "(" eq_result4 ") "
		call hasEquation.settrue
	}
	if eq_status5.iseq("active") & eq_result5 {
		put "(" eq_result5 ") "
		call hasEquation.settrue
	}
	if eq_status6.iseq("active") & eq_result6 {
		put "(" eq_result6 ") "
		call hasEquation.settrue
	}
	if eq_status7.iseq("active") & eq_result7 {
		put "(" eq_result7 ") "
		call hasEquation.settrue
	}
	if eq_status8.iseq("active") & eq_result8 {
		put "(" eq_result8 ") "
		call hasEquation.settrue
	}
	if eq_status9.iseq("active") & eq_result9 {
		put "(" eq_result9 ") "
		call hasEquation.settrue
	}
	if eq_status10.iseq("active") & eq_result10 {
		put "(" eq_result10 ") "
		call hasEquation.settrue
	}
	if eq_status11.iseq("active") & eq_result11 {
		put "(" eq_result11 ") "
		call hasEquation.settrue
	}
	if eq_status12.iseq("active") & eq_result12 {
		put "(" eq_result12 ") "
		call hasEquation.settrue
	}
	if eq_status13.iseq("active") & eq_result13 {
		put "(" eq_result13 ") "
		call hasEquation.settrue
	}
	if eq_status14.iseq("active") & eq_result14 {
		put "(" eq_result14 ") "
		call hasEquation.settrue
	}
	if eq_status15.iseq("active") & eq_result15 {
		put "(" eq_result15 ") "
		call hasEquation.settrue
	}
	if eq_status16.iseq("active") & eq_result16 {
		put "(" eq_result16 ") "
		call hasEquation.settrue
	}
	if eq_counter.iseq(0) {
		stopbox stop "Equations not defined. " ///
			"Please create an equation before proceeding."
	}
	if ! hasEquation {
		stopbox stop "All equations are disabled. " ///
			"Either define a new equation or enable an existing equation before proceeding."
	}
END

PROGRAM command
BEGIN
	allowxi
	put /program by_output " "
	put /program se_prefix_output " "
	put "nlsur "
	if main.rb_subexp {
		put /program nl_equation_output " "
	}
	if main.rb_preprog {
		require main.vn_dv
		require main.ed_user
		put main.ed_user
		put " " ": "
		varlist main.vn_dv [main.vl_iv]
	}

	if main.rb_evaluator {
		require main.vn_dv
		require main.ed_funcprog
		put main.ed_funcprog
		put " " "@ "
		varlist main.vn_dv [main.vl_iv]
	}

	put " " /program ifin_output
	put " " /program weights_output
	beginoptions
		optionarg main.vl_variables
		optionarg main.ed_initial
		if main.rb_evaluator {
			optionarg main.sp_nequation
			optionarg main.ed_param
			optionarg main.ed_paramnum
			if !main.ed_param & !main.ed_paramnum {
				stopbox stop `"On the "Model" tab,"' 	///
					`"either "Parameters" or "Number of parameters" must be filled in."'
			}
		}
		if main.ed_useropts {
			put " " main.ed_useropts
		}

		put main.ed_fpopts
		option main.rb_nls
		option main.rb_ifgnls

		put " " /program se_output

		optionarg /hidedefault rpt.sp_level
		optionarg rpt.ed_title
		optionarg rpt.ed_title2
		put " " rpt_bu_fmtcoefResults

		optionarg /hidedefault max.sp_iterate
		optionarg /hidedefault max.en_eps
		optionarg /hidedefault max.sp_ifgnlsiter
		optionarg /hidedefault max.en_ifgnlseps
		optionarg /hidedefault max.en_delta
		option max.ck_nocons
		optionarg max.ed_hascons

		option max.rb_trace
		option max.rb_nolog
	endoptions
END
