var velir=velir||{};velir.collections=velir.collections||{},velir.collections.NameValueCollection=function(){this._collection={},this._keys=[]},function(){function n(n){for(var t="",r,i=0;i<n.length;i++)(r=n[i],r)&&(t+=r+",");return t.length===0?null:t.substring(0,t.length-1)}this.add=function(n,t){var i=this._collection[n];i||(i=[],this._keys.push(n)),t&&i.push(t),this._collection[n]=i},this.addNameValueCollection=function(n){var f,i,r,t,u;if(n)for(f=n.getKeys(),i=0;i<f.length;i++)if(r=f[i],t=n.getValues(r),t&&t.length>0)for(u=0;u<t.length;u++)this.add(r,t[u]);else this.add(r,null)},this.setValue=function(n,t){var r=this._collection[n],i;r||this._keys.push(n),i=[],t&&i.push(t),this._collection[n]=i},this.clear=function(){this._collection={},this._keys=[]},this.getValue=function(t){if(!this._collection[t])return null;var i=this._collection[t];return n(i)},this.getValueAt=function(n){return this.getValue(this._keys[n])},this.getValues=function(n){return this._collection[n]?this._collection[n]:null},this.getValuesAt=function(n){return this.getValues(this._keys[n])},this.getKeys=function(){return this._keys},this.remove=function(n){var t=$.inArray(n,this._keys);t>-1&&this._keys.splice(t,1),delete this._collection[n]},this.toQueryString=function(){for(var n="",r,i,t=0;t<this._keys.length;t++)r=this._keys[t],i=this._collection[r],i||(i=""),n+="&"+r+"="+escape(i);return n.length>0?n.substring(1,n.length):n},this.fromQueryString=function(n){var i,t;if(n&&n.length!==0)for(n.indexOf("?")>-1&&(n=n.split("?")[1]),n.indexOf("#")>-1&&(n=n.split("#")[0]),i=n.split("&"),t=0;t<i.length;t++){var f=i[t],r=f.split("="),e=r[0],u=null;r.length>1&&(u=unescape(r[1])),this.add(e,u)}}}.call(velir.collections.NameValueCollection.prototype),velir.collections.NameValueCollection.parseQueryString=function(n){var t=new velir.collections.NameValueCollection;return t.fromQueryString(n),t},velir=velir||{},velir.datacenter=velir.datacenter||{},velir.datacenter.DatacenterContainer=function(){var n=this;return this.addValuesToCollection=function(n,t,i){for(var u,r=0;r<i.length;r++)u=i[r],n.add(t,u.id)},this.getValuesFromCollection=function(n,t,i,r,u){var o=n.getValue(t),f,e,s,h;o&&(f=o.split(","),e="",velir.datacenter.DatacenterContainer.entitySearchService&&(e="Loading..."),$(f).each(function(n,t){var r={id:""+t,name:e};i.push(r)}),velir.datacenter.DatacenterContainer.entitySearchService?(s=JSON.stringify({ids:f}),h="/Find"+r+"s",$.ajax({type:"POST",url:velir.datacenter.DatacenterContainer.entitySearchService+h,data:s,contentType:"application/json; charset=utf-8",dataType:"json",error:function(n,t){alert("Error connecting to entity search service.\n\n"+t)},success:function(n){for(var e=JSON.parse(n.d),f,r,t=0;t<e.length;t++)f=e[t],r=-1,$(i).each(function(n,t){if(t.id==f.id)return r=n,!1}),r>-1&&i.splice(r,1,f);u&&u()}})):u&&u())},{loadEntityNames:!1,entitySearchService:"",indicators:[],timeFrames:[],dataFormatMaps:[],characteristics:[],locations:[],categories:[],toNameValueCollection:function(){var i=velir.datacenter.UrlParams,t=new velir.collections.NameValueCollection;return n.addValuesToCollection(t,i.indicatorId,this.indicators),n.addValuesToCollection(t,i.timeFrameId,this.timeFrames),n.addValuesToCollection(t,i.dataFormatMapId,this.dataFormatMaps),n.addValuesToCollection(t,i.characteristicId,this.characteristics),n.addValuesToCollection(t,i.locationId,this.locations),n.addValuesToCollection(t,i.categoryId,this.categories),t},toQueryString:function(){return this.toNameValueCollection().toQueryString()},fromQueryString:function(t,i){var r=velir.datacenter.UrlParams,u=velir.collections.NameValueCollection.parseQueryString(t);n.getValuesFromCollection(u,r.indicatorId,this.indicators,"Indicator",i),n.getValuesFromCollection(u,r.timeFrameId,this.timeFrames,"TimeFrame",i),n.getValuesFromCollection(u,r.dataFormatMapId,this.dataFormatMaps,"DataFormatMap",i),n.getValuesFromCollection(u,r.characteristicId,this.characteristics,"Characteristic",i),n.getValuesFromCollection(u,r.locationId,this.locations,"Location",i),n.getValuesFromCollection(u,r.categoryId,this.categories,"Category",i)}}},velir.datacenter.DatacenterContainer.parseQueryString=function(n,t){var i=new velir.datacenter.DatacenterContainer;return i.fromQueryString(n,t),i},velir.datacenter.DatacenterContainer.entitySearchService=!1,velir=velir||{},velir.datacenter=velir.datacenter||{},velir.datacenter.UrlParams={indicatorId:"ind",categoryId:"cat",locationId:"loc",locationTypeId:"loct",sourceId:"src",timeFrameId:"tf",dataFormatMapId:"fmt",characteristicId:"ch",getParameter:function(n){var t=velir.datacenter.UrlParams;switch(n.toLowerCase()){case"indicator":return t.indicatorId;case"category":return t.categoryId;case"location":return t.locationId;case"locationtype":return t.locationTypeId;case"source":return t.sourceId;case"timeframe":return t.timeFrameId;case"dataformatmap":return t.dataFormatMapId;case"characteristic":return t.characteristicId}return null}},velir=velir||{},velir.forms=velir.forms||{},velir.forms.GhostText={apply:function(n,t,i,r){$(n).each(function(){velir.forms.GhostText.applyTo($(this),t,i,r)})},applyTo:function(n,t,i,r){if(n.is('input[type="text"]')){var u=velir.util.StringUtil.isNullOrEmpty;u(n.val())&&n.val(t),n.focus(function(){$(this).val()===t&&($(this).val(""),u(i)||$(this).toggleClass(i))}),n.blur(function(){$(this).val()===""&&($(this).val(t),u(i)||$(this).toggleClass(i))}),r!==null&&n.keypress(function(n){n.keyCode==13&&r(n)})}},install:function(n){$.fn[n]=function(n,t,i){return this.each(function(){velir.forms.GhostText.applyTo($(this),n,t,i)})}}},velir=velir||{},velir.util=velir.util||{},velir.util.DomUtil={scrollElementIntoView:function(n,t,i,r){var c;if(n&&t){typeof i=="undefined"&&(i=4);var e=$(n),u=$(t),l=e.offsetParent();if(l.get(0)!==u.get(0)){u.is(":visible")&&console.log("scrollElementIntoView: The specified container must be the offsetParent of the specified element. Try adding position:relative to the container.");return}var f=e.position().top,o=u.scrollTop(),s=e.outerHeight(),h=200;f<o?u.stop().animate({scrollTop:o+f},h,r):f>u.innerHeight()-s-i?(c=o+f-u.height()+s+i,u.stop().animate({scrollTop:c},h,r)):r&&r()}}},velir=velir||{},velir.util=velir.util||{},velir.util.Packer={_isArray:function(n){return n.constructor==Array},_isInteger:function(n){return!isNaN(n)&&parseInt(n,10)==n},pack:function(n){var e=this,u,t,i,r,f;if(!n||(this._isArray(n)||(n=n.split(",")),u=[],t=$.map(n,function(n){if(!e._isInteger(n))throw"All values in the comma separated string must be integers!";return parseInt(n,10)}),t.length===0))return"";if(t.length==1)return t[0]+"";for(r=0,f=function(n,i){n===i-1?u.push(t[n]):u.push(t[n]+"-"+t[i-1])},i=1;i<t.length;i++)t[i]!=t[i-1]+1&&(f(r,i),r=i);return i!=r&&f(r,i),u.join(",")},unpack:function(n,t){var u,f,i,r,e,o,s;if(!n)return t?[]:"";for(u=[],f=n.split(","),i=0;i<f.length;i++)if(f[i])if(r=f[i].split("-"),r.length===1)u.push(parseInt(r[0],10));else if(r.length>2)throw"Improperly formatted group: "+f[i];else for(o=parseInt(r[0],10),s=parseInt(r[1],10),e=o;e<=s;e++)u.push(e);return t?u:u.join(",")}},velir=velir||{},velir.util=velir.util||{},velir.util.StringUtil={isNullOrEmpty:function(n){return n===null||n===undefined||n===""},format:function(n){for(var i=n,r,t=1;t<arguments.length;t++)r=new RegExp("\\{"+(t-1)+"\\}","gm"),i=i.replace(r,arguments[t]);return i}},function(){this.toQueryStringReplaceCommas=function(){return this.toQueryString().replace(/%2C/gi,",")}}.call(velir.collections.NameValueCollection.prototype),velir=velir||{},velir.caching=velir.caching||{},function(n){velir.caching.TemplateCache=function(){this.templates={},this.loaders={}},function(t){t.get=function(t){var u=this,i=n.Deferred(),f=this.templates[t],r;return f?i.resolve(f):(r=this.loaders[t],r?i=r:(this.loaders[t]=i,this.loadTemplate(t,function(n){delete u.loaders[t],u.templates[t]=n,i.resolve(n)}))),i.promise()},t.loadTemplate=function(t,i){var r=n(t).html(),f,u;if(!r||r.length===0){f="Could not find template: '"+t+"'",u=new Error(f),u.name="NoTemplateError";throw u;}r=this.compileTemplate(r),i.call(this,r)},t.compileTemplate=function(n){return _.template(n)},t.clear=function(){var t=arguments.length,n;if(t>0)for(n=0;n<t;n++)delete this.templates[arguments[n]];else this.templates={}}}(velir.caching.TemplateCache.prototype)}(jQuery),velir=velir||{},velir.caching=velir.caching||{},function(n){velir.caching.AsyncTemplateCache=function(n){this.promises={},this.templateBasePath=n||"",this.templateBasePath.charAt(this.templateBasePath.length-1)!="/"&&(this.templateBasePath=n+"/")},velir.caching.AsyncTemplateCache.prototype=new velir.caching.TemplateCache,function(t){t.loadTemplateAsync=function(t){var i=this.promises[t]||n.get(this.templateBasePath+t+".html");return this.promises[t]=i,i},t.loadTemplate=function(n,t){var r=this,i;n=n.replace("#",""),i=this.loadTemplateAsync(n),i.done(function(n){n=r.compileTemplate(n),t.call(this,n)})}}(velir.caching.AsyncTemplateCache.prototype)}(jQuery)