function requestFriend(friendId){Ext.Ajax.request({url:webRoot+"/lib/ajax/site/member/profile/tab/account/friend/request.php",success:function(){Ext.get("member-link-"+friendId).dom.innerHTML="Request sent";},failure:function(){console.log();},params:{friendId:friendId}});}
Ext.namespace("Spire","Spire.app");Spire.QueryString=Ext.urlDecode((document.location+"").replace(/#$/,"").split("?")[1]);Spire.app.FeedItem=function(el){this.el=Ext.get(el);this.id=this.el.dom.id.split("-")[1];this.optionContainer=Ext.get(Ext.query(".feedOption",this.el.dom)[0]);if(this.optionContainer){this.optionContainer.hide();}
this.options={comment:Ext.get(Ext.query(".feedOption .comment",this.el.dom)[0])}
var formContainer=this.el.dom;var commentContainer=Ext.query(".itemCommentContainer .commentContainer",this.el.dom)[0];if(commentContainer){this.commentFormContainer=Ext.get(Ext.query(".commentItem",this.el.dom)[0]);this.commentFormContainer.setVisibilityMode(Ext.Element.DISPLAY);this.commentFormContainer.hide();textarea=Ext.query("textarea",formContainer)[0];textarea.id=Ext.id();textarea=Ext.get(textarea);textarea.on("focus",function(e){var el=e.getTarget();if(el.value==="Write a comment..."){el.value="";}});textarea.on("blur",function(e){var el=e.getTarget();if(el.value===""){el.value="Write a comment...";}});this.commentForm=new Spire.app.CommentForm({commentBody:textarea,commentButton:Ext.query(".submit",formContainer)[0],addCommentUrl:webRoot+"/lib/ajax/site/member/profile/tab/general/comment/add.php?activity_id="+this.id});this.commentForm.init();this.commentForm.on("commentadded",function(){this.commentForm.config.commentBody.dom.value="Write a comment...";this.commentFormContainer.hide();Ext.get(Ext.query("input",this.commentForm.config.commentButton.dom)[0]).removeClass("loading");},this);this.commentForm.on("beforeadd",function(){Ext.get(Ext.query("input",this.commentForm.config.commentButton.dom)[0]).addClass("loading");},this)
this.commentFeed=new Spire.app.CommentFeed({getCommentsUrl:webRoot+"/lib/ajax/site/member/profile/tab/general/comment/get.php?activity_id="+this.id,removeCommentUrl:webRoot+"/lib/ajax/site/member/profile/tab/general/comment/remove.php?activity_id="+this.id,commentContainer:commentContainer,perPage:5,commentForm:this.commentForm});this.commentFeed.refreshComments(function(){this.commentFeed.showPage(1);},this);this.commentForm.config.commentButton;}
this.linkHandlers();}
Spire.app.FeedItem.prototype={linkHandlers:function(){var mouseover=function(e){clearTimeout(this.throttle);this.hideAllOptions();if(this.options&&this.optionContainer){if(!this.optionContainer.isStyle("visibility","visible")){this.optionContainer.show();}}}
var mouseout=function(e){this.throttle=setTimeout((function(){if(this.optionContainer){this.optionContainer.hide();}}).createDelegate(this),100);}
var commentClick=function(e){e.stopEvent();if(this.commentFormContainer){this.commentFormContainer.show();}}
return function(){if(Spire.loggedIn){this.el.on("mouseover",mouseover,this);this.el.on("mouseout",mouseout,this);if(this.options.comment){this.options.comment.on("click",commentClick,this);}}}}(),hideAllOptions:function(){Ext.select(".feedOption").hide();}}
Spire.app.StatusUpdate=function(){return{init:function(){this.status=Ext.get(Ext.query("#memberName .status")[0]);this.changeStatusField=Ext.get(Ext.query("#status")[0]);this.changeStatusButton=Ext.get(Ext.query(".statusUpdateContainer input")[1]);this.linkHandlers();},linkHandlers:function(){if(this.changeStatusButton){this.changeStatusButton.on("click",function(e){e.stopEvent();if(!Ext.get(e.getTarget()).hasClass("loading")){var el=Ext.get(e.getTarget());if(this.changeStatusField.dom.value!==""&&this.changeStatusField.dom.value!=="is "){el.addClass("loading");Ext.Ajax.request({url:webRoot+"/index.php?cmd=member&sec=profile&act=view&id="+Spire.QueryString.id+"&subsec=general&tiersec=status&subact=update",success:function(r){this.updateStatus(this.changeStatusField.dom.value);this.changeStatusField.dom.value="is ";el.removeClass("loading");},params:{status:this.changeStatusField.dom.value},scope:this});}}},this);}},updateStatus:function(status){this.status.hide(true);(function(){this.status.update(status);this.status.show(true);}).createDelegate(this).defer(500);}}}()
Ext.onReady(function(){Ext.each(Ext.query(".feedItem"),function(el){var feedItem=new Spire.app.FeedItem(el);});Spire.app.StatusUpdate.init();});