/*
 * $Source: $
 * $Revision: $
 * $Date: $
 * $State: $
 * $Author: $
 *
 *
 * $Log: $
 * Revision 3.1  3/10/92 wade
 * Added Baylor's changes
 * allow creation/modification of image node type
 * 
 * Revision 3.1 4/1/92 wade
 * Changed GetInfo to display keyword list and fixed
 * bug to display file path for an image.
 *
 * Revision 3.2 6/15/92 mec
 * Added code in dlog_phone() to manage new radio buttons
 *
 */

/*	Copyright (c) 1991 by the Massachusetts Institute of Technology,
 *	For copying and distribution information, see the file
 *	"mit-copyright.h".
 *
 *  dialogMgr.c  - WADE 8/23/89
 *	
 *	DialogInit
 *	CommandDialog
 *	OpenMsgDialog
 *	CloseMsgDialog
 *	OpenAlertDialog
 *	networkDialog
 *	AlertUser
 *	BigBadError
 *	GetIdFilter
 *	dlog_login
 *	dlog_disclaimer
 *	dlog_version
 *
 */
 
#include <Limits.h>
#include <Types.h>
#include <QuickDraw.h>
#include <Fonts.h>
#include <Events.h>
#include <Controls.h>
#include <Windows.h>
#include <Menus.h>
#include <TextEdit.h>
#include <Dialogs.h>
#include <Desk.h>
#include <Scrap.h>
#include <ToolUtils.h>
#include <Memory.h>
#include <SegLoad.h>
#include <Files.h>
#include <OSUtils.h>
#include <Traps.h>
#include "pips.h" 
#include <packages.h>
#include "prototype.h"
#include <resources.h>
#include <OSEvents.h>
#include "Utilities.h"
#include <stdio.h>
#include <Ctype.h>
#include "mit-copyright.h"

extern DialogPtr		gMsgDialog;
static Str255			gPasswordStr;

#define ICN				1229147683

/*     
 *
 * dlog_init: 
 * 
 *
 */
void
DialogInit()
{
	gMsgDialog = GetNewDialog( MESSAGE_DIALOG, NIL_POINTER, (WindowPtr)-1 ); 
}

/*     
 *
 * dlog_find: 
 * 
 *
 */
Boolean
dlog_keyword( commandStr, search_criteria )
char			*commandStr;
Boolean			*search_criteria;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		optionsDialog;
	GrafPtr			oldPort;
	static Boolean	search_current_menu = 0;
	
	optionsDialog = GetNewDialog( KEYWORD_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	
	ShowWindow( optionsDialog ); 
	
	GetPort( &oldPort );
	SetPort( optionsDialog );
	
	/* display last user input in the dialog box */
	GetDItem( optionsDialog, USER_INPUT, &itemType, &itemHandle, &itemRect );
	c2pstr( commandStr );
	SetIText( (Handle)itemHandle, commandStr );
	SelIText( optionsDialog, USER_INPUT, 0, 32767);	/* select the entire string */
	
	/* set the starting search criteria value - remains static for session */
	/* if the current menu does not have a parent, force search from main menu */
	if ( !cmd_menu_owner() ) {
		search_current_menu = false;
		/* make control inactive */
		GetDItem( optionsDialog, SEARCH_CURRENT_RADIO, &itemType, &itemHandle, &itemRect );
		HiliteControl((ControlHandle)itemHandle, 255);
	}
		
	if (search_current_menu) 
		GetDItem( optionsDialog, SEARCH_CURRENT_RADIO, &itemType, &itemHandle, &itemRect );
	else
		GetDItem( optionsDialog, SEARCH_ALL_RADIO, &itemType, &itemHandle, &itemRect );
	SetCtlValue ( (ControlHandle)itemHandle, ON );

	/* let's put up a default button to keep with mac standards */
	GetDItem( optionsDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);
	
	dialogDone = -1;
	while ( dialogDone < 0 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				dialogDone = true;
				GetDItem( optionsDialog, USER_INPUT, &itemType, &itemHandle,
					&itemRect );
				GetIText ((Handle)itemHandle, commandStr );
				
				/* what type of a search is this? */
				GetDItem( optionsDialog, SEARCH_CURRENT_RADIO, &itemType, &itemHandle, &itemRect );
				*search_criteria = GetCtlValue( (ControlHandle)itemHandle);
				search_current_menu = *search_criteria;  /* save this value */

				break;
				
			case CANCEL_BUTTON:
				dialogDone = false;
				break;
				
			case SEARCH_ALL_RADIO:
				GetDItem( optionsDialog, SEARCH_ALL_RADIO, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, ON );
				
				GetDItem( optionsDialog, SEARCH_CURRENT_RADIO, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, OFF );
				break;
				
			case SEARCH_CURRENT_RADIO:
				GetDItem( optionsDialog, SEARCH_ALL_RADIO, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, OFF );
				
				GetDItem( optionsDialog, SEARCH_CURRENT_RADIO, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, ON );
				break;

		}
	}
	
	DisposDialog( optionsDialog );
	SetPort( oldPort );
	p2cstr( commandStr );                     /* convert pascal string to C string */
	
	if (dialogDone  && commandStr[0] > 0) {
		
		/* remove leading blanks */
		util_remove_leading_blanks( commandStr );
		
		if ( *commandStr == '\0' )
			return false;
		else 
			return true;	 					
	}
	else
		return false;
}
/*     
 *
 * dlog_phone: 
 * 
 *
 */
#pragma segment special
Boolean
dlog_phone( commandStr )
char			*commandStr;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		phoneDialog;
	GrafPtr			oldPort;
// mec
	Boolean			doPartialMatch;
// mec
	
	phoneDialog = GetNewDialog( PHONE_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	
// mec
	GetDItem( phoneDialog, 5, &itemType, &itemHandle, &itemRect );
	SetCtlValue ( (ControlHandle)itemHandle, ON );
	doPartialMatch = false;
// mec

	ShowWindow( phoneDialog ); 
	
	GetPort( &oldPort );
	SetPort( phoneDialog );
	
	/* display last user input in the dialog box */
	GetDItem( phoneDialog, USER_INPUT, &itemType, &itemHandle, &itemRect );
	c2pstr( commandStr );
	SetIText( (Handle)itemHandle, commandStr );
	SelIText( phoneDialog, USER_INPUT, 0, 32767);	/* select the entire string */
	
	/* let's put up a default button to keep with mac standards */
	GetDItem( phoneDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);
	
	dialogDone = -1;
	while ( dialogDone < 0 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				dialogDone = true;
				GetDItem( phoneDialog, USER_INPUT, &itemType, &itemHandle,
					&itemRect );
				GetIText ((Handle)itemHandle, commandStr );
				break;
				
			case CANCEL_BUTTON:
				dialogDone = false;
				break;

// mec - new radios

			case 5:
				GetDItem( phoneDialog, 6, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, OFF );
				GetDItem( phoneDialog, 5, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, ON );
				doPartialMatch = false;
				break;

			case 6:
				GetDItem( phoneDialog, 5, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, OFF );
				GetDItem( phoneDialog, 6, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, ON );
				doPartialMatch = true;
				break;
// mec
		}
	}
	
	DisposDialog( phoneDialog );
	SetPort( oldPort );
	p2cstr( commandStr );                     /* convert pascal string to C string */
	
	if (dialogDone  && commandStr[0] > 0) {
		
		/* remove leading blanks */
		util_remove_leading_blanks( commandStr );
		
		if ( *commandStr == '\0' )
			return false;
		else {
// mec
			// if we are doing a partial match and there isn't an * already
			// at the end...
			if (doPartialMatch && commandStr[strlen(commandStr) - 1] != '*')
				strcat(commandStr, "*");
// mec
			return true;	 					
		}
	}
	else
		return false;
}

/*     
 *
 * dlog_open_msg: 
 * 
 *
 */
OpenMsgDialog( message )
char      *message;
{
	short		itemType;
	Rect		itemRect;
	Handle		itemHandle;
		
	c2pstr( message );
	
	SelectWindow( gMsgDialog );
	ShowWindow( gMsgDialog ); 
	
	GetDItem ( gMsgDialog, 1, &itemType, &itemHandle, &itemRect );
	SetIText( itemHandle,message );
	
	p2cstr( message );
	
}

/*     
 *
 * dlog_close_msg:
 * 
 *
 */
CloseMsgDialog()
{
	HideWindow( gMsgDialog ); 
}

/*     
 *
 * 	dlog_alert:
 * 
 *	Put up a Note Alert, used for warning messages.
 *
 */
void
OpenAlertDialog( message_id, options)
int		message_id;		/* initial message from the strings resource */
char	*options;		/* this is the second line of the alert      */
{
	short		itemHit;
	Str255		message;
	
	/* make sure that cursor is in an arrow shape for the alert box */
	wind_set_cursor(0); 
	
	/* get string message from resource */
	GetIndString(message, MESSAGES, message_id);
	c2pstr(options);
	ParamText(message, options, "", "");
	p2cstr(options);
	
	itemHit = NoteAlert ( NOTE_ID, NIL_POINTER );
	
} /* OpenAlertDialog */

/*     
 *
 * dlog_network:
 * 
 *
 */
Boolean
networkDialog( host,port )
char *host;
char *port;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		networkDialog;
	char			thost[30], tport[20], banner[BANNER_SIZE];
	int				active;
	GrafPtr			oldPort;
	
	networkDialog = GetNewDialog( NETWORK_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	
	GetDItem( networkDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	active = net_check();
	if ( active )
		SetCTitle( (ControlHandle)itemHandle, "\pCLOSE" );
	else
		SetCTitle( (ControlHandle)itemHandle, "\pOPEN" ); 
	
	/* GetDItem( networkDialog, CANCEL_BUTTON, &itemType, &itemHandle, &itemRect ); */
	GetDItem( networkDialog, 2, &itemType, &itemHandle, &itemRect ); 
	
	GetDItem( networkDialog, HOST_DLOG, &itemType, &itemHandle, &itemRect );
	strcpy( thost, host );
	c2pstr( thost );
	SetIText( itemHandle, thost );
	
	GetDItem( networkDialog, PORT_DLOG, &itemType, &itemHandle, &itemRect );
	strcpy( tport,port );
	c2pstr( tport );
	SetIText( itemHandle, tport );
	 
	GetDItem( networkDialog, BANNER_ITEM, &itemType, &itemHandle, &itemRect );
	net_banner( banner );
	c2pstr( banner );
	SetIText( itemHandle, banner );
	
	GetPort( &oldPort );
	SetPort( networkDialog );
	
	ShowWindow( networkDialog );
	
	/* let's put up a default button to keep with mac standards */
	GetDItem( networkDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);
	
	dialogDone = -1;
	while ( dialogDone < 0 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				dialogDone = true;
				GetDItem( networkDialog, HOST_DLOG, &itemType, &itemHandle,
					&itemRect );
				GetIText ((Handle)itemHandle, host );
				p2cstr( host );
				
				GetDItem( networkDialog, PORT_DLOG, &itemType, &itemHandle,
					&itemRect );
				GetIText ((Handle)itemHandle, port );
				p2cstr( port );
				break;
				
			case CANCEL_BUTTON: 
				dialogDone = false;
				break;
		}
	}
	
	DisposDialog( networkDialog );
	SetPort( oldPort );
	
	return dialogDone;
}

/*     
 *
 *  AlertUser:
 *
 *	Display an alert that tells the user an error occurred, then exit the program.
 *	This routine is used as an ultimate bail-out for serious errors that prohibit
 *	the continuation of the application. Errors that do not require the termination
 *	of the application should be handled in a different manner. Error checking and
 *	reporting has a place even in the simplest application. The error number is used
 *	to index an 'STR#' resource so that a relevant message can be displayed. 
 *
 */
#pragma segment Main
void AlertUser(error)
	short		error;
{
	short		itemHit;
	Str255		message;

	SetCursor(&qd.arrow);
	/* type Str255 is an array in MPW 3 */
	GetIndString(message, kErrStrings, error);
	ParamText(message, "", "", "");
	
	itemHit = Alert(rUserAlert, nil);
} /* AlertUser */

/*     
 *
 * BigBadError:
 *
 * Used whenever a, like, fully fatal error happens 
 *
 */
#pragma segment Initialize
void BigBadError(error)
	short error;
{
	AlertUser(error);
	ExitToShell();
}

/* field can be null, but not contain the transaction delimiter */
#define FIELD_TEST1(n,m) { \
	for(cp=n; *cp != NULL && dialogDone != bad_result; cp++) \
		if (!(isascii(*cp) && *cp != DELIM_CHAR && *cp >= 32)) \
			dialogDone = bad_result; \
	if (dialogDone == bad_result) \
		OpenAlertDialog(FIELD_ENTRY_ERROR1,m); \
}

/* same error check as FIELD_TEST1, except - null value not allowed */
#define FIELD_TEST2(n,m) { \
	if ( strlen(n) == 0 ) dialogDone = bad_result; \
	for(cp=n; *cp != NULL && dialogDone != bad_result; cp++) \
		if (!(isascii(*cp)) || *cp == DELIM_CHAR || *cp < 32) \
			dialogDone = bad_result; \
	if (dialogDone == bad_result) \
		OpenAlertDialog(FIELD_ENTRY_ERROR2,m); \
}

/* field can not be null, contain the transaction delimiter or contain a blank */
#define FIELD_TEST3(n,m) { \
	if ( strlen(n) == 0 ) dialogDone = bad_result; \
	for(cp=n; *cp != NULL && dialogDone != bad_result; cp++) \
		if (!(isalnum(*cp) || *cp == '.' || *cp == '_' || *cp == '/' || *cp == '-')) { \
			dialogDone = bad_result; }\
	if (dialogDone == bad_result) \
		OpenAlertDialog(FIELD_ENTRY_ERROR3,m); \
}

/* field can not be null, contain the transaction delimiter or contain a blank */
/* this is like FIELD_TEST_3, except we don't allow a '/' */
#define FIELD_TEST5(n,m) { \
	if ( strlen(n) == 0 ) dialogDone = bad_result; \
	for(cp=n; *cp != NULL && dialogDone != bad_result; cp++) \
		if (!(isalnum(*cp) || *cp == '.' || *cp == '_' || *cp == '-')) { \
			dialogDone = bad_result; }\
	if (dialogDone == bad_result) \
		OpenAlertDialog(FIELD_ENTRY_ERROR5,m); \
}

/*     
 *
 * dlog_menu_item1:
 *
 * Display modify subject dialog, retrieve any changes and return button user clicked.
 *
 */
Boolean
dlog_menu_item1(menu_type, mode,topic_ptr,title_ptr,source_ptr,parent_ptr)
int		*menu_type;
int		mode;
char	*topic_ptr;
char	*title_ptr;
char	*source_ptr;
char	*parent_ptr;

{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		modifyDialog;
	GrafPtr			oldPort;
	char			*curr_ptr;
	char			*cp;

	
	enum {bad_result = -1, cancel_result = 0, ok_result, more_result};
	
	modifyDialog = GetNewDialog( DEFINE_ITEM_DIALOG1, NIL_POINTER, (WindowPtr)-1 );
	
	/* we need to change the port inorder to draw the default button frame */
	GetPort( &oldPort );
	SetPort( modifyDialog );
	
	GetDItem( modifyDialog, KEYWORDS_FIELD, &itemType, &itemHandle, &itemRect );
	c2pstr( topic_ptr );
	SetIText( itemHandle, topic_ptr );
	
	GetDItem( modifyDialog, TITLE_FIELD, &itemType, &itemHandle, &itemRect );
	c2pstr( title_ptr );
	SetIText( itemHandle, title_ptr );	
	
	GetDItem( modifyDialog, SOURCE_FIELD, &itemType, &itemHandle, &itemRect );
	c2pstr( source_ptr );
	SetIText( itemHandle, source_ptr );
	
	GetDItem( modifyDialog, PARENT_TITLE_FIELD, &itemType, &itemHandle, &itemRect );
	c2pstr( parent_ptr );
	SetIText( itemHandle, parent_ptr );
	
	/* set radio button */
	switch (*menu_type) {
		case text:
			GetDItem( modifyDialog, FOLDER_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
			SetCtlValue ( (ControlHandle)itemHandle, OFF );
			GetDItem( modifyDialog, DOCUMENT_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
			SetCtlValue ( (ControlHandle)itemHandle, ON );
			GetDItem( modifyDialog, IMAGE_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
			SetCtlValue ( (ControlHandle)itemHandle, OFF );
			break;
		case list:
			GetDItem( modifyDialog, FOLDER_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
			SetCtlValue ( (ControlHandle)itemHandle, ON );
			GetDItem( modifyDialog, DOCUMENT_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
			SetCtlValue ( (ControlHandle)itemHandle, OFF );
			GetDItem( modifyDialog, MORE_BUTTON, &itemType, &itemHandle, &itemRect );
			GetDItem( modifyDialog, IMAGE_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
			SetCtlValue ( (ControlHandle)itemHandle, OFF );
			HiliteControl( (ControlHandle)itemHandle, 255);	/* disable the more button */
			break;
		case gif:
			GetDItem( modifyDialog, FOLDER_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
			SetCtlValue ( (ControlHandle)itemHandle, OFF );
			GetDItem( modifyDialog, DOCUMENT_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
			SetCtlValue ( (ControlHandle)itemHandle, OFF );
			GetDItem( modifyDialog, IMAGE_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
			SetCtlValue ( (ControlHandle)itemHandle, ON );
			break;
	}

	ShowWindow( modifyDialog ); 
	
	/* setup button name */
	GetDItem( modifyDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	switch (mode) {
		case add:
			SetCTitle( (ControlHandle)itemHandle, "\pAdd" );
			break;
		case modify:
			SetCTitle( (ControlHandle)itemHandle, "\pModify" ); 
			break;
	}
	
	dialogDone = bad_result;
	while ( dialogDone == bad_result )  {
		/* setup default button frame */
		GetDItem( modifyDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
		PenSize(3,3);
		InsetRect(&itemRect,-4,-4);
		FrameRoundRect(&itemRect,16,16);

		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				
				/* 	set end of loop control to true.  this will get set back to false		
					if the user left empty fields in the dialog box.  We really need
					to give some sort of helpfull message when this happens. */
				dialogDone = ok_result;
					
				GetDItem( modifyDialog, TITLE_FIELD, &itemType, &itemHandle, &itemRect );
				GetIText ((Handle)itemHandle, title_ptr );
				p2cstr( title_ptr );
				util_remove_leading_blanks( title_ptr );
				FIELD_TEST2(title_ptr,""); /* set's dialogDone to bad if error found */
				if (dialogDone == bad_result)
					SelIText( modifyDialog, TITLE_FIELD, 0, 32767);	/* select the entire string */
				
				if (dialogDone != bad_result) {
					GetDItem( modifyDialog, KEYWORDS_FIELD, &itemType, &itemHandle, &itemRect );
					GetIText ((Handle)itemHandle, topic_ptr );
					p2cstr( topic_ptr );
					
					/* remove leading spaces for start of string */
					util_remove_leading_blanks( topic_ptr );

					/* now remove leading spaces for each keyword */
					curr_ptr = topic_ptr;
					for ( curr_ptr = (char*)strstr(curr_ptr,","); curr_ptr != NULL; curr_ptr = (char*)strstr(curr_ptr,",") ) {
						curr_ptr++;  
						util_remove_leading_blanks( curr_ptr );
					}
					
					FIELD_TEST1(topic_ptr,"");  /* set's dialogDone to bad if error found */
					if (dialogDone == bad_result)
						SelIText( modifyDialog, KEYWORDS_FIELD, 0, 32767);	/* select the entire string */
				}


				if (dialogDone != bad_result) {
					GetDItem( modifyDialog, SOURCE_FIELD, &itemType, &itemHandle, &itemRect );
					GetIText ((Handle)itemHandle, source_ptr );
					p2cstr( source_ptr );
					util_remove_leading_blanks( source_ptr );
					FIELD_TEST2(source_ptr,"");	 /* set's dialogDone to bad if error found */
					if (dialogDone == bad_result)
						SelIText( modifyDialog, SOURCE_FIELD, 0, 32767);	/* select the entire string */
				}
				
				GetDItem( modifyDialog, FOLDER_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
				if (GetCtlValue( (ControlHandle)itemHandle))
					*menu_type = list;
				else {
					GetDItem( modifyDialog, DOCUMENT_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
					*menu_type = GetCtlValue( (ControlHandle)itemHandle) ? text : gif;
				}
				break;
				
			case CANCEL_BUTTON:
				dialogDone = cancel_result;
				break;
				
			case MORE_BUTTON:
				GetDItem( modifyDialog, KEYWORDS_FIELD, &itemType, &itemHandle, &itemRect );
				GetIText ((Handle)itemHandle, topic_ptr );
				p2cstr( topic_ptr );
				
				GetDItem( modifyDialog, TITLE_FIELD, &itemType, &itemHandle, &itemRect );
				GetIText ((Handle)itemHandle, title_ptr );
				p2cstr( title_ptr );

				GetDItem( modifyDialog, SOURCE_FIELD, &itemType, &itemHandle, &itemRect );
				GetIText ((Handle)itemHandle, source_ptr );
				p2cstr( source_ptr );
				
				p2cstr( parent_ptr );
				
				GetDItem( modifyDialog, FOLDER_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
				if (GetCtlValue( (ControlHandle)itemHandle))
					*menu_type = list;
				else {
					GetDItem( modifyDialog, DOCUMENT_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
					*menu_type = GetCtlValue( (ControlHandle)itemHandle) ? text : gif;
				}
				
				dialogDone = more_result;
				break;
				
			case FOLDER_RADIO_BUTTON:
				GetDItem( modifyDialog, FOLDER_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, ON );
				GetDItem( modifyDialog, DOCUMENT_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, OFF );
				GetDItem( modifyDialog, IMAGE_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, OFF );
				GetDItem( modifyDialog, MORE_BUTTON, &itemType, &itemHandle, &itemRect );
				HiliteControl( (ControlHandle)itemHandle, 255);	/* disable the more button */
				break;
				
			case DOCUMENT_RADIO_BUTTON:
				GetDItem( modifyDialog, FOLDER_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, OFF );
				GetDItem( modifyDialog, DOCUMENT_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, ON );
				GetDItem( modifyDialog, IMAGE_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, OFF );
				GetDItem( modifyDialog, MORE_BUTTON, &itemType, &itemHandle, &itemRect );
				HiliteControl( (ControlHandle)itemHandle, 0);	/* enable the more button */
				break;
				
			case IMAGE_RADIO_BUTTON:
				GetDItem( modifyDialog, FOLDER_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, OFF );
				GetDItem( modifyDialog, DOCUMENT_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, OFF );
				GetDItem( modifyDialog, IMAGE_RADIO_BUTTON, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, ON );
				GetDItem( modifyDialog, MORE_BUTTON, &itemType, &itemHandle, &itemRect );
				HiliteControl( (ControlHandle)itemHandle, 0);	/* enable the more button */
				break;
		}
	}
	
	DisposDialog( modifyDialog );
	SetPort( oldPort );
	
	return dialogDone;
}

/*     
 *
 * dlog_menu_item2:
 *
 * Display modify subject dialog, retrieve any changes and return button user clicked.
 *
 */
Boolean
dlog_menu_item2(filename_ptr,path_ptr,locker_ptr)
char	*filename_ptr;
char	*path_ptr;
char	*locker_ptr;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		modifyDialog;
	GrafPtr			oldPort;
	char			*cp;
	
	enum {bad_result = -1, cancel_result = 0, ok_result, more_result};
	
	modifyDialog = GetNewDialog( DEFINE_ITEM_DIALOG2, NIL_POINTER, (WindowPtr)-1 );
	
	/* we need to change the port inorder to draw the default button frame */
	GetPort( &oldPort );
	SetPort( modifyDialog );
	
	GetDItem( modifyDialog, FILENAME_FIELD, &itemType, &itemHandle, &itemRect );
	c2pstr( filename_ptr );
	SetIText( itemHandle, filename_ptr );
	
	GetDItem( modifyDialog, PATH_FIELD, &itemType, &itemHandle, &itemRect );
	c2pstr( path_ptr );
	SetIText( itemHandle, path_ptr );	
	
	GetDItem( modifyDialog, LOCKER_FIELD, &itemType, &itemHandle, &itemRect );
	c2pstr( locker_ptr );
	SetIText( itemHandle, locker_ptr );
		
	ShowWindow( modifyDialog ); 
	
	dialogDone = bad_result;
	while ( dialogDone == bad_result )  {
		/* setup default button frame */
		GetDItem( modifyDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
		PenSize(3,3);
		InsetRect(&itemRect,-4,-4);
		FrameRoundRect(&itemRect,16,16);
		
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				
				/* 	set end of loop control to true.  this will get set back to false		
					if the user left empty fields in the dialog box.  We really need
					to give some sort of helpfull message when this happens. */
				dialogDone = ok_result;
				
				GetDItem( modifyDialog, FILENAME_FIELD, &itemType, &itemHandle, &itemRect );
				GetIText ((Handle)itemHandle, filename_ptr );
				p2cstr( filename_ptr );
				util_remove_leading_blanks( filename_ptr );
				FIELD_TEST5(filename_ptr,"");  /* set's dialogDone to bad if error found */
				if (dialogDone == bad_result)
					SelIText( modifyDialog, FILENAME_FIELD, 0, 32767);	/* select the entire string */

					
				if (dialogDone != bad_result) {
					GetDItem( modifyDialog, PATH_FIELD, &itemType, &itemHandle, &itemRect );
					GetIText ((Handle)itemHandle, path_ptr );
					p2cstr( path_ptr );
					util_remove_leading_blanks( path_ptr );
					FIELD_TEST3(path_ptr,""); /* set's dialogDone to bad if error found */
					if (dialogDone == bad_result)
						SelIText( modifyDialog, PATH_FIELD, 0, 32767);	/* select the entire string */
				}
				
				if (dialogDone != bad_result) {
					GetDItem( modifyDialog, LOCKER_FIELD, &itemType, &itemHandle, &itemRect );
					GetIText ((Handle)itemHandle, locker_ptr );
					p2cstr( locker_ptr );
					util_remove_leading_blanks( locker_ptr );
					FIELD_TEST1(locker_ptr,"");	 /* set's dialogDone to bad if error found */	
					if (dialogDone == bad_result)
						SelIText( modifyDialog, LOCKER_FIELD, 0, 32767);	/* select the entire string */
				}
				
				break;
				
			case CANCEL_BUTTON:
				p2cstr( filename_ptr );
				p2cstr( path_ptr );
				p2cstr( locker_ptr );
				dialogDone = cancel_result;
				break;
				
		}
	}
	
	DisposDialog( modifyDialog );
	SetPort( oldPort );
	
	return dialogDone;
}

/*
 *	SendDialog
 *
 *
 */
Boolean
SendDialog( commandStr )
char			*commandStr;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		sendDialog;
	GrafPtr			oldPort;
	
	sendDialog = GetNewDialog( SEND_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	 
	*commandStr = '\0';
	GetDItem( sendDialog, USER_INPUT, &itemType, &itemHandle, &itemRect );
	c2pstr( commandStr );
	SetIText( itemHandle, commandStr );
	
	ShowWindow( sendDialog ); 
	
	GetPort( &oldPort );
	SetPort( sendDialog );
	
	/* let's put up a default button to keep with mac standards */
	GetDItem( sendDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);
	
	dialogDone = -1;
	while ( dialogDone < 0 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				dialogDone = true;
				GetDItem( sendDialog, USER_INPUT, &itemType, &itemHandle, &itemRect);
				GetIText ((Handle)itemHandle, commandStr );
				p2cstr(commandStr);
				break;
				
			case CANCEL_BUTTON:
				dialogDone = false;
				break;
		}
	}
	
	DisposDialog( sendDialog );
	SetPort( oldPort );
	
	return dialogDone;
}

/*     
 *
 * dlog_get_file:
 * 
 *
 */
Boolean
dlog_get_file(refNum,name)
short	*refNum;
char	*name;
{
	Point		where;
	Str255		prompt;
	int			numTypes;
	SFTypeList	typeList;
	SFReply		reply;
	
	/* bring up "get file" dialog box */
	where.v = 50;
	where.h = 50;
	numTypes = 1;
	typeList[0] = 1413830740;
	SFGetFile(where, prompt, 0L, numTypes, typeList, 0L, &reply );
	
	/* return these values from the SFGetFile routine if user did not cancel dialog */
	if (reply.good) {
		*refNum = reply.vRefNum;
		strcpy(name,reply.fName);
	}
	
	return reply.good;
}

/*     
 *
 * dlog_find_string: 
 * 
 *
 */
Boolean
dlog_find_string( search, case_flag, beginning_flag )
char		*search;
Boolean		*case_flag;
Boolean		*beginning_flag;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		findsearchDialog;
	GrafPtr			oldPort;
	
	findsearchDialog = GetNewDialog( FIND_STRING_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	if ( findsearchDialog == NULL )
		BigBadError(NO_MEMORY);
		
	GetPort( &oldPort );
	SetPort( findsearchDialog );
	
	ShowWindow( findsearchDialog ); 
	
	/* display last user input in the dialog box */
	GetDItem( findsearchDialog, STRING, &itemType, &itemHandle, &itemRect );
	c2pstr( search );
	SetIText( (Handle)itemHandle, search );
	SelIText( findsearchDialog, STRING, 0, 32767);	/* select the entire search */
	
	GetDItem( findsearchDialog, CASE_CHECKBOX, &itemType, &itemHandle, &itemRect );
	SetCtlValue ( (ControlHandle)itemHandle, *case_flag );
		
	GetDItem( findsearchDialog, BEGINNING_CHECKBOX, &itemType, &itemHandle, &itemRect );
	SetCtlValue ( (ControlHandle)itemHandle, *beginning_flag );
	
	/* let's put up a default button to keep with mac standards */
	GetDItem( findsearchDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);
	
	dialogDone = -1;
	while ( dialogDone < 0 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				GetDItem( findsearchDialog, STRING, &itemType, &itemHandle,
					&itemRect );
				GetIText ((Handle)itemHandle, search );
				
				GetDItem( findsearchDialog, CASE_CHECKBOX, &itemType, &itemHandle, &itemRect );
				*case_flag = GetCtlValue( (ControlHandle)itemHandle );
				
				GetDItem( findsearchDialog, BEGINNING_CHECKBOX, &itemType, &itemHandle, &itemRect );
				*beginning_flag = GetCtlValue( (ControlHandle)itemHandle );
				
				dialogDone = true;
				break;
				
			case CANCEL_BUTTON:
				dialogDone = false;
				break;
				
			case CASE_CHECKBOX: 
				GetDItem( findsearchDialog, CASE_CHECKBOX, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, 
					!(GetCtlValue( (ControlHandle)itemHandle ) ) ); 
				break;
			
			case BEGINNING_CHECKBOX: 
				GetDItem( findsearchDialog, BEGINNING_CHECKBOX, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, 
					!(GetCtlValue( (ControlHandle)itemHandle ) ) ); 
				break;
		}
	}
	
	DisposDialog( findsearchDialog );
	SetPort( oldPort );
	p2cstr( search );                     /* convert pascal search to C search */
	
	if (dialogDone  && search[0] > 0) 
		return true;	 					
	else
		return false;
}

/*     
 *
 * dlog_put_file:
 * 
 *
 */
Boolean
dlog_put_file(refNum,name)
short	*refNum;
char	*name;
{
	Point		where;
	SFReply		reply;
	
	/* bring up "get file" dialog box */
	where.v = 50;
	where.h = 50;
	SFPutFile(where, "\pSave Text as:", "", nil, &reply );
	
	if (reply.good) {
		*refNum = reply.vRefNum;
		strcpy(name,reply.fName);
	}
	
	return reply.good;
}

/*     
 *
 * dlog_get_info: 
 * 
 *	This routine is called to either create or update an existing getinfo window.
 *
 */
WindowPtr
dlog_get_info( window,title,source,path,type,id,long_caption,name,email,phone,topic )
WindowPtr	window;
char		*title;
char		*source;
char		*path;
char		*type;
char		*id;
char		*long_caption;
char		*name;
char		*email;
char		*phone;
char		*topic;
{
	DialogPtr		getInfoDialog;
	GrafPtr			oldPort;
	short			itemType;
	Rect			itemRect;
	Handle			itemHandle;
	Handle			tempH = NULL;
	
	if ( window == NULL ) {
		
		getInfoDialog = GetNewDialog( GETINFO_DIALOG, NIL_POINTER, (WindowPtr)-1L ); 
	
		if ( getInfoDialog == NULL ) {
			OpenAlertDialog(NO_DIALOG,"Get Info");
			return(NULL);
		}
		wind_set_type(getInfoDialog,getinfo);
		ShowWindow(getInfoDialog);
	}
	else
		getInfoDialog = window;
		
	/* we should not have changed the windowclass, but we did, so */
	/* change it back for this routine */
	/* it wants to be a dialog for drawing */
	/* someday, this will be a real window */
	wind_set_type(getInfoDialog,dialogKind);

	GetPort( &oldPort );
	SetPort( getInfoDialog );
	TextSize(9);
	TextFont(3); /* geneva */
	
	TextFace(bold);
	GetDItem( getInfoDialog, 3, &itemType, &itemHandle, &itemRect );
	SetIText( itemHandle, "\pShort Source:" );
	
	GetDItem( getInfoDialog, 5, &itemType, &itemHandle, &itemRect );
	SetIText( itemHandle, "\pContact:" );
	
	GetDItem( getInfoDialog, 9, &itemType, &itemHandle, &itemRect );
	SetIText( itemHandle, "\pID:" );
	
	GetDItem( getInfoDialog, 11, &itemType, &itemHandle, &itemRect );
	SetIText( itemHandle, "\pEmail:" );
	
	GetDItem( getInfoDialog, 13, &itemType, &itemHandle, &itemRect );
	SetIText( itemHandle, "\pPhone:" );
	
	GetDItem( getInfoDialog, 15, &itemType, &itemHandle, &itemRect );
	SetIText( itemHandle, "\pLong Source:" );
	
	GetDItem( getInfoDialog, 18, &itemType, &itemHandle, &itemRect );
	SetIText( itemHandle, "\pKeyword List:" );
	
	if (*type == TEXT_ITEM || *type == IMAGE_ITEM) {
		GetDItem( getInfoDialog, 7, &itemType, &itemHandle, &itemRect );
		SetIText( itemHandle, "\pPath:" );
	}
	else {
		GetDItem( getInfoDialog, 7, &itemType, &itemHandle, &itemRect );
		SetIText( itemHandle, "\p" );
	}
	
	TextFace(normal);
	
	GetDItem( getInfoDialog, 2, &itemType, &itemHandle, &itemRect );
	c2pstr( title );
	SetIText( itemHandle, title );
	
	GetDItem( getInfoDialog, 4, &itemType, &itemHandle, &itemRect );
	c2pstr( source );
	SetIText( itemHandle, source );
	
	GetDItem( getInfoDialog, 6, &itemType, &itemHandle, &itemRect );
	c2pstr( name );
	SetIText( itemHandle, name );
	
	GetDItem( getInfoDialog, 10, &itemType, &itemHandle, &itemRect );
	c2pstr( id );
	SetIText( itemHandle, id );
	
	GetDItem( getInfoDialog, 12, &itemType, &itemHandle, &itemRect );
	c2pstr( email  );
	SetIText( itemHandle, email );

	GetDItem( getInfoDialog, 14, &itemType, &itemHandle, &itemRect );
	c2pstr( phone  );
	SetIText( itemHandle, phone );
	
	GetDItem( getInfoDialog, 16, &itemType, &itemHandle, &itemRect );
	c2pstr( long_caption  );
	SetIText( itemHandle, long_caption );
	
	GetDItem( getInfoDialog, 19, &itemType, &itemHandle, &itemRect );
	c2pstr( topic  );
	SetIText( itemHandle, topic );

	GetDItem( getInfoDialog, 8, &itemType, &itemHandle, &itemRect );
	c2pstr( path );
	SetIText( itemHandle, path );
	
	switch(*type){
		case MENU_ITEM:
			tempH = GetResource(ICN,FOLDER_ICON);	
			break;
		case TEXT_ITEM:
			tempH = GetResource(ICN,DOCUMENT_ICON);	
			break;
		case IMAGE_ITEM:
			tempH = GetResource(ICN,IMAGE_ICON);
			break;
		case SERVER_ITEM:
			tempH = GetResource(ICN,PIPS_ICON);
			break;
		case PHONE_ITEM:
			tempH = GetResource(ICN,PHONE_ICON);
			break;
		default:
			tempH = GetResource(ICN,PIPS_ICON);	
			break;
	}
				
	if ( tempH != NULL ) {
		GetDItem( getInfoDialog, 1, &itemType, &itemHandle, &itemRect );
		PlotIcon(&itemRect,tempH);
	} 
	
	BeginUpdate( getInfoDialog ); 
	DrawDialog( getInfoDialog );
	EndUpdate( getInfoDialog );
	
	/* reset the window class */
	wind_set_type(getInfoDialog,getinfo);

	SetPort( oldPort ); 
	
	/* if we created a new dialog, then return the dialogPtr */ 
	return((WindowPtr) getInfoDialog);
}


/*     
 *
 * 	dlog_help:
 * 
 *	Put up a Help Alert.
 *
 */
void
dlog_help()
{
	short		itemHit;
	
	itemHit = NoteAlert ( HELP_ID, NIL_POINTER );
	
} /* dlog_help */

/*
 *	dlog_disclaimer
 *
 *
 */
Boolean
dlog_disclaimer()
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		disclaimerDialog;
	GrafPtr			oldPort;
	Handle			tempH = NULL;
	
	disclaimerDialog = GetNewDialog( DISCLAIMER_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	
	GetPort( &oldPort );
	SetPort( disclaimerDialog );
	
	/* let's put up a default button to keep with mac standards */
	GetDItem( disclaimerDialog, CONTINUE_BUTTON, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);
	
	tempH = GetResource(ICN,128);		
	if ( tempH != NULL ) {
		GetDItem( disclaimerDialog, LOGO, &itemType, &itemHandle, &itemRect );
		PlotIcon(&itemRect,tempH);
	}
	
	ShowWindow( disclaimerDialog ); 
	
	dialogDone = -1;
	while ( dialogDone < 0 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case CONTINUE_BUTTON:
				dialogDone = true;
				break;
			case STOP_BUTTON:
				dialogDone = false;
				break;
		}
	}
	
	DisposDialog( disclaimerDialog );
	SetPort( oldPort );
	
	return dialogDone;
}

/*
 *	DeleteDialog
 *
 *
 */
Boolean
DeleteDialog(menu_ptr)
char *menu_ptr;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		deleteDialog;
	GrafPtr			oldPort;
	
	deleteDialog = GetNewDialog( DELETE_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	
	ShowWindow( deleteDialog ); 
	
	GetPort( &oldPort );
	SetPort( deleteDialog );
	
	/* display item that is to be deleted */
	GetDItem( deleteDialog, REMOVE_WHAT, &itemType, &itemHandle, &itemRect );
	c2pstr( menu_ptr );
	SetIText( itemHandle, menu_ptr );
	
	/* let's put up a default button to keep with mac standards */
	GetDItem( deleteDialog, CANCEL_REMOVE, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);
	
	dialogDone = -1;
	while ( dialogDone < 0 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_REMOVE:
				dialogDone = true;
				break;
				
			case CANCEL_REMOVE:
				dialogDone = false;
				break;
		}
	}
	
	DisposDialog( deleteDialog );
	SetPort( oldPort );
	
	return dialogDone;
}

/*     
 *
 * dlog_thermometer: 
 * 
 *
 */
dlog_thermometer(action,myDialog,percent,title)
short		action;
DialogPtr	*myDialog;
float		percent;
Str255		title;
{
	short		itemType;
	Rect		itemRect;
	Handle		itemHandle;
	GrafPtr		oldPort;
	int			width;
	
	enum{init,show,close};
	
	switch (action) {
		case init:
			*myDialog = GetNewDialog( THERMOMETER_DIALOG, NIL_POINTER, (WindowPtr)-1 );
			
			GetPort( &oldPort );
			SetPort( *myDialog );
			
			ShowWindow( *myDialog );
			
			GetDItem( *myDialog,MESSAGE_BOX, &itemType, &itemHandle, &itemRect );
			SetIText(itemHandle,"\pPress \021. to abort");
			
			GetDItem( *myDialog,TITLE_BOX, &itemType, &itemHandle, &itemRect );
			SetIText( itemHandle, title );
			
			GetDItem( *myDialog,CONTROL, &itemType, &itemHandle, &itemRect );
			FrameRect(&itemRect);
			
			SetPort( oldPort );
			
			break;
			
		case show:
			GetPort( &oldPort );
			SetPort( *myDialog );

			GetDItem( *myDialog,CONTROL, &itemType, &itemHandle, &itemRect );
			width = itemRect.right - itemRect.left;
			itemRect.right = itemRect.left + (int)(width * percent);
			FillRect(&itemRect,&qd.black);
			
			SetPort( oldPort );
			break;
			
		case close:
			DisposDialog( *myDialog );
	}
}

/*
 *	DeleteDialog
 *
 *
 */
Boolean
dlog_replace(menu_ptr)
char *menu_ptr;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		replaceDialog;
	GrafPtr			oldPort;
	
	replaceDialog = GetNewDialog( REPLACE_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	
	ShowWindow( replaceDialog ); 
	
	GetPort( &oldPort );
	SetPort( replaceDialog );
	
	/* display item that is to be deleted */
	GetDItem( replaceDialog, REPLACE_WHAT, &itemType, &itemHandle, &itemRect );
	/* truncate string if needed, not best algorithm as it should really 
		look at character width, etc... */
	if (strlen(menu_ptr) > 30) {
		menu_ptr[29] = 'É';
		menu_ptr[30] = NULL;
	}
	c2pstr( menu_ptr );
	SetIText( itemHandle, menu_ptr );
	
	/* let's put up a default button to keep with mac standards */
	GetDItem( replaceDialog, CANCEL_REPLACE, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);
	
	dialogDone = -1;
	while ( dialogDone < 0 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_REPLACE:
				dialogDone = true;
				break;
				
			case CANCEL_REPLACE:
				dialogDone = false;
				break;
		}
	}
	
	DisposDialog( replaceDialog );
	SetPort( oldPort );
	
	return dialogDone;
}

/*
 *	PreferenceDialog
 *
 *
 */
PreferenceDialog( )
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		preferenceDialog;
	GrafPtr			oldPort;
	Str255			cwis_server;
	Str255			cwis_port;
	Str255			disclaimer;
	Str255			outline_depth;
	Str255			cwis_server_old;
	Str255			cwis_port_old;
	Boolean			disclaimer_old;
	Str255			outline_depth_old;
	char			*c;
	char			window_startup[6];
	Boolean			window_settings;
	
	/* get resources */
	preferenceDialog = GetNewDialog( PREFERENCES_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	pref_get_string(SERVER_NAME, cwis_server);
	pref_get_string(SERVER_PORT, cwis_port);
	pref_get_string(SHOW_DISCLAIMER, disclaimer);
	pref_get_string(OUTLINE_DEPTH, outline_depth);
	pref_get_string(WINDOW_STARTUP, window_startup);
	
	/* save original */
	strcpy(cwis_server_old,cwis_server);
	strcpy(cwis_port_old,cwis_port);
	strcpy(outline_depth_old,outline_depth);
	
	ShowWindow( preferenceDialog ); 
	
	GetPort( &oldPort );
	SetPort( preferenceDialog );
	
	/* display outline depth */
	GetDItem( preferenceDialog, OUTLINE_ITEM, &itemType, &itemHandle, &itemRect );
	c2pstr( outline_depth );
	SetIText( itemHandle, outline_depth );
	
	/* display server name */
	GetDItem( preferenceDialog, HOST_ITEM, &itemType, &itemHandle, &itemRect );
	c2pstr( cwis_server );
	SetIText( itemHandle, cwis_server );
	
	/* display server port */
	GetDItem( preferenceDialog, PORT_ITEM, &itemType, &itemHandle, &itemRect );
	c2pstr( cwis_port );
	SetIText( itemHandle, cwis_port );
	
	GetDItem( preferenceDialog, DISCLAIMER_ITEM, &itemType, &itemHandle, &itemRect );
	if ( !strcmp(disclaimer,"true" ) ) {
		SetCtlValue ( (ControlHandle)itemHandle, true ); 
		disclaimer_old = true;
	}
	else  {
		SetCtlValue ( (ControlHandle)itemHandle, false ); 
		disclaimer_old = false;
	}

	/* display check box for window setup */
	GetDItem( preferenceDialog, WINDOW_SETTINGS, &itemType, &itemHandle, &itemRect );
	if (!strcmp("true",window_startup)) 
		window_settings = true;
	else
		window_settings = false;
	SetCtlValue ( (ControlHandle)itemHandle, window_settings);

	/* let's put up a default button to keep with mac standards */
	GetDItem( preferenceDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);
	
	dialogDone = false;
	while ( dialogDone != true )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				dialogDone = true;
				
				GetDItem( preferenceDialog, OUTLINE_ITEM, &itemType, &itemHandle, &itemRect );				
				GetIText ((Handle)itemHandle, outline_depth );
				p2cstr(outline_depth);
				if (strcmp(outline_depth,outline_depth_old)) {
					for(c = outline_depth; *c != NULL; c++)
						if (!isdigit(*c)) dialogDone = false;
					if (dialogDone && (atoi(outline_depth) > 0) && 
						(atoi(outline_depth) < 100))
						pref_put_string(OUTLINE_DEPTH, outline_depth);
					else {
						dialogDone = false;
						SetIText( itemHandle, "\pHuh?" );
						SysBeep(1);
					}
				}
				
				GetDItem( preferenceDialog, HOST_ITEM, &itemType, &itemHandle, &itemRect );				
				GetIText ((Handle)itemHandle, cwis_server );
				p2cstr(cwis_server);
				if (strcmp(cwis_server,cwis_server_old)) {
					if (*cwis_server != NULL && strcmp(cwis_port,"Huh?"))
						pref_put_string(SERVER_NAME, cwis_server);
					else {
						dialogDone = false;
						SetIText( itemHandle, "\pHuh?" );
						SysBeep(1);
					}
				}
				
				GetDItem( preferenceDialog, PORT_ITEM, &itemType, &itemHandle, &itemRect );				
				GetIText ((Handle)itemHandle, cwis_port );
				p2cstr(cwis_port);
				if (strcmp(cwis_port,cwis_port_old)) {
					if (*cwis_port != NULL && strcmp(cwis_port,"Huh?"))
						pref_put_string(SERVER_PORT, cwis_port);
					else {
						dialogDone = false;
						SetIText( itemHandle, "\pHuh?" );
						SysBeep(1);
					}
				}

				GetDItem( preferenceDialog, DISCLAIMER_ITEM, &itemType, &itemHandle, &itemRect );
				if (disclaimer_old != GetCtlValue( (ControlHandle)itemHandle))
					pref_put_string(SHOW_DISCLAIMER,
					GetCtlValue( (ControlHandle)itemHandle) ? "true" : "false");
					
				GetDItem( preferenceDialog, WINDOW_SETTINGS, &itemType, &itemHandle, &itemRect );
				if (window_settings != GetCtlValue( (ControlHandle)itemHandle))
					pref_put_string(WINDOW_STARTUP,
					GetCtlValue( (ControlHandle)itemHandle) ? "true" : "false");

				break;
				
			case CANCEL_BUTTON:
				dialogDone = true;
				break;
				
			case DISCLAIMER_ITEM:
				GetDItem( preferenceDialog, DISCLAIMER_ITEM, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, !( GetCtlValue( (ControlHandle)itemHandle )) ); 
				break;
				
			case WINDOW_SETTINGS:
				GetDItem( preferenceDialog, WINDOW_SETTINGS, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, !( GetCtlValue( (ControlHandle)itemHandle )) ); 
				break;
		}
	}
	
	DisposDialog( preferenceDialog );
	SetPort( oldPort );
	
}

/*
 *	User Startup Dialog
 *
 *
 */
Boolean
StartupDialog(list_button,text_button, list_title, text_title )
Boolean	*list_button;
Boolean *text_button;
Str255	list_title;
Str255	text_title;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		setstartupDialog;
	GrafPtr			oldPort;
	
	setstartupDialog = GetNewDialog( SETSTARTUP_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	ShowWindow( setstartupDialog ); 
	
	GetPort( &oldPort );
	SetPort( setstartupDialog );
	
	GetDItem( setstartupDialog, RADIO_LIST, &itemType, &itemHandle, &itemRect );
	if (*list_title != NULL) {
		if (*list_button)
			SetCtlValue ( (ControlHandle)itemHandle, true); 
		else
			SetCtlValue ( (ControlHandle)itemHandle, false); 
		SetCTitle( (ControlHandle)itemHandle, (Str255)c2pstr(list_title) );
	}
	else
		/* make control inactive */
		HiliteControl((ControlHandle)itemHandle, 255);

	
	GetDItem( setstartupDialog, RADIO_TEXT, &itemType, &itemHandle, &itemRect );
	if (*text_title != NULL) {
		if (*text_button)
			SetCtlValue ( (ControlHandle)itemHandle, true); 
		else
			SetCtlValue ( (ControlHandle)itemHandle, false); 
		SetCTitle( (ControlHandle)itemHandle, (Str255)c2pstr(text_title) );
	}
	else
		/* make control inactive */
		HiliteControl((ControlHandle)itemHandle, 255);

	
	/* let's put up a default button to keep with mac standards */
	GetDItem( setstartupDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);

	dialogDone = -1;
	while ( dialogDone == -1 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				GetDItem( setstartupDialog, RADIO_LIST, &itemType, &itemHandle, &itemRect );
				*list_button = GetCtlValue( (ControlHandle)itemHandle);
				
				GetDItem( setstartupDialog, RADIO_TEXT, &itemType, &itemHandle, &itemRect );
				*text_button = GetCtlValue( (ControlHandle)itemHandle);
				dialogDone = true;
				break;

			case CANCEL_BUTTON:
				dialogDone = false;
				break;
				
			case RADIO_LIST:
				GetDItem( setstartupDialog, RADIO_LIST, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, !( GetCtlValue( (ControlHandle)itemHandle )) );
				break;
				
			case RADIO_TEXT:
				GetDItem( setstartupDialog, RADIO_TEXT, &itemType, &itemHandle, &itemRect );
				SetCtlValue ( (ControlHandle)itemHandle, !( GetCtlValue( (ControlHandle)itemHandle )) );
				break;
		}
	}

	DisposDialog( setstartupDialog );
	SetPort( oldPort );

	return dialogDone;
}

/*
 *	dlog_about alert dialog box
 *
 *
 */
dlog_about()
{
	Str255		apName;
	VersRecHndl	curVersion;
	Str255		verNum = "\p????";
	Ptr			verNumLocation;

	/* get application name */
	pref_get_string(APPLICATION_NAME,apName);
	c2pstr(apName);
	
	/* get version number */
	curVersion = (VersRecHndl) GetAppResource('vers', 1);
	if (curVersion != nil) {
		verNumLocation = (Ptr) ((long)(**curVersion).shortVersion
						+ (long)*(**curVersion).shortVersion + 1);
		PStrCopy(verNum, verNumLocation);
	}

	ParamText(apName, verNum, "\p", "\p");

	(void) CenteredAlert(ABOUT_ALERT);
	
}

/* field can not be null, contain the transaction delimiter or contain a blank */
#define FIELD_TEST4(n,m) { \
	if ( atoi(n) <=0 || atoi(n) > 60) {\
			dialogDone = bad_result; \
			OpenAlertDialog(FIELD_ENTRY_ERROR4,m);} \
}

/*
 *	dlog_prov_options 
 *	provider settable options
 *
 */
Boolean
dlog_prov_options(char *optionsStr, char *tab) 
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		optionsDialog;
	GrafPtr			oldPort;
	char			*cp;
	
	enum {bad_result = -1, cancel_result = 0, ok_result};

	optionsDialog = GetNewDialog( PROVIDER_OPTIONS_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	ShowWindow( optionsDialog ); 
	
	GetPort( &oldPort );
	SetPort( optionsDialog );
	
	GetDItem( optionsDialog, STORE_DIRECTORY, &itemType, &itemHandle, &itemRect );
	c2pstr( optionsStr );
	SetIText( (Handle)itemHandle, optionsStr );
	
	GetDItem( optionsDialog, TAB_SETTING_VALUE, &itemType, &itemHandle, &itemRect );
	c2pstr( tab );
	SetIText( (Handle)itemHandle, tab );
	SelIText( optionsDialog, TAB_SETTING_VALUE, 0, 32767);	
	
	/* let's put up a default button to keep with mac standards */
	GetDItem( optionsDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);

	dialogDone = -1;
	while ( dialogDone == -1 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				dialogDone = true;

				GetDItem( optionsDialog, STORE_DIRECTORY, &itemType, &itemHandle, &itemRect );
				GetIText ((Handle)itemHandle, optionsStr );
				p2cstr(optionsStr);
				FIELD_TEST1(optionsStr,"");	 /* set's dialogDone to bad if error found */	
				if (dialogDone == bad_result)
					SelIText( optionsDialog, STORE_DIRECTORY, 0, 32767);	/* select the entire string */

				if (dialogDone != bad_result) {
					GetDItem( optionsDialog, TAB_SETTING_VALUE, &itemType, &itemHandle, &itemRect );
					GetIText ((Handle)itemHandle, tab  );
					p2cstr(tab);
					FIELD_TEST4(tab,"");	 /* set's dialogDone to bad if error found */	
					if (dialogDone == bad_result)
						SelIText( optionsDialog, TAB_SETTING_VALUE, 0, 32767);	/* select the entire string */
				}

				break;

			case CANCEL_BUTTON:
				dialogDone = false;
				break;
				
		}
	}

	DisposDialog( optionsDialog );
	SetPort( oldPort );

	return dialogDone;
}

/*
 *	dlog_send_document
 *
 *
 */
Boolean
dlog_send_document( title )
char			*title;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		sendDialog;
	GrafPtr			oldPort;
	
	sendDialog = GetNewDialog( SEND_DOCUMENT_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	 
	GetDItem( sendDialog, DOCUMENT_NAME, &itemType, &itemHandle, &itemRect );
	c2pstr( title );
	SetIText( itemHandle, title );
	
	ShowWindow( sendDialog ); 
	
	GetPort( &oldPort );
	SetPort( sendDialog );
	
	/* let's put up a default button to keep with mac standards */
	GetDItem( sendDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);
	
	dialogDone = -1;
	while ( dialogDone < 0 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				dialogDone = true;
				break;
				
			case CANCEL_BUTTON:
				dialogDone = false;
				break;
		}
	}
	
	DisposDialog( sendDialog );
	SetPort( oldPort );
	
	return dialogDone;
}

typedef struct {
	TEHandle passTeH;
} LDialogStg, *LDialogStgPtr;

/*     
 *
 * dlog_login: 
 * 
 * get username and password
 */
Boolean
dlog_login( username, password )
char			*username;
char			*password;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		askIdDialog;
	GrafPtr			oldPort;
	Rect			aRect;
	LDialogStg		LDStg;
	Handle			usernameHandle;
	Rect			okbuttonRect;

	askIdDialog = GetNewDialog( ASK_ID, NIL_POINTER, (WindowPtr)-1 );
	
	if (askIdDialog == NULL)
		BigBadError(NO_MEMORY);

	GetPort( &oldPort );
	SetPort( askIdDialog );
	
	/*  make an offscreen rect for the text edit to hold the plain
		text of the entered password */
	SetRect(&aRect,0,0,1,1);
	OffsetRect(&aRect,askIdDialog->portRect.right,askIdDialog->portRect.bottom);
	LDStg.passTeH = TENew(&aRect,&aRect);
	
	/* store the text pointer to the dialog refcon */
	SetWRefCon(askIdDialog, (long) &LDStg);
		
	ShowWindow( askIdDialog ); 
	
	/* store some information */
	GetDItem( askIdDialog, USERNAME, &itemType, &usernameHandle, &itemRect );
	GetDItem( askIdDialog, OK_BUTTON, &itemType, &itemHandle, &okbuttonRect );
	InsetRect(&okbuttonRect,-4,-4);

	dialogDone = false;
	while( !((dialogDone && itemHit == OK_BUTTON) || (itemHit == CANCEL_BUTTON))) {
	
		GetIText ((Handle)usernameHandle, username );
		
		dialogDone = ((*LDStg.passTeH)->teLength > 0 && username[0] > 0);
		
		/* let's put up a default button to keep with mac standards */
		if (dialogDone) {
			PenSize(3,3);
			FrameRoundRect(&okbuttonRect,16,16);
		}
		else {
			/* turn off any hilighting */
			PenMode(notPatCopy);
			FrameRoundRect(&okbuttonRect,16,16);
			PenMode(patCopy); /* set default pattern */
		}
		
		HiliteControl((ControlHandle) itemHandle, dialogDone ? 0 : 255 );

		ModalDialog( (ModalFilterProcPtr) GetIdFilter,&itemHit);
	}
	
	if (itemHit == OK_BUTTON) {
		/* get the username field */
		GetIText ((Handle)usernameHandle, username );
		p2cstr( username );                     /* convert pascal string to C string */
		
		TECpyText(LDStg.passTeH,password);
		p2cstr(password);
	}
	else
		dialogDone = false;
		
	DisposDialog( askIdDialog );
	TEDispose(LDStg.passTeH);
	SetPort( oldPort );
	
	return dialogDone;
}

/*
 *	GetIdFilter:
 *
 * 	Trap password keystrokes and change it into apple mask for display, ie.
 *	don't actually display password.
 */
pascal Boolean 
GetIdFilter(theDialog, event, itemHit)
DialogPtr		theDialog;
EventRecord		*event;
short			*itemHit;
{
	register	key;
	int			field;
	TEPtr 		tePtr;
	LDialogStg	*ldStg;
	
	enum{CR=0x0d, DEL=0x7f, BS=0x08};
	
	/* let's get out of here if there was not a key stroke or insertion point */
	if (event->what != keyDown && event->what != autoKey )
		return false;
		
	/* get actual key stroke */
	key = event->message & charCodeMask;
	
	/* handle tab, ENTER and RETURN key strokes */
	switch(key) {
		case 9:	/* tab key - user switched dialog (username vs. password) */
			return false;
			break;
		case 3:	/* RETURN key */
		case 13:/* ENTER key  */
			*itemHit = 1;
			return true;
			break;
	}
		
	/* make sure the edit text item is the one we are interested in and
		check to see if the length is not too large */
	field = ((DialogPeek) theDialog)->editField+1;
	
	tePtr = *(((DialogPeek) theDialog)->textH);
	
	/* user is typing in the username - check length */
	if (field == USERNAME) {
	
		/* we don't allow colon's to be input */
		if (key == ':') {
			SysBeep(1);
			return(true); /* ignore the event */
		}
		
		/* make sure we don't exceed our bounds */
		if (TELengthCheck(tePtr,key,30)) {
			SysBeep(1);
			return(true);
		}
	}
	
	if (field == PASSWORD) {
	
		/* we need to check that the length is not too large */

		/* insert the character into our private password text edit record.
			first, set the text selection so action mimicks exactly what
			user is selecting and typing in the password text edit field.
		*/
		
		/* make sure we don't exceed our bounds */
		if (TELengthCheck(tePtr,key,30)) {
			SysBeep(1);
			return(true);
		}

		/* we don't allow colon's to be input */
		if (key == ':') {
			SysBeep(1);
			return(true); /* ignore the event */
		}

		ldStg = (LDialogStg *) GetWRefCon(theDialog);
		if (ldStg == 0)
			return (false);
		
		TESetSelect(tePtr->selStart,tePtr->selEnd,ldStg->passTeH);
		
		TEKey(key,ldStg->passTeH);
		
		if (key != DEL && key != BS)
			event -> message = appleMark;
		
		return(false);	/* return ok */
	}
	
	return(false);	/* all other items */
}

/*     
 *
 * dlog_source_info:
 *
 * Display modify subject dialog, retrieve any changes and return button user clicked.
 *
 */
Boolean
dlog_source_info(shortname_ptr, longname_ptr, contactname_ptr, phone_ptr, email_ptr)
char	*shortname_ptr;
char	*longname_ptr;
char	*phone_ptr;
char	*contactname_ptr;
char	*email_ptr;
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		modifyDialog;
	GrafPtr			oldPort;
	char			*cp;
		
	enum {bad_result = -1, cancel_result = 0, ok_result};

	modifyDialog = GetNewDialog( SOURCE_INFO_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	
	if ( modifyDialog == NULL ) {
		OpenAlertDialog(NO_DIALOG,"Source Info");
		return false;
	}

	/* we need to change the port inorder to draw the default button frame */
	GetPort( &oldPort );
	SetPort( modifyDialog );

	GetDItem( modifyDialog, SOURCE_SHORT_NAME_F, &itemType, &itemHandle, &itemRect );
	c2pstr( shortname_ptr );
	SetIText( itemHandle, shortname_ptr );
	
	GetDItem( modifyDialog, SOURCE_LONG_NAME_F, &itemType, &itemHandle, &itemRect );
	c2pstr( longname_ptr ); 
	SetIText( itemHandle, longname_ptr );	
	
	GetDItem( modifyDialog, SOURCE_PHONE_F, &itemType, &itemHandle, &itemRect );
	c2pstr( phone_ptr );
	SetIText( itemHandle, phone_ptr );
	
	GetDItem( modifyDialog, SOURCE_CONTACT_NAME_F, &itemType, &itemHandle, &itemRect );
	c2pstr( contactname_ptr );
	SetIText( itemHandle, contactname_ptr );
	
	GetDItem( modifyDialog, SOURCE_EMAIL_F, &itemType, &itemHandle, &itemRect );
	c2pstr( email_ptr );
	SetIText( itemHandle, email_ptr );

	ShowWindow( modifyDialog ); 
	
	dialogDone = bad_result;
	while ( dialogDone == bad_result )  {
		/* setup default button frame */
		GetDItem( modifyDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
		PenSize(3,3);
		InsetRect(&itemRect,-4,-4);
		FrameRoundRect(&itemRect,16,16);
		
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				dialogDone = ok_result;

				GetDItem( modifyDialog, SOURCE_SHORT_NAME_F, &itemType, &itemHandle, &itemRect );
				GetIText ((Handle)itemHandle, shortname_ptr );
				p2cstr(shortname_ptr);
				util_remove_leading_blanks( shortname_ptr );
				FIELD_TEST2(shortname_ptr,"");  /* set's dialogDone to bad if error found */
				if (dialogDone == bad_result)
					SelIText( modifyDialog, SOURCE_SHORT_NAME_F, 0, 32767);	/* select the entire string */
					
				if (dialogDone != bad_result) {
					GetDItem( modifyDialog, SOURCE_LONG_NAME_F, &itemType, &itemHandle, &itemRect );
					GetIText ((Handle)itemHandle, longname_ptr );
					p2cstr(longname_ptr);
					util_remove_leading_blanks( longname_ptr );
					FIELD_TEST2(longname_ptr,"");  /* set's dialogDone to bad if error found */
					if (dialogDone == bad_result)
						SelIText( modifyDialog, SOURCE_LONG_NAME_F, 0, 32767);	/* select the entire string */
				}
					
				if (dialogDone != bad_result) {
					GetDItem( modifyDialog, SOURCE_PHONE_F, &itemType, &itemHandle, &itemRect );
					GetIText ((Handle)itemHandle, phone_ptr );
					p2cstr(phone_ptr);
					FIELD_TEST1(phone_ptr,"");  /* set's dialogDone to bad if error found */
					if (dialogDone == bad_result)
						SelIText( modifyDialog, SOURCE_PHONE_F, 0, 32767);	/* select the entire string */
				}
				
				if (dialogDone != bad_result) {
					GetDItem( modifyDialog, SOURCE_CONTACT_NAME_F, &itemType, &itemHandle, &itemRect );
					GetIText ((Handle)itemHandle, contactname_ptr );
					p2cstr(contactname_ptr);
					FIELD_TEST1(contactname_ptr,"");  /* set's dialogDone to bad if error found */
					if (dialogDone == bad_result)
						SelIText( modifyDialog, SOURCE_CONTACT_NAME_F, 0, 32767);	/* select the entire string */
				}
				
				if (dialogDone != bad_result) {
					GetDItem( modifyDialog, SOURCE_EMAIL_F, &itemType, &itemHandle, &itemRect );
					GetIText ((Handle)itemHandle, email_ptr );
					p2cstr(email_ptr);
					FIELD_TEST1(email_ptr,"");  /* set's dialogDone to bad if error found */
					if (dialogDone == bad_result)
						SelIText( modifyDialog, SOURCE_EMAIL_F, 0, 32767);	/* select the entire string */
				}

				break;
				
			case CANCEL_BUTTON:
				dialogDone = cancel_result;
				break;
				
		}
	}
	
	DisposDialog( modifyDialog );
	SetPort( oldPort );
	
	return dialogDone;
}

/*
 *	dlog_send_document
 *
 *
 */
Boolean
dlog_version()
{
	short			itemType;
	short			itemHit;
	Rect			itemRect;
	Handle			itemHandle;
	int				dialogDone;
	DialogPtr		versionDialog;
	GrafPtr			oldPort;
	Str255			message;
	
	versionDialog = GetNewDialog( VERSION_DIALOG, NIL_POINTER, (WindowPtr)-1 );
	 
	GetDItem( versionDialog, DOCUMENT_NAME, &itemType, &itemHandle, &itemRect );
	GetIndString(message, MESSAGES, BAD_VERSION);
	SetIText( itemHandle, message );
	
	ShowWindow( versionDialog ); 
	
	GetPort( &oldPort );
	SetPort( versionDialog );
	
	/* let's put up a default button to keep with mac standards */
	GetDItem( versionDialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
	PenSize(3,3);
	InsetRect(&itemRect,-4,-4);
	FrameRoundRect(&itemRect,16,16);
	
	dialogDone = -1;
	while ( dialogDone < 0 )  {
		ModalDialog( NIL_POINTER, &itemHit ); 
		switch ( itemHit ) {
			case OK_BUTTON:
				dialogDone = true;
				break;
				
			case CANCEL_BUTTON:
				dialogDone = false;
				break;
		}
	}
	
	DisposDialog( versionDialog );
	SetPort( oldPort );
	
	return dialogDone;
}
