{
 ***************************************************************************
 *
 *						INVESTMENT INTELLIGENCE SYSTEMS CORP.
 *
 *									PROPRIETARY DATA
 *
 *		THIS DOCUMENT CONTAINS TRADE SECRET DATA WHICH IS THE PROPERTY OF
 *		INVESTMENT INTELLIGENCE. THIS DOCUMENT IS SUBMITTED TO RECIPIENT IN
 *		CONFIDENCE. INFORMATION CONTAINED HEREIN MAY NOT BE USED, COPIED OR
 *		DISCLOSED IN WHOLE OR IN PART EXCEPT AS PERMITTED BY WRITTEN AGREEMENT
 *		SIGNED BY AN OFFICER OF INVESTMENT INTELLIGENCE SYSTEMS CORP.
 *
 *		THIS MATERIAL IS ALSO COPYRIGHTED AS AN UNPUBLISHED WORK UNDER
 *		SECTIONS 104 AND 408 OF TITLE 17 OF THE UNITED STATES CODE.
 *		UNAUTHORIZED USE, COPYING OR OTHER REPRODUCTION IS PROHIBITED BY LAW.
 *
 *		Title:		rtdg.txt
 *		Sccsid:		@(#)rtdg.txt	3.3.1.10	98/03/11
 *		Author:		Unknown
 *		Created:		Tue Jan 5 11:20:08 CST 1993
 *
 ***************************************************************************
}

DEFINE colpikit, current_unit, currentprinter, do_find, doit, hpval, ok,
		printfile, platform, print_range, report_units, temp,
		text_load_interactive, str1, str2, str3, str4, val1, val2, val3, val4


{===========================================================================

This is a list of the functions available in this script that you may want
to modify for your application. The easiest way to go to these functions
is to select them here and press Control/Command-H or the equivalent of
Find Selection in your editor.

	BASIC SETUP
		RTSetup

	PAGE PREVIEW FUNCTIONS
		LayoutOptions
		UpdateLayoutOptions
		ActiveDocByType
		ConvertValue
		PerformLayoutOptions
		HeaderFooter
		ReportBody
		ScriptLayoutOptions
		DGPreviewGoto
		DGGrayPrintDest
		DGGrayPrintRange
		DGCheckPrinterName - SIGNIFICANT FOR UNIX ONLY
		DGPrint
		fixPageSetupLists
		PageSetupDialog

	UTILITY FUNCTIONS
		DoubleQuoteIt
		DGAsk

	PLATFORM-INDEPENDANT DIALOG CONTROL PLACEMENT
		DialogControlArea

	DOUBLECLICK TRAPS
		Gallery
		ChartTitle
		FootNote
		Legend
		Plot
		ChartDataSources
		LabelsAndLayout
		Series
		Axis
		ColorsAndLines
		ControlOptionsDispatcher
		FieldOptions
		FunctionGlossary

	BASIC CLEANUP
		ExitScript
		CloseFile

========================================================================}



{========================================================================
	BASIC SETUP

	Use the functions in this section to setup your application.
========================================================================}

{
	RTSetup()

	Gets pictures necessary for the worksheet entry bar, the help
		window, and portfolios.

	Takes no arguments:

	Returns nothing
}

FUNCTION RTSetup()
	DEFINE env_variable
	DEFINE plat_ext
	DEFINE twips_per_pixel
	DEFINE icon_size
	DEFINE icon_color

	env_variable = GETENV("WINGZ3")

	IF GETENV(0) = 8 OR GETENV(0) = 3
		twips_per_pixel = GETENV(3)

		CASE
			WHEN twips_per_pixel > (1440/80)	{ 80 dpi }
				icon_size = "s"
			WHEN twips_per_pixel > (1440/100)	{ 100 dpi }
				icon_size = "m"
			OTHERWISE
				icon_size = "l"
		END CASE

		{ only handle color displays now }
		icon_color = "color"

		plat_ext = ".gif"
		IF GETENV(21) = 1			{ 0 => non-realtime, 1 => realtime }
			GET RESOURCE env_variable & GETENV(16) & GETENV(22) & "RT" &
							GETENV(16) & icon_size & icon_color & ".brf"
		ELSE
			GET RESOURCE env_variable & GETENV(16) & GETENV(22) &
							GETENV(16) & icon_size & icon_color & ".brf"
		END IF

	ELSEIF GETENV(0) = 1 {Macintosh}
		{ only handle color displays now }
		icon_color = "color"

		plat_ext = ""
		GET RESOURCE env_variable & ":" & GETENV(22) & LEFT(icon_color,1) & "i"

	ELSE
		plat_ext = ""
	END IF

	GET PICTURE "olex" & plat_ext AS "expand"
	GET PICTURE "olexd" & plat_ext AS	"expandd"
	GET PICTURE "olct" & plat_ext AS "contract"
	GET PICTURE "olctd" & plat_ext AS	"contractd"
	GET PICTURE "olexm" & plat_ext AS	"expandm"
	GET PICTURE "olexdm" & plat_ext AS "expanddm"
	GET PICTURE "olctm" & plat_ext AS	"contractm"
	GET PICTURE "olctdm" & plat_ext AS "contractdm"

	{ entry bar pictures }
	GET PICTURE "ebab" & plat_ext AS "abslicon" { range reference type toggle }
	GET PICTURE "ebabm" & plat_ext AS	"absliconm"
	GET PICTURE "ebae" & plat_ext AS "acpticon" { accept entry bar }
	GET PICTURE "ebaem" & plat_ext AS	"acpticonm"
	GET PICTURE "ebce" & plat_ext AS "rjcticon" { reject entry bar }
	GET PICTURE "ebcem" & plat_ext AS	"rjcticonm"
	GET PICTURE "ebdi" & plat_ext AS "slshicon" { insert divide }
	GET PICTURE "ebdim" & plat_ext AS	"slshiconm"
	GET PICTURE "ebeq" & plat_ext AS "eqlsicon" { insert equal sign }
	GET PICTURE "ebeqm" & plat_ext AS	"eqlsiconm"
	GET PICTURE "ebfu" & plat_ext AS "funcactn" { invoke function glossary }
	GET PICTURE "ebfum" & plat_ext AS	"funcactnm"
	GET PICTURE "ebmi" & plat_ext AS "mnusicon" { insert minus sign }
	GET PICTURE "ebmim" & plat_ext AS	"mnusiconm"
	GET PICTURE "ebmu" & plat_ext AS "staricon" { insert as sterisk }
	GET PICTURE "ebmum" & plat_ext AS	"stariconm"
	GET PICTURE "ebpl" & plat_ext AS "plusicon" { insert plus }
	GET PICTURE "ebplm" & plat_ext AS	"plusiconm"
	GET PICTURE "ebsum" & plat_ext AS	"sumactn" { guess as as sum range }
	GET PICTURE "ebsumm" & plat_ext AS "sumactnm"
	GET PICTURE "pclk" & plat_ext AS "linkicon"
	GET PICTURE "pclkm" & plat_ext AS "linkiconm"

	{ help window pictures }
	GET PICTURE "hpct" & plat_ext AS "hpct" { table of contents }
	GET PICTURE "hpctm" & plat_ext AS	"hpctm"
	GET PICTURE "hpfn" & plat_ext AS "hpfn" { find topic }
	GET PICTURE "hpfnm" & plat_ext AS	"hpfnm"
	GET PICTURE "hpix" & plat_ext AS "hpix" { topic index }
	GET PICTURE "hpixm" & plat_ext AS	"hpixm"
	GET PICTURE "hpnx" & plat_ext AS "hpnx" { next topic }
	GET PICTURE "hpnxm" & plat_ext AS	"hpnxm"
	GET PICTURE "hppv" & plat_ext AS "hppv" { previous topic }
	GET PICTURE "hppvm" & plat_ext AS	"hppvm"
	GET PICTURE "hprt" & plat_ext AS "hprt" { related topics }
	GET PICTURE "hprtm" & plat_ext AS	"hprtm"

	{ portfolio navigation button pictures }
	GET PICTURE "fthm" & plat_ext AS "fthm" { go home }
	GET PICTURE "fthmm" & plat_ext AS	"fthmm"
	GET PICTURE "ftnx" & plat_ext AS "ftnx"	{ next sketch }
	GET PICTURE "ftnxm" & plat_ext AS	"ftnxm"
	GET PICTURE "ftpv" & plat_ext AS "ftpv"	{ previous sketch }
	GET PICTURE "ftpvm" & plat_ext AS	"ftpvm"
END FUNCTION { RTSetup }



{========================================================================
	PAGE PREVIEW FUNCTIONS

	These functions provide basic functionality for the buttons in the
	Page Preview Window. You can expand the functionality by using the
	Sheet Layout and Reporting commands and functions.
========================================================================}



FUNCTION LayoutOptions()
	NEW MODAL DIALOG BOX NAMED "Layout Options" AT (-1,-1)(6140,3160)

		ADD CUSTOM BUTTON AT (180,180)+(5860,1980)
		CONTROL ALIAS "margins_title"
		DISABLE CONTROL
		FILL PATTERN 0
		SHOW CONTROL TITLE "Margins@"

		ADD POPUP MENU "Inches","Centimeters","Points" AT (1400,480)+(4460,500)
		SHOW CONTROL NAME "Units Of Measure@"
		IF ISSTRING(report_units)
			SELECT CONTROL ITEM report_units
		END IF
		UNIVERSAL SCRIPT
			"CALL DG:UpdateLayoutOptions(0)",
			"ON MOUSEDOWN",
				"DG:current_unit = CTVALUE(""Units of Measure"",0)",
			"END MOUSEDOWN"

		ADD TEXT "Left:" AT (360,1080)+(650,300)
		NO LINE BORDER
		ALIGN RIGHT

		ADD NUMBER WHEEL AT (1050,1040)+(1200,360)
		NUMBER WHEEL RANGE 0 TO 32768
		NUMBER WHEEL STEP 1
		NUMBER WHEEL POSITION 0
		CONTROL ALIAS "Left"

		ADD TEXT "Top:" AT (360,1640)+(650,300)
		NO LINE BORDER
		ALIGN RIGHT

		ADD NUMBER WHEEL AT (1050,1600)+(1200,360)
		NUMBER WHEEL RANGE 0 TO 32768
		NUMBER WHEEL STEP 1
		NUMBER WHEEL POSITION 0
		CONTROL ALIAS "Top"

		ADD TEXT "Right:" AT (2650,1080)+(1100,300)
		NO LINE BORDER
		ALIGN RIGHT

		ADD NUMBER WHEEL AT (3790,1040)+(1200,360)
		NUMBER WHEEL RANGE 0 TO 32768
		NUMBER WHEEL STEP 1
		NUMBER WHEEL POSITION 0
		CONTROL ALIAS "Right"

		ADD TEXT "Bottom:" AT (2650,1640)+(1100,300)
		NO LINE BORDER
		ALIGN RIGHT

		ADD NUMBER WHEEL AT (3790,1600)+(1200,360)
		NUMBER WHEEL RANGE 0 TO 32768
		NUMBER WHEEL STEP 1
		NUMBER WHEEL POSITION 0
		CONTROL ALIAS "Bottom"

		CALL DialogControlArea(6140,3160,"OK@","Cancel@",0,0)

		SELECT CONTROL "OK@"
		SCRIPT
			"CALL DG:PerformLayoutOptions()",
			"DG:ok = 1"
		DIALOG DEFAULT PUSH BUTTON

		SELECT CONTROL "Cancel@"
		DIALOG CANCEL PUSH BUTTON

		CALL UpdateLayoutOptions(1)

		ok = 0

	USE DIALOG BOX

	RETURN ok { returning 1 forces the Page Preview window to repaint }
END FUNCTION { LayoutOptions }

FUNCTION UpdateLayoutOptions(from_script)
	DEFINE t, l, b, r, new_unit, p, s

	IF from_script
		TARGET WINDOW ActiveDocByType("Script")
			t = PAGEMARGINTOP()/1440
			l = PAGEMARGINLEFT()/1440
			b = PAGEMARGINBOTTOM()/1440
			r = PAGEMARGINRIGHT()/1440
		RESET TARGET WINDOW
		current_unit = 1
	ELSE
		t = CTVALUE("Top",0)
		l = CTVALUE("Left",0)
		b = CTVALUE("Bottom",0)
		r = CTVALUE("Right",0)
	END IF

	report_units = CTSTRING("Units of Measure",0)
	new_unit = CTVALUE("Units of Measure",0)

	t = ConvertValue(t,current_unit,new_unit)
	l = ConvertValue(l,current_unit,new_unit)
	b = ConvertValue(b,current_unit,new_unit)
	r = ConvertValue(r,current_unit,new_unit)

	CASE report_units
		WHEN "Inches"
			p = 2
			s = 0.05
		WHEN "Centimeters"
			p = 2
			s = 0.05
		WHEN "Points"
			p = 0
			s = 1
	END CASE

	SELECT CONTROL "Top"
	NUMBER WHEEL PRECISION p
	NUMBER WHEEL STEP s
	NUMBER WHEEL POSITION t

	SELECT CONTROL "Bottom"
	NUMBER WHEEL PRECISION p
	NUMBER WHEEL STEP s
	NUMBER WHEEL POSITION b

	SELECT CONTROL "Left"
	NUMBER WHEEL PRECISION p
	NUMBER WHEEL STEP s
	NUMBER WHEEL POSITION l

	SELECT CONTROL "Right"
	NUMBER WHEEL PRECISION p
	NUMBER WHEEL STEP s
	NUMBER WHEEL POSITION r
END FUNCTION { UpdateLayoutOptions }

FUNCTION PerformLayoutOptions()
	DEFINE t, l, b, r, units, mult

	t = CTVALUE("Top",0)
	l = CTVALUE("Left",0)
	b = CTVALUE("Bottom",0)
	r = CTVALUE("Right",0)
	units = CTSTRING("Units of Measure",0)
	report_units = units

	TARGET WINDOW ActiveDocByType("Script")
		CASE units
			WHEN "Inches"
				mult = 1440
			WHEN "Centimeters"
				mult = 1440/2.54
			WHEN "Points"
				mult = 20
		END CASE

		RUN "PAGE MARGIN TOP " & t * mult
		RUN "PAGE MARGIN LEFT " & l * mult
		RUN "PAGE MARGIN BOTTOM " & b * mult
		RUN "PAGE MARGIN RIGHT " & r * mult
	RESET TARGET WINDOW
END FUNCTION { PerformLayoutOptions }

FUNCTION ConvertValue(value,old_unit,new_unit)
	DEFINE twips

	IF old_unit = new_unit
		RETURN value
	END IF

	CASE old_unit
		WHEN 1 {inches}
			twips = value*1440
		WHEN 2 {centimeters}
			twips = value*1440/2.54
		WHEN 3 {points}
			twips = value*20
		WHEN 4 {twips}
			twips = value
		WHEN 5 {millimeters}
			twips = (value/10)*1440/2.54
	END CASE

	CASE new_unit
		WHEN 1
			RETURN ROUND(twips/1440,2)
		WHEN 2
			RETURN ROUND(twips/1440*2.54,2)
		WHEN 3
			RETURN ROUND(twips/20,0)
		WHEN 4
			RETURN twips
		WHEN 5
			RETURN ROUND((twips*10)/1440*2.54,2)
	END CASE
END FUNCTION { ConvertValue }



FUNCTION HeaderFooter(header_footer)	{ 1 = header, footer otherwise }
	doit = 0

	IF header_footer = 1
		NEW MODAL DIALOG BOX NAMED "Report Header" AT (-1,-1)(4425,1540)
			CALL DialogControlArea(4425,1540,"OK","Cancel",0,0)

			SELECT CONTROL "OK"
			DIALOG DEFAULT PUSH BUTTON
			SCRIPT
				"REPORT HEADER SOURCE CTSTRING(""val"",0)",
				"DG:doit=1"

			SELECT CONTROL "Cancel"
			DIALOG CANCEL PUSH BUTTON

			ADD FIELD AT (180,180)+(4000,360)
			SHOW CONTROL NAME "Report Header"
			TEXT SIZE 10
			FIELD WORD WRAP OFF
			CONTROL ALIAS "val"
			FIELD TEXT REPORTHEADERSOURCE()

		USE DIALOG BOX
	ELSE { must be footer }
		NEW MODAL DIALOG BOX NAMED "Report Footer" AT (-1,-1)(4425,1540)

			CALL DialogControlArea(4425,1540,"OK","Cancel",0,0)

			SELECT CONTROL "OK"
			DIALOG DEFAULT PUSH BUTTON
			SCRIPT
				"REPORT FOOTER SOURCE CTSTRING(""val"",0)",
				"DG:doit=1"

			SELECT CONTROL "Cancel"
			DIALOG CANCEL PUSH BUTTON

			ADD FIELD AT (180,180)+(4000,360)
			SHOW CONTROL NAME "Report Footer"
			FIELD WORD WRAP OFF
			CONTROL ALIAS "val"
			FIELD TEXT REPORTFOOTERSOURCE()

		USE DIALOG BOX
	END IF

	RETURN doit { 1 forces preview window repaint }
END FUNCTION { ReportFooter }

FUNCTION ReportBody()
	NEW MODAL DIALOG BOX NAMED "Report Body" AT (-1,-1)(5025,1540)

		CALL DialogControlArea(5025,1540,"OK","Cancel",0,0)

		SELECT CONTROL "OK"
		DIALOG DEFAULT PUSH BUTTON
		SCRIPT "DG:print_range = CTSTRING(""val"",0)"

		SELECT CONTROL "Cancel"
		DIALOG CANCEL PUSH BUTTON
		SCRIPT "DG:print_range = 0"

		ADD FIELD AT (180,180)+(4600,360)
		SHOW CONTROL NAME "Report Print Range"
		FIELD WORD WRAP OFF
		CONTROL ALIAS "val"
		FIELD TEXT REPORTPRINTRANGE()

	USE DIALOG BOX

	IF print_range <> 0
		IF ISRANGE(RANGE(print_range))
			SELECT RANGE print_range
			REPORT PRINT RANGE
		ELSE
			ERROR MESSAGE "Invalid Range"
		END IF
		RETURN 1 { repaint preview window }
	ELSE { dlg canceled }
		RETURN 0 { dont repaint preview window }
	END IF
END FUNCTION { ReportBody }

FUNCTION ScriptLayoutOptions()
	CALL LayoutOptions()
END FUNCTION

FUNCTION DGPreviewGoto(CurPageNum)

	NEW MODAL DIALOG BOX NAMED "Goto" AT (-1,-1)(3700,1700)

		ADD NUMBER WHEEL AT (200,200)+(3300,600)
		NUMBER WHEEL RANGE 1 TO 32767
		NUMBER WHEEL STEP 1
		NUMBER WHEEL POSITION CurPageNum
		SHOW CONTROL NAME "Page Number@"
		CONTROL ALIAS "GotoWheel"
		SELECT KEY CONTROL "GotoWheel"

		val1 = 0

		CALL DialogControlArea(3700,1700,"OK","Cancel",0,0)

		SELECT CONTROL "OK"
			DIALOG DEFAULT PUSH BUTTON
			UNIVERSAL SCRIPT "DG:val1 = CTVALUE(""GotoWheel"",0)"

		SELECT CONTROL "Cancel"
			DIALOG CANCEL PUSH BUTTON

	USE DIALOG BOX

	RETURN val1
END FUNCTION



{ PRINT DIALOG FUNCTIONS FOR UNIX PLATFORMS ONLY }

FUNCTION DGGrayPrintDest()
	IF CTVALUE(9,1) = 1
		SELECT CONTROL 10
		GREY CONTROL
	ELSE
		SELECT CONTROL 10
		UNGREY CONTROL
	END IF
END FUNCTION



FUNCTION DGGrayPrintRange()
	IF CTVALUE(4,1) = 1
		SELECT CONTROL 5,6
		GREY CONTROL
	ELSE
		SELECT CONTROL 5
		UNGREY CONTROL
		SELECT FIELD LINE 1

		SELECT CONTROL 6
		UNGREY CONTROL
		SELECT FIELD LINE 1
	END IF
END FUNCTION



FUNCTION DGCheckPrinterName(printer)
	IF PRINTER = "File"
		SELECT CONTROL 9
		SELECT CONTROL ITEM 2
		GREY CONTROL
		SELECT CONTROL 10
		UNGREY CONTROL
	ELSE
		SELECT CONTROL 9
		UNGREY CONTROL
		IF CTVALUE(9,1) = 1
			SELECT CONTROL 10
			GREY CONTROL
		ELSE
			SELECT CONTROL 10
			UNGREY CONTROL
		END IF
	END IF
END FUNCTION



FUNCTION DGPrint(firstp, lastp)
	DEFINE command, lastpage, found, target, available, env

	doit = 0
	env = getenv(0);

	IF printfile = 0
		printfile = GETENV("HOME") & "/printfile.eps"
	END IF

	available = AVAILABLEPRINTERS()
	target = TARGETPRINTER()
	found = ISARRAY(SEARCHARRAY(available,target,1))

	IF NOT found
		ERROR MESSAGE "The printer '"&target&"' is not available. The default printer will be used."
	END IF

	{1 2}
	CALL dgokcan(7000,6000,1000,5100,6000,6000,"Print Options",
	"DG:val1 = CTVALUE(4,0) DG:str1 = CTSTRING(5,0) DG:str2 = CTSTRING(6,0)
	DG:val2 = CTVALUE(7,0) DG:val3 = CTVALUE(9,0) DG:str3 = CTSTRING(10,0)
	DG:str4 = CTSTRING(11,0)")

	{3}
	ADD CUSTOM BUTTON AT (300, 100)(6700, 2050)
	FILL PATTERN 0
	DISABLE CONTROL
	SHOW CONTROL TITLE "Page Information"

	{4}
	ADD RADIO BUTTON "@All", "Range" AT (500, 700)(1750, 1800)
	UNIVERSAL SCRIPT
		"ON MOUSEUP",
			"CALL DG:DGGrayPrintRange()",
		"END MOUSEUP"
	IF firstp = lastp
		SELECT CONTROL ITEM "Range"
	ELSE
		SELECT CONTROL ITEM "All"
	END IF

	{5}
	ADD FIELD AT (2000, 700)(3900, 1100)
	FIELD TEXT firstp
	MAXIMUM FIELD LENGTH 8
	SHOW CONTROL NAME "From@"

	{6}
	ADD FIELD AT (2250, 1400)(3900, 1800)
	IF firstp = lastp
		FIELD TEXT lastp
	ELSE
		FIELD TEXT "last"
	END IF
	MAXIMUM FIELD LENGTH 8
	SHOW CONTROL NAME "To@"

	{7}
	ADD NUMBER WHEEL AT (4200, 900)(6500, 1260)
	NUMBER WHEEL RANGE 1 TO 100
	NUMBER WHEEL PRECISION 0
	NUMBER WHEEL STEP 1
	SHOW CONTROL NAME "Copies@"
	NUMBER WHEEL POSITION copiesToPrint()

	{8}
	ADD CUSTOM BUTTON AT (300, 2100)(6700, 5000)
	FILL PATTERN 0
	DISABLE CONTROL
	SHOW CONTROL TITLE "Destination Information"

	{9}
	ADD RADIO BUTTON "Printer", "File" AT (500, 2700) (2000, 3800)
	UNIVERSAL SCRIPT
		"ON MOUSEUP",
			"CALL DG:DGGrayPrintDest()",
		"END MOUSEUP"

	{10}
	ADD FIELD AT (500, 4000) (6500, 4800)
	SHOW CONTROL TITLE "File Name"
	FIELD TEXT printfile
	MAXIMUM FIELD LENGTH 256
	SELECT FIELD LINE 1

	{11}
	ADD LIST BOX available AT (2200, 2700) (6500, 3800)
	SHOW SCROLL BAR LIST BOX
	SHOW CONTROL NAME "Printer Name"
	IF found
		SELECT CONTROL ITEM target
		TOP LIST BOX ITEM target
	END IF
	IF env = 3 OR env = 8
		UNIVERSAL SCRIPT "ON MOUSEUP CALL RTDG:DGCheckPrinterName(ctstring(11,0)) END MOUSEUP"
	END IF

	CALL DGGrayPrintRange()
	CALL DGGrayPrintDest()
	IF env = 3 OR env = 8
		CALL DGCheckPrinterName(ctstring(11,0))
	END IF

	USE DIALOG BOX

	IF doit

		REPAINT OFF

		SELECT SHEET LAYOUT currentSheetLayout()
		TARGET PRINTER str4
		COPIES TO PRINT val2
		CURRENT SHEET LAYOUT currentSheetLayout()

		command = "PRINT"

		IF val1<>1
			lastpage = VALUE(str2)
			IF lastpage < 1
				lastpage = NRPAGES()
			END IF

			command = command & " FROM " & VALUE(str1) & " TO " & lastpage
		END IF

		IF val3 <> 1
			printfile = str3
			command = command & " FILE """ & printfile & """"
		END IF

		IF val1 = 1 AND val3 = 1
			command = command & " NOW"
		END IF

		UNIVERSAL RUN command

		REPAINT ON
	END IF
END FUNCTION { DGPrint }



FUNCTION fixPageSetupLists()
	DEFINE newprinter

	newprinter = CTSTRING("PrinterName", 0)

		IF LENGTH(newprinter) = 0
				SELECT CONTROL "PrinterName"
				SELECT CONTROL ITEM 1
				newprinter = CTSTRING("PrinterName",0)
				REPAINT CONTROL
		END IF

	IF newprinter <> currentprinter

		TARGET PRINTER newprinter
		currentprinter = newprinter

		SELECT CONTROL "PaperType"
		POPUP MENU ITEMS PAPERTYPES()
		SELECT CONTROL ITEM PAPERTYPE()

		SELECT CONTROL "Resolution"
		POPUP MENU ITEMS PRINTERRESOLUTIONS()
		SELECT CONTROL ITEM PRINTERRESOLUTION()

		SELECT CONTROL "Orientation"
		SELECT CONTROL ITEM PAGEORIENTATION() + 1
	END IF
END FUNCTION { fixPageSetupLists }



FUNCTION PageSetupDialog()
	DEFINE type, orient, resol, origprinter, origpaper, origorient, origresol,
			available,found

	TARGET WINDOW ActiveDocByType("Sheet")
	SELECT SHEET LAYOUT CURRENTSHEETLAYOUT()

	available = AVAILABLEPRINTERS()
	currentprinter = TARGETPRINTER()
	origprinter = currentprinter
	type = PAPERTYPE()
	origpaper = type
	orient = PAGEORIENTATION()
	origorient = orient
	resol = PRINTERRESOLUTION()
	origresol = resol
	RESET TARGET WINDOW

		found = ISARRAY(SEARCHARRAY(available,currentprinter,1))

		IF NOT found
			ERROR MESSAGE "The printer '"&currentprinter&"' is not available. The default printer will be used."
		END IF

		NEW MODAL DIALOG BOX NAMED "Page Setup" AT (-1,-1)(5500,3900)

		ADD LIST BOX available AT (2300,200) + (3000,1300)
		CONTROL ALIAS "PrinterName"
		SHOW SCROLL BAR LIST BOX
		IF found
				SELECT CONTROL ITEM currentprinter
		END IF
		UNIVERSAL SCRIPT "ON MOUSEUP CALL DG:fixPageSetupLists() END MOUSEUP"

		ADD POPUP MENU PAPERTYPES() AT (2300,1600) +(3000,500)
		CONTROL ALIAS "PaperType"
		SELECT CONTROL ITEM type

		ADD POPUP MENU "Portrait","Landscape" AT (2300,2100) +(3000,500)
		CONTROL ALIAS "Orientation"
		IF orient
				SELECT CONTROL ITEM "Landscape"
		END IF

		ADD POPUP MENU PRINTERRESOLUTIONS() AT (2300,2600) +(3000,500)
		CONTROL ALIAS "Resolution"
		SELECT CONTROL ITEM resol

		ADD TEXT "Printer Name:" AT (200,650+50{Motif}) +(2000,350)
		NO LINE BORDER
		ALIGN RIGHT

		ADD TEXT "Paper Type:" AT (200,1600+50{Motif}) +(2000,350)
		NO LINE BORDER
		ALIGN RIGHT

		ADD TEXT "Orientation:" AT (200,2100+50{Motif}) +(2000,350)
		NO LINE BORDER
		ALIGN RIGHT

		ADD TEXT "Resolution:" AT (200,2600+50{Motif}) +(2000,350)
		NO LINE BORDER
		ALIGN RIGHT

		CALL HSA:DialogControlArea(5500,3900,"OK@","Cancel@",0,0)

		SELECT CONTROL "Cancel"
		DIALOG CANCEL PUSH BUTTON

		SELECT CONTROL "OK"
		DIALOG DEFAULT PUSH BUTTON
		UNIVERSAL SCRIPT
			"IF LENGTH(CTSTRING(""PrinterName"",0)) = 0",
				"		SELECT CONTROL ""PrinterName"" ",
				"		SELECT CONTROL ITEM 1",
				"		CALL DG:fixPageSetupLists()",
				"END IF",
			"DG:doit = 1",
			"DG:val1 = CTSTRING(""PaperType"",0)",
			"DG:val2 = CTSTRING(""Orientation"",0)",
			"DG:val3 = CTSTRING(""Resolution"",0)",
			"DG:val4 = CTSTRING(""PrinterName"",0)"

		doit = 0
	USE DIALOG BOX

	TARGET WINDOW ActiveDocByType("Sheet")

	REPAINT OFF

	IF doit
		SELECT SHEET LAYOUT CURRENTSHEETLAYOUT()

		PAPER TYPE val1
		IF val2 = "Landscape"
			PAGE ORIENTATION LANDSCAPE
		ELSE
			PAGE ORIENTATION PORTRAIT
		END IF
		PRINTER RESOLUTION val3
	ELSE
		IF TARGETPRINTER() <> origprinter
			TARGET PRINTER origprinter
			doit = 1
		END IF
		IF PAPERTYPE() <> origpaper
			PAPER TYPE origpaper
			doit = 1
		END IF
		IF PAGEORIENTATION() <> origorient
			IF origorient
				PAGE ORIENTATION LANDSCAPE
			ELSE
				PAGE ORIENTATION PORTRAIT
			END IF
			doit = 1
		END IF
		IF PRINTERRESOLUTION() <> origresol
			PRINTER RESOLUTION origresol
			doit = 1
		END IF
	END IF

	CURRENT SHEET LAYOUT CURRENTSHEETLAYOUT()

	REPAINT ON
	REPAINT WINDOW
	RETURN doit
END FUNCTION { PageSetupDialog() }



{========================================================================
	UTILITY FUNCTIONS

	These functions provide nice utilities that may be useful in your
	programs.
========================================================================}



{=============================================================================
	FUNCTION NAME
		DoubleQuoteIt
	DESCRIPTION
		This function doubles the number of quotes contained in the string. E.G.
	the string:
			He said "See you later!" to her.
		would become:
			He said ""See you later!"" to her.
	RETURNS
		string after being double quoted
	PARAMETERS
		string - string to be double quoted
=============================================================================}

FUNCTION DoubleQuoteIt(string)
	DEFINE pos

	IF CONTAINS(string,"""")
		pos = MATCH(string,"""",1)
		RETURN LEFT(string,pos) & """" & DoubleQuoteIt(RIGHT(string,LENGTH(string)-pos))
	ELSE
		RETURN string
	END IF
END FUNCTION { DoubleQuoteIt }

FUNCTION DGAsk(prmpt,initstr,maxlength)
	DEFINE fw, tw, w, a, b, mult

	mult = 130
	fw = maxlength*mult + 130
	tw = length(prmpt)*mult

	w = max(fw,tw)+400

	IF w < 3000
		w = 3000
	ELSEIF w > 10000
		w = 10000
	END IF

	IF fw > 9600
		fw = 9600
	END IF

	IF fw > tw
		tw = fw
	END IF

	a = 0 b = w
	IF w > 5000
		a = (w-5000) / 2
		b = b - a
	END IF

	CALL dgokcan(w,2100,a,1200,b,2100,"???","DG:str1 = CTSTRING(4,0)")

		ADD TEXT prmpt AT (200,100)+(tw,600)
		NO LINE BORDER

		ADD FIELD AT (200,700)+(fw,360)
		FIELD TEXT initstr
		MAXIMUM FIELD LENGTH maxlength
		str1 = initstr

	USE DIALOG BOX

	RETURN str1
END FUNCTION



{========================================================================
	PLATFORM-INDEPENDANT DIALOG CONTROL PLACEMENT

	This function automatically arranges the OK/Cancel buttons or their
	equivalents in the layout specified by the platform.
========================================================================}



{
	FUNCTION
		DialogControlArea
	Description
		This function creates and positions the control buttons in dialog boxes.
		This function automatically adapts to each platform.
	RETURNS
		Nothing.
	PARAMETERS
		dg_width	- the width of the dialog box.
		dg_height - the height of the dialog box.
		def_button	- the dialog default button.
		can_button	- the dialog cancel button.
		more_button - the (1) more choices or (-1) less choices button.
		other_buttons - a 1-n arrayel of button names.
}
FUNCTION DialogControlArea(dg_width, dg_height, def_button, can_button,
					more_button, other_buttons)

	DEFINE button_height, button_width, one_grid, two_grid, cur_button,
			button_top, button_left, button_index, num_buttons,
			total_button_width, button_spacing, def_extra_width,
			button_array, button_number, display_length, total_length,
			total_space

	platform = GETENV(0)

	IF NOT CONTAINS(def_button,"@")
		def_button = def_button & "@"
	END IF

	IF CONTAINS(UPPER(can_button),"CANCEL")
		IF NOT CONTAINS(can_button,"@")
			can_button = can_button & "@"
		END IF
	END IF

	CASE platform
		WHEN 1 { mac }
			button_height = 400
			button_width = 1200
			button_number = 1
			one_grid = 100
			two_grid = 200
			button_top = dg_height - 6 * one_grid

			REDIMENSION button_array[IF(ISSTRING(def_button),1,0)+
				IF(ISSTRING(can_button),1,0)+
				IF(ISARRAY(other_buttons),NRELEMENTS(other_buttons,1),0),2]

			IF ISSTRING(def_button)
				def_extra_width = one_grid
				display_length = DISPLAYLENGTH(SearchAndReplace(def_button,
						"@",""),"Chicago",12,"bious")
				button_array[button_number,1] = def_button
				button_array[button_number,2] =
						IF(display_length+200>button_width,display_length+200,button_width)
				button_number = button_number+1
			END IF

			IF ISSTRING(can_button)
				display_length = DISPLAYLENGTH(SearchAndReplace(can_button,
						"@",""),"Chicago",12,"bious")
				button_array[button_number,1] = can_button
				button_array[button_number,2] =
						IF(display_length + 300 > button_width, display_length + 300, button_width)
				button_number = button_number + 1
			END IF

			IF ISARRAY(other_buttons)
				FOR button_index = 1 TO NRELEMENTS(other_buttons,1)
					display_length = DISPLAYLENGTH(SearchAndReplace(
						other_buttons[button_index],"@",""), "Chicago",12,"bious")
					button_array[button_number,1] = other_buttons[button_index]
					button_array[button_number,2] =
								IF(display_length + 200 > button_width, display_length + 200, button_width)
					button_number = button_number + 1
				END FOR
			END IF

			button_left = dg_width - two_grid

			FOR button_number = 1 TO NRELEMENTS(button_array,1)
				button_left = button_left - button_array[button_number,2]
				IF button_number = 1
					button_left = button_left - def_extra_width
				END IF
				ADD PUSH BUTTON button_array[button_number,1] AT (button_left, button_top)+
						(button_array[button_number,2], button_height)
				button_left = button_left - one_grid
				IF button_number = 1
					button_left = button_left - def_extra_width
				END IF
			END FOR { cycle thru buttons }

			IF more_button = 1
				ADD PUSH BUTTON "More Choices" AT (two_grid, button_top)+(2040, button_height)
			ELSEIF more_button = -1
				ADD PUSH BUTTON "Fewer Choices" AT (two_grid, button_top)+(2040, button_height)
			END IF

		WHEN 5 { Windows }
			button_height = 380
			button_width = 1000
			button_number = 1
			one_grid = 90
			two_grid = 180
			button_top = dg_height - 6 * one_grid
			num_buttons = IF(ISSTRING(def_button),1,0) + IF(ISSTRING(can_button),1,0) +
								IF(ISARRAY(other_buttons),NRELEMENTS(other_buttons,1),0)+
								IF(more_button <> 0,1,0)

			REDIMENSION button_array[num_buttons,2]

			IF ISSTRING(def_button)
				display_length = DISPLAYLENGTH(SearchAndReplace(def_button,"@",""),"Arial",10,"Bious")
				button_array[button_number,1] = def_button
				button_array[button_number,2] = IF(display_length +200 > button_width, display_length + 200, button_width)
				button_number = button_number + 1
			END IF

			IF ISSTRING(can_button)
				display_length = DISPLAYLENGTH(SearchAndReplace(can_button,"@",""),"Arial",10,"Bious")
				button_array[button_number,1] = can_button
				button_array[button_number,2] = IF(display_length +200 > button_width, display_length + 200, button_width)
				button_number = button_number + 1
			END IF

			IF ISARRAY(other_buttons)
				FOR button_index = 1 TO NRELEMENTS(other_buttons,1)
					display_length = DISPLAYLENGTH(SearchAndReplace(other_buttons[button_index],"@",""),
						"Arial",10,"Bious")
					button_array[button_number,1] = other_buttons[button_index]
					button_array[button_number,2] = IF(display_length +200 > button_width, display_length + 200, button_width)
					button_number = button_number + 1
				END FOR
			END IF

			IF more_button = 1
				display_length = DISPLAYLENGTH("More Choices","Arial",10,"Bious")
				button_array[button_number,1] = "More Choices"
				button_array[button_number,2] = IF(display_length +200 > button_width, display_length + 200, button_width)
				button_number = button_number + 1
			ELSEIF more_button = -1
				display_length = DISPLAYLENGTH("Fewer Choices","Arial",10,"Bious")
				button_array[button_number,1] = "Fewer Choices"
				button_array[button_number,2] = IF(display_length +200 > button_width, display_length + 200, button_width)
				button_number = button_number + 1
			END IF

			total_length = SUM(button_array[*,2])
			total_space = (num_buttons-1) * one_grid
			total_length = total_length + total_space
			button_left = (dg_width / 2) - (total_length / 2)

			FOR button_number = 1 TO num_buttons
				ADD PUSH BUTTON button_array[button_number,1] AT (button_left, button_top)+
						(button_array[button_number,2], button_height)
				button_left = button_left + button_array[button_number,2] + one_grid
			END FOR { cycle thru buttons }

		WHEN 3 { OL }
			button_height = 400
			button_width = 1440
			button_number = 1
			one_grid = 100
			two_grid = 200
			button_top = dg_height - 6 * one_grid

			REDIMENSION button_array[IF(ISSTRING(def_button),1,0) + IF(ISSTRING(can_button),1,0) +
										IF(ISARRAY(other_buttons),NRELEMENTS(other_buttons,1),0),2]

			IF ISSTRING(def_button)
				display_length = DISPLAYLENGTH(SearchAndReplace(def_button,"@",""),"Chicago",12,"bious")
				button_array[button_number,1] = def_button
				button_array[button_number,2] = IF(display_length > 1200, display_length + 200, 1440)
				button_number = button_number + 1
			END IF

			IF ISSTRING(can_button)
				display_length = DISPLAYLENGTH(SearchAndReplace(can_button,"@",""),"Chicago",12,"bious")
				button_array[button_number,1] = can_button
				button_array[button_number,2] = IF(display_length > 1200, display_length + 300, 1440)
				button_number = button_number + 1
			END IF

			IF ISARRAY(other_buttons)
				FOR button_index = 1 TO NRELEMENTS(other_buttons,1)
					display_length = DISPLAYLENGTH(SearchAndReplace(other_buttons[button_index],"@",""),
						"Chicago",12,"bious")
					button_array[button_number,1] = other_buttons[button_index]
					button_array[button_number,2] = IF(display_length > 1200, display_length + 200, 1440)
					button_number = button_number + 1
				END FOR
			END IF

			button_left = dg_width - two_grid

			FOR button_number = 1 TO NRELEMENTS(button_array,1)
				button_left = button_left - button_array[button_number,2]
				ADD PUSH BUTTON button_array[button_number,1] AT (button_left, button_top)+
						(button_array[button_number,2], button_height)
				button_left = button_left - one_grid
			END FOR { cycle thru buttons }

			IF more_button = 1
				ADD PUSH BUTTON "More Choices" AT (two_grid, button_top)+(2040, button_height)
			ELSEIF more_button = -1
				ADD PUSH BUTTON "Fewer Choices" AT (two_grid, button_top)+(2040, button_height)
			END IF
		WHEN 8 { Motif }
			button_height = 400
			button_width = 1440
			button_number = 1
			one_grid = 100
			two_grid = 200
			button_top = dg_height - 6 * one_grid

			REDIMENSION button_array[IF(ISSTRING(def_button),1,0) + IF(ISSTRING(can_button),1,0) +
										IF(ISARRAY(other_buttons),NRELEMENTS(other_buttons,1),0) +
										IF(more_button<>0,1,0),2]

			IF ISSTRING(def_button)
				display_length = DISPLAYLENGTH(SearchAndReplace(def_button,"@",""),"helvetica",12,"bious")
				button_array[button_number,1] = def_button
					button_array[button_number,2] = IF(display_length > 1100, display_length + 640, 1440)
				button_number = button_number + 1
			END IF

			IF ISARRAY(other_buttons)
				FOR button_index = 1 TO NRELEMENTS(other_buttons,1)
					display_length = DISPLAYLENGTH(SearchAndReplace(other_buttons[button_index],"@",""),
						"helvetica",12,"bious")
					button_array[button_number,1] = other_buttons[button_index]
					button_array[button_number,2] = IF(display_length > 1100, display_length + 640, 1440)
					button_number = button_number + 1
				END FOR
			END IF

			IF ISSTRING(can_button)
				display_length = DISPLAYLENGTH(SearchAndReplace(can_button,"@",""),"helvetica",12,"bious")
				button_array[button_number,1] = can_button
					button_array[button_number,2] = IF(display_length > 1100, display_length + 640, 1440)
				button_number = button_number + 1
			END IF

			IF more_button = 1
				button_array[NRELEMENTS(button_array,1),1] = "More Choices"
				button_array[NRELEMENTS(button_array,1),2] = 2040
			ELSEIF more_button = -1
				button_array[NRELEMENTS(button_array,1),1] = "Fewer Choices"
				button_array[NRELEMENTS(button_array,1),2] = 2040
			END IF

			total_button_width = 0
			FOR button_number = 1 TO NRELEMENTS(button_array,1)
				total_button_width = total_button_width + button_array[button_number,2]
			END FOR

			IF NRELEMENTS(button_array,1) > 1
				button_spacing = (dg_width-(two_grid*2)-total_button_width) / (NRELEMENTS(button_array,1)-1)
				button_left = two_grid
			ELSE { only one button }
				button_spacing = 0
				button_left = (dg_width/2) - (total_button_width/2)
			END IF { if more than one button }

			FOR button_number = 1 TO NRELEMENTS(button_array,1)
				ADD PUSH BUTTON button_array[button_number,1] AT (button_left, button_top)+
						(button_array[button_number,2], button_height)
				button_left = button_left + button_array[button_number,2] + button_spacing
			END FOR { cycle thru buttons }
	END CASE { platform }

	ADD CUSTOM BUTTON AT (two_grid, dg_height - 8 * one_grid-20)
												(dg_width-two_grid, dg_height - 8 * one_grid)
		CONTROL ALIAS "dialog_separator"
		OUTLINE 2 BORDER
		DISABLE CONTROL

END FUNCTION { DialogControlArea }

FUNCTION SearchAndReplace(string, searchstr, replacestr)
		DEFINE replacelen, searchlen, findloc, elements, count

		IF searchstr = replacestr
			RETURN string
		END IF

		IF NOT ISARRAY(string)
			IF LENGTH(string) > 0
					replacelen = LENGTH(replacestr)
					searchlen = LENGTH(searchstr)

					findloc = FIND(searchstr, string, 0)
					WHILE NOT ISERR(findloc)
						string = REPLACE(string, findloc, searchlen, replacestr)
						findloc = FIND(searchstr, string, findloc+replacelen)
					END WHILE
			END IF
		ELSE
			elements = NRELEMENTS(string,1)

			FOR count = 1 TO elements

					IF LENGTH(string[count]) > 0
						replacelen = LENGTH(replacestr)
						searchlen = LENGTH(searchstr)

						findloc = FIND(searchstr, string[count], 0)
						WHILE NOT ISERR(findloc)
								string[count] = REPLACE(string[count], findloc, searchlen, replacestr)
								findloc = FIND(searchstr, string[count], findloc+replacelen)
						END WHILE
					END IF

			END FOR
		END IF

		RETURN string

END FUNCTION { SearchAndReplace() }

FUNCTION ActiveDocByType(type)
	DEFINE windex, nrwins, win_type

	nrwins = NRWINDOWS()
	IF nrwins = 0
		RETURN 0
	ELSE
		IF type = "Sheet"
			FOR windex = 1 TO nrwins
				win_type = WINDOWINFO(windex, 3)
				IF (win_type = 0 OR
							win_type = 9 {form} OR
							win_type = 10 {report} OR
							win_type = 13) {graphics editor}
					AND WINDOWINFO(windex,2) { window visible }
					RETURN WINDOWINFO(windex, 0)
				END IF
			END FOR
		ELSE
			FOR windex = 1 TO nrwins
				IF WINDOWINFO(windex,4) = type
					RETURN WINDOWINFO(windex,0)
				END IF
			END FOR
		END IF
		RETURN 0
	END IF
END FUNCTION { ActiveDocByType }



{========================================================================
	DOUBLECLICK TRAPS

	Use the functions in this section to trap object tool doubleclicks
========================================================================}

FUNCTION Gallery()
	{	This function called if user doubleclicks on chart background area }
END FUNCTION

FUNCTION ChartTitle()
	{	This function called if user doubleclicks on chart title area }
END FUNCTION

FUNCTION FootNote()
	{	This function called if user doubleclicks on chart footnote area }
END FUNCTION

FUNCTION Legend()
	{	This function called if user doubleclicks on chart legend area }
END FUNCTION

FUNCTION Plot()
	{	This function called if user doubleclicks on chart plot area }
END FUNCTION

FUNCTION ChartDataSources()
	{	This function called if user doubleclicks on chart plot area }
END FUNCTION

FUNCTION LabelsAndLayout()
	{	This function called if user doubleclicks on chart title, legend, or footnote }
END FUNCTION

FUNCTION Series()
	{	This function called if user doubleclicks on chart series or series label }
END FUNCTION

FUNCTION Axis()
	{	This function called if user doubleclicks on any chart axis }
END FUNCTION

FUNCTION ColorsAndLines()
	{	This function called if user doubleclicks on an object }
END FUNCTION

FUNCTION ControlOptionsDispatcher()
	{	This function called if user doubleclicks on a control }
END FUNCTION

FUNCTION FieldOptions()
	{	This function called if user doubleclicks on text field }
END FUNCTION

FUNCTION FunctionGlossary()
	{	This function called if user clicks on Function Glossary icon }
	{	The function glossary icon is called "funcactn" and may be	}
	{	found in the Wingz/WingzPro resource file for Windows		}
END FUNCTION

FUNCTION RenameSheet()
	{ This function is called if the user double clicks on a sheet }
	{ in the navigator bar. }
END FUNCTION



{========================================================================
	BASIC FUNCTIONALITY

	These functions provide basic functionality needed by the HyperScript
	Engine. Modification of these functions is not recommended.
========================================================================}


{
	num = DGPromptAutoloadWS(str1,str2)

	Builds a dialog box that asks what a user wants to do about
		a worksheet related to the current worksheet

	Takes two string arguments:
		Argument str1:	The parent filename
		Argument str2:	The related filename

	Returns a number:
		0:	User doesn't want to open related file
		1:	User only wants to refresh related file
		2:	User wants to load related file
}

FUNCTION DGPromptAutoloadWS(base,relation)
	DEFINE button[1]

		NEW MODAL DIALOG BOX NAMED "Related Workbook" AT (-1,-1)(6700,3000)

			ADD TEXT base AT (180,180)(6520,980)
		SHOW CONTROL TITLE "Workbook"

			ADD TEXT relation AT (180,1180)(6520,1980)
		SHOW CONTROL TITLE "Is Related to"

		Button[1] = "Refresh Only"
		CALL DialogControlArea(6700,3000,"Open File","Don't Open",FALSE(),Button)

		SELECT CONTROL "Don't Open"
		DIALOG CANCEL PUSH BUTTON
		SCRIPT "DG:temp = 0"

		SELECT CONTROL "Refresh Only"
		SCRIPT
			"DG:temp = 1",
			"QUIT DIALOG BOX"

		SELECT CONTROL "Open File"
		DIALOG DEFAULT PUSH BUTTON
		SCRIPT "DG:temp = 2"

	USE DIALOG BOX

	RETURN temp
END FUNCTION { DGPromptAutoloadWS }


{
	num = DGFindWS(str1)

	Builds a dialog box that displays a filename which wingz
	cannot find to load, and asks the user for another name

	Takes one string argument:
		Argument str1:	The filename which Wingz can't find

	Returns a number or a string:
		String: if user clicks the "open" button
		Number: returns zero if user clicks the "cancel" button
}

FUNCTION DGFindWS(file)
	DEFINE browse_button[1]

	browse_button[1] = "Browse..."

	NEW MODAL DIALOG BOX NAMED "Find Workbook File" AT (-1,-1) +(6760,2500)

		ADD TEXT "Cannot Find:" AT (180,360)+(2000, 400)
		ALIGN RIGHT
		NO LINE BORDER

		ADD TEXT file AT (2200,360)+(4380, 400)
		NO LINE BORDER

		ADD TEXT "Find as:" AT (180,960)+(2000, 400)
		ALIGN RIGHT
		NO LINE BORDER

		ADD FIELD AT (2200,920)+(4380, 360)
		FIELD TEXT file

		CALL DialogControlArea(6760,2500,"OK@","Cancel@",0,browse_button)

		SELECT CONTROL "Cancel"
		DIALOG CANCEL PUSH BUTTON
		SCRIPT "DG:temp = 0"

		SELECT CONTROL "OK"
		DIALOG DEFAULT PUSH BUTTON
		UNIVERSAL SCRIPT "DG:temp = CTSTRING(4,0)"

		SELECT CONTROL browse_button[1]
		SCRIPT
			"OPEN NAME DIALOG ITEMS ""Workbook"" EXTENSIONS "".wkz""",
			"IF OPENSAVENAME()<>""""",
				"SELECT CONTROL 4",
				"FIELD TEXT OPENSAVENAME()",
			"END IF"
	USE DIALOG BOX

	RETURN temp
END FUNCTION { DGFindWS }


{
	num = DGNameConflict(str1,str2)

	Builds a dialog box which displays two filenames that
		conflict, and asks the user for a third name.

	Takes two string arguments:
		Argument str1:	The first conflicting filename
		Argument str2:	The second conflicting filename

	Returns a number or a string:
		String: Returns the string typed in by the user, if he
							clicked the "OK" button
		Number: Returns a zero if the user clicked the "cancel"
							button
}

FUNCTION DGNameConflict(name1,name2)

	NEW MODAL DIALOG BOX NAMED "Name Conflict" AT (-1,-1)+(5700,3400)

		ADD TEXT "Current File:" AT (200,200)+(5300,300)
		NO LINE BORDER

		ADD TEXT name1 AT (200,500)+(5300,300)
		NO LINE BORDER

		ADD TEXT "Is Conflicting With Another File Named:" AT (200,1000)+(5300,300)
		NO LINE BORDER

		ADD TEXT name2 AT (200,1300)+(5300,300)
		NO LINE BORDER

		ADD TEXT "New Name:" AT (200,1800)+(5300,300)
		NO LINE BORDER

		ADD FIELD AT (200,2100)+(5300,360)
		FIELD TEXT name2

		CALL DialogControlArea(5700,3400,"OK","Cancel",0,0)

		SELECT CONTROL "OK"
		DIALOG DEFAULT PUSH BUTTON
		SCRIPT "DG:temp = CTSTRING(8,0)"

		SELECT CONTROL "Cancel"
		DIALOG CANCEL PUSH BUTTON
		SCRIPT "DG:temp = 0"

	USE DIALOG BOX

	RETURN temp
END FUNCTION { DGNameConlict }


{
	GetTextType(str)

	Builds a dialog box which prompts the user whether
	to parse the text file with tabs or commas.

	Takes one string arguments:
		Argument str:	The filename

	Returns a number:
		Number: 1 for tabs and 2 for commas. 0 for cancel.
}

FUNCTION GetTextType(fname)
	DEFINE name_len

	{ text_load_interactive must be set to 1 before issuing the OPEN DIALOG }
	{ command in order for the tab/comma delimited to be invoked			}
	IF NOT text_load_interactive
		RETURN 1
	END IF

	name_len = DISPLAYLENGTH(fname, "", 0, "")
	IF name_len<4640
		name_len = 4640
	END IF

	val1 = 0

	{1, 2}
	CALL dgokcan(name_len+360,3800,0,2900,name_len+360, 3800,"Text Type","DG:val1 = CTVALUE(5,0)")

		{3}
		ADD TEXT "Specify text file format for:" AT (180, 360)(name_len+180,760)
		NO LINE BORDER
		ALIGN CENTER

		{4}
		ADD TEXT fname AT (180, 1060)(name_len+180,1460)
		NO LINE BORDER
		ALIGN CENTER

		{5}
		ADD RADIO BUTTON "Tab-Delimited","Comma-Delimited" AT ((name_len-2880)/2+180,1660)+(2880,1100)

	USE DIALOG BOX

	RETURN val1
END FUNCTION



FUNCTION dgokcan(dx,dy,x0,y0,x1,y1,n,s)
	DEFINE xx0, xx1

	xx0 = x0
	xx1 = x1

	IF (x1-x0)>5000
		xx0 = xx0 + ((x1 - x0) - 5000) / 2
		xx1 = xx1 - ((x1 - x0) - 5000) / 2
	END IF

	NEW MODAL DIALOG BOX NAMED n AT (-1,-1)(dx,dy)

{1 2} ADD PUSH BUTTON "OK@","Cancel@" at (xx0,y0)(xx1,y1)
		UNIVERSAL SCRIPT "DG:doit = 0"
		DIALOG CANCEL PUSH BUTTON

		SELECT CONTROL 1
		UNIVERSAL SCRIPT "DG:doit = 1 "&s
		DIALOG DEFAULT PUSH BUTTON
END FUNCTION

FUNCTION DGNewName(name)
	NEW MODAL DIALOG BOX NAMED "New Name" AT (-1,-1) (5800,2400)

		ADD PUSH BUTTON "OK@" AT (2300,1600) (3500,2100)
		UNIVERSAL script "DG:str1 = CTSTRING(3,0)"
		DIALOG DEFAULT PUSH BUTTON

		ADD TEXT "Invalid range name, enter new name." AT (240,200) (5600,550)
		NO LINE BORDER

		ADD FIELD AT (200,550) (5600,950)
		MAXIMUM FIELD LENGTH 200
		FIELD TEXT NAME
		FIELD WORD WRAP OFF
		str1 = name

	USE DIALOG BOX

	RETURN str1
END FUNCTION



FUNCTION FindInHelp()
	DEFINE dgWidth, dgHeight

	dgWidth = 4500
	dgHeight = 1540
	NEW MODAL DIALOG BOX NAMED "Find Help" AT (-1,-1)(dgWidth,dgHeight)

		ADD FIELD AT (180, 180)+(dgWidth-(2*180), 360)
		MAXIMUM FIELD LENGTH 255
		FIELD WORD WRAP OFF
		CONTROL NAME "Search String"

		CALL DialogControlArea(dgWidth, dgHeight, "Find@", "Cancel@", 0, 0)

		SELECT CONTROL "Cancel"
		UNIVERSAL SCRIPT "DG:do_find = NA()"
		DIALOG CANCEL PUSH BUTTON

		SELECT CONTROL "Find"
		UNIVERSAL SCRIPT
			"DEFINE fld_val",
			"fld_val = CTSTRING(1,0)",
			"DG:do_find = IF(LENGTH(fld_val) = 0,NA(),fld_val)"
		DIALOG DEFAULT PUSH BUTTON

	USE DIALOG BOX

	IF ISSTRING(do_find)
		UNIVERSAL RUN "@FIND HELP TEXT """ & DoubleQuoteIt(do_find) & """"
	END IF
END FUNCTION { FindInHelp }



FUNCTION DGGraphManip(ch)
		RUN "INVALIDATE ON"
		RUN "SELECT CHART " & CH
		RUN "ROTATION " & ROTATION()
		RUN "ELEVATION " & ELEVATION()
		RUN "DISTANCE " & PERSPECTIVE()
		RUN "3D WIDTH HEIGHT " & WTOHRATIO()
		RUN "3D DEPTH HEIGHT " & DTOHRATIO()
		RUN "INVALIDATE OFF"
END FUNCTION



FUNCTION DGPieExplode(n,s,x)
		RUN "INVALIDATE ON"
		RUN "SELECT CHART " & n & " SERIES " & (s + 1)
		RUN "SERIES PIE OFFSET " & x & " PERCENT"
		RUN "UNSELECT"
		RUN "INVALIDATE OFF"
END FUNCTION


FUNCTION DGFileError(prmpt,sel)
	DEFINE cw, w, a, b

	cw = 150
	w = LENGTH(prmpt) * cw

	IF w < 5000
		w = 5000
	ELSEIF w > 10000
		w = 10000
	END IF

	a = 0
	b = w

	IF w > 5000
		a = (w-5000) / 2
		b = b - a
	END IF

{1 2} CALL dgokcan(w,3000,a,2100,b,3000,"Error","DG:val1 = CTVALUE(3,0)")

{3} ADD RADIO BUTTON "@All Errors","@Total Errors" AT (w/2-2200,900) (w/2+2200,1500)
	RADIO BUTTON sel

{4} ADD TEXT prmpt AT (300,300) (w-300,800)
	NO LINE BORDER
	val1 = 0

	USE DIALOG BOX

	RETURN val1
END FUNCTION



FUNCTION getpaswrd()
	NEW MODAL DIALOG BOX NAMED "Password" AT (-1,-1)(3600,1540)

		ADD FIELD AT (180,180)+(3200,360)
		FIELD WORD WRAP OFF
		FIELD CHARACTER 63
		MAXIMUM FIELD LENGTH 15
		SHOW CONTROL NAME "Password@"
		CONTROL ALIAS "Passwrd"

		str1 = 0

		CALL DialogControlArea(3600,1540,"OK","Cancel",0,0)

		SELECT CONTROL "OK"
		DIALOG DEFAULT PUSH BUTTON
		UNIVERSAL SCRIPT "DG:str1 = CTSTRING(""Passwrd"",0)"

		SELECT CONTROL "Cancel"
		DIALOG CANCEL PUSH BUTTON

	USE DIALOG BOX

	RETURN str1
END FUNCTION



FUNCTION colpik(clr)
	DEFINE col

	SHOW COLOR MIXER DIALOG BOX INITIAL COLOR clr
	col = MIXEDCOLOR()

	IF col = -1
		colpikit = 0
		RETURN clr
	ELSE
		colpikit = 1
		RETURN col
	END IF
END FUNCTION



FUNCTION LinePik(linewidth)
	doit = 0

	NEW MODAL DIALOG BOX NAMED "Line Width" AT (-1,-1)(3800,1540)

		ADD NUMBER WHEEL AT (1000,180)+(1400,360)
		NUMBER WHEEL RANGE 0 TO 1638
		NUMBER WHEEL STEP 1
		NUMBER WHEEL PRECISION 2
		NUMBER WHEEL POSITION linewidth

		ADD TEXT "points" AT (2600,220)+(1000,300)
		NO LINE BORDER

		CALL DialogControlArea(3800,1540,"OK","Cancel",0,0)
		SELECT CONTROL "OK"
		DIALOG DEFAULT PUSH BUTTON
		UNIVERSAL SCRIPT
			"DG:doit = TRUE()",
			"DG:val1 = CTVALUE(1,0)"

		SELECT CONTROL "Cancel"
		DIALOG CANCEL PUSH BUTTON

		USE DIALOG BOX

		IF doit
		RETURN val1*20
	ELSE
		RETURN -1
		END IF
END FUNCTION



FUNCTION DGHelp(s)
	NEW MODAL DIALOG BOX NAMED s AT (-1,-1)(6700,5400)

	CALL DialogControlArea(6700, 5400, "OK@", "Cancel@", 0, 0)

	SELECT CONTROL "Cancel@"
	UNIVERSAL SCRIPT
		"DG:hpval = -1",
		"DG:doit = 0"
	DIALOG CANCEL PUSH BUTTON

	SELECT CONTROL "OK@"
	UNIVERSAL SCRIPT "DG:hpval = CTVALUE(""list_box"",0)"
	DIALOG DEFAULT PUSH BUTTON

	ADD LIST BOX " " at (300,300) (6400,4200)
	CONTROL ALIAS "list_box"
	UNIVERSAL SCRIPT
		"ON MOUSEDOUBLECLICK",
			"DG:hpval = CTVALUE(""list_box"",0)",
			"QUIT DIALOG BOX",
		"END MOUSEDOUBLECLICK"
	SHOW SCROLL BAR LIST BOX
	SHOW CONTROL TITLE s
END FUNCTION

FUNCTION DGHpval()
	USE DIALOG BOX

	RETURN HPVAL
END FUNCTION


FUNCTION ExitScript()
	{ this is called when the application is quitting }
END FUNCTION

FUNCTION RecordFile(name)
	{ this is called when the applications is SAVE RECORDED }
END FUNCTION
