ChatterPolls={questionTextLimit:140,choiceTextLimit:75,questionTextMin:3,choiceTextMin:1,activatePollButton:function(pollButton){pollButton.unbind('click');pollButton.siblings('div.addVideoButton').removeClass('addVideoInactive');pollButton.siblings('div.addPhotoButton').removeClass('addPhotoInactive');pollButton.addClass('addPollInactive');pollButton.siblings('div.photoHandlerContainer').hide().children().hide();pollButton.siblings('div.addVideo').remove();pollButton.siblings('div.truthGameCreationContainer').children('img.closeContainer').trigger('click')},deactivatePollButton:function(pollButton){pollButton.removeClass('addPollInactive');pollButton.unbind('click');ChatterPolls.bindEvents(['createPoll'],$('#updateStatusContainer'))},getPollForm:function(){var ajaxUrl=MyYearbook.URLs.Chatter+'chatterPolls/json/';var pollCreationContainer=$('div.pollCreationContainer','#updateStatusContainer');var pollButton=$('div.addPollButton','#updateStatusContainer');pollButton.unbind('click');var promo=$('div.chatterPollPromo a','#updateStatusContainer');promo.unbind('click');if(pollCreationContainer.length>0){myb.checkLogin(ChatterPolls.showPollForm)}else{$.ajax({url:ajaxUrl+'pollForm',dataType:'jsonp',success:function(result){ChatterPolls.getPollFormCallback(result,pollButton.parent())}})}},fauxPollChoiceClick:function(){$(this).hide().next('input.pollTextInput').show().focus().blur(ChatterPolls.pollChoiceBlur)},pollChoiceBlur:function(){var choiceValue=$(this).val();var trimmedChoiceValue=choiceValue.replace(/^\s+|\s+$/g,'');if(trimmedChoiceValue.length===0){$(this).hide().val('').prev('div.fauxPollChoiceInput').show()}},changePollChoiceCount:function(){var currentPollChoiceCount=parseInt($('#pollChoiceCount').val());oldChoiceCount=$('div.fauxPollChoiceInput:visible','div.pollChoiceContainer').length;if(oldChoiceCount!==currentPollChoiceCount){$('div.fauxPollChoiceInput','div.pollChoiceContainer').each(function(i){var choiceId=i+1;if(i<currentPollChoiceCount){if($('#pollChoice'+choiceId).val().length>0){$('#pollChoice'+choiceId).show();$('#fauxPollChoice'+choiceId+'Input').hide()}else{$('#pollChoice'+choiceId).hide();$('#fauxPollChoice'+choiceId+'Input').show()}$('#pollChoice'+choiceId+'InputCountDown').show()}else{$('#fauxPollChoice'+choiceId+'Input').hide();$('#pollChoice'+choiceId).hide().val('');$('#pollChoice'+choiceId+'InputCountDown').hide().html('75')}})}if($.browser.msie){Feed.activateContainerAutoClose(ChatterPolls.containerMouseLeaveFunction,ChatterPolls.containerMouseEnterFunction)}},changeResponseType:function(){if($(this).val()=='multipleChoice'){$('div.pollChoiceCountContainer, div.pollChoiceContainer','#updateStatusContainer').show();$('#pollChoiceCount').trigger('change')}else{$('div.pollChoiceCountContainer, div.pollChoiceContainer','#updateStatusContainer').hide()}},fixIEChangePollChoice:function(){Feed.deactivateContainerAutoClose(ChatterPolls.containerMouseLeaveFunction,ChatterPolls.containerMouseEnterFunction)},initPollCreationForm:function(isInitialLoad){var pollButton=$('div.addPollButton','#updateStatusContainer');ChatterPolls.activatePollButton(pollButton);Status.activateSubmitButton(Status.submitButton);Status.submitButton.unbind('click').bind('click',ChatterPolls.submitPoll);$('#fauxStatusInput').hide();$('#statusInput').hide();$('#statusCountDownArea').hide();Feed.activateContainerAutoClose(ChatterPolls.containerMouseLeaveFunction,ChatterPolls.containerMouseEnterFunction);Feed.toggleCaptcha(true);$('#pollQuestionInput').focus();if(isInitialLoad===true){var pollCreationContainer=$('div.pollCreationContainer','#updateStatusContainer');$('img.closeContainer',pollCreationContainer).bind('click',ChatterPolls.hidePollCreationForm);$('div.fauxPollChoiceInput',pollCreationContainer).bind('focus',ChatterPolls.fauxPollChoiceClick);if($.browser.msie){$('#pollChoiceCount').mousedown(ChatterPolls.fixIEChangePollChoice)}$('#pollChoiceCount').change(ChatterPolls.changePollChoiceCount);$('input.pollResponseTypeInput',pollCreationContainer).bind('click',ChatterPolls.changeResponseType);var inputCountdown=new InputCountdown($('#pollQuestionInput'),$('#pollQuestionInputCountDown'),ChatterPolls.questionTextLimit,function(){});inputCountdown.init();$('div.pollChoiceContainer input.pollTextInput',pollCreationContainer).each(function(){var inputCountdown=new InputCountdown($(this),$(this).next('span.pollInputCountDownArea:first'),ChatterPolls.choiceTextLimit,function(){});inputCountdown.init()})}},showPollForm:function(loggedIn){if(loggedIn===true){$('#updateStatusContainer div.pollCreationContainer').show();ChatterPolls.initPollCreationForm(false)}else{$('#updateStatusContainer div.pollCreationContainer').remove();ChatterPolls.getPollForm()}},getPollFormCallback:function(result,container){ChatterPolls.bindEvents(['createPoll'],$('#updateStatusContainer'));$(result.display).insertAfter($('div.photoHandlerContainer',container));ChatterPolls.initPollCreationForm(true)},hidePollCreationForm:function(){var pollCreationContainer=$('div.pollCreationContainer','#updateStatusContainer');$('input.pollResponseTypeInput:first',pollCreationContainer).attr('checked','checked').trigger('click');$('#pollChoiceCount').val('4').trigger('click').trigger('mousedown');Feed.deactivateContainerAutoClose(ChatterPolls.containerMouseLeaveFunction,ChatterPolls.containerMouseEnterFunction);ChatterPolls.deactivatePollButton($('div.addPollButton','#updateStatusContainer'));pollCreationContainer.hide();$('#fauxStatusInput').show();$('#statusCountDownArea').show();$('#statusUpdateButton').unbind('click');Status.statusButtonBind($('#statusUpdateButton'));Feed.postType='status';Feed.toggleCaptcha(false);$('input.pollTextInput:visible:not(#pollQuestionInput)',pollCreationContainer).val('').trigger('keyup').hide().prev('div.fauxPollChoiceInput').show();$('#pollQuestionInput').val('').trigger('keyup');ChatterPolls.showError(false)},showError:function(message){var errorContainer=$('div.pollCreationErrorContainer','#updateStatusContainer');if(message===false){errorContainer.remove()}else{if(errorContainer.length>0){errorContainer.html(message)}else{markup='<div class="pollCreationErrorContainer">'+message+'</div>';$(markup).insertAfter('#updateStatusContainer div.pollInstructions')}}},submitPoll:function(){var question=$('#pollQuestionInput').val();if(question.length===0){ChatterPolls.showError('You must enter a question to continue.');return}else if(question.length<3){ChatterPolls.showError('Your question must be at least 3 characters to continue.');return}var pollCreationContainer=$('div.pollCreationContainer','#updateStatusContainer');var responseType=$('input.pollResponseTypeInput:checked',pollCreationContainer).val();var validChoices={};var choiceCount=0;if(responseType==='multipleChoice'){$('div.pollChoiceContainer input.pollTextInput',pollCreationContainer).each(function(){var choiceText=$(this).val();if(choiceText.length>0){choiceCount++;var key='choice'+choiceCount;validChoices[key]=choiceText}})}else{validChoices['choice1']='Yes';validChoices['choice2']='No';choiceCount=2}if(choiceCount<2){ChatterPolls.showError('You must enter at least two choices for your poll.');return}var sendData={};sendData['choices']=validChoices;sendData['question']=question;sendData['isMatchingFeedFilter']=Feed.isMatchingFeedFilter;sendData['xslFile']=Feed.displayType;if(typeof Recaptcha!='undefined'){var response=Recaptcha.get_response();if(response!==null){sendData['recaptcha_response_field']=response}var challenge=Recaptcha.get_challenge();if(challenge!==null){sendData['recaptcha_challenge_field']=challenge}}var queryStr={};$.each(sendData,function(k,v){if(typeof v!=='object'){queryStr[k]=v}else{$.each(v,function(k2,v2){queryStr[k+'['+k2+']']=v2})}});var ajaxUrl=MyYearbook.URLs.Chatter+'chatterPolls/json/';$.ajax({url:ajaxUrl+'createPoll',dataType:'jsonp',data:queryStr,success:function(result){ChatterPolls.submitPollCallback(result)}})},submitPollCallback:function(result){Status.setPageCaptcha(result.nextRequiresCaptcha);if(result.success===true){Feed.buildNewFeedItem(result);ChatterPolls.hidePollCreationForm()}else{if(result.nextRequiresCaptcha&&result.captchaMarkup){$('div.aiCaptchaBox','#updateStatusContainer').remove();$('div.statusFormContainer','#updateStatusContainer').append(result.captchaMarkup)}ChatterPolls.showError(result.error)}},bindEvents:function(names,container){if(container.length>0){for(var x in names){switch(names[x]){case'createPoll':$('div.addPollButton',container).unbind('click').bind('click',ChatterPolls.getPollForm);break;case'vote':$('img.pollVoteButton',container).unbind('click').bind('click',ChatterPolls.vote);break}}}},initFeedPage:function(){ChatterPolls.bindEvents(['createPoll'],$('#updateStatusContainer'))},initFeedItems:function(container){ChatterPolls.bindEvents(['vote'],$('div.feedItem_ChatterPoll',container))},vote:function(){var feedItemArea=$(this).parents('div.feedItemArea');var pollUUID=feedItemArea.attr('data-reference-uuid');var questionNumber=$(this).parent().children('img.pollVoteButton').attr('data-question-number');var choiceNumber=$(this).parent().children('label').children('input:checked').attr('value');var displayTypeContainer=$('#displayTypeContainer');var expandPhotos=1;if(displayTypeContainer.hasClass('view')){expandPhotos=3}else if($('#HALFeed').length<1&&displayTypeContainer.hasClass('profile')!=true){expandPhotos=2}var ajaxUrl=MyYearbook.URLs.Chatter+'chatterPolls/json/';ChatterPolls.showVoteLoading(feedItemArea);$.ajax({url:ajaxUrl+'vote',dataType:'jsonp',data:{pollUUID:pollUUID,questionNumber:questionNumber,choiceNumber:choiceNumber,xslFile:Feed.displayType,expandPhotos:expandPhotos,fromProfile:displayTypeContainer.hasClass('profile')?true:false},success:function(result){ChatterPolls.voteCallback(result,feedItemArea)}})},showVoteLoading:function(feedItemArea){feedItemArea.find('div.pollVoteContainer').hide().after('<div class="pollLoadingContainer"><div>Submitting your</div><div>Vote...</div><img class="pollLoadingImage" src="'+IMAGE_URL+'ajax_black_big_trans.gif"></div>')},voteCallback:function(result,oldContainer){if(result.success===true){if(typeof result.renderedItem==='string'){var similarPosts=$('span.showSimilarPosts',oldContainer);var container=$(result.renderedItem).insertAfter(oldContainer);if(similarPosts.length>0){$(similarPosts).insertAfter($('div.feedComments',container))}if(result.commentId!=null){if($('li.comment:last-child',container).children('span.id').html()!==result.commentId){$(result.renderedComment).appendTo($('ul.comments',container))}}var featuredAI=oldContainer.find('#ChatterFeaturedItemActionIcons');if(featuredAI.length>0){container.find('div.actionIcons').remove()}oldContainer.find('#ChatterFeaturedItemSponsored').add(featuredAI).appendTo(container.find('div.posterPhotoContainer'));oldContainer.remove();eval(result.aiMembersJS);eval(result.aiIconSetsJS);if($('#Profile').length>0){ActionIcons.init($('div.feedComments',container))}else{ActionIcons.init(container)}container.find('a.btnActionIcon:not(.aiFan)').hide();Feed.initItems(container);$('div.input textarea',container.parent()).val('').parent().addClass('hidden').siblings('.fauxInput').removeClass('hidden');var postCommentInput=$('input.postCommentInput',container.parent());if(postCommentInput.hasClass('captchaCommentButton')){postCommentInput.insertAfter(postCommentInput.siblings('div.addPhotoButton')).removeClass('captchaCommentButton')}Comments.showPostError(container.parent(),false);Comments.setPageCaptcha(result.nextRequiresCaptcha);Status.setPageCaptcha(result.nextRequiresCaptcha)}}else if(result.success===false){oldContainer.find('div.pollLoadingContainer').remove();oldContainer.find('div.pollVoteContainer').show();$.dragonAlertHTML(result.error,{title:'Polls'})}var postComment=container.find('div.feedItemRightContainer').children('div.boxNub, div.feedComments').removeClass('hidden').find('div.postComment');Feed.blurCommentsArea(postComment)},containerMouseLeaveFunction:function(){$(document).bind('mousedown',ChatterPolls.hideFormWithTimeOut)},containerMouseEnterFunction:function(){$(document).unbind('mousedown',ChatterPolls.hideFormWithTimeOut)},hideFormWithTimeOut:function(){setTimeout(ChatterPolls.hidePollCreationForm,100)}};