SUBROUTINE SAVPALLETFIL(CHECKED)
!***************************************************************************
!*																		   *
!*  THIS SUBROUTINE CREATES A DIALOG BOX THAT ALLOWS THE USER TO save THE  *
!*  PALLET DATA FILE.  THIS ROUTINE USES THE SYSTEM COMMON DIALOG ACCESSES *
!*  THROUGH THE WINDOWS API'S                                              *
!*																		   *
!***************************************************************************

  USE DFLIB
  USE INPUTINFO
  USE DFWINTY
  USE DFWIN

  IMPLICIT NONE

  TYPE (T_OPENFILENAME)FRED

  LOGICAL(KIND=4)RET
  INTEGER(KIND=4)IERROR
  CHARACTER(LEN=26*7)ALLFILTERS
  CHARACTER(LEN=60)DLGTITLE
  LOGICAL(KIND=4)CHECKED

  CALL UNUSEDQQ(CHECKED)
!* SET UP FILE SEARCH FILTERS
  ALLFILTERS = 'Chaos data files(*.DAT)' // char(0) // &
               '*.dat' // char(0) // &
               'Palette data files(*.PAL)' // char (0) // &
			   '*.pal' // char(0) // &
			   'All files(*.*)' // char(0) // &
			   '*.*' // char(0) // char(0)  

!* DIALOG TITLE
  DLGTITLE = 'Save Palette Data File'C

!* SET UP STRUCTURE USED BY COMMON DIALOGS - SEE WIN32 API HELP FOR EXPLANATION
  FRED%LSTRUCTSIZE = (BIT_SIZE(FRED%LSTRUCTSIZE) +        &
                       BIT_SIZE(FRED%HWNDOWNER) +        &
                       BIT_SIZE(FRED%HINSTANCE) +        &
                       BIT_SIZE(FRED%LPSTRFILTER) +        &
                       BIT_SIZE(FRED%LPSTRCUSTOMFILTER) +        &
                       BIT_SIZE(FRED%NMAXCUSTFILTER) +        &
                       BIT_SIZE(FRED%NFILTERINDEX) +        &
                       BIT_SIZE(FRED%LPSTRFILE) +        &
                       BIT_SIZE(FRED%NMAXFILE) +        &
                       BIT_SIZE(FRED%LPSTRFILETITLE) +        &
                       BIT_SIZE(FRED%NMAXFILETITLE) +        &
                       BIT_SIZE(FRED%LPSTRINITIALDIR) +        &
                       BIT_SIZE(FRED%LPSTRTITLE) +        &
                       BIT_SIZE(FRED%FLAGS) +        &
                       BIT_SIZE(FRED%NFILEOFFSET) +        &
                       BIT_SIZE(FRED%NFILEEXTENSION) +        &
                       BIT_SIZE(FRED%LPSTRDEFEXT) +        &
                       BIT_SIZE(FRED%LCUSTDATA) +        &
                       BIT_SIZE(FRED%LPFNHOOK) +        &
                       BIT_SIZE(FRED%LPTEMPLATENAME))/8

  FRED%HWNDOWNER = GETHWNDQQ(QWIN$FRAMEWINDOW)
  FRED%HINSTANCE = NULL
  FRED%LPSTRFILTER = LOC(ALLFILTERS)
  FRED%LPSTRCUSTOMFILTER = NULL
  FRED%NMAXCUSTFILTER = NULL
  FRED%NFILTERINDEX = 2
  FRED%LPSTRFILE = LOC(PALLET_SAV) 
  FRED%NMAXFILE = LEN(PALLET_SAV) 
  FRED%LPSTRFILETITLE = NULL 
  FRED%NMAXFILETITLE = NULL
  FRED%LPSTRINITIALDIR = NULL
  FRED%LPSTRTITLE = LOC(DLGTITLE)
  FRED%FLAGS = NULL 
  FRED%NFILEOFFSET = NULL
  FRED%NFILEEXTENSION = NULL
  FRED%LPSTRDEFEXT = NULL
  FRED%LCUSTDATA = NULL
  FRED%LPFNHOOK = NULL
  FRED%LPTEMPLATENAME = NULL 

!* CREATE DIALOG
  RET = GETSAVEFILENAME(FRED)
!* CHECK FOR ERROR
  CALL COMDLGER(IERROR)
!* SAVE FILE
  PALLET_FILE_SAV = .FALSE.
!* CHECK TO SEE IF THE OK BUTTON HAS BEEN PRESSED
  IF(RET .AND. (IERROR == 0))THEN
!* GET THE NEW INFORMATION
	CALL SAV_PALLET
	PALLET_FILE_SAV = .TRUE.
  ENDIF

  RETURN
END SUBROUTINE SAVPALLETFIL 
