'//////////////////////////////////////////////////////////////////////////////
'// Globals
'//////////////////////////////////////////////////////////////////////////////

Dim StartTime, EndTime, ElapsedTime


'//////////////////////////////////////////////////////////////////////////////
'// ScanFix Parameter Settings Procedures
'//////////////////////////////////////////////////////////////////////////////


''''''''''''''''''''''''''''''''''''''''''''''
Sub ShowSelectedFeature(strSelectedFeature)
    call setActiveFeatureButton(strSelectedFeature)

    'reset any selection made on the Cleanup Action queue
    selectedEnhancements.selectedIndex = -1
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Sub setActiveFeatureButton(strFeature)
	Dim strPushedButtonTextColor
	strPushedButtonTextColor = "yellow"
	
	'first, hide all feature divisions, and reset
	'the active button text colors
	call resetFeatureDivisions()
	'call resetFeatureButtons

	'show the ones we want now
	if (strFeature = BINARIZE) then
		DemoFeatureBinarize.style.display = "block"
	elseif (strFeature = DESKEW) then
		DemoFeatureDeskew.style.display = "block"		
	elseif (strFeature = DESPECKLE) then
		DemoFeatureDespeckle.style.display = "block"
	elseif (strFeature = DOT_SHADING) then
		DemoFeatureDotShade.style.display = "block"
	elseif (strFeature = BLOB_REMOVAL) then
		DemoFeatureRemoveBlobs.style.display = "block"
	elseif (strFeature = LINE_REMOVAL) then
		DemoFeatureLineRemoval.style.display = "block"
	elseif (strFeature = INVERSE_TEXT) then
		DemoFeatureInvertText.style.display = "block"	
	elseif (strFeature = SMOOTH_OBJECTS) then
		DemoFeatureSmoothObjects.style.display = "block"
	elseif (strFeature = BORDER_REMOVAL) then
		DemoFeatureAutoBorderCrop.style.display = "block"
	elseif (strFeature = BLANK_PAGE) then
		DemoFeatureBlankPageDetect.style.display = "block"
	elseif (strFeature = COMB_REMOVAL) then
		DemoFeatureCombRemoval.style.display = "block"
	elseif (strFeature = NEGATIVE_CORRECTION) then
		DemoFeatureNegate.style.display = "block"
	elseif (strFeature = REGISTRATION) then
		DemoFeatureImageRegistration.style.display = "block"
	end if
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
' This function will hide all of the feature
' divisions by setting display = "none".
' This is used as a precursor to a division
' change.
Sub resetFeatureDivisions
	DemoFeatureBinarize.style.display = "none"
	DemoFeatureDeskew.style.display = "none"
	DemoFeatureDespeckle.style.display = "none"
	DemoFeatureDotShade.style.display = "none"
	DemoFeatureRemoveBlobs.style.display = "none"
	DemoFeatureLineRemoval.style.display = "none"
	DemoFeatureInvertText.style.display = "none"
	DemoFeatureSmoothObjects.style.display = "none"
	DemoFeatureAutoBorderCrop.style.display = "none"
	DemoFeatureBlankPageDetect.style.display = "none"
	DemoFeatureCombRemoval.style.display = "none"
	DemoFeatureNegate.style.display = "none"
	DemoFeatureImageRegistration.style.display = "none"
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
' This function will set all of the feature
' buttons back to white text.
' This is used as a precursor to a division
' change, when the active button text color
' is set to yellow.
Sub resetFeatureButtons
	Dim strColor
	strColor = "black"
	cmdBinarize.style.color = strColor
	cmdDeskew.style.color = strColor
	cmdDespeckle.style.color = strColor
	cmdDotShadingRemoval.style.color = strColor
	cmdBlobRemoval.style.color = strColor
	cmdLineRemoval.style.color = strColor
	cmdTextCorrection.style.color = strColor
	cmdSmoothObjects.style.color = strColor
	cmdAutoBorderCrop.style.color = strColor
	cmdBlankPageDetect.style.color = strColor
	cmdCombRemoval.style.color = strColor
	cmdNegate.style.color = strColor
	cmdImageRegistration.style.color = strColor
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Sub resetDefaultParameterValues()
	'this will toggle all events of objects off
	parameterShouldUpdate = false

    'reset any selection on the cleanup queue
    selectedEnhancements.selectedIndex = -1

    chkBinarizeAuto.checked = true
    setBinarizeParameterVisibilty
	cboBinarizeBlur.selectedIndex = 0
	lblBinarizeHighThreshold.value = 0
	scrBinarizeHighThreshold = 0
	lblBinarizeLowThreshold.value = 0
	scrBinarizeLowThreshold = 0
	lblBinarizeLCEFactor.value = 0
	scrBinarizeLCEFactor = 0
	chkDeskewMaintainSize.checked = false
	cboDeskewPadColor.selectedIndex = 0
	lblDeskewMinConfidence.value = 50
	scrDeskewMinConfidence = 50
	txtDeskewMaxAcceptAngle.value = 0.2
	lblDespeckleSpeckHeight.value = 2
	scrDespeckleSpeckHeight = 2
	lblDespeckleSpeckWidth.value = 3
	scrDespeckleSpeckWidth = 3
	lblDotShadeMinAreaWidth.value = 300
	scrDotShadeMinAreaWidth = 300
	lblDotShadeMinAreaHeight.value = 50
	scrDotShadeMinAreaHeight = 50
	lblDotShadeVSizeAdjust.value = 0
	scrDotShadeVertSizeAdjust = 0
	lblDotShadeHSizeAdjust.value = 0
	scrDotShadeHorzSizeAdjust = 0
	lblDotShadeDensity.value = 0
	scrDotShadeDensity = 0
	lblDotShadeMaxDotSize.value = 5
	scrDotShadeMaxDotSize = 5
	lblRemoveBlobsAreaX.value = 0
	scrRemoveBlobsAreaX = 0
	lblRemoveBlobsAreaY.value = 0
	scrRemoveBlobsAreaY = 0
	lblRemoveBlobsAreaWidth.value = 0
	scrRemoveBlobsAreaWidth = 0
	lblRemoveBlobsAreaHeight.value = 0
	scrRemoveBlobsAreaHeight = 0
	lblRemoveBlobsMinPixelCount.value = 300
	scrRemoveBlobsMinPixelCount = 300
	lblRemoveBlobsMaxPixelCount.value = 9999 'max scroll bar value is 9999, control default is 10000
	scrRemoveBlobsMaxPixelCount = 9999
	lblRemoveBlobsMinDensity.value = 50
	scrRemoveBlobsMinDensity = 50
    lblRemoveCombsAreaX.value = 0
    scrRemoveCombsAreaX = 0
    lblRemoveCombsAreaY.value = 0
    scrRemoveCombsAreaY = 0
    lblRemoveCombsAreaWidth.value = 0
    scrRemoveCombsAreaWidth = 0
    lblRemoveCombsAreaHeight.value = 0
    scrRemoveCombsAreaHeight = 0
    lblRemoveCombsMinCombLength.value = 50
    scrRemoveCombsMinCombLength = 50
    lblRemoveCombsCombHeight.value = 20
    scrRemoveCombsCombHeight = 20
    lblRemoveCombsCombSpacing.value = 25
    scrRemoveCombsCombSpacing = 25
    lblRemoveCombsMinConfidence.value = 50
    scrRemoveCombsMinConfidence = 50
	lblLineMinLength.value = 50
	scrLineMinLength = 50
	lblLineMaxThickness.value = 20
	scrLineMaxThickness = 20
	txtLineMinAspect.value = 10
	lblLineMaxGap.value = 1
	scrLineMaxGap = 1
	lblLineMaxRepairSize.value = 20
	scrLineMaxRepairSize = 20
	chkNegateApplyCorrection.checked = true
	lblNegateMinConfidence.value = 50
	scrNegateMinConfidence = 50
	lblNegateQuality.value = 80
	scrNegateQuality = 80
    chkRmvBorderCropBorder.checked = true
    chkRmvBorderReplaceBorder.checked = false
    chkRmvBorderDeskewBorder.checked = true
    cboRmvBorderPadColor.selectedIndex = 0
    lblRmvBorderBorderSpeckSize.value = 3
    scrRmvBorderBorderSpeckSize = 3
    lblRmvBorderPageSpeckSize.value = 2
    scrRmvBorderPageSpeckSize = 2
    lblRmvBorderQuality.value = 80
    scrRmvBorderQuality = 80
    lblRmvBorderMinConfidence.value = 50
    scrRmvBorderMinConfidence = 50
	lblInvertTextMinAreaWidth.value = 300
	scrInvertTextMinAreaWidth = 300
	lblInvertTextMinAreaHeight.value = 50
	scrInvertTextMinAreaHeight = 50
	lblInvertTextMinBlackOnEdges.value = 10
	scrInvertTextMinBlackOnEdges = 10
	lblSmoothObjectsSize.value = 3
	scrSmoothObjectsSize = 3
	chkBlankPageIgnoreBorder.checked = false
	lblBlankPageTopMargin.value = 0
	scrBlankPageTopMargin = 0
	lblBlankPageLeftMargin.value = 0
	scrBlankPageLeftMargin = 0
	lblBlankPageBottomMargin.value = 0
	scrBlankPageBottomMargin = 0
	lblBlankPageRightMargin.value = 0
	scrBlankPageRightMargin = 0
	lblBlankPageMinObjectDim.value = 10
	scrBlankPageMinObjectDim = 10
	lblBlankPageGapFill.value = 5
	scrBlankPageGapFill = 5	
    chkRegistrationCentralFocus.checked = false
    chkRegistrationIgnoreHoles.checked = false
    chkRegistrationSkipActive.checked = false
    chkRegistrationLineActive.checked = false
    chkRegistrationThinLinesActive.checked = false
    chkRegistrationAddOnly.checked = false
    scrRegistrationMinimumActivity = 3
    lblRegistrationMinimumActivity.Value = 3
    scrRegistrationMinimumBackground = 5
    lblRegistrationMinimumBackground.Value = 5
    scrRegistrationMinimumForeground = 5
    lblRegistrationMinimumForeground.Value = 5
    scrRegistrationResultantMargin = 150
    lblRegistrationResultantMargin.Value = 150
    scrRegistrationSkipDistance = 300
    lblRegistrationSkipDistance.Value = 300
    scrRegistrationMaximumLineGap = 2
    lblRegistrationMaximumLineGap.Value = 2
    scrRegistrationMaximumLineThickness = 22
    lblRegistrationMaximumLineThickness.Value = 22
    scrRegistrationMinimumLineLength = 300
    lblRegistrationMinimumLineLength.Value = 300

	'this will toggle all event objects on
	parameterShouldUpdate = true
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
' The Binarize feature has the ability to use the AutoBinarize
' function or Binarize.  If the AutoBinarize checkbox is checked
' this function will disable the parameter setting.
Sub setBinarizeParameterVisibilty()
	'this will toggle all event objects off
	'parameterShouldUpdate = false

    If (chkBinarizeAuto.checked) Then
        cboBinarizeBlur.selectedIndex = 0
	    lblBinarizeHighThreshold.value = 0
	    scrBinarizeHighThreshold = 0
	    lblBinarizeLowThreshold.value = 0
	    scrBinarizeLowThreshold = 0
	    lblBinarizeLCEFactor.value = 0
	    scrBinarizeLCEFactor = 0
        cboBinarizeBlur.disabled = true
	    scrBinarizeHighThreshold.enabled = false
	    scrBinarizeLowThreshold.enabled = false
	    scrBinarizeLCEFactor.enabled = false
    Else
        cboBinarizeBlur.disabled = false
	    scrBinarizeHighThreshold.enabled = true
	    scrBinarizeLowThreshold.enabled = true
	    scrBinarizeLCEFactor.enabled = true
    End If

	'this will toggle all event objects on
	'parameterShouldUpdate = true
End Sub

'//////////////////////////////////////////////////////////////////////////////
'// Cleanup Actions Queue Procedures
'//////////////////////////////////////////////////////////////////////////////

''''''''''''''''''''''''''''''''''''''''''''''
' This function will add a single image
' enhancement selected by the user.
Sub addToQueue(strEnhancement, bUpdate)
	Dim strQueueEnhancement
	Dim numElements
    Dim iSelectedIndex

	if (strEnhancement = BINARIZE) then
		strQueueEnhancement = strEnhancement & _
			" #" & chkBinarizeAuto.checked & _
            " #" & cboBinarizeBlur.value & _
			" #" & scrBinarizeLowThreshold & _
			" #" & scrBinarizeHighThreshold & _
			" #" & scrBinarizeLCEFactor
	elseif (strEnhancement = NEGATIVE_CORRECTION) then
		strQueueEnhancement = strEnhancement & _
			" #" & chkNegateApplyCorrection.checked & _
			" #" & scrNegateMinConfidence & _
			" #" & scrNegateQuality
	elseif (strEnhancement = DESKEW) then
		strQueueEnhancement = strEnhancement & _
			" #" & chkDeskewMaintainSize.checked & _
			" #" & txtDeskewMaxAcceptAngle.value & _
			" #" & scrDeskewMinConfidence & _
			" #" & cboDeskewPadColor.selectedIndex
	elseif (strEnhancement = DESPECKLE) then
		strQueueEnhancement = strEnhancement & _
			" #" & scrDespeckleSpeckHeight & _
			" #" & scrDespeckleSpeckWidth
	elseif (strEnhancement = DOT_SHADING) then
		strQueueEnhancement = strEnhancement & _
			" #" & scrDotShadeMinAreaWidth & _
			" #" & scrDotShadeMinAreaHeight & _
			" #" & scrDotShadeVertSizeAdjust & _
			" #" & scrDotShadeHorzSizeAdjust & _
			" #" & scrDotShadeDensity & _
			" #" & scrDotShadeMaxDotSize
	elseif (strEnhancement = BLOB_REMOVAL) then
		strQueueEnhancement = strEnhancement & _
			" #" & scrRemoveBlobsAreaX & _
			" #" & scrRemoveBlobsAreaY & _
			" #" & scrRemoveBlobsAreaWidth & _
			" #" & scrRemoveBlobsAreaHeight & _
			" #" & scrRemoveBlobsMinPixelCount & _
			" #" & scrRemoveBlobsMaxPixelCount & _
			" #" & scrRemoveBlobsMinDensity
	elseif (strEnhancement = COMB_REMOVAL) then
		strQueueEnhancement = strEnhancement & _
			" #" & scrRemoveCombsAreaX & _
			" #" & scrRemoveCombsAreaY & _
			" #" & scrRemoveCombsAreaWidth & _
			" #" & scrRemoveCombsAreaHeight & _
			" #" & scrRemoveCombsMinCombLength & _
			" #" & scrRemoveCombsCombHeight & _
			" #" & scrRemoveCombsCombSpacing & _
			" #" & scrRemoveCombsMinConfidence
	elseif (strEnhancement = LINE_REMOVAL) then
		strQueueEnhancement = strEnhancement & _
			" #" & scrLineMinLength & _
			" #" & scrLineMaxThickness & _
			" #" & txtLineMinAspect.value & _
			" #" & scrLineMaxGap & _
			" #" & scrLineMaxRepairSize
	elseif (strEnhancement = INVERSE_TEXT) then
		strQueueEnhancement = strEnhancement & _
			" #" & scrInvertTextMinAreaWidth & _
			" #" & scrInvertTextMinAreaHeight & _
			" #" & scrInvertTextMinBlackOnEdges
	elseif (strEnhancement = BORDER_REMOVAL) then
		strQueueEnhancement = strEnhancement & _
			" #" & chkRmvBorderCropBorder.checked & _
            " #" & chkRmvBorderReplaceBorder.checked & _
            " #" & chkRmvBorderDeskewBorder.checked & _
            " #" & cboRmvBorderPadColor.selectedIndex & _
            " #" & scrRmvBorderBorderSpeckSize & _
            " #" & scrRmvBorderPageSpeckSize & _
            " #" & scrRmvBorderQuality & _
            " #" & scrRmvBorderMinConfidence
	elseif (strEnhancement = SMOOTH_OBJECTS) then
		strQueueEnhancement = strEnhancement & _
			" #" & scrSmoothObjectsSize
	elseif (strEnhancement = BLANK_PAGE) then
		strQueueEnhancement = strEnhancement & _
			" #" & chkBlankPageIgnoreBorder.checked & _
			" #" & scrBlankPageTopMargin & _
			" #" & scrBlankPageLeftMargin & _
			" #" & scrBlankPageBottomMargin & _
			" #" & scrBlankPageRightMargin & _
			" #" & scrBlankPageMinObjectDim & _
			" #" & scrBlankPageGapFill
	elseif (strEnhancement = REGISTRATION) then
		strQueueEnhancement = strEnhancement & _
            " #" & chkRegistrationCentralFocus.checked & _
            " #" & chkRegistrationIgnoreHoles.checked & _
            " #" & chkRegistrationSkipActive.checked & _
            " #" & chkRegistrationLineActive.checked & _
            " #" & chkRegistrationThinLinesActive.checked & _
            " #" & chkRegistrationAddOnly.checked & _
            " #" & scrRegistrationMinimumActivity & _
            " #" & scrRegistrationMinimumBackground & _
            " #" & scrRegistrationMinimumForeground & _
            " #" & scrRegistrationResultantMargin & _
            " #" & scrRegistrationSkipDistance & _
            " #" & scrRegistrationMaximumLineGap & _
            " #" & scrRegistrationMaximumLineThickness & _
            " #" & scrRegistrationMinimumLineLength
	end if

	'show the division which contains the select object
	EnhancementQueue.style.display = "block"

    'if bUpdate is true, it means that this function was called
    'from the change event of one of the parameter interfaces. if this
    'is the case, update the currently selected action in the cleanup
    'queue, instead of adding a new action
    if (bUpdate) then
        iSelectedIndex = selectedEnhancements.selectedIndex
        selectedEnhancements.options(iSelectedIndex).value = strQueueEnhancement
    else
        AddItemToSelectObject strEnhancement, strQueueEnhancement
    end if

End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Function QueueUpdateParms(strFeature)
	Dim selIndex
	Dim selLength
    if (parameterShouldUpdate) then
	    selLength = selectedEnhancements.length
	    if (selLength > 0) then
		    selIndex = selectedEnhancements.selectedIndex
            if (selIndex > -1) then
    		    if (selectedEnhancements.options(selIndex).text = strFeature) then
	    		    addToQueue strFeature, true
		        end if
            end if
	    end if
    end if
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function QueueShowParms(iSelIndex)
	Dim strEnhancement, strSettings

    strEnhancement = selectedEnhancements.options(iSelIndex).text
	strSettings = selectedEnhancements.options(iSelIndex).value

    'set the parameters
    QueueSetFeatureParms(strSettings)

    'show the division
	setActiveFeatureButton(strEnhancement)
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Sub QueueSetFeatureParms(strEnhancement)
On Error Resume Next

	Dim stringArray, strResults

	'this will toggle all event objects off
	parameterShouldUpdate = false

	'tokenize the hidden string to retrieve the parameter settings
	stringArray = Split(strEnhancement, "#")

	if (Trim(stringArray(0)) = BINARIZE) then
        chkBinarizeAuto.checked = CBool(Trim(stringArray(1)))
        call setBinarizeParameterVisibilty            
        cboBinarizeBlur.selectedIndex = CInt(Trim(stringArray(2)))
	    lblBinarizeHighThreshold.value = Trim(stringArray(4))
	    scrBinarizeHighThreshold = CInt(Trim(stringArray(4)))
	    lblBinarizeLowThreshold.value = Trim(stringArray(3))
	    scrBinarizeLowThreshold = CInt(Trim(stringArray(3)))
	    lblBinarizeLCEFactor.value = Trim(stringArray(5))
	    scrBinarizeLCEFactor = CInt(Trim(stringArray(5)))
	elseif (Trim(stringArray(0)) = DESKEW) then
        chkDeskewMaintainSize.checked = CBool(Trim(stringArray(1)))
	    txtDeskewMaxAcceptAngle.value = CDbl(Trim(stringArray(2)))
	    lblDeskewMinConfidence.value = Trim(stringArray(3))
	    scrDeskewMinConfidence = CInt(Trim(stringArray(3)))
	    cboDeskewPadColor.selectedIndex = Trim(stringArray(4))
	elseif (Trim(stringArray(0)) = DESPECKLE) then
	    lblDespeckleSpeckHeight.value = Trim(stringArray(1))
	    scrDespeckleSpeckHeight = CInt(Trim(stringArray(1)))
	    lblDespeckleSpeckWidth.value = Trim(stringArray(2))
	    scrDespeckleSpeckWidth = CInt(Trim(stringArray(2)))
	elseif (Trim(stringArray(0)) = DOT_SHADING) then
	    lblDotShadeMinAreaWidth.value = Trim(stringArray(1))
	    scrDotShadeMinAreaWidth = CInt(Trim(stringArray(1)))
	    lblDotShadeMinAreaHeight.value = Trim(stringArray(2))
	    scrDotShadeMinAreaHeight = CInt(Trim(stringArray(2)))
	    lblDotShadeVSizeAdjust.value = Trim(stringArray(3))
	    scrDotShadeVertSizeAdjust = CInt(Trim(stringArray(3)))
	    lblDotShadeHSizeAdjust.value = Trim(stringArray(4))
	    scrDotShadeHorzSizeAdjust = CInt(Trim(stringArray(4)))
	    lblDotShadeDensity.value = Trim(stringArray(5))
	    scrDotShadeDensity = CInt(Trim(stringArray(5)))
	    lblDotShadeMaxDotSize.value = Trim(stringArray(6))
	    scrDotShadeMaxDotSize = CInt(Trim(stringArray(6)))
	elseif (Trim(stringArray(0)) = BLOB_REMOVAL) then
	    lblRemoveBlobsAreaX.value = Trim(stringArray(1))
	    scrRemoveBlobsAreaX = CInt(Trim(stringArray(1)))
	    lblRemoveBlobsAreaY.value = Trim(stringArray(2))
	    scrRemoveBlobsAreaY = CInt(Trim(stringArray(2)))
	    lblRemoveBlobsAreaWidth.value = Trim(stringArray(3))
	    scrRemoveBlobsAreaWidth = CInt(Trim(stringArray(3)))
	    lblRemoveBlobsAreaHeight.value = Trim(stringArray(4))
	    scrRemoveBlobsAreaHeight = CInt(Trim(stringArray(4)))
	    lblRemoveBlobsMinPixelCount.value = Trim(stringArray(5))
	    scrRemoveBlobsMinPixelCount = CInt(Trim(stringArray(5)))
	    lblRemoveBlobsMaxPixelCount.value = Trim(stringArray(6))
	    scrRemoveBlobsMaxPixelCount = CInt(Trim(stringArray(6)))
	    lblRemoveBlobsMinDensity.value = Trim(stringArray(7))
	    scrRemoveBlobsMinDensity = CInt(Trim(stringArray(7)))
	elseif (Trim(stringArray(0)) = COMB_REMOVAL) then
	    lblRemoveCombsAreaX.value = Trim(stringArray(1))
	    scrRemoveCombsAreaX = CInt(Trim(stringArray(1)))
	    lblRemoveCombsAreaY.value = Trim(stringArray(2))
	    scrRemoveCombsAreaY = CInt(Trim(stringArray(2)))
	    lblRemoveCombsAreaWidth.value = Trim(stringArray(3))
	    scrRemoveCombsAreaWidth = CInt(Trim(stringArray(3)))
	    lblRemoveCombsAreaHeight.value = Trim(stringArray(4))
	    scrRemoveCombsAreaHeight = CInt(Trim(stringArray(4)))
	    lblRemoveCombsMinCombLength.value = Trim(stringArray(5))
	    scrRemoveCombsMinCombLength = CInt(Trim(stringArray(5)))
	    lblRemoveCombsCombHeight.value = Trim(stringArray(6))
	    scrRemoveCombsCombHeight = CInt(Trim(stringArray(6)))
        lblRemoveCombsCombSpacing.value = Trim(stringArray(7))
	    scrRemoveCombsCombSpacing = CInt(Trim(stringArray(7)))
	    lblRemoveCombsMinConfidence.value = Trim(stringArray(8))
	    scrRemoveCombsMinConfidence = CInt(Trim(stringArray(8)))	
    elseif (Trim(stringArray(0)) = LINE_REMOVAL) then
	    lblLineMinLength.value = Trim(stringArray(1))
	    scrLineMinLength = CInt(Trim(stringArray(1)))
	    lblLineMaxThickness.value = Trim(stringArray(2))
	    scrLineMaxThickness = CInt(Trim(stringArray(2)))
	    txtLineMinAspect.value = CDbl(Trim(stringArray(3)))
	    lblLineMaxGap.value = Trim(stringArray(4))
	    scrLineMaxGap = CInt(Trim(stringArray(4)))
	    lblLineMaxRepairSize.value = Trim(stringArray(5))
	    scrLineMaxRepairSize = CInt(Trim(stringArray(5)))
	elseif (Trim(stringArray(0)) = NEGATIVE_CORRECTION) then
	    chkNegateApplyCorrection.checked = CBool(Trim(stringArray(1)))
	    lblNegateMinConfidence.value = Trim(stringArray(2))
	    scrNegateMinConfidence = CInt(Trim(stringArray(2)))
	    lblNegateQuality.value = Trim(stringArray(3))
	    scrNegateQuality = CInt(Trim(stringArray(3)))
	elseif (Trim(stringArray(0)) = INVERSE_TEXT) then
	    lblInvertTextMinAreaWidth.value = Trim(stringArray(1))
	    scrInvertTextMinAreaWidth = CInt(Trim(stringArray(1)))
	    lblInvertTextMinAreaHeight.value = Trim(stringArray(2))
	    scrInvertTextMinAreaHeight = CInt(Trim(stringArray(2)))
	    lblInvertTextMinBlackOnEdges.value = Trim(stringArray(3))
	    scrInvertTextMinBlackOnEdges = CInt(Trim(stringArray(3)))
	elseif (Trim(stringArray(0)) = BORDER_REMOVAL) then
        chkRmvBorderCropBorder.checked = CBool(Trim(stringArray(1)))
        chkRmvBorderReplaceBorder.checked = CBool(Trim(stringArray(2)))
        chkRmvBorderDeskewBorder.checked = CBool(Trim(stringArray(3)))
        cboRmvBorderPadColor.selectedIndex = CInt(Trim(stringArray(4)))
        lblRmvBorderBorderSpeckSize.value = Trim(stringArray(5))
        scrRmvBorderBorderSpeckSize = CInt(Trim(stringArray(5)))
        lblRmvBorderPageSpeckSize.value = Trim(stringArray(6))
        scrRmvBorderPageSpeckSize = CInt(Trim(stringArray(6)))
        lblRmvBorderQuality.value = Trim(stringArray(7))
        scrRmvBorderQuality = CInt(Trim(stringArray(7)))
        lblRmvBorderMinConfidence.value = Trim(stringArray(8))
        scrRmvBorderMinConfidence = CInt(Trim(stringArray(8)))
	elseif (Trim(stringArray(0)) = SMOOTH_OBJECTS) then
	    lblSmoothObjectsSize.value = Trim(stringArray(1))
	    scrSmoothObjectsSize = CInt(Trim(stringArray(1)))
	elseif (Trim(stringArray(0)) = BLANK_PAGE) then
	    chkBlankPageIgnoreBorder.checked = CBool(Trim(stringArray(1)))
	    lblBlankPageTopMargin.value = Trim(stringArray(2))
	    scrBlankPageTopMargin = CInt(Trim(stringArray(2)))
	    lblBlankPageLeftMargin.value = Trim(stringArray(3))
	    scrBlankPageLeftMargin = CInt(Trim(stringArray(3)))
	    lblBlankPageBottomMargin.value = Trim(stringArray(4))
	    scrBlankPageBottomMargin = CInt(Trim(stringArray(4)))
	    lblBlankPageRightMargin.value = Trim(stringArray(5))
	    scrBlankPageRightMargin = CInt(Trim(stringArray(5)))
	    lblBlankPageMinObjectDim.value = Trim(stringArray(6))
	    scrBlankPageMinObjectDim = CInt(Trim(stringArray(6)))
	    lblBlankPageGapFill.value = Trim(stringArray(7))
	    scrBlankPageGapFill = CInt(Trim(stringArray(7)))
	elseif (Trim(stringArray(0)) = REGISTRATION) then
        chkRegistrationCentralFocus = CBool(Trim(stringArray(1)))
        chkRegistrationIgnoreHoles = CBool(Trim(stringArray(2)))
        chkRegistrationSkipActive = CBool(Trim(stringArray(3)))
        chkRegistrationLineActive = CBool(Trim(stringArray(4)))
        chkRegistrationThinLinesActive = CBool(Trim(stringArray(5)))
        chkRegistrationAddOnly = CBool(Trim(stringArray(6)))
        lblRegistrationMinimumActivity.value = Trim(stringArray(7))
        scrRegistrationMinimumActivity = CInt(Trim(stringArray(7)))
        lblRegistrationMinimumBackground.value = Trim(stringArray(8))
        scrRegistrationMinimumBackground = CInt(Trim(stringArray(8)))
        lblRegistrationMinimumForeground.value = Trim(stringArray(9))
        scrRegistrationMinimumForeground = CInt(Trim(stringArray(9)))
        lblRegistrationResultantMargin.value = Trim(stringArray(10))
        scrRegistrationResultantMargin = CInt(Trim(stringArray(10)))
        lblRegistrationSkipDistance.value = Trim(stringArray(11))
        scrRegistrationSkipDistance = CInt(Trim(stringArray(11)))
        lblRegistrationMaximumLineGap.value = Trim(stringArray(12))
        scrRegistrationMaximumLineGap = CInt(Trim(stringArray(12)))
        lblRegistrationMaximumLineThickness.value = Trim(stringArray(13))
        scrRegistrationMaximumLineThickness = CInt(Trim(stringArray(13)))
        lblRegistrationMinimumLineLength.value = Trim(stringArray(14))
        scrRegistrationMinimumLineLength = CInt(Trim(stringArray(14)))
	end if

	'this will toggle all event objects on
	parameterShouldUpdate = true
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Function QueueMoveUp()
	Dim sSelIndex, sSelValue, sSelText
	Dim sUpIndex, sUpValue, sUpText
	
	sSelIndex = selectedEnhancements.selectedIndex
	If (sSelIndex = 0 Or sSelIndex = -1) Then
		Exit Function
	End If
	
	'first, store the selected info
	sSelValue = selectedEnhancements.options(sSelIndex).value
	sSelText = selectedEnhancements.options(sSelIndex).text
	'next, store the info of the one-up index
	sUpIndex = sSelIndex - 1
	sUpValue = selectedEnhancements.options(sUpIndex).value
	sUpText = selectedEnhancements.options(sUpIndex).text
	
	'now swap the value and text info of the selected index and one-up index
	selectedEnhancements.options(sUpIndex).value = sSelValue
	selectedEnhancements.options(sUpIndex).text = sSelText
	selectedEnhancements.options(sSelIndex).value = sUpValue
	selectedEnhancements.options(sSelIndex).text = sUpText
	
	'reselect the selected index, now in its new location
	selectedEnhancements.selectedIndex = sUpIndex
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function QueueMoveDown()
	Dim sSelIndex, sSelValue, sSelText
	Dim sDownIndex, sDownValue, sDownText
	
	sSelIndex = selectedEnhancements.selectedIndex
	If ((sSelIndex = selectedEnhancements.length - 1) Or sSelIndex = -1) Then
		Exit Function
	End If
	
	'first, store the selected info
	sSelValue = selectedEnhancements.options(sSelIndex).value
	sSelText = selectedEnhancements.options(sSelIndex).text
	'next, store the info of the one-up index
	sDownIndex = sSelIndex + 1
	sDownValue = selectedEnhancements.options(sDownIndex).value
	sDownText = selectedEnhancements.options(sDownIndex).text
	
	'now swap the value and text info of the selected index and one-up index
	selectedEnhancements.options(sDownIndex).value = sSelValue
	selectedEnhancements.options(sDownIndex).text = sSelText
	selectedEnhancements.options(sSelIndex).value = sDownValue
	selectedEnhancements.options(sSelIndex).text = sDownText
	
	'reselect the selected index, now in its new location
	selectedEnhancements.selectedIndex = sDownIndex
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function QueueRemove()
	Dim sSelIndex, sCurrentLength, sNewLength
	Dim sDownValue, sDownText
	
	sSelIndex = selectedEnhancements.selectedIndex
	sCurrentLength = selectedEnhancements.length
	sNewLength = sCurrentLength - 1
	
	If (sSelIndex = -1) Then
		Exit Function
	End If
	
	'if there is more than one entry in the queue, this loop
	'will be run to move each of the entries up one index.
	'if there is only one entry, this loop will not run, and
	'the length assignment below the loop will take care of
	'removing the single entry
	For I = sSelIndex To sNewLength - 1
		'get the next value and text
		sDownValue = selectedEnhancements.options(I + 1).value
		sDownText = selectedEnhancements.options(I + 1).text
		'move them up
		selectedEnhancements.options(I).value = sDownValue
		selectedEnhancements.options(I).text = sDownText
	Next
	
	'remove the extra index
	selectedEnhancements.length = sNewLength

	sSelIndex = selectedEnhancements.selectedIndex
	sCurrentLength = selectedEnhancements.length

    'if there is an item still selected, show that
    If (sSelIndex > -1) Then
        QueueShowParms(sSelIndex)
    Elseif (sCurrentLength > 0) Then
        selectedEnhancements.selectedIndex = sCurrentLength - 1
        QueueShowParms(sCurrentLength - 1)
    End If
        
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function QueueDetails()
	Dim selIndex, selValue, selText, details
	
	selIndex = selectedEnhancements.selectedIndex
	If (selIndex = -1) Then
		Exit Function
	End If
	
	selValue = selectedEnhancements.options(selIndex).value
	selText = selectedEnhancements.options(selIndex).text
	
	details = QueueDetailsToString(selValue)
	
	call DisplayResults(details, "Cleanup Action Parameter Details")
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function QueueDetailsToString(strQueueString)
	Dim numParams
	Dim stringArray

	'tokenize the hidden string to retrieve the parameter settings
	stringArray = Split(strQueueString, "#")
			
	'get the number of parameters for the current enhancement
	numParams = UBound(stringArray)
		
	if (Trim(stringArray(0)) = BINARIZE) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"AutoBinarize: " & Trim(stringArray(1)) & vbCrLf & _
            "PreBlur Type: " & Trim(stringArray(2)) & vbCrLf & _
			"Low Threshold: " & Trim(stringArray(3)) & vbCrLf & _
			"High Threshold: " & Trim(stringArray(4)) & vbCrLf & _
			"Local Contrast Enhancement: " & Trim(stringArray(4))
	elseif (Trim(stringArray(0)) = DESKEW) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"Maintain Original Size: " & Trim(stringArray(1)) & vbCrLf & _
			"Max Acceptable Angle: " & Trim(stringArray(2)) & vbCrLf & _
			"Min Confidence: " & Trim(stringArray(3)) & vbCrLf & _
			"Pad Color: " & Trim(stringArray(4))
	elseif (Trim(stringArray(0)) = DESPECKLE) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"Speck Height: " & Trim(stringArray(1)) & vbCrLf & _
			"Speck Width: " & Trim(stringArray(2))
	elseif (Trim(stringArray(0)) = DESPECKLE) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"Min Area Width: " & Trim(stringArray(1)) & vbCrLf & _
			"Min Area Height: " & Trim(stringArray(2)) & vbCrLf & _
			"Vertical Size Adjustment: " & Trim(stringArray(3)) & vbCrLf & _
			"Horizontal Size Adjustment: " & Trim(stringArray(4)) & vbCrLf & _
			"Density: " & Trim(stringArray(5)) & vbCrLf & _
			"Max Dot Size: " & Trim(stringArray(6))
	elseif (Trim(stringArray(0)) = BLOB_REMOVAL) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"Area X-Coordinate: " & Trim(stringArray(1)) & vbCrLf & _
			"Area Y-Coordinate: " & Trim(stringArray(2)) & vbCrLf & _
			"Area Width: " & Trim(stringArray(3)) & vbCrLf & _
			"Area Height: " & Trim(stringArray(4)) & vbCrLf & _
			"Min Pixel Count: " & Trim(stringArray(5)) & vbCrLf & _
			"Max Pixel Count: " & Trim(stringArray(6)) & vbCrLf & _
			"Min Density: " & Trim(stringArray(7))
	elseif (Trim(stringArray(0)) = COMB_REMOVAL) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"Nothing"
	elseif (Trim(stringArray(0)) = LINE_REMOVAL) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"Min Length: " & Trim(stringArray(1)) & vbCrLf & _
			"Max Thickness: " & Trim(stringArray(2)) & vbCrLf & _
			"Min Aspect: " & Trim(stringArray(3)) & vbCrLf & _
			"Max Gap: " & Trim(stringArray(4)) & vbCrLf & _
			"Max Character Repair Size: " & Trim(stringArray(5))
	elseif (Trim(stringArray(0)) = NEGATIVE_CORRECTION) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"Apply Correction: " & Trim(stringArray(1)) & vbCrLf & _
			"Min Confidence: " & Trim(stringArray(2)) & vbCrLf & _
			"Quality: " & Trim(stringArray(3))
	elseif (Trim(stringArray(0)) = INVERSE_TEXT) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"Min Area Width: " & Trim(stringArray(1)) & vbCrLf & _
			"Min Area Height: " & Trim(stringArray(2)) & vbCrLf & _
			"Min Black On Edges: " & Trim(stringArray(3))
	elseif (Trim(stringArray(0)) = BORDER_REMOVAL) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"Nothing"
	elseif (Trim(stringArray(0)) = SMOOTH_OBJECTS) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"Object Size: " & Trim(stringArray(1))
	elseif (Trim(stringArray(0)) = BLANK_PAGE) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
			"Ignore Border: " & Trim(stringArray(1)) & vbCrLf & _
			"Top Margin: " & Trim(stringArray(2)) & vbCrLf & _
			"Left Margin: " & Trim(stringArray(3)) & vbCrLf & _
			"Bottom Margin: " & Trim(stringArray(4)) & vbCrLf & _
			"Right Margin: " & Trim(stringArray(5)) & vbCrLf & _
			"Min Object Dimension: " & Trim(stringArray(6)) & vbCrLf & _
			"Gap Fill: " & Trim(stringArray(7))
	elseif (Trim(stringArray(0)) = REGISTRATION) then
		QueueDetailsToString = Trim(stringArray(0)) & " Options: " & vbCrLf & _
		    "Central Focus: " & Trim(stringArray(1)) & vbCrLf & _
            "Ignore Holes: " & Trim(stringArray(2)) & vbCrLf & _
            "Skip Active: " & Trim(stringArray(3)) & vbCrLf & _
            "Line Active: " & Trim(stringArray(4)) & vbCrLf & _
            "Thin Lines Active: " & Trim(stringArray(5)) & vbCrLf & _
            "Add Only: " & Trim(stringArray(6)) & vbCrLf & _
            "Minimum Activity: " & Trim(stringArray(7)) & vbCrLf & _
            "Minimum Background: " & Trim(stringArray(8)) & vbCrLf & _
            "Minimum Foreground: " & Trim(stringArray(9)) & vbCrLf & _
            "Resultant Margin: " & Trim(stringArray(10)) & vbCrLf & _
            "Skip Distance: " & Trim(stringArray(11)) & vbCrLf & _
            "Maximum Line Gap: " & Trim(stringArray(12)) & vbCrLf & _
            "Maximum Line Thickness: " & Trim(stringArray(13)) & vbCrLf & _
            "Maximum Line Length: " & Trim(stringArray(14))
	end if

End Function


'//////////////////////////////////////////////////////////////////////////////
'// Load Image Procedures
'//////////////////////////////////////////////////////////////////////////////

''''''''''''''''''''''''''''''''''''''''''''''
Sub LoadSampleImage(strImageFileName, iSelectedIndex)
    Dim strSettings
    Dim strCurrentSettings
    Dim strAction
    Dim strActions
    Dim iNumActions

    On Error Resume Next

    'clear cleanup action queue
    selectedEnhancements.Length = 0

    'check valid index
    If (iSelectedIndex < 1 Or iSelectedIndex > cboSampleImages.Length) Then
        Exit Sub
    End If

	'load image into ImagXpress
    loadNewFile strImageFileName

    'subtract 1 since the combo box has a place holder in the 0-index
    strActions = sampleImageSettings(iSelectedIndex - 1)

	'tokenize the string to retrieve the action settings.
    'if an sample image has multiple cleanup actions, each action
    'string will be separated by "\"
	strSettings = Split(strActions, "\")
    
    'see how many actions there are. UBound returns the highest 0-based
    'subscript, so add 1 to that to get the actual number of actions.
    iNumActions = UBound(strSettings) + 1

    'add each action to the queue
    For I = 0 To iNumActions - 1
        'if there was only 1 action, strSettings will not be an array.
        'if there was more the 1 action, strSettings will contain an
        'array of substrings.
        If (iNumFeatures = 1) Then
            strCurrentSettings = strSettings
        Else
            strCurrentSettings = strSettings(I)
        End If

	    'tokenize the string to retrieve the parameter settings
	    strAction = Split(strCurrentSettings, "#")

        'insert the default cleanup actions for the selected sample image
        AddItemToSelectObject Trim(strAction(0)), strCurrentSettings
    Next

    If Not (CheckForRuntimeError(errNum, errMsg)) Then
        'select the action and show parms
        selectedEnhancements.selectedIndex = 0        
        QueueShowParms(0)
    End If
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
' UPDATE THE IMAGE WITH THE SPECIFIED FILENAME 
sub loadNewFile(newFileName)
	' "INIT" EQUATES TO THE "SELECT FROM STOCK IMAGES" SELECTION
	if (newFileName <> "INIT") then
		currentFileName = newFileName
		LoadCurrentFile 1
	end if

end sub

const idleTimeout = 15  ' Number of seconds before a load will timeout

''''''''''''''''''''''''''''''''''''''''''''''
' UPDATE THE IMAGE WITH WHAT IS SPECIFIED IN THE FILENAME GLOBAL
sub LoadCurrentFile(pageNo)
	dim idleCount
	dim fName
	dim Time1, Time2
	dim bCancel

	on error resume next

	IX8.PageNbr = pageNo
	CurrentPage = pageNo
	IX8.Autosize = 4
	IX8.Async = false
	IX8.Notify = true

	' CLEAR THE IMAGE BUFFER
	IX8.FileName = ""
	IXPreview.FileName = ""

	' Make sure the control has a chance to clear
	while (IX8.Idle = false)
		WScript.Sleep 100
	wend
		
	' Stop window from drawing until later
	bCancel = false
	'IX8.ViewUpdate = false
	
	' LOAD OR RELOAD THE FILE
	fName = conditionallyPrependPath(currentFileName)
	IX8.FileName = fName

	' Make sure the image loads, before going forward
	window.status = "Loading image:  " & fName
	'Time1 = Time()
	'do while (IX8.Idle = false and IX8.ImagError = 0)
	'	WScript.Sleep 100
	'	if (not bCancel) then
	'		Time2 = Time()
	'		if (clng(datediff("s", Time1, Time2)) >= idleTimeout) then
	'			bCancel = true
	'			IX8.Cancel IX8.ViewImageID
	'			window.status = ""
	'		end if
	'	end if
	'loop
	window.status = ""	

	' Check for an error loading the image	
	if (IX8.imagError <> 0) then
		IX8.ViewUpdate = true

		if (imagError = -8) then
			msgbox "The image is not currently available, please try again later", vbinformation, "ImagXpress Load"
		else
			msgbox errString(IX8.imagError), vbinformation, "ImagXpress Load"
		end if

		if (fName <> defaultFileName) Then
			loadNewFile defaultFileName
			if (IX8.imagError <> 0) then
				exit sub
			end if
		End If
	Else
        lblIXOriginalStatus.value = "Image Loaded: " & StripPath(IX8.FileName)
    End If

	' Turn the view update back on	
	'IX8.ViewUpdate = true

	window.status = ""

end sub

''''''''''''''''''''''''''''''''''''''''''''''''''''
function conditionallyPrependPath(baseName)
	dim l, m, path

	if (mid(baseName,1,2) <> "##") then
	
		' ALL STOCK SAMPLE IMAGE DROP-DOWN-LIST ENTRIES
		' START WITH A '##' SO ANYTHING ELSE IS A FILE
		' THE USER SELECTED FROM 'OPEN-FILE...'
		conditionallyPrependPath = baseName
	else
		
		' IF THERE IS NO WEB KEY THEN WE ARE RUNNING
		' LOCALLY AND WE MUST GET THE FILE FROM THE 
		' RELATIVE PATH DIRECTORY
		if (IXWebKey = "") then
	
			' THE PATH WILL BE SOMETHING LIKE "FILE:///C:/DEV/JUNK/WEB DEMO/IX8Demo.htm"
			' START BY FINDING THE ":" AFTER THE DRIVE LETTER
			l = InStrRev(window.location, ":")

			' INCLUDE THE DRIVE LETTER
			l = l - 1

			' FIND THE FINAL SLASH
			m = InStrRev(window.location, "/")

			' SNIP THAT OUT
			path = mid(window.location, l, m - l)

			' REPLACE ANY SPACE -> %20 CONVERSIONS THAT WINDOWS DOES
			path = replace(path, "%20", " ", 1, -1)

			' REPLACE ANY "/" CHARS WITH THE LOCAL WINDOWS EQUIVALENT "\"
			path = replace(path, "/", "\", 1, -1)

			' BUILD THE PATH TO THE LOCAL MACHINE
			conditionallyPrependPath = path & "\samples\" & mid(baseName,3)
		else
			' IF THERE IS A WEB KEY THEN WE ARE CURRENTLY
			' RUNNING OFF THE WEB SO WE CAN LOOK TO THE WEB
			' FOR SAMPLE FILES

            ' FIND THE FINAL SLASH
            'msgbox window.location
			'm = InStrRev(window.location, "/")

            ' SNIP THAT OUT
			'path = mid(window.location, 1, m)

            'conditionallyPrependPath = path & "/samples/" & mid(baseName,3)

			'TODO: Remove the testing path, and replace with live path on release
			'conditionallyPrependPath = "http://pegasusi.temp.veriohosting.com/scanfixdemo/samples/" & mid(baseName,3)
			
            conditionallyPrependPath = "http://www.pegasusimaging.com/demos/scanfixdemo/samples/" & mid(baseName,3)
            'conditionallyPrependPath = "http://chrisgtest/scanfixdemo3/samples/" & mid(baseName,3)
		end if
	end if

end function

''''''''''''''''''''''''''''''''''''''''''''''
Function StripPath(sFullPath)
    Dim iPos
    
    iPos = InStrRev(sFullPath, "/")
    If (iPos = 0) Then
        'if / wasn't found, try \, since this could be called from SaveFile,
        'which means we're saving on a local machine
        iPos = InStrRev(sFullPath, "\")
    End If
    StripPath = Right(sFullPath, Len(sFullPath) - iPos)
End Function


'//////////////////////////////////////////////////////////////////////////////
'// ImagXpress Viewing Toolbar Procedures
'//////////////////////////////////////////////////////////////////////////////

''''''''''''''''''''''''''''''''''''''''''''''
Sub SetIXOriginalMouseTool(strTool)
On Error Resume Next
    'reset mouse pointer (set by Ruler)
    IX8.MousePointer = 0
    DisableIXOriginalRulerTool

	If (strTool = "Arrow") Then
		IX8.ToolSet 0, 1, 0
	ElseIf (strTool = "ZoomIn") Then
		IX8.ToolSet 1, 1, 0
	ElseIf (strTool = "ZoomOut") Then
		IX8.ToolSet 2, 1, 0
	ElseIf (strTool = "ZoomRect") Then
		IX8.ToolSet 3, 1, 0
	ElseIf (strTool = "Hand") Then
		IX8.ToolSet 4, 1, 0
	ElseIf (strTool = "Magnify") Then
		IX8.ToolSet 5, 1, 0
	ElseIf (strTool = "Refresh") Then
		IX8.AutoSize = 4
		'see if sync is enabled, if so, refresh original image too
		If (toolbarSyncIXOriginal = true) Then
			IXPreview.AutoSize = 4
		End If
    ElseIf (strTool = "Ruler") Then
        'first, set IX tool back to standard pointer
        IX8.ToolSet 0, 1, 0
        'then, enable the NX ruler annotation
        EnableIXOriginalRulerTool
	End If
	
	If IX8.ImagError <> 0 Then
		call DisplayResults("ImagXpress Error: " & IX8.ImagError & " Description: " & ErrString(IX8.ImagError), "Error")
	End If

    lblIXOriginalStatus.value = "Toolbar Option Selected: " & strTool
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Sub SetIXPreviewMouseTool(strTool)
On Error Resume Next

	If (strTool = "Arrow") Then
		IXPreview.ToolSet 0, 1, 0
	ElseIf (strTool = "ZoomIn") Then
		IXPreview.ToolSet 1, 1, 0
	ElseIf (strTool = "ZoomOut") Then
		IXPreview.ToolSet 2, 1, 0
	ElseIf (strTool = "ZoomRect") Then
		IXPreview.ToolSet 3, 1, 0
	ElseIf (strTool = "Hand") Then
		IXPreview.ToolSet 4, 1, 0
	ElseIf (strTool = "Magnify") Then
		IXPreview.ToolSet 5, 1, 0
	ElseIf (strTool = "Refresh") Then
		IXPreview.AutoSize = 4
		'see if sync is enabled, if so, refresh original image too
		If (toolbarSyncIXPreview = true) Then
			IX8.AutoSize = 4
		End If
	End If
	
	If IXPreview.ImagError <> 0 Then
		call DisplayResults("ImagXpress Error: " & IXPreview.ImagError & " Description: " & ErrString(IXPreview.ImagError), "Error")
	End If

    lblIXPreviewStatus.value = "Toolbar Option Selected: " & strTool
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Sub SetIXOriginalViewSync()
	'check if sync is on
	If (toolbarSyncIXOriginal = true) Then
		toolbarSyncIXOriginal = false
		document.IXOriginalToolbarSync.src ="images/syncix.bmp"
	else
		toolbarSyncIXOriginal = true
		document.IXOriginalToolbarSync.src ="images/syncixPushed.bmp"
		'if original is at full-image, do the same to the preview.
		'else, sync the zoom/scroll
		If (IX8.AutoSize = 4) Then
			IXPreview.AutoSize = 4
		Else
			UpdateIXPreviewSync()
		End If
	End If		
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Sub SetIXPreviewViewSync()
	'check if sync is on
	If (toolbarSyncIXPreview = true) Then
		toolbarSyncIXPreview = false
		document.IXPreviewToolbarSync.src ="images/syncix.bmp"
	else
		toolbarSyncIXPreview = true
		document.IXPreviewToolbarSync.src ="images/syncixPushed.bmp"
		'if preview is at full-image, do the same to the original.
		'else, sync the zoom/scroll
		If (IXPreview.AutoSize = 4) Then
			IX8.AutoSize = 4
		Else
			UpdateIXOriginalSync()
		End If
	End If		
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Sub UpdateIXOriginalSync()
	If (IX8.AutoSize <> 5) Then 
		IX8.AutoSize = 5
	End If
	IX8.Zoom (IXPreview.ZoomFactor)
	IX8.ScrollX = IXPreview.ScrollX
	IX8.ScrollY = IXPreview.ScrollY
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Sub UpdateIXPreviewSync()
	If (IXPreview.AutoSize <> 5) Then 
		IXPreview.AutoSize = 5
	End If
	IXPreview.ZoomFactor = IX8.ZoomFactor
	IXPreview.ScrollX = IX8.ScrollX
	IXPreview.ScrollY = IX8.ScrollY
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Sub EnableIXOriginalRulerTool
    If (IX8.hDib = 0) Then
        Exit Sub
    End If

    'clear all existing layers
    NX8.Clear
    
    NX8.SetToolDefaultAttribute 4107, 2112, true ' show abbreviation    
    NX8.SetToolDefaultAttribute 4107, 2113, 2061 ' measurement choice: pixels
    NX8.SetToolDefaultAttribute 4107, 2114, true ' show length    
    NX8.SetToolDefaultAttribute 4107, 2115, 30 ' gauge length
    NX8.SetToolDefaultAttribute 4107, 2116, 0 ' whole number precision
    
    NX8.SetMeasureAbbr 2061, ""
    NX8.DefaultRulerFont.Name = "Arial"
    NX8.DefaultRulerFont.Size = 18
    NX8.DefaultTextColor = RGB(0,0,255)
    curLayer = NX8.CreateLayer
	NX8.SetPenWidth curLayer, 4107, 1     
    IX8.MousePointer = 2
    
    NX8.ToolbarSetTool curLayer, 4107
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Sub DisableIXOriginalRulerTool
    'clear all existing layers
    NX8.Clear
End Sub


'//////////////////////////////////////////////////////////////////////////////
'// ScanFix Image Processing Procedures
'//////////////////////////////////////////////////////////////////////////////

''''''''''''''''''''''''''''''''''''''''''''''
Sub processImage()
On Error Resume Next

	Dim I, J, K
	Dim numElements, numParams
	Dim stringArray, strResults

	'get the number of user-selected enhancements
	numElements = selectedEnhancements.length
    If (numElements < 1) Then
        MsgBox "Error: No Cleanup Actions Selected.", vbOkOnly, "Process Error"
		Exit Sub
    End If

	'reset the IX controls
	IX8.AutoSize = 4
	IXPreview.hDib = 0
	IXPreview.AutoSize = 4

    StartTime = 0
    EndTime = 0
    ElapsedTime = 0

	sf1.FromHdib(IX8.CopyDib)
	If (CheckForRuntimeError(Err.number, Err.Description)) Then
		Exit Sub
	End If

	window.status = "Processing Cleanup Actions..."

	'for each select enhancement...
	For I = 0 To numElements - 1
	

		'tokenize the hidden string to retrieve the parameter settings
		stringArray = Split(selectedEnhancements.options(I).value, "#")
				
		'get the number of parameters for the current enhancement
		numParams = UBound(stringArray)
		
		window.status = window.status & ".."		
		
		if (Trim(stringArray(0)) = BINARIZE) then
			strResults = strResults & ScanFixBinarize(Trim(stringArray(1)), Trim(stringArray(2)), Trim(stringArray(3)), Trim(stringArray(4)), Trim(stringArray(5)))
		elseif (Trim(stringArray(0)) = DESKEW) then
			strResults = strResults & _ 
			ScanFixDeskew(Trim(stringArray(1)), Trim(stringArray(2)), Trim(stringArray(3)), Trim(stringArray(4)))
		elseif (Trim(stringArray(0)) = DESPECKLE) then
			strResults = strResults & _ 
			ScanFixDespeckle(Trim(stringArray(1)), Trim(stringArray(2)))
		elseif (Trim(stringArray(0)) = DOT_SHADING) then
			strResults = strResults & _ 
			ScanFixDotShadingRemoval(Trim(stringArray(1)), Trim(stringArray(2)), Trim(stringArray(3)), Trim(stringArray(4)), Trim(stringArray(5)), Trim(stringArray(6)))
		elseif (Trim(stringArray(0)) = BLOB_REMOVAL) then
			strResults = strResults & _ 
			ScanFixBlobRemoval(Trim(stringArray(1)), Trim(stringArray(2)), Trim(stringArray(3)), Trim(stringArray(4)), Trim(stringArray(5)), Trim(stringArray(6)), Trim(stringArray(7)))
		elseif (Trim(stringArray(0)) = COMB_REMOVAL) then
			strResults = strResults & _ 
			ScanFixCombRemoval(Trim(stringArray(1)), Trim(stringArray(2)), Trim(stringArray(3)), Trim(stringArray(4)), Trim(stringArray(5)), Trim(stringArray(6)), Trim(stringArray(7)), Trim(stringArray(8)))
		elseif (Trim(stringArray(0)) = LINE_REMOVAL) then
			strResults = strResults & _ 
			ScanFixLineRemoval(Trim(stringArray(1)), Trim(stringArray(2)), Trim(stringArray(3)), Trim(stringArray(4)), Trim(stringArray(5)))
		elseif (Trim(stringArray(0)) = NEGATIVE_CORRECTION) then
			strResults = strResults & _ 
			ScanFixNegativeCorrection(Trim(stringArray(1)), Trim(stringArray(2)), Trim(stringArray(3)))
		elseif (Trim(stringArray(0)) = INVERSE_TEXT) then
			strResults = strResults & _ 
			ScanFixTextCorrection(Trim(stringArray(1)), Trim(stringArray(2)), Trim(stringArray(3)))
		elseif (Trim(stringArray(0)) = BORDER_REMOVAL) then
			strResults = strResults & _ 
			ScanFixAutoBorderCrop(Trim(stringArray(1)), Trim(stringArray(2)), Trim(stringArray(3)), Trim(stringArray(4)), Trim(stringArray(5)), Trim(stringArray(6)), Trim(stringArray(7)), Trim(stringArray(8)))
		elseif (Trim(stringArray(0)) = SMOOTH_OBJECTS) then
			strResults = strResults & _ 
			ScanFixSmoothing(Trim(stringArray(1)))
		elseif (Trim(stringArray(0)) = BLANK_PAGE) then
			strResults = strResults & _ 
			ScanFixBlankPageDetect(Trim(stringArray(1)), Trim(stringArray(2)), Trim(stringArray(3)), Trim(stringArray(4)), Trim(stringArray(5)), Trim(stringArray(6)), Trim(stringArray(7)))	
		elseif (Trim(stringArray(0)) = REGISTRATION) then
			strResults = strResults & _
			ScanFixImageRegistration(Trim(stringArray(1)), Trim(stringArray(2)), Trim(stringArray(3)), Trim(stringArray(4)), Trim(stringArray(5)), Trim(stringArray(6)), Trim(stringArray(7)), Trim(stringArray(8)), Trim(stringArray(9)), Trim(stringArray(10)), Trim(stringArray(11)), Trim(stringArray(12)), Trim(stringArray(13)), Trim(stringArray(14)) )
		end if
	Next

	IXPreview.hDIB = sf1.ToHdib(true)			
	
	MsgBox strResults, vbOKOnly, "Cleanup Action Results"
	
	window.status = ""
End Sub

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixBinarize(bAutoBinarize, iPreBlur, iLoThresh, iHiThresh, iLceFactor)
On Error Resume Next
	Dim strResults

    If (CBool(bAutoBinarize)) Then
        StartTime = Timer()
        sf1.AutoBinarize
        EndTime = Timer()
    Else
	    Set options = CreateObject("PegasusImaging.ScanFix5.BinarizeOpts")
	    If (Err.Number <> 0) Then
		    strResults = "Runtime error during Binarization process." & vbCrLf & _
			    "Error Number: " & Err.Number & vbCrLf & _
			    "Error Description: " & Err.Description & vbCrLf & vbCrLf
		    Err.Clear
		    ScanFixBinarize = strResults
		    Exit Function
	    End If
    	
	    options.preBlurType = CInt(iPreBlur)
	    options.lowThreshold = CLng(iLoThresh)
	    options.highThreshold = CLng(iHiThresh)
	    options.lceFactor = CLng(iLceFactor)
    	
        StartTime = Timer()
	    sf1.Binarize(options)
        EndTime = Timer()
    End If

	If (sf1.ErrorNumber = 0) Then
        ElapsedTime = EndTime - StartTime
		strResults = "Binarization completed successfully in " & ElapsedTime & " seconds." & vbCrLf & vbCrLf
	Else
		strResults = "ScanFix error during Binarization process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF

	ScanFixBinarize = strResults
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixDeskew(bMaintainSize, iMaxAngle, iMinConfidence, cPadColor)
On Error Resume Next
	Dim strResults
	
	Set options = CreateObject("PegasusImaging.ActiveX.ScanFix.5.DeskewOpt")
	If (Err.Number <> 0) Then
		strResults = "Runtime error during Deskew process." & vbCrLf & _
			"Error Number: " & Err.Number & vbCrLf & _
			"Error Description: " & Err.Description & vbCrLf & vbCrLf
		Err.Clear
		ScanFixDeskew = strResults
		Exit Function
	End If

	options.maintainOriginalSize = CBool(bMaintainSize)
	if (cPadColor = 0) then
		options.padColor = vbWhite
	else
		options.padColor = vbBlack
	end if
	options.minimumConfidence = CLng(iMinConfidence)
	options.maximumAcceptableAngle = CDbl(iMaxAngle)

    StartTime = Timer()
	Set results = sf1.Deskew(options)
	EndTime = Timer()

	If (sf1.ErrorNumber = 0) Then
        ElapsedTime = EndTime - StartTime

		strResults = "Deskew completed successfully in " & ElapsedTime & " seconds." & vbCrLf & _
			"    Deskew Results: " & vbCrLf & _
			"    - Confidence: " & results.confidence & vbCrLf & _
			"    - Image Was Modified: " & results.imageWasModified & vbCrLf & _
			"    - Rotation Angle: " & results.rotationAngle & vbCrLf & _
			"    - Variation: " & results.variation & vbCrLf & vbCrLf
	Else
		strResults = "ScanFix error during Deskew process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF

	ScanFixDeskew = strResults
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixDespeckle(iSpeckHeight, iSpeckWidth)
On Error Resume Next
	Dim strResults
	
	Set options = CreateObject("PegasusImaging.ActiveX.ScanFix.5.Despeckle")
	If (Err.Number <> 0) Then
		strResults = "Runtime error during Despeckle process." & vbCrLf & _
			"Error Number: " & Err.Number & vbCrLf & _
			"Error Description: " & Err.Description & vbCrLf & vbCrLf
		Err.Clear
		ScanFixDespeckle = strResults
		Exit Function
	End If

	options.speckHeight = CLng(iSpeckHeight)
	options.speckWidth = CLng(iSpeckWidth)

		
	sf1.Despeckle(options)
	
	If (sf1.ErrorNumber = 0) Then
		strResults = "Despeckle completed successfully." & vbCrLf & vbCrLf
	Else
		strResults = "ScanFix error during Despeckle process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF

	ScanFixDespeckle = strResults
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixDotShadingRemoval(iMinAreaWidth, iMinAreaHeight, iVertAdjust, iHorizAdjust, iDotDensity, iMaxDotSize)
On Error Resume Next
	Dim strResults
	
	Set options = CreateObject("PegasusImaging.ScanFix5.DotShadeRmOpt")
	If (Err.Number <> 0) Then
		strResults = "Runtime error during Dot Shading Removal process." & vbCrLf & _
			"Error Number: " & Err.Number & vbCrLf & _
			"Error Description: " & Err.Description & vbCrLf & vbCrLf
		Err.Clear
		ScanFixDotShadingRemoval = strResults
		Exit Function
	End If

	options.minimumAreaWidth = CLng(iMinAreaWidth)
    options.minimumAreaHeight = CLng(iMinAreaHeight)
    options.horizontalSizeAdjustment = CLng(iHorizAdjust)
    options.verticalSizeAdjustment = CLng(iVertAdjust)
    options.maximumDotSize = CLng(iMaxDotSize)
    options.densityAdjustment = CLng(iDotDensity)

	Set results = sf1.RemoveDotShading(options)
	
	If (sf1.ErrorNumber = 0) Then
		strResults = "Dot Shading Removal completed successfully." & vbCrLf & _
			"Dot Shading Removal Results: " & vbCrLf & _
			"- Count of Areas Found: " & results.countOfAreasFound & vbCrLf & _
			"- Image Was Modified: " & results.imageWasModified & vbCrLf & vbCrLf
	Else
		strResults = "ScanFix error during Dot Shading Removal process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF

	ScanFixDotShadingRemoval = strResults
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixBlobRemoval(iX, iY, iWidth, iHeight, iMinPixelCount, iMaxPixelCount, iMinDensity)
On Error Resume Next
	Dim strResults
	
	Set options = CreateObject("PegasusImaging.ScanFix5.BlobRemoveOpt")
	If (Err.Number <> 0) Then
		strResults = "Runtime error during Blob Removal process." & vbCrLf & _
			"Error Number: " & Err.Number & vbCrLf & _
			"Error Description: " & Err.Description & vbCrLf & vbCrLf
		Err.Clear
		ScanFixBlobRemoval = strResults
		Exit Function
	End If

	options.areaX = CLng(iX)
	options.areaY = CLng(iY)
	options.areaWidth = CLng(iWidth)
	options.areaHeight = CLng(iHeight)
	options.minimumPixelCount = CLng(iMinPixelCount)
	options.maximumPixelCount = CLng(iMaxPixelCount)
	options.minimumDensity = CLng(iMinDensity)

	Set results = sf1.RemoveBlobs(options)
	
	If (sf1.ErrorNumber = 0) Then
		strResults = "Blob Removal completed successfully." & vbCrLf & _
			"Blob Removal Results: " & vbCrLf & _
			"- Count of Blobs Found: " & results.countOfBlobsFound & vbCrLf & _
			"- Image Was Modified: " & results.imageWasModified & vbCrLf & vbCrLf
	Else
		strResults = "ScanFix error during Blob Removal process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF

	ScanFixBlobRemoval = strResults
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixCombRemoval(iX, iY, iWidth, iHeight, iMinCombLength, iCombHeight, iCombSpacing, iMinConfidence)
On Error Resume Next

	Set options = CreateObject("PegasusImaging.ScanFix5.CombRemoveOpt")
	If (Err.Number <> 0) Then
		strResults = "Runtime error during Comb Removal process." & vbCrLf & _
			"Error Number: " & Err.Number & vbCrLf & _
			"Error Description: " & Err.Description & vbCrLf & vbCrLf
		Err.Clear
		ScanFixCombRemoval = strResults
		Exit Function
	End If
    
	options.areaX = CLng(iX)
	options.areaY = CLng(iY)
	options.areaWidth = CLng(iWidth)
	options.areaHeight = CLng(iHeight)
    options.minimumCombLength = CLng(iMinCombLength)
    options.combHeight = CLng(iCombHeight)
    options.combSpacing = CLng(iCombSpacing)
    options.minimumConfidence = CLng(iMinConfidence)

	Set results = sf1.RemoveCombs(options)
	
	If (sf1.ErrorNumber = 0) Then
		strResults = "Comb Removal completed successfully." & vbCrLf & _
			"Comb Removal Results: " & vbCrLf & _
			"- Count of Combs Found: " & results.countOfCombsFound & vbCrLf & _
			"- Image Was Modified: " & results.imageWasModified & vbCrLf & vbCrLf
	Else
		strResults = "ScanFix error during Comb Removal process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF

	ScanFixCombRemoval = strResults

End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixLineRemoval(iMinLength, iMaxThickness, iMinAspect, iMaxGap, iMaxRepairSize)
On Error Resume Next
	Dim strResults
	
	Set options = CreateObject("PegasusImaging.ActiveX.ScanFix.5.LineRemov")
	If (Err.Number <> 0) Then
		strResults = "Runtime error during Line Removal process." & vbCrLf & _
			"Error Number: " & Err.Number & vbCrLf & _
			"Error Description: " & Err.Description & vbCrLf & vbCrLf
		Err.Clear
		ScanFixLineRemoval = strResults
		Exit Function
	End If

    options.minimumLength = CLng(iMinLength)
    options.maximumThickness = CLng(iMaxThickness)
    options.minimumAspectRatio = CLng(iMinAspect)
    options.maximumGap = CLng(iMaxGap)
    options.maximumCharacterRepairSize = CLng(iMaxRepairSize)

	Set results = sf1.RemoveLines(options)
	
	If (sf1.ErrorNumber = 0) Then
		strResults = "Line Removal completed successfully." & vbCrLf & _
			"Line Removal Results: " & vbCrLf & _
			"- Count of Lines Found: " & results.countOfLinesFound & vbCrLf & _
			"- Image Was Modified: " & results.imageWasModified & vbCrLf & vbCrLf
	Else
		strResults = "ScanFix error during Line Removal process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF

	ScanFixLineRemoval = strResults
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixNegativeCorrection(bApplyCorrection, iMinConfidence, iQuality)
On Error Resume Next
	Dim strResults
	
	Set options = CreateObject("PegasusImaging.ScanFix5.NegativeCrOpt")
  	If (Err.Number <> 0) Then
		strResults = "Runtime error during Negative Correction process." & vbCrLf & _
			"Error Number: " & Err.Number & vbCrLf & _
			"Error Description: " & Err.Description & vbCrLf & vbCrLf
		Err.Clear
		ScanFixNegativeCorrection = strResults
		Exit Function
	End If

    options.applyCorrection = CBool(bApplyCorrection)
    options.minimumConfidence = CLng(iMinConfidence)
    options.quality = CLng(iQuality)

	Set results = sf1.CorrectNegativePage(options)
	
	If (sf1.ErrorNumber = 0) Then
		strResults = "Negative Correction completed successfully." & vbCrLf & _
			"Negative Correction Results: " & vbCrLf & _
			"- Confidence: " & results.confidence & vbCrLf & _
			"- Image Is Normal: " & results.imageIsNormal & vbCrLf & _
			"- Image Was Modified: " & results.imageWasModified & vbCrLf & vbCrLf
	Else
		strResults = "SCanFix error during Negative Correction process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF

	ScanFixNegativeCorrection = strResults
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixTextCorrection(iMinAreaWidth, iMinAreaHeight, iMinBlackOnEdges)
On Error Resume Next
	Dim strResults

	Set options = CreateObject("PegasusImaging.ScanFix5.InverseTxtOpt")
	If (Err.Number <> 0) Then
		strResults = "Runtime error during Inverse Text Correction process." & vbCrLf & _
			"Error Number: " & Err.Number & vbCrLf & _
			"Error Description: " & Err.Description & vbCrLf & vbCrLf
		Err.Clear
		ScanFixTextCorrection = strResults
		Exit Function
	End If

    options.minimumAreaWidth = CLng(iMinAreaWidth)
    options.minimumAreaHeight = CLng(iMinAreaHeight)
    options.minimumBlackOnEdges = CLng(iMinBlackOnEdges)

	Set results = sf1.CorrectInverseText(options)
	
	If (sf1.ErrorNumber = 0) Then
		strResults = "Inverse Text Correction completed successfully." & vbCrLf & _
			"Inverse Text Correction Results: " & vbCrLf & _
			"- Count Of Areas Found: " & results.countOfAreasFound & vbCrLf & _
			"- Image Was Modified: " & results.imageWasModified & vbCrLf & vbCrLf
	Else
		strResults = "ScanFix error during Inverse Text Correction process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF

	ScanFixTextCorrection = strResults
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixAutoBorderCrop(bCropBorder, bReplaceBorder, bDeskewBorder, cPadColor, iBorderSpeck, iPageSpeck, iQuality, iMinConfidence)
On Error Resume Next
	Dim strResults

	Set options = CreateObject("PegasusImaging.ScanFix5.BorderRmvOpt")
	If (Err.Number <> 0) Then
		strResults = "Runtime error during Border Removal process." & vbCrLf & _
			"Error Number: " & Err.Number & vbCrLf & _
			"Error Description: " & Err.Description & vbCrLf & vbCrLf
		Err.Clear
		ScanFixAutoBorderCrop = strResults
		Exit Function
	End If

    options.cropBorder = CBool(bCropBorder)
    options.replaceBorder = CBool(bReplaceBorder)
    options.deskewBorder = CBool(bDeskewBorder)
	if (cPadColor = 0) then
		options.padColor = vbWhite
	else
		options.padColor = vbBlack
	end if
    options.borderSpeckSize = CInt(iBorderSpeck)
    options.pageSpeckSize = CInt(iPageSpeck)
    options.quality = CInt(iQuality)
    options.minimumConfidence = CInt(iMinConfidence)

	Set results = sf1.RemoveBorder(options)

	If (sf1.ErrorNumber = 0) Then
		strResults = "Border Removal completed successfully." & vbCrLf & _
			"Border Removal Results: " & vbCrLf & _
			"- Confidence: " & results.confidence & vbCrLf & _
			"- Image Was Modified: " & results.imageWasModified & vbCrLf & _
            "- Detected Vertical Angle: " & results.detectedVerticalAngle & vbCrLf & _
            "- Detected Horizontal Angle: " & results.detectedHorizontalAngle & vbCrLf & _
            "- Page Dimensions (without border): {" & results.pageX & ", " & results.pageY & _
            ", " & results.pageWidth & ", " & results.pageHeight & "}" & vbCrLf & vbCrLf
	Else
		strResults = "ScanFix error during Border Removal process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End If

	ScanFixAutoBorderCrop = strResults
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixSmoothing(iSmoothAmount)
On Error Resume Next
	Dim strResults
	
	Set results = sf1.SmoothObjects(iSmoothAmount)
	
	If (sf1.ErrorNumber = 0) Then
		strResults = "Smoothing completed successfully."
	Else
		strResults = "ScanFix error during Smoothing process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF

	ScanFixSmoothing = strResults
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function ScanFixBlankPageDetect(bIgnoreBorder, iTopMargin, iLeftMargin, iBottomMargin, iRightMargin, iMinObjDim, iGapFill)
On Error Resume Next
	Dim strResults
	
	Set options = CreateObject("PegasusImaging.ScanFix5.BlankPgDetOpt")
	If (Err.Number <> 0) Then
		strResults = "Runtime error during Blank Page Detection process." & vbCrLf & _
			"Error Number: " & Err.Number & vbCrLf & _
			"Error Description: " & Err.Description & vbCrLf & vbCrLf
		Err.Clear
		ScanFixBlankPageDetect = strResults
		Exit Function
	End If

    options.ignoreBorder = CBool(bIgnoreBorder)
    options.topMargin = CLng(iTopMargin)
    options.leftMargin = CLng(iLeftMargin)
    options.bottomMargin = CLng(iBottomMargin)
    options.rightMargin = CLng(iRightMargin)
    options.minimumObjectDimension = CLng(iMinObjDim)
    options.gapFill = CLng(iGapFill)

	Set results = sf1.DetectBlankPage(options)
	
	If (sf1.ErrorNumber = 0) Then
		strResults = "Blank Page Detection completed successfully." & vbCrLf & _
			"Blank Page Detection Results: " & vbCrLf & _
			"- Confidence: " & results.confidence & vbCrLf & _
			"- Is Blank: " & results.isBlank & vbCrLf & vbCrLf
	Else
		strResults = "ScanFix error during Blank Page Detection process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF

	ScanFixBlankPageDetect = strResults
End Function

Function ScanFixImageRegistration(bCentralFocus, bIgnoreHoles, bSkipActive, bLineActive, bThinLinesActive, bAddOnly, iMinimumActivity, iMinimumBackground, iMinimumForeground, iResultantMargin, iSkipDistance, iMaximumLineGap, iMaximumLineThickness, iMaximumLineLength)

On Error Resume Next
    Dim strResults
	
	Set options = CreateObject("PegasusImaging.ScanFix5.ImageRegOpt")    
	If (Err.Number <> 0) Then        
		strResults = "Runtime error during image registration process." & vbCrLf & _
			"Error Number: " & Err.Number & vbCrLf & _
			"Error Description: " & Err.Description & vbCrLf & vbCrLf
		Err.Clear
		ScanFixImageRegistration = strResults
		Exit Function
	End If	    

    options.horizonalActive = True
    options.verticalActive = True

    options.horizontalAddOnly = CBool(bAddOnly)
    options.horizontalCentralFocus = CBool(bCentralFocus)
    options.horizontalIgnoreHoles = CBool(bIgnoreHoles)
    options.horizontalMinimumActivity = CInt(iMinimumActivity)
    options.horizontalMinimumBackground = CInt(iMinimumBackground)
    options.horizontalMinimumForeground = CInt(iMinimumForeground)
    options.horizontalResultantMargin = CInt(iResultantMargin)
    options.horizontalSkipActive = CBool(bSkipActive)
    options.horizontalSkipDistance = CInt(iSkipDistance)
    options.horizontalToLineActive = CBool(bLineActive)
    options.horizontalToLineCheckThinLinesActive = CBool(bThinLinesActive)
    options.horizontalToLineMaximumLineGap = CInt(iMaximumLineGap)
    options.horizontalToLineMaximumLineThickness = CInt(iMaximumLineThickness)
    options.horizontalToLineMinimumLineLength = CInt(iMaximumLineLength)
    
    options.verticalAddOnly = CBool(bAddOnly)
    options.verticalCentralFocus = CBool(bCentralFocus)
    options.verticalIgnoreHoles = CBool(bIgnoreHoles)
    options.verticalMinimumActivity = CInt(iMinimumActivity)
    options.verticalMinimumBackground = CInt(iMinimumBackground)
    options.verticalMinimumForeground = CInt(iMinimumForeground)
    options.verticalResultantMargin = CInt(iResultantMargin)
    options.verticalSkipActive = CBool(bSkipActive)
    options.verticalSkipDistance = CInt(iSkipDistance)
    options.verticalToLineActive = CBool(bLineActive)
    options.verticalToLineCheckThinLinesActive = CBool(bThinLinesActive)
    options.verticalToLineMaximumLineGap = CInt(iMaximumLineGap)
    options.verticalToLineMaximumLineThickness = CInt(iMaximumLineThickness)
    options.verticalToLineMinimumLineLength = CInt(iMaximumLineLength)

    Set results = sf1.RegisterImage(options)

    If (sf1.ErrorNumber = 0) Then
		strResults = "Image Registration completed successfully." & vbCrLf & _
			"Image Registration Results: " & vbCrLf & _
			"- Horizontal Margin Adjustment: " & results.horizontalMarginAdjustment & vbCrLf & _
            "- Vertical Margin Adjustment: " & results.verticalMarginAdjustment & vbCrLf & _
			"- Image Was Modified: " & results.imageWasModified & vbCrLf & vbCrLf
	Else
		strResults = "ScanFix error during the Image Registration process." & vbCrLf & _
			"Error Number: " & sf1.ErrorNumber & vbCrLf & _
			"Error Description: " & sf1.ErrorDescription & vbCrLf & vbCrLf
	End IF
    
    ScanFixImageRegistration = strResults
End Function

'//////////////////////////////////////////////////////////////////////////////
'// Miscellaneous Procedures
'//////////////////////////////////////////////////////////////////////////////

''''''''''''''''''''''''''''''''''''''''''''''
' adds an item to the enhancement queue select
' object
Function AddItemToSelectObject(strText, strValue)
On Error Resume Next
    Dim numElements

	'add the new enhancement to the list
	numElements = selectedEnhancements.options.length	
	selectedEnhancements.options.length = numElements + 1
	selectedEnhancements.options(numElements).value = strValue
	selectedEnhancements.options(numElements).text = strText
End Function

''''''''''''''''''''''''''''''''''''''''''''''
' checks the vbscript error object
Function CheckForRuntimeError(errNum, errMsg)
	If (errNum <> 0) Then
		DisplayResults "General Error: " & errNum & " - " & errMsg, "Runtime Error"
		CheckForRuntimeError = true
	Else
		CheckForRuntimeError = false
	End If
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function DisplayResults(strResults, strTitle)
	MsgBox strResults, vbOKOnly, strTitle
End Function

''''''''''''''''''''''''''''''''''''''''''''''
Function CheckInputText(vkey)
	If ((vkey < 48 Or vkey > 57) And ((vkey <> 46) And (vkey <> 8) And (vkey <> 127))) Then
		window.event.keycode = 0
	End If
End Function

''''''''''''''''''''''''''''''''''''''''''''''
'translates IX error numbers into descriptions
Function ErrString(ErrNum) 

	Select Case (ErrNum)
		Case 0
			ErrString = "ixERROR_NONE ( 0) - No error"
		Case -1
			ErrString = "ixERROR_FILEOPEN (-1) - Cannot find or cannot open the image file"
		Case -2
			ErrString = "ixERROR_FORMATUNKNOWN (-2) - The image file type is unknown or unable to read the image file type"
		Case -3
			ErrString = "ixERROR_MEMORYLOCK (-3) - Cannot lock memory"
		Case -4
			ErrString = "ixERROR_DITHER (-4) - Cannot dither the image"
		Case -5
			ErrString = "ixERROR_QUANTIZE (-5) - Cannot quantize the image palette"
		Case -6
			ErrString = "ixERROR_FILEREAD (-6) - Error reading the fi"
		Case -7
			ErrString = "ixERROR_MEMORYALLOC (-7) - Cannot allocate memory for the image"
		Case -8
			ErrString = "ixERROR_CANCELED (-8) - Image load or decompression was canceled"
		Case -9
			ErrString = "ixERROR_CREATEFILE (-9) - Cannot create file."
		Case -10
			ErrString = "ixERROR_FILEWRITE (-10) - Error writing file"
		Case -11
			ErrString = "ixERROR_INVALIDFORMAT (-11) - Invalid image format"
		Case -12
			ErrString = "ixERROR_INVALIDOPTION (-12) - Invalid option"
		Case -13
			ErrString = "ixERROR_INVALIDPALETTEFILE (-13) - Invalid palette file"
		Case -14
			ErrString = "ixERROR_INVALIDEXT (-14) - Invalid file extension"
		Case -15
			ErrString = "ixERROR_CLIPBOARDPASTE (-15) - Error pasting from clipboard"
		Case -16
			ErrString = "ixERROR_CLIPBOARDCOPY (-16) - Error copying image to the clipboard."
		Case -17
			ErrString = "ixERROR_FORMATNOTSUPPORTED (-17) - Image format not supported."
		Case -18
			ErrString = "ixERROR_LOADLIBTIFF (-18) -"
		Case -19
			ErrString = "ixERROR_UNABLETOSETPICTURE (-19) - Unable to set the Picture property because the CreateDIBits API function failed. The image is probably too large to display with a Device Dependent Bitmap."
		Case -20
			ErrString = "ixERROR_LZWACCESSERROR (-20) - Attempting to read or write a GIF or LZW-TIFF file and the LZWPassword property is not set to the correct password. GIF and LZW-TIFF require licensing from Unisys Corp. Please see GIF/LZW Licensing in the Appendix for detailed information."
		Case -21
			ErrString = "ixERROR_INVALIDPAGE (-21) - Attempting to read a multiple page TIFF or DCX file and the PageNbr property specifies a page that does not exist in the file. "
		Case -22
			ErrString = "ixERROR_INVALIDPICPASSWORD (-22) - Attempting to read a password protected PIC file and the password in the PICPassword property does not match the password in the file."
		Case -23
			ErrString = "ixERROR_PIXEL_OUT_OF_RANGE (-23) - Specified pixel location does not lie within the boundaries of the current DIB."
		Case -24
			ErrString = "ixERROR_PALINDEX_OUT_OF_RANGE (-24) - Specified palette index does not lie within the number of palette entries for the current DIB."
		Case -25
			ErrString = "ixERROR_NO_IMAGE (-25) - The operation failed because the control does not have a DIB."
		Case -26
			ErrString = "ixERROR_NO_CAPTURE (-26) - The operation failed because the controls picture property is not set."
		Case -27
			ErrString = "ixERROR_BAD_ANGLE (-27) - The operation failed because an invalid angle was specified. "
		Case -28
			ErrString = "ixERROR_BAD_RADIUS (-28) - The operation failed because an invalid radius was specified. "
		Case -29
			ErrString = "ixERROR_INVALIDCROP (-29) - Loading a JPEG or ePIC image failed because PICCropEnabled property was set and the PICCropX or PICCropY property was out of range for the specified image."
		Case -30
			ErrString = "ixERROR_NO_UNODIB (-30) - Attempting to 'undo' but there is no undo DIB. "
		Case -31
			ErrString = "ixERROR_INVALID_PROPERTY_VALUE (-31) - Invalid property value."
		Case -32
			ErrString = "ixERROR_LLWININET (-32) - Load library failed for WININET.DLL."
		Case -33
			ErrString = "ixERROR_FTP (-33) - FTP error."
		Case -34
			ErrString = "ixERROR_INVALIDFILENAME (-34) - Invalid file name."
		Case -35
			ErrString = "ixERROR_UNABLE_TO_DESKEW (-35) - Unable to deskew image."
		Case -36
			ErrString = "ixERROR_LLIMAGR6 (-36) - Load library failed for IMAGR7.DLL."
		Case -37
			ErrString = "ixERROR_CAPTURE_FAILED (-37) - Capture failed."
		Case -38
			ErrString = "ixERROR_INVALIDLICENSE (-38) - Invalid License. Attempting to access a function using a function that you are not licensed to use. See ImagXpress Professional/ ImagXpress Standard Differences for more information."
		Case -39
			ErrString = "ixERROR_LOADLIBTWAIN (-39) - Load library failed for TWNLIB4.DLL."
		Case -40
			ErrString = "ixERROR_UNABLETOCROP (-40) - Unable to Crop"
		Case -41
			ErrString = "ixERROR_UNABLETODELETEPAGE (-41) - Unable to Delete Page"
		Case -42
			ErrString = "ixERROR_NOWINDOW (-42) - No Window Handle"
		Case -43
			ErrString = "ixERROR_JPEGCOMMENTNOTFOUND (-43) - JPEG comment not found. The requested comment does not exist."
		Case -44
			ErrString = "ixERROR_JPEGCOMMENTADDERROR (-44) - Unable to add a JPEG comment."
		Case -45
			ErrString = "ixERROR_SAVETOBUFFER_FAILED (-45) - Save to buffer failed."
		Case -46
			ErrString = "ixERROR_OPTION_NOTINSTALLED (-46) - Additional option not installed. See JPEG 2000 Option , JPEG LS Option , or WSQ Option for more information."
		Case -47
			ErrString = "ixERROR_INTERNAL_ERROR (-47)"
		Case -48
			ErrString = "ixERROR_INVALID_HANDLE (-48)"
		Case -49
			ErrString = "ixERROR_INVALID_IMAGE_ID (-49)"
		Case -50
			ErrString = "ixERROR_INVALID_POINTER (-50)"
		Case -51
			ErrString = "ixERROR_INVALID_AREA_OR_REGION (-51)"
		Case -52
			ErrString = "ixERROR_NOCURRENTBUFFER (-52)"
		Case -53
			ErrString = "ixERROR_IMAGE_ACCESS_TIMEOUT (-53)"
		Case -54
			ErrString = "ixERROR_BUFFER_ACCESS_TIMEOUT (-54)"
		Case -55
			ErrString = "ixERROR_EVENT_RESPONSE (-55)"
		Case -56
			ErrString = "ixERROR_PROCESSOR_THREAD_CREATION (-56)"
		Case -57
			ErrString = "ixERROR_IMAGE_HAS_TASKS_PENDING (-57)"
		Case -58
			ErrString = "ixERROR_RESUME_THREAD_ERROR (-58)"
		Case -59
			ErrString = "ixERROR_SHUTDOWN (-59)"
		Case -60
			ErrString = "ixERROR_OPERATION_NA_FOR_RAWDATA (-60)"
		Case -61
			ErrString = "ixERROR_NO_LICENSE (-61)"
		Case -62
			ErrString = "ixERROR_INVALID_WEB_INT_LICENSE (-62)"
		Case -63
			ErrString = "ixERROR_INVALID_ADD_ON_LICENSE (-63)"
		Case -64
			ErrString = "ixERROR_LOAD_WATERMARK_IMAGE (-64)"
		Case -65
			ErrString = "ixERROR_BITMAP_TO_DIB_CONVERSION (-65)"
		Case -301
			ErrString = "ixERROR_NORESOURCES (-301) - Image capture failed."
		Case -500
			ErrString = "ixERROR_PRINT_NOT_SUPPORTED (-500) - Printer does not support the StretchDIBits API function "
		Case -501
			ErrString = "ixERROR_PRINT_OUT_OF_RANGE (-501) - Cannot print outside the valid printer area"
		Case -601
			ErrString = "ixERROR_TAG_TAGNOTFOUND (-601) - Tag not found."
		Case -602
			ErrString = "ixERROR_TAG_ITEMNOTFOUND (-602) - Tag item not found."
		Case -603
			ErrString = "ixERROR_TAG_ADDERROR (-603) - Tag error adding tag."
		Case 1000
			ErrString = "ixERROR_TWPRO_TWAIN (1000) - TWAIN General error."
		Case 1001
			ErrString = "ixERROR_TWPRO_TINIT (1001) - TWAIN Initialization error."
		Case 1002
			ErrString = "ixERROR_TWPRO_FILEOPEN (1002)"
		Case 1003
			ErrString = "ixERROR_TWPRO_MEMORYALLOC (1003) - TWAIN Could not allocate required memory."
		Case 1004
			ErrString = "ixERROR_TWPRO_CANCELED (1004) - TWAIN Operation canceled."
		Case 1005
			ErrString = "ixERROR_TWPRO_CREATEFILE (1005)"
		Case 1006
			ErrString = "ixERROR_TWPRO_FILEWRITE (1006)"
		Case 1007
			ErrString = "ixERROR_TWPRO_FORMATNOTSUPPORTED (1007)"
		Case 1008
			ErrString = "ixERROR_TWPRO_BADLENGTH (1008)"
		Case 1009
			ErrString = "ixERROR_TWPRO_BADVALUE (1009)"
		Case 1010
			ErrString = "ixERROR_TWPRO_NODIB (1010)"
		Case 1011
			ErrString = "ixERROR_TWPRO_NOPICFILES (1011)"
		Case 1012
			ErrString = "ixERROR_TWPRO_NONETFILES (1012)"
		Case 1013
			ErrString = "ixERROR_TWPRO_FTP (1013)"
		Case 1014
			ErrString = "ixERROR_TWPRO_TSEQERROR (1014)"
		Case 1015
			ErrString = "ixERROR_TWPRO_BADINDEX (1015)"
		Case 1016
			ErrString = "ixERROR_TWPRO_WRONGCAPTYPE (1016)"
		Case 1017
			ErrString = "ixERROR_TWPRO_CLIPBOARD (1017)"
		Case 1018
			ErrString = "ixERROR_TWPRO_PIC (1018)"
		Case 1019
			ErrString = "ixERROR_TWPRO_BADBITDEPTH (1019)"
		Case 1020
			ErrString = "ixERROR_TWPRO_NOTAVAILABLE (1020)"
		Case 1021
			ErrString = "ixERROR_TWPRO_NOIMAGE (1021)"
		Case 1022
			ErrString = "ixERROR_TWPRO_DSINVALIDOP (1022)"
		Case Else
			ErrString = "Unknown Error! Error #" & ErrNum & "."
	End Select

End Function
