Index: trunk/FACT++/www/index.js
===================================================================
--- trunk/FACT++/www/index.js	(revision 13642)
+++ trunk/FACT++/www/index.js	(revision 13664)
@@ -189,7 +189,5 @@
 function onload()
 {
-    var xmlHttp = null;
-    
-    try { xmlHttp = new XMLHttpRequest(); }
+    try { new XMLHttpRequest(); }
     catch(e)
     {
@@ -218,11 +216,11 @@
 function loadPage(name, z, dz)
 {
-    var xmlHttp = new XMLHttpRequest();
-    xmlHttp.open('POST', name+'.table', true);
-    xmlHttp.onload = function ()
-    {
-        if (xmlHttp.status!=200)
+    var xmlPage = new XMLHttpRequest();
+    xmlPage.open('POST', name+'.table', true);
+    xmlPage.onload = function ()
+    {
+        if (xmlPage.status!=200)
         {
-            alert("ERROR[0] - HTTP request '"+name+".table': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
+            alert("ERROR[0] - HTTP request '"+name+".table': "+xmlPage.statusText+" ["+xmlPage.status+"]");
             //setTimeout("loadPage('+name+')", 5000);
             /****** invalidate ******/
@@ -230,5 +228,5 @@
         }
 
-        buildPage(name, xmlHttp.responseText, z, dz);
+        buildPage(name, xmlPage.responseText, z, dz);
         changePage(z, z+dz);
 
@@ -239,5 +237,5 @@
     };
 
-    xmlHttp.send(null);
+    xmlPage.send(null);
 
     location.hash = name;
@@ -264,10 +262,10 @@
 
     table = document.createElement("table");
-    table.setAttribute("class",       "tborder");
-    table.setAttribute("id",          "table"+z);
-    table.setAttribute("border",      "0");
-    table.setAttribute("cellspacing", "0");
-    table.setAttribute("cellpadding", "6");
-    table.setAttribute("width",       "100%");
+    table.setAttribute("class", "tborder");
+    table.id = "table"+z;
+    table.border = 0;
+    table.cellspacing = 0;
+    table.cellpadding = "6px";
+    table.width = "100%";
     table.setAttribute("style",       "overflow:hidden;position:fixed;top:0px;left:"+window.innerWidth+"px;");
 
@@ -275,6 +273,6 @@
 
     var th = document.createElement("thead");
-    th.setAttribute("colspan", "3");
-    th.setAttribute("width",   "100%");
+    th.colSpan = 3;
+    th.width = "100%";
     table.appendChild(th);
 
@@ -283,7 +281,7 @@
 
     var htd = document.createElement("td");
-    htd.setAttribute("class",   "thead");
-    htd.setAttribute("colspan", "3");
-    htd.setAttribute("width",   "100%");
+    htd.setAttribute("class", "thead");
+    htd.colSpan = 3;
+    htd.width = "100%";
     htr.appendChild(htd);
 
@@ -291,5 +289,5 @@
 
     var htab = document.createElement("table");
-    htab.setAttribute("width", "100%");
+    htab.width = "100%";
     htd.appendChild(htab);
 
@@ -327,7 +325,7 @@
     var sp1 = document.createElement("span");
     var sp2 = document.createElement("span");
-    sp0.setAttribute("id", "ldot" +z);
-    sp1.setAttribute("id", "title"+z);
-    sp2.setAttribute("id", "rdot" +z);
+    sp0.id = "ldot" +z;
+    sp1.id = "title"+z;
+    sp2.id = "rdot" +z;
     sp0.setAttribute("data-color", "3");
     sp2.setAttribute("data-color", "3");
@@ -341,5 +339,5 @@
 
     div1.setAttribute("style", "font-size:small;");
-    div1.setAttribute("id", "reporttime"+z);
+    div1.id = "reporttime"+z;
     div1.appendChild(document.createTextNode("---"));
 
@@ -366,10 +364,10 @@
     var ftd = document.createElement("td");
     ftd.setAttribute("class",   "tfoot");
-    ftd.setAttribute("width",   "100%");
-    ftd.setAttribute("colspan", "3");
+    ftd.width = "100%";
+    ftd.colSpan = 3;
     ftr.appendChild(ftd);
 
     var ftab = document.createElement("table");
-    ftab.setAttribute("width", "100%");
+    ftab.width = "100%";
     ftd.appendChild(ftab);
 
@@ -388,5 +386,5 @@
     fdiv0.setAttribute("style", "font-size:x-large;");
     fdiv1.setAttribute("style", "font-size:small;");
-    fdiv1.setAttribute("id",    "localtime"+z);
+    fdiv1.id = "localtime"+z;
 
     fdiv0.appendChild(document.createTextNode("logbook"));
@@ -409,5 +407,5 @@
         if (cols.length != 3 && cols.length !=4)
         {
-            alert("Size mismatch #"+i+": '"+lines[i]+"' N(cols)="+cols.length);
+            alert("Wrong number of columns in line #"+i+" in '"+name+"': '"+lines[i]+"' N(cols)="+cols.length);
             continue;
         }
@@ -424,24 +422,24 @@
 
             var td = document.createElement("td");
-            td.setAttribute("class",   "container");
-            td.setAttribute("id",      "container");
-            //td.setAttribute("onclick", "save();");
-            td.setAttribute("colspan", "3");
+            td.setAttribute("class", "container");
+            td.id = "container";
+            td.colSpan = 3;
             tr.appendChild(td);
 
             var canv = document.createElement("canvas");
-            canv.setAttribute("id",     "canvas"+z);
-            canv.setAttribute("width",  "1");
-            canv.setAttribute("height", "1");
+            canv.id = "canvas"+z;
+            canv.width = "1";
+            canv.height = "1";
+            //canv.onclick = function() { save(); }
             canv.setAttribute("data-type", check[0]);
             canv.setAttribute("data-file", data[0]);
             canv.setAttribute("data-data", cols[1].substring(check[0].length+data[0].length+2));
-            canv.setAttribute("style", "display:none;");
+//            canv.setAttribute("style", "display:none;");
             td.appendChild(canv);
 
             var img = document.createElement("img");
             img.src = "dummy.png";//needed in firefox
-            img.setAttribute("id",    "image"+z);
-            img.setAttribute("style", "width:1px;height:1px;");
+            img.id = "image"+z;
+            img.setAttribute("style", "width:1px;height:1px;display:none;");
             td.appendChild(img);
 
@@ -471,10 +469,10 @@
         var td1 = document.createElement("td");
         td1.setAttribute("class", "tcol1");
-        td1.setAttribute("width", "100%");
+        td1.width = "100%";
         tr.appendChild(td1);
 
         var td2 = document.createElement("td");
         td2.setAttribute("class", "tcol2");
-        td2.setAttribute("width", "18px");
+        td2.width = "18px";
         if (valid(cols[3]))
         {
@@ -487,5 +485,5 @@
 
         var tab = document.createElement("table");
-        tab.setAttribute("width", "100%");
+        tab.width = "100%";
         td1.appendChild(tab);
 
@@ -499,6 +497,6 @@
 
         var cell2 = document.createElement("td");
+        cell2.id = "data"+counter;
         cell2.setAttribute("class", "tcell2");
-        cell2.setAttribute("id",    "data"+counter);
         cell2.setAttribute("data-form",  cols[2]);
         cell2.appendChild(document.createTextNode("---"));
@@ -515,11 +513,10 @@
     if (debug == true)
     {
-
         tr = document.createElement("tr");
         tr.setAttribute("class", "row");
 
         td = document.createElement("td");
-        td.setAttribute("id", "debug"+z);
-        td.setAttribute("colspan", "3");
+        td.id = "debug"+z;
+        td.colSpan = 3;
         tr.appendChild(td);
 
@@ -559,5 +556,15 @@
 
     if ($("table"+z).offsetHeight == H || cnt==2)
-        return;
+    {
+        // ------ debug -----
+        if (debug == true)
+        {
+            $('debug'+z).innerHTML = "";
+            $('debug'+z).innerHTML += "|W="+W +"/"+H;
+            $('debug'+z).innerHTML += "|H="+h+"/"+$("table"+z).offsetHeight+"/"+img.offsetHeight;
+            $('debug'+z).innerHTML += "|I="+img.style.height+"+"+H+"-"+h;
+        }
+        return;
+    }
 
     resizeimpl(z, ++cnt);
@@ -567,13 +574,4 @@
 {
     resizeimpl(z, 0);
-
-    // ------ debug -----
-    if (debug == true)
-    {
-        $('debug'+z).innerHTML = "";
-        $('debug'+z).innerHTML += "|W="+W +"/"+H;
-        $('debug'+z).innerHTML += "|H="+h+"/"+$("table"+z).offsetHeight+"/"+img.offsetHeight;
-        $('debug'+z).innerHTML += "|I="+img.style.height+"+"+H+"-"+h;
-    }
 }
 
@@ -598,22 +596,17 @@
     }
 
-    //intervalSlide = setInterval("doSlideOut("+z+")", 25);
-
-    //var k = (z+1)%2;
-    //$("table"+k).style.display="";
-    //$("table"+z).style.display="";
-    //$("table"+k).style.zIndex="0";
-    //$("table"+z).style.zIndex="1";
-    //$("table"+k).style.left=0;
-    //$("table"+z).style.left=0;
-    //$("table"+k).style.backgroundColor = "#ffffff";
-    //$("table"+z).style.backgroundColor = "#ffffff";
-    //doresize(k);
-    //intervalSlide = setInterval("doSlide("+z+",1)", 50);
+    var W = window.innerWidth;
+    if (W==0)
+    {
+        $("table"+newz).style.left="0px";
+        $("body").setAttribute("data-visible", newz);
+        $("body").removeChild($("table"+oldz));
+        return;
+    }
 
     if (newz>oldz)
-        $("table"+newz).style.left=window.innerWidth+"px";
+        $("table"+newz).style.left = W+"px";
     else
-        $("table"+newz).style.left=(-window.innerWidth-1)+"px";
+        $("table"+newz).style.left = (-W-1)+"px";
 
     //window.clearTimeout(timeoutText);
@@ -662,104 +655,4 @@
     t1.style.left = x1+"px";
 }
-
-/*
-function doSlide(z, dir)
-{
-    var k = (z+1)%2;
-
-    var W = window.innerWidth;
-
-    var tz = $("table"+z);
-    var tk = $("table"+k);
-
-    var xz = tz.offsetLeft;
-    var xk = tk.offsetLeft;
-
-    var ixz = parseInt(xz, 10);
-    var ikz = parseInt(xk, 10);
-
-    ixz += dir*W/10;
-    ikz -= dir*W/10;
-
-    tz.style.left = parseInt(ixz, 10)+"px";
-    tk.style.left = parseInt(ikz, 10)+"px";
-
-    if (ixz>W/2)
-    {
-        clearInterval(intervalSlide);
-
-        $("table"+k).style.zIndex="1";
-        $("table"+z).style.zIndex="0";
-
-        $("body").setAttribute("data-visible", k);
-        doresize(k);
-
-        intervalSlide = setInterval("doSlide("+z+",-1)", 50);
-    }
-    if (ikz>0)
-    {
-        clearInterval(intervalSlide);
-
-        tz.style.left = 0;
-        tk.style.left = 0;
-
-        tz.style.display="none";
-    }
-}
-
-
-function doSlideOut(z)
-{
-    var table = $("table"+z);
-
-    var W = window.innerWidth;
-    var x = table.offsetLeft;
-
-    var ix = parseInt(x, 10);
-    if (ix>W)
-    {
-        clearInterval(intervalSlide);
-
-        table.style.display="none";
-
-        z = (z+1)%2;
-        table = $("table"+z);
-
-        table.style.display="";
-        table.style.left = window.innerWidth+"px";
-
-        $("body").setAttribute("data-visible", z);
-        doresize(z);
-
-        intervalSlide = setInterval("doSlideIn("+z+")", 25);
-        return;
-    }
-
-    ix += W/10;
-    table.style.left=ix+"px";
-}
-
-function doSlideIn(z)
-{
-    var table = $("table"+z);
-
-    var W = window.innerWidth;
-    var x = table.offsetLeft;
-
-    var ix = parseInt(x, 10);
-
-    ix -= W/10;
-    if (ix<0)
-        ix = 0;
-
-    table.style.left=ix+"px";
-
-    if (ix<=0)
-    {
-        clearInterval(intervalSlide);
-        return;
-    }
-}
-*/
 
 var timeoutText = null;
@@ -775,15 +668,16 @@
     if (isSliding() || !valid(fname))
     {
+        // invalidate?
         timeoutText = setTimeout(refresh_text, 1000);
         return;
     }
 
-    var xmlHttp = new XMLHttpRequest();
-    xmlHttp.open('POST', fname+'.txt', true);
-    xmlHttp.onload = function ()
-    {
-        if (xmlHttp.status!=200)
+    var xmlText = new XMLHttpRequest();
+    xmlText.open('POST', fname+'.txt', true);
+    xmlText.onload = function ()
+    {
+        if (xmlText.status!=200)
         {
-            alert("ERROR[1] - HTTP request '"+fname+".txt': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
+            alert("ERROR[1] - HTTP request '"+fname+".txt': "+xmlText.statusText+" ["+xmlText.status+"]");
             timeoutText = setTimeout(refresh_text, 10000);
             return;
@@ -793,9 +687,9 @@
         {
             cycleCol($("ldot"+z));
-            update_text(fname, xmlHttp.responseText);
+            update_text(fname, xmlText.responseText);
         }
         timeoutText = setTimeout(refresh_text, 3000);
     };
-    xmlHttp.send(null);
+    xmlText.send(null);
 }
 
@@ -811,4 +705,5 @@
 }
 
+/*
 function gray(id, str)
 {
@@ -827,7 +722,6 @@
         e.style.textDecoration="line-through";
     }
-
-}
-
+}
+*/
 var date0 = null;
 
@@ -878,4 +772,7 @@
     for (var line=1; line<tokens.length; line++)
     {
+        if (tokens[line].length==0)
+            continue;
+
         var c = tbody.rows[line-1].cells[1];
         if (c == undefined)
@@ -919,15 +816,16 @@
     if (isSliding() || !valid(fname))
     {
+        // invalidate?
         timeoutGraphics = setTimeout(refresh_graphics, 1000);
         return;
     }
 
-    var xmlHttp = new XMLHttpRequest();
-    xmlHttp.open('POST', fname, true);
-    xmlHttp.onload = function()
-    {
-        if (xmlHttp.status!=200)
+    var xmlGfx = new XMLHttpRequest();
+    xmlGfx.open('POST', fname, true);
+    xmlGfx.onload = function()
+    {
+        if (xmlGfx.status!=200)
         {
-            alert("ERROR[2] - Request '"+fname+"': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
+            alert("ERROR[2] - Request '"+fname+"': "+xmlGfx.statusText+" ["+xmlGfx.status+"]");
             timeoutGraphics = setTimeout(refresh_graphics, 10000);
             //****** invalidate ******
@@ -938,9 +836,9 @@
         {
             cycleCol($("rdot"+z));
-            process_eventdata(xmlHttp.responseText);
+            process_eventdata(xmlGfx.responseText);
         }
         timeoutGraphics = setTimeout(refresh_graphics, 5000)
     };
-    xmlHttp.send(null);
+    xmlGfx.send(null);
 }
 
@@ -1074,5 +972,5 @@
     if (data.length!=40 && data.length!=160 && data.length!=320 && data.length!=1440)
     {
-        alert("Data length mismatch ("+data.length+")");
+        alert("Camera - Received data has invalid size ("+data.length+"b)");
         return;
     }
@@ -1149,10 +1047,12 @@
 }
 
-function drawCamLegend(canv)
-{
-    var vals = canv.getAttribute("data-data").split("/");
-
-    var v0 = parseFloat(vals[0]);
-    var v1 = parseFloat(vals[1]);
+function drawCamLegend(canv, min, max)
+{
+    var unit = canv.getAttribute("data-data");//.split("/");
+    if (unit.length>0)
+        unit = " "+unit;
+
+    var v0 = parseFloat(min);
+    var v1 = parseFloat(max);
 
     var diff = v1-v0;
@@ -1167,13 +1067,17 @@
     ctx.textBaseline = "top";
 
-    for (var i=0; i<9; i++)
+    for (var i=0; i<11; i++)
     {
         ctx.strokeStyle = "#"+color(16*i);
-        ctx.strokeText((v0+diff*i/8)+vals[2], cw-5, 135-i*15);
-    }
-}
-
-function drawGraph(canv, data)
-{
+        ctx.strokeText((v0+diff*i/10)+unit, cw-5, 120-i*12);
+    }
+}
+
+function drawGraph(canv, min, max, data)
+{
+    var unit = canv.getAttribute("data-data");//.split("/");
+    if (unit.length>0)
+        unit = " "+unit;
+
     var cw = canv.width;
     var ch = canv.height;
@@ -1181,6 +1085,4 @@
     var ctx = canv.getContext("2d");
 
-    var vals = canv.getAttribute("data-data").split("/");
-
     var dw = 3;  // tick width
 
@@ -1190,14 +1092,14 @@
     ctx.textAlign = "right";
 
-    var dim0 = ctx.measureText(vals[0]);
-    var dim1 = ctx.measureText(vals[1]);
-
-    var tw = vals.length>=2 ? Math.max(dim0.width, dim1.width)+dw+2 : 0;
-
-    var ml = vals.length>=2 ? 5+tw   : 10; // margin left
-    var mr = 10;                           // margin right
-
-    var mt = vals.length>=2 ? fs/2+5 : 5; // margin top
-    var mb = vals.length>=2 ? fs/2+4 : 5; // margin bottom
+    var dim0 = ctx.measureText(min+unit);
+    var dim1 = ctx.measureText(max+unit);
+
+    var tw = Math.max(dim0.width, dim1.width)+dw+2;
+
+    var ml = 5+tw; // margin left
+    var mr = 10;   // margin right
+
+    var mt = fs/2+5; // margin top
+    var mb = fs/2+4; // margin bottom
 
     var nx = 20;
@@ -1262,16 +1164,18 @@
     ctx.closePath();
 
-    if (vals.length>=2)
-    {
-        ctx.textBaseline = "bottom";
-        ctx.strokeText(vals[0], ml-dw-2, ch-1);
-
-        ctx.textBaseline = "top";
-        ctx.strokeText(vals[1], ml-dw-2, 0);
-    }
-}
+    ctx.textBaseline = "bottom";
+    ctx.strokeText(min+unit, ml-dw-2, ch-1);
+
+    ctx.textBaseline = "top";
+    ctx.strokeText(max+unit, ml-dw-2, 0);
+}
+
+var gfxtime0 = null;
 
 function process_eventdata(result)
 {
+    if (result.length==0)
+        return;
+
     var z = $("body").getAttribute("data-visible");
     var canv = $("canvas"+z);
@@ -1284,15 +1188,32 @@
     ctx.clearRect(0, 0, canv.width, canv.height);
 
+    var data = result.split('\n');
+    if (result.length<3)
+        return;
+
+    var l = data[0].length+1+data[1].length+1;
+
     switch (type)
     {
-    case "hist":   drawGraph(canv, result); break;
-    //case "camera": drawCam(result);     break;
-    case "camera": drawFullCam(result); drawCamLegend(canv); break;
-    }
-
-    $("image"+z).src = canv.toDataURL("image/png");
-}
-
-/*
+        //case "camera": drawCam(result);     break;
+    case "hist":
+        drawGraph(canv, data[0], data[1], result.substr(l));
+        break;
+    case "camera":
+        drawFullCam(result.substr(l));
+        drawCamLegend(canv, data[0], data[1]);
+        break;
+    }
+
+    var date = new Date();
+    if (gfxtime0 != null && gfxdate0.getTime()+60000>date.getTime())
+    {
+        ctx.fillStyle = "rgba(255, 255, 255, 0.75)";
+        ctx.fillRect(0, 0, canv.width, canv.height);
+    }
+
+    //$("image"+z).src = canv.toDataURL("image/png");
+}
+
 function save()
 {
@@ -1306,4 +1227,4 @@
     document.location.href = img;
 }
-*/
+
 window['onload'] = onload;
