﻿
function allIndicators_sortDropdownList(a,b){if(a.value<b.value)return-1;if(a.value>b.value)return 1;return 0;}
function allIndicators_indicatorsLoaded(doc){var nl=this.selectNodes("/indicators/i",doc);var out=[];for(var i=0;i<nl.length;i++){var priority=nl[i].getAttribute("priority");var strategy=nl[i].getAttribute("strategy");var instanceId=nl[i].getAttribute("instance-id");var tns=this.selectNodes("so",nl[i]);var theUrl="/whistler/site/indicator.acds?instanceid="+instanceId+"&context="+this.context;this.instances["i"+instanceId]={name:nl[i].getAttribute("name"),theUrl:theUrl};this.all.push(instanceId);if(priority){if(this.priorities[priority]){this.priorities[priority].push(instanceId);}else{this.priorities[priority]=[instanceId];}}
if(strategy){if(this.strategies[strategy]){this.strategies[strategy].push(instanceId);}else{this.strategies[strategy]=[instanceId];}}
if(tns.length>0){for(var j=0;j<tns.length;j++){var s=this.getNodeText(tns[j]);if(this.tns[s]){this.tns[s].push(instanceId);}else{this.tns[s]=[instanceId];}}}
var instanceId=nl[i].getAttribute("instance-id");var name=nl[i].getAttribute("name");}
var priorityList=[{value:null,label:"-- Please choose --"}];for(var v in this.priorities){priorityList.push({value:v,label:v});}
priorityList.sort(allIndicators_sortDropdownList);var strategyList=[{value:null,label:"-- Please choose --"}];for(var v in this.strategies){strategyList.push({value:v,label:v});}
strategyList.sort(allIndicators_sortDropdownList);var tnsList=[{value:null,label:"-- Please choose --"}];for(var v in this.tns){tnsList.push({value:v,label:v});}
tnsList.sort(allIndicators_sortDropdownList);var onchangeEvent="AS("+this.id+").show";this.getElementById("prioritiesPicker").innerHTML=this.renderDropdown("priorities",priorityList,{label:"Core Indicators by Priority",onchange:onchangeEvent+"('priorities')"});this.getElementById("strategiesPicker").innerHTML=this.renderDropdown("strategies",strategyList,{label:"Strategy Indicators by Strategy",onchange:onchangeEvent+"('strategies')"});this.getElementById("tnsPicker").innerHTML=this.renderDropdown("tns",tnsList,{label:"Sustainability Objective",onchange:onchangeEvent+"('tns')"});filterName=ASPEN.Cookie.get("whistlerIndicatorPickerFilterName");if(filterName!=null){if(filterName!="all"){this.field(filterName).value=ASPEN.Cookie.get("whistlerIndicatorPickerFilterValue");}
this.show(filterName);}}
function allIndicators_showAll(){this.show("all");}
function allIndicators_show(filterName){for(var s in this.filters){var picker=this.getElementById(s+"Picker");if(s!=filterName){if(s!="all"){this.field(s).selectedIndex=null;}
ASPEN.Element.removeClassName(picker,"pickerSelected");}else{ASPEN.Element.addClassName(picker,"pickerSelected");}}
var inds;var filterValueSelected="";var out=[];switch(filterName){case"all":inds=this.all;break;default:filterValueSelected=this.field(filterName).value;inds=this.filters[filterName][filterValueSelected];}
if(filterName=="tns"){var objectives=["ongoing build-up of substances taken from the earth's crust (e.g. renewable energy)","ongoing build-up of substances produced by society (e.g. non-toxic, biodegradable materials)","ongoing degradation of natural systems by physical means (e.g. sustainably harvested fish)","to undermining the ability of people to meet their human needs (e.g. fair wages)"]
if(filterName=="tns"){var str=objectives[parseInt(filterValueSelected.charAt(2))-1];out.push("<div class='explanation'>"+filterValueSelected+": To reduce and eventually eliminate our contribution to "+str+"</div>");}}
ASPEN.Cookie.set("whistlerIndicatorPickerFilterName",filterName);ASPEN.Cookie.set("whistlerIndicatorPickerFilterValue",filterValueSelected);for(var i=0;i<inds.length;i++){var ind=this.instances["i"+inds[i]];out.push("<a class='indicatorLink' href='"+ind.theUrl+"'>"+ind.name+"</a>");}
this.getElementById("results").innerHTML=out.join("");}
function allIndicators(id){this.base1=xmlDoc;this.base1(id);this.base2=xmlAction;this.base2(id);this.base3=formElement;this.base3(id);this.indicatorsLoaded=allIndicators_indicatorsLoaded;this.strategies={};this.priorities={};this.tns={};this.all=[];this.instances={};this.show=allIndicators_show;this.showAll=allIndicators_showAll;this.context=this.field("context").value;this.filters={"strategies":this.strategies,"priorities":this.priorities,"tns":this.tns,"all":this.all};var theUrl="/whistler/site/allIndicatorsAction.acds?context="+this.context;this.makeRequest(theUrl,null,false,this.indicatorsLoaded);}