Index: cprs/branches/tmg-cprs/CPRS-Chart/fReminderDialog.pas
===================================================================
--- cprs/branches/tmg-cprs/CPRS-Chart/fReminderDialog.pas	(revision 496)
+++ cprs/branches/tmg-cprs/CPRS-Chart/fReminderDialog.pas	(revision 541)
@@ -991,4 +991,5 @@
   WHArray: TStringlist;
   GecRemIen, GecRemStr, RemWipe: String;
+  HTMLEditing : boolean;  //kt 8/09
 
   procedure Add(PCEItemClass: TPCEItemClass);
@@ -1073,27 +1074,21 @@
         repeat
         //AGP Added RemWipe section this section will determine if the Dialog is a patient specific
-          if FProcessingTemplate or (i < RemindersInProcess.Count) then
-          begin
-            if FProcessingTemplate then
-              begin
-                 Rem := FReminder;
-                 if Rem.RemWipe = 1 then
-                     RemWipe := Piece(Rem.DlgData,U,1);
-              end
-            else
-              begin
-                Rem := TReminder(RemindersInProcess.Objects[i]);
-                if TReminderDialog(TReminder(RemindersInProcess.Objects[i])).RemWipe = 1 then
-                   begin
-                     if RemWipe ='' then RemWipe := TReminder(RemindersInProcess.Objects[i]).IEN
-                     else RemWipe := RemWipe + U + TReminder(RemindersInProcess.Objects[i]).IEN;
-                   end;
-                end;
+          if FProcessingTemplate or (i < RemindersInProcess.Count) then begin
+            if FProcessingTemplate then begin
+              Rem := FReminder;
+              if Rem.RemWipe = 1 then
+                RemWipe := Piece(Rem.DlgData,U,1);
+            end else begin
+              Rem := TReminder(RemindersInProcess.Objects[i]);
+              if TReminderDialog(TReminder(RemindersInProcess.Objects[i])).RemWipe = 1 then begin
+                if RemWipe ='' then RemWipe := TReminder(RemindersInProcess.Objects[i]).IEN
+                else RemWipe := RemWipe + U + TReminder(RemindersInProcess.Objects[i]).IEN;
+              end;
+            end;
 
             Flds := FALSE;
             OldCount := TmpList.Count;
             Rem.FinishProblems(TmpList, Flds);
-            if(OldCount <> TmpList.Count) or Flds then
-            begin
+            if(OldCount <> TmpList.Count) or Flds then begin
               TmpList.Insert(OldCount, '');
               if not FProcessingTemplate then
@@ -1113,54 +1108,54 @@
 
         Process := TRUE;
-        if(TmpList.Count > 0) then
-        begin
+        if(TmpList.Count > 0) then begin
           Msg := REQ_TXT + TmpList.Text;
           InfoBox(Msg, REQ_HDR, MB_OK);
           Process := FALSE;
-        end
-        else
-        begin
+        end else begin
           TmpText := TStringList.Create;
           try
-            if (not FProcessingTemplate) and (not InsertRemTextAtCursor) then
-              RemForm.NewNoteRE.SelStart := MaxInt; // Move to bottom of note
-            AddLine := FALSE;
-            BeforeLine := SendMessage(RemForm.NewNoteRE.Handle, EM_EXLINEFROMCHAR, 0, RemForm.NewNoteRE.SelStart);
-            if (SendMessage(RemForm.NewNoteRE.Handle, EM_LINEINDEX, BeforeLine, 0) <> RemForm.NewNoteRE.SelStart) then
-            begin
-              RemForm.NewNoteRE.SelStart := SendMessage(RemForm.NewNoteRE.Handle, EM_LINEINDEX, BeforeLine+1, 0);
-              inc(BeforeLine);
-            end;
-            if(RemForm.NewNoteRE.SelStart > 0) then
-            begin
-              if(RemForm.NewNoteRE.SelStart = 1) then
-                AddLine := TRUE
-              else
-              begin
-                TR.chrg.cpMin := RemForm.NewNoteRE.SelStart-2;
-                TR.chrg.cpMax := TR.chrg.cpMin+2;
-                TR.lpstrText := @buf;
-                SendMessage(RemForm.NewNoteRE.Handle, EM_GETTEXTRANGE, 0, LPARAM(@TR));
-                if(buf[0] <> #13) or (buf[1] <> #10) then
-                  AddLine := TRUE;
+            if (RemForm.Form is TfrmNotes) and Assigned(RemForm.NewNoteHTMLE) then begin //kt
+              HTMLEditing := (vmHTML in TfrmNotes(RemForm.Form).ViewMode);               //kt
+            end else HTMLEditing := false;                                               //kt
+            if HTMLEditing then begin  //kt added this entire block                      //kt
+              if (not FProcessingTemplate) and (not InsertRemTextAtCursor) then begin    //kt
+                RemForm.NewNoteHTMLE.MoveCaretToEnd;                                     //kt
+              end;                                                                       //kt
+              AddLine := TRUE;                                                           //kt
+            end else begin             //kt (original code below)
+              if (not FProcessingTemplate) and (not InsertRemTextAtCursor) then
+                RemForm.NewNoteRE.SelStart := MaxInt; // Move to bottom of note
+              AddLine := FALSE;
+              BeforeLine := SendMessage(RemForm.NewNoteRE.Handle, EM_EXLINEFROMCHAR, 0, RemForm.NewNoteRE.SelStart);
+              if (SendMessage(RemForm.NewNoteRE.Handle, EM_LINEINDEX, BeforeLine, 0) <> RemForm.NewNoteRE.SelStart) then begin
+                RemForm.NewNoteRE.SelStart := SendMessage(RemForm.NewNoteRE.Handle, EM_LINEINDEX, BeforeLine+1, 0);
+                inc(BeforeLine);
               end;
-            end;
+              if(RemForm.NewNoteRE.SelStart > 0) then begin
+                if(RemForm.NewNoteRE.SelStart = 1) then
+                  AddLine := TRUE
+                else begin
+                  TR.chrg.cpMin := RemForm.NewNoteRE.SelStart-2;
+                  TR.chrg.cpMax := TR.chrg.cpMin+2;
+                  TR.lpstrText := @buf;
+                  SendMessage(RemForm.NewNoteRE.Handle, EM_GETTEXTRANGE, 0, LPARAM(@TR));
+                  if(buf[0] <> #13) or (buf[1] <> #10) then
+                    AddLine := TRUE;
+                end;
+              end;
+            end; //kt 8/09
             if FProcessingTemplate then
               FReminder.AddText(TmpText)
-            else
-            begin
+            else begin
               for i := 0 to RemindersInProcess.Count-1 do
                 TReminder(RemindersInProcess.Objects[i]).AddText(TmpText);
             end;
-            if(TmpText.Count > 0) then
-            begin
-              if not FProcessingTemplate then
-              begin
+            if(TmpText.Count > 0) then begin
+              if not FProcessingTemplate then begin
                 tmp := ClinRemText;
-                if(tmp <> '') then
-                begin
+                //kt if(tmp <> '') then begin
+                if(tmp <> '') and (not HTMLEditing) then begin  //kt 8/09
                   i := RemForm.NewNoteRE.Lines.IndexOf(tmp);
-                  if(i < 0) or (i > BeforeLine) then
-                  begin
+                  if(i < 0) or (i > BeforeLine) then begin
                     TmpText.Insert(0, tmp);
                     if(RemForm.NewNoteRE.SelStart > 0) then
@@ -1177,14 +1172,20 @@
               if TmpText.Count = 0 then
                 Process := FALSE
-              else
-              begin
+              else begin
                 if RemForm.PCEObj.NeedProviderInfo and MissingProviderInfo(RemForm.PCEObj, PCEType) then
                   Process := FALSE
-                else
-                  RemForm.NewNoteRE.SelText := TmpText.Text;
+                else begin
+                  If HTMLEditing then begin                                                //kt 8/09
+                    for i := 0 to TmpText.count-1 do begin                                 //kt 8/09
+                      RemForm.NewNoteHTMLE.InsertTextAtCaret(TmpText.Strings[i]+'<BR>');   //kt 8/09
+                    end;                                                                   //kt 8/09
+                  end else begin                                                           //kt 8/09
+                    RemForm.NewNoteRE.SelText := TmpText.Text;
+                  end;                                                                     //kt 8/09
+                end;
               end;
             end;
-            if(Process) then
-            begin
+            //kt if(Process) then begin
+            if(Process) and (not HTMLEditing) then begin  //kt
               SendMessage(RemForm.NewNoteRE.Handle, EM_SCROLLCARET, 0, 0);
               AfterTop := SendMessage(RemForm.NewNoteRE.Handle, EM_GETFIRSTVISIBLELINE, 0, 0);
