mesa.home.InviteUtil=new function(){this.enterEmailText="Enter emails, separate with comma";this.openSimplePopup=function(c){new mesa.Popup.MessageWindow(pageContext.basePath,"Share & Invite Others",pageContext.basePath+"home/inviteGame.jsp",480,c?440:320,true,c).show()};this.openFullPopup=function(c,d){new mesa.Popup.MessageWindow(pageContext.basePath,"Spread the word about Muse Games",pageContext.basePath+"home/invite.jsp",935,470,true,{mode:c,emails:d},function(e){}).show()};this.addFriend=function(c,d){new mesa.Ajax.Request("user/makeFriend.do",{userId:c},function(e){if(e){if(d){d()}}}).send()};var a,b;this.openAddFriendPanel=function(e,d){var c=mesa.WebUtils.findElementPosition(d);if(!a){a=document.createElement("div");a.className="addFriendPanel";document.body.appendChild(a)}a.innerHTML=mesa.WebUtils.applyTemplate("addFriendPanel",{userId:e});a.style.left=c.x+"px";a.style.top=c.y+"px";if(!a.visible()){a.show()}b=d};this.closeAddFriendPanel=function(){a.hide()};this.addFriendFromPanel=function(c){mesa.home.InviteUtil.addFriend(c,function(){mesa.home.InviteUtil.closeAddFriendPanel();b.replace("Added!")})};this.previewEmail=function(c){new mesa.Ajax.Request("user/previewInvite.do",{message:c.strip()},function(d){d=d.replace(/<\/?a[^>]*>/gi,"");new parent.mesa.Popup.MessageWindow(pageContext.basePath,"Invite Preview","home/previewInvite.jsp",770,550,true,d,null,null).show()}).send()};this.parseEmailString=function(c,d){var e=[];if(c==mesa.home.InviteUtil.enterEmailText){c=""}c=c.replace(/ /g,"").replace(/[:;]/g,",");$A(c.split(",")).each(function(f){if((!d&&f)||mesa.util.Utils.validateEmail(f)){e.push(f)}});return e};this.sendEmailInvites=function(d,f,e,c){var g=mesa.home.InviteUtil.parseEmailString(d,true);if(g.length==0){alert("Please enter an email address to invite");return}new mesa.Ajax.Request("user/sendInvitation.do",{message:f.strip(),email:g.join(",")},c).send();if(e){e()}};this.sendFacebookInvites=function(e,d,g,f,c){if(e.length==0){alert("Please check at least one user to invite");return}new mesa.Ajax.Request("user/sendInvitation.do",{facebookId:e.join(","),sessionKey:d,message:g.strip()},c).send();if(f){f()}}}();