Index: WikiEdit.aspx.cs
===================================================================
--- WikiEdit.aspx.cs	(revision 641)
+++ WikiEdit.aspx.cs	(working copy)
@@ -37,11 +37,27 @@
     {
         private QualifiedTopicRevision _theTopic;
 
-        private void Page_Load(object sender, System.EventArgs e)
+        protected QualifiedTopicRevision TheTopic
         {
-            // Put user code to initialize the page here
+            get
+            {
+                if (_theTopic != null)
+                {
+                    return _theTopic;
+                }
+                string topic;
+                if (IsPost)
+                {
+                    topic = Request.Form["Topic"];
+                }
+                else
+                {
+                    topic = Request.QueryString["topic"];
+                }
+                _theTopic = new QualifiedTopicRevision(topic);
+                return _theTopic;
+            }
         }
-
         protected string ReturnTopic
         {
             get
@@ -62,22 +78,27 @@
                 return answer;
             }
         }
-        protected QualifiedTopicRevision TheTopic
+
+        private bool IsBack
         {
             get
             {
-                if (_theTopic != null)
-                    return _theTopic;
-                string topic;
-                if (IsPost)
-                    topic = Request.Form["Topic"];
+                string saveButton = Request.Form["SaveButtonPressed"];
+
+                if (string.IsNullOrEmpty(saveButton))
+                {
+                    return false;
+                }
+                else if (saveButton == "Back")
+                {
+                    return true;
+                }
                 else
-                    topic = Request.QueryString["topic"];
-                _theTopic = new QualifiedTopicRevision(topic);
-                return _theTopic;
+                {
+                    return false;
+                }
             }
         }
-
         private bool IsBanned
         {
             get
@@ -185,6 +206,24 @@
         }
 
 
+        protected void DoPage()
+        {
+            if (IsPost && !IsConflictingChange && !IsBanned)
+            {
+                if (IsCaptchaVerified)
+                {
+                    ProcessPost();
+                }
+                else
+                {
+                    ShowEditPage(true);
+                }
+            }
+            else
+            {
+                ShowEditPage();
+            }
+        }
         protected void ProcessSave(bool back)
         {
             QualifiedTopicRevision returnTo = null;
@@ -232,48 +271,36 @@
                 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);
-            }
-            else
-            {
-                FlexWikiWebApplication.LogDebug(this.GetType().ToString(),
-                    "Redirecting to: " + returnTo.DottedNameWithVersion);
-                Response.Redirect(TheLinkMaker.LinkToTopic(returnTo));
-            }
-
-        }
-
-        protected void DoPage()
-        {
-            if (IsPost && !IsConflictingChange && !IsBanned)
-            {
-                if (IsCaptchaVerified)
+               
+                if (TheTopic != null && TheTopic.DottedName != null)
                 {
-                    ProcessPost();
+                    Response.Redirect(TheLinkMaker.LinkToTopic(TheTopic.ToString()));
                 }
                 else
                 {
-                    ShowEditPage(true); 
+                    FlexWikiWebApplication.LogDebug(this.GetType().ToString(),
+                        "Redirecting to wiki root.");
+                    Response.Redirect(RootUrl);
                 }
+                
             }
             else
             {
-                ShowEditPage();
+                FlexWikiWebApplication.LogDebug(this.GetType().ToString(),
+                    "Redirecting to: " + returnTo.DottedNameWithVersion);
+                Response.Redirect(TheLinkMaker.LinkToTopic(returnTo));
             }
+
         }
 
+
         private int CountLinks(string text)
         {
             return TopicParser.CountExternalLinks(text); 
@@ -352,9 +379,14 @@
             msg.Body = w.ToString();
             SendMail(msg);
         }
+        private void Page_Load(object sender, System.EventArgs e)
+        {
+            // Put user code to initialize the page here
+        }
+
         private void ProcessPost()
         {
-            ProcessSave(true);
+            ProcessSave(IsBack);
         }
         private void ShowEditPage()
         {
@@ -467,8 +499,9 @@
             Response.Write(@"</textarea>");
             if (IsWritable)
             {
-                Response.Write("<input type='text' style='display:none' name='CaptchaEnteredSubmitted' value =''>"); 
-                Response.Write("<input type='text' style='display:none' name='CaptchaContextSubmitted' value =''>"); 
+                Response.Write("<input type='text' style='display:none' name='CaptchaEnteredSubmitted' value =''>");
+                Response.Write("<input type='text' style='display:none' name='CaptchaContextSubmitted' value =''>");
+                Response.Write("<input type='text' style='display:none' id='SaveButtonPressed' name='SaveButtonPressed' value=''>");
                 Response.Write("<input type='text' style='display:none' name='UserSuppliedName' value ='" + Formatter.EscapeHTML(UserPrefix == null ? "" : UserPrefix) + "'>");
                 if (Federation.TopicExists(TheTopic))
                     Response.Write("<input type='text' style='display:none' name='TopicLastWrite' value ='" + Formatter.EscapeHTML(Federation.GetTopicModificationTime(TheTopic).ToString("s")) + "'>");
Index: WikiEdit.js
===================================================================
--- WikiEdit.js	(revision 641)
+++ WikiEdit.js	(working copy)
@@ -1,13 +1,43 @@
-function textArea_OnFocus(event)
+function CalcEditBoxHeight()
 {
-	document.onkeypress = Document_OnKeyPress;
+	var answer = CalcEditZoneHeight();
+	return answer;
 }
 
-function textArea_OnBlur(event)
+function CalcEditZoneHeight()
 {
-	document.onkeypress = null;
+	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();
+		}
+	}
+}
+
 function Document_OnKeyPress(event)
 {
 	if (event != null) // FireFox only
@@ -28,25 +58,26 @@
 	return true;
 }
 
-function CalcEditBoxHeight()
+function MainHeight()
 {
-	var answer = CalcEditZoneHeight();
+	var answer = document.body.clientHeight;
+	var e;
 	return answer;
 }
 
-function CalcEditZoneHeight()
+function MainWidth()
 {
-	var answer = MainHeight();
+	var answer = document.body.clientWidth;
+	var e;
+
+	e = document.getElementById("Sidebar");
+	if (e != null)
+	{
+		answer -= e.scrollWidth;
+	}
 	return answer;
 }
 
-function ShowTip(tipid)
-{
-	var s = document.getElementById(tipid);
-	TipArea.innerHTML = s.innerHTML;
-	TipArea.style.display = 'block';
-}
-
 function preview()
 {
 	var s = document.forms["Form1"].Text1.value;
@@ -55,22 +86,31 @@
 	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')
+	SetUserName();
+	SetCaptcha();
+	var r = document.getElementById("ReturnTopic");
+    	document.getElementById("SaveButtonPressed").value = "Save"; 
+	if (r != null)
 	{
-		a.style.display = 'none';
-		b.style.display = 'block';
+		r.value = ""; // prevent return action by emptying this out
 	}
-	else
-	{
-		b.style.display = 'none';
-		a.style.display = 'block';
-	}	
+	document.getElementById("Form1").submit();
 }
 
+function SaveAndReturn()
+{
+	SetUserName();
+    	document.getElementById("SaveButtonPressed").value = "Back"; 
+	document.getElementById("Form1").submit();
+}
+
+function search()
+{
+	window.open('Search.aspx');
+}
+
 function SetCaptcha()
 {
     var c = document.getElementById("CaptchaContext"); 
@@ -92,74 +132,41 @@
 {
 	var r = document.getElementById("UserNameEntryField");
 	if (r != null)
+	{
 		document.forms["Form1"].UserSuppliedName.value = r.value;
+	}
 }
-
-function Cancel()
+function ShowTip(tipid)
 {
-	history.back();
+	var s = document.getElementById(tipid);
+	TipArea.innerHTML = s.innerHTML;
+	TipArea.style.display = 'block';
 }
 
-function Save()
+function Swap(alpha, beta)
 {
-	SetUserName();
-	SetCaptcha();
-	var r = document.getElementById("ReturnTopic");
-	if (r != null)
-		r.value = ""; // prevent return action by emptying this out
-	document.getElementById("Form1").submit();
+	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 SaveAndReturn()
+function textArea_OnBlur(event)
 {
-	SetUserName();
-	document.getElementById("Form1").submit();
+	document.onkeypress = null;
 }
 
-function search()
+function textArea_OnFocus(event)
 {
-	window.open('Search.aspx');
+	document.onkeypress = Document_OnKeyPress;
 }
 
 
-function MainHeight()
-{
-	var answer = document.body.clientHeight;
-	var e;
-	return answer;
-}
-
-function MainWidth()
-{
-	var answer = document.body.clientWidth;
-	var e;
-
-	e = document.getElementById("Sidebar");
-	if (e != null)
-		answer -= e.scrollWidth;
-	return answer;
-}
-
-
-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();
-		}
-	}
-}
