var wm_apdex_widget={};wm_apdex_widget.wm_widget_defaults={defaults:{widget_container_id:"#wm-chart-widget",widget_captions:1,first_time_loaded:true,first_monitor_loaded:false},messages:{h3_title:"Live Apdex Report",uid_not_valid:"Please fill a valid WM Account id",fid_not_valid:"Please fill a valid WM Monitor id",request_timeout:"Data request time-out.<br />Retrying in a minute...",error:"Data could not be loaded.<br />Retrying in a minute...",empty_chart_data:"There is no data for that chart. Try later.",fetching_new_data:"Fetching new data from server.",charts:{colors:["#119dee","#b211ee","#669900","#EEA111","#116fee","#7c7c7c","#CC0000","#ee11b7","#1116ee","#11ee5f","#a811ee"]},captions:{powered_by:'Apdex Report [<a href="http://apdex.org/" title="Apdex.org">?</a>] is powered by WatchMouse <a href="http://www.watchmouse.com/" title="Website monitoring by WatchMouse">website monitoring</a>.'}},urls:{mongo_cache_api:"http://api.io.watchmouse.com/"}};wm_apdex_widget.initMap=function(a){var b=wm_apdex_widget.urls.mongo_cache_api+"latest/synth/current/"+parseInt(WM_instances[a].uid,10)+"/folder/"+parseInt(WM_instances[a].fid,10)+"?callback=?";$.jsonp({url:b,data:WM_instances[a].fields,dataType:"jsonp",timeout:10000,success:function(c){if(c.code!==200){wm_apdex_widget.handleError(c.info,a)}else{if(wm_apdex_widget.opts.first_time_loaded===true){wm_apdex_widget.loadPackages(c,a)}else{wm_apdex_widget.drawApdexChart(c,a)}}},error:function(c,e,d){wm_apdex_widget.handleError(e,a)}})};wm_apdex_widget.loadPackages=function(b,a){google.load("visualization","1",{packages:"corechart",callback:function(){wm_apdex_widget.drawApdexChart(b,a)}})};wm_apdex_widget.drawApdexChart=function(v,w){var s=v.result.length,m=v.result[0].daily.length;if(s<1){wm_apdex_widget.handleChartEmptyDataError("ApdexChart-"+w);return false}var A=new google.visualization.DataTable();A.addRows(m-1);A.addColumn("string",wm_apdex_widget.msgs.charts.days);var t,f,n=100,d;for(i=0;i<s;i++){t=v.result[i];var q=t.daily.length,x;var B=t.info.name,p=t.info.timewarn/1000;var b=wm_apdex_widget.build_monitor_name(B,p);if(wm_apdex_widget.opts.first_time_loaded===true){$(".legend-ApdexChart-"+w).append('<li style="color:'+wm_apdex_widget.msgs.charts.colors[i]+';"><span>'+b[1]+"</span></li>")}A.addColumn("number",b[0]);if(wm_apdex_widget.opts.first_monitor_loaded===false){var r=t.daily[q-1].stats.probes,u=WM_instances[w].minimum_probes*10;if(r<u||u===0){x=0;q=q-1}else{x=1}wm_apdex_widget.opts.first_monitor_loaded=true}else{q=(x===0)?q-1:q}var l=0;for(y=x;y<(q);y++){f=t.daily[y];if(i===0){dateString=wm_apdex_widget.getDateStr(f.period.from.sec*1000,t.info.tz,"day");A.setValue(l,0,dateString.toString())}d=wm_apdex_widget.round_number(f.apdex,2);n=(n>d)?d:n;A.setValue(l,i+1,d);l++}}var k,h,g;k=wm_apdex_widget.getDateStr(t.daily[0].period.from.sec*1000,t.info.tz,"month");h=wm_apdex_widget.getDateStr(t.daily[q-1].period.from.sec*1000,t.info.tz,"month");g=(k!==h)?k+" / "+h:h;var c={width:WM_instances[w].widget_width,height:WM_instances[w].widget_height,is3D:false,backgroundColor:{stroke:null,fill:"#E0E0E0",strokeWidth:0},fontSize:10,interpolateNulls:true,pointSize:4,lineWidth:3,gridlineColor:"#b2b2b2",vAxis:{minValue:n-0.03,maxValue:1,textStyle:{color:"#4c4c4c"}},hAxis:{title:g,titleTextStyle:{color:"#4c4c4c"},textStyle:{color:"#4c4c4c"},showTextEvery:2,slantedText:false},colors:wm_apdex_widget.msgs.charts.colors,chartArea:{top:10,left:30,height:"83%",width:"81%"}};if(n<=0.65){c.pointSize=2;c.lineWidth=2}if(0.8>n&&n>=0.7){c.vAxis={minValue:0.6,maxValue:1,textStyle:{color:"#4c4c4c"}}}else{if(0.6>n&&n>=0.55){c.vAxis={minValue:0.4,maxValue:1,textStyle:{color:"#4c4c4c"}}}}var a=document.getElementById("ApdexChart-"+w);var o=new google.visualization.LineChart(a);o.draw(A,c);if(WM_instances[w].refresh_time>0){wm_apdex_widget.opts.first_monitor_loaded=false;wm_apdex_widget.opts.first_time_loaded=false;var j=WM_instances[w].refresh_time*60000,e=setTimeout(wm_apdex_widget.initMap,j,w)}};wm_apdex_widget.build_monitor_name=function(a,b){b=wm_apdex_widget.round_number(b,1);var c=[];c[0]=a+" ["+b+"]";c[1]=a+" <strong>["+b+"]</strong>";return c};wm_apdex_widget.round_number=function(a,b){return Math.round(a*Math.pow(10,b))/Math.pow(10,b)};wm_apdex_widget.createElement=function(a,c,d){if($(".wm-chart-widget-light .error").length>0){$(".wm-chart-widget-light .error").remove()}var b='<div class="chart-wrap">\n<h3>'+wm_apdex_widget.msgs.h3_title+'</h3>\n<ul class="legend-'+c+"-"+a+' legend"></ul>\n<div id="'+c+"-"+a+'">\n<img height="16" width="16" class="loading" src="assets/ajax-loader_'+((wm_apdex_widget.opts.widget_theme==="dark")?"dark":"light")+'.gif">\n</div>\n'+((wm_apdex_widget.opts.widget_captions===1)?"<p>"+d+"</p>":'<p style="margin:0 0 8px"></p>')+"\n</div>";$(WM_instances[a].instance_container_id).append(b);wm_apdex_widget.styleChartArea(a);wm_apdex_widget.initMap(a)};wm_apdex_widget.styleChartArea=function(a){var c={};var e={};var d={width:WM_instances[a].widget_width+(WM_instances[a].widget_chart_padding*2)+"px",margin:(WM_instances[a].widget_chart_gap/2)+" auto"};var b={width:WM_instances[a].widget_width,padding:WM_instances[a].widget_chart_padding+"px "+WM_instances[a].widget_chart_padding+"px 0px",margin:"0"};$(WM_instances[a].instance_container_id).css(d).removeClass("wm-hidden");$(WM_instances[a].instance_container_id).find(".chart-wrap").css(b)};wm_apdex_widget.handleError=function(e,a){var d="";switch(e){case"timeout":d=wm_apdex_widget.msgs.request_timeout;var b=setTimeout(function(){wm_apdex_widget.createElement(a,WM_instances[a].chart_types,wm_apdex_widget.msgs.captions.powered_by)},60000);break;case"error":d=wm_apdex_widget.msgs.error;var c=setTimeout(function(){wm_apdex_widget.createElement(a,WM_instances[a].chart_types,wm_apdex_widget.msgs.captions.powered_by)},60000);break;default:d=e;break}$(WM_instances[a].instance_container_id).addClass("error").html('<div class="error">'+d+"</div>")};wm_apdex_widget.handleChartEmptyDataError=function(a){$("#"+a).parent().addClass("error").css("padding","20px "+WM_instances[instance].widget_chart_padding+"px").html(wm_apdex_widget.msgs.empty_chart_data)};wm_apdex_widget.getMonth=function(b){var a={};a[0]="January";a[1]="February";a[2]="March";a[3]="April";a[4]="May";a[5]="June";a[6]="July";a[7]="August";a[8]="September";a[9]="October";a[10]="November";a[11]="December";return a[b]};wm_apdex_widget.moduleInstances=function(a){WM_instances[a].instance_container_id=wm_apdex_widget.opts.widget_container_id+"-"+a;WM_instances[a].refresh_time=(typeof(WM_instances[a].refresh_time)==="undefined")?10:parseInt(WM_instances[a].refresh_time,10);WM_instances[a].minimum_probes=(typeof(WM_instances[a].minimum_probes)==="undefined")?10:parseInt(WM_instances[a].minimum_probes,10);if(WM_instances[a].uid===0){wm_apdex_widget.handleError(wm_apdex_widget.msgs.uid_not_valid,a);return false}if(WM_instances[a].fid===0){wm_apdex_widget.handleError(wm_apdex_widget.msgs.fid_not_valid,a);return false}WM_instances[a].fields="fields=code;info;daily.apdex;daily.period.from;daily.stats.probes";wm_apdex_widget.styleChartArea(a);wm_apdex_widget.initMap(a)};wm_apdex_widget.makeDate=function(a,c){var b=-(new Date()).getTimezoneOffset()/60;return new Date(parseInt(a,10)+(c-b)*60*60*1000)};wm_apdex_widget.getDateStr=function(c,g,e){g=parseInt(g,10);var f=wm_apdex_widget.makeDate(c,g);if(e==="date"){return f.getDate()+" "+wm_apdex_widget.getMonth(f.getMonth())}else{if(e==="day"){return f.getDate()}else{if(e==="month"){return wm_apdex_widget.getMonth(f.getMonth())}else{var a=f.getHours();a=a<10?a="0"+a:a;var b=f.getMinutes();b=(b<10)?"0"+b:b;return a+":"+b}}}return false};wm_apdex_widget.initJQuery=function(){if(typeof(jQuery)==="undefined"){if(!wm_apdex_widget.jQueryScriptOutputted){wm_apdex_widget.jQueryScriptOutputted=true;(function(){var a=document.createElement("script");a.type="text/javascript";a.async=true;a.src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js";var b=document.getElementsByTagName("head")[0];b.appendChild(a)})()}setTimeout("wm_apdex_widget.initJQuery()",80)}else{$(function(){(function(Z,ac){function aa(){}function I(b){ab=[b]}function R(b){Y.insertBefore(b,Y.firstChild)}function S(b,d,c){return b&&b.apply(d.context||d,c)}function T(b){return/\?/.test(b)?"&":"?"}var Q="async",J="charset",M="",N="error",K="_jqjsp",F="on",P=F+"click",O=F+N,ad=F+"load",V=F+"readystatechange",C="removeChild",X="<script/>",G="success",D="timeout",E=Z.browser,Y=Z("head")[0]||document.documentElement,H={},U=0,ab,W={callback:K,url:location.href};function L(c){c=Z.extend({},W,c);var e=c.complete,r=c.dataFilter,j=c.callbackParameter,d=c.callback,p=c.cache,m=c.pageCache,n=c.charset,b=c.url,k=c.data,f=c.timeout,g,l=0,o=aa;c.abort=function(){!l++&&o()};if(S(c.beforeSend,c,[c])===false||l){return c}b=b||M;k=k?((typeof k)=="string"?k:Z.param(k,c.traditional)):M;b+=k?(T(b)+k):M;j&&(b+=T(b)+encodeURIComponent(j)+"=?");!p&&!m&&(b+=T(b)+"_"+(new Date()).getTime()+"=");b=b.replace(/=\?(&|$)/,"="+d+"$1");function h(s){!l++&&ac(function(){o();m&&(H[b]={s:[s]});r&&(s=r.apply(c,[s]));S(c.success,c,[s,G]);S(e,c,[c,G])},0)}function q(s){!l++&&ac(function(){o();m&&s!=D&&(H[b]=s);S(c.error,c,[c,s]);S(e,c,[c,s])},0)}m&&(g=H[b])?(g.s?h(g.s[0]):q(g)):ac(function(u,v,t){if(!l){t=f>0&&ac(function(){q(D)},f);o=function(){t&&clearTimeout(t);u[V]=u[P]=u[ad]=u[O]=null;Y[C](u);v&&Y[C](v)};window[d]=I;u=Z(X)[0];u.id=K+U++;if(n){u[J]=n}function s(w){(u[P]||aa)();w=ab;ab=undefined;w?h(w[0]):q(N)}if(E.msie){u.event=P;u.htmlFor=u.id;u[V]=function(){/loaded|complete/.test(u.readyState)&&s()}}else{u[O]=u[ad]=s;E.opera?((v=Z(X)[0]).text="jQuery('#"+u.id+"')[0]."+O+"()"):u[Q]=Q}u.src=b;R(u);v&&R(v)}},0);return c}L.setup=function(b){Z.extend(W,b)};Z.jsonp=L})(jQuery,setTimeout);for(var a in WM_instances){wm_apdex_widget.moduleInstances(a)}})}};wm_apdex_widget.opts=wm_apdex_widget.wm_widget_defaults.defaults;wm_apdex_widget.msgs=wm_apdex_widget.wm_widget_defaults.messages;wm_apdex_widget.urls=wm_apdex_widget.wm_widget_defaults.urls;wm_apdex_widget.jQueryScriptOutputted=false;WM_instances[0].chart_types="ApdexChart";WM_instances[0].widget_width=186;WM_instances[0].widget_height=260;WM_instances[0].widget_chart_gap=5;WM_instances[0].widget_chart_padding=0;WM_instances[0].widget_layout="vertical";wm_apdex_widget.initJQuery();
