Index: moodle/lib/ajax/ajaxcourse.js
--- moodle/lib/ajax/ajaxcourse.js Base (1.9.6.5)
+++ moodle/lib/ajax/ajaxcourse.js Locally Modified (Based On 1.9.6.5)
@@ -59,8 +59,11 @@
     this.leftcolumn = null;
     this.rightcolumn = null;
     this.adminBlock = null;
     this.icons = [];
     this.marker = null;
+    this.numsections = null;
 
     //things to process onload
     onloadobj.add('main.process_document();');
@@ -115,8 +118,13 @@
     this.rightcolumn = new column_class('right-column', "blocks", null, 'r');
 
     //process sections
-    var ct = 0;
-    while (document.getElementById('section-'+ct) != null) {
+    var maxct = this.portal.numsections;+        
+    this.courseformat = this.portal.courseformat;
+    
+    for(var ct=0; ct <= maxct; ct++){
+        if(document.getElementById('section-'+ct) != null) {  
         this.sections[ct] = new section_class('section-'+ct, "sections", null, ct!=0?true:false);
         this.sections[ct].addToGroup('resources');
         if (ct > 0) {
@@ -125,13 +133,14 @@
                 this.sectiondates[ct] = sectiontitle.innerHTML;
             }
         }
-        ct++;
     }
+    }
     if (this.debug) {
         YAHOO.log("Processed "+ct+" sections");
     }
 
     this.adminBlock = YAHOO.util.Dom.getElementsByClassName('block_adminblock')[0]; 
     YAHOO.log("admin - "+this.adminBlock.className);
 }
 
Index: moodle/lib/ajax/ajaxlib.php
--- moodle/lib/ajax/ajaxlib.php Base (1.40.6.7)
+++ moodle/lib/ajax/ajaxlib.php Locally Modified (Based On 1.40.6.7)
@@ -145,7 +145,7 @@
      * Prints the JavaScript code needed to set up AJAX for the course.
      */
     function print_javascript($courseid, $return=false) {
 
         $blocksoutput = $output = '';
         for ($i=0; $i<count($this->blocks); $i++) {
@@ -160,10 +160,12 @@
         $output .= "<script type=\"text/javascript\">\n";
         $output .= "    main.portal.id = ".$courseid.";\n";
         $output .= "    main.portal.blocks = new Array(".$blocksoutput.");\n";
         $output .= "    main.portal.strings['wwwroot']='".$CFG->wwwroot."';\n";
         $output .= "    main.portal.strings['pixpath']='".$CFG->pixpath."';\n";
         $output .= "    main.portal.strings['marker']='".get_string('markthistopic', '', '_var_')."';\n";
         $output .= "    main.portal.strings['marked']='".get_string('markedthistopic', '', '_var_')."';\n";
+        $output .= "    main.portal.numsections = ".$COURSE->numsections.";\n";
         $output .= "    main.portal.strings['hide']='".get_string('hide')."';\n";
         $output .= "    main.portal.strings['hidesection']='".get_string('hidesection', '', '_var_')."';\n";
         $output .= "    main.portal.strings['show']='".get_string('show')."';\n";
