var adhocRecipientCounter=0;var EventLinks={getBitlyResult:function(b){for(var a in b.results){return b.results[a];break}return null},displayLink:function(b){var a=EventLinks.getBitlyResult(b);$("#shortLink").val(a.shortUrl.toString())},retweet:function(b){var a=EventLinks.getBitlyResult(b);window.open("http://twitter.com/home?source=strategyeye&status=RT @"+$("#twitter-username").val()+": "+$("#newsTitle").val()+" "+a.shortUrl.toString())}};var EventRules={"#newEmailButton":function(a){a.onclick=function(){tb_show("Send an email","/#TB_inline?height=240&amp;width=500&amp;inlineId=emailArticleSection",false);$("#emailArticleSectionMessage").hide();$("#emailArticleSectionForm").show()}},"#emailArticleButton":function(a){a.onclick=function(){tb_show("Share article with colleagues and associates","/#TB_inline?height=415&amp;width=670&amp;inlineId=emailArticleSection",false);$(".emailArticleMessage").hide();$("#emailArticleSectionForm").show();$("#emailArticleSectionRecipients").show()}},"#swaSendButton":function(a){a.onclick=function(){}},"#sendEmailForm":function(element){$("#sendEmailForm").validate({errorLabelContainer:"#messageBox",wrapper:"li",onsubmit:false,onkeyup:false});element.onsubmit=function(){if(!recipients.hasValues()){$("#emailArticleSectionMessageNoRecipients").show();return false}$("#emailArticleSectionRecipients").hide();$("#emailArticleSectionForm").hide();$(".emailArticleMessage").hide();$("#emailArticleSectionMessageSubmitting").show();postBody=$("#sendEmailForm").serialize(false);postBody+="&check=confirmed";$.post("/data/share/share-article",postBody,function(data){if(typeof(data)=="string"&&data!=""){var data=eval("("+data+")")}if(data.status=="success"){$(".emailArticleMessage").hide();$("#emailArticleSectionMessageSent").show()}else{if(data.status=="failure"){$(".emailArticleMessage").hide();$("#emailArticleSectionMessageFailure").text(data.errorMessage);$("#emailArticleSectionMessageFailure").show()}}TeamShare.initialiseRecipients()});return false}},"#saveArticleButton":function(a){a.onclick=function(){$("#bookmarkFormInfo").css("display","none");$("#bookmarkFormFunc").css("display","block");tb_show("Bookmark this page","/#TB_inline?height=90&width=350&inlineId=bookmarkForm",false);$("#bookmarkname").val($("#newsTitle").val())}},"#select-associate":function(a){a.onchange=function(){if($(a).val()&&$(a).val()!=""){var b=$("#select-associate :selected");recipients.add("associate_"+$(a).val(),b.text(),b.attr("rel"));$(a).val("")}}},"#select-colleague":function(a){a.onchange=function(){if($(a).val()&&$(a).val()!=""){var b=$("#select-colleague :selected");recipients.add("colleague_"+$(a).val(),b.text(),b.attr("rel"));$(a).val("")}}},"input.adHocEntry":function(a){},"#add-recipient":function(a){a.onclick=function(){var c=$("#recipientName").val();var b=$("#recipientEmail").val();if(c&&b){$("#adHocRecipientName_"+adhocRecipientCounter).remove();$("#adHocRecipientEmail_"+adhocRecipientCounter).remove();recipients.add("adhoc_"+adhocRecipientCounter,c,b);$("#sendEmailForm").append('<input type="hidden" class="adHocRecipientField" id="adHocRecipientName_'+adhocRecipientCounter+'" name="adHocRecipientName_'+adhocRecipientCounter+'" value="'+c+'" />');$("#sendEmailForm").append('<input type="hidden" class="adHocRecipientField" id="adHocRecipientEmail_'+adhocRecipientCounter+'" name="adHocRecipientEmail_'+adhocRecipientCounter+'" value="'+b+'" />');$("#recipientName").val("Enter another name");$("#recipientEmail").val("Enter email address");adhocRecipientCounter++}}},"#emailArticleReset":function(a){a.onclick=function(){$(".emailArticleMessage").hide();$("#emailArticleSectionRecipients").show();$("#emailArticleSectionForm").show()}},"#sendEmailForm .resettableField":function(a){a.defaultValue=$(a).val();a.onfocus=function(){if($(a).val()==a.defaultValue){$(a).val("")}};a.onblur=function(){if($(a).val()==""){$(a).val(a.defaultValue)}}},"#show-link-button":function(a){a.onclick=function(){BitlyClient.call("shorten",{longUrl:$("#externalLinkUrl").val()},"EventLinks.displayLink");tb_show("Link generator","#TB_inline?height=110&amp;width=500&amp;inlineId=showLinkWindow")}},"#retweet-button":function(a){a.onclick=function(){BitlyClient.call("shorten",{longUrl:$("#externalLinkUrl").val()},"EventLinks.retweet")}},".gallery-strip-film-image":function(a){a.onmouseover=function(){$("#caption_"+$(this).attr("id").replace("image_","")).show()};a.onmouseout=function(){$(".image-caption").hide()}}};var TeamShare={disableAddedRecipients:function(){},clearAdHocRecipients:function(){var e=recipients.getValues();for(var b=0;b<e.length;b++){val=e[b];id=recipients._id+"-"+val;if(!$("#"+id).length){var c=id.split("_",val);var a=c[0];var d=c[1];switch(a){case"associate":break;case"colleague":break;case"adhoc":$("#adHocRecipientName_"+d).remove();$("#adHocRecipientEmail"+d).remove();break}}}},hideNoRecipientsMessage:function(){$("#emailArticleSectionMessageNoRecipients").hide()},initialiseRecipients:function(){$("#sendEmailForm .adHocRecipientField").remove();$("#recipients-list li").remove();$("#recipientName").val("Enter new name");$("#recipientEmail").val("Enter new email");recipients=new EntityList;recipients.setup("recipients-list","recipients[]",callbacks)}};Behaviour.register(EventRules);var recipients;$(document).ready(function(){callbacks=Array("TeamShare.disableAddedRecipients()","TeamShare.clearAdHocRecipients()","TeamShare.hideNoRecipientsMessage()");TeamShare.initialiseRecipients();if($("#printing").val()=="true"){window.print()}});