function toggleVisibility(n,t){var i=$('[data-toogle-visibility="hidden"]');t?$(i).show():$(i).hide()}function isValidUrl(n){return/((http|https):\/\/(\w+:{0,1}\w*@)?(\S+)|)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(n)}function AchievementsApi(){function t(n,t){app.user.isLoggedIn&&$.getJSON(n,t,function(n){u(n);layoutUserInfoViewModel.checkLevelUp()})}function u(t){t!=null&&t.length!=0&&(i=t,n.showNextAchievement())}var n=this,i=[],r=0;n.init=function(){$(document).on("click",".mdlAchievement .btn-continue",function(){achievementsApi.showNextAchievement()})};n.checkForNewAchievements=function(){t("/api/achievements/GetUnread",null)};n.votes=function(){t("/api/achievements/votes",null)};n.comments=function(n){t("/api/achievements/comments",{discussionId:n})};n.shares=function(){t("/api/achievements/shares",null)};n.signup=function(){t("/api/achievements/signup",null)};n.markAsRead=function(n){$.getJSON("/api/achievements/MarkAsRead",{userAchievementId:n},function(){})};n.showNextAchievement=function(){var n,u,t;i.length<r||(n=i[r],u="/images/achievements/",achievementsApi.markAsRead(n.Id),t=$("#mdlAchievement-template").clone(),$(t).attr("id","#mdlAchievement-"+n.Achievement.Id),$(t).attr("data-user-achievement-id",n.Id),$(t).find(".achievement-picture").attr("src",u+n.Achievement.PictureMedium),$(t).find(".achievement-name").html(n.Achievement.Name),$(t).find(".achievement-message").html(n.Achievement.Message),$(t).modal("show"),r++)}}function ShareDiscussionViewModal(){var n=this;n.modal=$("#mdlShareContentByEmail");n.form=$(n.modal).find("#form-share-discussion-email");n.btnSend=$(n.modal).find(".btn-send");n.btnClose=$(n.modal).find(".btn-close");n.pnlError=$(n.modal).find("p.error");n.pnlErrorMessage=$(n.modal).find(".error span.error-message");n.pnlSuccess=$(n.modal).find("p.success");n.pnlSuccessEmails=$(n.modal).find("p.success .emails");n.pnlSending=$(n.modal).find(".sending");n.getFormData=function(){var t=$(n.modal).attr("data-discussion-id"),i=$(n.modal).attr("data-comment-id"),r=t?t:i;return{ReferenceId:r,UserName:$(n.modal).find("#sdYourName").val(),UserEmail:$(n.modal).find("#sdYourEmail").val(),Email:$(n.modal).find("#sdEmail").val()}};n.resetForm=function(){$(n.form).validate().resetForm();$(n.modal).find("#sdEmail").val("");$(n.pnlError).hide();$(n.pnlSuccess).hide();$(n.pnlSending).hide();$(n.form).show();$(n.btnSend).show()}}function LayoutUserInfoViewModel(){var n=this,t=parseInt($(".nav .points .user-ranking-points").html()),i=parseInt($(".nav .points .user-ranking-level").html());n.rankingPoints=ko.observable(t);n.rankingLevel=ko.observable(i);n.notificationsCount=ko.observable(0);n.load=function(){n.loadUserInfo();n.loadNotifications()};n.loadUserInfo=function(){app.user.isLoggedIn&&$.getJSON("/api/users/getCurrent",null,function(t){n.rankingLevel(t.RankingLevel);n.rankingPoints(t.RankingPoints)})};n.loadNotifications=function(){app.user.isLoggedIn&&$.getJSON("/api/messages/NotificationsUnreadTotal",null,function(t){n.notificationsCount(t.Total)})};n.checkLevelUp=function(){app.user.isLoggedIn&&$.getJSON("/api/gamification/checkLevelUp",null,function(t){t!=null&&(n.load(),$("#mdlLevelUp").find(".level").html(t.Number),$("#mdlLevelUp").modal("show"))})}}function displayPointsPopup(){toastr.info("You have earned <strong>+1 xp<\/strong>!");toastr.options={closeButton:!1,debug:!1,newestOnTop:!0,progressBar:!0,positionClass:"toast-top-center",preventDuplicates:!1,onclick:null,showDuration:"300",hideDuration:"1000",timeOut:"5000",extendedTimeOut:"1000",showEasing:"swing",hideEasing:"linear",showMethod:"fadeIn",hideMethod:"fadeOut"}}var HashSearch,achievementsApi,angularApp,app,SHARE_CONTENT_TYPE_DISCUSSION,SHARE_CONTENT_TYPE_COMMENT,layoutUserInfoViewModel;String.prototype.toElipsis=String.prototype.toElipsis||function(n){return this.length>n?this.substr(0,n-1)+"&hellip;":this};String.prototype.urlEncode=String.prototype.urlEncode||function(){return this.length>0?encodeURIComponent(this):""};$(function(){$.ajaxSetup({cache:!1});$('[data-toogle-visibility="hidden"]').hide();$(".unsortable").attr("data-defaultsort","disabled");$(".field-validation-error").each(function(n,t){var i=$(t).html();$(t).html('<span class="glyphicon glyphicon-remove-sign"><\/span>&nbsp;'+i);$(t).addClass("alert alert-danger")});$(".staging-banner a").click(function(){return $(".staging-banner").remove(),$("body").css("background-position-y",0),!1})});HashSearch=new function(){var n;this.set=function(t,i){n[t]=i;this.push()};this.remove=function(t){delete n[t];this.push()};this.get=function(t){return n[t]};this.getWithDefault=function(t,i){return this.keyExists(t)?n[t]:i};this.keyExists=function(t){return n.hasOwnProperty(t)};this.push=function(){var r=[],t,i;for(t in n)n.hasOwnProperty(t)&&(t=escape(t),i=escape(n[t]),t.length>0&&r.push(t+(i!=="undefined"?"="+i:"")));window.location.hash=r.join("&")};(this.load=function(){var t,u,i,r;for(n={},t=window.location.hash,t=t.substring(1,t.length),u=t.split("&"),r=0;r<u.length;r++)i=u[r].split("="),n[unescape(i[0])]=typeof i[1]!="undefined"?unescape(i[1]):i[1]})()};$.fn.isOnScreen=function(){var i=$(window),t={top:i.scrollTop(),left:i.scrollLeft()},n;return t.right=t.left+i.width(),t.bottom=t.top+i.height(),n=this.offset(),n.right=n.left+this.outerWidth(),n.bottom=n.top+this.outerHeight(),!(t.right<n.left||t.left>n.right||t.bottom<n.top||t.top>n.bottom)};typeof String.prototype.trim!="function"&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});typeof console=="undefined"&&(this.console={log:function(){}});angularApp=angular.module("NetivistApp",[]);app={user:{isLoggedIn:$("#nav-user-info").length>0,validateLogin:function(){return app.user.isLoggedIn||$("#mdlNotLoggedIn").modal("show"),app.user.isLoggedIn}},displaySignupSuggestion:function(){if(!app.user.isLoggedIn){var n=$.cookie("signup-suggestion")==="true";n||($("#mdlLogInSuggestion").modal("show"),$.cookie("signup-suggestion","true",{expires:7,path:"/"}))}},displaySocialFollowSuggestion:function(){var n=$.cookie("social-follow-suggestion")==="true";n||setTimeout(function(){$("#mdlFollowSuggestion").modal("show");$.cookie("social-follow-suggestion","true",{expires:7,path:"/"})},3e4)},displayCookiesWarning:function(){var n=$.cookie("cookies-warning")==="true";n||$("#cookies-warning").show()}};$(function(){$("[data-toggle='tooltip']").tooltip();$(".tooltip-toggle").tooltip();$(".footer").fadeIn(100);$('a.dropdown-toggle[data-toggle="dropdown"]').click(function(){window.location=$(this).attr("href");e.preventDefault()});app.displaySocialFollowSuggestion();app.displayCookiesWarning();achievementsApi=new AchievementsApi;achievementsApi.init();$("#btnCookiesWarningDismiss").click(function(){$.cookie("cookies-warning","true",{expires:7300,path:"/"});$("#cookies-warning").hide()});$(window).scroll(function(){$(this).scrollTop()>78?($(".subnav").addClass("fixed"),$(".subnav .navbar-brand").css("width","128px")):($(".subnav").removeClass("fixed"),$(".subnav .navbar-brand").css("width","0px"))});$(document).on("click","a.popup",function(){var n=575,t=400,i=($(window).width()-n)/2,r=($(window).height()-t)/2,u=this.href,f="status=1,width="+n+",height="+t+",top="+r+",left="+i;return window.open(u,"popupwindow",f),!1});$(window).scroll(function(){$(this).scrollTop()>178?($(".title-share-vote").addClass("stay-on-screen"),$(".stay-on-screen").stop().animate({top:"36px"},{queue:!1,duration:300})):($(".stay-on-screen").stop().animate({top:"-50px"},{queue:!1,duration:300}),$(".title-share-vote").removeClass("stay-on-screen"))});$(document).on("click",".scroll-button",function(n){n.preventDefault();var t=$(this).attr("data-scroll-target"),i=$(t),r=$(i).position().top;$(window).scrollTop(r)})});SHARE_CONTENT_TYPE_DISCUSSION="DISCUSSION";SHARE_CONTENT_TYPE_COMMENT="COMMENT";$(function(){function h(){$.post("/api/share/DiscussionByEmail",n.getFormData(),function(t){e(t);u("Email",n.getFormData().ReferenceId)})}function c(){$.post("/api/share/CommentByEmail",n.getFormData(),function(n){e(n)})}function e(t){$(n.pnlSending).hide();t.ErrorEmails!=null&&t.ErrorEmails.length>0&&($(n.pnlError).show(),$(n.pnlErrorMessage).html(t.ErrorEmails));t.SuccessEmails!=null&&t.SuccessEmails.length>0&&($(n.pnlSuccess).show(),$(n.pnlSuccessEmails).html(t.SuccessEmails));$(n.btnSend).hide()}function o(n,t,i){$.ajax({url:"/api/share/GetDiscussionShareUrl",async:!1,dataType:"json",data:{discussionId:t,network:n},success:function(n){i!=null&&i(n)}})}function s(n,t,i){$.ajax({url:"/api/share/GetCommentShareUrl",async:!1,dataType:"json",data:{commentId:t,network:n},success:function(n){i!=null&&i(n)}})}function u(n,t){$.getJSON("/api/share/discussion",{network:n,discussionId:t},function(){})}function f(n){return $(n).closest(".share-menu-container")}function t(n){var t=$(n).attr("data-discussion-id");return t||(t=$(n).attr("data-discussion-id")),t}function i(n){var t=$(n).attr("data-comment-id");return t||(t=$(n).attr("data-comment-id")),t}function r(n){var r=t(n),u=i(n);return r?SHARE_CONTENT_TYPE_DISCUSSION:u?SHARE_CONTENT_TYPE_COMMENT:null}var n=new ShareDiscussionViewModal;$(n.form).validate({rules:{sdYourEmail:{required:!0,email:!0}}});$(document).on("click",".share-email",function(u){u.preventDefault();n.resetForm();$(n.modal).removeAttr("data-discussion-id");$(n.modal).removeAttr("data-comment-id");var e=f($(this)),o=r(e);o==SHARE_CONTENT_TYPE_DISCUSSION?$(n.modal).attr("data-discussion-id",t(e)):o==SHARE_CONTENT_TYPE_COMMENT?$(n.modal).attr("data-comment-id",i(e)):alert("ERROR: Invalid Content ID.");$(n.modal).modal()});$(n.btnSend).bind("click",function(){if($(n.form).valid()){$(n.form).hide();$(n.pnlSending).show();var t=$(n.modal).attr("data-discussion-id"),i=$(n.modal).attr("data-comment-id"),r=t?t:i;r==t?h():r==i?c():alert("ERROR: Invalid Content ID.")}});$.getScript("//connect.facebook.net/en_UK/all.js",function(){FB.init({appId:$('meta[property="fb:app_id"]').attr("content"),version:"v2.8"})});$(document).on("click",".share-facebook",function(n){var e,h,c,l;n.preventDefault();e=f($(this));h=r(e);h==SHARE_CONTENT_TYPE_DISCUSSION?(c=t(e),o("facebook",c,function(n){FB.ui({method:"share",href:n},function(n){n&&!n.error_code&&u("facebook",c)})})):h==SHARE_CONTENT_TYPE_COMMENT?(l=i(e),s("facebook",l,function(n){FB.ui({method:"share",href:n},function(n){n&&!n.error_code})})):alert("ERROR: Invalid Content ID.")});$(document).on("click",".modal .share-button",function(){$(this).closest(".modal").modal("hide")});$(document).on("click",".share-dialog-button",function(){var c=575,l=400,p=($(window).width()-c)/2,w=($(window).height()-l)/2,b="status=1,width="+c+",height="+l+",top="+w+",left="+p,a=window.open("/home/share/","popupwindow",b),n=$(this).attr("data-share-network"),e=f($(this)),v=r(e),h,y;return v==SHARE_CONTENT_TYPE_DISCUSSION?(h=t(e),o(n,h,function(t){t.length>0&&(a.location=t,u(n,h))})):v==SHARE_CONTENT_TYPE_COMMENT?(y=i(e),s(n,y,function(n){n.length>0&&(a.location=n)})):alert("ERROR: Invalid Content ID."),!1});$(document).on("click",".share-content",function(n){var f,u,e;n.preventDefault();f=$(this);u=$("#mdlSocialShareButtons");$(u).removeAttr("data-discussion-id");$(u).removeAttr("data-comment-id");e=r(f);e==SHARE_CONTENT_TYPE_DISCUSSION?($(u).attr("data-discussion-id",t(f)),$(u).find(".share-title").html("Share Discussion")):e==SHARE_CONTENT_TYPE_COMMENT?($(u).attr("data-comment-id",i(f)),$(u).find(".share-title").html("Share Comment")):alert("ERROR: Invalid Content ID.");$(u).modal("show")})});layoutUserInfoViewModel=null;$(function(){var t=$("#nav-user-info"),n;$(t)[0]!=null&&(n=new LayoutUserInfoViewModel,layoutUserInfoViewModel=n,ko.applyBindings(n,$(t)[0]),n.load())});angularApp.service("categoriesService",["$http",function(n){this.findTopLevel=function(t){n.get("/api/categories/top-level").then(function(n){t!=null&&t(n)})};this.findTree=function(t){n.get("/api/categories/tree").then(function(n){t!=null&&t(n)})}}]);angularApp.controller("NavigationController",["$scope","$timeout","categoriesService",function(n,t,i){n.navigationLoaded=!1;n.menuCategories=null;var r=!1;n.init=function(){i.findTopLevel(function(i){n.menuCategories=i.data;t(function(){n.navigationLoaded=!0},400)})};n.loadCategoryTree=function(){r||i.findTree(function(t){n.menuCategories=t.data;r=!0})};n.init()}])