function goToMetadataPage(n){lock();setPageMode(PAGE_MODES.METADATA);areIndicatorsInDomain()?(isDefined(n)||(n=getIndicatorIndex()),setIndicatorIndexAndUpdateModel(n),ajaxMonitor.setCalls(2),getIndicatorMetadata(FT.model.groupId),getMetadataProperties(),ajaxMonitor.monitor(displayFingertipsMetadata),$(window).scrollTop()>300&&$(window).scrollTop(0)):displayNoData()}function displayMetadata(n,t){var i=getMetadataHtml(n,t),r=i.html,u=$("#metadataBox");u.length?u.html(r):pages.getContainerJq().html(r);labelAsync.populate(i.labelArgs)}function addMetadataRow(n,t,i){var u=i.ColumnName,r,e,f;t!==null&&t.hasOwnProperty(u)&&(r=t[u],isDefined(r)&&!String.isNullOrEmpty(r)&&(u==="DataQuality"&&showDataQuality?(e=parseInt(r),f=getIndicatorDataQualityHtml(r)+" "+getIndicatorDataQualityTooltipText(e)):f=r,n.push([i.DisplayName,f])))}function getMetadataProperties(){isDefined(loaded.indicatorProperties)?ajaxMonitor.callCompleted():ajaxGet("api/indicator_metadata_text_properties","",function(n){loaded.indicatorProperties=n;ajaxMonitor.callCompleted()})}function getMetadataHtml(n,t){var r,o,y,p,s,f,l=isDefined(t)&&t.hasOwnProperty("Grouping")?t.Grouping[0]:t,h,w,c,a,v;isDefined(l)?(y=t.Age.Id,s=l.MethodId,f=l.SigLevel,p=t.Sex.Id):y=s=f=p=null;var b={},i=[],e=n.Descriptive,u=loaded.indicatorProperties;for(r=0;r<u.length;r++){if(h=u[r],h.Order>59)break;h.ColumnName!=="Name"&&addMetadataRow(i,e,h)}for(i.push(["Value type",n.ValueType.Name]),addMetadataRow(i,e,u[r++]),w=n.Unit.Label,String.isNullOrEmpty(w)||i.push(["Unit",n.Unit.Label]),addMetadataRow(i,e,u[r++]),t&&(i.push(["Age",t.Age.Name]),i.push(["Sex",t.Sex.Name])),i.push(["Year type",n.YearType.Name]),addMetadataRow(i,e,u[r++]),isDefined(s)&&(o=labelAsync.getLabel(s,loaded.comparatorMethods,"comparator-method",b),i.push(["Benchmarking method",o])),isDefined(f)&&(o=f<=0?NOT_APPLICABLE:f+"%",i.push(["Benchmarking significance level",o])),c=n.ConfidenceIntervalMethod,c&&(i.push(["Confidence interval method",c.Name]),a=c.Description,a&&i.push(["Confidence interval methodology",a])),v=n.ConfidenceLevel,v>-1&&i.push(["Confidence level",v+"%"]);r<u.length;)addMetadataRow(i,e,u[r]),r++;return{html:templates.render("metadata",{rows:i,iid:FT.model.iid}),labelArgs:b}}function getLabelSpan(n){return'<span id="'+n+'-label"><\/span>'}function goToPopulationPage(){var n,i,t;lock();showSpinnerIfNoPopulation();n=PP.model.practiceCode;isDefined(n)&&(i=loaded.population[PP.model.year][n],isDefined(i)||showSpinner());setPageMode(PAGE_MODES.POPULATION);t=getYearOffset();ajaxMonitor.setCalls(9);ajaxMonitor.setState({year:PP.model.year,offset:t});getPracticeAndParentLists();getIndicatorMetadata(populationGroupId);getMetadataProperties();getPracticePopulation(PP.model.year,t);getLabelSeries();getPracticeParentPopulation();getNationalPopulation();ajaxMonitor.monitor(displayPopulation)}function getPracticeParentPopulation(){PP.model.parentCode!=null&&getSelectedParentPopulation()==null?getAveragedPopulation(PP.model.parentCode,getPracticeParentPopulationCallback):ajaxMonitor.callCompleted()}function displayPopulationInfo(){var n=populationState,i,t,u,r;n.lastDecile&&($("#d"+n.lastDecile).html(""),n.lastDecile=null);i=$("#noPractice");t=PP.data.currentPracticePopulation;n.isAnyPopulation()?($("#practice-label").html(getPracticeLabel()),updateEthnicity(t),updateDeprivationTable(t),updateFurtherInfo(t.AdHocValues),i.hide()):(u=t===null?"Select a practice<br>for further information":"No population data<br>available for current practice",i.html(u),i.show());r=getPracticeParentName().toUpperCase();updateRegisteredPersons(r);$("#pctLabel").html(r);n.displayPageElements()}function displayPopulation(){if(PP.model.year!=latestYear){unlock();return}if(!populationState.redrawChart()){populationState.displayPageElements();unlock();return}populationState.setDisplayedKey();displayPopulationInfo();displayPopulationChart();unlock()}function getAveragedPopulation(n,t){ajaxGet("api/quinary_population_data","area_code="+n+"&data_point_offset="+getYearOffset()+"&group_id="+populationGroupId,t)}function getNationalPopulation(){isDefined(nationalPopulation[PP.model.year])?ajaxMonitor.callCompleted():getAveragedPopulation(NATIONAL_CODE,getNationalPopulationCallback)}function getNationalPopulationCallback(n){isDefined(n)&&isDefined(n.Values)&&(nationalPopulation[PP.model.year]=n,makeValuesNegative(n.Values[SEX_MALE]));ajaxMonitor.callCompleted()}function getPracticeParentPopulationCallback(n){isDefined(n)&&isDefined(n.Values)&&(makeValuesNegative(n.Values[SEX_MALE]),loaded.population[PP.model.year][n.Code]=n);ajaxMonitor.callCompleted()}function getPracticePopulationCallback(n){var t=PP.data,i;isDefined(n)&&isDefined(n.Values)?(t.currentPracticePopulation=n,makeValuesNegative(n.Values[SEX_MALE]),i=ajaxMonitor.state.year,loaded.population[i][n.Code]=n):t.currentPracticePopulation=null;ajaxMonitor.callCompleted()}function getSelectedParentPopulation(){var r=PP.model,i=r.parentCode,n,t;return i!==null&&(n=r.year,t=loaded.population,t.hasOwnProperty(n)&&t[n].hasOwnProperty(i))?t[n][i]:null}function getPracticePopulation(n,t){var i=PP.model.practiceCode,r;if(isDefined(i))if(r=loaded.population[n][i],isDefined(r))PP.data.currentPracticePopulation=r;else{ajaxGet("api/quinary_population_data","area_code="+i+"&data_point_offset="+t+"&group_id="+populationGroupId,getPracticePopulationCallback);return}else PP.data.currentPracticePopulation=null;ajaxMonitor.callCompleted()}function updateDeprivationTable(n){var t=n.GpDeprivationDecile,i;isDefined(t)?(i=labels[t],$("#d"+t).html('<div class="decileSpacer"><\/div><div class="decile decile'+t+'" >'+t+"<\/div>"),populationState.lastDecile=t):i="<i>Data not available for current practice<\/i>";$("#deprivation").html(i)}function updateEthnicity(n){var t=n.Ethnicity,i=isDefined(t)?t:"<i>Insufficient data to provide accurate summary<\/i>";$("#ethnicity").html(i)}function updateFurtherInfo(n){var i=[],u=n.Qof,t=isDefined(u)?roundNumber(u.Count,1)+" (out of "+u.Denom+")":null,f;i.push({name:"QOF achievement",val:t,iid:295});var e="ale life expectancy",r=n.LifeExpectancyMale,o=isDefined(r);t=o?r.ValF+" years":null;i.push({name:"M"+e,val:t,iid:650});r=n.LifeExpectancyFemale;t=o?r.ValF+" years":null;i.push({name:"Fem"+e,val:t,iid:650});f=n.Recommend;t=isDefined(f)?f.ValF+"%":null;i.push({name:"% of patients that would recommend their practice",val:t,iid:347});$("#further-info-table").html(templates.render("furtherInfo",{rows:i}))}function updateRegisteredPersons(n){var t=[],i,r;populationState.isAnyPopulation()&&t.push({name:ui.getCurrentPractice().Name,val:new PopulationNumber(PP.data.currentPracticePopulation.ListSize).val()});r=getSelectedParentPopulation();r&&(i=new PopulationNumber(r.ListSize),t.push({name:n,val:i.val(),average:i.isData()}));t.push({name:"ENGLAND",val:new PopulationNumber(nationalPopulation[PP.model.year].ListSize).val(),average:!0});$("#pop-table").html(templates.render("furtherInfo",{rows:t}))}function getSelectedPractice(){return $("#practiceMenu").find("option:selected").val()=="-"?"Practice Not Selected":$.parseHTML($("#practiceMenu_chosen span")[0].innerHTML)[0].data}function getExportPopulationHeading(){var n="<b>Age Distribution "+PP.model.year;return $("#parentAreaMenu").find("option:selected").val()=="-"?n+"<\/b>":$("#practiceMenu").find("option:selected").val()=="-"?n+" for "+$("#parentAreaMenu_chosen span")[0].innerHTML+"<\/b>":n+" for "+$("#parentAreaMenu_chosen span")[0].innerHTML+" ("+getSelectedPractice()+")<\/b>"}function exportPopulationChart(){populationChart.exportChart({type:"image/png"},{chart:{spacingTop:70,events:{load:function(){this.renderer.text(getExportPopulationHeading(),250,15).attr({align:"center"}).css({fontSize:"10px",width:"450px"}).add()}}},title:{text:"",style:CHART_TEXT_STYLE}})}function displayPopulationChart(){var f=" (Male)",e=" (Female)",o=chartColours.pink,n=!1,s=getPracticeParentLabel(),h="Age Distribution "+PP.model.year,r=new Population(PP.data.currentPracticePopulation),u=new Population(getSelectedParentPopulation()),i=new Population(nationalPopulation[PP.model.year]),t;try{populationChart&&populationChart.series?(t=populationChart.series,t[0].setData(r.male,n),t[1].setData(r.female,n),t[2].setData(u.male,n),t[3].setData(u.female,n),t[4].setData(i.male,n),t[5].setData(i.female,n),populationChart.setTitle({text:h}),populationChart.redraw()):populationChart=new Highcharts.Chart({chart:{renderTo:"population-chart",defaultSeriesType:"line",margin:[40,55,50,55]},title:{text:h,style:CHART_TEXT_STYLE},xAxis:[{categories:i.Labels,reversed:n},{opposite:!0,reversed:n,categories:i.Labels,linkedTo:0}],yAxis:{title:{text:"Population (%)",style:CHART_TEXT_STYLE},labels:{formatter:function(){return Math.abs(this.value)}}},plotOptions:{series:{events:{legendItemClick:function(){return n}}},bar:{borderWidth:0,pointPadding:0,stacking:"normal"},line:{marker:HC.noLineMarker,states:{hover:{marker:HC.noLineMarker}}}},legend:{enabled:n,layout:"vertical",align:"center",verticalAlign:"bottom",x:0,y:0},tooltip:{formatter:function(){return"<b>"+this.series.name.replace(/2$/,"")+"<br>Age: "+this.point.category+"<\/b><br/>Population: "+Math.abs(this.point.y)+"%"}},credits:HC.credits,exporting:{enabled:!1},series:[{name:"Practice"+f,data:r.male,type:"bar",color:colours.bobLower},{name:"Practice"+e,data:r.female,type:"bar",color:colours.bobHigher},{name:s+f,data:u.male,color:o,showInLegend:n},{name:s+e,data:u.female,color:o},{name:"England"+f,data:i.male,color:colours.comparator,showInLegend:n},{name:"England"+e,data:i.female,color:colours.comparator}]})}catch(c){}}function Population(n){if(n)t=n.Values[SEX_MALE],i=n.Values[SEX_FEMALE],this.Labels=n.Labels;else var t=[],i=[];this.male=t;this.female=i}function PopulationNumber(n){this.data=n}function goToIndicatorsPage(){lock();setPageMode(PAGE_MODES.SPINE);getSpineChartData(PP.model.year,getYearOffset())}function displaySpineCharts(){var s=PP.model,n=s.groupId,i=loaded.data[n],r=null,u=i[NATIONAL_CODE],y=loaded.indicatorMetadata[n],h,f,t,p,c,w;if(!spineChartState.isSubgroupDisplayed(n)){if(h=new PPTooltipProvider(stems),tooltipManager.setTooltipProvider(h),spineChartState.tooltipProvider=h,spineChartState.hideDisplayedTable(),spineChartState.doesSubgroupTableExist(n))spineChartState.showTable(n);else{if(!isRequiredDataAvailable(n)){getSpineChartData(PP.model.year-1,getYearOffset()+1);return}isDefined(i)&&(r=createSpineChartTable(n,u,y))}spineChartState.setDisplayedSubgroupId(n)}updatePracticeLabel();var l=s.isPractice(),e=getBenchmarkCode(),tt=e!==null,b=getBenchmarkId(),k=!spineChartState.isBenchmarkDisplayed(n,e)||b==BENCHMARKS.CCG;k&&(spineChartState.setDisplayedBenchmark(n,e),f=null,b==BENCHMARKS.CCG?l&&(f=getParentMarkerImage(0)):l&&(f=getBenchmarkImage()));var o=spineChartState.getTableId(n),it=$("#"+o+" tbody tr"),rt=i[s.practiceCode],ut=i[e],d=getYearOffset();for(t in u){var a=u[t],v=a.IID,g=y[v],nt=it.filter(":eq("+t+")");getAreaInfo(l,3,g,rt,nt,t,d,v,a,o,!0,null);k&&getAreaInfo(tt,4,g,ut,nt,t,d,v,a,o,!1,f)}if(showAndHidePageElements(),unlock(),r!==null)for(t in u)p=r[t],p!==null&&addTableSpineChartTooltip(t+"_"+o,new IndicatorFormatter(r[t]));changeManager.initChangeTooltips();c=spineChartState.markerIds;for(w in c)tooltipManager.initElement(c[w]);spineChartState.markerIds=[]}function addSpineChartHeader(n){n.push("<thead><tr>");addTh(n,"Indicator");addTh(n,"Period","period");addTh(n,"Practice<br/>Count",CSS_VAL);addTh(n,"Practice<br/>Value",CSS_VAL);addTh(n,getBenchmarkHeader(),CSS_VAL+" benchmark");addTh(n,"England<br>Value",CSS_VAL);addTh(n,"England<br>Lowest",CSS_VAL);addTh(n,'<div class="fl w100" style="position:relative;height:20px;"><div id="info-spinechart" class="info-tooltip" onclick="showSpineInfo()" title="More information about these charts"><\/div><\/div><div style="float:left;width:100%;clear:both;">England Range<\/div>',"range");addTh(n,"England<br>Highest",CSS_VAL);n.push("<tr><\/thead>")}function getTrendTriangle(n,t,i,r,u){var o,f,e,s,h;return PP.model.year>earliestYear&&i>0&&(o=i-1,f=n.Data[o],isDefined(f)&&(e=f.Val,e!=null))?(s=getTrendTriangleImage(r,e),h=changeManager.newImage(t,f.ValF),'<img id="'+h+'" class="change" alt="" src="'+FT.url.img+s+'">'+u):u}function getTrendTriangleImage(n,t){if(n>t)var i="up";else i=n<t?"down":"same";return"change-"+i+".png"}function addIndicatorName(n,t,i,r){if(isDefined(t))var u='<a href="javascript:selectRoot('+r+')">'+t.Descriptive.Name+(new SexAndAge).getLabel(i)+"<\/a>";else u="";addTd(n,u,"rowTitle")}function getAreaData(n,t,i){var f,r,u,e;if(isDefined(t)&&(f=loaded.data,!f.hasOwnProperty(n)||!f[n].hasOwnProperty(t))){r=[];t!==NATIONAL_CODE&&(r.push(NATIONAL_CODE),u=PP.model.parentCode,u!==null&&u!==t&&r.push(u));e=(new ParameterBuilder).add("group_ids",n).add("area_type_id",AreaTypeIds.Practice).add("area_codes",t).add("comparator_area_codes",r.join(","));isDefined(i)&&i&&e.add("include_time_periods","yes");ajaxGet("api/latest_data/all_indicators_in_multiple_profile_groups_for_multiple_areas",e.build(),getAreaDataCallback);return}ajaxMonitor.callCompleted()}function getAreaDataCallback(n){var t,i,r;if(isDefined(n)){t=_.keys(n)[0];checkHash(loaded.data,t);i=n[t];for(r in i)loaded.data[t][r]=i[r]}ajaxMonitor.callCompleted()}function checkHash(n,t){n.hasOwnProperty(t)||(n[t]={})}function getBenchmarkData(){var u=PP.model,f=displaySpineCharts,i,n,t,r,e;if(u.isPractice()&&(i=PP.data.currentPracticePopulation,n=getBenchmarkId()===BENCHMARKS.PEER_GROUP?getPeerGroupCode(i.Shape):getDeprivationCode(i.GpDeprivationDecile),n!==null&&(t=u.groupId,r=loaded.data,!r.hasOwnProperty(t)||!r[t].hasOwnProperty(n)))){ajaxMonitor.setCalls(1);e=(new ParameterBuilder).add("group_ids",t).add("area_type_id",AreaTypeIds.Practice).add("area_codes",n).add("comparator_area_codes",NATIONAL_CODE);ajaxGet("api/latest_data/all_indicators_in_multiple_profile_groups_for_multiple_areas",e.build(),getAreaDataCallback);ajaxMonitor.monitor(f);return}f()}function benchmarkChanged(){setBenchmarkImage();updateBenchmarkHeaders();goToIndicatorsPage()}function getBenchmarkImage(){var n=getBenchmarkId();switch(n){case 0:return getParentMarkerImage(0);case 1:return"square_white_18.png";case 2:return"diamond_white_18.png"}return""}function setBenchmarkImage(){$("#benchmark-img").attr("src",FT.url.img+getBenchmarkImage())}function createSpineChartTable(n,t,i){var k=PP.model.year,rt=loaded.indicatorStats[n][k],d=getYearOffset(),l=[],g=spineChartState.getTableId(n),r=[],f,u,a,o,v,nt,s,y;r.push('<table id="',g,'" class="spine-table bordered-table" cellspacing="0">');addSpineChartHeader(r);r.push("<tbody>");for(f in t){var e=rt[f],ut=isDefined(e.Stats),h=t[f],p=i[h.IID],w=h.Data,b=new TimePeriod(h.Periods,w.length,d);if(ut?u=w[b.yearIndex]:d===0?(e=loaded.indicatorStats[n][k-1][f],u=w[b.yearIndex]):u=null,a=isDefined(u)&&isDefined(e.Stats),r.push("<tr>"),o=getUnitLabel(p),addIndicatorName(r,p,h,f),addTd(r,b.label,CSS_CENTER),addTd(r,"",CSS_NUMERIC),addTd(r,"",CSS_NUMERIC),addTd(r,"",CSS_NUMERIC),v=getValF(u,o),nt=v,addTd(r,nt,CSS_NUMERIC),a)var c=e.StatsF,tt=c.Min+o,it=c.Max+o;else c=null,tt=NO_DATA,it=NO_DATA;addTd(r,tt,CSS_NUMERIC);a?(l.push({metadata:p,stats:c,average:v}),s="proportions",u.hasOwnProperty(s)||(u[s]=getSpineProportions(u.Val,e.Stats,1),u.dimensions=spineChart.getDimensions(u[s])),y=spineChart.getHtml(u.dimensions,f+"_"+g,"")):(l.push(null),y='<div class="noSpine">-<\/div>');addTd(r,y);addTd(r,it,CSS_NUMERIC);r.push("<\/tr>")}return r.push("<\/tbody><\/table>"),$("#spine-table-box").append(r.join("")),spineChartState.addSubgroup(n),l}function addTableSpineChartTooltip(n,t){var i,r;spineChartState.tooltipProvider.add(n,t);i=stems.getKeys();for(r in i)tooltipManager.initElement(i[r]+"_"+n)}function getAreaInfo(n,t,i,r,u,f,e,o,s,h,c,l){var b=null,g=NO_DATA,it=NO_DATA,rt,y,k,v,ut,p,w,nt;if(n){var d=r[f],ft=d.Data,a=ft.length-e-1,tt=ft[a],et=new CoreDataSetInfo(tt);c&&(it=formatCount(et));et.isValue()&&(rt=getUnitLabel(i),y=getValF(tt,rt),b=tt.Val,g=y,c&&d.Sig?(k=d.Sig[NATIONAL_CODE],v=k[a],k.length&&(ut=k[a-1],v!==ut&&(g=getTrendTriangle(d,o,a,b,y))),v=v===3?1:v):v=0)}c&&u.children(":eq(2)").html(it);u.children(":eq("+t+")").html(g);p=getMarkerId(f,h,c?"p":"b");w=$("#"+p);b===null?(y=null,w.length&&w.hide()):(s.Data[a]&&s.Data[a].dimensions&&(nt=spineChart.getMarkerOffset(b,s.Data[a].dimensions,s.Data[a].proportions,0)+s.Data[a].dimensions.q1Offset,l===null&&(l=c?getPracticeMarkerImage(v):getParentMarkerImage(v)),w.length?w.attr("src",FT.url.img+l).css("left",nt).show():(u.children(":eq(7)").children(":eq(0)").append(getMarkerHtml(p,nt,l,2,c?"":" onTop")),spineChartState.markerIds.push(p))),spineChartState.markerValues[p]=y)}function getMarkerHtml(n,t,i,r,u){return['<img id="',n,'" src="',FT.url.img,i,'" class="marker',u,'" style="left:',t,"px;top:",r,'px" alt=""/>'].join("")}function getMarkerId(n,t,i){return["m",n,t,i].join("_")}function getBenchmarkId(){return parseInt($("#benchmarkMenu").val(),10)}function getBenchmarkCode(){var r=getBenchmarkId(),n=PP.model,t=PP.data.currentPracticePopulation,i=n.practiceCode;switch(r){case BENCHMARKS.CCG:return n.parentCode;case BENCHMARKS.DEPRIVATION:if(i!==null)return getDeprivationCode(t.GpDeprivationDecile);break;case BENCHMARKS.PEER_GROUP:if(i!==null)return getPeerGroupCode(t.Shape)}return null}function updateBenchmarkHeaders(){$("TH.benchmark").html(getBenchmarkHeader())}function getNationalData(n){getAreaData(n,NATIONAL_CODE,!0)}function getPracticeMarkerImage(n){return n==1?"circle_darkblue.png":n==0?"circle_white.png":"circle_orange.png"}function updatePracticeLabel(){spineChartState.refreshPracticeLabel()&&spineChartState.setDisplayedPractice()}function showSpineInfo(){getHelpText("spine-chart",300,370,410)}function showBenchmarkInfo(){lightbox.show("<h1>Benchmarks<\/h1><p><\/p>",300,360,300)}function isRequiredDataAvailable(n){var r=PP.model.year,t=loaded.indicatorStats[n][r],f=getYearOffset(),i,u;if(f==0){if(!isDefined(t.isAllData)){i=!0;for(u in t)if(!isDefined(t[u].Stats)){i=!1;break}t.isAllData=i}if(!t.isAllData&&!isDefined(loaded.indicatorStats[n][r-1]))return!1}return!0}function getSpineChartData(n,t){var i=PP.model.groupId,r;ajaxMonitor.setCalls(9);ajaxMonitor.setState({year:n,offset:t});getPracticeAndParentLists();getIndicatorMetadata(i);getIndicatorStats(i,n,t);getLabelSeries();getBenchmarkId()==BENCHMARKS.CCG?(r=displaySpineCharts,getAreaData(i,PP.model.parentCode,!1)):(getPracticePopulation(n,t),r=getBenchmarkData);getAreaData(i,PP.model.practiceCode);getNationalData(i);ajaxMonitor.monitor(r)}function getBenchmarkHeader(){var t=getBenchmarkId(),n;switch(t){case BENCHMARKS.CCG:n=getPracticeParentLabel();break;case BENCHMARKS.DEPRIVATION:n="Decile";break;case BENCHMARKS.PEER_GROUP:n="Peer"}return n+"<br>Value"}function getParentMarkerImage(n){var t;switch(n){case 0:t="white";break;case 2:t="orange";break;default:t="darkblue"}return"markers/triangle-down-"+t+".png"}function goToScatterPage(){lock();setPageMode(PAGE_MODES.SCATTER);ajaxMonitor.setCalls(5);ui.callbackIds.areaData=null;getPracticeAndParentLists();var n=PP.model.groupId;getIndicatorMetadata(n);getNationalData(n);ajaxMonitor.monitor(getScatter2Data)}function displayScatterChart(){var r,f,i;ui.callbackIds.metadata=null;ui.callbackIds.areaData=null;evaluateIndicator1Menu();evaluateSubgroup2Menu();evaluateIndicator2Menu();var n=PP.model,t=[FT.url.bridge,"img/gp-scatter-chart?width=900&height=500&pyr=",n.year,"&off=",getYearOffset()],e=isDefined(n.practiceCode);e&&t.push("&are=",n.practiceCode);updatePracticeScatterLabel(e);r=isDefined(n.parentCode);r&&t.push("&par=",n.parentCode);updatePctScatterLabel(r);f=ui.getSelectedRootIndex();i=ui.getData(NATIONAL_CODE)[f];t.push("&gid1=",n.groupId,"&iid1=",i.IID,"&sex1=",i.Sex.Id,"&age1=",i.Age.Id);var s=$("#indicator2Menu").val(),o=n.groupId2,u=loaded.data[o][NATIONAL_CODE][s];t.push("&gid2=",o,"&iid2=",u.IID,"&sex2=",u.Sex.Id,"&age2=",u.Age.Id);setScatterSrc(t.join(""));showAndHidePageElements();unlock()}function group2Changed(n){lock();PP.model.groupId2=n;ftHistory.setHistory();setScatterSrc("");getScatter2Data()}function indicator2Changed(n){lock();scatterState.setPreferredGroupRoot(n);ftHistory.setHistory();setScatterSrc("");displayScatterChart()}function evaluateIndicator2Menu(){var n=loaded.data[PP.model.groupId2][NATIONAL_CODE],t=$("#indicator2Menu"),i,r;scatterState.doIndicatorRepopulate()&&(scatterState.setIndicatorMenuSubgroupId(),i=loaded.indicatorMetadata[PP.model.groupId2],populateIndicatorMenu(t,i,n));r=getIndicator2Index(n);t.val(r)}function evaluateSubgroup2Menu(){scatterState.isSubgroup2MenuPopulated||(populateSubgroupMenu(loaded.subgroups,"group2Menu"),scatterState.isSubgroup2MenuPopulated=!0);$("#group2Menu").val(PP.model.groupId2)}function setScatterSrc(n){$("#scatter").html('<img src="'+n+'" alt="" />')}function updatePctScatterLabel(n){if(scatterState.doParentUpdate(PP.model.parentCode)){if(n)var t=getPracticeParentName();else t=getPracticeParentLabel();setScatterKeyImg("scatterPct","pct",t);scatterState.setParentCode(PP.model.parentCode)}}function updatePracticeScatterLabel(n){var i=PP.model.practiceCode,t;scatterState.doPracticeUpdate(i)&&(t=n?getPracticeLabel():"PRACTICE",setScatterKeyImg("scatterPractice","practice",t),scatterState.setPracticeCode())}function getScatter2Data(){var n=PP.model.groupId2;isDefined(n)||(n=PP.model.groupId,PP.model.groupId2=n);ajaxMonitor.setCalls(2);ui.callbackIds.areaData=n;getIndicatorMetadata(n);getNationalData(n);ajaxMonitor.monitor(displayScatterChart)}function setScatterKeyImg(n,t,i){$("#"+n).html('<img src="'+FT.url.img+"scatter-"+t+'.png" />'+i)}function goToBarChartPage(){lock();setPageMode(PAGE_MODES.BAR);ajaxMonitor.setCalls(5);getPracticeAndParentLists();getIndicatorMetadata(PP.model.groupId);getNationalData(PP.model.groupId);ajaxMonitor.monitor(getAreaValues)}function displayBarChart(){var o,i,y,n,s,t,h,c,l;initBarChart();var r=ui.getSelectedRootIndex(),a=barChartState.recreateChart(r),b=barChartState.doResort(),p=PP.model.parentCode;if(a||b){if(o=!1,p)if(i=barChartState.getAreaValues(p,r),isDefined(i)&&!_.isEmpty(i)){y=ui.getPractices();a&&(barChartState.practiceList=getPracticeDataForBarChart(i,y));n=barChartState.practiceList;sortPractices(n);var v=[],w=[],u=[],f=[],k=PP.model.practiceCode;for(s in n){t=n[s];h=t.Code;v.push(trimName(t.Name,23)+" "+h);var d=n[s].Sig[-1],g=getPracticeSigColour(d),e=t.Val;e!==-1&&(h!==k?(u.push({y:e,color:g}),f.push(0)):(u.push(0),f.push({y:e,color:"#000"})),w[e]=getYValLabel(t))}barChartState.displayedAreaValues=w;o=!0;barChartState.setSortKey();a?createBarChart(u,f,v,r):resortBarChart(u,f,v)}else c="No data is available";else c="Select a CCG";barChartState.setDisplayedKey(r);showOrHideBarChart(o,c)}l=barChartState.scrollTop;l&&($(window).scrollTop(l),barChartState.scrollTop=null);showAndHidePageElements();unlock()}function getPracticeSigColour(n){if(n===0)var t=colours.noComparison;else t=getColourFromSignificance(n,!1,colours,!1),t===colours.bobHigher&&(t=colours.bobLower);return t}function getAreaValues(){if(evaluateIndicator1Menu(),PP.model.parentCode!==null){var t=ui.getSelectedRootIndex(),i=PP.model.parentCode,r=barChartState.getAreaValues(i,t);if(!isDefined(r)){ajaxMonitor.setCalls(2);getAreaData(PP.model.groupId,i,!1);var u=ui.getData(NATIONAL_CODE),n=u[t],f=(new ParameterBuilder).add("group_id",PP.model.groupId).add("area_type_id",AreaTypeIds.Practice).add("parent_area_code",NATIONAL_CODE).add("comparator_id",-1).add("data_point_offset",getYearOffset()).add("indicator_id",n.IID).add("sex_id",n.Sex.Id).add("age_id",n.Age.Id);ajaxGet("api/latest_data/single_indicator_for_all_areas",f.build(),getAreaValuesCallback);ajaxMonitor.monitor(displayBarChart);return}}displayBarChart()}function getAreaValuesCallback(n){barChartState.setAreaValues(PP.model.parentCode,n);ajaxMonitor.callCompleted()}function getYValLabel(n){var t=n.Val;return t<10?roundNumber(t,2):n.ValF}function getCategoryFromLabel(n){var t=n.split(" ");return $.trim(t[t.length-1])}function barClicked(n){lock();barChartState.scrollTop=$(window).scrollTop();var t=getCategoryFromLabel(n);setPracticeCode(t);ftHistory.setHistory();goToBarChartPage()}function showOrHideBarChart(n,t){var i=$("#noBarChart"),r=$("#barChart,#sortPracticeBox"),u=$("#barBox .export-chart-box"),f=$("#barBox .legends");n?(r.show(),i.hide(),u.show(),f.show()):(i.html(t),r.hide(),i.show(),u.hide(),f.hide())}function createBarChart(n,t,i,r){var u=ui.getData(NATIONAL_CODE)[r],ft=u.IID,v=u.Data,y=new TimePeriod(u.Periods,v.length,getYearOffset()),p=y.yearIndex,w=[],f=v[p],b,k,e,d,o,s,h;if(f){b=f.Val;for(d in t)w.push(b)}var et=ui.getData(PP.model.parentCode),ot=et[r].Data,c=ot[p];if(c){k=c.Val;e=[];for(d in t)e.push(k)}var g=ui.getMetadataHash()[ft],nt=g.Descriptive.Name,tt=g.Unit,st=getBarChartYLabel(nt,tt.Label),l=getPracticeParentName(),a=[{name:l+" (individual practices)",data:n,events:{click:function(n){barClicked(n.point.category)}},showInLegend:!1}];PP.model.isPractice()&&(o=ui.getCurrentPractice(),a.push({name:o.Code+" - "+o.Name,data:t,color:"#000",events:{click:function(n){barClicked(n.point.category)}},legendIndex:3}));var it="England",rt=chartColours.pink,ut=" (value)";a.push({name:it+ut,type:"line",data:w,color:colours.comparator,legendIndex:0},{name:l+ut,type:"line",data:e,color:rt,legendIndex:1});s={color:"#333",fontWeight:"normal",textShadow:"0"};h=nt+(new SexAndAge).getLabel(u);try{barChart=new Highcharts.Chart({chart:{renderTo:"barChart",animation:!1,defaultSeriesType:"bar",width:850,height:getBarChartHeight(n)},title:{text:'<div class="barChartTitle"><b>'+h+"<\/b> - <b>"+y.label+"<\/div>",style:CHART_TEXT_STYLE,useHTML:!0},subtitle:{style:{direction:"ltr",align:"center",color:chartColours.label,fontWeight:"normal",fontFamily:"Verdana"},text:l,useHTML:!0,align:"center"},xAxis:{categories:i,labels:{step:1}},yAxis:{title:{text:h+st,style:CHART_TEXT_STYLE}},plotOptions:{series:{animation:!1,events:{legendItemClick:function(){return!1}}},bar:{borderWidth:0,pointPadding:0,pointWidth:11,stacking:"normal",shadow:!1,dataLabels:{allowOverlap:!0,enabled:!0,style:s,align:"right",y:0,x:28,formatter:function(){return this.y===0?"":barChartState.displayedAreaValues[this.y]}}},line:{marker:HC.noLineMarker,states:{hover:{marker:HC.noLineMarker}}}},legend:{enabled:!0,borderWidth:0,layout:"vertical",itemStyle:s},tooltip:{formatter:function(){var t=this.series,n,i,e,r,u;return t.name.indexOf(it)===0?(n=t.name,i=f.ValF):t.color===rt?(n=t.name,i=c.ValF):(e=this.point.y,i=barChartState.displayedAreaValues[e],n=this.point.category,r=getCategoryFromLabel(n),u=getPracticeFromCode(r),u&&(n=r+" - "+u.Name)),"<b>"+n+"<\/b><br/>"+new ValueWithUnit(tt).getFullLabel(i)}},credits:HC.credits,series:a,exporting:{allowHTML:!0,enabled:!1}})}catch(ht){}}function getPracticeDataForBarChart(n,t){var e=[],u={},f,i,r;_.each(n,function(n){u[n.AreaCode]=n});for(f in t)i=t[f].Code,u[i]&&(r=u[i],e.push({Code:i,Val:r.Val,ValF:r.ValF,Name:t[f].Name,Sig:r.Sig}));return e}function sortPractices(n){if(barChartState.sortType===0)var t=sortAreasByName;else t=barChartState.sortType===1?sortByCode:sortData;n.sort(t);barChartState.sortDirection===1&&n.reverse()}function sortPracticesClicked(n){lock();var t="#sortPractice";setPageSelected(t+"Box",t+n);barChartState.setSortType(n);displayBarChart()}function getBarChartHeight(n){var t=n.length*15+205;return PP.model.isPractice()&&(t+=20),t}function initBarChart(){barChartState.isInitialised||($("#barBox").html(templates.render("barChart",{options:barChartState.sortOptions})),barChartState.isInitialised=!0)}function getBarChartYLabel(n,t){return t!==""&&(t=" ("+t+")",n.endsWith(t)&&(t="")),t}function resortBarChart(n,t,i){chart.series[0].setData(n,!1);PP.model.isPractice()&&chart.series[1].setData(t,!1);chart.xAxis[0].setCategories(i,!1);chart.redraw()}function sortByCode(n,t){var i=n.Code.toLowerCase(),r=t.Code.toLowerCase();return i<r?-1:i>r?1:0}function showExportChartLink(){return'<div class="export-chart-box"><a class="export-link" href="javascript:exportChartAsImage(barChart)">Export chart as image<\/a><\/div>'}function goToTrendsPage(){lock();showSpinner();var i=latestYear,r=getYearOffset(),n=PP.model.groupId,t=PP.model.parentCode;setPageMode(PAGE_MODES.TRENDS);ajaxMonitor.setCalls(9);ajaxMonitor.setState({year:i,offset:r});getPracticeAndParentLists();getIndicatorMetadata(n);getValueLimits(n,AreaTypeIds.Practice,t);getMetadataProperties();getAreaData(n,t,!1);getAreaData(n,PP.model.practiceCode);getNationalData(n);ajaxMonitor.monitor(displayTrends)}function displayTrends(){var a=PP.model.practiceCode,f=PP.model.groupId,e=PP.model.isPractice(),o=loaded.data[f],i=o[NATIONAL_CODE],et=loaded.indicatorMetadata[f],ot=o[a],st=o[getBenchmarkCode()],v=!!PP.model.parentCode,y=[],ht=getPracticeParentLabel(),p=[],w=[],s=0,n,b,k,r,h,u,t,d;for(n in i){i[n].Data.length>s&&(s=i[n].Data.length);var g=i[n],nt=g.IID,tt=et[nt],c={rows:[],benchmark:ht,practice:e?a:"Practice",iid:nt,groupId:f,name:tt.Descriptive.Name},it=i[n].Data;for(e&&(b=ot[n].Data),v&&(k=st[n].Data),r=new TrendData,h=[],p.push(r),w.push(h),u=getUnitLabel(tt),t=0;t<it.length;){var l=it[t],rt=g.Periods[t],ut=e?b[t]:null,ft=v?k[t]:null;l&&(c.rows.push([rt,getValF(ut,u),getValF(ft,u),getValF(l,u)]),h.push(rt),r.addPracticePoint(ut),r.addCcgPoint(ft),r.addNationalPoint(l));t++}c.index=n;y.push(templates.render("trends",c))}$("#trendsBox").html(y.join(""));displayTrendCharts(p,w,i);showAndHidePageElements();d=s*20+280+"px";$(".small-trend-box").css("height",d);unlock()}function createTrendChart(n,t,i,r){var u=[{data:t.getNationalPoints(),color:colours.comparator,name:"England"}];PP.model.parentCode&&u.push({data:t.getCcgPoints(),color:chartColours.pink,name:"CCG"});PP.model.isPractice()&&u.push({data:t.getPracticePoints(),color:colours.bobLower,name:ui.getCurrentPractice().Name});try{new Highcharts.Chart({chart:{renderTo:n,defaultSeriesType:"line",zoomType:"xy",width:300,height:200},title:{text:""},xAxis:{title:{enabled:!1},categories:i,tickLength:3,tickPosition:"outside",tickWidth:1,tickmarkPlacement:"on"},yAxis:{title:{text:""},max:r.Max,min:r.Min},legend:{enabled:!0,layout:"vertical",borderWidth:0},plotOptions:{line:{enableMouseTracking:!0,lineWidth:2,animation:!1,marker:{radius:3,symbol:"circle",lineWidth:1,lineColor:"#000000"}},series:{events:{legendItemClick:function(){return!1}}}},credits:HC.credits,series:u,exporting:{enabled:!1}})}catch(f){}}function TrendData(){var t=[],i=[],r=[],n=function(n){return n?isValidValue(n.Val)?parseFloat(n.ValF):null:null};this.addPracticePoint=function(t){r.push(n(t))};this.addNationalPoint=function(i){t.push(n(i))};this.getNationalPoints=function(){return t};this.getPracticePoints=function(){return r};this.addCcgPoint=function(t){i.push(n(t))};this.getCcgPoints=function(){return i}}function displayTrendCharts(n,t,i){var f=loaded.valueLimits[getValueLimitsKey()],r,u;for(r in n)u=f[r],u&&(adjustLimitsForNationalValue(u,i[r].Data),createTrendChart("trendChart"+r,n[r],t[r],u))}function getValueLimits(n,t,i){var u=getValueLimitsKey(),r;loaded.valueLimits[u]?ajaxMonitor.callCompleted():(r=(new ParameterBuilder).add("group_id",n).add("area_type_id",t),i&&r.add("parent_area_code",i),ajaxGet("api/value_limits",r.build(),getValueLimitsCallback))}function getValueLimitsCallback(n){loaded.valueLimits[getValueLimitsKey()]=n;ajaxMonitor.callCompleted()}function getValueLimitsKey(){var n=PP.model.parentCode;return getKey(PP.model.groupId,n?n:"")}function adjustLimitsForNationalValue(n,t){var u,r,i;for(u in t)r=t[u],r&&(i=r.Val,n.Min>i&&(n.Min=i),n.Max<i&&(n.Max=i))}function goToPracticeSearchPage(){lock();setPageMode(PAGE_MODES.SELECT);ajaxMonitor.setCalls(3);getPracticeAndParentLists();ajaxMonitor.monitor(displaySearch)}function selectPractice(n){FT.ajaxLock||(lock(),loaded.addresses[n]=_.find(practiceSearchState.results,function(t){return t.Code===n}),$("#all_ccg_practices").show(),getParentAreas(n))}function getParentAreasCallback(n){var t=n,i;t&&(loaded.parentAreas[t.Code]=n,i=_.find(t.Parents,function(n){return n.AreaTypeId===PP.model.parentAreaType}),PP.model.parentCode=i?i.Code:null,$(ID_PARENT_AREA_MENU).val(i.Code),setPracticeCode(t.Code),PP.model.mode=PAGE_MODES.POPULATION,ftHistory.setHistory(),$("#mapBox").hide(),goToCurrentPage())}function getParentAreas(n){var t=loaded.parentAreas,i;t.hasOwnProperty(n)?getParentAreasCallback(t[n]):(i=(new ParameterBuilder).add("child_area_code",n).add("parent_area_type_ids",AreaTypeIds.CCG),ajaxGet("api/area/parent_areas",i.build(),function(n){getParentAreasCallback(n)}))}function displaySearch(){var t;showAndHidePageElements();var u=PP.model.parentCode,n=practiceSearchState,i=n.displayedArea,r=n.selectedArea;n.selectedArea&&r!==i?(n.displayedArea=r,t=initTableAndMapData(),displayPracticeResultsTable(t),t.length?displayMarkersOnMap():defaultGoogleMap(r.LatLng),n.selectedArea=null):n.showAllInCcg&&u!==i?(n.displayedArea=u,t=initTableAndMapData(),displayPracticeResultsTable(t),displayMarkersOnMap(),n.showAllInCcg=!1):i||(n.displayedArea="default",defaultGoogleMap());unlock()}function displayPracticeResultsTable(n){var t=practiceSearchState.showAllInCcg,i=$("#search-table tbody"),r;isDefined(n)?(t&&n.sort(sortAreasByName),i.html(templates.render("rows",{rows:n,showAllInCcg:t})),$(".nearby-practices-table").show(),$("#table-container").scrollTop(0),r=t?templates.render("searchCCGHeader",{selectedArea:getPracticeParentName(),practiceCount:n.length}):templates.render("searchNearHeader",{selectedArea:practiceSearchState.selectedArea.PlaceName}),$("#data_page_header").html(r),t||displayNumberOfPracticesFound(n.length)):i.html("No GP practice found")}function areaSearchResultSelected(n,t){FT.ajaxLock||(lock(),practiceSearchState.selectedArea=t,practiceSearchState.showAllInCcg=!1,$("#default_search_header").hide(),$("#all_ccg_practices").html("Show all practices"),ajaxMonitor.setCalls(1),getPractices(t),ajaxMonitor.monitor(goToPracticeSearchPage))}function showAllPracticesInCCG(){FT.ajaxLock||(lock(),practiceSearchState.selectedArea=null,practiceSearchState.showAllInCcg=!0,$("#default_search_header").hide(),logEvent("PracticeSearch","ShowAllPracticesInCCG"),ajaxMonitor.setCalls(1),getCCGPractices(),ajaxMonitor.monitor(goToPracticeSearchPage))}function getPractices(n){var t=(new ParameterBuilder).add("easting",n.Easting).add("northing",n.Northing).add("area_type_id",AreaTypeIds.Practice);ajaxGet("api/area_search_by_proximity",t.build(),getGpPracticesNearbyCallback)}function getCCGPractices(){var n=(new ParameterBuilder).add("parent_area_code",PP.model.parentCode).add("area_type_id",AreaTypeIds.Practice);ajaxGet("api/area_addresses/by_parent_area_code",n.build(),getGpPracticesNearbyCallback)}function getGpPracticesNearbyCallback(n){loaded.nearbyPractices=n;ajaxMonitor.callCompleted()}function initTableAndMapData(){var t=loaded.nearbyPractices,u=[],i,f,n,r;practiceSearchState.practicesOnMap=u;i=practiceSearchState.showAllInCcg;for(f in t)n=t[f],i&&(n.AreaName=n.Name,n.AreaCode=n.Code,n.AddressLine1=n.A1,n.AddressLine2=n.A2),r=i?isDefined(n.Pos)?{Name:n.AreaName,Lat:n.Pos.Lat,Lng:n.Pos.Lng,AreaCode:n.AreaCode}:null:isDefined(n.LatLng)?{Name:n.AreaName,Lat:n.LatLng.Lat,Lng:n.LatLng.Lng,AreaCode:n.AreaCode}:null,r&&u.push(r);return t}function displayNumberOfPracticesFound(n){var i=practiceSearchState.selectedArea.PlaceName,t;t=n===0?"are no practices":n===1?"is 1 practice":"are "+n+" practices";$("#no-of-practices").html("There "+t+" within 5 miles of "+i)}function defaultGoogleMap(n){var i=google.maps,r,t;$("#mapBox").addClass("default");$("#default_search_header").html(templates.render("searchDefaultHeader",{}));r=getGoogleMap();t=new i.LatLngBounds;n||(n=new i.LatLng(53.415649,-2.209015));t.extend(n);r.setCenter(t.getCenter())}function displayMarkersOnMap(){for(var u,r,f,t=practiceSearchState.practicesOnMap,i=google.maps,e=getGoogleMap(),o=new i.LatLngBounds,n=0;n<t.length;n++)u=new i.LatLng(t[n].Lat,t[n].Lng),o.extend(u),r=new i.Marker({position:u,map:e}),r.set("marker_id",t[n].AreaCode),f=new i.InfoWindow({}),i.event.addListener(r,"click",function(n,i){return function(){var r,s,u;if(!FT.ajaxLock){r=n.get("marker_id");s='<div class="map-popup-content"><a class="select-area-link" href="javascript:selectPractice(\''+r+"')\">"+t[i].Name+"<\/a><\/div>";f.setContent(s);f.open(e,n);var o=$("#table-container"),h=$("#"+r+"-practice-header"),c=h.offset().top-o.offset().top+o.scrollTop();o.scrollTop(c);u="highlight";$(".highlight").removeClass(u);h.addClass(u);$("#"+r+"-address").addClass(u)}}}(r,n));fitMapToPracticeResults(e,o)}function goToClusterPage(){lock();setPageMode(PAGE_MODES.CLUSTER);ajaxMonitor.setCalls(4);getPracticeAndParentLists();getClusters();ajaxMonitor.monitor(displayCluster)}function displayCluster(){clusterState.isInitialised||initCluster();$("#clusterBox").html(templates.render(clusterState.getTemplate()));cluster.setUpClusterIcon();displayClusterList();displayTabsByClusterMode();showAndHidePageElements();unlock()}function Cluster(){this.areas=[];this.clear=function(){this.areas=[]};this.getName=function(){return $("#clusterName").val()};this.getId=function(){return""};this.icon=null;this.iconOver=!1;this.togglePractice=function(n){var t=loaded.addresses[n],i=_.reject(this.areas,function(t){return t.Code===n});i.length===this.areas.length?(t.Address=getAddressText(t),this.areas.push(t)):this.areas=i;this.refreshClusterIcon()};this.setUpClusterIcon=function(){this.icon===null&&(this.icon=$("#mainClusterIcon"));PP.model.isPractice()&&clusterState.isEditMode?this.icon.show():this.icon.hide();this.refreshClusterIcon()};this.refreshClusterIcon=function(){var t="clusterRemove",n;_.any(this.areas,function(n){return n.Code===PP.model.practiceCode})?(this.icon.addClass(t),n=this.iconOver?"remove practice from cluster":"practice in cluster"):(this.icon.removeClass(t),n="add practice to cluster");this.icon.html(n)}}function toggleClusterArea(n){n===null&&(n=PP.model.practiceCode);cluster.togglePractice(n);displayClusterList()}function displayClusterList(){var n,t,i;if(clusterState.mode===clusterState.USER_CLUSTERS){n=clusterState.clusterList;for(t in n)n[t].count=n[t].AreaCodes.length;$("#clusterBox").html(templates.render("userClusters",{clusters:n}))}clusterState.mode===clusterState.EDIT&&(i=cluster.areas,$("#clusterList").html(templates.render("practiceList",{areas:i.length?i:null})))}function displayTabsByClusterMode(){var n=$("#downloadPdf,#exportExcel,#tabMetadata,#tabScatter,#tabIndicators,#tabBar,#tabTrends,#yearBox");clusterState.isEditMode?n.hide():n.show()}function cancelClusterEdit(){cluster.clear();setClusterMode(clusterState.USER_CLUSTERS)}function initCluster(){cluster=new Cluster;clusterState.mode=clusterState.LOGIN_REQUIRED;$('<div id="mainClusterIcon" class="fl clusterIcon" onmouseover="clusterIconOver()" onmouseout="clusterIconOut()" onclick="toggleClusterArea(null)"><\/div>').insertAfter("#practiceMenu");cluster.setUpClusterIcon();clusterState.isInitialised=!0}function setClusterMode(n){clusterState.mode=n;n==clusterState.NEW||n==clusterState.EDIT?clusterState.editOn():clusterState.editOff();displayCluster()}function saveCluster(){var n=cluster.getName(),t;if(String.isNullOrEmpty(n)){alert("no name");return}if(!cluster.areas.length){alert("no practices");return}t=_.pluck(cluster.areas,"Code");$.post("SaveCluster.aspx",{s:"sc",acs:t.join(","),nam:n,cid:cluster.getId()},saveClusterCallback,"json")}function clusterIconOver(){cluster.iconOver=!0;cluster.refreshClusterIcon()}function clusterIconOut(){cluster.iconOver=!1;cluster.refreshClusterIcon()}function saveClusterCallback(n){n.result===1?cancelClusterEdit():alert(n.message)}function getClusters(){ajaxGetPage("GetClusters.aspx","",getClustersCallback)}function getClustersCallback(n){clusterState.clusterList=n;ajaxMonitor.callCompleted()}function ajaxGetPage(n,t,i,r){var u={type:"GET",url:n,data:t,cache:!1,contentType:"application/json",success:i,error:isDefined(r)?r:ajaxError};u.dataType=useJsonp?"jsonp":"json";useJsonp&&(u.jsonpCallback="jp");$.ajax(u)}function login(){setClusterMode(clusterState.USER_CLUSTERS)}function viewCluster(){}function documentReady(){if(isInitRequired){lock();PP.model.reset();ftHistory.init(PP.model);spineChart.init(200,18);stems=new SpineChartStems({min:"Lowest",max:"Highest"});loaded.areaLists[AreaTypeIds.Practice]={};loaded.areaLists[AreaTypeIds.CCG]={};addYearHashes(loaded.population);loaded.indicatorMetadata={};loaded.indicatorStats={};loaded.addresses={};var n=$("#subgroupSelection");spineChartJQs=[n];metadataJQs=[$(".indicatorSelection"),n];scatterJQs=metadataJQs;trendsJQs=[n];barJQs=metadataJQs;allJQs=[spineChartJQs,metadataJQs];PP.menuManager=new MenuManager;ajaxMonitor.setCalls(1);getGroupingTree();ajaxMonitor.monitor(PP.model.restore);tooltipManager.init();initYears();initAreaSearch("#searchText",!0)}}function handleAjaxFailure(){var n=window.location.href;n.indexOf("#")>0&&(alert("The data could not be loaded. Please try again."),PP.model.reset())}function getPracticeList(){var n=PP.model.parentCode,t,r,i,u;isDefined(n)?(t=loaded.areaLists[AreaTypeIds.Practice][n],isDefined(t)?getPracticeListCallback(t):(r=loaded.areaLists[AreaTypeIds.Practice],i=r[n],isDefined(i)?getPracticeListCallback(i):(u=(new ParameterBuilder).add("parent_area_code",n).add("area_type_id",AreaTypeIds.Practice),ajaxGet("api/areas/by_parent_area_code",u.build(),getPracticeListCallback)))):($("#all_ccg_practices").hide(),$("#practiceMenuBox").hide(),ajaxMonitor.callCompleted())}function getPracticeListCallback(n){loaded.areaLists[AreaTypeIds.Practice][PP.model.parentCode]=n;displayPracticeMenu(n);ajaxMonitor.callCompleted()}function practiceChanged(n){lock();setPracticeCode(n);setPopulationModeIfDataPageNotDisplayed();ftHistory.setHistory();goToCurrentPage()}function getLabelSeries(){if(isDefined(labels[1]))ajaxMonitor.callCompleted();else{var n=(new ParameterBuilder).add("category_type_id",CategoryTypeIds.DeprivationDecileGp2015);ajaxGet("api/categories",n.build(),function(n){labels=_.object(_.map(n,function(n){return[n.Id,n.Name]}));ajaxMonitor.callCompleted()})}}function showBox(n){n=n.toLowerCase();var t="page-selected";$(".pageBox").hide();$("."+t).removeClass(t);$("#page-"+n).addClass(t);$("#"+n+"Box").show()}function goToCurrentPage(n){lock();switch(PP.model.mode){case PAGE_MODES.SELECT:goToPracticeSearchPage(n);break;case PAGE_MODES.SPINE:goToIndicatorsPage(n);break;case PAGE_MODES.POPULATION:goToPopulationPage(n);break;case PAGE_MODES.METADATA:goToMetadataPage(n);break;case PAGE_MODES.SCATTER:goToScatterPage(n);break;case PAGE_MODES.BAR:goToBarChartPage(n);break;case PAGE_MODES.TRENDS:goToTrendsPage(n)}}function makeValuesNegative(n){for(var t in n)n[t]=-Math.abs(n[t])}function getPracticeParentName(){var n=$(ID_PARENT_AREA_MENU+" option:selected");return n.val()!==NULL_OPTION?n.text():getPracticeParentLabel()}function getPracticeParentLabel(){return"CCG"}function yearClicked(n){FT.ajaxLock||(lock(),setPopulationModeIfDataPageNotDisplayed(),setYear(n),ftHistory.setHistory(),goToCurrentPage())}function getYearOffset(){return latestYear-PP.model.year}function setPracticeCode(n){PP.model.practiceCode=n&&n!==NULL_OPTION?n:null;ui.setPreferredPractice();selectCodeInMenu(ID_PRACTICE_MENU,PP.model.practiceCode)}function getGroupingTree(){var n=(new ParameterBuilder).add("group_ids",groupIds);ajaxGet("api/group_metadata",n.build(),function(n){isDefined(n)&&(loaded.subgroups=n,PP.model.groupId=n[0].Id,populateSubgroupMenu(n,"subgroupMenu"));ajaxMonitor.callCompleted()})}function populateSubgroupMenu(n,t){var r=$("#"+t)[0],u,f,i;r.options.length=0;u=0;for(f in n)i=n[f],r.options[u++]=new Option(i.Name,i.Id)}function getSelectedSubgroup(){return $("#subgroupMenu").val()}function subgroupChanged(n){lock();PP.model.groupId=n;ftHistory.setHistory();goToCurrentPage()}function getIndicatorStats(n,t,i){var r=loaded.indicatorStats[n],u;isDefined(r)&&isDefined(r[t])?ajaxMonitor.callCompleted():(u=(new ParameterBuilder).add("group_id",n).add("child_area_type_id",AreaTypeIds.Practice).add("data_point_offset",i).add("parent_area_code",NATIONAL_CODE),ajaxGet("api/indicator_statistics",u.build(),getIndicatorStatsCallback))}function getIndicatorStatsCallback(n){var t,i,r;isDefined(n)&&(t=PP.model.groupId,i=loaded.indicatorStats,checkHash(i,t),r=ajaxMonitor.state.year,i[t][r]=n);ajaxMonitor.callCompleted()}function getValF(n,t){return isDefined(n)?n.ValF+t:NO_DATA}function getUnitLabel(n){return isDefined(n)&&n.Unit.Id===5?'<span class="unit">%<\/span>':""}function lock(){FT.ajaxLock||(FT.ajaxLock=1,PP.menuManager.disableAll())}function addYearHashes(n){for(var t=earliestYear;t<=latestYear;t++)n[t]={}}function IndicatorFormatter(n){var t=n.stats,r=n.metadata,u=r.Unit,f=new ValueWithUnit(u),i=!1,e=n.average;this.getIndicatorName=function(){return r.Descriptive.Name};this.getIndicatorNameLong=function(){return r.Descriptive.NameLong};this._getVal=function(n,t){return!n||n[t]==="-"?NO_DATA:f.getShortLabel(n[t])};this.getSuffixIfNoShort=function(){return new ValueSuffix(u).getFullLabelIfNoShort()};this.getArea=function(n){return this.getMarker(n).name};this.getAverage=function(){return e};this.getMin=function(){return this._getVal(t,i?"Max":"Min")};this.getMax=function(){return this._getVal(t,i?"Min":"Max")};this.get25=function(){return this._getVal(t,i?"P75":"P25")};this.get75=function(){return this._getVal(t,i?"P25":"P75")}}function unlock(){FT.ajaxLock===1&&(FT.ajaxLock=null,PP.menuManager.enableAll(),hideSpinner(),$(MAIN).show())}function getDeprivationCode(n){return isDefined(n)?"cat-1-"+n:null}function getPeerGroupCode(n){return isDefined(n)?"S_"+n:null}function goToMetadataPage(){lock();setPageMode(PAGE_MODES.METADATA);ajaxMonitor.setCalls(6);getPracticeAndParentLists();var n=PP.model.groupId;getIndicatorMetadata(n);getNationalData(n);getMetadataProperties();ajaxMonitor.monitor(displayPracticeProfilesMetadata)}function displayPracticeProfilesMetadata(){var n,t;if(evaluateIndicator1Menu(),n=ui.getSelectedRootIndex(),t=PP.model.groupId,metadataState.redisplay(n,t)){metadataState.setDisplayedKey(n,t);var r=ui.getMetadataHash(),i=ui.getData(NATIONAL_CODE)[n],u=i.IID;displayMetadata(r[u],i)}showAndHidePageElements();unlock()}function populateIndicatorMenu(n,t,i,r){var f=n[0],u,e,h,o,s;f.options.length=0;for(u in i)e=i[u],h=e.IID,f.options[u]=new Option(t[h].Descriptive.Name+(new SexAndAge).getLabel(e),u);if(isDefined(r))for(o in i)if(r==o){s="selected";$(f.options[o]).attr(s,s);break}}function indicatorChanged(n){ui.setPreferredGroupRoot(n);ftHistory.setHistory();goToCurrentPage()}function showAndHidePageElements(){tooltipManager.isVisible&&tooltipManager.hide();switch(PP.model.mode){case PAGE_MODES.SELECT:showAllJQs([]);showBox("Map");break;case PAGE_MODES.SPINE:showAllJQs(spineChartJQs);showBox("Indicators");break;case PAGE_MODES.POPULATION:showAllJQs([]);showBox("Population");break;case PAGE_MODES.METADATA:showAllJQs(metadataJQs);showBox("Metadata");break;case PAGE_MODES.SCATTER:showAllJQs(scatterJQs);showBox("Scatter");break;case PAGE_MODES.BAR:showAllJQs(barJQs);showBox("Bar");break;case PAGE_MODES.CLUSTER:showAllJQs([]);showBox("Cluster");break;case PAGE_MODES.TRENDS:showAllJQs(trendsJQs);showBox("Trends")}}function evaluateIndicator1Menu(){var n=ui.getData(NATIONAL_CODE,PP.model.year),t=$("#indicatorMenu"),i;ui.doIndicatorRepopulate()&&(ui.setIndicatorMenuSubgroupId(),populateIndicatorMenu(t,ui.getMetadataHash(),n));i=getIndicator1Index(n);t.val(i.toString())}function selectRoot(n){FT.ajaxLock||(lock(),ui.setPreferredGroupRoot(n),PP.model.mode=PAGE_MODES.BAR,ftHistory.setHistory(),goToBarChartPage())}function selectMenuOption(n,t){$("#"+n+" option:eq("+t+")").attr("selected","selected")}function getPracticeFromCode(n){var t=ui.getPractices();for(var i in t)if(t[i].Code===n)return t[i];return null}function getPracticeLabel(){if(PP.model.practiceCode===null)return"";var n=ui.getCurrentPractice();return n.Code+" - "+n.Name}function displayPracticeMenu(n){var u=$(ID_PRACTICE_MENU),h=PP.model.practiceCode,f="selected",t=u[0].options,i,e;t.length=0;i=0;t[i++]=new Option("SELECT A PRACTICE >>","-");for(e in n){var o=n[e],r=o.Code,s=new Option(r+" - "+o.Name,r);t[i++]=s;r===h&&$(s).prop(f,f)}$("#practiceMenuBox").show();$(ID_PRACTICE_MENU+"_chosen").length||u.chosen({search_contains:!0})}function getPracticeAddress(){var t,n,i;if(displayPracticeHeading(),t=$("#practiceTitle"),n=PP.model.practiceCode,n){if(ui.displayedAddressCode!==n)if(i=loaded.addresses[n],ui.displayedAddressCode=n,isDefined(i))updatePracticeAddress(i);else{t.html("");ajaxGet("api/area_address","area_code="+n,getPracticeAddressCallback);return}}else{ui.displayedAddressCode=null;t.html("");try{clusterState.isEditMode&&cluster.setUpClusterIcon()}catch(r){}}ajaxMonitor.callCompleted()}function getPracticeAddressCallback(n){if(isDefined(n)){var t=n.Code;loaded.addresses[t]=n;PP.model.practiceCode===t&&updatePracticeAddress(n)}ajaxMonitor.callCompleted()}function updatePracticeAddress(n){$("#practiceTitle").html(getAddressText(n));try{clusterState.isEditMode&&cluster.setUpClusterIcon()}catch(t){}}function clearPracticeAddress(){$("#address").html("")}function setPageMode(n){PP.model.mode!==n&&(PP.model.mode=n,ftHistory.setHistory())}function setYear(n){PP.model.year=n;displayCurrentYear()}function setAreaType(n){PP.model.parentAreaType=n;var t="CCG";$("#areaTypeSelected").html(t);$("#areaTypeUnselected").html(t);$("#parentBoxLabel").html(t+":");$("#benchmark-parent-option").html(t);setBenchmarkImage();updateBenchmarkHeaders()}function selectCodeInMenu(n,t){isDefined(t)?$(n).val(t):$(n).val(NULL_OPTION)}function getIndicator1Index(n){var t=PP.model.indicator1,i;return t!==null&&(i=PP.model.getRootIndex(t,n),PP.model.indicator1=null,ui.setPreferredGroupRoot(i)),ui.getPreferredGroupRoot()}function getIndicator2Index(n){var i=PP.model.indicator2,t;return i!==null?(t=PP.model.getRootIndex(i,n),PP.model.indicator2=null,scatterState.setPreferredGroupRoot(t)):(t=scatterState.indicator2DefaultIndex,t!==null&&(t>n.length-1&&(t=0),scatterState.indicator2DefaultIndex=null)),t!==null&&scatterState.setPreferredGroupRoot(t),scatterState.getPreferredGroupRoot()}function ifNoLock(n){FT.ajaxLock||n()}function showExport(){var n;if(!FT.ajaxLock){var i=PP.model.isPractice(),u=i?getPracticeLabel():"",r=PP.model.parentCode!==null,f=r?getPracticeParentName():getPracticeParentLabel(),t="exportSubgroupMenu",e=templates.render("export",{practice:u,parent:f,isPractice:i,isParent:r,menuId:t});lightbox.show(e,150,410,400);populateSubgroupMenu(loaded.subgroups,t);n=$("#"+t);n.prepend('<option value="pop" selected="selected">Population Age Distribution<\/option>');n[0].selectedIndex=0}}function exportData(){var u=parseInt($("input[name=g1]:checked").val(),10),n,t,i,r;switch(u){case 1:n=PP.model.parentCode;break;default:n=NATIONAL_CODE}t=$("#exportSubgroupMenu").val();lightbox.hide();t==="pop"?i=FT.url.corews+"GetData.ashx?s=db&are="+n+"&ati="+PP.model.parentAreaType+"&pro=qp&gid="+populationGroupId:(r=(new ParameterBuilder).add("parent_area_code",n).add("parent_area_type_id",PP.model.parentAreaType).add("group_id",t).add("child_area_type_id",AreaTypeIds.Practice),i=FT.url.corews+"api/all_data/csv/by_group_id?"+r.build());setUrl(i);logEvent("Download","Excel","AreaCode="+n)}function downloadPdf(){var n,t;try{FT.ajaxLock||(n=PP.model.practiceCode,n?(t=FT.url.pdf+"?CCG="+PP.model.parentCode+"&PracCode="+n,setUrl(t),logEvent("Download","PDF",n)):lightbox.show("Please select a practice",300,700,300))}catch(i){try{lightbox.show('<div>Please <a href="'+t+'">click here<\/a> to <br>download a practice<br>summary.<\/div>',300,500,160)}catch(i){setUrl(t)}}}function showMetadata(n,t,i){var u=getMetadataHtml(ui.getMetadataHashBySid(n)[t],null),e='<div style="padding:15px;">'+u.html+"<\/div>",f=800,o=($(window).width()-f)/2,r=200;isDefined(i)&&(r=$(i).parent().position().top-r);lightbox.show(e,r,o,f);labelAsync.populate(u.labelArgs)}function getCurrentSubgroup(){return PP.model.groupId}function getParentList(){var t=PP.model.parentAreaType,n;loaded.areaLists[t].length?ajaxMonitor.callCompleted():(n=new ParameterBuilder,n.add("area_type_id",t),n.add("profile_id",ProfileIds.PracticeProfiles),ajaxGet("api/areas/by_area_type",n.build(),function(n){isDefined(n)&&(loaded.areaLists[t]=n,populateParentMenu(n));ajaxMonitor.callCompleted()}))}function getPracticeAndParentLists(){getParentList();getPracticeList();getPracticeAddress()}function initYears(){var t,n;for(templates.add("years",'<table cellspacing="0"><tr><td onclick="yearClicked({{first}})" class="firstYearLine"><\/td>{{#middleYears}}<td class="yearLine" onclick="yearClicked({{year}})"><\/td>{{/middleYears}}<td class="lastYearLine" onclick="yearClicked({{last}})"><\/td><\/tr><tr><td id="timeline" colspan="{{yearCount}}">TIMELINE<div id="info-timeline" class="info-tooltip" onclick="getHelpText(\'timeline\',200,lightbox.leftForMiddle(410),410)" title="More information about this timeline"><\/div><\/td><\/tr><\/table>'),t=[],n=earliestYear+1;n<latestYear;n++)t.push({year:n});$("#yearBox").html(templates.render("years",{middleYears:t,first:earliestYear,last:latestYear,yearCount:latestYear-earliestYear+1}));displayCurrentYear()}function displayCurrentYear(){var t=PP.model.year,f=t-earliestYear,n="selectedYearLine",u="Last",i=n,r;t==earliestYear?i+="First":t==latestYear&&(i+=u);r=$("#yearBox TR:eq(0) TD");r.removeClass(n+" "+n+"First "+n+u);$(r[f]).addClass(i)}function displayPracticeHeading(){$("#practiceHeading").css("color",PP.model.parentCode?"#333":"#fff")}function setPopulationModeIfDataPageNotDisplayed(){(PP.model.mode===PAGE_MODES.SELECT||PP.model.mode===PAGE_MODES.METADATA)&&(PP.model.mode=PAGE_MODES.POPULATION)}function showSpinnerIfNoPopulation(){var n=PP.model.practiceCode,t;isDefined(n)&&(t=loaded.population[PP.model.year][n],isDefined(t)||showSpinner())}function populateParentMenu(n){var r=ID_PARENT_AREA_MENU,t=$(r),i=PP.model;populateAreaMenu(n,t,"SELECT A CCG >>");selectCodeInMenu(r,i.parentCode);t.show();t.chosen({search_contains:!0});t.change(function(){var n,r;lock();n=t.find("option:selected").val();i.parentCode=n===NULL_OPTION?null:n;i.practiceCode=ui.getPreferredPractice();ftHistory.setHistory();ajaxMonitor.setCalls(1);getPracticeList();ajaxMonitor.monitor(goToCurrentPage);r=$("#all_ccg_practices");n!="-"?r.show():r.hide()})}function getHelpText(n,t,i,r){if(!FT.ajaxLock){loaded.hasOwnProperty("content")||(loaded[u]={});var u=loaded[u];u.hasOwnProperty(n)?lightbox.show(u[n],t,i,r):(lightbox.show('<div class="ajax-loading"><img src="'+FT.url.img+'spinner.gif" alt=""/><\/div>',t,i,r),ajaxGet("api/content?","profile_id="+ProfileIds.PracticeProfiles+"&key="+n,function(t){lightbox.setHtml(t);u[n]=t},handleAjaxFailure))}}function showAllJQs(n){for(var t in allJQs)allJQs[t]!==n&&hideJQs(allJQs[t]);showJQs(n)}function TimePeriod(n,t,i){var u=t>0,n=n,r;u?r=t-i-1:i===0?(r=t-2,r<0&&(r=0)):n=null;this.isData=n&&n[r];this.label=this.isData?n[r]:NO_DATA;this.yearIndex=r}function MenuManager(){var t=".chosen-select",i="disabled",r=$("select"),u=function(u){n||(n=$(".chosen-drop"));r.not(t).attr(i,u);r.filter(t).attr(i,u).trigger("chosen:updated")},n;this.enableAll=function(){u(!1);n.show()};this.disableAll=function(){u(!0);n.hide()}}var populationState,NO_DATA,populationChart,scatterState,barChartState,barChart,practiceProfilesLegend,practiceSearchState;(function(){var n,r,t,i,u,f={}.hasOwnProperty,e=function(n,t){function r(){this.constructor=n}for(var i in t)f.call(t,i)&&(n[i]=t[i]);return r.prototype=t.prototype,n.prototype=new r,n.__super__=t.prototype,n};i=function(){function n(){this.options_index=0;this.parsed=[]}return n.prototype.add_node=function(n){return n.nodeName.toUpperCase()==="OPTGROUP"?this.add_group(n):this.add_option(n)},n.prototype.add_group=function(n){var i,f,t,e,r,u;for(i=this.parsed.length,this.parsed.push({array_index:i,group:!0,label:this.escapeExpression(n.label),title:n.title?n.title:void 0,children:0,disabled:n.disabled,classes:n.className}),r=n.childNodes,u=[],t=0,e=r.length;t<e;t++)f=r[t],u.push(this.add_option(f,i,n.disabled));return u},n.prototype.add_option=function(n,t,i){if(n.nodeName.toUpperCase()==="OPTION")return n.text!==""?(t!=null&&(this.parsed[t].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:n.value,text:n.text,html:n.innerHTML,title:n.title?n.title:void 0,selected:n.selected,disabled:i===!0?i:n.disabled,group_array_index:t,group_label:t!=null?this.parsed[t].label:null,classes:n.className,style:n.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1},n.prototype.escapeExpression=function(n){var t,i;return n==null||n===!1?"":/[\&\<\>\"\'\`]/.test(n)?(t={"<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},i=/&(?!\w+;)|[\<\>\"\'\`]/g,n.replace(i,function(n){return t[n]||"&amp;"})):n},n}();i.select_to_array=function(n){var f,r,t,e,u;for(r=new i,u=n.childNodes,t=0,e=u.length;t<e;t++)f=u[t],r.add_node(f);return r.parsed};r=function(){function n(t,i){(this.form_field=t,this.options=i!=null?i:{},n.browser_is_supported())&&(this.is_multiple=this.form_field.multiple,this.set_default_text(),this.set_default_values(),this.setup(),this.set_up_html(),this.register_observers(),this.on_ready())}return n.prototype.set_default_values=function(){var n=this;return this.click_test_action=function(t){return n.test_active_click(t)},this.activate_action=function(t){return n.activate_field(t)},this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.allow_single_deselect=this.options.allow_single_deselect!=null&&this.form_field.options[0]!=null&&this.form_field.options[0].text===""?this.options.allow_single_deselect:!1,this.disable_search_threshold=this.options.disable_search_threshold||0,this.disable_search=this.options.disable_search||!1,this.enable_split_word_search=this.options.enable_split_word_search!=null?this.options.enable_split_word_search:!0,this.group_search=this.options.group_search!=null?this.options.group_search:!0,this.search_contains=this.options.search_contains||!1,this.single_backstroke_delete=this.options.single_backstroke_delete!=null?this.options.single_backstroke_delete:!0,this.max_selected_options=this.options.max_selected_options||Infinity,this.inherit_select_classes=this.options.inherit_select_classes||!1,this.display_selected_options=this.options.display_selected_options!=null?this.options.display_selected_options:!0,this.display_disabled_options=this.options.display_disabled_options!=null?this.options.display_disabled_options:!0,this.include_group_label_in_selected=this.options.include_group_label_in_selected||!1,this.max_shown_results=this.options.max_shown_results||Number.POSITIVE_INFINITY,this.case_sensitive_search=this.options.case_sensitive_search||!1},n.prototype.set_default_text=function(){return this.default_text=this.form_field.getAttribute("data-placeholder")?this.form_field.getAttribute("data-placeholder"):this.is_multiple?this.options.placeholder_text_multiple||this.options.placeholder_text||n.default_multiple_text:this.options.placeholder_text_single||this.options.placeholder_text||n.default_single_text,this.results_none_found=this.form_field.getAttribute("data-no_results_text")||this.options.no_results_text||n.default_no_result_text},n.prototype.choice_label=function(n){return this.include_group_label_in_selected&&n.group_label!=null?"<b class='group-name'>"+n.group_label+"<\/b>"+n.html:n.html},n.prototype.mouse_enter=function(){return this.mouse_on_container=!0},n.prototype.mouse_leave=function(){return this.mouse_on_container=!1},n.prototype.input_focus=function(){var n=this;if(this.is_multiple){if(!this.active_field)return setTimeout(function(){return n.container_mousedown()},50)}else if(!this.active_field)return this.activate_field()},n.prototype.input_blur=function(){var n=this;if(!this.mouse_on_container)return this.active_field=!1,setTimeout(function(){return n.blur_test()},100)},n.prototype.results_option_build=function(n){var u,t,i,f,r,o,e;for(u="",f=0,e=this.results_data,r=0,o=e.length;r<o;r++)if(t=e[r],i="",i=t.group?this.result_add_group(t):this.result_add_option(t),i!==""&&(f++,u+=i),(n!=null?n.first:void 0)&&(t.selected&&this.is_multiple?this.choice_build(t):t.selected&&!this.is_multiple&&this.single_set_selected_text(this.choice_label(t))),f>=this.max_shown_results)break;return u},n.prototype.result_add_option=function(n){var t,i;return n.search_match?this.include_option_in_results(n)?(t=[],n.disabled||n.selected&&this.is_multiple||t.push("active-result"),!n.disabled||n.selected&&this.is_multiple||t.push("disabled-result"),n.selected&&t.push("result-selected"),n.group_array_index!=null&&t.push("group-option"),n.classes!==""&&t.push(n.classes),i=document.createElement("li"),i.className=t.join(" "),i.style.cssText=n.style,i.setAttribute("data-option-array-index",n.array_index),i.innerHTML=n.search_text,n.title&&(i.title=n.title),this.outerHTML(i)):"":""},n.prototype.result_add_group=function(n){var i,t;return n.search_match||n.group_match?n.active_options>0?(i=[],i.push("group-result"),n.classes&&i.push(n.classes),t=document.createElement("li"),t.className=i.join(" "),t.innerHTML=n.search_text,n.title&&(t.title=n.title),this.outerHTML(t)):"":""},n.prototype.results_update_field=function(){return this.set_default_text(),this.is_multiple||this.results_reset_cleanup(),this.result_clear_highlight(),this.results_build(),this.results_showing?this.winnow_results():void 0},n.prototype.reset_single_select_options=function(){var i,n,u,r,t;for(r=this.results_data,t=[],n=0,u=r.length;n<u;n++)i=r[n],i.selected?t.push(i.selected=!1):t.push(void 0);return t},n.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},n.prototype.results_search=function(){return this.results_showing?this.winnow_results():this.results_show()},n.prototype.winnow_results=function(){var e,n,h,u,t,i,r,o,c,f,l,s;for(this.no_results_clear(),u=0,i=this.get_search_text(),e=i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),c=new RegExp(e,"i"),h=this.get_search_regex(e),s=this.results_data,f=0,l=s.length;f<l;f++)n=s[f],n.search_match=!1,t=null,this.include_option_in_results(n)&&(n.group&&(n.group_match=!1,n.active_options=0),n.group_array_index!=null&&this.results_data[n.group_array_index]&&(t=this.results_data[n.group_array_index],t.active_options===0&&t.search_match&&(u+=1),t.active_options+=1),n.search_text=n.group?n.label:n.html,n.group&&!this.group_search||(n.search_match=this.search_string_match(n.search_text,h),n.search_match&&!n.group&&(u+=1),n.search_match?(i.length&&(r=n.search_text.search(c),o=n.search_text.substr(0,r+i.length)+"<\/em>"+n.search_text.substr(r+i.length),n.search_text=o.substr(0,r)+"<em>"+o.substr(r)),t!=null&&(t.group_match=!0)):n.group_array_index!=null&&this.results_data[n.group_array_index].search_match&&(n.search_match=!0)));return this.result_clear_highlight(),u<1&&i.length?(this.update_results_content(""),this.no_results(i)):(this.update_results_content(this.results_option_build()),this.winnow_results_set_highlight())},n.prototype.get_search_regex=function(n){var t,i;return t=this.search_contains?"":"^",i=this.case_sensitive_search?"":"i",new RegExp(t+n,i)},n.prototype.search_string_match=function(n,t){var u,i,r,f;if(t.test(n))return!0;if(this.enable_split_word_search&&(n.indexOf(" ")>=0||n.indexOf("[")===0)&&(i=n.replace(/\[|\]/g,"").split(" "),i.length))for(r=0,f=i.length;r<f;r++)if(u=i[r],t.test(u))return!0},n.prototype.choices_count=function(){var i,n,r,t;if(this.selected_option_count!=null)return this.selected_option_count;for(this.selected_option_count=0,t=this.form_field.options,n=0,r=t.length;n<r;n++)i=t[n],i.selected&&(this.selected_option_count+=1);return this.selected_option_count},n.prototype.choices_click=function(n){return n.preventDefault(),this.results_showing||this.is_disabled?void 0:this.results_show()},n.prototype.keyup_checker=function(n){var t,i;t=(i=n.which)!=null?i:n.keyCode;this.search_field_scale();switch(t){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices_count()>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:if(n.preventDefault(),this.results_showing)return this.result_select(n);break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:case 18:break;default:return this.results_search()}},n.prototype.clipboard_event_checker=function(){var n=this;return setTimeout(function(){return n.results_search()},50)},n.prototype.container_width=function(){return this.options.width!=null?this.options.width:""+this.form_field.offsetWidth+"px"},n.prototype.include_option_in_results=function(n){return this.is_multiple&&!this.display_selected_options&&n.selected?!1:!this.display_disabled_options&&n.disabled?!1:n.empty?!1:!0},n.prototype.search_results_touchstart=function(n){return this.touch_started=!0,this.search_results_mouseover(n)},n.prototype.search_results_touchmove=function(n){return this.touch_started=!1,this.search_results_mouseout(n)},n.prototype.search_results_touchend=function(n){if(this.touch_started)return this.search_results_mouseup(n)},n.prototype.outerHTML=function(n){var t;return n.outerHTML?n.outerHTML:(t=document.createElement("div"),t.appendChild(n),t.innerHTML)},n.browser_is_supported=function(){return"Microsoft Internet Explorer"===window.navigator.appName?document.documentMode>=8:/iP(od|hone)/i.test(window.navigator.userAgent)||/IEMobile/i.test(window.navigator.userAgent)||/Windows Phone/i.test(window.navigator.userAgent)||/BlackBerry/i.test(window.navigator.userAgent)||/BB10/i.test(window.navigator.userAgent)||/Android.*Mobile/i.test(window.navigator.userAgent)?!1:!0},n.default_multiple_text="Select Some Options",n.default_single_text="Select an Option",n.default_no_result_text="No results match",n}();n=jQuery;n.fn.extend({chosen:function(i){return r.browser_is_supported()?this.each(function(){var u,r;if(u=n(this),r=u.data("chosen"),i==="destroy"){r instanceof t&&r.destroy();return}r instanceof t||u.data("chosen",new t(this,i))}):this}});t=function(t){function r(){return u=r.__super__.constructor.apply(this,arguments)}return e(r,t),r.prototype.setup=function(){return this.form_field_jq=n(this.form_field),this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field_jq.hasClass("chosen-rtl")},r.prototype.set_up_html=function(){var t,i;return t=["chosen-container"],t.push("chosen-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&t.push(this.form_field.className),this.is_rtl&&t.push("chosen-rtl"),i={"class":t.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.form_field.id.length&&(i.id=this.form_field.id.replace(/[^\w]/g,"_")+"_chosen"),this.container=n("<div />",i),this.is_multiple?this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="'+this.default_text+'" class="default" autocomplete="off" style="width:25px;" /><\/li><\/ul><div class="chosen-drop"><ul class="chosen-results"><\/ul><\/div>'):this.container.html('<a class="chosen-single chosen-default"><span>'+this.default_text+'<\/span><div><b><\/b><\/div><\/a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /><\/div><ul class="chosen-results"><\/ul><\/div>'),this.form_field_jq.hide().after(this.container),this.dropdown=this.container.find("div.chosen-drop").first(),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chosen-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chosen-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chosen-search").first(),this.selected_item=this.container.find(".chosen-single").first()),this.results_build(),this.set_tab_index(),this.set_label_behavior()},r.prototype.on_ready=function(){return this.form_field_jq.trigger("chosen:ready",{chosen:this})},r.prototype.register_observers=function(){var n=this;return this.container.bind("touchstart.chosen",function(t){return n.container_mousedown(t),t.preventDefault()}),this.container.bind("touchend.chosen",function(t){return n.container_mouseup(t),t.preventDefault()}),this.container.bind("mousedown.chosen",function(t){n.container_mousedown(t)}),this.container.bind("mouseup.chosen",function(t){n.container_mouseup(t)}),this.container.bind("mouseenter.chosen",function(t){n.mouse_enter(t)}),this.container.bind("mouseleave.chosen",function(t){n.mouse_leave(t)}),this.search_results.bind("mouseup.chosen",function(t){n.search_results_mouseup(t)}),this.search_results.bind("mouseover.chosen",function(t){n.search_results_mouseover(t)}),this.search_results.bind("mouseout.chosen",function(t){n.search_results_mouseout(t)}),this.search_results.bind("mousewheel.chosen DOMMouseScroll.chosen",function(t){n.search_results_mousewheel(t)}),this.search_results.bind("touchstart.chosen",function(t){n.search_results_touchstart(t)}),this.search_results.bind("touchmove.chosen",function(t){n.search_results_touchmove(t)}),this.search_results.bind("touchend.chosen",function(t){n.search_results_touchend(t)}),this.form_field_jq.bind("chosen:updated.chosen",function(t){n.results_update_field(t)}),this.form_field_jq.bind("chosen:activate.chosen",function(t){n.activate_field(t)}),this.form_field_jq.bind("chosen:open.chosen",function(t){n.container_mousedown(t)}),this.form_field_jq.bind("chosen:close.chosen",function(t){n.input_blur(t)}),this.search_field.bind("blur.chosen",function(t){n.input_blur(t)}),this.search_field.bind("keyup.chosen",function(t){n.keyup_checker(t)}),this.search_field.bind("keydown.chosen",function(t){n.keydown_checker(t)}),this.search_field.bind("focus.chosen",function(t){n.input_focus(t)}),this.search_field.bind("cut.chosen",function(t){n.clipboard_event_checker(t)}),this.search_field.bind("paste.chosen",function(t){n.clipboard_event_checker(t)}),this.is_multiple?this.search_choices.bind("click.chosen",function(t){n.choices_click(t)}):this.container.bind("click.chosen",function(n){n.preventDefault()})},r.prototype.destroy=function(){return n(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.search_field[0].tabIndex&&(this.form_field_jq[0].tabIndex=this.search_field[0].tabIndex),this.container.remove(),this.form_field_jq.removeData("chosen"),this.form_field_jq.show()},r.prototype.search_field_disabled=function(){return(this.is_disabled=this.form_field_jq[0].disabled,this.is_disabled)?(this.container.addClass("chosen-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus.chosen",this.activate_action),this.close_field()):(this.container.removeClass("chosen-disabled"),this.search_field[0].disabled=!1,!this.is_multiple)?this.selected_item.bind("focus.chosen",this.activate_action):void 0},r.prototype.container_mousedown=function(t){if(!this.is_disabled&&(t&&t.type==="mousedown"&&!this.results_showing&&t.preventDefault(),!(t!=null&&n(t.target).hasClass("search-choice-close"))))return this.active_field?!this.is_multiple&&t&&(n(t.target)[0]===this.selected_item[0]||n(t.target).parents("a.chosen-single").length)&&(t.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),n(this.container[0].ownerDocument).bind("click.chosen",this.click_test_action),this.results_show()),this.activate_field()},r.prototype.container_mouseup=function(n){if(n.target.nodeName==="ABBR"&&!this.is_disabled)return this.results_reset(n)},r.prototype.search_results_mousewheel=function(n){var t;return n.originalEvent&&(t=n.originalEvent.deltaY||-n.originalEvent.wheelDelta||n.originalEvent.detail),t!=null?(n.preventDefault(),n.type==="DOMMouseScroll"&&(t=t*40),this.search_results.scrollTop(t+this.search_results.scrollTop())):void 0},r.prototype.blur_test=function(){if(!this.active_field&&this.container.hasClass("chosen-container-active"))return this.close_field()},r.prototype.close_field=function(){return n(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClass("chosen-container-active"),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},r.prototype.activate_field=function(){return this.container.addClass("chosen-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},r.prototype.test_active_click=function(t){var i;return i=n(t.target).closest(".chosen-container"),i.length&&this.container[0]===i[0]?this.active_field=!0:this.close_field()},r.prototype.results_build=function(){return this.parsing=!0,this.selected_option_count=null,this.results_data=i.select_to_array(this.form_field),this.is_multiple?this.search_choices.find("li.search-choice").remove():this.is_multiple||(this.single_set_selected_text(),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?(this.search_field[0].readOnly=!0,this.container.addClass("chosen-container-single-nosearch")):(this.search_field[0].readOnly=!1,this.container.removeClass("chosen-container-single-nosearch"))),this.update_results_content(this.results_option_build({first:!0})),this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.parsing=!1},r.prototype.result_do_highlight=function(n){var t,i,r,f,u;if(n.length){if(this.result_clear_highlight(),this.result_highlight=n,this.result_highlight.addClass("highlighted"),r=parseInt(this.search_results.css("maxHeight"),10),u=this.search_results.scrollTop(),f=r+u,i=this.result_highlight.position().top+this.search_results.scrollTop(),t=i+this.result_highlight.outerHeight(),t>=f)return this.search_results.scrollTop(t-r>0?t-r:0);if(i<u)return this.search_results.scrollTop(i)}},r.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClass("highlighted"),this.result_highlight=null},r.prototype.results_show=function(){return this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.container.addClass("chosen-with-drop"),this.results_showing=!0,this.search_field.focus(),this.search_field.val(this.search_field.val()),this.winnow_results(),this.form_field_jq.trigger("chosen:showing_dropdown",{chosen:this}))},r.prototype.update_results_content=function(n){return this.search_results.html(n)},r.prototype.results_hide=function(){return this.results_showing&&(this.result_clear_highlight(),this.container.removeClass("chosen-with-drop"),this.form_field_jq.trigger("chosen:hiding_dropdown",{chosen:this})),this.results_showing=!1},r.prototype.set_tab_index=function(){var n;if(this.form_field.tabIndex)return n=this.form_field.tabIndex,this.form_field.tabIndex=-1,this.search_field[0].tabIndex=n},r.prototype.set_label_behavior=function(){var t=this;return this.form_field_label=this.form_field_jq.parents("label"),!this.form_field_label.length&&this.form_field.id.length&&(this.form_field_label=n("label[for='"+this.form_field.id+"']")),this.form_field_label.length>0?this.form_field_label.bind("click.chosen",function(n){return t.is_multiple?t.container_mousedown(n):t.activate_field()}):void 0},r.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices_count()<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},r.prototype.search_results_mouseup=function(t){var i;return i=n(t.target).hasClass("active-result")?n(t.target):n(t.target).parents(".active-result").first(),i.length?(this.result_highlight=i,this.result_select(t),this.search_field.focus()):void 0},r.prototype.search_results_mouseover=function(t){var i;return i=n(t.target).hasClass("active-result")?n(t.target):n(t.target).parents(".active-result").first(),i?this.result_do_highlight(i):void 0},r.prototype.search_results_mouseout=function(t){if(n(t.target).hasClass("active-result"||n(t.target).parents(".active-result").first()))return this.result_clear_highlight()},r.prototype.choice_build=function(t){var i,r,u=this;return i=n("<li />",{"class":"search-choice"}).html("<span>"+this.choice_label(t)+"<\/span>"),t.disabled?i.addClass("search-choice-disabled"):(r=n("<a />",{"class":"search-choice-close","data-option-array-index":t.array_index}),r.bind("click.chosen",function(n){return u.choice_destroy_link_click(n)}),i.append(r)),this.search_container.before(i)},r.prototype.choice_destroy_link_click=function(t){return t.preventDefault(),t.stopPropagation(),this.is_disabled?void 0:this.choice_destroy(n(t.target))},r.prototype.choice_destroy=function(n){if(this.result_deselect(n[0].getAttribute("data-option-array-index")))return this.show_search_field_default(),this.is_multiple&&this.choices_count()>0&&this.search_field.val().length<1&&this.results_hide(),n.parents("li").first().remove(),this.search_field_scale()},r.prototype.results_reset=function(){return this.reset_single_select_options(),this.form_field.options[0].selected=!0,this.single_set_selected_text(),this.show_search_field_default(),this.results_reset_cleanup(),this.form_field_jq.trigger("change"),this.active_field?this.results_hide():void 0},r.prototype.results_reset_cleanup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.selected_item.find("abbr").remove()},r.prototype.result_select=function(n){var i,t;if(this.result_highlight)return(i=this.result_highlight,this.result_clear_highlight(),this.is_multiple&&this.max_selected_options<=this.choices_count())?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.is_multiple?i.removeClass("active-result"):this.reset_single_select_options(),i.addClass("result-selected"),t=this.results_data[i[0].getAttribute("data-option-array-index")],t.selected=!0,this.form_field.options[t.options_index].selected=!0,this.selected_option_count=null,this.is_multiple?this.choice_build(t):this.single_set_selected_text(this.choice_label(t)),(n.metaKey||n.ctrlKey)&&this.is_multiple||this.results_hide(),this.show_search_field_default(),(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.form_field_jq.trigger("change",{selected:this.form_field.options[t.options_index].value}),this.current_selectedIndex=this.form_field.selectedIndex,n.preventDefault(),this.search_field_scale())},r.prototype.single_set_selected_text=function(n){return n==null&&(n=this.default_text),n===this.default_text?this.selected_item.addClass("chosen-default"):(this.single_deselect_control_build(),this.selected_item.removeClass("chosen-default")),this.selected_item.find("span").html(n)},r.prototype.result_deselect=function(n){var t;return t=this.results_data[n],this.form_field.options[t.options_index].disabled?!1:(t.selected=!1,this.form_field.options[t.options_index].selected=!1,this.selected_option_count=null,this.result_clear_highlight(),this.results_showing&&this.winnow_results(),this.form_field_jq.trigger("change",{deselected:this.form_field.options[t.options_index].value}),this.search_field_scale(),!0)},r.prototype.single_deselect_control_build=function(){if(this.allow_single_deselect)return this.selected_item.find("abbr").length||this.selected_item.find("span").first().after('<abbr class="search-choice-close"><\/abbr>'),this.selected_item.addClass("chosen-single-with-deselect")},r.prototype.get_search_text=function(){return n("<div/>").text(n.trim(this.search_field.val())).html()},r.prototype.winnow_results_set_highlight=function(){var n,t;return t=this.is_multiple?[]:this.search_results.find(".result-selected.active-result"),n=t.length?t.first():this.search_results.find(".active-result").first(),n!=null?this.result_do_highlight(n):void 0},r.prototype.no_results=function(t){var i;return i=n('<li class="no-results">'+this.results_none_found+' "<span><\/span>"<\/li>'),i.find("span").first().html(t),this.search_results.append(i),this.form_field_jq.trigger("chosen:no_results",{chosen:this})},r.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},r.prototype.keydown_arrow=function(){var n;if(this.results_showing&&this.result_highlight){if(n=this.result_highlight.nextAll("li.active-result").first(),n)return this.result_do_highlight(n)}else return this.results_show()},r.prototype.keyup_arrow=function(){var n;if(this.results_showing||this.is_multiple){if(this.result_highlight)return n=this.result_highlight.prevAll("li.active-result"),n.length?this.result_do_highlight(n.first()):(this.choices_count()>0&&this.results_hide(),this.result_clear_highlight())}else return this.results_show()},r.prototype.keydown_backstroke=function(){var n;return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(n=this.search_container.siblings("li.search-choice").last(),n.length&&!n.hasClass("search-choice-disabled"))?(this.pending_backstroke=n,this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClass("search-choice-focus")):void 0},r.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},r.prototype.keydown_checker=function(n){var t,i;t=(i=n.which)!=null?i:n.keyCode;this.search_field_scale();t!==8&&this.pending_backstroke&&this.clear_backstroke();switch(t){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(n);this.mouse_on_container=!1;break;case 13:this.results_showing&&n.preventDefault();break;case 32:this.disable_search&&n.preventDefault();break;case 38:n.preventDefault();this.keyup_arrow();break;case 40:n.preventDefault();this.keydown_arrow()}},r.prototype.search_field_scale=function(){var t,u,h,f,e,o,i,r,s;if(this.is_multiple){for(h=0,i=0,e="position:absolute; left: -1000px; top: -1000px; display:none;",o=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"],r=0,s=o.length;r<s;r++)f=o[r],e+=f+":"+this.search_field.css(f)+";";return t=n("<div />",{style:e}),t.text(this.search_field.val()),n("body").append(t),i=t.width()+25,t.remove(),u=this.container.outerWidth(),i>u-10&&(i=u-10),this.search_field.css({width:i+"px"})}},r}(r)}).call(this);"use strict";var metadata={},metadataState={yearTypeId:null,_displayedKey:"",redisplay:function(n,t){var i=getKey(n,t);return i!==this._displayedKey},setDisplayedKey:function(n,t){this._displayedKey=getKey(n,t)}},labelAsync=function(){var n=function(n,t,i){n[t]&&ajaxGet("api/"+t.replace("-","_")+"?","id="+n[t],function(n){isDefined(n)&&(loaded[i][n.Id]=n.Name,$("#"+t+"-label").html(n.Name))})};return{getLabel:function(n,t,i,r){return n<=0?NOT_APPLICABLE:t.hasOwnProperty(n)?t[n]:(r[i]=n,getLabelSpan(i))},populate:function(t){n(t,"comparator-method","comparatorMethods")}}}();templates.add("metadata",'<div id="definition-table"><h2>Indicator Definitions and Supporting Information<\/h2><table class="bordered-table" cellspacing="0"><tr><td class="header">Indicator ID<\/td><td>{{iid}}<\/td><\/tr>{{#rows}}<tr><td class="header">{{0}}<\/td><td>{{{1}}}<\/td><\/tr>{{/rows}}<\/table><\/div>');pages.add(PAGE_MODES.METADATA,{id:"metadata",title:"Definitions",goto:goToMetadataPage,gotoName:"goToMetadataPage",needsContainer:!0,jqIds:["indicator-menu-div","areaTypeBox"]});populationState={_displayedKey:"",lastDecile:"",getKey:function(){var n=PP.model,t=n.parentCode,i=n.practiceCode;return(t?t:"-")+(i?i:"-")+n.year},redrawChart:function(){return this._displayedKey!==this.getKey()},setDisplayedKey:function(){this._displayedKey=this.getKey()},displayPageElements:function(){showAndHidePageElements();var n=$("#population-info");populationState.isAnyPopulation()?n.show():n.hide()},isAnyPopulation:function(){var n=PP.data.currentPracticePopulation;return n&&n.hasOwnProperty("ListSize")}};PopulationNumber.prototype={isData:function(){return this.data&&this.data.Val>0},val:function(){return this.isData()?new CommaNumber(this.data.Val).rounded():null}};NO_DATA='<div class="noData">-<\/div>';templates.add("furtherInfo",'{{#rows}}<tr><td class="header info">{{#iid}}<div class="fl info-tooltip" onclick="showMetadata(populationGroupId,{{iid}})"><\/div>{{/iid}}{{name}}<\/td><td>{{val}}{{^val}}'+NO_DATA+'{{/val}}{{#average}} <span class="averageLabel">(average)<\/span>{{/average}}<\/td><\/tr>{{/rows}}');"use strict";var spineChartState={displayedSubgroupId:null,_displayedPractice:"-",displayedBenchmarks:{},createdSubgroups:[],tooltipProvider:null,markerIds:[],markerValues:{},refreshPracticeLabel:function(){return PP.model.practiceCode!==this._displayPractice},setDisplayedPractice:function(){this._displayPractice=PP.model.practiceCode},isSubgroupDisplayed:function(n){return n!==null&&this.getId(n)===this.displayedSubgroupId},doesSubgroupTableExist:function(n){return $.inArray(this.getId(n),this.createdSubgroups)>-1},getTableId:function(n){return"st"+this.getId(n)},getJq:function(n){return $("#"+this.getTableId(n))},hideDisplayedTable:function(){var n=this.displayedSubgroupId;n!==null&&($("#st"+n).hide(),this.displayedSubgroupId=null)},setDisplayedSubgroupId:function(n){this.displayedSubgroupId=this.getId(n)},addSubgroup:function(n){this.createdSubgroups.push(this.getId(n))},showTable:function(n){this.getJq(n).show()},getId:function(n){return n!==null?getYearOffset().toString()+n.toString():""},isBenchmarkDisplayed:function(n,t){var i=this.displayedBenchmarks[this.getId(n)];return isDefined(i)?i===t:!1},setDisplayedBenchmark:function(n,t){var i=this.getId(n);this.displayedBenchmarks[i]=t}},changeManager={changeValues:[],changeIds:[],changeIndex:0,getValF:function(n){return this.changeValues[n]},newImage:function(n,t){var i="ch_"+this.changeIndex+"_"+n;return this.changeValues.push(t),this.changeIds.push(i),this.changeIndex++,i},initChangeTooltips:function(){for(var n in this.changeIds)tooltipManager.initElement(this.changeIds[n]);this.changeIds=[]},getChangeText:function(n,t){var r=PP.model.groupId,u=t[1],f=t[2],i=loaded.indicatorMetadata[r][f];return["<i>Significantly different to previous year (",this.changeValues[u],getUnitLabel(i),")<\/i><br><b>",i.Descriptive.Name,"<\/b>"].join("")}},PPTooltipProvider=function(n){var t={};this.add=function(n,i){t[n.toString()]=i};this.getHtml=function(n){if(n!==""){var t=n.split("_");return t[0]==="ch"?changeManager.getChangeText(n,t):this.getChartText(n,t)}return""};this.getChartText=function(i,r){var o=r[0],l=r[1],s=o==="m",f,u,e,h,c;try{f=t[l+"_"+r[2]]}catch(a){}return u=[],isDefined(f)&&(u.push('<span id="tooltipData">'),u.push(s?spineChartState.markerValues[i]:n.getStemText(o,f)),u.push(f.getSuffixIfNoShort(),"<\/span>"),s||u.push(n.getStemQualifier(o)),u.push('<span id="tooltipArea">'),s?r[3]=="p"?e=getPracticeLabel():(h=getBenchmarkId(),h==BENCHMARKS.DEPRIVATION?(c=PP.data.currentPracticePopulation.GpDeprivationDecile,e=labels[LABELS_DEPRIVATION][c]):e=h==BENCHMARKS.CCG?getPracticeParentName():$("#benchmarkMenu option:selected").text()):e="England",u.push(e,'<\/span><span id="tooltipIndicator">',f.getIndicatorName(),"<\/span>")),u.join("")}};scatterState={indicatorMenuSubgroupId:null,rootIndexes:{},isSubgroup2MenuPopulated:!1,parent:"",practice:"",indicator2DefaultIndex:1,doParentUpdate:function(n){return!isDefined(PP.model.parentCode)||n!==this.parent},doPracticeUpdate:function(n){return!isDefined(PP.model.practiceCode)||n!==this.practice},setParentCode:function(n){this.parent=n},setPracticeCode:function(n){this.practice=n},setPreferredGroupRoot:function(n){var t=PP.model.groupId2;this.rootIndexes[t]=n},getPreferredGroupRoot:function(){var n=PP.model.groupId2;return ui._getValidRootIndex(this.rootIndexes[n])},doIndicatorRepopulate:function(){return this.indicatorMenuSubgroupId===null||this.indicatorMenuSubgroupId!=PP.model.groupId2},setIndicatorMenuSubgroupId:function(){this.indicatorMenuSubgroupId=PP.model.groupId2}};barChartState={isInitialised:!1,displayedAreaValues:null,displayedUnit:null,scrollTop:null,_displayedKey:"",_lastSortKey:"",sortType:2,sortDirection:1,practiceList:null,sortOptions:[{id:2,label:"Indicator Value",extraClass:"page-selected",defaultOrder:1},{id:0,label:"Practice Name",defaultOrder:0},{id:1,label:"Practice Code",defaultOrder:0}],resetSort:function(){this.sortType=0;this.sortDirection=0},setSortType:function(n){this.sortDirection=this.sortType==n?Math.abs(this.sortDirection-1):_.find(this.sortOptions,function(t){return t.id===n}).defaultOrder;this.sortType=n},_getSortKey:function(){return this.sortType+"-"+this.sortDirection},setSortKey:function(){this._lastSortKey=this._getSortKey()},doResort:function(){return this._lastSortKey!=this._getSortKey()},getAreaValueKey:function(n,t){return[t,n,PP.model.groupId,PP.model.year].join("-")},setAreaValues:function(n,t){var i=this.getAreaValueKey(ui.getSelectedRootIndex(),n);loaded.areaValues[i]=t},getAreaValues:function(n,t){var i=this.getAreaValueKey(t,n);return loaded.areaValues[i]},getKey:function(n){var t=PP.model.parentCode===null?"-":PP.model.parentCode,i=this.getAreaValueKey(n,t);return i+(PP.model.practiceCode===null?"-":PP.model.practiceCode)},recreateChart:function(n){var t=this.getKey(n);return t!==this._displayedKey},setDisplayedKey:function(n){this._displayedKey=this.getKey(n)}};practiceProfilesLegend='<div class="legends" style="position: relative; top: 10px;">    <table id="barChartKeyTable">    <tr><td style="background-color: #682EE3;" class="key">&nbsp;<\/td><td>Significantly different from England average<\/td><\/tr><tr><td style="background-color: #F5C720;" class="key">&nbsp;<\/td>    <td>No significant difference from England average<\/td><\/tr><tr><td style="background-color: #c9c9c9;" class="key">&nbsp;<\/td><td>Significance not calculated<\/td><\/tr>    <\/table><\/div>';templates.add("barChart",showExportChartLink()+practiceProfilesLegend+'<div id="sortPracticeBox" class="greyBoxed">Sort by:{{#options}}<a href="javascript:sortPracticesClicked({{id}});" id="sortPractice{{id}}" class="{{extraClass}} practiceSort page-selector" >{{label}}<\/a>{{/options}}<\/div><div id="barChart"><\/div><div id="noBarChart" class="selectLabel"><\/div>');templates.add("trends",'<div class="small-trend-box"><table class="bordered-table"><thead><tr><th colspan="4" class="indicator"><div class="indicator">{{name}}<div class="info-tooltip" onclick="showMetadata({{groupId}},{{iid}},this)"><\/div><\/div><\/th><\/tr><tr><th>Period<\/th><th>{{practice}}<\/th><th>{{benchmark}}<\/th><th>England<\/th><\/tr><\/thead><\/tbody>{{#rows}}<tr><td>{{0}}<\/td><td>{{& 1}}<\/td><td>{{& 2}}<\/td><td>{{& 3}}<\/td><\/tr>{{/rows}}<\/tbody><\/table><div id="trendChart{{index}}"><\/div><\/div>');practiceSearchState={displayedArea:null,selectedArea:null,practicesOnMap:[],showAllInCcg:null};loaded.nearbyPractices=[];templates.add("rows",'{{#rows}}<tr id="{{AreaCode}}-practice-header"><td colspan="2"><div class="header national clearfix">{{AreaCode}} - {{AreaName}}<\/div><\/td><\/tr><tr id="{{AreaCode}}-address"><td><div>{{AddressLine1}}<\/div><div>{{AddressLine2}}<\/div><div>{{Postcode}}<\/div><\/td><td><div class="center-text"><br>{{^showAllInCcg}}{{DistanceValF}} miles{{/showAllInCcg}}<\/div><div><a href="javascript:selectPractice(\'{{AreaCode}}\')">Select<\/a><\/div><\/td><\/tr><tr><td class="empty" colspan="2">&nbsp;<\/td><\/tr>{{/rows}}');templates.add("counter","<span>{{noOfPractices}}<\/span>");templates.add("searchNearHeader",'<h2 class="area_name">Practices near {{selectedArea}}<\/h2><h3 id="no-of-practices"><\/h3>');templates.add("searchCCGHeader",'<h2 class="area_name">The are {{practiceCount}} practices in {{selectedArea}}<\/h2>');templates.add("searchDefaultHeader",'<h3 class="area_name">Search above for a practice by postcode or place name. <\/h3>');templates.add("searchResults",'<table class="w100" cellspacing="0">{{#areas}}<tr id="{{Code}}-result"><td class="resultCode">{{Code}}<\/td><td class="result">{{Name}}, {{Address}}<\/td><\/tr>{{/areas}}<\/table>');clusterState={EDIT:0,NEW:1,LOGIN_REQUIRED:2,USER_CLUSTERS:3,isInitialised:!1,isEditMode:!1,clusterList:null,editOn:function(){this.isEditMode=!0},editOff:function(){this.isEditMode=!1},getTemplate:function(){switch(this.mode){case this.NEW:case this.EDIT:return"editCluster";case this.USER_CLUSTERS:return"userClusters";default:return"loginRequired"}}};templates.add("editCluster",'<h3>New cluster<\/h3>Create groups of practice, etc.<br>Name:<input id="clusterName" type="text" /><table id="clusterList"><\/table><input type="button" value="Save" class="link-button" onclick="saveCluster()"/><input class="link-button" type="button" value="Cancel" onclick="cancelClusterEdit()"/>');templates.add("loginRequired",'<h3 style="margin-left:10%;">Create your own practice clusters<\/h3><p style="margin-left:10%;width:80%;">Group practices together to view data for a limited number of practices at a time. Cluster indicator averages are calculated. You must be logged in to use.<\/p><br><input id="loginCluster" class="link-button" onclick="login();" value="Login">');templates.add("practiceList",'<tbody>{{#areas}}<tr><td style="vertical-align:top;padding: 0 6px 0 6px;"><div class="removeClusterItem" onclick="toggleClusterArea(\'{{Code}}\')"><\/div><\/td><td class="resultCode">{{Code}}<\/td><td class="result">{{Name}}, {{Address}}<\/td><\/tr>{{/areas}}{{^areas}}<tr><td>No assigned practices<\/td><\/tr>{{/areas}}<\/tbody>');templates.add("userClusters",'<h3>Your practice clusters<\/h3><ul id="clusterList">{{#clusters}}<li><a href="javascript:viewCluster(\'{{Id}}\');">{{Name}} ({{count}})<\/li>{{/clusters}}{{^clusters}}<li>You have no clusters<\/li>{{/clusters}}<\/ul><input style="float:left;clear:both;" type="button" class="link-button" onclick="setClusterMode(clusterState.NEW);" value="New">');"use strict";var PP={data:{}},download={},PAGE_MODES={SPINE:1,POPULATION:2,METADATA:3,SCATTER:4,BAR:5,SELECT:6,TRENDS:8},colours={better:"#92d050",same:"#ffc000",worse:"#c00000",none:"#ffffff",noComparison:"#c9c9c9",limit99:"#a8a8cc",limit95:"#444444",border:"#666666",comparator:"#000000",bobLower:"#5555E6",bobHigher:"#C2CCFF"},ui={_selects:null,practice:null,rootIndexes:{},indicatorMenuSubgroupId:null,callbackIds:{},displayedAddressCode:null,preferredPractices:{},_getParentKey:function(){return getKey(PP.model.parentAreaType)},setPreferredPractice:function(){var n=PP.model.parentCode;n!==null&&(this.preferredPractices[n]=PP.model.practiceCode)},getPreferredPractice:function(){var n=this.preferredPractices[PP.model.parentCode];return isDefined(n)?n:null},setPreferredGroupRoot:function(n){var t=PP.model.groupId;this.rootIndexes[t]=n},getPreferredGroupRoot:function(){var n=PP.model.groupId;return this._getValidRootIndex(this.rootIndexes[n])},getMetadataHash:function(){var n=PP.model.groupId;return loaded.indicatorMetadata[n]},getMetadataHashBySid:function(n){return loaded.indicatorMetadata[n]},getSelectedRootIndex:function(){return this._getValidRootIndex($("#indicatorMenu").find("option:selected").val())},_getValidRootIndex:function(n){return isDefined(n)||(n=0),n},getPractices:function(){return loaded.areaLists[AreaTypeIds.Practice][PP.model.parentCode]},getCurrentPractice:function(){var t=PP.model.practiceCode,n,i;if(!isDefined(this.practice)||this.practice.Code!==t)if(PP.model.parentCode===null)this.practice=loaded.addresses[t];else{n=this.getPractices();for(i in n)if(n[i].Code===t){this.practice=n[i];break}}return this.practice},getData:function(n){var t=PP.model.groupId,i=loaded.data;return i.hasOwnProperty(t)?i[t][n]:null},doIndicatorRepopulate:function(){return this.indicatorMenuSubgroupId===null||this.indicatorMenuSubgroupId!=PP.model.groupId},setIndicatorMenuSubgroupId:function(){this.indicatorMenuSubgroupId=PP.model.groupId}},BENCHMARKS={CCG:0,DEPRIVATION:1,PEER_GROUP:2},chartColours,CHART_TEXT_STYLE;PP.model={mode:null,year:null,parentAreaType:null,parentCode:null,practiceCode:null,groupId:null,indicator1:null,groupId2:null,indicator2:null,reset:function(){var n=PP.model;n.mode=PAGE_MODES.SELECT;n.year=latestYear;n.parentAreaType=AreaTypeIds.CCG;n.parentCode=null;n.practiceCode=null},restore:function(){var n=PP.model;n.reset();n._update();n.setupUI();ui.setPreferredPractice();goToCurrentPage()},setupUI:function(){setYear(PP.model.year);$("#subgroupMenu").val(PP.model.groupId);setAreaType(PP.model.parentAreaType)},_update:function(){var t=ftHistory.getKeyValuePairsFromHash(),n;_.size(t)&&(n=this,n.mode=parseInt(t.mod,10),t.pyr&&(n.year=t.pyr),n.parentAreaType=parseInt(t.pat,10),n.parentCode=n._parseVal(t.par),n.practiceCode=n._parseVal(t.are),n.groupId=n._parseVal(t.sid1),n.indicator1=n._parseIndicator(t.ind1),n.groupId2=n._parseVal(t.sid2),n.indicator2=n._parseIndicator(t.ind2))},_parseIndicator:function(n){if(n.length<2)return"-";var t=n.split("-");return{IID:t[0],SexId:t[1]}},_parseVal:function(n){return n==="-"?null:n},_valToString:function(n){return n===null?"-":n},toString:function(){var n=this._valToString(this.groupId),t=this._valToString(this.groupId2),i=this._getIndicatorKey(ui.getPreferredGroupRoot(),this.groupId),r=this._getIndicatorKey(scatterState.getPreferredGroupRoot(),this.groupId2),u=this._valToString(PP.model.parentCode),f=this._valToString(PP.model.practiceCode),e=["mod",PP.model.mode,"pyr",this.year,"pat",this.parentAreaType,"par",u,"are",f,"sid1",n,"ind1",i,"sid2",t,"ind2",r];return e.join(",")},_getIndicatorKey:function(n,t){var i,r;return isDefined(n)&&isDefined(t)&&(checkHash(loaded.data,t),i=loaded.data[t],i.hasOwnProperty(NATIONAL_CODE))?(r=i[NATIONAL_CODE][n],r.IID+"-"+r.Sex.Id):"-"},getRootIndex:function(n,t){var u=!1,i,r;if(n!=="-")for(i in t)if(r=t[i],r.IID===n.IID&&r.Sex.Id===n.SexId){u=!0;break}return u?i:0},isPractice:function(){return this.practiceCode!==null}};chartColours={label:"#333",bar:"#76B3B3",pink:"#FF66FC"};CHART_TEXT_STYLE={color:chartColours.label,fontWeight:"normal",fontFamily:"Verdana"};templates.add("export","<div id='popupTitle'><h2>Export Data<\/h2><\/div> <table class='export greyBoxed'><tr><td><b>Topic:<\/b><\/td><td> <select id='{{menuId}}'><\/select><\/td><\/tr><\/table> <table class='export greyBoxed'><tr><td colspan='2'><b>Practices:<\/b><\/td><\/tr><tr><td style='width:15px;'><input type='radio' name='g1' value='2' {{^isParent}}checked='checked'{{/isParent}}><\/td><td>All practices in England <\/td><\/tr><tr><td>{{#isParent}}<input type='radio' name='g1' value='1' {{^isPractice}}checked='checked'{{/isPractice}}><\/td><td>All practices in {{parent}}{{/isParent}}{{^isParent}}<\/td><td class='noDataText'>No {{parent}} selected{{/isParent}}<\/td><\/tr><\/table><div class='fl w100' style='padding:15px;padding-left:130px;clear:left;'><input type='button' class='exportBtn' onclick='exportData()' value='Export' /><input type='button' class='exportBtn' onclick='lightbox.hide()' value='Cancel' /><\/div>");loaded.population={};loaded.data={};loaded.valueLimits={};var MAIN="#main",ID_PARENT_AREA_MENU="#parentAreaMenu",ID_PRACTICE_MENU="#practiceMenu",NULL_OPTION_TEXT="...",NULL_OPTION="-",SEX_MALE=1,SEX_FEMALE=2,SEX_PERSON=4,SEARCH_NO_RESULT_TOP_OFFSET=27,NATIONAL_CODE="E92000001",labels={},changeIndex=0,lastDecile=null,CSS_NUMERIC="numeric",CSS_CENTER="center",CSS_VAL="value",nationalPopulation={},correctForPolarity=!1,stems,spineChartJQs,scatterJQs,trendsJQs,barJQs,metadataJQs,allJQs,chart=null,barChart=null;FT.ajaxLock=1;$(document).ready(documentReady)