$( document ).ready( function() {

	// Build and initialise the generic dialog.
	var NewDiv = document.createElement( 'div' );
	NewDiv.id = 'GenericDialog';
	$( NewDiv ).css( 'display', 'none' );
	$( NewDiv ).html( '<p id="GenericDialogMessage"></p>' );
	document.body.appendChild( NewDiv );
	$( '#GenericDialog' ).dialog( { autoOpen: false, resizable: false, modal: true } );

	SimpleMessage = function( ProblemMessage, DialogTitle, DismissalFunction ) {
		// Display a simple message, with an "OK" button, an optional dialog title, and an optional function to be called when the dialog is dismissed.
		$( '#GenericDialog' ).dialog( 'option', 'title', ( DialogTitle ? DialogTitle : '' ) );
		$( '#GenericDialogMessage' ).html( ProblemMessage );
		$( '#GenericDialog' ).dialog( 'option', 'buttons', {
			OK: function() {
				$( this ).dialog( 'close' );
				if ( DismissalFunction ) DismissalFunction();
			}
		});
		$( '#GenericDialog' ).dialog( 'open' );
	}
	
	MakeChoice = function( ChoiceMessage, YesButtonTitle, YesButtonAction, NoButtonTitle, NoButtonAction, DialogTitle ) {
		// Allow the user to choose from two options. Action parameters are functions. Dialog title is optional.
		$( '#GenericDialog' ).dialog( 'option', 'title', ( DialogTitle ? DialogTitle : '' ) );
		$( '#GenericDialogMessage' ).html( ChoiceMessage );
		var ButtonList = {};
		ButtonList[YesButtonTitle] = function() { $( '#GenericDialog' ).dialog( 'close' ); YesButtonAction(); };
		ButtonList[NoButtonTitle]  = function() { $( '#GenericDialog' ).dialog( 'close' ); NoButtonAction(); };
		$( '#GenericDialog' ).dialog( 'option', 'buttons', ButtonList);
		$( '#GenericDialog' ).dialog( 'open' );
	}
	
});
