var VoicestormHeader=function(){function n(){var n=this;n._apiWrapper=new VoicestormUtilities;VoiceStorm.currentUser().then(function(){jQuery(".voicestorm-navigation").show();n.AddProfilePictureToHeader()}).then(function(){jQuery("#notifications").length?n.MarkUnreadNotificationsAsRead():n.ShowUnreadNotificationsCount()})}return n.prototype.AddProfilePictureToHeader=function(){var n=jQuery("<img><\/img>").attr("src","/Website.UI/web.ui/images/Voicestorm/default-profile-image.png").addClass("header-profile-image");VoiceStorm.api("GET","/user",{include:"images"}).then(function(t){t.profilePictureImages&&t.profilePictureImages.Square20&&n.attr("src",t.profilePictureImages.Square20.url);jQuery(".profile-link").prepend(n)})},n.prototype.MarkUnreadNotificationsAsRead=function(){var n=this._apiWrapper.Notifications({allRead:!1,take:99,skip:0},function(n){for(var t=0;t<n.length;t++)VoiceStorm.api("PUT","/notification/"+n[t].notificationId+"/acknowledge ")});jQuery(".notifications-counter").hide()},n.prototype.ShowUnreadNotificationsCount=function(){var n=this._apiWrapper.Notifications({allRead:!1,take:99,skip:0},function(n){var t=n.length,i;t>0&&(i=jQuery("<span>"+t+"<\/span>").addClass("notifications-counter"),jQuery(".notication-link").append(i))})},n}(),VoicestormNotifications=function(){function n(){}return n.prototype.GetNotifications=function(n,t){var i=this,r=[];VoiceStorm.userNotifications({all:n.allRead,take:n.take,skip:n.skip}).then(function(n){var u=i.PostIds(n);u.length>0?VoiceStorm.api("GET","posts",{ids:u.toString()}).then(function(u){for(var o=i.AssociatedPosts(u),e,f=0;f<n.notifications.length;f++)e=n.notifications[f],i.AddNotificationToArray(e,r,o);t(r)}):t(r)})},n.prototype.PostIds=function(n){var t=[];return jQuery.each(n.notifications,function(n,i){t.push(i.postId)}),t},n.prototype.AssociatedPosts=function(n){var t=[];return jQuery.each(n.posts,function(n,i){t.hasOwnProperty(i.postId)||(t[i.postId]=i)}),t},n.prototype.AddNotificationToArray=function(n,t,i){var s=n.createdDate,h=n.title,c=n.content,r=n.postId,l=n.notificationId,f,e,u,o;r in i&&(f=VoicestormUtilities.IsPostShareable(i[r].approvalState,i[r].sharable),e=i[r].sharePoints);u=!1;n.acknowledgementDate!=null&&n.acknowledgementDate!="undefined"&&(u=!0);o=new Notification(s,h,c,r,u,f,l,e);t.push(o)},n}(),Notification=function(){function n(n,t,i,r,u,f,e,o){this.createdDate=n;this.title=t;this.content=i;this.postId=r;this.acknowledged=u;this.isShareable=f;this.notificationId=e;this.sharePoints=o}return n}(),VoicestormUtilities=function(){function n(){this._voicestormNotifications=new VoicestormNotifications;this._voicestormLeaderboard=new VoicestormLeaderboard}return n.prototype.Login=function(n,t,i){VoiceStorm.login(n,t).then(function(){i()})},n.ProvideLogin=function(){var n="//"+location.hostname+"/SsoLogin.aspx";window.open(n,"","location=1,toolbar=0,"+this.Popup(320,600))},n.GetShortName=function(n){var t=n.firstName;return n.lastName.length>0&&(t+=" "+n.lastName.charAt(0)),t+"."},n.CommaFormat=function(n){if(n==null)return"";var t=n.toString();return t.length===3?t:t.replace(/\B(?=(\d{3})+(?!\d))/g,",")},n.prototype.Notifications=function(n,t){this._voicestormNotifications.GetNotifications(n,t)},n.prototype.LeaderBoard=function(n,t){this._voicestormLeaderboard.GetLeaderboard(n,t)},n.Popup=function(n,t){var i=typeof window.screenX!="undefined"?window.screenX:window.screenLeft,r=typeof window.screenY!="undefined"?window.screenY:window.screenTop,u=typeof window.outerWidth!="undefined"?window.outerWidth:document.documentElement.clientWidth,f=typeof window.outerHeight!="undefined"?window.outerHeight:document.documentElement.clientHeight-22,e=i<0?window.screen.width+i:i,o=e+(u-n)/2,s=r+(f-t)/2.5;return"width="+n+",height="+t+",left="+o+",top="+s+",scrollbars=1"},n.ChangeButtonText=function(t,i){var r,u=this;VoiceStorm.post(t).then(function(t){r=t.sharePoints;jQuery(".voicestorm-share-button[data-postid='"+t.postId+"']").html("SHARE NOW AND GET "+r+" POINTS");i!=null&&typeof i!="undefined"&&i();VoiceStorm.currentUser().fail(function(){jQuery(".voicestorm-share-button[data-postid='"+t.postId+"']").click(function(){return n.ProvideLogin(),!1})})})},n.IsPostShareable=function(n,t){return n==null||t==null?!1:n.toLowerCase()==="published"&&t===!0},n}(),VoicestormNotificationsRendering=function(){function n(){this._amountAdded=0;this._takeNumber=10;jQuery("#notifications").length&&(this._voicestormUtilities=new VoicestormUtilities,this.RenderNotifications(0),this.AttachScrollHandler())}return n.prototype.RenderNotifications=function(n){var i=this._voicestormUtilities,t=this;t.RegisterHelpers();VoiceStorm.currentUser().then(function(){i.Notifications({allRead:!0,take:t._takeNumber,skip:n},function(n){if(jQuery("#loading").hide(),t._amountAdded=t._amountAdded+n.length,n.length==t._takeNumber&&(t._scrollMore=!0),n.length>0){var i={notifications:n},r=Handlebars.compile(jQuery("#mynotifications-template").html());jQuery("#notifications").append(r(i));t.BindNotificationClickEvents()}else n.length==0&&t._amountAdded==0&&jQuery("#no-notifications").show()})}).fail(function(){VoicestormUtilities.ProvideLogin()})},n.prototype.BindNotificationClickEvents=function(){jQuery(".notification-button").click(function(){var n=jQuery(this).attr("data-postid");VoiceStorm.currentUser().then(function(){VoiceStorm.sharePost({postId:n})}).fail(function(){VoicestormUtilities.ProvideLogin()})})},n.prototype.RegisterHelpers=function(){Handlebars.registerHelper("formatDate",function(n){return moment?moment(n).format("Do MMMM YYYY"):n})},n.prototype.AttachScrollHandler=function(){var n=this;jQuery(window).scroll(function(){jQuery(window).scrollTop()>=(jQuery(document).height()-jQuery(window).height())*.99&&n._scrollMore&&(jQuery("#loading").show(),n.RenderNotifications(n._amountAdded),n._scrollMore=!1)})},n}(),VoicestormLeaderboard=function(){function n(){}return n.prototype.GetLeaderboard=function(n,t){var r=this,i;VoiceStorm.api("GET","/user",{include:"images"}).then(function(n){var u="/Website.UI/web.ui/images/Voicestorm/default-profile-image.png";n.profilePictureImages&&n.profilePictureImages.Square160&&(u=n.profilePictureImages.Square160.url);var s=n.displayName.replace(/\./g,""),f="",e=0,o=[];VoiceStorm.api("GET","/user/"+n.id+"/rankings").then(function(n){n.leaderboards&&n.leaderboards[0]&&(f="#"+n.leaderboards[0].rank,e=n.leaderboards[0].points)}).always(function(){VoiceStorm.api("GET","/leaderboardrankings",{id:1,include:"images"}).then(function(n){for(var h,l,c=0;c<n.rankings.length;c++)h=n.rankings[c],l=new LeaderboardRanking(h.rank,h.user.displayName,h.points),l.pictureUrl=r.GetProfilePicUrl(h.user.profilePictureImages),o.push(l);i=new Leaderboard(o,f,e,u,s);t(i);jQuery("#loading").hide()})})}).fail(function(){VoicestormUtilities.ProvideLogin()})},n.prototype.GetProfilePicUrl=function(n){return n&&n.Square40?n.Square40.url:"/Website.UI/web.ui/images/Voicestorm/default-profile-image.png"},n}(),Leaderboard=function(){function n(n,t,i,r,u){this.leaderboardRankings=n;this.userRank=t;this.userPoints=i;this.userPictureUrl=r;this.userDisplayName=u}return n}(),LeaderboardRanking=function(){function n(n,t,i){this.rank=n;this.displayName=t;this.points=i}return n}(),VoicestormLeaderboardRendering=function(){function n(){var n=this;jQuery("#leaderboard").length&&(n._voicestormUtilities=new VoicestormUtilities,n.RegisterAlternativeHelper(),n.RenderLeaderboard())}return n.prototype.RenderLeaderboard=function(){this._voicestormUtilities.LeaderBoard(1,function(n){var t={leaderboard:n},i=Handlebars.compile(jQuery("#myleaderboard-template").html());jQuery("#leaderboard").append(i(t))})},n.prototype.RegisterAlternativeHelper=function(){Handlebars.registerHelper("everyOther",function(n,t,i){return++n%t?i.inverse(this):i.fn(this)});Handlebars.registerHelper("commaFormat",function(n){return VoicestormUtilities.CommaFormat(n)})},n}(),VoicestormFeedRendering=function(){function n(){this._takeNumber=6;this._amountAdded=0;this._canUpdate=!0;this._numberOfPostsReturned=0;this._postSelector=".post";this._streamWidget=jQuery("#post-stream");this._loadingImage=jQuery("#loading");this._postIdsAdded=[];this._voicestormUtilities=new VoicestormUtilities;this._streamWidget.length&&(this.InitMasonry(),this.AddScrollHandler())}return n.prototype.InitMasonry=function(){var n=this,t=0;n._streamWidget.on("rendered.voicestorm.renderpost",function(){t++;t==n._numberOfPostsReturned&&n._streamWidget.imagesLoaded(function(){n.HideLoadingImage();n.ShowNewPosts();n.ChangeButtonTextAndUrlIfNotLoggedIn();n._streamWidget.fadeIn();n._streamWidget.masonry({columnWidth:n._postSelector,itemSelector:n._postSelector,gutter:20,hiddenStyle:{opacity:0},visibleStyle:{opacity:1}})})});n.AddPostsToStream(n._amountAdded);n._streamWidget.hide();n._numberOfPostsReturned=0;n._postIdsAdded=[]},n.prototype.UpdateMasonry=function(n){var t=this,i;t.AddPostsToStream(n);i=0;t._streamWidget.on("rendered.voicestorm.renderpost",function(){i++;i==t._numberOfPostsReturned&&t._streamWidget.imagesLoaded(function(){t._canUpdate=!0;t.ShowNewPosts();t.ChangeButtonTextAndUrlIfNotLoggedIn();t.HideLoadingImage();t._streamWidget.masonry("reloadItems").masonry()})});t._numberOfPostsReturned=0;t._postIdsAdded=[]},n.prototype.AddPostsToStream=function(n){var t=this,i;jQuery(this._loadingImage).show();i=VoiceStorm.stream({name:"Main Feed",idsOnly:!0,take:this._takeNumber,skip:n}).then(function(n){var i,r;for(t._numberOfPostsReturned=n.postIds.length,t._amountAdded=t._amountAdded+t._numberOfPostsReturned,t.HideLoadingImagefAllPostsLoaded(),i=0;i<t._numberOfPostsReturned;i++)r=jQuery('<div class="post" style="display: none"><\/div>').VoiceStormRenderPost({postId:n.postIds[i],includeSummary:!1,includeContent:!0,includeShareButton:!0,shareButtonText:"SHARE NOW"}),t._streamWidget.append(r),t._postIdsAdded.push(n.postIds[i])})},n.prototype.AddScrollHandler=function(){var n=this;jQuery(window).scroll(function(){jQuery(window).scrollTop()>=(jQuery(document).height()-jQuery(window).height())*.6&&n._canUpdate&&(n.UpdateMasonry(n._amountAdded),n._canUpdate=!1)})},n.prototype.HideLoadingImagefAllPostsLoaded=function(){this._numberOfPostsReturned==0?this.HideLoadingImage():jQuery(this._loadingImage).show()},n.prototype.HideLoadingImage=function(){jQuery(this._loadingImage).hide()},n.prototype.ShowNewPosts=function(){jQuery(this._postSelector).fadeIn()},n.prototype.ChangeButtonTextAndUrlIfNotLoggedIn=function(){for(var t=this,n=0;n<t._numberOfPostsReturned;n++)VoiceStorm.post(t._postIdsAdded[n]).then(function(n){VoicestormUtilities.ChangeButtonText(n.postId)})},n}(),VoicestormPostRendering=function(){function n(){this._postSelector="#post";this._postId=QueryString.GetParameterByName("id");this._postWidget=jQuery(this._postSelector);this._loadingImage=jQuery("#loading");this._voicestormUtilities=new VoicestormUtilities;var n=this;this._postWidget.on("rendered.voicestorm.renderpost",function(){n._postWidget.imagesLoaded(function(){n.HideLoadingImage();VoicestormUtilities.ChangeButtonText(n._postId,function(){n.FadeInPost()})})})}return n.prototype.FadeInPost=function(){this._postWidget.fadeIn()},n.prototype.HideLoadingImage=function(){jQuery(this._loadingImage).hide()},n}(),Channel=function(){function n(n,t){this.name=n;this.displayName=t}return n}(),Share=function(){function n(){this.channels=[]}return n}(),ScheduledShare=function(){function n(){this.shareDates=[];this.channels=[]}return n}(),ShareOptions=function(){function n(n,t,i){this.takeNumber=n;this.amountAdded=t;this.scrollMore=i}return n}(),VoicestormSharesRendering=function(){function n(){this._takeNumber=10;this._amountAdded=0;this._scrollMore=!1;this._userChannels=[];jQuery("#voicestorm-scheduled-shares").length&&(this.RegisterHelpers(),this.BindEvents(),this.initilisePage())}return n.prototype.initilisePage=function(){var n=this;VoiceStorm.currentUser().then(function(t){return n._currentUser=t,n.GetUserChannels(t)}).then(function(t){n.ProcessChannels(t);n.GetScheduledShareData(n._currentUser);n.GetShareData(n._currentUser)}).fail(function(){VoicestormUtilities.ProvideLogin()})},n.prototype.GetUserChannels=function(n){return VoiceStorm.api("GET","/userchannels",{id:n.id})},n.prototype.ProcessChannels=function(n){for(var t=0;t<n.channels.length;t++)this._userChannels[n.channels[t].userChannelId]=n.channels[t]},n.prototype.GetScheduledShareData=function(n){var t=this;VoiceStorm.api("GET","share/scheduled",{userId:n.id}).then(function(n){var i=[];jQuery.each(n.shares,function(n,t){i.push(t.postId)});i.length>0?VoiceStorm.api("GET","posts",{ids:i.toString()}).then(function(i){var r=[],u=[],f,e;jQuery.each(i.posts,function(n,t){r.hasOwnProperty(t.postId)||(r[t.postId]=t)});jQuery.each(n.shares,function(n,i){u.push(t.ParseScheduledShare(i,r))});f={scheduledShares:u};e=Handlebars.compile(jQuery("#myscheduled-shares-template").html());jQuery("#scheduled-shares-title").show();jQuery("#voicestorm-scheduled-shares").append(e(f))}):(jQuery("#scheduled-shares-title").show(),jQuery("#no-scheduled-shares").show())})},n.prototype.ParseScheduledShare=function(n,t){var r=this,i=new ScheduledShare;return n.postId in t&&(i.title=t[n.postId].title,i.pointsValue=t[n.postId].sharePoints,i.sharePoints=t[n.postId].sharePoints,i.isShareable=VoicestormUtilities.IsPostShareable(t[n.postId].approvalState,t[n.postId].sharable)),jQuery.each(n.userChannelIds,function(n,t){var u=new Channel(r._userChannels[t].provider,r._userChannels[t].displayName);i.channels.push(u)}),i.scheduledShareId=n.id,i.postId=n.postId,i.shareDates=n.shareDates,i},n.prototype.GetShareData=function(n){var t=this;jQuery("#loading").show();VoiceStorm.api("GET","/usercomments",{id:n.id,take:t._takeNumber,skip:t._amountAdded,include:"channels"}).then(function(n){var i=[];jQuery.each(n.comments,function(n,r){i.push(r.postId);t._amountAdded++});t._takeNumber===n.comments.length&&(t._scrollMore=!0);i.length>0?VoiceStorm.api("GET","posts",{ids:i.toString()}).then(function(i){var r=[],u=[],f,e;jQuery.each(i.posts,function(n,t){r.hasOwnProperty(t.postId)||(r[t.postId]=t)});jQuery.each(n.comments,function(n,i){u.push(t.ParseComment(i,r))});f={shares:u};e=Handlebars.compile(jQuery("#myshares-template").html());jQuery("#loading").hide();jQuery("#shares-title").show();jQuery("#voicestorm-shared-comments").append(e(f))}):(jQuery("#loading").hide(),jQuery("#shares-title").show())})},n.prototype.ParseComment=function(n,t){var r=this,i=new Share;return n.postId in t&&(i.title=t[n.postId].title,i.isShareable=VoicestormUtilities.IsPostShareable(t[n.postId].approvalState,t[n.postId].sharable),i.pointsValue=t[n.postId].sharePoints),i.pointsEarned=n.totalPoints,i.shareCount=n.statistics.shareCount,i.clickCount=n.statistics.clickCount,i.reactionCount=n.statistics.reactionCount,i.impressionCount=n.statistics.impressionCount,jQuery.each(n.channels,function(n,t){var r=new Channel(t.provider,t.provider);i.channels.push(r)}),i.postId=n.postId,i},n.prototype.DeleteScheduledShare=function(n){VoiceStorm.currentUser().then(function(){VoiceStorm.api("PUT","share/"+n+"/delete/").then(function(){jQuery('section[data-scheduledid="'+n+'"]').remove()})}).fail(function(){VoicestormUtilities.ProvideLogin()})},n.prototype.BindEvents=function(){var n=this;jQuery("#voicestorm-scheduled-shares, #voicestorm-shared-comments").on("click",".notification-button",function(){var n=jQuery(this).attr("data-postid");VoiceStorm.currentUser().then(function(){VoiceStorm.sharePost({postId:n})}).fail(function(){VoicestormUtilities.ProvideLogin()})});jQuery("#voicestorm-scheduled-shares").on("click",".remove-scheduled-share",function(){var t=jQuery(this).attr("data-scheduledid");n.DeleteScheduledShare(t)});jQuery(window).scroll(function(){jQuery(window).scrollTop()>=(jQuery(document).height()-jQuery(window).height())*.99&&n._scrollMore&&(n.GetShareData(n._currentUser),n._scrollMore=!1)})},n.prototype.RegisterHelpers=function(){var n=this;Handlebars.registerHelper("toLowerCase",function(n){return n==null?"":n.toLowerCase()});Handlebars.registerHelper("formatDate",function(n,t){return n==null?"":moment?t===!0?moment(n).format("HH:mm on ddd Do MMM"):moment(n).format("HH:mm on dddd Do MMMM"):n})},n}(),VoicestormProfile=function(){function n(){this.REQUIRED_FIELDS_ERROR_MESSAGE="Please ensure you have completed all fields.";this.INVALID_EMAIL_ERROR_MESSAGE="Please enter a valid email address.";this.NEW_PASSWORD_MISMATCH_ERROR_MESSAGE="New passwords must match.";this.PASSWORD_STRENGTH_ERROR_MESSAGE="Password must be at least 8 characters containing a minimum of 1 lowercase character, 1 uppercase character and a number or symbol.";(jQuery("#profileNotifications").length||jQuery("#bioProfile").length||jQuery("#connectedProfileChannels").length||jQuery("#profileShareStatistics").length)&&this.initilisePage()}return n.prototype.initilisePage=function(){var n=this;VoiceStorm.currentUser().then(function(t){jQuery("#profileNotifications").length&&(n.InitialiseNotifications(),n.InitialiseDisplayName(t),n.BindNotificationClickEvents());jQuery("#bioProfile").length&&n.InitialiseBiography(t);jQuery("#connectedProfileChannels").length&&n.initialiseChannels();jQuery("#profileShareStatistics").length&&n.initialiseStatistics(t)})},n.prototype.BindNotificationClickEvents=function(){var n=this;jQuery("#contact-details-submit").click(function(){n.SaveContactDetails()});jQuery("#user-preferences-submit").click(function(){n.SaveUserPreferences()});jQuery("#notifications-update-button").click(function(){n.SaveNotifications()})},n.prototype.SaveContactDetails=function(){var n=this;n.SaveContactDetailsHideMessages();n.ValidateContactDetails()&&VoiceStorm.currentUser().then(function(t){n.SaveSitecoreContactDetails(t)}).fail(function(){VoicestormUtilities.ProvideLogin()})},n.prototype.ValidateContactDetails=function(){var n=this,t=!1;return(jQuery("#contact-details-validation-error").text(""),n.IsRequiredFieldEmpty("Forename")&&(t=!0),n.IsRequiredFieldEmpty("Surname")&&(t=!0),n.IsRequiredFieldEmpty("Postcode")&&(t=!0),n.IsRequiredFieldEmpty("Email")&&(t=!0),t)?(jQuery("#contact-details-validation-error").text(n.REQUIRED_FIELDS_ERROR_MESSAGE),!1):n.IsValidEmail("Email")},n.prototype.IsRequiredFieldEmpty=function(n){jQuery("#"+n).removeClass("input-validation-error");var t=jQuery("#"+n).val();return t.length>0?!1:(jQuery("#"+n).addClass("input-validation-error"),!0)},n.prototype.HasMatchingFields=function(n,t){var u=this,i,r;return(jQuery("#"+n).removeClass("input-validation-error"),jQuery("#"+t).removeClass("input-validation-error"),i=jQuery("#"+n).val(),r=jQuery("#"+t).val(),i===r)?!0:(jQuery("#preferences-validation-error").text(u.NEW_PASSWORD_MISMATCH_ERROR_MESSAGE),jQuery("#"+n).addClass("input-validation-error"),jQuery("#"+t).addClass("input-validation-error"),!1)},n.prototype.IsPasswordStrengthValid=function(n){var r=this,t,i;return(jQuery("#"+n).removeClass("input-validation-error"),t=jQuery("#"+n).val(),i=/(?=.{8,})(?=(.*[a-z]){1,})(?=(.*[A-Z]){1,})(?=(.*[\d|\W]){1,})/,t.match(i))?!0:(jQuery("#preferences-validation-error").text(r.PASSWORD_STRENGTH_ERROR_MESSAGE),jQuery("#"+n).addClass("input-validation-error"),!1)},n.prototype.IsValidEmail=function(n){var r=this,t,i;return(jQuery("#"+n).removeClass("input-validation-error"),t=jQuery("#"+n).val(),i=/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/,i.test(t))?!0:(jQuery("#contact-details-validation-error").text(r.INVALID_EMAIL_ERROR_MESSAGE),jQuery("#"+n).addClass("input-validation-error"),!1)},n.prototype.SaveSitecoreContactDetails=function(n){var t=this;jQuery.ajax({url:"/voicestorm/details",type:"POST",data:jQuery("#contact-details-form").serialize()}).done(function(i){if(i.success)return t.SaveVoiceStormContactDetails(n);t.SaveContactDetailsFail()}).fail(function(){t.SaveContactDetailsFail()})},n.prototype.SaveVoiceStormContactDetails=function(n){var t=this;n.firstName=t.GetFirstName();n.lastName=t.GetLastName();n.email=t.GetEmail();VoiceStorm.putUser(n).then(function(n){t.SaveContactDetailsSuccess();t.InitialiseBiographyName(n);t.InitialiseDisplayName(n)}).fail(function(){t.SaveContactDetailsFail()})},n.prototype.SaveContactDetailsHideMessages=function(){jQuery("#contact-post-success").hide();jQuery("#contact-post-failure").hide()},n.prototype.SaveContactDetailsSuccess=function(){jQuery("#contact-post-success").show();jQuery("#contact-post-failure").hide()},n.prototype.SaveContactDetailsFail=function(){jQuery("#contact-post-success").hide();jQuery("#contact-post-failure").show()},n.prototype.GetFirstName=function(){return jQuery("#Forename").val()},n.prototype.GetLastName=function(){return jQuery("#Surname").val()},n.prototype.GetEmail=function(){return jQuery("#Email").val()},n.prototype.SaveUserPreferences=function(){var n=this;n.SaveUserPreferencesHideMessages();n.ValidateUserPreferences()&&jQuery.ajax({url:"/voicestorm/preferences",type:"POST",data:jQuery("#user-preferences-form").serialize()}).done(function(t){t.success?n.SaveUserPreferencesSuccess():n.SaveUserPreferencesFail()}).fail(function(){n.SaveUserPreferencesFail()})},n.prototype.ValidateUserPreferences=function(){var n=this,t=!1,i;return(jQuery("#preferences-validation-error").text(""),n.IsRequiredFieldEmpty("CurrentPassword")&&(t=!0),n.IsRequiredFieldEmpty("NewPassword")&&(t=!0),n.IsRequiredFieldEmpty("ConfirmPassword")&&(t=!0),t)?(jQuery("#preferences-validation-error").text(n.REQUIRED_FIELDS_ERROR_MESSAGE),!1):(i=n.HasMatchingFields("NewPassword","ConfirmPassword"),i&&(i=n.IsPasswordStrengthValid("NewPassword")),i)},n.prototype.SaveUserPreferencesHideMessages=function(){jQuery("#preferences-post-success").hide();jQuery("#preferences-post-failure").hide()},n.prototype.SaveUserPreferencesSuccess=function(){jQuery("#preferences-post-success").show();jQuery("#preferences-post-failure").hide()},n.prototype.SaveUserPreferencesFail=function(){jQuery("#preferences-post-success").hide();jQuery("#preferences-post-failure").show()},n.prototype.InitialiseNotifications=function(){VoiceStorm.api("GET","/usernotificationspreferences").then(function(n){jQuery("#notificationEmail").prop("checked",n.subscribeToEmails);jQuery("#notificationEmailDigest").prop("checked",n.subscribeToDigests)})},n.prototype.InitialiseDisplayName=function(n){jQuery("#displayNameShort").text(VoicestormUtilities.GetShortName(n));jQuery("#displayNameFull").text(n.fullName);var t=jQuery("input:radio[name=displayNameFormat]");t.is(":checked")===!1&&t.filter("[value="+n.displayNameFormat+"]").prop("checked",!0)},n.prototype.SaveNotifications=function(){var n=this;n.SaveNotificationsHideMessages();VoiceStorm.currentUser().then(function(t){t.displayNameFormat=jQuery("input[name=displayNameFormat]:checked").val();VoiceStorm.putUser(t).then(function(){var t=jQuery("#notificationEmail").prop("checked"),i=jQuery("#notificationEmailDigest").prop("checked");VoiceStorm.updateUserNotificationPreferences({subscribeToDigests:i,subscribeToEmails:t}).then(function(){n.SaveNotificationsSuccess()}).fail(function(){n.SaveNotificationsFail()})}).fail(function(){n.SaveNotificationsFail()})}).fail(function(){VoicestormUtilities.ProvideLogin()})},n.prototype.SaveNotificationsHideMessages=function(){jQuery("#notifications-post-success").hide();jQuery("#notifications-post-failure").hide()},n.prototype.SaveNotificationsSuccess=function(){jQuery("#notifications-post-success").show();jQuery("#notifications-post-failure").hide()},n.prototype.SaveNotificationsFail=function(){jQuery("#notifications-post-success").hide();jQuery("#notifications-post-failure").show()},n.prototype.InitialiseBiography=function(n){jQuery("#bioProfilePhoto").VoiceStormProfilePhoto({profileImgSize:"Square160"});this.InitialiseBiographyName(n)},n.prototype.InitialiseBiographyName=function(n){jQuery("#bioName").text(n.firstName+" "+n.lastName)},n.prototype.initialiseStatistics=function(n){var t=this;VoiceStorm.api("GET","/user/"+n.id+"/rankings").then(function(i){if(i.leaderboards&&i.leaderboards[0]){var r=i.leaderboards[0].rank,u=i.leaderboards[0].points;t.determineRankDisplay(r);jQuery("#pointBalance").text(VoicestormUtilities.CommaFormat(u)+" points");jQuery("#totalShares").text(n.statistics.shareCount.toString()+" shares")}})},n.prototype.determineRankDisplay=function(n){jQuery(".user-rank").text("#"+n.toString());switch(n){case 1:jQuery(".user-rank").addClass("leaderboard-rank-first");break;case 2:jQuery(".user-rank").addClass("leaderboard-rank-second");break;case 3:jQuery(".user-rank").addClass("leaderboard-rank-third")}},n.prototype.initialiseChannels=function(){VoiceStorm.defaults.channelUrl="https://"+location.hostname+"/channel.html";jQuery("#connectedProfileChannels").VoiceStormProfileChannels();jQuery("#addProfileChannels").VoiceStormProfileAddChannels({submitCallback:function(n){n.status=="success"&&jQuery("#connectedProfileChannels").empty().VoiceStormProfileChannels("refresh")}})},n}(),VoicestormConfirmation=function(){function n(){jQuery(document).ready(function(){if(jQuery("#voicestormAccount").length){var n=jQuery("#voicestormAccount").val();VoiceStorm.login(n,n).then(function(){})}})}return n}()