Index: /trunk/webapps/EInotebook/index.html
===================================================================
--- /trunk/webapps/EInotebook/index.html	(revision 359)
+++ /trunk/webapps/EInotebook/index.html	(revision 363)
@@ -1,5 +1,5 @@
 <html>
   <head>
-    <title>Electronic Instructor Notebook v0.1</title>
+    <title>Electronic Instructor Notebook v0.2</title>
     <meta name="apple-mobile-web-app-capable" content="yes">
     <meta name="viewport" content="width=device-width; initial-scale=1.0; user-scalable=0;">
@@ -8,4 +8,5 @@
     <link rel="stylesheet" type="text/css" href="notebook.css"> 
     <link rel="stylesheet" type="text/css" href="ipadapp.css">
+    <script type="text/javascript" src="../js/common.js"></script> 
     <script type="text/javascript" src="scripts/cookies.js"></script>
     <script type="text/javascript" src="scripts/Events.js"></script>
@@ -18,9 +19,9 @@
     <script type="text/javascript" src="scripts/Incident.js"></script>
     <script type="text/javascript" src="scripts/Incidents.js"></script>
+    <script type="text/javascript" src="scripts/LoadEvents.js"></script> 
     <script type="text/javascript" src="scripts/PopulateIncidents.js"></script>
     <!--script type="text/javascript" src="scripts/PopulateEvents.js"></script-->
     <script type="text/javascript" src="summary/summary.js"></script> 
     <script type="text/javascript" src="notebook.js"></script> 
-    <script type="text/javascript" src="scripts/LoadEvents.js"></script> 
   </head>
   <body onLoad="setupNotebook(); run();">
Index: /trunk/webapps/EInotebook/scripts/Event.js
===================================================================
--- /trunk/webapps/EInotebook/scripts/Event.js	(revision 359)
+++ /trunk/webapps/EInotebook/scripts/Event.js	(revision 363)
@@ -50,5 +50,6 @@
 189: "#ffe680",        // CornSilk
 190: "MistyRose", 
-191: "Moccasin" }
+191: "Moccasin",
+181: "PowderBlue" }
 
 	
Index: /trunk/webapps/EInotebook/scripts/Events.js
===================================================================
--- /trunk/webapps/EInotebook/scripts/Events.js	(revision 359)
+++ /trunk/webapps/EInotebook/scripts/Events.js	(revision 363)
@@ -309,5 +309,9 @@
 {
 	var event = null;
-	
+	if (this.length == 0)
+    {
+        console.log("Error: event list is empty in getLastExecutedEvent");
+        return;
+    }
 	// IF there is only one event and it has been executed THEN
 	if (this.length == 1 && this[0].time.getSeconds() <= time)
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)
+        }
+});
+
Index: /trunk/webapps/EInotebook/scripts/PopulateIncidents.js
===================================================================
--- /trunk/webapps/EInotebook/scripts/PopulateIncidents.js	(revision 359)
+++ /trunk/webapps/EInotebook/scripts/PopulateIncidents.js	(revision 363)
@@ -5,2 +5,4 @@
 incidents.add(new Incident(new Time(1, 51, 0), 190, "Tanker Truck vs. Car/Spill", "Incident Description - This is a collision involving a tanker truck and a car that block the #3 and 4 lanes on NB I-5 just north of Main Street. There are 2 minor injured and 1 major injured. Liquid is leaking out of the tanker truck which is identified as milk. The leak is plugged and the fire department sprays the milk down the drain. The fire department, ambulance, additional units, TMT, a big rig tow, and a rotational tow are sent to the scene."));
 incidents.add(new Incident(new Time(2, 17, 0), 191, "RV Fire", "This is an RV fire on the shoulder southbound 73 just north of Bear/Baker Street. There are two injured victims who were pulled from the RV by passers-by. The #3 is closed to fight the fire. The fire department, paramedics, an extra unit, sign truck/s, and ambulance are sent to the scene."));
+// Practice Incident
+incidents.add(new Incident(new Time(0,0,0), 181, "Overturned Hay Truck", "This is a three-vehicle collision involving a hay truck and two cars blocking the #1, 2, and 3 lanes on NB 405 just south of MacArthur Boulevard. The truck spills hay over the #2 and 3 lanes. There is one 11-44 and two minor injured. Ambulance, fire, paramedics, additional units, Maintenance, and coroner are requested on this incident."));
Index: /trunk/webapps/EInotebook/notebook.js
===================================================================
--- /trunk/webapps/EInotebook/notebook.js	(revision 359)
+++ /trunk/webapps/EInotebook/notebook.js	(revision 363)
@@ -30,4 +30,5 @@
 function setupNotebook()
 {
+   console.log("setupNotebook() starting");
    changeTab('summaryTab');
    showContent('summaryPageContent')
@@ -138,25 +139,4 @@
     });
 }
-// Load the dynamic json file for highways, etc.
-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);
-}
 /**
  * Selects a new tab to be viewed. 
