Index: trunk/webapps/EInotebook/scripts/LoadEvents.js
===================================================================
--- trunk/webapps/EInotebook/scripts/LoadEvents.js	(revision 361)
+++ trunk/webapps/EInotebook/scripts/LoadEvents.js	(revision 363)
@@ -1,23 +1,3 @@
-var xmlDoc;
-function loadJSON(inFile, callback)
-{
-    var xobj = new XMLHttpRequest();
-    // Assume XML unless filename ends with .json
-    if (inFile.endsWith(".json"))
-    {
-        xobj.overrideMimeType("application/json");
-    }
-    xobj.open('GET', inFile, true);
-    xobj.onreadystatechange = function()
-    {
-        if (xobj.readyState == 4 && xobj.status == "200")
-        {
-            callback(xobj.responseText);
-        }
-    };
-    // We want ajax to ignore any cached responses
-    xobj.setRequestHeader('If-Modified-Since', 'Sat, 01 Jan 2000 01:01:01 GMT')
-    xobj.send(null);
-}
+
 
 // Parse the entire Incident XML Script file 
@@ -27,7 +7,7 @@
     // Create a parser and grab the high level tag we're interested in
     var parser = new DOMParser();
-    xmlDoc = parser.parseFromString(response,"text/xml");
+    var xmlDoc = parser.parseFromString(response,"text/xml");
     var eventTags = xmlDoc.getElementsByTagName("SCRIPT_EVENT");
-
+    console.log("parsing incident xml file");
     // Process each SCRIPT_EVENT tag
     for (var i = 0; i < eventTags.length; i++)
@@ -54,5 +34,11 @@
                         incidentNum = Number(currEvt.childNodes[child].attributes["LogNum"].value); 
                         break;
-                    case "GENERAL_INFO":  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
+                        have a separate function that parses xml to extract incidents before
+                        we load events.)  Creating an event (below) requires that the incident has already
+                        been created. */
+                        break;
                     case "CAD_DATA": 
                         var caddata = parseCAD(currEvt.childNodes[child]); 
@@ -84,12 +70,15 @@
         }
         //console.log(evtTime.format(), incidentNum, proparray.length, evalarray.length);
-        if (incidentNum != undefined)
+        // Ignore Media Log incident and empty nodes
+        if (incidentNum != undefined && incidentNum != 100)
         {
-          events.add(new Event(evtTime, incidents.get(incidentNum), new Properties(proparray), 
+          // Create new event with fields obtained from xml file
+          events.add(new Event(evtTime, incidents.get(incidentNum), 
+                new Properties(proparray), 
                 new Evaluations(evalarray)) );
         }
     }
+}
 
-}
 function parseCAD(element)
 {
@@ -148,5 +137,21 @@
 
 // MAIN
-loadJSON("full_script.xml", parseXml)
-// Note: the script has the Media Log event removed
+console.log("starting LoadEvents");
+/** Load the sim script name file and extract the filename of the Incident Script */
+loadJSON("../sim_scriptname.json", function(response)
+{
+    console.log("scriptname file loaded");
+    try {
+        var scriptnamejson = JSON.parse(response);
+        // For now the script must be located in the EInotebook folder.
+        // It would be better to use the file located in trunk/scripts folder. 
+        var scriptFilename = scriptnamejson.filename;
+        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 sim_scriptname.json: "+response)
+        }
+});
+
