/*
Widget: q4.api
Version: 1.10.0
Compiled: 2015-10-26
*/
!function(a){a.widget("q4.api",{options:{url:"",limit:0,skip:0,fetchAllYears:!1,showAllYears:!1,allYearsText:"All",startYear:null,forceStartYear:!1,showFuture:!0,showPast:!0,tags:[],titleLength:0,bodyLength:0,shortBodyLength:0,shortTypes:{"Annual Report":"Annual","Supplemental Report":"Supplemental","First Quarter":"Q1","Second Quarter":"Q2","Third Quarter":"Q3","Fourth Quarter":"Q4"},dateFormat:"mm/dd/yy",useMoment:!1,sortAscending:!1,years:[],minYear:null,maxYear:null,minDate:null,maxDate:null,defaultThumb:"",template:"",append:!0,cssClass:null,loadingClass:null,loadingMessage:"Loading...",yearContainer:null,yearTemplate:null,yearTrigger:null,yearSelect:null,tagSelect:null,activeClass:"active",itemContainer:null,itemTemplate:"",itemLoadingClass:null,itemLoadingMessage:null,itemNotFoundMessage:"No items found.",onYearChange:function(a,b){},onTagChange:function(a,b){},beforeRender:function(a,b){},beforeRenderItems:function(a,b){},itemsComplete:function(a){},complete:function(a){}},$widget:null,years:null,currentYear:-1,currentTags:[],_setOption:function(a,b){this._super(a,b),this._normalizeOptions()},_convertToArray:function(b){return"string"==typeof b&&(b=a.trim(b).split(/[\s,|]+/)),a.isArray(b)?b:[]},_convertToDate:function(a){var b=new Date(a);return"Invalid Date"==b.toString()?null:b},_normalizeOptions:function(){var a=this.options;a.url=a.url.replace(/\/$/,""),a.years=this._convertToArray(a.years).sort(function(a,b){return b-a}),a.tags=this._convertToArray(a.tags),"string"==typeof a.startYear&&a.startYear.length&&(a.startYear=parseInt(a.startYear)),a.minDate=a.minDate?this._convertToDate(a.minDate):null,a.maxDate=a.maxDate?this._convertToDate(a.maxDate):null,null===a.itemLoadingClass&&(a.itemLoadingClass=a.loadingClass),null===a.itemLoadingMessage&&(a.itemLoadingMessage=a.loadingMessage);var b=(new Date).getFullYear();a.showPast&&!a.showFuture?a.maxYear=Math.min(b,a.maxYear||b):a.showFuture&&!a.showPast&&(a.minYear=Math.max(b,a.minYear||b))},_init:function(){var b=this,c=this.options,d=this.element;if("api"==this.widgetName)throw new Error("Please use one of q4.api's child widgets.");this.contentType=this.contentTypes[this.widgetName],this._normalizeOptions(),this.$widget=c.append?a("
").appendTo(d):d,c.cssClass&&this.$widget.addClass(c.cssClass),c.loadingClass&&this.$widget.addClass(c.loadingClass),this.$widget.html(c.loadingMessage||""),this.currentTags=c.tags,this._getYears().done(function(a,c){b.years=b._filterYears(a),b.currentYear=b._getCurrentYear(b.years),void 0!==c?b._renderWidget(c):b._fetchItems(b.currentYear).done(function(a){b._renderWidget(a)})})},_getYears:function(){var b=this.options;if(b.fetchAllYears&&!b.limit){var c=a.Deferred();return this._fetchItems(-1).done(function(b){var d=[];a.each(b,function(b,c){-1==a.inArray(c.year,d)&&d.push(c.year)}),c.resolve(d,b)}),c}return this._fetchYears()},_filterYears:function(b){var c=this.options;return b=a.grep(b,function(b){return(!c.minYear||b>=c.minYear)&&(!c.maxYear||b<=c.maxYear)&&(!c.years.length||a.inArray(b,c.years)>-1)}),c.forceStartYear&&-1==a.inArray(c.startYear,b)&&b.push(c.startYear),b.sort(function(a,b){return b-a}),b},_getCurrentYear:function(b){var c=this.options;if(b.length){if(a.inArray(c.startYear,b)>-1)return c.startYear;if(!c.showAllYears)return b[0]}return-1},_buildParams:function(){return{serviceDto:{ViewType:GetViewType(),ViewDate:GetViewDate(),RevisionNumber:GetRevisionNumber(),LanguageId:GetLanguageId(),Signature:GetSignature()}}},_callApi:function(b,c){var d=this.options;return a.ajax({type:"POST",url:d.url+b,data:JSON.stringify(c),contentType:"application/json; charset=utf-8",dataType:"json"})},_fetchYears:function(){var b=this,c=this.options,d=a.Deferred(),e=a.grep(this.currentTags||[],function(a){return a.length>0});return this._callApi(this.contentType.yearsUrl,a.extend(!0,this._buildParams(),this.contentType.buildParams.call(this,c),{serviceDto:{TagList:e}})).done(function(a){d.resolve(a[b.contentType.yearsResultField])}),d},_fetchItems:function(b){var c=this,d=this.options,e=a.Deferred(),f=a.grep(this.currentTags,function(a){return a.length>0});return this._callApi(this.contentType.itemsUrl,a.extend(!0,this._buildParams(),this.contentType.buildParams.call(this,d),{serviceDto:{ItemCount:d.limit||-1,StartIndex:d.skip,TagList:f,IncludeTags:!0},year:d.fetchAllYears?-1:b})).done(function(b){var f=a.map(b[c.contentType.itemsResultField],function(a){return c.contentType.parseItem.call(c,d,a)});f=a.grep(f,function(a){return(!d.minDate||a.dateObj>=d.minDate)&&(!d.maxDate||a.dateObj<=d.maxDate)}),f.sort(function(a,b){return(b.dateObj-a.dateObj)*(d.sortAscending?-1:1)}),e.resolve(f)}),e},_truncate:function(a,b){return a?!b||a.length<=b?a:a.substring(0,b)+"...":""},_formatDate:function(b){var c=this.options,d=new Date(b),e=c.useMoment&&"undefined"!=typeof moment;if("string"==typeof c.dateFormat)return e?moment(d).format(c.dateFormat):a.datepicker.formatDate(c.dateFormat,d);if("object"==typeof c.dateFormat){var f={};for(name in c.dateFormat)f[name]=e?moment(d).format(c.dateFormat[name]):a.datepicker.formatDate(c.dateFormat[name],d);return f}},_buildTemplateData:function(b){var c=this,d=this.options,e={},f={items:[],years:[],yearsWithItems:[]};return a.each(b,function(b,d){return-1==a.inArray(d.year,c.years)?!0:(d.year in e||(e[d.year]=[]),f.items.push(d),void e[d.year].push(d))}),d.showAllYears&&this.years.length&&f.years.push({year:d.allYearsText,value:-1,items:f.items}),a.each(this.years,function(a,b){f.years.push({year:b,value:b,items:e[b]||[]}),b in e&&f.yearsWithItems.push({year:b,value:b,items:e[b]})}),f},_renderItems:function(b){var c=this.options,d=this.element,e=a(c.itemContainer,d);this._trigger("beforeRenderItems",null,{items:b}),c.itemLoadingClass&&e.removeClass(c.itemLoadingClass),b.length?(e.empty(),a.each(b,function(a,b){e.append(Mustache.render(c.itemTemplate,b))})):e.html(c.itemNotFoundMessage||""),this._trigger("itemsComplete")},_renderWidget:function(b){var c=this,d=this.options,e=this.element,f=this._buildTemplateData(b),g=[];a.each(f.years,function(a,b){b.value==c.currentYear&&(b.active=!0,g=b.items)}),this._trigger("beforeRender",null,f),d.loadingClass&&this.$widget.removeClass(d.loadingClass),this.$widget.html(Mustache.render(d.template,f)),d.itemContainer&&d.itemTemplate&&this._renderItems(g),d.yearContainer&&d.yearTemplate&&(a(d.yearContainer,e).empty(),a.each(f.years,function(b,c){a(d.yearContainer,e).append(Mustache.render(d.yearTemplate,c))})),d.yearTrigger&&a(d.yearTrigger,e).each(function(b){var e=f.years[b].value;a(this).data("year",e),a(this).click(function(b){a(this).hasClass(d.activeClass)||c.setYear(e,b)})}),d.yearSelect&&a(d.yearSelect,e).change(function(b){c.setYear(a(this).val(),b)}),d.tagSelect&&a(d.tagSelect,e).change(function(b){c.setTags(a(this).val(),b)}),this._updateYearControls(this.currentYear),this._trigger("complete")},_updateYearControls:function(b){var c=this.options,d=this.element;c.yearTrigger&&a(c.yearTrigger,d).each(function(){a(this).toggleClass(c.activeClass,a(this).data("year")==b)}),c.yearSelect&&a(c.yearSelect,d).val(b)},reloadItems:function(){var b=this,c=this.options,d=this.element;if(c.itemContainer&&c.itemTemplate){var e=a(c.itemContainer,d);c.itemLoadingClass&&e.addClass(c.itemLoadingClass),e.html(c.itemLoadingMessage||"")}else c.loadingClass&&this.$widget.addClass(c.loadingClass),this.$widget.html(c.loadingMessage||"");this._fetchItems(this.currentYear).done(function(a){c.itemContainer&&c.itemTemplate?b._renderItems(a):b._renderWidget(a)})},setYear:function(b,c){var d=this.options,e=parseInt(b);-1==a.inArray(e,this.years)&&(e=d.showAllYears?-1:this.years[0]),this._trigger("onYearChange",c,{year:e}),c&&c.isDefaultPrevented()||(this.currentYear=e,this._updateYearControls(this.currentYear),this.reloadItems())},setTags:function(a,b){a=this._convertToArray(a),this._trigger("onTagChange",b,{tags:a}),b&&b.isDefaultPrevented()||(this.currentTags=a,this.reloadItems())},contentTypes:{downloads:{itemsUrl:"/Services/ContentAssetService.svc/GetContentAssetList",yearsUrl:"/Services/ContentAssetService.svc/GetContentAssetYearList",itemsResultField:"GetContentAssetListResult",yearsResultField:"GetContentAssetYearListResult",buildParams:function(a){return{assetType:a.downloadType}},parseItem:function(a,b){return{title:this._truncate(b.Title,a.titleLength),url:b.FilePath,dateObj:new Date(b.ContentAssetDate),year:new Date(b.ContentAssetDate).getFullYear(),date:this._formatDate(b.ContentAssetDate),type:b.Type,fileType:b.FileType,size:b.FileSize,icon:b.IconPath,thumb:b.ThumbnailPath,tags:b.TagsList,description:this._truncate(b.Description,a.bodyLength)}}},events:{itemsUrl:"/Services/EventService.svc/GetEventList",yearsUrl:"/Services/EventService.svc/GetEventYearList",itemsResultField:"GetEventListResult",yearsResultField:"GetEventYearListResult",buildParams:function(a){return{eventSelection:a.showFuture&&!a.showPast?1:a.showPast&&!a.showFuture?0:3,includeFinancialReports:!0,includePresentations:!0,includePressReleases:!0,sortOperator:a.sortAscending?0:1}},parseItem:function(b,c){var d=this,e=new Date,f=new Date(c.StartDate),g=new Date(c.EndDate);return{title:this._truncate(c.Title,b.titleLength),url:c.LinkToDetailPage,id:c.EventId,dateObj:f,year:f.getFullYear(),date:this._formatDate(c.StartDate),endDate:this._formatDate(c.EndDate),timeZone:c.TimeZone,isFuture:f>e,isPast:e>g,location:c.Location,tags:c.TagsList,body:this._truncate(c.Body,b.bodyLength),webcast:c.WebCastLink,docs:a.map(c.Attachments,function(a){return{title:a.Title,url:a.Url,type:a.Type,extension:a.Extension,size:a.Size}}),speakers:a.map(c.EventSpeaker,function(a){return{name:a.SpeakerName,position:a.SpeakerPosition}}),financialReports:a.map(c.EventFinancialReport,function(a){return d.contentTypes.financials.parseItem.call(d,b,a)}),pressReleases:a.map(c.EventPressRelease,function(a){return d.contentTypes.news.parseItem.call(d,b,a)}),presentations:a.map(c.EventPresentation,function(a){return d.contentTypes.presentations.parseItem.call(d,b,a)})}}},financials:{itemsUrl:"/Services/FinancialReportService.svc/GetFinancialReportList",yearsUrl:"/Services/FinancialReportService.svc/GetFinancialReportYearList",itemsResultField:"GetFinancialReportListResult",yearsResultField:"GetFinancialReportYearListResult",buildParams:function(a){return{reportSubType:a.reportTypes,reportSubTypeList:a.reportTypes}},parseItem:function(b,c){var d=this,e=a.map(c.Documents,function(a){return{docCategory:a.DocumentCategory,docSize:a.DocumentFileSize,docThumb:a.ThumbnailPath,docTitle:d._truncate(a.DocumentTitle,b.titleLength),docType:a.DocumentFileType,docUrl:a.DocumentPath}});return a.isArray(b.docCategories)&&b.docCategories.length&&(e=a.grep(e,function(c){return a.inArray(c.docCategory,b.docCategories)>-1})),{coverUrl:c.CoverImagePath,title:c.ReportTitle,fiscalYear:c.ReportYear,dateObj:new Date(c.ReportDate),year:new Date(c.ReportDate).getFullYear(),date:this._formatDate(c.ReportDate),tags:c.TagsList,type:c.ReportSubType,shortType:b.shortTypes[c.ReportSubType],docs:e}}},presentations:{itemsUrl:"/Services/PresentationService.svc/GetPresentationList",yearsUrl:"/Services/PresentationService.svc/GetPresentationYearList",itemsResultField:"GetPresentationListResult",yearsResultField:"GetPresentationYearListResult",buildParams:function(a){return{presentationSelection:a.showFuture&&!a.showPast?0:a.showPast&&!a.showFuture?1:3}},parseItem:function(a,b){return{title:this._truncate(b.Title,a.titleLength),url:b.LinkToDetailPage,dateObj:new Date(b.PresentationDate),year:new Date(b.PresentationDate).getFullYear(),date:this._formatDate(b.PresentationDate),tags:b.TagsList,body:this._truncate(b.Body,a.bodyLength),docUrl:b.DocumentPath,docSize:b.DocumentFileSize,docType:b.DocumentFileType,thumb:b.ThumbnailPath}}},news:{itemsUrl:"/Services/PressReleaseService.svc/GetPressReleaseList",yearsUrl:"/Services/PressReleaseService.svc/GetPressReleaseYearList",itemsResultField:"GetPressReleaseListResult",yearsResultField:"GetPressReleaseYearListResult",buildParams:function(a){return{pressReleaseSelection:a.showFuture&&!a.showPast?0:a.showPast&&!a.showFuture?1:3,pressReleaseBodyType:a.loadShortBody?a.loadBody?1:3:a.loadBody?2:0,pressReleaseCategoryWorkflowId:a.category}},parseItem:function(a,b){return{title:this._truncate(b.Headline,a.titleLength),url:b.LinkToDetailPage,dateObj:new Date(b.PressReleaseDate),year:new Date(b.PressReleaseDate).getFullYear(),date:this._formatDate(b.PressReleaseDate),tags:b.TagsList,body:this._truncate(b.Body,a.bodyLength),shortBody:this._truncate(b.ShortBody,a.shortBodyLength),docUrl:b.DocumentPath,docSize:b.DocumentFileSize,docType:b.DocumentFileType,thumb:b.ThumbnailPath||a.defaultThumb}}},sec:{itemsUrl:"/Services/SECFilingService.svc/GetEdgarFilingList",yearsUrl:"/Services/SECFilingService.svc/GetEdgarFilingYearList",itemsResultField:"GetEdgarFilingListResult",yearsResultField:"GetEdgarFilingYearListResult",buildParams:function(a){return{exchange:a.exchange,symbol:a.symbol,formGroupIdList:a.filingTypes.join(",")}},parseItem:function(b,c){return{id:c.FilingId,description:this._truncate(c.FilingDescription,b.titleLength),url:c.LinkToDetailPage,dateObj:new Date(c.FilingDate),year:new Date(c.FilingDate).getFullYear(),date:this._formatDate(c.FilingDate),agent:c.FilingAgentName,type:c.FilingTypeMnemonic,docs:a.map(c.DocumentList,function(a){return{docType:a.DocumentType,docUrl:a.Url}})}}}}}),a.widget("q4.downloads",a.q4.api,{options:{template:""}}),a.widget("q4.events",a.q4.api,{options:{template:""}}),a.widget("q4.financials",a.q4.api,{options:{reportTypes:[],docCategories:[],template:""},_sortItemsByType:function(b){var c=this.options,d=[],e={};return a.each(b,function(b,c){-1==a.inArray(c.type,d)&&(d.push(c.type),e[c.type]=[]),a.each(c.docs,function(a,b){e[c.type].push(b)})}),a.map(d,function(a,b){return{type:a,shortType:c.shortTypes[a],items:e[a]}})},_buildTemplateData:function(b){var c=this,d=this._super(b);return d.types=this._sortItemsByType(d.items),a.each(d.years,function(a,b){b.types=c._sortItemsByType(b.items)}),d}}),a.widget("q4.presentations",a.q4.api,{options:{template:""}}),a.widget("q4.news",a.q4.api,{options:{category:"00000000-0000-0000-0000-000000000000",loadBody:!0,loadShortBody:!0,template:""}}),a.widget("q4.sec",a.q4.api,{options:{exchange:"",symbol:"",filingTypes:[],excludeNoDocuments:!1,template:""}})}(jQuery);