	// Diary Windows and the Status History window.

	var diaryWindow = null;
	var activeDiaryField = null;

	var formHTML = "<body><form name=\"diaryform\">\n";
	var diaryTableHTML = "<center><table border=0>\n";
	var diaryHistHTML1 = "<tr><td height=\"21\">Diary History:</td></tr>\n"
			+ "<tr><td height=\"100\"><textarea cols=\"55\" rows=\"6\" readonly wrap "
			+ "name=\"DiaryHistoryText\" onFocus=\"this.blur();\">\n";
	var diaryHistHTML2 = "</textarea></td></tr>\n";
	var diaryEditHTML1 = "<tr><td height=\"21\">Diary Editor:</td></tr>\n"
			+ "<tr><td height=\"97\"><textarea cols=\"55\" rows=\"6\" "
			+ "wrap name=\"DiaryEditorText\"";
	var diaryEditHTML2 = "</textarea></td></tr>\n";
	var okButtonHTML = "<tr><td height=\"10\"><div align=\"right\"><p>\n"
			+ "<input type=\"button\" value=\"Cancel\" name=\"Cancel\" "
			+ "onClick=\"window.close();\"></td></tr>\n";
	var okCancelButtonHTML = "<tr><td height=\"10\"><div align=\"right\"><p>\n"
			+ "<input type=\"button\" value=\"   OK   \" name=\"OK\" "
			+ "onClick=\"window.opener.setDiaryFieldValue(this.form.DiaryEditorText.value);"
			+ "window.close();\">\n"
			+ "<input type=\"button\" value=\"Cancel\" name=\"Cancel\" "
			+ "onClick=\"window.close();\"></td></tr>\n";
	var endHTML = "</table></center></form></body></html>\n";

	var diaryEditorHTML1 = "<center><table border=0>\n"
			+ "<tr><td height=\"16\">Diary Editor:</td></tr>\n"
			+ "<tr><td height=\"121\"><textarea cols=\"55\" rows=\"12\" "
			+ "wrap name=\"DiaryEditorText\"";
	var diaryEditorHTML2 = "</textarea></td></tr>\n";

	var statusHistWindow = null;

	// -----------------------------------------------------------------
	// Opens a diary window for the diary field specified. The diary window
	// contains a diary history field, and a diary editor field. 
	// The diary editor can be typed in, and if the user presses OK, the
	// value is sent to the field and the diary window closes.
	// -----------------------------------------------------------------
	function openDiary(fieldID, diaryHistory)
	{
		var field = getFieldInstanceByID(fieldID);
		var accessHTML = "";

		if (field.access == disabled) return;
		
		if (diaryWindow != null && !diaryWindow.closed)
		{
			// alert with message defined in arweb.jsp
			if (activeDiaryField != field.ctrl)
				alert( DiaryOpenMsgStr );
			diaryWindow.focus();
			return;
		}

		activeDiaryField = field.ctrl;
		diaryWindow = window.open("about:blank", 'diaryWindow',
			'toolbar=no,location=no,directories=no,dependent=yes' 
			+ 'status=no,menubar=no,scrollbars=yes,resizable=yes,' 
			+ 'width=520,height=350');

		var htmlLabel;
		htmlLabel = field.label;
		htmlLabel = EncodeHtmlString(htmlLabel);
		diaryWindow.document.write("<html><title>" + htmlLabel +"</title>");
		diaryWindow.document.write(formHTML);
		diaryWindow.document.write(diaryTableHTML);

		var htmlDiaryHistory;
		htmlDiaryHistory = diaryHistory;
		htmlDiaryHistory = EncodeHtmlStringTextArea(htmlDiaryHistory);
		diaryWindow.document.write(diaryHistHTML1 + htmlDiaryHistory + diaryHistHTML2);
		if (field.access == readOnly)
			accessHTML = " readonly onFocus=\"this.blur();\">";
		else
			accessHTML = ">";

		var htmlValue;
		htmlValue = field.ctrl.value;
		htmlValue = EncodeHtmlStringTextArea(htmlValue);
		diaryWindow.document.write(diaryEditHTML1 + accessHTML);
		diaryWindow.document.write(htmlValue + diaryEditHTML2);
		if (field.access == readOnly)
			diaryWindow.document.write(okButtonHTML);
		else
			diaryWindow.document.write(okCancelButtonHTML);
		diaryWindow.document.write(endHTML);
		diaryWindow.focus();
	}

	function openDiaryEdit(fieldID)
	{
		var field = getFieldInstanceByID(fieldID);
		var accessHTML = "";

		if (field.access == disabled) return;

		if (diaryWindow != null && !diaryWindow.closed)
		{
			// alert with message defined in arweb.jsp
			if (activeDiaryField != field.ctrl)
				alert( DiaryOpenMsgStr );
			diaryWindow.focus();
			return;
		}

		activeDiaryField = field.ctrl;
		diaryWindow = window.open("about:blank", 'diaryWindow',
			'toolbar=no,location=no,directories=no,dependent=yes' +
			'status=no,menubar=no,scrollbars=yes,resizable=yes,' +
			'width=520,height=330');

		var htmlLabel;
		htmlLabel = field.label;
		htmlLabel = EncodeHtmlString(htmlLabel);
		diaryWindow.document.write("<title>" + htmlLabel +"</title>");
		diaryWindow.document.write(formHTML);
		
		if (field.access == readOnly)
			accessHTML = " readonly onFocus=\"this.blur();\">";
		else
			accessHTML = ">";
		diaryWindow.document.write(diaryEditorHTML1 + accessHTML);

		var htmlValue;
		htmlValue = field.ctrl.value;
		htmlValue = EncodeHtmlStringTextArea(htmlValue);
		diaryWindow.document.write(htmlValue + diaryEditorHTML2);

		if (field.access == readOnly)
			diaryWindow.document.write(okButtonHTML);
		else
			diaryWindow.document.write(okCancelButtonHTML);
		diaryWindow.document.write(endHTML);
		diaryWindow.focus();
	}


// -----------------------------------------------------------------
	// The diary editor can be typed in, and if the user presses OK, the
	// value is sent to the field and the diary window closes. This function
	// sets the field's value.
	// -----------------------------------------------------------------
	function setDiaryFieldValue(newValue)
	{
		activeDiaryField.value = newValue;
	}
	// -----------------------------------------------------------------
	// the Diary History text field should be read only. This function 
	// is called when focus is set to the Diary History field, and it 
	// causes focus to be lost, thereby not allowing the user to type into
	// the diary history field.
	// -----------------------------------------------------------------
	function setDiaryReadOnly(form)
	{
		form.DiaryHistoryText.blur();
	}
	// -----------------------------------------------------------------
	// Opens the status history dialog box. 
	// -----------------------------------------------------------------	
	function openStatusHistory(statusHistHtml)
	{
		if (statusHistWindow != null && !statusHistWindow.closed)
		{
			statusHistWindow.focus();
			return;
		}
		statusHistWindow = window.open("about:blank", 'statusHistWindow',
			'toolbar=no,location=no,directories=no,dependent=yes,' +
			'status=no,menubar=no,scrollbars=yes,resizable=yes,' +
			'width=500,height=350');

		statusHistWindow.document.write("<html><head><title>Status History</title></head>");
		statusHistWindow.document.write("<body>" + statusHistHtml + "</body></html>");
		statusHistWindow.focus();
	}
	
