(function(a){a.Notifi={root:null,ajaxUrl:"extensions/Notifi/ajax.php",postBackKey:"",init:function(){var b=a.Notifi;b.root=Definition("WebRoot")||"";a(".notifiToggleCBox input").click(b.toggleCBox);a(".notifiToggleLink").click(b.toggleLink)},update:function(d,g,e,b){var f,c;c=(function(){var h=1;return function(i){if(i.indexOf("Vanilla-Csrf-Check")>=0&&a.Notifi.updatePostBackKey(i)&&h++<3){f.data.PostBackKey=a.Notifi.postBackKey;a.Notifi._update(f);return true}return false}})();f={type:"POST",dataType:"text",url:this.root+this.ajaxUrl,beforeSend:b.beforeSend,success:b.success,error:function(i){var h;if(i.status===401){h=i.getResponseHeader("Www-Authenticate")}if(!h||!c(h)){b.undo&&b.undo();window.alert(i.responseText)}},data:{PostBackAction:"ChangeNotifi",Type:d,ElementID:g,Value:e,PostBackKey:this.postBackKey}};a.Notifi._update(f);return true},_update:function(b){a.ajax(a.extend({},b))},toggleCBox:function(){var h=a(this),f=h.parents(".notifiToggleCBox"),d="PreferenceProgress",e=h.attr("checked")?1:0,b,c,g;b=h.attr("name").split("_");c=b[1];g=b.length===3?b[2]:0;a.Notifi.update(c,g,e,{beforeSend:function(){f.addClass(d)},success:function(){f.removeClass(d);if(c==="ALL"){if(e===1){a("#NotifiOwnCont").hide();a("#NotifiCommentCont").hide();a("#categoriesContainer").hide();a("#discussionsContainer").hide()}else{a("#NotifiOwnCont").show();a("#NotifiCommentCont").show();a("#categoriesContainer").show();a("#discussionsContainer").show()}}if(c==="COMMENT"){if(e===1){a("#NotifiOwnCont").hide()}else{a("#NotifiOwnCont").show()}}},undo:function(){f.removeClass(d);h.attr("checked",!h.attr("checked"))}})},toggleLink:function(f){var d=a(this),h="Progress",c="notifiActive",g,b,e,i;f.preventDefault();b=d.attr("href").split("_");e=b[1];i=b.length===3?b[2]:0;if(a(".notifiSubscribe",this).hasClass(c)){g=0}else{g=1}a.Notifi.update(e,i,g,{beforeSend:function(){d.addClass(h)},success:function(){d.removeClass(h);a(".notifiSubscribe",d).toggleClass(c);a(".notifiUnSubscribe",d).toggleClass(c)},undo:function(){d.removeClass(h)}})},updatePostBackKey:function(c){var b=c.split("=");if(b.length!=2||c[0].indexOf("Vanilla-Csrf-Check")>=0){return false}this.postBackKey=b[1].replace('"',"");return true}};a(a.Notifi.init)})(jQuery.noConflict());
