/*=======================================================================*\
|| ###################################################################### ||
|| # vBulletin 5.4.1
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2018 vBulletin Solutions Inc. All Rights Reserved.  # ||
|| # This file may not be redistributed in whole or significant part.   # ||
|| # ----------------- VBULLETIN IS NOT FREE SOFTWARE ----------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html   # ||
|| ###################################################################### ||
\*========================================================================*/
window.vBulletin=window.vBulletin||{};window.vBulletin.phrase=window.vBulletin.phrase||{};window.vBulletin.phrase.precache=window.vBulletin.phrase.precache||[];window.vBulletin.phrase.precache=$.merge(window.vBulletin.phrase.precache,["vote_failed","vote_now","vote_first","vote_error_retrieving","votes","vote","voters","voter"]);window.vBulletin.options=window.vBulletin.options||{};window.vBulletin.options.precache=window.vBulletin.options.precache||[];window.vBulletin.options.precache=$.merge(window.vBulletin.options.precache,["maxpolloptions"]);(function(A){A(document).ready(function(){function E(J){var I=window.vBulletin.options.get("maxpolloptions"),H=(I>3)?3:I;var F=function(K){K.find(".js-remove-button").prop("disabled",(K.find("li").length<=2))};A(".b-poll-fieldset__poll-answers").each(function(){F(A(this))});J.off("click",".js-poll__view-results").on("click",".js-poll__view-results",function(M){M.preventDefault();var L=A(this).attr("data-nodeid"),K=A(this).closest("form");A.post(vBulletin.getAjaxBaseurl()+"/poll/get",{nodeid:L},function(N){B(K,N)},"json")});J.off("click",".js-poll__back-to-poll").on("click",".js-poll__back-to-poll",function(L){L.preventDefault();var K=A(this).closest(".js-poll__parent");K.find("div.pollresults").addClass("h-hide");K.find("form.poll").show()});J.off("click",".b-poll-fieldset__add-more").on("click",".b-poll-fieldset__add-more",function(M){var N=A(this),L=N.prev(".b-poll-fieldset__poll-answers"),K=L.find("li").first().clone(true);K.find(".b-form-input__input").val("").attr("name","polloptions[new][]");K.appendTo(L).find(".b-form-input__input").focus();if(L.find("li").length==I){N.addClass("h-hide")}F(L);return false});J.off("click",".b-poll-fieldset__poll-answers .js-remove-button").on("click",".b-poll-fieldset__poll-answers .js-remove-button",function(){var L=A(this),K=L.closest(".b-poll-fieldset__poll-answers");L.closest("li").remove();K.next(".b-poll-fieldset__add-more").removeClass("h-hide");F(K);return false});J.off("click",".js-poll-timeout").on("click",".js-poll-timeout",function(L){var K=A(this).closest(".b-poll-fieldset__poll-options").next(".b-poll-fieldset__datepicker-container");if(this.checked){K.removeClass("h-hide")}else{K.addClass("h-hide").find(".b-datepicker__input").val("")}});J.off("submit.formpoll","form.poll").on("submit.formpoll","form.poll",function(N){N.preventDefault();var K=A(this);var M=K.find('[name="polloptionid"]:checked').val();var L=[];K.find('[name="polloptionids[]"]:checked').each(function(){L.push(A(this).val())});A.post(vBulletin.normalizeAjaxUrl(K.attr("action")),{polloptionid:M,"polloptionids[]":L},function(P){if(P==false){openAlertDialog({title:vBulletin.phrase.get("vote_now"),message:vBulletin.phrase.get("vote_failed"),iconType:"warning"})}else{B(K,P);var O=K.parent();A("div.pollresults",O).find(".js-poll__back-to-poll").remove()}},"json")});A(document).off("click",".pollresults-data .voter-icon").on("click",".pollresults-data .voter-icon",function(){var K=A(this);if(K.find(".voters").is(":visible")){return false}A(".pollresults-data tr td.pollvoter-cell .voter-icon .voters").hide();var N=K.attr("data-node-id"),M=K.attr("data-polloption-id"),L=K.closest("form");A.post(vBulletin.getAjaxBaseurl()+"/poll/get-voters",{nodeid:N,polloptionid:M},function(O){if(O){if(!O.error){C(L,O,M,K)}else{D({message:O.error,type:"error"},K)}}else{D({message:vBulletin.phrase.get("vote_error_retrieving"),type:"error"},K)}},"json")});A(document).off("click",".pollresults-data .voter-icon .voters").on("click",".pollresults-data .voter-icon .voters",function(){e.stopPropagation();return true});if(A(".polloptioncontainer.new",J).length>0){for(var G=0;G<H-1;G++){A("a#addanswer",J).click()}if(H==I){A("a#addanswer",J).hide()}}}vBulletin.conversation.bindEditFormEventHandlers("poll");function D(H,G){var I=G.find(".voters");if(H.message){var F=A("<span />").addClass(H.type).text(H.message);I.html(F)}else{I.html(H.voters)}I.fadeIn("slow");A("body").on("click.voterpopup",function(J){if(A(J.target).closest(".voter-icon").length==0){I.hide();A("body").off("click.voterpopup")}})}function C(F,H,K,I){var M=false;if(H.options){B(F,H);var J=H.options[K];if(J){M=true;if(!A.isEmptyObject(J.votersinfo)){var L=[];for(var G in J.votersinfo){L.push('<a href="{0}">{1}</a>'.format(pageData.baseurl+J.votersinfo[G].profileUrl,J.votersinfo[G].username))}D({voters:L.join(", ")},I)}else{D({message:vBulletin.phrase.get("vote_first"),type:"note"},I)}}}if(!M){D({message:vBulletin.phrase.get("vote_error_retrieving"),type:"error"},I)}}function B(G,L){var F=G.parent(),H=L.options,K="";for(var I in H){var J=A(".pollresults-option-"+H[I].polloptionid);J.find(".title").html(JShtmlEncode(H[I].title));J.find(".bar-container .bar").css("width",H[I].percentage+"%");J.find(".percentage").html(H[I].display_percentage+"%");J.find(".votes span").html(H[I].votes);if(H[I].votes==1){K="vote"}else{K="votes"}J.find(".votes label").html(vBulletin.phrase.get(K))}A(".pollresults .pollvote-count span",F).html(L.poll_votes);if(L.poll_votes==1){K="voter"}else{K="voters"}A(".pollresults .pollvote-count label",F).html(vBulletin.phrase.get(K));G.hide();A("div.pollresults",F).removeClass("h-hide")}E(A(document))})})(jQuery);