// Detect browser quirks that we should be aware of. function needsDynPrefix() { var span = document.createElement("span"); span.innerHTML = ""; var scripts = span.getElementsByTagName("script"); return scripts.length == 0; } var dynPrefix = needsDynPrefix() ? "A" : ""; // Function versions of operators function not(x) { return !x; } function neg(x) { return -x; } function eq(x, y) { return x == y; } function plus(x, y) { return x + y; } function minus(x, y) { return x - y; } function times(x, y) { return x * y; } function div(x, y) { return x / y; } function divInt(x, y) { var n = x / y; return n < 0 ? Math.ceil(n) : Math.floor(n); } function mod(x, y) { return x % y; } function modInt(x, y) { var n = x % y; return n < 0 ? Math.ceil(n) : Math.floor(n); } function lt(x, y) { return x < y; } function le(x, y) { return x <= y; } // Characters function isLower(c) { return c >= 'a' && c <= 'z'; } function isUpper(c) { return c >= 'A' && c <= 'Z'; } function isAlpha(c) { return isLower(c) || isUpper(c); } function isDigit(c) { return c >= '0' && c <= '9'; } function isAlnum(c) { return isAlpha(c) || isDigit(c); } function isBlank(c) { return c == ' ' || c == '\t'; } function isSpace(c) { return isBlank(c) || c == '\r' || c == '\n'; } function isXdigit(c) { return isDigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); } function toLower(c) { return c.toLowerCase(); } function toUpper(c) { return c.toUpperCase(); } // Lists function cons(v, ls) { return { next : ls, data : v }; } function rev(ls) { var acc = null; for (; ls; ls = ls.next) acc = cons(ls.data, acc); return acc; } function concat(ls1, ls2) { var acc = ls2; ls1 = rev(ls1); for (; ls1; ls1 = ls1.next) acc = cons(ls1.data, acc); return acc; } function member(x, ls) { for (; ls; ls = ls.next) if (ls.data == x) return true; return false; } function remove(x, ls) { var acc = null; for (; ls; ls = ls.next) if (ls.data == x) return concat(acc, ls.next); else acc = cons(ls.data, acc); return ls; } function union(ls1, ls2) { var acc = ls2; for (; ls1; ls1 = ls1.next) if (!member(ls1.data, ls2)) acc = cons(ls1.data, acc); return acc; } function length(ls) { var acc = 0; for (; ls; ls = ls.next) ++acc; return acc; } // Floats function float(n) { return n; } function trunc(n) { return ~~n; } function ceil(n) { return Math.ceil(n); } function round(n) { return Math.round(n); } // Time, represented as counts of microseconds since the epoch function showTime(tm) { var newDate = new Date(); newDate.setTime(tm / 1000); var r = newDate.toUTCString(); return r; } function now() { return (new Date()).getTime() * 1000; } function diffInSeconds(tm1, tm2) { return Math.round((tm2 - tm1) / 1000000); } function toSeconds(tm) { return Math.round(tm / 1000000); } function addSeconds(tm, n) { return tm + n * 1000000; } function stringToTime_error(string) { var t = Date.parse(string); if (isNaN(t)) onFail("Invalid date string: " + string); else return t * 1000; } function stringToTime(string) { try { var t = Date.parse(string); if (isNaN(t)) return null; else return t * 1000; } catch (e) { return null; } } /* strftime for Javascript Copyright (c) 2008, Philip S Tellis All rights reserved. This code is distributed under the terms of the BSD licence Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The names of the contributors to this file may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ Date.ext = {}; Date.ext.util = {}; Date.ext.util.xPad=function(x, pad, r) { if(typeof(r) == 'undefined') { r=10; } for( ; parseInt(x, 10)1; r/=10) x = pad.toString() + x; return x.toString(); }; Date.prototype.locale = 'en-US'; if(document.getElementsByTagName('html') && document.getElementsByTagName('html')[0].lang) { Date.prototype.locale = document.getElementsByTagName('html')[0].lang; } Date.ext.locales = { }; Date.ext.locales.en = { a: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], A: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], b: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], B: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], c: '%a %d %b %Y %T %Z', p: ['AM', 'PM'], P: ['am', 'pm'], x: '%d/%m/%y', X: '%T' }; Date.ext.locales['en-US'] = Date.ext.locales.en; Date.ext.locales['en-US'].c = '%a %d %b %Y %r %Z'; Date.ext.locales['en-US'].x = '%D'; Date.ext.locales['en-US'].X = '%r'; Date.ext.locales['en-GB'] = Date.ext.locales.en; Date.ext.locales['en-AU'] = Date.ext.locales['en-GB']; Date.ext.formats = { a: function(d) { return Date.ext.locales[d.locale].a[d.getDay()]; }, A: function(d) { return Date.ext.locales[d.locale].A[d.getDay()]; }, b: function(d) { return Date.ext.locales[d.locale].b[d.getMonth()]; }, B: function(d) { return Date.ext.locales[d.locale].B[d.getMonth()]; }, c: 'toLocaleString', C: function(d) { return Date.ext.util.xPad(parseInt(d.getFullYear()/100, 10), 0); }, d: ['getDate', '0'], e: ['getDate', ' '], g: function(d) { return Date.ext.util.xPad(parseInt(Date.ext.util.G(d)/100, 10), 0); }, G: function(d) { var y = d.getFullYear(); var V = parseInt(Date.ext.formats.V(d), 10); var W = parseInt(Date.ext.formats.W(d), 10); if(W > V) { y++; } else if(W===0 && V>=52) { y--; } return y; }, H: ['getHours', '0'], I: function(d) { var I=d.getHours()%12; return Date.ext.util.xPad(I===0?12:I, 0); }, j: function(d) { var ms = d - new Date('' + d.getFullYear() + '/1/1 GMT'); ms += d.getTimezoneOffset()*60000; var doy = parseInt(ms/60000/60/24, 10)+1; return Date.ext.util.xPad(doy, 0, 100); }, m: function(d) { return Date.ext.util.xPad(d.getMonth()+1, 0); }, M: ['getMinutes', '0'], p: function(d) { return Date.ext.locales[d.locale].p[d.getHours() >= 12 ? 1 : 0 ]; }, P: function(d) { return Date.ext.locales[d.locale].P[d.getHours() >= 12 ? 1 : 0 ]; }, S: ['getSeconds', '0'], u: function(d) { var dow = d.getDay(); return dow===0?7:dow; }, U: function(d) { var doy = parseInt(Date.ext.formats.j(d), 10); var rdow = 6-d.getDay(); var woy = parseInt((doy+rdow)/7, 10); return Date.ext.util.xPad(woy, 0); }, V: function(d) { var woy = parseInt(Date.ext.formats.W(d), 10); var dow1_1 = (new Date('' + d.getFullYear() + '/1/1')).getDay(); var idow = woy + (dow1_1 > 4 || dow1_1 <= 1 ? 0 : 1); if(idow == 53 && (new Date('' + d.getFullYear() + '/12/31')).getDay() < 4) { idow = 1; } else if(idow === 0) { idow = Date.ext.formats.V(new Date('' + (d.getFullYear()-1) + '/12/31')); } return Date.ext.util.xPad(idow, 0); }, w: 'getDay', W: function(d) { var doy = parseInt(Date.ext.formats.j(d), 10); var rdow = 7-Date.ext.formats.u(d); var woy = parseInt((doy+rdow)/7, 10); return Date.ext.util.xPad(woy, 0, 10); }, y: function(d) { return Date.ext.util.xPad(d.getFullYear()%100, 0); }, Y: 'getFullYear', z: function(d) { var o = d.getTimezoneOffset(); var H = Date.ext.util.xPad(parseInt(Math.abs(o/60), 10), 0); var M = Date.ext.util.xPad(o%60, 0); return (o>0?'-':'+') + H + M; }, Z: function(d) { return d.toString().replace(/^.*\(([^)]+)\)$/, '$1'); }, '%': function(d) { return '%'; } }; Date.ext.aggregates = { c: 'locale', D: '%m/%d/%y', h: '%b', n: '\n', r: '%I:%M:%S %p', R: '%H:%M', t: '\t', T: '%H:%M:%S', x: 'locale', X: 'locale' }; Date.ext.aggregates.z = Date.ext.formats.z(new Date()); Date.ext.aggregates.Z = Date.ext.formats.Z(new Date()); Date.ext.unsupported = { }; function strftime(fmt, thisTime) { var thisDate = new Date(); thisDate.setTime(thisTime / 1000); if(!(thisDate.locale in Date.ext.locales)) { if(thisDate.locale.replace(/-[a-zA-Z]+$/, '') in Date.ext.locales) { thisDate.locale = thisDate.locale.replace(/-[a-zA-Z]+$/, ''); } else { thisDate.locale = 'en-US'; } } var d = thisDate; while(fmt.match(/%[cDhnrRtTxXzZ]/)) { fmt = fmt.replace(/%([cDhnrRtTxXzZ])/g, function(m0, m1) { var f = Date.ext.aggregates[m1]; return (f == 'locale' ? Date.ext.locales[d.locale][m1] : f); }); } var str = fmt.replace(/%([aAbBCdegGHIjmMpPSuUVwWyY%])/g, function(m0, m1) { var f = Date.ext.formats[m1]; if(typeof(f) == 'string') { return d[f](); } else if(typeof(f) == 'function') { return f.call(d, d); } else if(typeof(f) == 'object' && typeof(f[0]) == 'string') { return Date.ext.util.xPad(d[f[0]](), f[1]); } else { return m1; } }); d=null; return str; }; // End of code from Philip S Tellis // Error handling function whine(msg) { alert(msg); throw msg; } function pf(loc) { throw ("Pattern match failure (" + loc + ")"); } var lameDuck = false; function runHandlers(kind, ls, arg) { if (!lameDuck) { if (ls == null) alert(kind + ": " + arg); for (; ls; ls = ls.next) try { exec({c:"a", f:{c:"a", f:ls.data, x:{c:"c", v:arg}}, x:{c:"c", v:null}}); } catch (v) { } } } var errorHandlers = null; function onError(f) { errorHandlers = cons(f, errorHandlers); } function er(s) { runHandlers("Error", errorHandlers, s); throw {uw_error: s}; } var failHandlers = null; function onFail(f) { failHandlers = cons(f, failHandlers); } function doExn(v) { if (v == null || v.uw_error == null) { var s = (v == null ? "null" : v.message ? v.message : v.toString()); if (v != null && v.fileName && v.lineNumber) s += " (" + v.fileName + ":" + v.lineNumber + ")"; runHandlers("Fail", failHandlers, s); } } var disconnectHandlers = null; function flift(f) { return {c: "c", v:{env:cons(f,null), body:{c:"v", n:1}}}; } function onDisconnect(f) { disconnectHandlers = cons(flift(f), disconnectHandlers); } function discon() { runHandlers("Disconnect", disconnectHandlers, null); } var connectHandlers = null; function onConnectFail(f) { connectHandlers = cons(flift(f), connectHandlers); } function conn() { runHandlers("Connect", connectHandlers, null); } var serverHandlers = null; function onServerError(f) { serverHandlers = cons(f, serverHandlers); } function servErr(s) { window.setTimeout(function () { runHandlers("Server", serverHandlers, s); }, 0); } // Key events var uw_event = null; function kc() { return window.event ? event.keyCode : (uw_event ? uw_event.which : 0); } // Document events function uw_handler(name, f) { var old = document[name]; if (old == undefined) document[name] = function(event) { uw_event = event; execF(f); }; else document[name] = function(event) { uw_event = event; old(); execF(f); }; } function uw_onClick(f) { uw_handler("onclick", f); } function uw_onDblclick(f) { uw_handler("ondblclick", f); } function uw_onMousedown(f) { uw_handler("onmousedown", f); } function uw_onMouseup(f) { uw_handler("onmouseup", f); } function uw_keyHandler(name, f) { var old = document[name]; if (old == undefined) document[name] = function(event) { uw_event = event; execF(execF(f, kc())); }; else document[name] = function(event) { uw_event = event; old(); execF(execF(f, kc())); }; } function uw_onKeydown(f) { uw_keyHandler("onkeydown", f); } function uw_onKeypress(f) { uw_keyHandler("onkeypress", f); } function uw_onKeyup(f) { uw_keyHandler("onkeyup", f); } // Cancelling of further event processing function uw_preventDefault() { var e = window.event ? window.event : uw_event; e.returnValue = false; if (e.preventDefault) e.preventDefault(); } function uw_stopPropagation() { var e = window.event ? window.event : uw_event; e.cancelBubble = true; if (e.stopPropagation) e.stopPropagation(); } // Embedding closures in XML strings function cs(f) { return {closure: f}; } function isWeird(v) { return v.closure != null || v.cat1 != null; } function cat(s1, s2) { if (isWeird(s1) || isWeird(s2)) return {cat1: s1, cat2: s2}; else return s1 + s2; } var closures = []; var freeClosures = null; function newClosure(f) { var n; if (freeClosures == null) { n = closures.length; } else { n = freeClosures.data; freeClosures = freeClosures.next; } closures[n] = f; return n; } function freeClosure(n) { closures[n] = null; freeClosures = cons(n, freeClosures); } function cr(n) { return closures[n]; } function flatten(cls, tr) { if (tr.cat1 != null) return flatten(cls, tr.cat1) + flatten(cls, tr.cat2); else if (tr.closure != null) { var cl = newClosure(tr.closure); cls.v = cons(cl, cls.v); return "cr(" + cl + ")"; } else return tr; } function flattenLocal(s) { var cls = {v : null}; var r = flatten(cls, s); for (cl = cls.v; cl != null; cl = cl.next) freeClosure(cl.data); return r; } // Dynamic tree management function populate(node) { var s = node.signal; var oldSources = node.sources; try { var sr = execF(s, null); var newSources = sr._sources; for (var sp = oldSources; sp; sp = sp.next) if (!member(sp.data, newSources)) sp.data.dyns = remove(node, sp.data.dyns); for (var sp = newSources; sp; sp = sp.next) if (!member(sp.data, oldSources)) sp.data.dyns = cons(node, sp.data.dyns); node.sources = newSources; node.recreate(sr._data); } catch (v) { doExn(v); } } function sc(v) { return {data : v, dyns : null}; } function sv(s, v) { if (s.data != v) { s.data = v; for (var ls = s.dyns; ls; ls = ls.next) if (!ls.dead) populate(ls.data); } } function sg(s) { return s.data; } function ss(s) { return {env:cons(s, null), body:{c:"r", l: cons({n:"sources", v:{c:"c", v:cons(s, null)}}, cons({n:"data", v:{c:"f", f:sg, a:cons({c:"v", n:1}, null)}}, null))}}; } function sr(v) { return {env:null, body:{c:"c", v:{_sources : null, _data : v}}}; } function sb(x,y) { return {env:cons(y,cons(x,null)), body:{c:"=", e1:{c:"a", f:{c:"v", n:2}, x:{c:"c", v:null}}, e2:{c:"=", e1:{c:"a", f:{c:"a", f:{c:"v", n:2}, x:{c:".", r:{c:"v", n:0}, f:"data"}}, x:{c:"c", v:null}}, e2:{c:"r", l:cons( {n:"sources", v:{c:"f", f:union, a:cons({c:".", r:{c:"v", n:1}, f:"sources"}, cons({c:".", r:{c:"v", n:0}, f:"sources"}, null))}}, cons({n:"data", v:{c:".", r:{c:"v", n:0}, f:"data"}}, null))}}}}; } function scur(s) { return execF(s, null)._data; } function lastParent() { var pos = document.body; while (pos.lastChild && pos.lastChild.nodeType == 1) pos = pos.lastChild; pos = pos.parentNode; return pos; } function parent() { return thisScript ? thisScript.parentNode : lastParent(); } function addNode(node) { if (thisScript) thisScript.parentNode.replaceChild(node, thisScript); else lastParent().appendChild(node); } var thisScript = null; function runScripts(node) { if (node.getElementsByTagName) { var savedScript = thisScript; var scripts = node.getElementsByTagName("script"), scriptsCopy = []; var len = scripts.length; for (var i = 0; i < len; ++i) scriptsCopy[i] = scripts[i]; for (var i = 0; i < len; ++i) { thisScript = scriptsCopy[i]; try { eval(thisScript.text); } catch (v) { doExn(v); } if (thisScript.parentNode) thisScript.parentNode.removeChild(thisScript); } thisScript = savedScript; } } // Dynamic tree entry points function killScript(scr) { scr.dead = true; for (var ls = scr.sources; ls; ls = ls.next) ls.data.dyns = remove(scr, ls.data.dyns); for (var ls = scr.closures; ls; ls = ls.next) freeClosure(ls.data); } // Sometimes we wind up with tables that contain