Move contentPage.onload in/out of HTML
EPF-78
diff --git a/source/app/models/checkout.rb b/source/app/models/checkout.rb
index 869b163..403f54f 100644
--- a/source/app/models/checkout.rb
+++ b/source/app/models/checkout.rb
@@ -5,13 +5,12 @@
 
 class Checkout < ActiveRecord::Base
   
-  belongs_to :version
+  belongs_to :version # Version we are creating
   belongs_to :user
   belongs_to :page
   belongs_to :site
   
-  # Version we are checking out
-  attr_accessor :source_version
+  attr_accessor :source_version # Version we are checking out
   
   # Note supplied with checkout will be used to create Version.note
   attr_accessor :note
@@ -76,7 +75,9 @@
     h = h.gsub(Page::TREEBROWSER_PLACEHOLDER, self.page.treebrowser_tag) if self.page.treebrowser_tag
     h = h.gsub(Page::COPYRIGHT_PLACEHOLDER, self.page.copyright_tag) if self.page.copyright_tag
     h = h.gsub('class="pageTitle"', 'nowrap="true" class="pageTitle"') # TODO workaround for 250148: No-wrap should be part of CSS file https://bugs.eclipse.org/bugs/show_bug.cgi?id=250148
-    self.page.html = Nokogiri::HTML(h).to_html # this wil force html, body tags
+    h = Nokogiri::HTML(h).to_html # this wil force html, body tags
+    h = h.gsub(/<\/body>/,Page::BODY_CLOSING_TAG) # Put back in the contentPage.onload
+    self.page.html = h
     # TODO set title equal to pageTitle? 
     self.destroy
   end
@@ -100,6 +101,7 @@
     # 3. the EPF iframe element is removed
     # 4. the copyright_tag is replaced by a placeholder tag # DISABLED, didn't work after upgrade of EPF
     # 5. head tag is removed, because this TinyMCE cannot (and should not) manage this (this was BUG 96 - Doubling meta-tags)
+    # 6. replace IBM contentPage.onload for normal body tag
     # 
     # See also #Page.before_create 
     #-- 
@@ -111,6 +113,7 @@
     h = h.gsub(Page::TREEBROWSER_PATTERN, Page::TREEBROWSER_PLACEHOLDER) # 2
     #html = html.gsub(COPYRIGHT_PATTERN, COPYRIGHT_PLACEHOLDER) # 4
     h = h.gsub(Page::HEAD_PATTERN, '') # 5
+    h = h.gsub(Page::BODY_CLOSING_TAG_PATTERN, '</body>') # 6
     self.version.html = h
   end
   
diff --git a/source/app/models/page.rb b/source/app/models/page.rb
index d62fe6d..5234b7e 100644
--- a/source/app/models/page.rb
+++ b/source/app/models/page.rb
@@ -34,7 +34,11 @@
   # Used to remove onload event from HTML files because it crashed the HTML Editor
   BODY_TAG_PATTERN = /<body.*>/i
   # Used to add the page_script
-  BODY_CLOSING_TAG_PATTERN = /<\/body>/i
+  BODY_CLOSING_TAG_PATTERN = /<\/body>.*?<script.*?<\/script>/m
+  BODY_CLOSING_TAG = "</body>
+<script type=\"text/javascript\" language=\"JavaScript\">
+    contentPage.onload();
+</script>"
   # Used to fix some layout problems with the 'horizontal rule'
   SHIM_TAG_PATTERN = /images\/shim.gif(")?( )*\/?>.?( )*?.?( )*?<\/td>/im 
   # Used to fix some layout problems with the 'horizontal rule'
diff --git a/source/app/models/version.rb b/source/app/models/version.rb
index a7e8447..2a336d6 100644
--- a/source/app/models/version.rb
+++ b/source/app/models/version.rb
@@ -33,7 +33,10 @@
   def previous_version
     case self.version
     when 0 then nil 
-    when nil then self.page.current_version 
+    when nil # TODO when the version no is nil, it is a checked out version
+      if true
+      self.page.current_version 
+      end
     else Version.find(:first, :conditions => ['page_id=? and version=?', self.page_id, self.version - 1])
     end
   end