define(["require","exports","stApp","angular","cookie-helper","wh.jsencrypt","intersect-observer"],function(e,t){function n(){return null!=c.match(/iPhone|iPad|iPod/i)||d&&null!=d.match(/iPhone|iPad|iPod/i)}var s=e("stApp"),a=e("angular"),o=e("cookie-helper"),i=e("wh.jsencrypt"),r=e("intersect-observer"),l=a.element,c=navigator.userAgent,d=navigator.platform?navigator.platform:"";s.register.factory("$question-resolver",function(){var e;return{set:function(t){e=t},clear:function(){e=null},get:function(){return e}}}),s.register.controller("CommunitySearchController",["$rootScope","$scope","$element","$timeout","$question-resolver","$http","$q","$window","$location",function(t,s,i,c,d,u,p,m,f){function h(e){a.forEach(e,function(e){var t=e.ques_content,n=document.createElement("div");n.innerHTML=t,e.ques_content_label=n.innerText,a.forEach(e.answers||[],function(e){a.isArray(e.content)&&2==e.content.length&&"[[:hellip:]]"==e.content[0]?e.content_parsed=e.content[1]||"":e.content_parsed=function(e){var t="<span class='ellipsis' aria-hidden='true' tabindex='-1'>&hellip;</span><br><span data-hm-tap='morelink($event);' class='more-link' tabindex='0' role='button'>show more <i class='af-icon-down-open' ng-aria-hidden></i></span>";return a.isArray(e.content)&&2==e.content.length?"<div class='condensed'>"+e.content[0].replace("[[:hellip:]]",t)+"</div><div class='hidden'>"+e.content[1]+"</div><span data-hm-tap='lesslink($event);' class='less-link' tabindex='0' role='button'>show less <i class='af-icon-up-open' ng-aria-hidden></i></span>":e.content.replace("[[:hellip:]]",t)}(e)})})}s.comsearch_q_link=function(e){return"/answers/"+e.ques_slug+"-"+e.id.replace(/^q/,"")+"/"},s.morelink=function(e){l(e.target).closest(".answer-content").addClass("more")},s.lesslink=function(e){l(e.target).closest(".answer-content").removeClass("more")},s.open_sort=function(e){l(e.target).next(".popup-list").addClass("show")},s.comresults_loading=!1,s.sort_ans_opts=[["Most Popular","mp"],["Most Upvotes","mv"]],s.ans_sort="mp",s.$watch("ans_sort",function(e,t){e!=t&&u({url:"/ajax.php",params:{action:"Answers.CommunityQASort",uri:document.location.pathname,sort_by:e}}).then(function(e){var t=e.data,n=l(i),s=n.find(".questions");s.html(t.html),s.find(".answer-user-avatar[data-src]").each(function(){var e=l(this);e.attr("src",e.attr("data-src")),e.removeAttr("data-src"),e.addClass("answer-user-avatar-load"),e.css({display:"block"})}),n.data("qp",1),1==t.pages?l(i).find(".ftrbtns .viewmore").remove():0==l(i).find(".ftrbtns .viewmore").length&&l("<span class='btn blank grey no-decoration viewmore'><span class='txt'>View More Questions</span><span class='af-icon-spin6 animate-spin'></span></span>").prependTo(l(i).find(".ftrbtns")),setTimeout(function(){l(i).find(".questions .question .answers .message.more-content .answer-content").each(function(){var e=l(this);e.prop("scrollHeight")<=e.prop("clientHeight")&&e.closest(".message").removeClass("more-content")}),l(i).find(".questions .question .main-q .more-info").each(function(){var e=l(this);e.prop("scrollHeight")<=e.prop("offsetHeight")+(e.find("span.match").length>0?2:0)&&e.next(".more-info-more").remove()})},150)})}),s.showUserGeneratedDisc=!1,s.showMoreDisc=function(e,t){s.showUserGeneratedDisc="more"==t},s.isShowIntroQA=!1,s.showIntroQA=function(e,t){"more"==t?(s.isShowIntroQA=!0,c(function(){s.isShowIntroQA=!0})):s.isShowIntroQA=!1},s.autoExpand=function(e){var t="object"==typeof e?e.target:document.getElementById(e),n=t.offsetHeight-t.clientHeight;t.style.height="auto",t.style.height=t.scrollHeight+n+"px"},s.live_status="",l(i).on("click",".questions .question .main-q .more-info-more span[class$=-link]",function(){l(this).closest(".main-q").toggleClass("more")}).on("click",".questions .question .main-q .reply",function(){function t(t){var s=c[0];c.show().trigger("focus").hide();var a=c.data("ckeditor-instance");a?a.setValue(t||""):e(["input-ckeditor"],function(e){var a=e(s,{},t,!0);a.ready(function(e){e?c.data("ckeditor-instance",a):(s.show().focus(),n.attr("aria-expanded","true"))})})}var n=l(this),s=n.closest(".question"),i=s.data("id"),r=s.find(".replyform"),c=r.find(".editor-content"),d=o.read("mw_signon")||"{}",p=o.is_logged_in();d.length>2&&"{"==d.charAt(0)&&"}"==d.charAt(d.length-1)&&(d=a.fromJson(d),a.isObject(d)&&"pp"in d&&r.find(".avatar img").attr("src",d.pp)),s.addClass("show-reply"),i&&0===i.indexOf("q")&&(i=i.substring(1)),p?(r.addClass("disabled"),c.attr("disabled","disabled"),u({url:"/ajax.php",params:{action:"Answers.QuestionHasAnswered",qid:i}}).then(function(e){r.removeClass("disabled"),c.removeAttr("disabled");var n=e.data;"answer"in n?t(n.answer):t()},function(e){401!=e.status?(s.removeClass("disabled"),c.removeAttr("disabled"),t()):top.location.href="/join/light?lg&redirect_to="+encodeURIComponent(document.location.href)})):t()}).on("click",".questions .question .replyform .hide-reply",function(){l(this).closest(".question").removeClass("show-reply");var e=l(this).closest(".question").find(".main-q .reply");e.attr("aria-expanded","false"),e.trigger("focus")}).on("click",".questions .question .replyform .submit",function(){var e=l(this).closest(".question"),t=e.find(".replyform"),n=t.find(".editor-content"),a=n.data("ckeditor-instance")&&n.data("ckeditor-instance").value||n.val();if(!t.hasClass("disabled")){if(a.length<30)return window.alert("Please add at least 30 characters."),void(n.data("ckeditor-instance")&&n.data("ckeditor-instance").view||n).focus();s.$applyAsync(function(){s.live_status="Posting Answer"}),t.addClass("disabled"),u({method:"POST",url:"/ajax.php",data:{action:"Answers.AnswerQuestion",do:"user-answer",question_id:e.data("id").replace(/^q/,""),answer:a}}).then(function(a){t.removeClass("disabled");var o,i=a.data;if(i){if("redirect"in i)return void(top.location.href=i.redirect);if("error"in i&&!0===i.error&&"message"in i){var r=i.message.match(/^Bad word `(.+)` detected\.$/);return r&&r.length?window.alert('Profanity is not allowed, including words such as "'+r[1]+'". Please adjust.'):window.alert(i.message),void n.trigger("focus")}if("id"in i){if((o=e.find(".message[data-id="+i.id+"]")).length>0)"answer"in i&&o.find(".answer-content").html(i.answer);else{var d="<div class='message more-content show' data-id='"+i.id+"'><div class='answer-top'><div class='avatar'><img src='"+i.avatar+"' class='avatar-img' alt='user avatar' width='40' height='40'></div><div class='answer-names'><div class='full-name' tabindex='0'>"+i.fullname+"</div><div class='second-name' aria-hidden='true' tabindex='-1'>@"+i.username+'</div></div></div><span class="ng-hide" role="tooltip" id="ans-desc-'+i.id+'">Answer provided by you</span><div class="answer-content" tabindex="0" aria-describedby="ans-desc-'+i.id+'">'+i.answer+"</div><div class='thumbs' role='none'><span class='upvote bf-icon-upvote' role='button' tabindex='0' aria-label='0 up votes'><span class='upvotes'>0<i class='af-icon-spin6 animate-spin' aria-hidden='true' tabindex='-1'></i></span></span><span class='dnvote bf-icon-downvote' role='button' tabindex='0' aria-label='0 down votes'><span class='dnvotes'>0<i class='af-icon-spin6 animate-spin' aria-hidden='true' tabindex='-1'></i></span></span></div></div>";0==(o=e.find(".answers")).length&&(o=l("<div class='answers'></div>").insertAfter(e.find(".main-q"))),o.append(d),s.$applyAsync(function(){s.live_status="Answer Posted",c(function(){s.live_status="",o.find(".message").last().find(".answer-content").focus()},1e3)})}e.find(".main-q span.reply").hide()}e.removeClass("show-reply"),e.find(".main-q span.reply").attr("aria-expanded","false")}},function(e){t.removeClass("disabled"),401==e.status&&(top.location.href="/join/light?lg&redirect_to="+encodeURIComponent(document.location.href))})}}).on("click",".questions .question .moreans",function(){var e=l(this),t=e.closest(".question"),a=t.find(".q-title").attr("href"),o={};o.action="Answers.GetMoreAnswers",o.qid=t.data("id"),o.v=2,o.answers=t.find(".answers > .message").length,e.focus(),e.addClass("loading"),s.$applyAsync(function(){s.live_status="Loading more answers"}),u({url:"/ajax.php",params:o}).then(function(o){for(var i=o.data,r=0;r<i.answers.length;r++){var l=i.answers[r],c="<div class='message more-content' data-id='"+l.id+"'><div class='answer-top'><div class='avatar'><img src='"+l.user_avatar+"' class='avatar-img' width='40' height='40' alt='user avatar' tabindex='0' /></div><div class='answer-names'>";""!=l.user_title?c+="<div class='full-name' role='text' tabindex='0'>"+l.user_fullname+"<span class='cap'>, "+l.user_title+"</span></div>":c+="<div class='full-name' role='text' tabindex='0'>"+l.user_fullname+"</div>",c+="<div class='second-name' tabindex='-1' aria-hidden='true'>@"+l.user_login+'</div></div></div><span class="ng-hide" id="ans-desc-'+l.id+'">Answer provided by user: '+l.user_fullname+"</span><div class='answer-content' tabindex='0' aria-describedby='ans-desc-"+l.id+"'>"+l.content+"</div><div class='answer-content-more'><a href='"+a+"' class='more-link' tabindex='0' rel='nofollow'>show more<span class='bf-icon-right-open-big' aria-hidden='true' tabindex='-1'></span></a></div><div class='thumbs'><span class='upvote bf-icon-upvote' role='button' tabindex='0' aria-label='"+l.upvote+" up vote"+(1!=l.upvote?"s":"")+"'><span class='upvotes'>"+l.upvote+"<i class='af-icon-spin6 animate-spin'></i></span></span><span class='dnvote bf-icon-downvote' role='button' tabindex='0' aria-label='"+l.upvote+" down vote"+(1!=l.upvote?"s":"")+"'><span class='dnvotes'>"+l.downvote+"<span class='af-icon-spin6 animate-spin'></span></span></span></div></div>",(l=t.find(".answers").append(c).find(".answer-content:last")).prop("scrollHeight")<=l.prop("offsetHeight")&&l.closest(".message").removeClass("more-content")}0==i.left?e.closest(".moreans").hide():e.closest(".moreans").removeClass("loading");var d=i.answers.length;if(d){var u=document.querySelector("[data-status-ans]")||document.createElement("div");u.setAttribute("data-status-ans","status"),u.setAttribute("aria-live","polite"),u.setAttribute("role","status"),u.setAttribute("tabindex","-1"),u.setAttribute("aria-hidden","true");var p=document.querySelector('.answers .message[data-id="'+i.answers[0].id+'"]');t.find(".answers")[0].insertBefore(u,p),u.setAttribute("aria-label","");var m="Loaded "+d+" more answer"+(1!=d?"s":"");u.setAttribute("aria-label",m),n()&&s.$applyAsync(function(){s.live_status=m}),requestAnimationFrame(function(){u.focus()})}})}).on("click",".question-form.no-question .q-btn,.question-form .question-box .q-btn,.question-form .search-notice .btn,.ftrbtns .btn.blue",function(){function e(){d.set(s.comsearch),l(".ask-overlay .askform").css("top",m.scrollY-55+"px"),s.$apply(function(){t.show_ask_overlay=!0})}var n=l(document).height();n-l(document).scrollTop()<1200?(l("html,body").scrollTop(n-1200),e()):e()}).on("click",".answer-content-more span",function(){var e=l(this).closest(".message");e.toggleClass("show"),e.hasClass("show")?e.find(".answer-content").focus():(e.find(".more-link").focus(),setTimeout(function(){e.find(".more-link").focus()}))}).on("click",".ftrbtns .viewmore",function(){var e=l(this),t=l(i);"p"in f.search()&&void 0===t.data("qp")&&t.data("qp",parseInt(f.search().p));var a=t.data("qp")||1;e.addClass("loading");var o=document.location.href,r=e.data("url");void 0!==r&&""!=r&&(o=r),s.$applyAsync(function(){s.live_status="Loading more questions"}),u({url:"/ajax.php",params:{action:"Answers.GetMoreQuestions",url:o,p:a+1,sort_by:s.ans_sort}}).then(function(o){s.$applyAsync(function(){s.live_status=""});var r=document.querySelectorAll(".comqa .questions .question"),d=r[r.length-1],u=r.length,p=o.data;e.removeClass("loading");var m=document.createElement("div");l(m).html(p.html),l(m).find(".answer-user-avatar[data-src]").each(function(){var e=l(this);e.attr("src",e.attr("data-src")),e.removeAttr("data-src"),e.addClass("answer-user-avatar-load"),e.css({display:"block"})}),t.find(".questions").append(l(m).html()),s.after_loading_more=!0,c(function(){s.after_loading_more=!1},100);var f=(r=document.querySelectorAll(".comqa .questions .question")).length-u,h=document.querySelector("[data-status-question]")||document.createElement("div");h.setAttribute("data-status-question","status"),h.setAttribute("aria-live","polite"),h.setAttribute("role","status"),h.setAttribute("tabindex","-1"),h.setAttribute("aria-hidden","true"),document.querySelector(".comqa .questions").insertBefore(h,d.nextSibling||d),h.setAttribute("aria-label","");var v="Loaded "+f+" more question"+(1!=f?"s":"");h.setAttribute("aria-label",v),n()&&s.$applyAsync(function(){s.live_status=v}),requestAnimationFrame(function(){h.focus()}),setTimeout(function(){l(i).find(".questions .question .answers .message.more-content .answer-content").each(function(){var e=l(this);e.prop("scrollHeight")<=e.prop("clientHeight")&&e.closest(".message").removeClass("more-content")}),l(i).find(".questions .question .main-q .more-info").each(function(){var e=l(this);e.prop("scrollHeight")<=e.prop("offsetHeight")+(e.find("span.match").length>0?2:0)&&e.next(".more-info-more").remove()})},150),!1===p.more?e.remove():t.data("qp",a+1)})}).on("click",".upvote,.dnvote",function(){if(!o.is_logged_in())return top.location.href="/join/light?redirect_to="+encodeURI(document.location.href),!1;var e=l(this),t=e.closest(".question"),n=e.find("> span[class$='votes']").addClass("loading"),i="answer",r="up",c=t.data("id");e.parent().hasClass("main-q")&&(i="question"),e.hasClass("dnvote")&&(r="dn"),"answer"==i&&(c=e.closest(".message").data("id")),s.live_status="Voting "+i;var d=c.match(/^([abceq])(\d+)$/);d&&(c=d.pop(),i=d.pop(),~["q","a"].indexOf(i)||(i="q"+i)),u.post("/ajax.php?action=Answers.Vote",{dir:r,kind:i,id:c}).then(function(a){s.live_status="",n.removeClass("loading");var o=a.data;if(o.error)window.alert("An unknown error has ocured.");else{e.attr("aria-live","polite"),setTimeout(function(){e.attr("aria-live","off")},1e3);var r,l;"q"==i.charAt(0)?(t.find("> .upvotes strong").text(o.votes_up),r=t.find(".main-q .upvotes"),l=t.find(".main-q .dnvotes"),r.parent().attr("aria-label",o.votes_up+" up vote"+(1!=o.votes_up?"s":"")),r.html(o.votes_up+"<i class='af-icon-spin6 animate-spin'></i>"),l.parent().attr("aria-label",o.votes_dn+" down vote"+(1!=o.votes_dn?"s":"")),l.html(o.votes_dn+"<i class='af-icon-spin6 animate-spin'></i>")):(r=n.closest(".thumbs").find(".upvotes"),l=n.closest(".thumbs").find(".dnvotes"),r.parent().attr("aria-label",o.votes_up+" up vote"+(1!=o.votes_up?"s":"")),r.html(o.votes_up+"<i class='af-icon-spin6 animate-spin'></i>"),l.parent().attr("aria-label",o.votes_dn+" down vote"+(1!=o.votes_dn?"s":"")),l.html(o.votes_dn+"<i class='af-icon-spin6 animate-spin'></i>")),o.upClass&&r?r.parent().attr("aria-label",r.parent().attr("aria-label")+". Pressed"):o.dnClass&&l&&l.parent().attr("aria-label",l.parent().attr("aria-label")+". Pressed")}},function(e){s.live_status="",n.removeClass("loading"),a.isObject(e)&&"data"in e&&(401!=e.status?window.alert("An unknown error has ocured."):top.location.href="/join/light?redirect_to="+encodeURI(document.location.href))})}).on("change","#sorting",function(){var e=l(this);u({url:"/ajax.php",params:{action:"Answers.CommunityQASort",uri:document.location.pathname,sort_by:e.val()}}).then(function(e){var t=e.data,n=l(i),s=n.find(".questions");s.html(t.html),s.find(".answer-user-avatar[data-src]").each(function(){var e=l(this);e.attr("src",e.attr("data-src")),e.removeAttr("data-src"),e.addClass("answer-user-avatar-load"),e.css({display:"block"})}),n.data("qp",1),1==t.pages?l(i).find(".ftrbtns .viewmore").remove():0==l(i).find(".ftrbtns .viewmore").length&&l("<span class='btn blank grey no-decoration viewmore'><span class='txt'>View More Questions</span><span class='af-icon-spin6 animate-spin'></span></span>").prependTo(l(i).find(".ftrbtns")),setTimeout(function(){l(i).find(".questions .question .answers .message.more-content .answer-content").each(function(){var e=l(this);e.prop("scrollHeight")<=e.prop("clientHeight")&&e.closest(".message").removeClass("more-content")}),l(i).find(".questions .question .main-q .more-info").each(function(){var e=l(this);e.prop("scrollHeight")<=e.prop("offsetHeight")+(e.find("span.match").length>0?2:0)&&e.next(".more-info-more").remove()})},150)})});var v,g=new RegExp("\\/css\\/searchtools\\/common\\.v13\\.d(_V[\\da-f]+_)?\\.css(\\.gz)?"),w=s.$watch(function(){for(var e=0;e<document.styleSheets.length;e++)if("href"in document.styleSheets[e]&&null!=document.styleSheets[e].href&&!1!==g.test(document.styleSheets[e].href))return!0;return!1},function(e){e&&setTimeout(function(){l(i).find(".questions .question .main-q .more-info").each(function(){var e=l(this);e.prop("scrollHeight")<=e.prop("offsetHeight")&&e.next(".more-info-more").remove()});var e=0;l(i).find(".questions .question .answers .message .answer-content").each(function(){var t=l(this);t.prop("scrollHeight")<=t.prop("clientHeight")&&(t.closest(".message").removeClass("more-content"),0==e&&(t.closest(".message").addClass("show"),t.next(".answer-content-more").find(".less-link").remove())),e++}),w()})}),b=p.defer();s.qna_result_label="",s.$watch("comsearch",function(e,n){e!=n?(c.cancel(v),t.comsearch=e,l(".question-form.no-question").length>0||(s.comresults_loading=!0,""==e?(b.resolve(),b=p.defer(),delete s.comresults,s.comresults_loading=!1):v=c(function(){!function(e){var t={action:"Answers.CommunitySearch",query:e};"/credit-cards/compare/"==document.location.pathname?t.category="credit-cards":t.uri=document.location.pathname,u({url:"/ajax.php",params:t,timeout:b.promise}).then(function(e){if(""!=s.comsearch){s.comresults=e.data,s.comresults_loading=!1,h(s.comresults||[]);var t=(s.comresults||[]).length;s.qna_result_label="Questions results. "+(t||"No ")+"Result"+(1!=t?"s":""),setTimeout(function(){l(i).find(".questions .question .main-q .more-info").each(function(){var e=l(this);e.prop("scrollHeight")<=e.prop("offsetHeight")+(e.find("span.match").length>0?2:0)&&e.next(".more-info-more").remove()})},100)}})}(e)},300))):c.cancel(v)});var q=new r(.5,50);l(".answer-user-avatar").each(function(e){var t=this,n=t.getAttribute("data-src");q.Observe(t.parentNode,function(){t.addEventListener("load",function(){l(t).addClass("answer-user-avatar-load")}),t.setAttribute("src",n),t.style.display="block",t.removeAttribute("data-src")})})}]),s.register.controller("CommunitySearchAskFormController",["$rootScope","$scope","$element","$question-resolver","$http",function(e,t,n,s,a){var r=1,c=!1;t.question="",t.details="",t.overlay_shown=!1,t.live_status="",e.$watch("show_ask_overlay",function(e){e&&(t.question=s.get()),t.overlay_shown!=e&&(t.overlay_shown=e||!1)}),t.autoExpand=function(e){var t="object"==typeof e?e.target:document.getElementById(e),n=t.offsetHeight-t.clientHeight;t.style.height="auto",t.style.height=t.scrollHeight+n+"px"};var d=140,u=3;t.chars_left=d,l(n).on("click touchend",".askform > span.closebtn",function(){t.$apply(function(){e.show_ask_overlay=!1});var n=document.querySelector(".comqa .search-notice .btn")||document.querySelector(".question-form.no-question .q-btn,.question-form .question-box .q-btn,.question-form .search-notice .btn,.ftrbtns .btn.blue");n&&n.focus()}).on("click touchend",".askform .ask .btn.next,.askform .step4 .btn.login,.askform .step4 .btn.em",function(){!function(e){if(t.question)if([].concat(t.question.split(/\s+/)).length<u)t.notice="Question must have at least "+u+" word"+(1!=u?"s":"")+".";else if(t.question.length>d)t.notice="Question cannot have more than "+d+" character"+(1!=d?"s":"");else if(!o.is_logged_in()&&r<4)r=4;else{c=!0;var n={question:t.question,url:document.location.href+""};""!=t.details&&(n.details=t.details),t.email?(n.email=i.localencrypt(t.email),n.publickey=i.localkey):e&&(n.light="true"),t.live_status="Submitting question",a({url:"/ajax.php?action=Answers.PostQuestion",method:"POST",data:n}).then(function(n){var s=n.data;if(c=!1,t.live_status="",s.error){if(!("message"in s))return void(s.message="Unexpected error. Please contact help@evolutionfinance.com");var a=s.message.match(/^Bad word `(.+)` detected\.$/);return a&&a.length&&(s.message='Profanity is not allowed, including words such as "'+a[1]+'". Please adjust.'),void(t.notice=s.message)}e&&"redirect"in s?top.location.href=s.redirect:(r=5,t.question="",t.details="",t.email="",l(".ask-overlay .closebtn").one("click touchend",function(){r=1}))})}else t.notice="Please enter your question."}(4==l(this).closest("section").data("step"))}),t.is_overlay_step=function(e){return r==e},t.is_additional_details_visible=function(){return t.chars_left<d},t.is_form_loading=function(){return c},t.back=function(){r=1}}]),e(["shortcode-js"],function(e){var t="https://"+location.host;(l(".pl-rates-div").length||l(".pl-terms-box").length)&&e.SetPrsWidgets(window,t),(l(".cc-mini-box").length||l(".cc-list-buttons").length||l(".cc-editorial-box").length)&&(e.ClearBoxes(),e.SetBoxes(window,t))},function(e){console.error(e)}),s.pageInjector.get("$stService").setControllerReady("CommunitySearchController"),s.pageInjector.get("$stService").setControllerReady("CommunitySearchAskFormController")});