Index: trunk/webapps/einotebook/scripts/LoadEvents.js
===================================================================
--- trunk/webapps/einotebook/scripts/LoadEvents.js	(revision 434)
+++ trunk/webapps/einotebook/scripts/LoadEvents.js	(revision 468)
@@ -9,5 +9,5 @@
     var xmlDoc = parser.parseFromString(response,"text/xml");
     var eventTags = xmlDoc.getElementsByTagName("SCRIPT_EVENT");
-    console.log("parsing incident xml file");
+    console.log("parsing incident xml file containing "+eventTags.length+" event tags.");
     // Process each SCRIPT_EVENT tag
     for (var i = 0; i < eventTags.length; i++)
@@ -33,8 +33,4 @@
                         break;
                     case "INCIDENT":
-                        incidentNum = Number(currEvt.childNodes[child].attributes["LogNum"].value);
-                        incidentTitle =  currEvt.childNodes[child].textContent;
-                        break;
-                    case "GENERAL_INFO":  
                         /* This tag identifies a new incident.  As long as it appears before any
                         other tags, we can use it to create a new incident. (The alternative is to
@@ -42,11 +38,24 @@
                         we load events.)  Creating an event (below) requires that the incident has already
                         been created. */
+                        incidentNum = Number(currEvt.childNodes[child].attributes["LogNum"].value);
+                        // If this incident number doesn't exist
+                        if (incidents.get(incidentNum) == undefined)
+                        {
+                            incidentTitle =  currEvt.childNodes[child].textContent;
+                            // Construct the incident
+                            var theIncident = new Incident(evtTime, incidentNum, incidentTitle, "");
+                            // Add the incident to the list of incidents
+                            incidents.add(theIncident);
+                        }
+                        break;
+                    case "GENERAL_INFO":  
+                        // Add the summary description to the incident
                         var desc = currEvt.childNodes[child].getElementsByTagName("TEXT")[0].textContent;
-                        var theIncident = new Incident(evtTime, incidentNum, incidentTitle, desc);
-                        incidents.add(theIncident);
-			// Create an entry showing the Incident start description. Fixes ticket #164
+                        incidentToUpdate = incidents.get(incidentNum);
+                        incidentToUpdate.setSummary(desc);                        
+                        // Create an entry showing the Incident start description. Fixes ticket #164
                         var result = new Array();   
                         result.push("Description:");
-			result.push(desc);
+                        result.push(desc);
                         proparray.push(new Property("Incident Start",result));
                         break;
@@ -101,6 +110,6 @@
                 }
             }
-        }
-        //console.log(evtTime.format(), incidentNum, proparray.length, evalarray.length);
+        }//end one event
+        // console.log(evtTime.format(), incidentNum, proparray.length, evalarray.length);
         // Ignore Media Log incident and empty nodes
         if (incidentNum != undefined && incidentNum != 100)
@@ -111,5 +120,9 @@
                 new Evaluations(evalarray)) );
         }
-    }
+    }// end all events
+    console.log("Done parsing xml, " + events.length + " events and " +incidents.length + " incidents saved.");
+    
+    // NOW THAT WE HAVE THE EVENT LIST WE CAN PERFORM SETUP
+    setupNotebook();
 }
 
@@ -208,16 +221,18 @@
     return result;
 }
-// MAIN
-//console.log("starting LoadEvents");
-try {
-    // the script must be located where accessible by the web server
-    var scriptFilename = "../dynamicdata/incident_script.xml";
-    console.log("Attempting to load ", scriptFilename);
-    // Now load the Incident Script and go parse it
-    loadJSON(scriptFilename, parseXml)
-
-    } catch(e) {
-        console.log("Error attempt to parse incident script "+response)
-    }
-
-
+// MAIN ENTRY POINT for this application
+function init()
+{
+    try {
+        // the script must be located where accessible by the web server
+        var scriptFilename = "../dynamicdata/incident_script.xml";
+        console.log("LoadEvents.js main Attempting to load ", scriptFilename);
+        // Now load the Incident Script and go parse it
+        // NB: This is an async function, so all other notebook setup must be in the callback.
+        loadJSON(scriptFilename, parseXml)
+
+        } catch(e) {
+            console.log("Error attempting to parse incident script "+response)
+        }
+}
+
