;(function(){function r(val,args){for(var x=0;x<args.length;x++){val=val.replace('{'+x+'}',args[x]);}
return val;}
function p(){var val=arguments[0];var ret;if(val.indexOf('{0}')!=-1)
ret=function(){return r(val,arguments);}
else ret=function(){return val;}
for(var x=1;x<arguments.length;x++){for(var a in arguments[x])
ret[a]=arguments[x][a];}
return ret;}
window.messages=({"dailyMessages":{"none":p("None")},"person":{"suspend":{"failed":p("Suspension failed"),"label":p("Suspend"),"confirm":p("Do you really want to suspend {0}?")},"createTribe":{"label":p("Create a tribe"),"close":{"label":p("Close")}},"reinstate":{"failed":p("Failed to reinstate {0}"),"label":p("Reinstate"),"confirm":p("Do you really want to reinstate {0}?")},"conversationSubs":{"none":{"ofanytype":p("None")}}},"mobileEmailForm":{"lastName":{"label":p("Last Name")},"submit":{"label":p("Done!")},"email":{"label":p("Email")},"service":{"fail":{"error":p("Apologies, an error has occurred")}},"firstName":{"label":p("First Name")}},"tag":{"number":{"subscribed":p("Subscribed: {0}")}},"promo":{"delete":{"confirm":p("Are you sure?")}},"tribe":{"name":{"availability":{"short":p("Tribe name is too short"),"taken":p("Tribe name is taken"),"available":p("Tribe name is available"),"long":p("Tribe name is too long")}},"members":{"open":p("Open"),"close":p("Close")}},"tribeMessageForm":{"to":{"who":{"emptytext":p("Text tribe members"),"close":p("Close")}}},"moderate":{"campaign":{"enable":p("Switch on"),"disable":p("Switch off")}},"sms":{"tribes":{"enable":{"heading":{"global":{"disabled":p("Make sure you have enabled the option to receive text messages from Commutineer on your mobile, otherwise your tribes will not be able to text you. You'll also not receive any subscriptions if it's disabled.")}}}}},"outOfCredit":{"text":p("(requires text credits)")},"mobileOrWebLoginForm":{"web":{"link":p("Registered on our website?"),"heading":p("Web Login")},"mobile":{"link":p("Signed up by mobile?"),"heading":p("Mobile Login")}},"tagMessageForm":{"cool":{"send":p("Cool"),"sendsubscribe":p("Cool and subscribe")},"flirt":{"send":p("Flirt"),"sendsubscribe":p("Flirt and subscribe")},"news":{"send":p("News"),"sendsubscribe":p("News and subscribe")},"rant":{"send":p("Rant"),"sendsubscribe":p("Rant and subscribe")},"flavour":{"remove":p("Remove")},"vanilla":{"send":p("Send"),"sendsubscribe":p("Send and subscribe")}},"username":{"availability":{"short":p("User name is too short"),"taken":p("User name is taken"),"available":p("User name is available"),"long":p("User name is too long")}},"mobileUsernameCommand":{"mobilePassword":{"blank":p("Password is required"),"minSize":{"notmet":p("Password must be at least 6 characters long")}},"mobilePasswordConfirm":{"non":{"match":p("The password and password confirmation did not match")}},"mobileUsername":{"blank":p("User name is required"),"size":{"toobig":p("Please choose a user name from 2 up to 10 characters long")}}},"conversation":{"subscribe":{"failed":p("An error occurred subscribing to the conversation"),"value":p("Subscribe"),"label":p("Text replies to my mobile"),"success":p("You will now receive replies to this conversation on your mobile"),"tooltip":p("Receive replies to this conversation on your mobile")},"tribeReply":{"all":p("Select All")},"unsubscribe":{"failed":p("An error occurred unsubscribing from the conversation"),"value":p("Unsubscribe"),"label":p("Stop texting replies"),"success":p("You will no longer receive replies to this conversation on your mobile"),"tooltip":p("Stop texting replies to this conversation to my mobile")},"unsubscribeAll":{"success":p("You will no longer receive replies to these conversations on your mobile")}},"mobileEmailCommand":{"mobileEmail":{"blank":p("Email is required"),"email":{"invalid":p("Please provide a valid email address")},"size":{"toobig":p("The email address is too long")}},"mobileLastName":{"blank":p("Last name is required"),"size":{"toobig":p("Abbreviate your last name if it is longer than 80 characters")}},"mobileFirstName":{"blank":p("First name is required"),"size":{"toobig":p("Abbreviate your first name if it is longer than 80 characters")}}},"profile":{"firstReplyToMyMobile":{"error":p("There was an error updating your mobile preferences."),"button":{"off":{"title":p("Click to stop receiving the first reply to the conversation you started from your mobile")},"on":{"title":p("Click to receive the first reply to the conversation you started from your mobile")}},"off":{"confirmation":p("You will no longer receive the first reply to the conversation you started from your mobile.")},"on":{"confirmation":p("You have successfully enabled receiving the first reply on your mobile.")},"info":{"2":p("To receive more replies to the conversation as text messages, subscribe to the conversation from your mobile by texting START followed by a space and the conversation code, or click Subscribe next to the conversation on the Web site."),"1":p("This option must be enabled if you want to receive the first reply to a conversation you started from your mobile as a text message. This will give you the conversation code allowing you to also reply from your mobile. You'll need to have text credits in your account. Please read our <a href='/fees'>fees<\/a>.")}},"receiveContentOnMobile":{"error":p("There was an error updating your mobile preferences"),"button":{"off":{"title":p("Click to switch off all text messages sent to your mobile")},"on":{"title":p("Click to switch on all text messages sent to your mobile")}},"off":{"confirmation":p("You will no longer receive commutineer content on your mobile.")},"on":{"confirmation":p("You have successfully enabled receiving content on your mobile.")},"info":p("This option must be enabled for you to receive text messages from Commutineer on your mobile.")},"forwardMyMobileTribeMessagesToOtherMembers":{"error":p("There was an error updating your tribe forwarding configuration."),"button":{"off":{"title":p("Click to stop forwarding all tribe text messages from your mobile")},"on":{"title":p("Click to start forwarding all tribe text messages from your mobile")}},"off":{"confirmation":p("We will no longer forward your messages to your fellow tribe members' mobiles.")},"on":{"confirmation":p("You have successfully enabled tribe forwarding from your mobile.")},"info":p("This option must be enabled if you want Commutineer to forward text messages you send your tribe to the mobiles of all tribe members. You'll need to have text credits in your account. Please read our <a href='/fees'>fees<\/a>.")},"tribe":{"allow":{"button":{"tribeOn":{"title":p("Click to enable {0} tribe text messaging to your mobile")},"tribeOff":{"title":p("Click to stop {0} tribe text messaging to your mobile")}},"failed":p("There was an error updating allowing {0} to send you text messages."),"off":{"confirmation":p("You will no longer receive text messages from the {0} tribe.")},"on":{"confirmation":p("You will receive text messages from the {0} tribe.")}}},"tribesAllowedToTxtMe":{"disabled":p("Enable text messaging in your mobile preferences before you can configure this tribe allowance."),"info":p("For each of your tribes, tell us whether you want the tribe's text messages to be sent to your mobile. The sender pays for it. It does not cost you to receive it.")}}})})();document.observe("dom:loaded",function(){if(EnergizedWork.EventHandlerRegistrar){EnergizedWork.EventHandlerRegistrar.activate();}
EnergizedWork.Application.registerDefaultResponders();});EnergizedWork.EventHandlerRegistrar.executeOnLoad(function(){EnergizedWork.Application.initPage();});EnergizedWork.Application={initPage:function(){this.showTabsInErrorState();this.showToggleControlsInErrorState();this.attachHoverStates();},showTabsInErrorState:function(){var tabPanesWithErrors=$$('#contentAreaLeft .tabPane .errors');if(tabPanesWithErrors.length){var tabPane=Element.up(tabPanesWithErrors[0],'.tabPane');var tabLink=$$('a[href$=#'+tabPane.id+']')[0];EnergizedWork.Application.showTribePageTabContent(tabLink);}},showToggleControlsInErrorState:function(){var toggleControlsWithErrors=$$('.toggleControlContent .errors');toggleControlsWithErrors.each(function(theControl){var toggleControl=Element.up(theControl,'div.toggleControl');openToggleControl(toggleControl.id);});},attachHoverStates:function(){EnergizedWork.EventHandlerRegistrar.registerOnLoad('reportThisHoverOn','input.iconReportThis','mouseover','EnergizedWork.Application.reportThisHoverOn');EnergizedWork.EventHandlerRegistrar.registerOnLoad('reportThisHoverOff','input.iconReportThis','mouseout','EnergizedWork.Application.reportThisHoverOff');},reportThisHoverOn:function(eventData,icon){icon.src=icon.src.replace('report-this-light.png','report-this-dark.png');},reportThisHoverOff:function(eventData,icon){icon.src=icon.src.replace('report-this-dark.png','report-this-light.png');},addRolledUpMobilesLinkToConversationAnywhereBox:function(disable,loggedInAndNoCredit){var containerDiv=$('conversationAnywhereMobiles');if(containerDiv){var rolledUpMessage=EnergizedWork.Application.message('tribeMessageForm.to.who.emptytext');var outOfCreditMessage=EnergizedWork.Application.message('outOfCredit.text');var rolledUpHTML='<span>'+rolledUpMessage+'</span>';if(loggedInAndNoCredit)rolledUpHTML+=(' '+outOfCreditMessage);var rolledUpDiv=new Element('div').writeAttribute('id','conversationAnywhereMobilesRolledUp').addClassName('noData').update(rolledUpHTML);Element.insert(containerDiv,{bottom:rolledUpDiv});if(loggedInAndNoCredit){rolledUpDiv.addClassName('outOfCredit');}
if(!disable&&!loggedInAndNoCredit){Event.observe(rolledUpDiv,'click',this.toggleMobilesInConversationAnywhereBox);}
var mobilesDiv=$('conversationAnywhereMobileList');mobilesDiv.removeClassName('jsHidden').hide();}},createCloseTribeMobilesLink:function(arrowUrl){var closeMessage=EnergizedWork.Application.message('tribeMessageForm.to.who.close');if(arrowUrl)closeMessage+='<img src="'+arrowUrl+'" />';var closeLink=new Element('a').writeAttribute('id','closeTribeMobilesForm').writeAttribute('href','#').update(closeMessage);var closeLinkWrapper=new Element('div').writeAttribute('id','closeTribeMobilesFormWrapper');Element.insert(closeLinkWrapper,{bottom:closeLink});var containerForLink=$$('#messageForm .sendToMobileWrapper')[0];Element.insert(containerForLink,{bottom:closeLinkWrapper});Event.observe(closeLink,'click',this.toggleMobilesInConversationAnywhereBox);},updateRolledUpMobilesText:function(){var rolledUpDiv=$('conversationAnywhereMobilesRolledUp');var checkedNames=[];var checkboxes=$$('#conversationAnywhereMobileList input');checkboxes.each(function(theCheckBox){if(theCheckBox.checked){var username=Element.next(theCheckBox).innerHTML;checkedNames[checkedNames.length]=username.strip();}});if(checkedNames.length==0){var rolledUpMessage=EnergizedWork.Application.message('tribeMessageForm.to.who.emptytext');rolledUpDiv.addClassName('noData');}else{var rolledUpMessage=checkedNames.join(', ');rolledUpDiv.removeClassName('noData');}
rolledUpDiv.select('span')[0].update(rolledUpMessage);},toggleMobilesInConversationAnywhereBox:function(eventData){Event.stop(eventData);var rolledUpDiv=$('conversationAnywhereMobilesRolledUp');var mobilesDiv=$('conversationAnywhereMobileList');if(mobilesDiv.visible()){Element.hide(mobilesDiv);Element.show(rolledUpDiv);EnergizedWork.Application.updateRolledUpMobilesText();}else{Element.show(mobilesDiv);Element.hide(rolledUpDiv);}},showReplyForm:function(event,link){var preamble=this.containerCtx+'_replyLink_';var uri=link.id.substring(preamble.length);var container=$(this.containerCtx+'_conversationContainer_'+uri);var conversationWrapper=container.up('.conversationWrapper');conversationWrapper.addClassName('replyFormOpen');container.select('div.message').each(function(element){element.addClassName('showInline');});container.select('form.replyForm').each(function(theForm){theForm.addClassName('showInline');theForm.elements['text'].focus();});link.addClassName('hidden');event.stop();},hideReplyForm:function(event,link){var preamble=this.containerCtx+'_closeLink_';var uri=link.id.substring(preamble.length);var container=$(this.containerCtx+'_conversationContainer_'+uri);var conversationWrapper=container.up('.conversationWrapper');conversationWrapper.removeClassName('replyFormOpen');container.select('div.message').each(function(element){element.removeClassName('showInline');});container.select('form.replyForm').each(function(element){element.removeClassName('showInline');});var replyLink=$(this.containerCtx+'_replyLink_'+uri);replyLink.removeClassName('hidden');event.stop();},submitReply:function(event,replyForm){EnergizedWork.Application.clearFieldErrors(replyForm);EnergizedWork.Application.clearFlashMessages();var containerId=EnergizedWork.Application.findAncestor(replyForm,'conversationListContainer_').id;var containerCtx=replyForm.id.split('_')[0];var ref=replyForm.id.split('_')[2];var parameters={'conversationContext.name':containerCtx,text:$F(containerCtx+'_text_'+ref)};if($(containerCtx+'_tags_'+ref)){parameters['tags']=$F(containerCtx+'_tags_'+ref);}
replyForm.getInputs('hidden').each(function(field){parameters[field.name]=field.value;});new Ajax.Request(this.url,{parameters:parameters,onSuccess:function(transport){var container=$(containerId);if(transport.responseJSON.success){EnergizedWork.Application.hideConversations(container);container=EnergizedWork.Application.replaceConversations(container,transport.responseJSON.html);EnergizedWork.Application.updateGlobalFlashMessage(transport.responseJSON.flashMessage);EnergizedWork.Application.show(container);}else{var replyForm=$(containerCtx+'_replyForm_'+ref);if(transport.responseJSON.flashError){EnergizedWork.Application.reportFormErrors(replyForm,transport.responseJSON.flashError);}
EnergizedWork.Application.reportFieldErrors(replyForm,$H(transport.responseJSON.errors),ref);}}});event.stop();},submitTribeReply:function(event,replyForm){EnergizedWork.Application.clearFieldErrors(replyForm);EnergizedWork.Application.clearFlashMessages();var containerId=EnergizedWork.Application.findAncestor(replyForm,'conversationListContainer_').id;var containerCtx=replyForm.id.split('_')[0];var ref=replyForm.id.split('_')[2];var parameters={'conversationContext.name':containerCtx,tags:$F(containerCtx+'_tags_'+ref),text:$F(containerCtx+'_text_'+ref)};replyForm.getInputs('hidden').each(function(field){parameters[field.name]=field.value;});replyForm.select('.recipient').each(function(element){if(element.checked){parameters[element.name]='on';}});new Ajax.Request(this.url,{parameters:parameters,onSuccess:function(transport){var container=$(containerId);if(transport.responseJSON.success){EnergizedWork.Application.hideConversations(container);container=EnergizedWork.Application.replaceConversations(container,transport.responseJSON.html);EnergizedWork.Application.updateGlobalFlashMessage(transport.responseJSON.flashMessage);EnergizedWork.Application.updateAllBalanceMessages(transport.responseJSON.balanceMessage);EnergizedWork.Application.show(container);}else{if(transport.responseJSON.flashError){EnergizedWork.Application.updateGlobalFlashError(transport.responseJSON.flashError);}
var replyForm=$(containerCtx+'_replyForm_'+ref);EnergizedWork.Application.reportFieldErrors(replyForm,$H(transport.responseJSON.errors));}}});event.stop();},hideConversations:function(container){container.addClassName('hidden');container.select('div.message').each(function(element){element.removeClassName('showInline');});container.select('form.replyForm').each(function(element){element.reset();element.removeClassName('showInline');});container.select('a.reply').each(function(element){element.removeClassName('hidden');});container.select('.errors').each(function(element){element.remove();});},replaceConversations:function(oldContainer,html){oldContainer.update('');oldContainer.replace(html);addCharCounters();return $(oldContainer.id);},isFlavourEnabled:false,enableFlavourTimeoutId:undefined,addToneIconBehaviour:function(params){EnergizedWork.EventHandlerRegistrar.registerOnLoad('flavourSelect','a.flavourPicker','click','EnergizedWork.Application.selectFlavour',params);EnergizedWork.EventHandlerRegistrar.registerOnLoad('flavourPreviewOn','a.flavourPicker','mouseover','EnergizedWork.Application.previewFlavour',{show:true});EnergizedWork.EventHandlerRegistrar.registerOnLoad('flavourPreviewOff','a.flavourPicker','mouseout','EnergizedWork.Application.previewFlavour',{show:false});if(params.forceEnabled){EnergizedWork.Application.enableFlavour();}else{EnergizedWork.EventHandlerRegistrar.registerOnLoad('flavourEnable','#locations','keyup','EnergizedWork.Application.enableFlavourIfLocationsTag');}},enableFlavourIfLocationsTag:function(event){if(this.enableFlavourTimeoutId!=undefined){window.clearTimeout(this.enableFlavourTimeoutId);};this.enableFlavourTimeoutId=setTimeout(function(){EnergizedWork.Application.enableFlavourTimeoutId=undefined;new Ajax.Request('/tag/hasLocationTagAjax',{parameters:{places:$F('locations')},onSuccess:function(transport){if(transport.responseJSON.hasLocationTag){EnergizedWork.Application.enableFlavour();}else{EnergizedWork.Application.disableFlavour();}}});},300);},disableFlavour:function(){if(EnergizedWork.Application.isFlavourEnabled){EnergizedWork.Application.removeFlavour();EnergizedWork.Application.isFlavourEnabled=false;$('conversationAnywhereTones').addClassName('disabled');}},enableFlavour:function(){if(!EnergizedWork.Application.isFlavourEnabled){EnergizedWork.Application.isFlavourEnabled=true;$('conversationAnywhereTones').removeClassName('disabled');}},previewFlavour:function(event,link){if(EnergizedWork.Application.isFlavourEnabled){var flavour=link.id;var messageForm=$('conversationAnywhere');if(this.show===true){if(!messageForm.savedFlavour||messageForm.savedFlavour==''){messageForm.savedFlavour=messageForm.className;}
EnergizedWork.Application.addFlavour(messageForm,flavour);}else{if(messageForm.savedFlavour){messageForm.className=messageForm.savedFlavour;messageForm.savedFlavour='';}}}},addFlavour:function(element,flavour){if(EnergizedWork.Application.isFlavourEnabled){var oldClassNames=$w(element.className);var classNamesToKeep=oldClassNames.without('vanilla','rant','flirt','cool','news');element.className=classNamesToKeep;element.addClassName(flavour);}},selectFlavour:function(event,link){link.blur();if(EnergizedWork.Application.isFlavourEnabled){var flavour=link.id;var messageForm=$('conversationAnywhere');EnergizedWork.Application.addFlavour(messageForm,flavour);messageForm.savedFlavour=messageForm.className;var tonesDiv=$('conversationAnywhereTones');Element.hide(tonesDiv);var removeFlavourMessage=EnergizedWork.Application.message('tagMessageForm.flavour.remove')+' '+flavour;var removeSelectedFlavourLink=$('conversationAnywhereSelectedToneIcon');if(!removeSelectedFlavourLink){removeSelectedFlavourLink=new Element('a').writeAttribute('id','conversationAnywhereSelectedToneIcon').writeAttribute('title',removeFlavourMessage);}
removeSelectedFlavourLink.update(removeFlavourMessage);removeSelectedFlavourLink.className=flavour;var parentFieldset=Element.up(link,'fieldset');Element.insert(parentFieldset,{bottom:removeSelectedFlavourLink});Event.observe(removeSelectedFlavourLink,'click',EnergizedWork.Application.removeFlavour.bindAsEventListener(null,this));$('flavour').value=flavour;$('send').value=eval('messages.tagMessageForm.'+flavour+'.send()');$('sendsubscribe').value=eval('messages.tagMessageForm.'+flavour+'.sendsubscribe()').unescapeHTML();}
event.stop();},removeFlavour:function(event,params){var removeSelectedFlavourLink=$('conversationAnywhereSelectedToneIcon');if(removeSelectedFlavourLink){Element.remove(removeSelectedFlavourLink);var tonesDiv=$('conversationAnywhereTones');tonesDiv.removeClassName('jsHidden');Element.show(tonesDiv);var messageForm=$('conversationAnywhere');EnergizedWork.Application.addFlavour(messageForm,'vanilla');$('flavour').value='vanilla';$('send').value=eval('messages.tagMessageForm.vanilla.send()');$('sendsubscribe').value=eval('messages.tagMessageForm.vanilla.sendsubscribe()').unescapeHTML();}},updateAllBalanceMessages:function(message){$$('#statusBarBalance span').each(function(element){element.update(message);});},conversationAnywhereTextObserver:function(event){var container=$('conversationAnywhere');var send=container.select('#send')[0];var sendsubscribe=container.select('#sendsubscribe')[0];var targetTextArea=container.select('#text')[0];var targetTags=container.select('#tags')[0];var targetLocations=container.select('#locations')[0];if((targetTextArea.value!=null&&(targetTags.value!=null||targetLocations.value!=null))&&(!targetTextArea.value.blank())&&(!targetTags.value.blank()||!targetLocations.value.blank())){if(send.disabled){send.enable();sendsubscribe.enable();}}else{if(!send.disabled){send.disable();sendsubscribe.disable();}}},setupConversationAnywhereValidation:function(container){container.select('#send')[0].disable();container.select('#sendsubscribe')[0].disable();container.select('#text')[0].observe('keyup',this.conversationAnywhereTextObserver);container.select('#tags')[0].observe('keyup',this.conversationAnywhereTextObserver);container.select('#locations')[0].observe('keyup',this.conversationAnywhereTextObserver);},submitGlobalSmsToggling:function(event,checkbox){var messageAfterSuccessfulToggle;var ajaxURL='/profile/setGlobalSmsAjax';if(checkbox.checked){messageAfterSuccessfulToggle='profile.receiveContentOnMobile.button.off.title';}else{messageAfterSuccessfulToggle='profile.receiveContentOnMobile.button.on.title';}
new Ajax.Request(ajaxURL,{parameters:{smsOn:checkbox.checked},onSuccess:function(transport){EnergizedWork.Application.handleProfileToggleSuccess(Object.clone(transport.responseJSON),checkbox,EnergizedWork.Application.message(messageAfterSuccessfulToggle));if(checkbox.checked){EnergizedWork.Application.activeTribesOnGlobalSms();}else{EnergizedWork.Application.deactiveTribesOnGlobalSms();}}});},submitFirstReplyToMobileToggling:function(event,checkbox){var messageAfterSuccessfulToggle;var ajaxURL='/profile/setFirstReplyAjax';if(checkbox.checked){messageAfterSuccessfulToggle='profile.firstReplyToMyMobile.button.off.title';}else{messageAfterSuccessfulToggle='profile.firstReplyToMyMobile.button.on.title';}
new Ajax.Request(ajaxURL,{parameters:{firstReplyOn:checkbox.checked},onSuccess:function(transport){EnergizedWork.Application.handleProfileToggleSuccess(Object.clone(transport.responseJSON),checkbox,EnergizedWork.Application.message(messageAfterSuccessfulToggle));}});},submitTribeForwardToggling:function(event,checkbox){var messageAfterSuccessfulToggle;var ajaxURL='/profile/setTribeForwardingAjax';if(checkbox.checked){messageAfterSuccessfulToggle='profile.forwardMyMobileTribeMessagesToOtherMembers.button.off.title';}else{messageAfterSuccessfulToggle='profile.forwardMyMobileTribeMessagesToOtherMembers.button.on.title';}
new Ajax.Request(ajaxURL,{parameters:{tribeForwardingOn:checkbox.checked},onSuccess:function(transport){EnergizedWork.Application.handleProfileToggleSuccess(Object.clone(transport.responseJSON),checkbox,EnergizedWork.Application.message(messageAfterSuccessfulToggle));}});},submitTribeToggling:function(event,checkbox){var messageAfterSuccessfulToggle;var ajaxURL='/profile/setTribeAjax';if(checkbox.checked){messageAfterSuccessfulToggle='profile.tribe.allow.button.tribeOff.title';}else{messageAfterSuccessfulToggle='profile.tribe.allow.button.tribeOn.title';}
var formValues=Form.serialize(checkbox.form,true);new Ajax.Request(ajaxURL,{parameters:{tribeOn:checkbox.checked,tribeUri:formValues.tribeUri,tribeName:formValues.tribeName},onSuccess:function(transport){EnergizedWork.Application.handleProfileToggleSuccess(Object.clone(transport.responseJSON),checkbox,EnergizedWork.Application.message(messageAfterSuccessfulToggle,[formValues.tribeName]));}});},handleProfileToggleSuccess:function(response,checkbox,checkboxTitle){if(response.success){checkbox.title=checkboxTitle;EnergizedWork.Application.updateGlobalFlashMessage(response.flashMessage);}else{EnergizedWork.Application.updateGlobalFlashError(response.flashError);}},setUpTribePageTabs:function(){var validTabBookmarks=[];var tribePageTabLinks=$$('#tabArea a');tribePageTabLinks.each(function(theLink){validTabBookmarks[validTabBookmarks.length]=theLink.href.substr(theLink.href.indexOf('#'));var theBookmark=EnergizedWork.Application.getBookmarkFromHref(theLink);if(theBookmark!=''){Event.observe(theLink,'click',EnergizedWork.Application.showTribePageTabContent);var contentDiv=$(theBookmark);if(contentDiv&&contentDiv.hasClassName('jsHidden'))contentDiv.removeClassName('jsHidden').hide();}});var theHash=window.location.hash;var validTabIndex=validTabBookmarks.indexOf(theHash);if(theHash!=''&&validTabIndex!=-1){EnergizedWork.Application.showTribePageTabContent(tribePageTabLinks[validTabIndex]);}else{var tabPanesWithErrors=$$('#contentAreaLeft .errors');if(!tabPanesWithErrors.length){Element.addClassName(tribePageTabLinks[0],'active');}}},showTribePageTabContent:function(eventData){var calledByPrototype=(eventData.type&&eventData.type=='click');var clickedLink=eventData;if(calledByPrototype)clickedLink=Event.element(eventData);clickedLink.blur();var tribePageTabLinks=$$('#tabArea a');tribePageTabLinks.each(function(theLink){var theBookmark=EnergizedWork.Application.getBookmarkFromHref(theLink);if(theBookmark!=''){var contentDiv=$(theBookmark);if(contentDiv)contentDiv.hide();}
Element.removeClassName(theLink,'active');});var theBookmark=EnergizedWork.Application.getBookmarkFromHref(clickedLink);var contentDiv=$(theBookmark);if(contentDiv)contentDiv.show();Element.addClassName(clickedLink,'active');if(calledByPrototype)Event.stop(eventData);},addTribeMembersToggleLink:function(){var containerDiv=$('tribeMembersListData');if(containerDiv){var openMessage=EnergizedWork.Application.message('tribe.members.open');var toggleLink=new Element('a').writeAttribute('id','tribeMembersListToggleLink').update(openMessage);Element.insert(containerDiv,{bottom:toggleLink});Event.observe(toggleLink,'click',this.toggleTribeMembersList);}},toggleTribeMembersList:function(eventData){var theLink=Event.element(eventData);theLink.blur();var parentDiv=$('tribeMembersListContainer');if(parentDiv.hasClassName('showInstructions')){var closeMessage=EnergizedWork.Application.message('tribe.members.close');theLink.update(closeMessage);parentDiv.removeClassName('showInstructions');}else{var openMessage=EnergizedWork.Application.message('tribe.members.open');theLink.update(openMessage);parentDiv.addClassName('showInstructions');}},activeTribesOnGlobalSms:function(){var tribeListContainer=$('tribeListContainer');if(tribeListContainer){EnergizedWork.Application.show(tribeListContainer);}
var tribesDisabledMessage=$('tribesDisabledInfo');if(tribesDisabledMessage)tribesDisabledMessage.remove();$$('form.tribeAllowedForm').each(function(form){var theCheckbox=form.select('input[type=checkbox]')[0];var theButton=form.select('input[type=submit]')[0];theCheckbox.disabled=false;theButton.disabled=false;var tribeOnOff=(theCheckbox.checked)?'tribeOff':'tribeOn';var tribeName=form.elements['tribeName'].value;theCheckbox.title=EnergizedWork.Application.message('profile.tribe.allow.button.'+tribeOnOff+'.title',[tribeName]);});},deactiveTribesOnGlobalSms:function(){var tribeListContainer=$('tribeListContainer');if(tribeListContainer){EnergizedWork.Application.hide(tribeListContainer);}
var tribesDisabledMessage=$('tribesDisabledInfo');if(!tribesDisabledMessage){tribesDisabledMessage=new Element('p').writeAttribute('id','tribesDisabledInfo');Element.insert($('tribesSmsHeading'),{after:tribesDisabledMessage});}
tribesDisabledMessage.update(EnergizedWork.Application.message('sms.tribes.enable.heading.global.disabled',{})).show();$$('form.tribeAllowedForm').each(function(form){var theCheckbox=form.select('input[type=checkbox]')[0];var theButton=form.select('input[type=submit]')[0];theCheckbox.disabled=true;theButton.disabled=true;theCheckbox.title=EnergizedWork.Application.message('profile.tribesAllowedToTxtMe.disabled');});},createCloseInviteToTribeLink:function(arrowUrl){var closeMessage=EnergizedWork.Application.message('person.createTribe.close.label');if(arrowUrl)closeMessage+='<img src="'+arrowUrl+'" />';var closeLink=new Element('a').writeAttribute('id','closeInviteToTribeForm').writeAttribute('href','#').update(closeMessage);var closeLinkWrapper=new Element('div').writeAttribute('id','closeInviteToTribeFormWrapper');Element.insert(closeLinkWrapper,{bottom:closeLink});var containerForLink=$('inviteToYourTribe');Element.insert(containerForLink,{bottom:closeLinkWrapper});Event.observe(closeLink,'click',this.hideInviteToTribeForm);},showInviteToTribeForm:function(event,link){EnergizedWork.Application.show($('inviteToYourTribe'));EnergizedWork.Application.hide($('inviteToTribeLinkForm'));event.stop();},hideInviteToTribeForm:function(event,link){EnergizedWork.Application.hide($('inviteToYourTribe'));EnergizedWork.Application.show($('inviteToTribeLinkForm'));event.stop();},createCloseTribeFormLink:function(arrowUrl){var closeMessage=EnergizedWork.Application.message('person.createTribe.close.label');if(arrowUrl)closeMessage+='<img src="'+arrowUrl+'" />';var closeLink=new Element('a').writeAttribute('id','closeCreateTribeForm').writeAttribute('href','#').update(closeMessage);var closeLinkWrapper=new Element('div').writeAttribute('id','closeCreateTribeFormWrapper');Element.insert(closeLinkWrapper,{bottom:closeLink});var containerForLink=$('tribeFormDiv');Element.insert(containerForLink,{bottom:closeLinkWrapper});Event.observe(closeLink,'click',this.hideCreateTribeForm);},showCreateTribeForm:function(event,link){EnergizedWork.Application.show($('tribeFormDiv'));EnergizedWork.Application.hide($('createTribeLink'));event.stop();},hideCreateTribeForm:function(event,link){EnergizedWork.Application.hide($('tribeFormDiv'));EnergizedWork.Application.show($('createTribeLink'));$('name').value='';$('tribeDescription').value='';event.stop();},submitCreateTribe:function(event,tribeForm){EnergizedWork.Application.clearFieldErrors(tribeForm);EnergizedWork.Application.clearFlashMessages();var name=$F('name');var description=$F('tribeDescription');new Ajax.Request('/action/tribe/saveAjax',{parameters:{name:name,description:description},onSuccess:function(transport){if(transport.responseJSON.success){tribeForm.reset();EnergizedWork.Application.hide($('tribeFormDiv'));EnergizedWork.Application.updateGlobalFlashMessage(transport.responseJSON.flashMessage);EnergizedWork.Application.replaceTribes($('tribeListContainer'),transport.responseJSON.html);var link=$('createTribeLink');if(transport.responseJSON.full=='true'){EnergizedWork.Application.hide(link);}else{link.value=EnergizedWork.Application.message('person.createTribe.label',{});EnergizedWork.Application.show(link);}}else{EnergizedWork.Application.updateGlobalFlashError(transport.responseJSON.flashError);EnergizedWork.Application.reportFieldErrors(tribeForm,$H(transport.responseJSON.errors));}}});event.stop();},replaceTribes:function(oldContainer,html){if(oldContainer){oldContainer.replace(html);}},updateMessageCounter:function(element,data){if(this.value.length>=100){$(this).addClass('overlimit');this.value=this.value.substring(0,100);}else{$(this).removeClass('overlimit');}
$('#counter').text(100-this.value.length);},setNameValidClass:function(target,classToAdd,classToRemove){target.removeClassName('empty');target.removeClassName(classToRemove);target.addClassName(classToAdd);target.setAttribute('alt',classToAdd);},verifyUsername:function(event,usernameTextField){var usernameAvailabilityIcon=$('usernameAvailability');var usernameEntered=usernameTextField.value;if(usernameEntered.length<this.usernameMinLength||usernameEntered.length>this.usernameMaxLength){EnergizedWork.Application.setNameValidClass(usernameAvailabilityIcon,'registrationNameFail','registrationNamePass');if(usernameEntered.length<this.usernameMinLength){usernameAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('username.availability.short'));}else{usernameAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('username.availability.long'));}}else{new Ajax.Request('/person/available',{parameters:{username:usernameEntered},onSuccess:function(transport){if(transport.responseJSON.username!=usernameTextField.value)return;if(transport.responseJSON.success){EnergizedWork.Application.setNameValidClass(usernameAvailabilityIcon,'registrationNamePass','registrationNameFail');usernameAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('username.availability.available'));}else{EnergizedWork.Application.setNameValidClass(usernameAvailabilityIcon,'registrationNameFail','registrationNamePass');usernameAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('username.availability.taken'));}}});}
event.stop();},verifyMobileUsername:function(event,usernameTextField){var usernameAvailabilityIcon=$('mobileUsernameAvailability');var usernameEntered=usernameTextField.value;if(usernameEntered.length<this.usernameMinLength||usernameEntered.length>this.usernameMaxLength){EnergizedWork.Application.setNameValidClass(usernameAvailabilityIcon,'registrationNameFail','registrationNamePass');if(usernameEntered.length<this.usernameMinLength){usernameAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('username.availability.short'));}else{usernameAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('username.availability.long'));}}else{new Ajax.Request('/mobile/available',{parameters:{mobileUsername:usernameEntered},onSuccess:function(transport){if(transport.responseJSON.mobileUsername!=usernameTextField.value)return;if(transport.responseJSON.success){EnergizedWork.Application.setNameValidClass(usernameAvailabilityIcon,'registrationNamePass','registrationNameFail');usernameAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('username.availability.available'));}else{EnergizedWork.Application.setNameValidClass(usernameAvailabilityIcon,'registrationNameFail','registrationNamePass');usernameAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('username.availability.taken'));}}});}
event.stop();},showQuickTip:function(event,link){var number=link.href.substring(link.href.indexOf('#')+1);var divElement=$('quickDiv-'+number);var nextNumber=link.className.substring(link.className.lastIndexOf(' ')+1);var nextLink=$('quick-'+nextNumber);var nextDiv=$('quickDiv-'+nextNumber);EnergizedWork.Application.hide(divElement);EnergizedWork.Application.hide(link);EnergizedWork.Application.show(nextLink);EnergizedWork.Application.show(nextDiv);EnergizedWork.EventHandlerRegistrar.unregisterEventHandler('show',$('quick-'+number),'click');EnergizedWork.EventHandlerRegistrar.registerEventHandler('show',$('quick-'+nextNumber),'click',EnergizedWork.Application.showQuickTip);},toggleQuickTipsContainer:function(event,link){$$('.quicktipLink').each(function(item){EnergizedWork.Application.hide(item);});$$('.quickTip').each(function(item){EnergizedWork.Application.hide(item);});EnergizedWork.Application.show($('quick-1'));EnergizedWork.Application.show($('quickDiv-1'));},verifyTribeName:function(event,nameTextField){var tribeAvailabilityIcon=$('tribeNameAvailability');var nameEntered=nameTextField.value;if(nameEntered.length<this.tribeNameMinLength||nameEntered.length>this.tribeNameMaxLength){EnergizedWork.Application.setNameValidClass(tribeAvailabilityIcon,'tribeNameFail','tribeNamePass');if(nameEntered.length<this.tribeNameMinLength){tribeAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('tribe.name.availability.short'));}else{tribeAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('tribe.name.availability.long'));}}else if(nameEntered){new Ajax.Request('/tribe/available',{parameters:{name:nameEntered},onSuccess:function(transport){if(transport.responseJSON.success){EnergizedWork.Application.setNameValidClass(tribeAvailabilityIcon,'tribeNamePass','tribeNameFail');tribeAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('tribe.name.availability.available'));}else{EnergizedWork.Application.setNameValidClass(tribeAvailabilityIcon,'tribeNameFail','tribeNamePass');tribeAvailabilityIcon.setAttribute('title',EnergizedWork.Application.message('tribe.name.availability.taken'));}}});}
event.stop();},changeCaptchaImage:function(imageId,cookieSuffix){var image=$(imageId);var cacheBuster=new Date().getTime()+Math.random();var baseUrl=image.src.replace(/\?.*/,'');image.src=baseUrl+'?cacheBuster='+cacheBuster;},showTagSub:function(event,link){EnergizedWork.Application.show($('tagSubscription'));EnergizedWork.Application.hide($('receiveUpdatesLink'));event.stop();},hideTagSub:function(event,link){EnergizedWork.Application.hide($('tagSubscription'));EnergizedWork.Application.show($('receiveUpdatesLink'));event.stop();},getBookmarkFromHref:function(anchorElement){if(anchorElement){if(!anchorElement.tagName)return'';if(!anchorElement.tagName.toLowerCase)return'';if(!anchorElement.tagName.toLowerCase()=='a')return'';if(!anchorElement.href)return'';var hashPos=anchorElement.href.indexOf('#');if(hashPos==-1)return'';return anchorElement.href.substr(hashPos+1);}else{return'';}},focus:function(element){if(!element)throw'focus: Element does not exist';if(!element.disabled){element.focus();}},show:function(element){element.removeClassName('hidden');element.removeClassName('jsHidden');},hide:function(element){element.addClassName('hidden');},findAncestor:function(element,id){var result;element.ancestors().each(function(ancestor){if(ancestor.id.startsWith(id)){result=ancestor;}});return result;},reportFormErrors:function(form,errors){var lastDivInForm=form.select('div')[0];lastDivInForm.insert({before:EnergizedWork.Application.createErrorsElement(errors)});},reportFieldErrors:function(form,errors){var fields=form.getElements();fields.each(function(field){var error=errors.get(field.name);if(error){field.addClassName('failField');field.up().insert({bottom:EnergizedWork.Application.createErrorsElement(error)});}});},clearFieldErrors:function(form){form.select('.errors').each(function(element){element.remove();});form.select('.failField').each(function(element){element.removeClassName('failField');});},updateFlashArea:function(message,id,className){var theDiv=$(id);if(!message||message.strip()==''){if(theDiv)Element.remove(theDiv);}else{if(!theDiv){var containerDiv=$('contentAreaLeft');if(containerDiv){theDiv=new Element('div').writeAttribute('id',id).addClassName(className);Element.insert(containerDiv,{top:theDiv});}}
if(theDiv)theDiv.update(message);}},updateGlobalFlashMessage:function(message){this.updateFlashArea(message,'globalFlashMessage','flashMessage');},updateGlobalFlashError:function(message){this.updateFlashArea(message,'globalFlashError','flashError');},createErrorsElement:function(errors){var element=new Element('div',{'class':'errors'});var list=new Element('ul');errors.each(function(errMsg){list.insert(new Element('li').update(errMsg));});element.insert(list);return element;},message:function(code,args){var fn=eval('messages.'+code);return fn(args);},registerDefaultResponders:function(){EnergizedWork.Debug={AjaxRequest:{}};Ajax.Responders.register({onComplete:function(requestor,request){switch(request.status){case 200:if(!EnergizedWork.Debug.AjaxRequest[requestor.url]){EnergizedWork.Debug.AjaxRequest[requestor.url]=1;}else{EnergizedWork.Debug.AjaxRequest[requestor.url]++;}
break;case 401:document.location='/login/divert';break;case 403:document.location='/login/suspended';break;case 500:EnergizedWork.Application.updateGlobalFlashError('An error has occured');break;}}});},checkAllRecipientCheckboxes:function(event,allLink){if(!allLink)return;var checkboxes=$$('input.'+allLink.parentNode.id);checkboxes.each(function(element){if(element!=allLink){element.checked=true;}});allLink.blur();event.stop();},createCheckAllLink:function(containerId){var container=$(containerId);container.update('<a href="#">'+messages.conversation.tribeReply.all()+'</a>');EnergizedWork.EventHandlerRegistrar.registerEventHandler('checkAll',container.select('a')[0],'click',EnergizedWork.Application.checkAllRecipientCheckboxes);},clearFlashMessages:function(){EnergizedWork.Application.updateGlobalFlashMessage('');EnergizedWork.Application.updateGlobalFlashError('');},submitFirstMobileStep:function(event,mobileForm){EnergizedWork.Application.hide($('chooseUsername'));EnergizedWork.Application.clearFieldErrors(mobileForm);var mobile=$F('loginMobile');var progressTime=$F('progressTime');$('checkForTxt').value='true';new Ajax.Request('/mobile/loginAjax',{parameters:{loginMobile:mobile},onSuccess:function(transport){if(transport.responseJSON.success){EnergizedWork.Application.hide($('mobileLoginForm'));var checkForTxtField=$F('checkForTxt');if(checkForTxtField=='true'){var container=$('mobileProcess');container.innerHTML=transport.responseJSON.instructions;EnergizedWork.Application.mobileRegistrationProgressBar=new ProgressBar($('progressContainer'),{classProgressBar:'mobileRegistrationProgressBar',style:ProgressBar.DETERMINATE,selection:100,color:{r:218,g:87,b:2},colorEnd:{r:47,g:112,b:2}});new PeriodicalExecuter(EnergizedWork.Application.mobileRegistrationProgressBarCountDown,progressTime);EnergizedWork.Application.show($('mobileProcess'));EnergizedWork.Application.hide($('chooseUsername'));new PeriodicalExecuter(EnergizedWork.Application.pollMobileConfirm,5.0);}}else{var mobileLoginForm=$('mobileLoginForm');EnergizedWork.Application.reportFieldErrors(mobileLoginForm,$H(transport.responseJSON.errors));}}});event.stop();},submitSecondMobileStep:function(event,mobileUsernameForm){var mobile=$F('loginMobile');EnergizedWork.Application.clearFieldErrors(mobileUsernameForm);var mobileUsername=$F('mobile_username');var mobilePassword=$F('mobile_password');var mobilePasswordConfirm=$F('mobile_passwordConfirm');new Ajax.Request('/mobile/usernameAjax',{parameters:{mobileUsername:mobileUsername,mobilePassword:mobilePassword,mobilePasswordConfirm:mobilePasswordConfirm,mobile:mobile},onSuccess:function(transport){if(transport.responseJSON.success){EnergizedWork.Application.hide($('mobileUsernameForm'));var container=$('mobileProcess');container.innerHTML=transport.responseJSON.mobileEmailForm;EnergizedWork.Application.show($('mobileProcess'));EnergizedWork.EventHandlerRegistrar.registerOnLoad('completeMobileSignup','#mobileEmailForm','submit','EnergizedWork.Application.submitThirdMobileStep');}else{var mobileUsernameForm=$('mobileUsernameForm');EnergizedWork.Application.reportFieldErrors(mobileUsernameForm,$H(transport.responseJSON.errors));}}});event.stop();},submitThirdMobileStep:function(event,mobileEmailForm){EnergizedWork.Application.clearFieldErrors(mobileEmailForm);EnergizedWork.Application.clearFlashMessages();var mobileEmail=$F('mobile_email');var mobileFirstName=$F('mobile_firstName');var mobileLastName=$F('mobile_lastName');new Ajax.Request('/mobile/completeAjax',{parameters:{mobileEmail:mobileEmail,mobileFirstName:mobileFirstName,mobileLastName:mobileLastName},onSuccess:function(transport){if(transport.responseJSON.success){EnergizedWork.Application.updateGlobalFlashMessage(transport.responseJSON.flashMessage);window.location='/person/'+transport.responseJSON.username+'/conversations'}else{var mobileEmailForm=$('mobileEmailForm');if(transport.responseJSON.flashError){EnergizedWork.Application.updateGlobalFlashMessage(transport.responseJSON.flashError);}
EnergizedWork.Application.reportFieldErrors(mobileEmailForm,$H(transport.responseJSON.errors));}}});event.stop();},mobileRegistrationProgressBarCountDown:function(){var progressBar=EnergizedWork.Application.mobileRegistrationProgressBar;if(progressBar.getSelection()==0){var checkForTxtField=$F('checkForTxt');if(checkForTxtField=='true'){EnergizedWork.Application.hide($('mobileProcess'));EnergizedWork.Application.hide($('chooseUsername'));EnergizedWork.Application.show($('mobileLoginForm'));}}else{progressBar.setSelection(progressBar.getSelection()-1);}},showMobileUsernameForm:function(event,link){new Ajax.Updater('chooseUsername','/action/person/atozAjax',{parameters:{id:link.innerHTML},onComplete:function(transport){$$('a.suspend').each(function(link){EnergizedWork.EventHandlerRegistrar.registerEventHandler('suspend',link,'click',EnergizedWork.Moderator.suspendAccount);});$$('a.reinstate').each(function(link){EnergizedWork.EventHandlerRegistrar.registerEventHandler('reinstate',link,'click',EnergizedWork.Moderator.reinstateAccount);});}});event.stop();},pollMobileConfirm:function(){var mobile=$F('loginMobile');var checkForTxtField=$F('checkForTxt');if(checkForTxtField=='true'){new Ajax.Request('/mobile/confirmAjax/'+mobile,{onComplete:function(transport){if(transport.responseJSON.success){$('checkForTxt').value='false';EnergizedWork.Application.show($('chooseUsername'));EnergizedWork.Application.hide($('mobileLoginForm'));EnergizedWork.Application.hide($('mobileProcess'));}}});}
event.stop();}};var deckInfos={};function previousDeckEntry(name){var info=getCurrentDeckEntry(name);var previousIndex=(info.index-1);if(info.index==1){previousIndex=(info.entries.size()-1);}
moveToDeckEntry(name,info,previousIndex);return false;}
function nextDeckEntry(name){var info=getCurrentDeckEntry(name);var nextIndex=(info.index+1);if(nextIndex>(info.entries.size()-1)){nextIndex=1;}
moveToDeckEntry(name,info,nextIndex);return false;}
function getCurrentDeckEntry(name){var deckInfo=deckInfos[name];if(deckInfo==null){deckInfo=initializeDeck(name);}
return deckInfo;}
function getDeckElement(name,index){return $("deckEntry-"+name+"-"+index);}
function moveToDeckEntry(name,info,toIndex){info.entries[info.index].addClassName("hidden");info.entries[toIndex].removeClassName("hidden");info.index=toIndex;}
function initializeDeck(name){var entries=[];var index=1;var entry=getDeckElement(name,index);while(entry!=null){entries[index++]=entry;entry=getDeckElement(name,index);}
deckInfo={entries:entries,index:1};deckInfos[name]=deckInfo;return deckInfo;}
EnergizedWork.EventHandlerRegistrar.executeOnLoad(function(){document.observe("tabPane:tabSelected",function(){});});function toggleControl(controlName){var toggleControlContainer=$(controlName);var toggleControlContent=$(controlName+"Content");var toggleControlHeaderLink=$(controlName+"HeaderLink");var toggleControlHeaderButton=$(controlName+"HeaderButton");var style=getStyle(controlName);if(style=='link'){}else{toggleControlHeaderButton.blur();}
if(toggleControlContainer.hasClassName('open')){closeToggleControl(controlName);}else{openToggleControl(controlName);}}
function closeToggleControl(controlName){var toggleControlContainer=$(controlName);var toggleControlContent=$(controlName+"Content");toggleControlContainer.removeClassName('open');toggleControlContent.addClassName("jsHidden");}
function openToggleControl(controlName){var toggleControlContainer=$(controlName);var toggleControlContent=$(controlName+"Content");toggleControlContainer.addClassName('open');toggleControlContent.removeClassName("jsHidden");}
function getStyle(controlName){var toggleControlHeaderLink=$(controlName+"HeaderLink");var style='link';if(toggleControlHeaderLink==null){style='button';}
return style;}
ew=EnergizedWork.Application;ew.updateFlashMessage=function(response){if(response.success){EnergizedWork.Application.updateGlobalFlashMessage(response.flashMessage);}else{EnergizedWork.Application.updateGlobalFlashError(response.flashError);}},ew.submitTagSubscription=function(event,subscribeTagForm){var tag=subscribeTagForm.select('#tag')[0].value;var tagType=subscribeTagForm.select('#tagType')[0].value;var time=subscribeTagForm.select('#time')[0].value;new Ajax.Request('/tag/subscribeAjax',{parameters:{tag:tag,tagType:tagType,time:time},onSuccess:function(transport){var response=transport.responseJSON;EnergizedWork.Application.updateFlashMessage(response);EnergizedWork.Application.updateTagSubscriptionCount(response);if(response.success){var tagSubscriptionPod=$('tagSubscription');tagSubscriptionPod.replace(response.tagSubscriptionPod);}},on404:function(transport){document.location='/tag';}});event.stop();},ew.submitTagDesubscription=function(event,form){var formData=form.serialize();new Ajax.Request('/tag/unsubscribeAjax',{parameters:formData,onSuccess:function(transport){var response=transport.responseJSON;EnergizedWork.Application.updateFlashMessage(response);EnergizedWork.Application.updateTagSubscriptionCount(response);if(response.success){var tagSubscriptionPod=$('tagSubscription');if(tagSubscriptionPod){tagSubscriptionPod.replace(response.tagSubscriptionPod);EnergizedWork.Application.hideTagSub(event,null);EnergizedWork.EventHandlerRegistrar.registerOnLoad('hideTagSub','#closeSubscribeTagForm','click','EnergizedWork.Application.hideTagSub');}
EnergizedWork.Application.removeTagSubscriptionsFromList(response.tagUris);}},on:function(transport){document.location='/tag';}});event.stop();},ew.removeTagSubscriptionsFromList=function(uris){var checkboxes=$$('#unsubscribeDailyMessagesForm input[type="checkbox"]');checkboxes.each(function(item){if(uris.indexOf(item.value)!=-1)item.up('li').remove();});checkboxes=$$('#unsubscribeDailyMessagesForm input[type="checkbox"]');if(!checkboxes.length){var noDailyMessagesText=EnergizedWork.Application.message('dailyMessages.none');var noDailyMessagesMarkup=new Element('p').addClassName('noData').update(noDailyMessagesText);$('unsubscribeDailyMessagesForm').replace(noDailyMessagesMarkup);}},ew.updateTagSubscriptionCount=function(response){var container=$('totalSubscribed');if(container){container.innerHTML=EnergizedWork.Application.message('tag.number.subscribed',[response.numberSubscribed]);}},ew.submitUnsubscribeFromConversations=function(event,container){EnergizedWork.Application.clearFlashMessages();var values=Form.serialize(container,true);delete values['_action_Unsubscribe'];new Ajax.Request('/conversation/unsubscribeAjax',{parameters:values,onSuccess:EnergizedWork.Application.removeConversationSubscriptionsFromList});event.stop();},ew.removeConversationSubscriptionsFromList=function(transport){var response=transport.responseJSON;if(response.success){var checkboxes=$$('#person-conversationSubs input[type="checkbox"]');checkboxes.each(function(item){if(response.uris.indexOf(item.value)!=-1){item.up('.conversationSubscription').remove();}});checkboxes=$$('#person-conversationSubs input[type="checkbox"]');if(!checkboxes.length){var noSubscriptionsMessage=EnergizedWork.Application.message('person.conversationSubs.none.ofanytype');var noSubscriptionsMarkup=new Element('p').addClassName('noData').update(noSubscriptionsMessage);$('conversationSubscriptionsPod').update(noSubscriptionsMarkup);}}
EnergizedWork.Application.updateFlashMessage(response);},ew.submitSubscribeToConversation=function(event,container){EnergizedWork.Application.clearFlashMessages();var form=container.select('form')[0];var values=Form.serialize(form,true);new Ajax.Request(values['ajaxTarget'],{parameters:{uris:values['uris'],convSubOrigin:values['convSubOrigin'],containerCtx:values['containerCtx']},onSuccess:function(transport){EnergizedWork.Application.conversationSubscriptionCallback(transport.responseJSON,container.id);}});event.stop();},ew.submitUnsubscribeFromConversation=function(event,container){EnergizedWork.Application.clearFlashMessages();var form;var containerId;if(container.id=='conversationUnsubscribeButton'){containerId=EnergizedWork.Application.getContainerIdFromConversationUnsubscribeBar(container);}else{containerId=container.id;}
form=$(containerId).select('form')[0];var values=Form.serialize(form,true);delete values['_action_Unsubscribe'];new Ajax.Request('/conversation/unsubscribeAjax',{parameters:values,onSuccess:function(transport){EnergizedWork.Application.conversationUnsubscriptionCallback(transport.responseJSON,containerId);}});event.stop();},ew.getContainerIdFromConversationUnsubscribeBar=function(container){var uri=container.form.elements['uris'].value;var conversationCtx=container.form.elements['containerCtx'].value;return conversationCtx+'_conversationSubscriptionContainer_'+uri;},ew.conversationSubscriptionCallback=function(response,containerId){EnergizedWork.Application.updateFlashMessage(response);EnergizedWork.Application.showUnsubscribeInfoBarIfPresent(response.infoBar);new Ajax.Updater({success:containerId+'wrapper'},'/conversation/renderSubscribeFormAjax',{parameters:{containerId:containerId},method:'post',evalScripts:true,onComplete:function(transport){EnergizedWork.EventHandlerRegistrar.registerEventHandler('unsubscribe',$(containerId),'click',EnergizedWork.Application.submitUnsubscribeFromConversation);}});},ew.conversationUnsubscriptionCallback=function(response,containerId){EnergizedWork.Application.updateFlashMessage(response);EnergizedWork.Application.removeUnsubscribeInfoBarIfPresent();new Ajax.Updater({success:containerId+'wrapper'},'/conversation/renderSubscribeFormAjax',{parameters:{containerId:containerId},method:'post',evalScripts:true,onComplete:function(transport){EnergizedWork.EventHandlerRegistrar.registerEventHandler('subscribe',$(containerId),'click',EnergizedWork.Application.submitSubscribeToConversation);}});},ew.showUnsubscribeInfoBarIfPresent=function(infoBarMarkup){var pageHeading=$('pageHeading');if((pageHeading!=null)&&(infoBarMarkup!=null)){Element.insert($('pageHeading'),{after:infoBarMarkup});}},ew.removeUnsubscribeInfoBarIfPresent=function(){var infoBar=$('conversationSubscription');if(infoBar!=null){Element.remove(infoBar);}};EnergizedWork.Promo={promos:[],wait:5,index:0,fadeDuration:1,appearDuration:1,executor:null,setUp:function(wait){if(wait!=null){this.wait=wait;}
this.start();},stop:function(){if(this.executor!=null){this.executor.stop();this.executor=null;}},start:function(){this.promos=$$('#promos .promo');if(this.promos.length==1&&!this.promos[0].visible()){Effect.Appear(this.promos[0],{duration:this.appearDuration,from:0.0,to:1.0,queue:{position:'end',scope:'promo'}});}else if(this.promos.length>1){this.executor=new PeriodicalExecuter(this.rotatePromo.bind(this),this.wait);}},restart:function(){this.stop();this.start();},rotatePromo:function(){var currentPromo=this.promos[this.index++];if(this.index>=this.promos.length){this.index=0;}
var nextPromo=this.promos[this.index];Effect.Fade(currentPromo,{duration:this.fadeDuration,from:1.0,to:0.0,queue:{scope:'promo'}});Effect.Appear(nextPromo,{duration:this.appearDuration,from:0.0,to:1.0,queue:{position:'end',scope:'promo'}});},savePromo:function(){new Ajax.Request('/moderator/savePromo',{parameters:$('editPromoForm').serialize(true),onSuccess:function(transport){var json=transport.responseJSON;var form=$('editPromoForm');EnergizedWork.Application.clearFieldErrors(form);if(json.success){var existingPromo=$('promo'+json.index);if(existingPromo!=null){existingPromo.replace(json.promo);}else{$('promos').insert(json.promo);}
lightbox.prototype.deactivate();new lightbox($('editPromo'+json.index));EnergizedWork.Promo.restart();}else{EnergizedWork.Application.reportFieldErrors(form,$H(json.errors));}}});},deletePromo:function(promoId){var shouldDelete=confirm(EnergizedWork.Application.message('promo.delete.confirm'));if(shouldDelete==true){var index=this.findPromoIndexById(promoId);if(index!=-1){this.deletePromoFromServer(index);}}},deletePromoFromServer:function(index){new Ajax.Request('/moderator/deletePromo',{parameters:{index:index},onSuccess:function(transport){if(transport.responseJSON.success){EnergizedWork.Promo.deletePromoFromPage(index);}else{EnergizedWork.Application.updateGlobalFlashError(transport.responseJSON.flashError);}}});},deletePromoFromPage:function(index){this.promos[index].remove();this.restart();},findPromoIndexById:function(promoId){var result=-1;for(var index=0;index<this.promos.length;index++){if(this.promos[index].id==promoId){result=index;break;}}
return result;}};