/* smartVISU, Martin Gleiß, 2012 - 2015, GPL [http://www.gnu.de] */
function printf(a,b){var c=function(a,b,c){0<c&&(a=a.slice(0,c));return a},g=function(a,b,c){a>>>=0;c=c&&a&&{2:"0b",8:"0",16:"0x"}[b]||"";return c+a.toString(b)};return a.replace(/%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(([\.,])(\*\d+\$|\*|\d+))?([sScboxXuideEfFgG])/g,function(a,m,n,k,h,d,e,f){m="";if("%%"===a)return"%";"+"==n&&(m="+");switch(f){case "s":return c(String(b),k,e);case "S":return c(String(b),k,e).toUpperCase();case "c":return c(String.fromCharCode(+b),k,e);case "b":return g(b,2,m);
case "o":return g(b,8,m);case "x":return g(b,16,m);case "X":return g(b,16,m).toUpperCase();case "u":return g(b,10,m);case "i":case "d":return a=+b||0,a=Math.round(a-a%1),(0>a?"-":m)+String(Math.abs(a));case "e":case "E":case "f":case "F":case "g":case "G":return a=+b,m=0>a?"-":m,n=["toExponential","toFixed","toPrecision"]["efg".indexOf(f.toLowerCase())],f=["toString","toUpperCase"]["eEfFgG".indexOf(f)%2],e=(m+Math.abs(a)[n](e))[f](),"."!=d&&(e=e.replace(".",d)),e;default:return a}})}
function activateAutoReconnect(){if(io.socket){var a=window.setInterval(function(){3==io.socket.readyState&&location.reload(!0)},5E3);window.onbeforeunload=function(){window.clearInterval(a)}}}Number.prototype.limit=function(a,b,c){var g=this;g<a&&(g=a);g>b&&(g=b);c&&(g=Math.floor(g,c));return g};String.prototype.explode=function(a){var b=[];if(this.length)for(b=this.split(void 0!==a?a:","),a=0;a<b.length;a++)b[a]=b[a].trim();return b};
String.prototype.md5=function(){var a=function(a,k){var h=a[0],d=a[1],e=a[2],f=a[3],h=c(h,d,e,f,k[0],7,-680876936),f=c(f,h,d,e,k[1],12,-389564586),e=c(e,f,h,d,k[2],17,606105819),d=c(d,e,f,h,k[3],22,-1044525330),h=c(h,d,e,f,k[4],7,-176418897),f=c(f,h,d,e,k[5],12,1200080426),e=c(e,f,h,d,k[6],17,-1473231341),d=c(d,e,f,h,k[7],22,-45705983),h=c(h,d,e,f,k[8],7,1770035416),f=c(f,h,d,e,k[9],12,-1958414417),e=c(e,f,h,d,k[10],17,-42063),d=c(d,e,f,h,k[11],22,-1990404162),h=c(h,d,e,f,k[12],7,1804603682),f=c(f,
h,d,e,k[13],12,-40341101),e=c(e,f,h,d,k[14],17,-1502002290),d=c(d,e,f,h,k[15],22,1236535329),h=g(h,d,e,f,k[1],5,-165796510),f=g(f,h,d,e,k[6],9,-1069501632),e=g(e,f,h,d,k[11],14,643717713),d=g(d,e,f,h,k[0],20,-373897302),h=g(h,d,e,f,k[5],5,-701558691),f=g(f,h,d,e,k[10],9,38016083),e=g(e,f,h,d,k[15],14,-660478335),d=g(d,e,f,h,k[4],20,-405537848),h=g(h,d,e,f,k[9],5,568446438),f=g(f,h,d,e,k[14],9,-1019803690),e=g(e,f,h,d,k[3],14,-187363961),d=g(d,e,f,h,k[8],20,1163531501),h=g(h,d,e,f,k[13],5,-1444681467),
f=g(f,h,d,e,k[2],9,-51403784),e=g(e,f,h,d,k[7],14,1735328473),d=g(d,e,f,h,k[12],20,-1926607734),h=b(d^e^f,h,d,k[5],4,-378558),f=b(h^d^e,f,h,k[8],11,-2022574463),e=b(f^h^d,e,f,k[11],16,1839030562),d=b(e^f^h,d,e,k[14],23,-35309556),h=b(d^e^f,h,d,k[1],4,-1530992060),f=b(h^d^e,f,h,k[4],11,1272893353),e=b(f^h^d,e,f,k[7],16,-155497632),d=b(e^f^h,d,e,k[10],23,-1094730640),h=b(d^e^f,h,d,k[13],4,681279174),f=b(h^d^e,f,h,k[0],11,-358537222),e=b(f^h^d,e,f,k[3],16,-722521979),d=b(e^f^h,d,e,k[6],23,76029189),
h=b(d^e^f,h,d,k[9],4,-640364487),f=b(h^d^e,f,h,k[12],11,-421815835),e=b(f^h^d,e,f,k[15],16,530742520),d=b(e^f^h,d,e,k[2],23,-995338651),h=l(h,d,e,f,k[0],6,-198630844),f=l(f,h,d,e,k[7],10,1126891415),e=l(e,f,h,d,k[14],15,-1416354905),d=l(d,e,f,h,k[5],21,-57434055),h=l(h,d,e,f,k[12],6,1700485571),f=l(f,h,d,e,k[3],10,-1894986606),e=l(e,f,h,d,k[10],15,-1051523),d=l(d,e,f,h,k[1],21,-2054922799),h=l(h,d,e,f,k[8],6,1873313359),f=l(f,h,d,e,k[15],10,-30611744),e=l(e,f,h,d,k[6],15,-1560198380),d=l(d,e,f,h,
k[13],21,1309151649),h=l(h,d,e,f,k[4],6,-145523070),f=l(f,h,d,e,k[11],10,-1120210379),e=l(e,f,h,d,k[2],15,718787259),d=l(d,e,f,h,k[9],21,-343485551);a[0]=h+a[0]&4294967295;a[1]=d+a[1]&4294967295;a[2]=e+a[2]&4294967295;a[3]=f+a[3]&4294967295},b=function(a,b,c,d,e,f){b=(b+a&4294967295)+(d+f&4294967295)&4294967295;return(b<<e|b>>>32-e)+c&4294967295},c=function(a,c,h,d,e,f,g){return b(c&h|~c&d,a,c,e,f,g)},g=function(a,c,h,d,e,f,g){return b(c&d|h&~d,a,c,e,f,g)},l=function(a,c,h,d,e,f,g){return b(h^(c|
~d),a,c,e,f,g)},m="0123456789abcdef".split("");return function(a){for(var b=0;b<a.length;b++){for(var c=b,d=a[b],e="",f=0;4>f;f++)e+=m[d>>8*f+4&15]+m[d>>8*f&15];a[c]=e}return a.join("")}(function(b){var c=b.length,h=[1732584193,-271733879,-1732584194,271733878],d;for(d=64;d<=b.length;d+=64){var e=b.substring(d-64,d),f=[],g;for(g=0;64>g;g+=4)f[g>>2]=e.charCodeAt(g)+(e.charCodeAt(g+1)<<8)+(e.charCodeAt(g+2)<<16)+(e.charCodeAt(g+3)<<24);a(h,f)}b=b.substring(d-64);e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
for(d=0;d<b.length;d++)e[d>>2]|=b.charCodeAt(d)<<(d%4<<3);e[d>>2]|=128<<(d%4<<3);if(55<d)for(a(h,e),d=0;16>d;d++)e[d]=0;e[14]=8*c;a(h,e);return h}(this))};Date.prototype.duration=function(a){var b={y:307584E5,m:2592E6,w:6048E5,d:864E5,h:36E5,i:6E4,s:1E3},c=0;if(a){a=a.toLowerCase().split(" ");for(var g=0,l,m=c=0;m<a.length;m+=1)if(Number(a[m]))g=a[m];else{if(l=a[m].match(/[a-z]/)){var n=l.index;l=a[m].substr(n);0<n&&(g=a[m].substr(0,n))}else l=a[m];l&&g&&(l=b[l],c+=g*l,g=0)}0==c&&0<g&&(c=g*b.s)}return new Date(c)};
var fx={init:function(){$('img.icon1[src$=".svg"], a.icon1 > img.icon[src$=".svg"]').each(function(){var a=$(this),b=a.attr("id"),c=a.attr("class"),g=a.attr("style"),l=a.attr("src");$.get(l,function(l){l=$(l).find("svg");"undefined"!==typeof b&&(l=l.attr("id",b));l=l.attr("class","fx-"+c);"undefined"!==typeof g&&(l=l.attr("style",g));l.find('[fill!="none"]').removeAttr("fill");l.find("g").children().removeAttr("stroke");l.children().removeAttr("stroke");a.replaceWith(l);"undefined"!==typeof b&&$("#"+
b.substr(0,b.lastIndexOf("-"))).trigger("draw")},"xml")})},rotate:function(a,b,c){return[Math.cos(b)*(a[0]-c[0])-Math.sin(b)*(a[1]-c[1])+c[0],Math.sin(b)*(a[0]-c[0])+Math.cos(b)*(a[1]-c[1])+c[1]]},grid:function(a,b,c,g){var l;for(this.remove(a);0<b;)l=document.createElementNS("http://www.w3.org/2000/svg","line"),l.setAttributeNS(null,"x1",c[0]),l.setAttributeNS(null,"y1",c[1]<g[1]?c[1]+b:c[1]-b),l.setAttributeNS(null,"x2",g[0]),l.setAttributeNS(null,"y2",c[1]<g[1]?c[1]+b:c[1]-b),$("#"+a.id+" g").append(l),
b-=6},bar:function(a,b,c,g){this.remove(a);for(var l=0,m=0;m<b;)g=document.createElementNS("http://www.w3.org/2000/svg","line"),g.setAttributeNS(null,"x1",c[0]+m),g.setAttributeNS(null,"y1",c[1]),g.setAttributeNS(null,"x2",c[0]+m),g.setAttributeNS(null,"y2",c[1]-l),$("#"+a.id+" g").append(g),m+=6,l+=3},remove:function(a,b){b||(b="line");$("#"+a.id+" g").children().each(function(a){a=$(this);a.is(b)&&a.remove()})},hsv2rgb:function(a,b,c){var g,l,m;a=Math.max(0,Math.min(360,a));b=Math.max(0,Math.min(100,
b));c=Math.max(0,Math.min(100,c));b/=100;c/=100;if(0==b)g=b=c;else switch(a/=60,g=Math.floor(a),l=a-g,a=c*(1-b),m=c*(1-b*l),l=c*(1-b*(1-l)),g){case 0:g=c;b=l;c=a;break;case 1:g=m;b=c;c=a;break;case 2:g=a;b=c;c=l;break;case 3:g=a;b=m;break;case 4:g=l;b=a;break;default:g=c,b=a,c=m}g=Math.round(255*g);b=Math.round(255*b);c=Math.round(255*c);return"rgb("+g+","+b+","+c+")"}},notify={i:0,messages:{},exists:function(){var a=!1,b;for(b in notify.messages)a=!0;return a},add:function(a,b,c,g){notify.i++;notify.messages[notify.i]=
[];notify.messages[notify.i]={level:a,signal:b,title:c,text:g,time:Date.now()}},debug:function(a,b){},update:function(a,b){notify.add("update","UPDATE",a,b);notify.display()},info:function(a,b){notify.add("info","INFO",a,b);notify.display()},warning:function(a,b){notify.add("warning","WARN",a,b);notify.display()},error:function(a,b){notify.add("error","ERROR",a,b);notify.display()},json:function(a,b,c){a=null!=a.responseJSON?a.responseJSON[0]:{title:"Unknown Error",text:a.responseText};notify.add("error",
"ERROR",a.title,a.text);notify.display()},remove:function(a){var b=notify.messages[notify.i];$(".alert").popup("close");$(".signal").removeClass(b.level).hide();void 0!==a?delete notify.messages[a]:notify.messages={}},display:function(){var a=notify.messages[notify.i];a&&($(".alert h1").html(a.title),$(".alert p").html(a.text),$(".alert .stamp").html((new Date(a.time)).transShort()),$(".signal").addClass(a.level).html(a.signal).show())}},repeater={dir:{},init:function(){$("[data-repeat]").each(function(a){repeater.dir[this.id]||
(a=$("#"+this.id),repeater.dir[this.id]=(new Date).duration(a.attr("data-repeat")),a.trigger("repeat"),repeater.tick(this.id))})},tick:function(a){var b=new Date,c=repeater.dir[a];6E4<=c&&(c-=1E3*b.getSeconds());36E5<=c&&(c-=6E4*b.getMinutes());864E5<=c&&(c-=36E5*b.getHours());setTimeout("$('#"+a+"').trigger('repeat'); repeater.tick('"+a+"');",c)},list:function(){var a=0;$("[data-repeat]").each(function(b){a++})}},widget={buffer:{},explode:function(a){var b=[],c=[];if(0<=a.indexOf(",")){a=a.explode();
for(var g=0;g<a.length;g++)""!=a[g]&&(c[a[g]]="");for(var l in c)b.push(l)}else""!=a.trim()&&b.push(a.trim());return b},list:function(){var a=0;$("[data-item]").each(function(b){""!=$(this).attr("data-item").trim()&&a++})},check:function(a){if(a instanceof Array)for(var b=0;b<a.length;b++){if(void 0===a[b]||null==a[b])return!1}else if(void 0===a||null==a)return!1;return!0},get:function(a){if(a instanceof Array)for(var b=[],c=0;c<a.length;c++)b.push(widget.buffer[a[c]]);else b=widget.buffer[a];return b},
set:function(a,b){widget.buffer[a]instanceof Array||void 0!==b&&(widget.buffer[a]=$.isNumeric(b)?1*b:b)},update:function(a,b){if(void 0===b||widget.buffer[a]!==b||widget.buffer[a]instanceof Array&&widget.buffer[a].toString()!=b.toString())widget.set(a,b),$('[data-item*="'+a+'"]').each(function(c){c=widget.explode($(this).attr("data-item"));for(var g=0;g<c.length;g++)if(c[g]==a){var l=[];if("plot."==$(this).attr("data-widget").substr(0,5)&&$("#"+this.id).highcharts()){for(var m=0;m<c.length;m++)l.push(c[m]==
a?b:null);void 0!==b&&null!=b&&$(this).trigger("point",[l])}else l=widget.get(c),widget.check(l)&&$(this).trigger("update",[l])}})},prepare:function(){$('[id^="'+$.mobile.activePage.attr("id")+'-"][data-widget^="plot."][data-item]').each(function(a){$("#"+this.id).highcharts()&&$("#"+this.id).highcharts().destroy()})},refresh:function(){$('[id^="'+$.mobile.activePage.attr("id")+'-"][data-item]').each(function(a){a=widget.get(widget.explode($(this).attr("data-item")));widget.check(a)&&$(this).trigger("update",
[a])})},checkseries:function(a){a=a.split(".");return 0<=$.inArray(a[a.length-4],"avg min max sum diff rate on".split(" "))},listeners:function(){var a=[],b=[];$('[id^="'+$.mobile.activePage.attr("id")+'-"][data-item]').each(function(a){if("status.log"!=$(this).attr("data-widget")){a=widget.explode($(this).attr("data-item"));for(var c=0;c<a.length;c++)widget.checkseries(a[c])||(b[a[c]]="")}});for(var c in b)a.push(c);return a},plot:function(a){var b=$();a?$('[id^="'+$.mobile.activePage.attr("id")+
'-"][data-widget^="plot."][data-item*="'+a+'"]').each(function(c){c=widget.explode($(this).attr("data-item"));for(var g=0;g<c.length;g++)c[g]==a&&(b=b.add(this))}):b=$('[id^="'+$.mobile.activePage.attr("id")+'-"][data-widget^="plot."][data-item]');return b},log:function(a){var b=$();a?$('[id^="'+$.mobile.activePage.attr("id")+'-"][data-widget="status.log"][data-item="'+a+'"]').each(function(c){c=widget.explode($(this).attr("data-item"));for(var g=0;g<c.length;g++)c[g]==a&&(b=b.add(this))}):b=$('[id^="'+
$.mobile.activePage.attr("id")+'-"][data-widget="status.log"][data-item]');return b}}; 
