
var com;if (!com) {com = {};} else if (typeof com != "object") {throw new Error("Non-object \"com\" is already defined.");}if (!com.civicscience) {com.civicscience = {};} else if (typeof com.civicscience != "object") {throw new Error("Non-object \"com.civicscience\" is already defined.");}if (!com.civicscience.ballotbox) {com.civicscience.ballotbox = {};} else if (typeof com.civicscience.ballotbox != "object") {throw new Error("Non-object \"com.civicscience.ballotbox\" is already defined.");}(function() {var NAMESPACE = com.civicscience.ballotbox;var DMODE_DESKTOP = "click";var DMODE_MOBILE = "touch";var REGEXP_DMODE = new RegExp("\\b" + DMODE_DESKTOP + "|" + DMODE_MOBILE + "\\b");var PAGE_URL = "";(function() {var w;for (w = window; w.parent != w; w = w.parent);try {PAGE_URL = w.location.href;} catch (e) {PAGE_URL = window.document.referrer;}})();var Request = (function() {var reqId = 0;var handlerMap = {};var constructor = function(url, handler) {this.send = function() {reqId++;handlerMap[reqId] = handler;if (url.indexOf("?") == -1) {url += "?";} else {url += "&";}url += "reqId=" + escape(reqId);url += "&responseHandler=com.civicscience.ballotbox.Request.acceptResponse";var script = document.createElement("SCRIPT");script.type = "text/javascript";script.src = url;document.body.appendChild(script);};};constructor.acceptResponse = function(response) {if (response.reqId) {var handler = handlerMap[response.reqId];delete handlerMap[response.reqId];if (typeof handler == "function") {handler(response.data);}}};return constructor;})();NAMESPACE.Request = Request;var Events = {addListener: function(obj, type, listener) {var f = function(event) {listener.apply(obj, [event || window.event]);};if (obj.addEventListener) {obj.addEventListener(type, f, false);} else if (obj.attachEvent) {obj.attachEvent("on" + type, f);} else {var orig = obj["on" + type];obj["on" + type] = function(event) {if (typeof orig == "function") {orig.apply(obj, [event || window.event]);}f(event);};}} };NAMESPACE.Events = Events;var DOM = {addClass: function(elt, cl) {if (typeof elt.className == "string") {var classes = elt.className.split(/\s+/);var i;for (i = 0; i < classes.length && classes[i] != cl; i++);if (i == classes.length) {classes.push(cl);elt.className = classes.join(" ");}}}, removeClass: function(elt, cl) {if (typeof elt.className == "string") {var classes = elt.className.split(/\s+/);var i;for (i = 0; i < classes.length; i++) {if (classes[i] == cl) {classes.splice(i--, 1);}}elt.className = classes.join(" ");}}, getVisibilityMetrics: function(elt) {var winh = document.documentElement.clientHeight;var winy = window.pageYOffset;if (!elt.getBoundingClientRect) {return {};}var bcr = elt.getBoundingClientRect();var elth = bcr.bottom - bcr.top + 1;var elty = bcr.top + winy;return {elth: Math.round(elth),
elty: Math.round(elty),
winh: Math.round(winh),
winy: Math.round(winy)
};}}; var Widget = function(containerElt, voteBtn) {var THIS = this;var deviceMode = (function() {var m = REGEXP_DMODE.exec(containerElt.getElementsByTagName("div")[0].className);return m == null ? "" : m[0];})();this.getDeviceMode = function() {return deviceMode;};var bodyElt = (function() {var re = /\bpoll_body\b/;var elts = containerElt.getElementsByTagName("div");var i;for (i = 0; i < elts.length; i++) {if (re.test(elts[i].className)) {return elts[i];}}return null;})();if (!bodyElt) {return;}this.getBodyElement = function() {return bodyElt;};var isMobileFriendly = false;this.setMobileFriendly = function(enabled) {isMobileFriendly = !!enabled;};this.isMobileFriendly = function() {return isMobileFriendly;};this.getProgressElement = function() {var progressElt = null;var re = isMobileFriendly || deviceMode != "" ? /\bballotbox\b/ : /\bpoll_progress\b/;var elts = containerElt.getElementsByTagName("div");var i;for (i = 0; i < elts.length && progressElt == null; i++) {if (re.test(elts[i].className)) {progressElt = elts[i];}}this.getProgressElement = function() {return progressElt;};return progressElt;};this.setProgress = function(current, total) {var elt = THIS.getProgressElement();if (elt == null || typeof elt.className != "string") {return;}var clear = /^(current|question|total)_/;var classes = elt.className.split(/\s+/);var i;for (i = 0; i < classes.length; i++) {if (clear.test(classes[i])) {classes.splice(i--, 1);}}if (current >= 0 && total >= 0) {if (isMobileFriendly || deviceMode != "") {classes.push("question_" + current);} else {classes.push("current_" + current);}classes.push("total_" + total);}elt.className = classes.join(" ");};var bodyLoadingClassIsEnabled = false;this.setBodyLoadingClassIsEnabled = function(enabled) {bodyLoadingClassIsEnabled = !!enabled;}; this.setBodyIsLoading = function(loading) {if (!loading) {DOM.removeClass(bodyElt, "loading");} else if (bodyLoadingClassIsEnabled) {DOM.addClass(bodyElt, "loading");}}; this.getQuestionsUrl = "";this.getResultsUrl = "";this.putResponsesUrl = "";this.isLongForm = false;this.isOptOutUser = false;var receivedQidList = [];this.getReceivedQidList = function() {return receivedQidList;}; function receivedQuestion(qid) {receivedQidList.unshift(qid);var i;for (i = 1; i < receivedQidList.length; i++) {if (receivedQidList[i] == qid) { receivedQidList.splice(i--, 1);}}if (receivedQidList.length > 30) {receivedQidList.pop();}} var LOCAL_NAME = "__iqpbb";function getLocalId() {var id = null;if (!THIS.isOptOutUser) {try {if ("localStorage" in window) {var storage = window["localStorage"];if (storage != null) {id = storage.getItem(LOCAL_NAME);if (id == null) {function r() {return Math.floor(Math.random() * 4294967296);}id = r() + "." + r();storage.setItem(LOCAL_NAME, id);}}}} catch (e) {}}return id;} function start() {var params = [];var id = getLocalId();if (id) {params.push("al=" + encodeURIComponent(id));}if (PAGE_URL) {params.push("pgurl=" + encodeURIComponent(PAGE_URL));}var vmmap = DOM.getVisibilityMetrics(containerElt);var vm;for (vm in vmmap) {params.push(encodeURIComponent(vm) + "=" + encodeURIComponent(vmmap[vm]));}if (params.length > 0) {THIS.getQuestionsUrl
+= (THIS.getQuestionsUrl.indexOf("?") == -1 ? "?" : "&")
+ params.join("&");}var qp = new QuestionPager(THIS, voteBtn);qp.addReceivedQuestionListener(receivedQuestion);qp.addFinishListener(showResults);qp.run();} var isRunning = false;this.run = function() {if (isRunning) {return;}isRunning = true;start();}; this.restart = function() {if (isRunning) { var qurl = this.getQuestionsUrl;qurl += qurl.indexOf("?") == -1 ? "?" : "&";qurl += "restart=1";this.getQuestionsUrl = qurl;this.getResultsUrl = "";this.putResponsesUrl = "";start();}}; var showResults = function() {if (THIS.getResultsUrl) {var url = THIS.getResultsUrl;if (THIS.isLongForm) {url += url.indexOf("?") == -1 ? "?" : "&";url += "form=long";}THIS.setBodyIsLoading(true);new Request(url, function(response) {THIS.setBodyIsLoading(false);if (response.results) {var pobjList = response.results.pages;if (pobjList) {var first = null;var prev = null;var i;for (i = 0; i < pobjList.length; i++) {var pobj = pobjList[i];if (pobj.html) {var prev = new ResultsPage(THIS, pobj.html, prev);if (first == null) {first = prev;}}}if (first == null) {while (bodyElt.firstChild) {bodyElt.removeChild(bodyElt.firstChild);}} else {first.show();}}}}).send();}}; };NAMESPACE.Widget = Widget;var VoteButton = function(html) {var THIS = this;var rootElt = document.createElement("div");rootElt.innerHTML = html;this.getRootElement = function() {return rootElt;};var voteBtn = null;(function() {var inputs = rootElt.getElementsByTagName("input");var i;for (i = 0; i < inputs.length && voteBtn == null; i++) {if (/\bvote\b/.test(inputs[i].className)) {voteBtn = inputs[i];}}if (voteBtn == null) {throw new Error("missing vote button control");}})();this.getButton = function() {return voteBtn;};};NAMESPACE.VoteButton = VoteButton;var QuestionPager = function(widget, voteBtn) {var THIS = this;var MAX_PAGE_SIZE = widget.isLongForm ? Number.MAX_VALUE : 1;var qobjList = [];var qobjIndex = 0;var askedList = [];var isVoting = false;var receivedQuestionListeners = [];this.addReceivedQuestionListener = function(f) {if (typeof f == "function") {receivedQuestionListeners.push(f);}}; var run = function() {var origIndex = qobjIndex;var bodyElt = widget.getBodyElement();while (bodyElt.firstChild) {bodyElt.removeChild(bodyElt.firstChild);}askedList = [];while (qobjIndex < qobjList.length) {var qobjMax = Math.min(qobjList.length, qobjIndex + MAX_PAGE_SIZE);var asked = false;while (qobjIndex < qobjMax) {var qobj = qobjList[qobjIndex++];var question = null;switch (qobj.type) {case "radio":question = new RadioQuestion(widget, THIS, qobj.html);break;}if (question != null) {if (MAX_PAGE_SIZE == 1) {widget.setProgress(qobjIndex, qobjList.length);}question.ask();askedList.push(question);}}if (askedList.length > 0) {if (voteBtn) {widget.getBodyElement().appendChild(voteBtn.getRootElement());}isVoting = false;return;}}if (MAX_PAGE_SIZE == 1) {widget.setProgress(-1, -1);}if (origIndex == 0 && qobjList.length != 0) {finish();} else if (widget.getQuestionsUrl) {var url = widget.getQuestionsUrl;var xqids = widget.getReceivedQidList();if (xqids.length > 0) {url += url.indexOf("?") == -1 ? "?" : "&";url += "xq=." + xqids.join(".");}widget.setBodyIsLoading(true);new Request(url, function(response) {widget.setBodyIsLoading(false);qobjList = response.questions || [];if (response.session) {widget.getQuestionsUrl = response.session.getQuestionsUrl;widget.getResultsUrl = response.session.getResultsUrl;widget.putResponsesUrl = response.session.putResponsesUrl;}if (qobjList.length == 0) {finish();} else {var i;for (i = 0; i < receivedQuestionListeners.length; i++) {var j;for (j = 0; j < qobjList.length; j++) {receivedQuestionListeners[i](qobjList[j].id);}}qobjIndex = 0;run();}}).send();}}; this.run = run;var vote = function() {if (!isVoting && widget.putResponsesUrl) {var params = "";var i;for (i = 0; i < askedList.length && askedList[i].isVotable(); i++) {if (params) {params += "&";}params += askedList[i].getUrlParams();}if (i == askedList.length) {var url = widget.putResponsesUrl;if (params != "") {url += url.indexOf("?") == -1 ? "?" : "&";url += params;}new Request(url, function(response) {if (response.ok) {if (response.session) {widget.getQuestionsUrl = response.session.getQuestionsUrl;widget.getResultsUrl = response.session.getResultsUrl;widget.putResponsesUrl = response.session.putResponsesUrl;}run();} else {isVoting = false;}}).send();isVoting = true;}}}; this.vote = vote;if (voteBtn) {Events.addListener(voteBtn.getButton(), "click", vote);}var finishListeners = [];this.addFinishListener = function(f) {if (typeof f == "function") {finishListeners.push(f);}};var finish = function() {var i;for (i = 0; i < finishListeners.length; i++) {finishListeners[i].apply(THIS, []);}}; }; var Question = function(widget, pager, html) {var rootElt = document.createElement("div");rootElt.innerHTML = html;this.getRootElement = function() {return rootElt;};this.getUrlParams = function() {return "";};this.isVotable = function() {return false;};this.ask = function() {widget.getBodyElement().appendChild(rootElt);};}; var RadioQuestion = function(widget, pager, html) {Question.apply(this, [widget, pager, html]);var THIS = this;var radioBtns = [];(function() {var inputs = THIS.getRootElement().getElementsByTagName("input");var i;for (i = 0; i < inputs.length; i++) {if (inputs[i].type == "radio") {radioBtns.push(inputs[i]);if (widget.isMobileFriendly() || widget.getDeviceMode() == DMODE_MOBILE) {Events.addListener(inputs[i], "click", function() {pager.vote();});}} else if (inputs[i].type == "button" && /\bsubmit\b/.test(inputs[i].className)) {Events.addListener(inputs[i], "click", function() {pager.vote();});}}})();this.getUrlParams = function() {var params = "";var i;for (i = 0; i < radioBtns.length && !params; i++) {if (radioBtns[i].checked) {params = radioBtns[i].value;}}return params;};this.isVotable = function() {var i;for (i = 0; i < radioBtns.length && !radioBtns[i].checked; i++);return i < radioBtns.length;};}; var ResultsPage = function(widget, html, prevPage) {var THIS = this;this.prevPage = prevPage;this.nextPage = null;if (prevPage != null) {prevPage.nextPage = this;} else {ResultsPage.questionTotal = 0;}var rootElt = document.createElement("div");rootElt.innerHTML = html;this.questionIndex = -1;(function() {var re = /\bquestion_text\b/;var elts = rootElt.getElementsByTagName("div");var i = 0;for ( ; i < elts.length && !re.test(elts[i].className); i++);if (i < elts.length) {var p = prevPage;for ( ; p != null && p.questionIndex == -1; p = p.prevPage);if (p == null) {THIS.questionIndex = 1;} else {THIS.questionIndex = p.questionIndex + 1;}ResultsPage.questionTotal = THIS.questionIndex;}})();this.show = function() {var container = widget.getBodyElement();while (container.firstChild) {container.removeChild(container.firstChild);}container.appendChild(rootElt);if (widget.isMobileFriendly() || widget.getDeviceMode() != "") {if (ResultsPage.questionTotal && this.questionIndex >= 0) {widget.setProgress(this.questionIndex, ResultsPage.questionTotal);} else {widget.setProgress(-1, -1);}}};var prevBtn = null;var nextBtn = null;(function() {var inputs = rootElt.getElementsByTagName("*");var i;for (i = 0; i < inputs.length; i++) {if (/\bprevious\b/.test(inputs[i].className)) {prevBtn = inputs[i];} else if (/\bnext\b/.test(inputs[i].className)) {nextBtn = inputs[i];}}})();if (prevBtn) {Events.addListener(prevBtn, "click", function() {if (THIS.prevPage) {THIS.prevPage.show();}});}if (nextBtn) {Events.addListener(nextBtn, "click", function() {if (THIS.nextPage) {THIS.nextPage.show();} else {widget.restart();}});}}; })();(function() {var BALLOTBOX = com.civicscience.ballotbox;var onload = function() {var linkElt = document.createElement("link");linkElt.rel = "stylesheet";linkElt.type = "text/css";linkElt.href = "https:\/\/civicscience-css.s3.amazonaws.com\/clients\/trib\/trib.css";document.getElementsByTagName("head")[0].appendChild(linkElt);var container = document.getElementById("3bb88dc5-ab29-74a4-c5f0-fd921cb48107");if (container) {container.innerHTML = "<div class=\"civicscience ballotbox\">\n    <div class=\"poll_title\">4-Question Trib Poll<\/div>\n    <div class=\"poll_body\"><\/div>\n            <div class=\"poll_progress\"><\/div>\n                <div class=\"poll_footer\"><\/div>\n    <\/div>";var voteBtn = new BALLOTBOX.VoteButton("<div class=\"buttons\">\n    <input type=\"button\" class=\"vote\" value=\"Submit\" \/>\n<\/div>\n");var widget = new BALLOTBOX.Widget(container, voteBtn);widget.isLongForm = false;widget.isOptOutUser = false;widget.getQuestionsUrl = "https:\/\/www.civicscience.com\/widget\/jspoll\/getQuestions?tgt=699";widget.setBodyLoadingClassIsEnabled(true);widget.setMobileFriendly(false);widget.run();}};BALLOTBOX.Events.addListener(window, "load", onload); })();