Index: EngineSource/LogEventType.cs
===================================================================
--- EngineSource/LogEventType.cs	(revision 641)
+++ EngineSource/LogEventType.cs	(working copy)
@@ -20,6 +20,7 @@
     WriteTopic, 
     DeleteTopic,
     CompareTopic,
-    NewsletterGeneration
+    NewsletterGeneration,
+    UploadFile
   };
 }
Index: FlexWiki.Web/flexwiki.config
===================================================================
--- FlexWiki.Web/flexwiki.config	(revision 641)
+++ FlexWiki.Web/flexwiki.config	(working copy)
@@ -167,6 +167,11 @@
         folder of the web application. Relative paths are relative to the root folder of the 
         web application. -->
   <!-- <Log4NetConfigPath>path\to\log4net.config</Log4NetConfigPath>-->
+  
+  <!-- The path to the upload directory. Path is relative to the root folder of the web application
+        and must exist prior to attmpted use (including subdirectories for:
+        doc, exe, files, html, images. -->
+  <ContentUploadPath>content\upload</ContentUploadPath>
 
   <!-- FlexWiki has a feature called newsletters, where the wiki will email members when 
         certain topics have changed. See http://www.flexwiki.com/default.aspx/FlexWiki/WikiNewsletter.html
Index: FlexWiki.Web/FlexWikiApplicationConfiguration.cs
===================================================================
--- FlexWiki.Web/FlexWikiApplicationConfiguration.cs	(revision 641)
+++ FlexWiki.Web/FlexWikiApplicationConfiguration.cs	(working copy)
@@ -12,7 +12,8 @@
         // Fields
 
         private string _captchaKey;
-        private int _captchaLinkThreshold; 
+        private int _captchaLinkThreshold;
+        private string _contentUploadPath;
         private string _defaultNamespaceProviderForNamespaceCreation = typeof(FileSystemNamespaceProvider).FullName;
         private bool _disableRenameFixup; 
         private bool _editOnDoubleClick = true;    // Required for legacy support - new properties should default to false
@@ -28,7 +29,7 @@
         private string _sendNamespaceCreationRequestsTo;
         private string _sendNamespaceRequestMailFrom;
         private bool _signNamespaceCreationMail;
-        
+
         // Properties
 
         public string CaptchaKey
@@ -41,6 +42,11 @@
             get { return _captchaLinkThreshold; }
             set { _captchaLinkThreshold = value; }
         }
+        public string ContentUploadPath
+        {
+            get { return _contentUploadPath; }
+            set { _contentUploadPath = value; }
+        }
         public string DefaultNamespaceProviderForNamespaceCreation
         {
             get { return _defaultNamespaceProviderForNamespaceCreation; }
Index: FlexWiki.Web/WikiEdit.aspx
===================================================================
--- FlexWiki.Web/WikiEdit.aspx	(revision 641)
+++ FlexWiki.Web/WikiEdit.aspx	(working copy)
@@ -1,4 +1,4 @@
-<%@ Page Language="c#" Codebehind="WikiEdit.aspx.cs" AutoEventWireup="false" Inherits="FlexWiki.Web.WikiEdit" %>
+<%@ Page Language="c#" AutoEventWireup="false" Inherits="FlexWiki.Web.WikiEdit" %>
 
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
 <html>
@@ -6,7 +6,7 @@
     <title>
         <%= TheTopic.ToString() %>
         (edit)</title>
-<meta name="Robots" content="NOINDEX, NOFOLLOW">
+<meta name="Robots" content="NOINDEX, NOFOLLOW" />
 <%= InsertStylesheetReferences() %>
 <script type="text/javascript" language="javascript" src="WikiEdit.js"></script>
 <style type="text/css"> @media all { tool\:tip { behavior: url(tooltip_js.htc) }}
@@ -17,5 +17,16 @@
 	.EditBox { font: 9pt Courier New; background: whitesmoke; height: 100%; height: expression(CalcEditBoxHeight()); width: 100%; }
 	</style>
 </head>
+<body class='EditBody' width='100%' height='100%' scroll='no'>
 <% DoPage(); %>
+
+<form name='Form3' id='Form3' method='post' enctype='multipart/form-data' runat='server' >
+<input id='_uploadFilePath' type='file' size='30' name='_uploadFilePath' runat='server' />   
+<input type='button' id='FileUploadSend' name='FileUploadSend' onclick='FileUploadSend_OnClick()' value='Send' />
+<input type='text' style='display:none' name='Topic' value='<%= TheTopic.ToString() %>' />
+<input type='text' style='display: none' id='_processAttachment' name='_processAttachment' value="IsNotAttachment" runat="server" />
+<textarea name='Text1' style='display:none' cols='20' rows='2'></textarea>
+<% ShowEditPageMiddle(); %>
+</form>
+<% ShowEditPageZ(); %>
 </html>
Index: FlexWiki.Web/WikiEdit.aspx.cs
===================================================================
--- FlexWiki.Web/WikiEdit.aspx.cs	(revision 641)
+++ FlexWiki.Web/WikiEdit.aspx.cs	(working copy)
@@ -13,6 +13,7 @@
 using System;
 using System.Collections;
 using System.ComponentModel;
+using System.Configuration;
 using System.Data;
 using System.Drawing;
 using System.IO;
@@ -35,13 +36,25 @@
     /// </summary>
     public class WikiEdit : BasePage
     {
+        protected System.Web.UI.HtmlControls.HtmlImage _imgFile;
+        protected System.Web.UI.HtmlControls.HtmlInputFile _uploadFilePath;
+        protected System.Web.UI.HtmlControls.HtmlInputText _processAttachment;
+
+        private string _errorMessage = "";
+        private string _fileName = "";
+        private string _fileSize = "";
+        private string _fileUrl = "";
         private QualifiedTopicRevision _theTopic;
 
         private void Page_Load(object sender, System.EventArgs e)
         {
-            // Put user code to initialize the page here
+            //Page_Load code here
+            if (IsPostBack)
+            {
+                if (IsAttachment)
+                    FileUploadSendClick(sender, e);
+            }
         }
-
         protected string ReturnTopic
         {
             get
@@ -49,16 +62,16 @@
                 string answer = null;
                 if (IsPost)
                 {
-                    answer = Request.Form["ReturnTopic"];
-                }
+                    answer = Request.Form["Topic"];
+				}
                 else
                 {
-                    answer = Request.QueryString["return"];
-                }
+                    answer = Request.QueryString["topic"];
+				}
                 if (answer == "")
-                {
+				{
                     answer = null;
-                }
+				}
                 return answer;
             }
         }
@@ -78,6 +91,20 @@
             }
         }
 
+        private bool IsAttachment
+        {
+            get
+            {
+                if (_processAttachment.Value == "IsAttachment")
+                {
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+        }
         private bool IsBanned
         {
             get
@@ -154,6 +181,21 @@
                     !(currentStamp = Federation.GetTopicModificationTime(TheTopic)).ToString("s").Equals(lastEdit);
             }
         }
+        private bool IsUploadable
+        {
+            get
+            {
+                string uploadDirectory = FlexWikiWebApplication.ApplicationConfiguration.ContentUploadPath;
+                if (uploadDirectory != null)
+                {
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+        }
         private bool IsWritable
         {
             get
@@ -185,6 +227,25 @@
         }
 
 
+        protected void DoPage()
+        {
+            if (IsPost && !IsConflictingChange && !IsBanned)
+            {
+                if (IsCaptchaVerified)
+                {
+                    ProcessPost();
+                }
+                else
+                {
+                    ShowEditPage(true);
+                }
+            }
+            else
+            {
+                ShowEditPage();
+            }
+        }
+
         protected void ProcessSave(bool back)
         {
             QualifiedTopicRevision returnTo = null;
@@ -232,19 +293,25 @@
                 string topic = "<<null>>";
                 if (TheTopic != null && TheTopic.DottedName != null)
                 {
-                    topic = TheTopic.DottedName;
-                    // On a null edit we want to make sure we go back to the right place. Without setting
-                    // returnTo, we'll wind up at the wiki default page. 
-                    returnTo = TheTopic; 
+                    topic = TheTopic.DottedName; 
                 }
                 FlexWikiWebApplication.LogDebug(this.GetType().ToString(), "A null edit was submitted for topic " + topic); 
             }
 
             if (returnTo == null)
             {
-                FlexWikiWebApplication.LogDebug(this.GetType().ToString(),
-                    "Redirecting to wiki root."); 
-                Response.Redirect(RootUrl);
+               
+                if (TheTopic != null && TheTopic.DottedName != null)
+                {
+                    Response.Redirect(TheLinkMaker.LinkToTopic(ReturnTopic.ToString()));
+                }
+                else
+                {
+                    FlexWikiWebApplication.LogDebug(this.GetType().ToString(),
+                        "Redirecting to wiki root.");
+                    Response.Redirect(RootUrl);
+                }
+                
             }
             else
             {
@@ -254,30 +321,175 @@
             }
 
         }
+        protected void ShowEditPageMiddle()
+        {
 
-        protected void DoPage()
+            //<p><input id='_uploadFilePath' type='file' size='30' name='_uploadFilePath' runat='server' />   
+            //        <input type='submit' id='FileUploadSend' name='FileUploadSend' onclick='FileUploadSend_OnClick()' value='Send' runat='server' />");
+
+            //Response.Write("<input type='text' style='display:none' name='Topic' value ='" + Formatter.EscapeHTML(TheTopic.ToString()) + "'>");
+            //            Response.Write(@"
+            //               <input type='text' style='display: none' id='AttachmentVisibility' name='AttachmentVisibility' value='Closed' />
+            //               <input type='text' style='display: none' id='uploadFilePath' name='uploadFilePath' />
+            //               <textarea name='Text1' style='display:none' cols='20' rows='2'></textarea>");
+            if (_errorMessage.Length > 0)
+            {
+                Response.Write("<p><span style='color: red'>" + _errorMessage + "</span></p>");
+            }
+            Response.Write("</td></tr><tr><td>");
+            Response.Write("<p><input id='Radio1' type='radio' name='attachFormat' value='Normal'  onfocus='showNormal_OnFocus()' />Normal Attachment</p>");
+            Response.Write("<p><input id='Radio2' type='radio' name='attachFormat' value='Folder'  onfocus='showFolder_OnFocus()' />File Folder Attachment</p>");
+            Response.Write("<p><input id='Radio3' type='radio' name='attachFormat'  value='DocMan' onfocus='showDocMan_OnFocus()' />Document Management Attachment</p>");
+            Response.Write("</td></tr><tr><td><div id='CommonFields' style='display:none' ><p>");
+
+            Response.Write("<input type='text' id='_fileName' value='" + _fileName + "' />&nbsp;Filename</p>");
+            Response.Write("<p><input type='text' id='_fileSize' value='" + _fileSize + "' />&nbsp;Size</p>");
+            Response.Write("<p><input type='text' id='_fileUrl' value='" + Formatter.EscapeHTML(_fileUrl) + "' />&nbsp;URL</p>");
+            Response.Write(@"
+                        <p><input id='Form3DocTitle' type='text' size='20' />&nbsp;Document Title</p></div>
+                        <div id='VersionFields' style='display:none' ><p><input id='Form3Version' type='text' /> Document Version</p></div>
+                        <div id='FileNoFields' style='display:none' ><p><input id='Form3FileNo' type='text' /> Orig File No</p></div>
+                        <div id='AuthorFields' style='display:none' ><p><input id='Form3Author' type='text' size='20' /> Originator</p></div>
+                        <div id='PublishedFields' style='display:none' ><p><input id='Form3Published' type='text' /> Published</p></div>
+                        <div id='FiledFields' style='display:none' ><p><input id='Form3Filed' type='text' /> Filed</p></div>");
+            Response.Write("<div id='StatusFields' style='display:none' ><p>");
+            Response.Write(@"<select id='Form3Status'>
+                                <option value='Draft'>Draft</option>
+                                <option value='Review'>Review</option>
+                                <option value='Acceptance'>Acceptance</option>
+                                <option value='Published'>Published</option>
+                                <option value='Cancelled'>Cancelled</option>
+                            </select> Document Status
+                        </p></div>");
+            Response.Write(@"<div id='StatusDateFields' style='display:none' ><p>
+                            <input id='Form3StatusDate' type='text' /> Status Date</p></div>
+                        <div id='CommentFields' style='display:none' ><p>Comment: <br /><textarea id='Form3Comment' cols='20' rows='2'></textarea></p></div>
+                <p>");
+            Response.Write(@"<p><button id='attachFile'  name='attachFile' onclick='attachFile_OnClick()' >Create Attachment</button> </p>
+                                </td>
+                        </tr>");
+            //                 <tr>
+            //                         <td align="center" colspan="2">
+            //                                 <asp:Image id="_imgFile" runat="server" Visible="False"></asp:Image>
+            //                         </td>
+            //                 </tr>
+            Response.Write("</table>");
+        }
+        protected void ShowEditPageZ()
         {
-            if (IsPost && !IsConflictingChange && !IsBanned)
+            Response.Write("</div></table></div></td></tr></table>");
+
+            Response.Write("</td></tr></table>");
+
+            Response.Write("</body>");
+        }
+
+        private void WriteTip(string id, string text)
+        {
+            Response.Write(@"<span onclick='javascript:ShowTip(""" + id + @""")'><b>" + text + "</b></span> ");
+        }
+
+        private int CountLinks(string text)
+        {
+            return TopicParser.CountExternalLinks(text); 
+        }
+        private void FileUploadSendClick(object sender, System.EventArgs e)
+        {
+
+            try
             {
-                if (IsCaptchaVerified)
+                // Check to        see        if file        was        uploaded
+                if (_uploadFilePath != null)
                 {
-                    ProcessPost();
+                    _errorMessage = "";
+                    // Get a reference to PostedFile object
+                    HttpPostedFile fileToUpload = _uploadFilePath.PostedFile;
+                    int fileLength = fileToUpload.ContentLength;
+                    if (fileLength > 0)
+                    {
+                        // Allocate a buffer for reading of the file
+                        byte[] fileData = new byte[fileLength];
+                        string directoryToWriteTo;
+                        string writeToFile;
+                        string fileName;
+                        // Read        uploaded file from the Stream
+                        fileToUpload.InputStream.Read(fileData, 0, fileLength);
+                        directoryToWriteTo = ReturnDirectoryToWriteTo(fileToUpload.FileName);
+                        // Create a        name for the file to store
+                        fileName = Path.GetFileName(fileToUpload.FileName); //
+                        // Write data into a file
+                        writeToFile = Server.MapPath(fileName);
+                        // Get the current virtual directory, mapped to        a path
+                        writeToFile = Server.MapPath("") + "\\" + directoryToWriteTo + "\\" + fileName;
+                        // fileNumber var is the one digit number that is added        to a file name if it exists
+                        int fileNumber = 0;
+                        string fileNameAdder = "";
+                        string newFileName = "";
+
+
+                        // append a        three digit        int        to the file        name to        make it        unique
+                        while (File.Exists(writeToFile))
+                        {
+                            if (fileNumber > 9)
+                            {
+                                throw new System.IO.IOException("Too many copies of file exist on server.");
+                            }
+                            fileNumber++;
+                            fileNameAdder = ("-" + fileNumber.ToString("0") + ".");
+                            newFileName = Server.MapPath("") + "\\" + directoryToWriteTo + "\\" + fileName.Replace(".", fileNameAdder);
+
+
+                            if (File.Exists(newFileName))
+                            {
+                                // if the new file name is taken start over
+                                continue;
+                            }
+                            else
+                            {
+                                // if the new file name is not taken, terminate the loop
+                                writeToFile = newFileName;
+                                break;
+                            }
+                        }
+
+
+                        // write the file out
+                        WriteToFile(writeToFile, ref fileData);
+                        // get the name of the file
+                        fileName = Path.GetFileName(writeToFile);
+
+
+                        // Set label's text
+                        _fileName = fileName;
+                        // show        the        location
+                        _fileSize = "File size: " + fileLength.ToString("0,0") + " bytes";
+                        // show        the        full path
+                        _fileUrl = RootUrl + directoryToWriteTo.Replace(@"\", @"/") + "/" + Path.GetFileName(writeToFile);
+
+
+                        // Set URL of the the object to        point to the file we've        just saved
+                        if (IsImageFile(writeToFile))
+                        {
+
+                            _imgFile.Src = RootUrl + directoryToWriteTo.Replace(@"\", @"/") + "/" + Path.GetFileName(writeToFile);
+
+                            // show the images and text
+                            // fix for height and width to ensure edit text remains visible for large files.
+                            _imgFile.Visible = true;
+                        }
+                    }
                 }
-                else
-                {
-                    ShowEditPage(true); 
-                }
             }
-            else
+            catch (System.IO.IOException)
             {
-                ShowEditPage();
+                _errorMessage = "There are too many files on the server with that name. Please rename it and upload again.";
             }
+            //no changes ever made to the topic before the attachment was made
+            if (Request.Form["Text1"] == null)
+                Request.Form["Text1"] = OriginalTopicText;
+
         }
 
-        private int CountLinks(string text)
-        {
-            return TopicParser.CountExternalLinks(text); 
-        }
         private string GenerateNewCaptchaCode()
         {
             string code = CaptchaImage.GenerateRandomCode();
@@ -322,6 +534,17 @@
 
             return false;
         }
+        private bool IsImageFile(string fullPath)
+        {
+            bool blnIsImage = false;
+            fullPath = fullPath.ToUpper();
+            string extensionName = Path.GetExtension(fullPath);
+            if ((extensionName == ".JPG") || (extensionName == ".GIF") || (extensionName == ".PNG"))
+            {
+                blnIsImage = true;
+            }
+            return blnIsImage;
+        }
         private void LogBannedAttempt()
         {
             string to = FlexWikiWebApplication.ApplicationConfiguration.SendBanNotificationsToMailAddress;
@@ -354,15 +577,47 @@
         }
         private void ProcessPost()
         {
-            ProcessSave(true);
+            if (!IsAttachment)
+            {
+                ProcessSave(true);
+            }
+            else
+            {
+                ShowEditPage(true);
+            }
         }
+        private string ReturnDirectoryToWriteTo(string fileName)
+        {
+            // get the root        directory for uploaded files
+            string rootUploadDir = FlexWikiWebApplication.ApplicationConfiguration.ContentUploadPath;
+            string returnDirectory = "";
+            fileName = fileName.ToLower();
+            string extensionName = Path.GetExtension(fileName);
+            if ((extensionName == ".jpg") || (extensionName == ".gif") || (extensionName == ".png"))
+            {
+                returnDirectory = rootUploadDir + "\\images";
+            }
+            else if ((extensionName == ".htm") || (extensionName == ".html"))
+            {
+                returnDirectory = rootUploadDir + "\\html";
+            }
+            else if (extensionName == ".doc")
+            {
+                returnDirectory = rootUploadDir + "\\doc";
+            }
+            else
+            {
+                returnDirectory = rootUploadDir + "\\files";
+            }
+            return returnDirectory;
+        }
         private void ShowEditPage()
         {
             ShowEditPage(false); 
         }
         private void ShowEditPage(bool preserveContent)
         {
-            Response.Write("<body class='EditBody' width='100%' height='100%' scroll='no'>");
+            //Response.Write("<body class='EditBody' width='100%' height='100%' scroll='no'>");
 
             Response.Write("<table width='100%' id='MasterTable' height='100%' border='0' cellpadding='0' cellspacing='0'><tr><td valign='top'>");
             Response.Write("<div id='MainRegion' class='EditMain'>");
@@ -735,22 +990,68 @@
                     Response.Write("<tr><td colspan='2'><button onclick='javascript:SaveAndReturn()'  name='SaveButton'>Save and Back</button></td></tr>");
                 }
 
-
-                Response.Write("</table></div>");
+                //Response.Write("</table></div>");
             }
 
             Response.Write("</td></tr></table>");
+            if (IsUploadable && IsWritable)
+            {
+                Response.Write("<div id='AttachFile' style='display: block'>");
+            }
+            else
+            {
+                Response.Write("<div id='AttachFile' style='display: none'>");
+            }
+            Response.Write(@"
+                    <div id='AttachFile' style='display: block'>
+                    <table id='Table2' cellspacing='0' cellpadding='2' border='0' class='SidebarTile'>
+                        <tr>
+                            <td valign='middle' class='SidebarTileTitle'>
+                                File Attachment
+                            </td>
+                        </tr>
+                        <tr class='SidebarTileBody'><td>");
 
-            Response.Write("</td></tr></table>");
+            if (IsAttachment)
+            {
+                Response.Write("<div id='ShowAttachmentControls' style='display: none' >");
+                Response.Write("<a onclick=\"javascript:Swap('ShowAttachmentControls', 'HideAttachmentControls')\">Show Attachment Controls...</a> </div>");
+                Response.Write("<div id='HideAttachmentControls' style='display: block' >");
+                Response.Write("<a onclick=\"javascript:Swap('HideAttachmentControls', 'ShowAttachmentControls')\" >Hide Attachment Controls...</a>");
+            }
+            else
+            {
+                Response.Write("<div id='ShowAttachmentControls' style='display: block' >");
+                Response.Write("<a onclick=\"javascript:Swap('ShowAttachmentControls', 'HideAttachmentControls')\">Show Attachment Controls...</a> </div>");
+                Response.Write("<div id='HideAttachmentControls' style='display: none' >");
+                Response.Write("<a onclick=\"javascript:Swap('HideAttachmentControls', 'ShowAttachmentControls')\" >Hide Attachment Controls...</a>");
+            }
+            // <form name='Form3' id='Form3' method='post' action='wikiedit.aspx?topic=" + Formatter.EscapeHTML(TheTopic.ToString()) + "' enctype='multipart/form-data' runat='server' >");
+            Response.Write("<table><tr><td colspan='2'>");
+            
 
-            Response.Write("</body>");
+        }
 
-        }
-        private void WriteTip(string id, string text)
+        // Writes file to specified path
+        private void WriteToFile(string filePath, ref byte[] Buffer)
         {
-            Response.Write(@"<span onclick='javascript:ShowTip(""" + id + @""")'><b>" + text + "</b></span> ");
+            LogEvent ev;
+            LogEventType evType = LogEventType.UploadFile;
+            ev = Federation.LogEventFactory.CreateAndStartEvent(Request.UserHostAddress, VisitorIdentityString, filePath, evType);
+
+            try
+            {
+                FileStream newFile = new FileStream(filePath, FileMode.Create);
+                newFile.Write(Buffer, 0, Buffer.Length);
+                newFile.Close();
+            }
+            finally
+            {
+                ev.Record();
+            }
         }
 
+
         #region Web Form Designer generated code
         override protected void OnInit(EventArgs e)
         {
Index: FlexWiki.Web/WikiEdit.js
===================================================================
--- FlexWiki.Web/WikiEdit.js	(revision 641)
+++ FlexWiki.Web/WikiEdit.js	(working copy)
@@ -1,13 +1,92 @@
-function textArea_OnFocus(event)
+function attachFile_OnClick()
 {
-	document.onkeypress = Document_OnKeyPress;
+    var insertText1 = "";
+    var insertText2 = "";
+    var insertText3 = "";
+    var insertText4 = "";
+    var textArea = document.forms["Form1"].Text1;
+    var docTitle = document.getElementById("Form3DocTitle").value;
+    var urlString = document.getElementById("_fileUrl").value;
+    var sizeString = document.getElementById("_fileSize").value;
+    var filedDate = document.getElementById("Form3Filed").value;
+    var publishedDate = document.getElementById("Form3Published").value;
+    var authorName = document.getElementById("Form3Author").value;
+    var fileNo = document.getElementById("Form3FileNo").value;
+    var versionNo = document.getElementById("Form3Version").value;
+    var commentText = document.getElementById("Form3Comment").value;
+    var attachFormatString = getCheckedValue(document.forms["Form3"].attachFormat);
+    var statusDate = document.getElementById("Form3StatusDate").value;
+    var templateCombo = document.getElementById("Form3Status");
+	if ((templateCombo) && (templateCombo.selectedIndex > -1))
+	{
+        var statusString = templateCombo.options[templateCombo.selectedIndex].value;
+    }
+    if (attachFormatString == "Normal")
+    {
+        insertText1 = '@@Presentations.Image(federation.LinkMaker.LinkToImage("images/attach/file.gif"))@@ '; 
+        insertText2 = '@@Presentations.Link("' + urlString + '", "' + docTitle + '", "' + sizeString + '")@@';
+    }
+    if (attachFormatString == "Folder")
+    {
+        insertText1 = '|| ' + filedDate + ' || @@Presentations.Image(federation.LinkMaker.LinkToImage("images/attach/file.gif"))@@ ';
+        insertText2 = '@@Presentations.Link("' + urlString + '", "' + docTitle + '", "' + sizeString + '")@@ || ';
+        insertText3 = fileNo + ' || ' + authorName + ' || ' + publishedDate + ' || ' + commentText + ' ||';
+    }
+    if (attachFormatString == "DocMan")
+    {
+        insertText1 = '|| ' + filedDate + ' || @@Presentations.Image(federation.LinkMaker.LinkToImage("images/attach/file.gif"))@@ ';
+        insertText2 = '@@Presentations.Link("' + urlString + '", "' + docTitle + '", "' + sizeString + '")@@ || ';
+        insertText3 = fileNo + ' || ' + authorName + ' || ' + statusString + ' || ' + statusDate + ' || ';
+        insertText4 = versionNo +  ' || @@Presentations.Checkbox("checkOut_' + statusString + '_' + versionNo + '", "strUrl", false)@@ ||' + commentText + ' ||';
+    }
+    textArea.value += "\n\r" + insertText1 + insertText2 + insertText3 + insertText4;
+    textArea.focus();
+    document.forms["Form3"].Text1.value = textArea.value;
+    document.getElementById("_processAttachment").value = "IsAttachment";
 }
 
-function textArea_OnBlur(event)
+function CalcEditBoxHeight()
 {
-	document.onkeypress = null;
+	var answer = CalcEditZoneHeight();
+	return answer;
 }
 
+function CalcEditZoneHeight()
+{
+	var answer = MainHeight();
+	return answer;
+}
+
+function Cancel()
+{
+	history.back();
+}
+
+function ChangeTemplate(selectId)
+{
+	var templateCombo = document.getElementById(selectId);
+	if ((templateCombo) && (templateCombo.selectedIndex > -1))
+	{
+		var strInsertText = templateCombo.options[templateCombo.selectedIndex].value;
+		
+		var objTextArea = document.forms['Form1'].Text1;
+		if (document.selection && document.selection.createRange)
+		{
+			objTextArea.focus();
+			var objSelectedTextRange = document.selection.createRange();
+			var strSelectedText = objSelectedTextRange.text;
+			objSelectedTextRange.text = strInsertText + strSelectedText;
+		}
+		else
+		{
+			objTextArea.value += strInsertText;
+			objTextArea.focus();
+		}
+	}
+	var s = document.forms["Form1"].Text1.value;
+	document.forms["Form3"].Text1.value = s;
+}
+
 function Document_OnKeyPress(event)
 {
 	if (event != null) // FireFox only
@@ -28,23 +107,63 @@
 	return true;
 }
 
-function CalcEditBoxHeight()
+function FileUploadSend_OnClick()
 {
-	var answer = CalcEditZoneHeight();
-	return answer;
+	var s = document.forms["Form1"].Text1.value;
+	document.forms["Form3"].Text1.value = s;
+    document.getElementById("_processAttachment").value = "IsAttachment";
+	document.getElementById("Form3").submit();
 }
 
-function CalcEditZoneHeight()
+// return the value of the radio button that is checked
+// return an empty string if none are checked, or
+// there are no radio buttons
+function getCheckedValue(radioObj) {
+	if(!radioObj)
+		return "";
+	var radioLength = radioObj.length;
+	if(radioLength == undefined)
+		if(radioObj.checked)
+			return radioObj.value;
+		else
+			return "";
+	for(var i = 0; i < radioLength; i++) {
+		if(radioObj[i].checked) {
+			return radioObj[i].value;
+		}
+	}
+	return "";
+}
+
+function ItemDisplay(itemId, display)
 {
-	var answer = MainHeight();
+    var a = document.getElementById(itemId);
+    if (display)
+    {
+        a.style.display = 'block';
+    }
+    else
+    {
+        a.style.display = 'none';
+    }
+}
+
+function MainHeight()
+{
+	var answer = document.body.clientHeight;
+	var e;
 	return answer;
 }
 
-function ShowTip(tipid)
+function MainWidth()
 {
-	var s = document.getElementById(tipid);
-	TipArea.innerHTML = s.innerHTML;
-	TipArea.style.display = 'block';
+	var answer = document.body.clientWidth;
+	var e;
+
+	e = document.getElementById("Sidebar");
+	if (e != null)
+		answer -= e.scrollWidth;
+	return answer;
 }
 
 function preview()
@@ -55,22 +174,29 @@
 	document.forms["Form2"].submit();
 }
 
-function Swap(alpha, beta)
+function Save()
 {
-	var a = document.getElementById(alpha);
-	var b = document.getElementById(beta);
-	if (a.style.display == 'block')
-	{
-		a.style.display = 'none';
-		b.style.display = 'block';
-	}
-	else
-	{
-		b.style.display = 'none';
-		a.style.display = 'block';
-	}	
+	SetUserName();
+	SetCaptcha();
+    document.getElementById("_processAttachment").value = "IsNotAttachment";
+	var r = document.getElementById("ReturnTopic");
+	if (r != null)
+		r.value = ""; // prevent return action by emptying this out
+	document.getElementById("Form1").submit();
 }
 
+function SaveAndReturn()
+{
+	SetUserName();
+    document.getElementById("_processAttachment").value = "IsNotAttachment";
+	document.getElementById("Form1").submit();
+}
+
+function search()
+{
+	window.open('Search.aspx');
+}
+
 function SetCaptcha()
 {
     var c = document.getElementById("CaptchaContext"); 
@@ -87,7 +213,28 @@
         document.forms["Form1"].CaptchaEnteredSubmitted.value = e.value; 
     }
 }
-
+function setCheckedValue(radioObj, newValue)
+{
+    if(!radioObj)
+    {
+        return;
+    }
+    
+    var radioLength = radioObj.length;
+    if (radioLength == undefined)
+    {
+        radioObj.checked = (radioObj.value == newValue);
+        return;
+    }
+    for(var i = 0; i < radioLength; i++)
+    {
+        radioObj[i].checked = false;
+        if(radioObj[i].value == newValue)
+        {
+            radioObj[i].checked = true;
+        }
+    }
+}
 function SetUserName()
 {
 	var r = document.getElementById("UserNameEntryField");
@@ -95,71 +242,77 @@
 		document.forms["Form1"].UserSuppliedName.value = r.value;
 }
 
-function Cancel()
+function showDocMan_OnFocus()
 {
-	history.back();
+    setCheckedValue(document.getElementsByName("attachFormat", "DocMan"));
+    ItemDisplay("CommonFields", true)
+    ItemDisplay("FiledFields", true);
+    ItemDisplay("PublishedFields", false);
+    ItemDisplay("AuthorFields", true);
+    ItemDisplay("FileNoFields", true);
+    ItemDisplay("VersionFields", true);
+    ItemDisplay("CommentFields", true);
+    ItemDisplay("StatusDateFields", true);
+    ItemDisplay("StatusFields", true);
 }
 
-function Save()
+function showFolder_OnFocus()
 {
-	SetUserName();
-	SetCaptcha();
-	var r = document.getElementById("ReturnTopic");
-	if (r != null)
-		r.value = ""; // prevent return action by emptying this out
-	document.getElementById("Form1").submit();
+    setCheckedValue(document.getElementsByName("attachFormat", "Folder"));
+    ItemDisplay("CommonFields", true)
+    ItemDisplay("FiledFields", true);
+    ItemDisplay("PublishedFields", true);
+    ItemDisplay("AuthorFields", true);
+    ItemDisplay("FileNoFields", true);
+    ItemDisplay("VersionFields", false);
+    ItemDisplay("CommentFields", true);
+    ItemDisplay("StatusDateFields", false);
+    ItemDisplay("StatusFields", false);
 }
 
-function SaveAndReturn()
+function showNormal_OnFocus()
 {
-	SetUserName();
-	document.getElementById("Form1").submit();
+    setCheckedValue(document.getElementsByName("attachFormat", "Normal"));
+    ItemDisplay("CommonFields", true)
+    ItemDisplay("FiledFields", false);
+    ItemDisplay("PublishedFields", false);
+    ItemDisplay("AuthorFields", false);
+    ItemDisplay("FileNoFields", false);
+    ItemDisplay("VersionFields", false);
+    ItemDisplay("CommentFields", false);
+    ItemDisplay("StatusDateFields", false);
+    ItemDisplay("StatusFields", false);
 }
 
-function search()
+function ShowTip(tipid)
 {
-	window.open('Search.aspx');
+	var s = document.getElementById(tipid);
+	TipArea.innerHTML = s.innerHTML;
+	TipArea.style.display = 'block';
 }
 
-
-function MainHeight()
+function Swap(alpha, beta)
 {
-	var answer = document.body.clientHeight;
-	var e;
-	return answer;
+	var a = document.getElementById(alpha);
+	var b = document.getElementById(beta);
+	if (a.style.display == 'block')
+	{
+		a.style.display = 'none';
+		b.style.display = 'block';
+	}
+	else
+	{
+		b.style.display = 'none';
+		a.style.display = 'block';
+	}	
 }
 
-function MainWidth()
+function textArea_OnFocus(event)
 {
-	var answer = document.body.clientWidth;
-	var e;
-
-	e = document.getElementById("Sidebar");
-	if (e != null)
-		answer -= e.scrollWidth;
-	return answer;
+	document.onkeypress = Document_OnKeyPress;
 }
 
-
-function ChangeTemplate(selectId)
+function textArea_OnBlur(event)
 {
-	var templateCombo = document.getElementById(selectId);
-	if ((templateCombo) && (templateCombo.selectedIndex > -1))
-	{
-		var strInsertText = templateCombo.options[templateCombo.selectedIndex].value;
-		
-		var objTextArea = document.forms['Form1'].Text1;
-		if (document.selection && document.selection.createRange)
-		{
-			objTextArea.focus();
-			var objSelectedTextRange = document.selection.createRange();
-			var strSelectedText = objSelectedTextRange.text;
-			objSelectedTextRange.text = strInsertText + strSelectedText;
-		}
-		else
-		{
-			objTextArea.value += strInsertText;
-			objTextArea.focus();
-		}
-	}
+	document.onkeypress = null;
 }
