
$(document).ready
(function()
{if($("#callShoutboxFunctions").val()=='yes'){if($("#txtInReplyToId").val()!=''&&$("#txtInReplyToName").val()!=''){$("#txtActualShoutBox").val("@"+$("#txtInReplyToName").val()+" ");onFocusChange();}else{if($("#txtUseAtMention").val()!=''){var atMention=$("#txtUseAtMention").val();$("#txtActualShoutBox").val("@"+atMention+" ");$("#txtActualShoutBox").focus();onFocusChange();}}
$("#txtActualShoutBox").bind('keyup',parseShoutText);$("#txtActualShoutBox").bind('keydown',parseShoutText);$("#txtActualShoutBox").bind('click',parseShoutText);$("#txtActualShoutBox").bind("paste",function(){$("#tempfadeoutspan").fadeIn(100,function(){onFocusChange();$("#tempfadeoutspan").hide();})});$("#txtActualShoutBox").bind('focus',onFocusChange);$("#txtActualShoutBox").bind('blur',onFocusOut);$("#btnBuzzButton").bind('click',shoutClicked);}});var allowedLength=140;function checkShoutLength(){var shoutText=$("#txtActualShoutBox").val();var textLength=shoutText.length;var charsLeft=allowedLength-(textLength*1);charsLeft=charsLeft*1;if(charsLeft==0){charsLeft="0";}
if(charsLeft>=140){$("#txtInReplyToId").val('');$("#txtInReplyToName").val('');}
$("#divShoutBoxLetterCount").css('color','#a9a9a9');if(charsLeft<0)
{$("#divShoutBoxLetterCount").css('color','rgb(212, 13, 18)');}
else
{if(charsLeft>=0&&charsLeft<=20)
{$("#divShoutBoxLetterCount").css('color','#000000');}}
$("#divShoutBoxLetterCount").html(charsLeft);var trimmedTextLength=trimShoutBoxText(shoutText).length;if(trimmedTextLength>0){$("#globalshoutbuzzbutton").addClass('on');$("#btnBuzzButton").removeAttr("disabled");}
else{$("#globalshoutbuzzbutton").removeClass('on');$("#btnBuzzButton").attr("disabled","disabled");}}
function onFocusChange(){parseShoutText();}
function onFocusOut(){parseShoutText();}
function shoutClicked(){var shoutText=$("#txtActualShoutBox").val();shoutText=trimShoutBoxText(shoutText);var textLength=shoutText.length;var divData='';var randomNumber='';var replacedDivData='';var newReplacedData='';var options={};var processedShoutText='';var showShoutText='';if(textLength==0||textLength>140){}
else{$("#btnBuzzButton").attr("disabled","disabled");$("#divShoutBoxLetterCount").html('<img src="'+$("#txtglobalbaseurl").val()+'/images/loading-img.gif" border="0" />');if($("#txtglobaltrailrefreshcontext").val()=="set"){if($("#txtprofileuserrole").val()=='ME'){divData=$("#hidden_template_for_shout").html();randomNumber=Math.floor(Math.random()*1000+1);replacedDivData=divData.replace("@@UNIQ_ID@@",randomNumber);showShoutText=shoutText.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');;newReplacedData=replacedDivData.replace("@@SHOUT_TEXT@@",showShoutText);$("#trailcontentDiplay").html(newReplacedData+$("#trailcontentDiplay").html());$("#refreshedShout_"+randomNumber).fadeIn("slow");}
else{if($("#txtprofilecorename").val()==$("#txtUseAtMention").val()){var atMentionValue=$("#txtUseAtMention").val();var atMentionLength=atMentionValue.length;atMentionLength=(atMentionLength*1)+1+1;if(shoutText.substring(0,atMentionLength)=='@'+atMentionValue+' '||shoutText=='@'+atMentionValue){$("#drinkEmptyMessage").hide();divData=$("#hidden_template_for_shout").html();randomNumber=Math.floor(Math.random()*1000+1);replacedDivData=divData.replace("@@UNIQ_ID@@",randomNumber);showShoutText=shoutText.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');;newReplacedData=replacedDivData.replace("@@SHOUT_TEXT@@",showShoutText);$("#trailcontentDiplay").html(newReplacedData+$("#trailcontentDiplay").html());$("#refreshedShout_"+randomNumber).fadeIn("slow");}}}}
var postToTwitter="false";if(document.getElementById('twitterConnStatus')){var twitterConnStatus=document.getElementById('twitterConnStatus');if(twitterConnStatus.checked==true){postToTwitter="true";}else{postToTwitter="false";}}
postObject=new Object;postObject.shoutString=shoutText;postObject.inReplyToId=$("#txtInReplyToId").val();postObject.inReplyToName=$("#txtInReplyToName").val();postObject.postToTwitter=postToTwitter;$.post
($("#txtglobalbaseurl").val()+"/shout/submitshout",postObject,function(data)
{obj=window.eval(data);var status=obj['status'];var lastShout='';if(status==-1)
{}
else
{lastShout=obj['shout_string'];}
$("#divShoutBoxLetterCount").html('140');if($("#txtUseAtMention").val()!=''){$("#txtActualShoutBox").val("@"+$("#txtUseAtMention").val()+" ");$("#divShoutBoxTitleString").html("Reply to @"+$("#txtUseAtMention").val());}
else{$("#txtActualShoutBox").val('');$("#divShoutBoxTitleString").html("Say something");}
$("#btnBuzzButton").removeAttr("disabled");$("#divShoutBoxLastBuzz").html('<strong>Last update:</strong> '+lastShout);$("#txtActualShoutBox").focus();},"json");}}
function parseShoutText(){checkShoutLength();var explodedShoutText='';var shoutText=$("#txtActualShoutBox").val();var trimmedShoutText=shoutText;$("#divShoutBoxTitleString").html("Say something");$("#btnBuzzButton").attr('value','submit');var atPattern=/^@[a-zA-Z0-9\_\-]+[^a-zA-Z0-9\_\-\@]/i;var atTest=atPattern.test(trimmedShoutText);var atUserName='';var displayUserName='';var appendInContext='';if($("#txtInReplyToId").val()==''||$("#txtInReplyToName").val()==''){}
else{appendInContext='In ';}
var dStartPattern=/^D\s/;var dStartTest=dStartPattern.test(trimmedShoutText);var dStartNegativePattern=/^D\s[^a-zA-Z0-9\_\-]/;var dStartNegativeTest=dStartNegativePattern.test(trimmedShoutText);var dUserPattern=/^D\s[a-zA-Z0-9\_\-]+[^a-zA-Z0-9\_\-]/;var dUsernameTest=dUserPattern.test(trimmedShoutText);var dUserName='';displayUserName='';if(atTest){atUserName=atPattern.exec(trimmedShoutText);displayUserName=atUserName[0].substr(1,atUserName[0].length-2);$("#divShoutBoxTitleString").html(appendInContext+"Reply to "+displayUserName);if(appendInContext!=''){$("#btnBuzzButton").attr('value','reply');}}
else{if(dUsernameTest){$("#btnBuzzButton").attr('value','send message');dUserName=dUserPattern.exec(trimmedShoutText);displayUserName=dUserName[0].substr(2,dUserName[0].length-2);$("#divShoutBoxTitleString").html("Send "+displayUserName+" a direct message");}
else
{if(dStartNegativeTest){$("#divShoutBoxTitleString").html("Say something");$("#btnBuzzButton").attr('value','submit');}
else{if(dStartTest){$("#btnBuzzButton").attr('value','send message');$("#divShoutBoxTitleString").html("Send a direct message");}
else{$("#divShoutBoxTitleString").html("Say something");$("#btnBuzzButton").attr('value','submit');}}}}}
function trimShoutBoxText(stringValue){return stringValue.replace(/^\s+|\s+$/g,"");}
function setInReplyToContext(irtId,irtName){if(irtId==''||irtName==''){}
else{$("#txtInReplyToId").val(irtId);$("#txtInReplyToName").val(irtName);$("#txtActualShoutBox").val("@"+irtName+" ");$("#txtActualShoutBox").focus();onFocusChange();var $target=$("#globalshoutboxdivstart");var targetOffset=$target.offset().top;if($.browser.opera){$('html').animate({scrollTop:targetOffset},100);}
else{$('html,body').animate({scrollTop:targetOffset},100);}}}
function fillDContext(userName){$("#txtActualShoutBox").val("D "+userName+" ");$("#txtActualShoutBox").focus();onFocusChange();}
function fillAtContext(name){$("#txtActualShoutBox").val("@"+name+" ");$("#txtActualShoutBox").focus();onFocusChange();}
function controlTwitterPost(){var postToTwitter="false";if(document.getElementById('twitterConnStatus')){var twitterConnStatus=document.getElementById('twitterConnStatus');if(twitterConnStatus.checked==true){postToTwitter="true";}else{postToTwitter="false";}
var ajaxRequestUrl=$("#txtglobalbaseurl").val()+"/shout/modifytwittercookie";$.ajax
({type:'POST',url:ajaxRequestUrl,data:"postToTwitter="+postToTwitter,success:function(response)
{},failure:function(response)
{}});}}
