text: function mConst(){return{awakeAbove:1000,lightAbove:120,sampleIntervalMins:10,swpAppStoreUrl:"https://itunes.apple.com/app/smartwatch-pro-for-pebble/id673907094?mt=8&at=10lIFm&pt=409665&ct=morpheuz_web",displayDateFmt:"WWW, NNN dd, yyyy hh:mm",iosDateFormat:"dd N yyyy hh:mm",swpUrlDate:"yyyy-MM-ddThh:mm:00",emailHeader:"<h2>CSV Sleep data</h2><br/>",emailFooter1:"<br/>Note: -1 is no data captured, -2 is ignore set, ALARM, START and END nodes represent smart alarm actual, start and end",emailFooter2:"<br/><br/><small>Please don't reply, this is an unmonitored mailbox</small><br/>",emailAddressMandatory:"valid email address is required",sendingEmail:"Sending..."}}function buildGraphDataSet(e,f,c){var d=new Date(e);for(var b=0;b<f.length;b++){if(f[b]===""){continue}var a=new Array();a[0]=d;a[1]=parseInt(f[b],10);if(a[1]<0){a[1]=null}c[b]=a;d=d.addMinutes(mConst().sampleIntervalMins)}}function populateIgnore(d,b,f){var c=new Date(d);for(var a=0;a<f.length;a++){if(f[a]===""){continue}if(parseInt(f[a],10)==-2){var e={verticalLine:{name:"ignore",x:c,lineWidth:5,yOffset:0,color:"#184E99",shadow:false}};b.show=true;b.objects.push(e)}c=c.addMinutes(mConst().sampleIntervalMins)}}function returnAbsoluteMatch(e,b,c){var a=e;while(a.getTime()<b.getTime()){var d=a.format("hhmm");if(c===d){return a}a=a.addMinutes(1)}return e}function startStopAlarm(h,k,r,l,p,g,j,f){if(h){var q=fixLen(k)+fixLen(r);var o=fixLen(l)+fixLen(p);var s=new Date(g);var a=null;var c=null;for(var n=0;n<f.length;n++){var e=s.format("hhmm");var m=s;s=s.addMinutes(mConst().sampleIntervalMins);var d=s.format("hhmm");if(a===null&&q>=e&&q<=d){a=returnAbsoluteMatch(m,s,q)}if(c===null&&o>=e&&o<=d){c=returnAbsoluteMatch(m,s,o)}if(c!==null&&a!==null){break}}if(a!==null){var t={dashedVerticalLine:{name:"start",x:a,lineWidth:1,yOffset:0,dashPattern:[1,4],color:"rgb(76, 217, 100)",shadow:false}};j.show=true;j.objects.push(t)}if(c!==null){var b={dashedVerticalLine:{name:"end",x:c,lineWidth:1,yOffset:0,dashPattern:[1,4],color:"rgb(255, 59, 48)",shadow:false}};j.show=true;j.objects.push(b)}}}function calculateStats(g,f,m,s){var o=new Date(g);var t=true;var b=null;var w=null;var a=null;var l=null;var u=null;var p=null;for(var y=0;y<f.length;y++){if(f[y]===""){continue}var A=parseInt(f[y],10);var d=o.format("hhmm");var r=o;o=o.addMinutes(mConst().sampleIntervalMins);var c=o.format("hhmm");if(m!="N"&&m>=d&&m<=c){a=returnAbsoluteMatch(r,o,m);l=y;break}else{if(A!=-1&&A!=-2&&A<=mConst().awakeAbove){if(t){b=r;w=y;var k={verticalLine:{name:"begin",x:b,lineWidth:1,yOffset:0,color:"rgb(255, 149, 0)",shadow:false}};s.show=true;s.objects.push(k);t=false}u=o;p=y}}}if(a===null&&u!==null){a=u;l=p}var q=0;var x=0;var e=0;var z=0;if(w!==null&&l!==null){for(var v=w;v<=l;v++){if(f[v]===""){continue}var h=parseInt(f[v],10);if(h==-1||h==-2){z++}else{if(h>mConst().awakeAbove){q++}else{if(h>mConst().lightAbove){e++}else{x++}}}}}if(a!==null){var n={verticalLine:{name:"endstop",x:a,lineWidth:1,yOffset:0,color:"rgb(255, 149, 0)",shadow:false}};s.show=true;s.objects.push(n)}return{tbegin:b,tends:a,deep:x,light:e,awake:q,ignore:z}}function generateCopyLinkData(a,k,j,m,g,l,d,c){var b=new Date(a);var f="<pre>";for(var e=0;e<k.length;e++){if(k[e]===""){continue}f=f+b.format("hh:mm")+","+k[e]+"<br/>";b=b.addMinutes(mConst().sampleIntervalMins)}if(j){f=f+m+":"+g+",START<br/>"+l+":"+d+",END<br/>";if(c!="N"){var h=c.substr(0,2)+":"+c.substr(2,2);f=f+h+",ALARM<br/>"}}return{body:f+"</pre>"}}$("document").ready(function(){adjustForViewport();document.ios=navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i);if(document.ios){$(".android").hide()}else{$(".ios").hide()}var p=getParameterByName("base");var i=new Date().valueOf();if(p!==""&&p!=="null"){i=parseInt(p,10)}var b=getParameterByName("graph");var r=getParameterByName("fromhr");var B=getParameterByName("frommin");var t=getParameterByName("tohr");var A=getParameterByName("tomin");var f=getParameterByName("smart");var z=getParameterByName("vers");var m=getParameterByName("goneoff");var g=decodeURIComponent(getParameterByName("emailto"));var v=decodeURIComponent(getParameterByName("potoken"));var h=decodeURIComponent(getParameterByName("pouser"));var a=decodeURIComponent(getParameterByName("postat"));var l=decodeURIComponent(getParameterByName("swpdo"));var c=decodeURIComponent(getParameterByName("lifxtoken"));var u=decodeURIComponent(getParameterByName("lifxtime"));var d=decodeURIComponent(getParameterByName("swpstat"));var D=getParameterByName("noset");var n=getParameterByName("token");var s=decodeURIComponent(getParameterByName("exptime"));var C=getParameterByName("usage");var o=f==="Y";var y=D==="Y";if(y){$(".noset").hide()}$("#emailto").val(g);$("#ptoken").val(v);$("#puser").val(h);$("#lifxToken").val(c);$("#lifxTime").val(u);$("#swpdo").prop("checked",l==="Y");$("#presult").text(a);$("#swpstat").text(d);$("#exptime").text(s);$("#usage").prop("checked",C!=="N");if(a==="OK"){$("#lipushover").addClass("green");$("#presult").addClass("green")}else{if(a===""||a===null||a==="Disabled"){$("#lipushover").addClass("blue");$("#presult").addClass("blue")}else{$("#lipushover").addClass("red");$("#presult").addClass("red")}}if(d==="OK"){$("#liswp").addClass("green");$("#swpstat").addClass("green")}else{if(d===""||d===null||d==="Disabled"){$("#liswp").addClass("blue");$("#swpstat").addClass("blue")}else{$("#liswp").addClass("red");$("#swpstat").addClass("red")}}if(c===""){$("#lilifx").addClass("blue")}else{$("#lilifx").addClass("green")}$("#version").text(parseInt(z,10)/10);$("#sleep-time").text(new Date(i).format(mConst().displayDateFmt));if((new Date().valueOf())%10===0){$("#info-message").css("display","block")}if(!y){setScreenMessageBasedOnVersion(z)}var e=b.split("!");var k=new Array();buildGraphDataSet(i,e,k);var q={show:false,objects:[]};populateIgnore(i,q,e);startStopAlarm(o,r,B,t,A,i,q,e);var x=calculateStats(i,e,m,q);$("#ttotal").text(hrsmin((x.deep+x.light+x.awake+x.ignore)*mConst().sampleIntervalMins));$("#tawake").text(hrsmin(x.awake*mConst().sampleIntervalMins));$("#tlight").text(hrsmin(x.light*mConst().sampleIntervalMins));$("#tdeep").text(hrsmin(x.deep*mConst().sampleIntervalMins));$("#tignore").text(hrsmin(x.ignore*mConst().sampleIntervalMins));if(x.tbegin!==null&&x.tends!==null){$("#swpnodata").hide();$("#tstarts").text(x.tbegin.format(mConst().iosDateFormat));$("#tends").text(x.tends.format(mConst().iosDateFormat));var w="swpro2hk://?source=Morpheuz&starts="+x.tbegin.format(mConst().swpUrlDate)+"&ends="+x.tends.format(mConst().swpUrlDate);if(n!=null&&n!==""){w+="&at="+n}$("#swp").prop("href",w);if(!y){$("#swp").click(function(){setTimeout(function(){window.location.href="pebblejs://close"},250)})}}else{$("#swp").hide()}$("#swplink").prop("href",mConst().swpAppStoreUrl);$("#swplink").click(function(){setTimeout(function(){window.location.href="pebblejs://close"},250)});var j=[["Restless",x.awake],["Light",x.light],["Deep",x.deep],["Ignore",x.ignore]];$(document).ready(function(){document.plot1=$.jqplot("chart1",[k],{grid:{background:"#2066C7",gridLineColor:"#1E75D7",borderColor:"#1E75D7",shadow:false},animate:true,canvasOverlay:q,series:[{showMarker:false,breakOnNull:true,color:"#40ADEB",label:new Date(i).format("yyyy-MM-dd"),shadow:false}],axesDefaults:{labelRenderer:$.jqplot.CanvasAxisLabelRenderer,showTicks:false,showTickMarks:false},legend:{show:false,location:"ne"},axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer,tickRenderer:$.jqplot.CanvasAxisTickRenderer,tickOptions:{formatString:"%R",angle:-30,fontSize:"8pt",textColor:"#40ADEB"},tickInterval:"1 hour",pad:0,showTicks:true,showTickMarks:true,min:new Date(i)},yaxis:{labelRenderer:$.jqplot.CanvasAxisLabelRenderer,label:"Movement",min:-50,max:4000,labelOptions:{textColor:"#1898FF"}}}});document.plot2=jQuery.jqplot("chart2",[j],{grid:{background:"#FF7D48",borderColor:"#FF7D48",shadow:false},seriesColors:["#FFFF92","#FFA966","#FF3C31","rgb(130,130,130)"],seriesDefaults:{renderer:jQuery.jqplot.PieRenderer,rendererOptions:{showDataLabels:true,shadow:false}},legend:{show:true,location:"e"}})});$(".save").click(function(){var I="N";var J="";var K=encodeURIComponent($("#emailto").val());var F=encodeURIComponent($("#ptoken").val());var G=encodeURIComponent($("#puser").val());var M=$("#swpdo").is(":checked")?"Y":"N";var L=$("#usage").is(":checked")?"Y":"N";var H=encodeURIComponent($("#lifxToken").val());var E=encodeURIComponent($("#lifxTime").val());window.location.href="pebblejs://close#reset!"+I+"!"+J+"!"+J+"!"+J+"!"+J+"!"+I+"!"+K+"!"+G+"!"+J+"!"+F+"!"+I+"!"+M+"!"+L+"!"+H+"!"+E});$("#mail").removeAttr("disabled");$("#mail").click(function(){var E=$("#emailto").val();if(E===""||!validateEmail(E)){$("#emailSendResult").text(mConst().emailAddressMandatory);$("#emailSendResult").addClass("red");return}var G=generateCopyLinkData(i,e,o,r,B,t,A,m);var F={from:"Morpheuz <noreply@morpheuz.co.uk>",to:E,subject:"Morpheuz-"+new Date(i).format("yyyy-MM-dd"),message:mConst().emailHeader+G.body+mConst().emailFooter1+mConst().emailFooter2};$("#mail").attr("disabled","disabled");$("#emailSendResult").removeClass("red").removeClass("green");$("#emailSendResult").text(mConst().sendingEmail);sendMailViaServer(F,function(H,I){if(H===1){$("#emailSendResult").addClass("green")}else{$("#emailSendResult").addClass("red")}$("#emailSendResult").text(I);$("#mail").removeAttr("disabled")})})});