/* Copyright © Pluck Corporation 2008. This software code and related intellectual property are the property of Pluck Corporation and are licensed for use solely on designated websites. Any distribution, copying, or other use of this intellectual property other than pursuant to a written agreement with Pluck Corporation is strictly prohibited. All Rights Reserved. */
// THIS FILE IS AUTOGENERATED. DO NOT EDIT THIS FILE DIRECTLY.
if (typeof(slwidgets) === 'undefined') {
  slwidgets = {};
}
if (typeof(slwidgets.widgetLoader) === 'undefined') {
  slwidgets.widgetLoader = {};
  (function(){
    // the local variable we'll use to queue up load calls
    var callbacks = [];
    // keeps track of what scripts we've already added
    var addedScripts = {};
    // have we added our onload handler before?
    var onLoadHandlerAdded = false;
    // called to check if every url is loaded
    var onLoadHandler = function(){
      // check that every url is loaded
      for (url in addedScripts) {
        if (addedScripts[url] == false) {
          // found a url that hasn't loaded, don't proceed
          return;
        }
      }
      // every url is loaded, so call all the callbacks
      for (var callbackIndex = 0; callbackIndex < callbacks.length; callbackIndex++) {
        callbacks[callbackIndex]();
      }
      // we've called all the callbacks, don't call them again
      callbacks = [];
    };
    
    var addUrlHandler = function(url) {
        // check to see if we've added this script before
        if (url in addedScripts) {
          // we've added it before, short circuit adding the script node to the head
          onLoadHandler();
          return;
        }
        // we've added the script, but haven't loaded it yet
        addedScripts[url] = false;
        // there should only be one head node
        var headNode = document.getElementsByTagName("head")[0];
        // make the script node
        var scriptNode = document.createElement("script");
        scriptNode.setAttribute("src", url);
        // if we're using Internet Explorer, use the onreadystatechange event; otherwise, use onload
        if ((/msie/i).test(navigator.userAgent)) {
          scriptNode.onreadystatechange = function(){
            if (this.readyState === 'loaded' || this.readyState === 'complete') {
              slwidgets.widgetLoader.requestComplete(url);
            }
          };
        } else {
          scriptNode.setAttribute("onload", "javascript:slwidgets.widgetLoader.requestComplete('" + url + "');");
        }
        headNode.appendChild(scriptNode);
    };
    
    slwidgets.widgetLoader.load = function(urls, callback){
        if (typeof(urls).length === 'undefined') {
            urls = [urls];
        }
        for (var i=0; i < urls.length; i++) {
            addUrlHandler(urls[i]);
        }
        
        // add the callback to our list of callbacks
        callbacks.push(callback);
        onLoadHandler();
    };
    
    slwidgets.widgetLoader.requestComplete = function(urlThatFinished){
      // set this url to loaded so our onload handler can check to make sure everything was loaded  before calling the callbacks
      addedScripts[urlThatFinished] = true;
      // check to see if we're done
      onLoadHandler();
    }
    
    slwidgets.widgetLoader.addWidgetDiv = function(){
        if (typeof(PLUCKSL_WIDGET_DIV) === 'string') {
            var id = PLUCKSL_WIDGET_DIV;
            delete PLUCKSL_WIDGET_DIV
            return id;
        } else if (typeof(PLUCKSLOLD_WIDGET_DIV) === 'string') {
            var id = PLUCKSLOLD_WIDGET_DIV;
            PLUCKSLOLD_WIDGET_DIV = false;
            return id;
        }
      var id = "widgetDiv-" + Math.random() + '-' + Math.random();
      document.write('<div id="' + id + '"><\/div>');
      return id;
    };
  })();
}
if (typeof(slwidgets.getServerBaseUrl) === 'undefined') {
	slwidgets.getServerBaseUrl = function(url){
		if(!url){ url = window.location.href; }
		if(url.indexOf('http://www.wellnessessentials.com') >= 0) {
			return 'http://sitelife.wellnessessentials.com/ver1.0';
		}
		if(url.indexOf('http://www.1stbirthdayideas.com') >= 0) {
			return 'http://sitelife.1stbirthdayideas.com/ver1.0';
		}
		if(url.indexOf('http://www.beermasters.com') >= 0) {
			return 'http://sitelife.beermasters.com/ver1.0';
		}
		if(url.indexOf('http://www.blogsports.net') >= 0) {
			return 'http://sitelife.blogsports.net/ver1.0';
		}
		if(url.indexOf('http://www.cod.com') >= 0) {
			return 'http://sitelife.cod.com/ver1.0';
		}
		if(url.indexOf('http://www.diabetesvoice.com') >= 0) {
			return 'http://sitelife.diabetesvoice.com/ver1.0';
		}
		if(url.indexOf('http://www.diabetesvoice.net') >= 0) {
			return 'http://sitelife.diabetesvoice.net/ver1.0';
		}
		if(url.indexOf('http://www.dogcare.com') >= 0) {
			return 'http://sitelife.dogcare.com/ver1.0';
		}
		if(url.indexOf('http://www.homeremodeling.com') >= 0) {
			return 'http://sitelife.homeremodeling.com/ver1.0';
		}
		if(url.indexOf('http://www.horsebarn.com') >= 0) {
			return 'http://sitelife.horsebarn.com/ver1.0';
		}
		if(url.indexOf('http://www.howtobecomeamodel.com') >= 0) {
			return 'http://sitelife.howtobecomeamodel.com/ver1.0';
		}
		if(url.indexOf('http://www.mastersoccer.net') >= 0) {
			return 'http://sitelife.mastersoccer.net/ver1.0';
		}
		if(url.indexOf('http://www.theaccidentalartist.com') >= 0) {
			return 'http://sitelife.theaccidentalartist.com/ver1.0';
		}
		return 'http://sitelife.wellnessessentials.com/ver1.0';
	};
}
if (typeof window.slCreatePollWidget == 'undefined') {
	slCreatePollWidget = function() { }
};

(function(){
	
	slwidgets.widgetLoader.load([slwidgets.getServerBaseUrl(window.location.domain) +'/content/widgets/globalOptions.js'], function() {
	    if (typeof slCreatePollWidget.__code === 'undefined') {

		    slCreatePollWidget.__code = true;
var thisWidget;

slCreatePollWidget.prototype = new slwidgets.slWidgetBase();

slCreatePollWidget.prototype.template = '<div class="slPoll"\><div class="slCreate"\>\n\t<h3 id="slPoll_CreateHeader"\>Create a Poll</h3\>\n\t<span class="slErrorText" id="${questionIsRequiredErrorId}"\>You must provide a question for the poll.</span\>\n\t<span class="slErrorText" id="${notEnoughAnswersErrorId}"\>You must provide between 2 and 10 answers for the poll.</span\>\n\t<span class="slErrorText" id="${dirtyWordErrorId}"\>The following blocked word(s) were found in the question or answers: <span id="${dirtyWordListErrorId}"\></span\></span\>\n\t<span class="slErrorText" id="${createPollResponseErrorMessages}"\></span\>\n\t<div class="slPoll_CreateQuestion"\>\n\t\t<label id="slPoll_CreateQuestion" for="question"\>Question:</label\><input type="text" id="slPollQuestion" name="pollQuestion" value="" maxlength="256" /\>\n\t</div\>\n\t<div class="slPoll_CreateAnswer"\>\n\t    <label id="slPoll_CreateAnswer0" for="slPollAnswer0"\>Answer</label\><input type="text" id="slPollAnswer0" name="pollAnswer" value="" maxlength="256" /\>\n\t</div\>\n\t<div class="slPoll_CreateAnswer"\>\n\t    <label id="slPoll_CreateAnswer1" for="slPollAnswer1"\>Answer</label\><input type="text" id="slPollAnswer1" name="pollAnswer" value="" maxlength="256" /\>\n\t</div\>\n\t<div class="slPoll_CreateAnswer"\>\n\t    <label id="slPoll_CreateAnswer2" for="slPollAnswer2"\>Answer</label\><input type="text" id="slPollAnswer2" name="pollAnswer" value="" maxlength="256" /\>\n\t</div\>\n\t<div class="slPoll_CreateAnswer"\>\n\t    <label id="slPoll_CreateAnswer3" for="slPollAnswer3"\>Answer</label\><input type="text" id="slPollAnswer3" name="pollAnswer" value="" maxlength="256" /\>\n\t</div\>\n\t<div id="slPoll_MoreAnswers" style="display:none;"\>\n    \t<div class="slPoll_CreateAnswer"\>\n\t        <label id="slPoll_CreateAnswer4" for="slPollAnswer4"\>Answer</label\><input type="text" id="slPollAnswer4" name="pollAnswer" value="" maxlength="256" /\>\n    \t</div\>\n\t    <div class="slPoll_CreateAnswer"\>\n    \t    <label id="slPoll_CreateAnswer5" for="slPollAnswer5"\>Answer</label\><input type="text" id="slPollAnswer5" name="pollAnswer" value="" maxlength="256" /\>\n\t    </div\>\n    \t<div class="slPoll_CreateAnswer"\>\n\t        <label id="slPoll_CreateAnswer6" for="slPollAnswer6"\>Answer</label\><input type="text" id="slPollAnswer6" name="pollAnswer" value="" maxlength="256" /\>\n    \t</div\>\n\t    <div class="slPoll_CreateAnswer"\>\n\t        <label id="slPoll_CreateAnswer7" for="slPollAnswer7"\>Answer</label\><input type="text" id="slPollAnswer7" name="pollAnswer" value="" maxlength="256" /\>\n    \t</div\>\n\t    <div class="slPoll_CreateAnswer"\>\n\t        <label id="slPoll_CreateAnswer8" for="slPollAnswer8"\>Answer</label\><input type="text" id="slPollAnswer8" name="pollAnswer" value="" maxlength="256" /\>\n    \t</div\>\n\t    <div class="slPoll_CreateAnswer"\>\n\t        <label id="slPoll_CreateAnswer9" for="slPollAnswer9"\>Answer</label\><input type="text" id="slPollAnswer9" name="pollAnswer" value="" maxlength="256" /\>\n    \t</div\>\n    </div\>\n    <div class="slPoll_CreateButtons"\>\n    \t<input type="button" id="slPoll_CreatePollButton" class="slPoll_CreatePollButton" onclick="WIDGETINSTANCE.createPoll(); " value="Create Poll" /\>\n        <a id="slPoll_ShowMoreAnswers" href="javascript:void(0);" onclick="WIDGETINSTANCE.showMoreAnswers(); return false;" title="show more answers"\>Show more answers</a\>\n    </div\>\n</div\></div\>\n';

slCreatePollWidget.prototype.addRequests = function() {
    thisWidget = this;
    this.validated = false;
    if (!this.context.options.pollOnKey) {
        this.context.pollOnKeySpecified = false;
    }
    else {
        this.context.pollOnKeySpecified = true;
    }
    this.context.currentUser = this.getCurrentUser();
    this.context.isAnonymous = this.context.currentUser.UserTier === 'Anonymous';
    this.context.isEditor = (this.context.currentUser.UserTier === 'Editor' || this.context.currentUser.AdministrativeTier !== 'None');
    // the error message displayed when the user does not enter a question
    this.context.questionIsRequiredErrorId = this.createErrorMessageId('questionIsRequired');
    // the error message displayed when the user has not provided enough answers
    this.context.notEnoughAnswersErrorId = this.createErrorMessageId('notEnoughAnswers');
    this.context.dirtyWordErrorId = this.createErrorMessageId('dirtyWord');
    this.context.dirtyWordListErrorId = this.createErrorMessageId('dirtyWordList');
    this.context.createPollResponseErrorMessages = this.createErrorMessageId('serverErrorMessages');
};

slCreatePollWidget.prototype.validate = function() {
    this.clearErrorMessages();
    this.validated = false;
    var hasError = false;
    var questionElem = document.getElementById('slPollQuestion');
    if (!questionElem) {
        this.showErrorMessage('questionIsRequired');
        hasError = true;
    }
    var question = PluckSlWidgetHelper.trim(questionElem.value);
    if (question === null || question.length === 0) {
        this.showErrorMessage('questionIsRequired');
        hasError = true;
    }
    var answers = [];
    for (var i = 0; i < 100; i++) {
        var answerElem = document.getElementById('slPollAnswer' + i);
        if (!answerElem) {
            break;
        }
        var answer = PluckSlWidgetHelper.trim(answerElem.value);
        if (answer !== null && answer.length !== 0) {
            answers.push(answer);
        }
    }
    if (answers.length < 2) {
        this.showErrorMessage('notEnoughAnswers');
        hasError = true;
    }
    if (hasError) {
        return false;
    }
    this.question = question;
    this.answers = answers;
    this.validated = true;
    return true; 
}

slCreatePollWidget.prototype.checkDirtyWords = function(callBack) {
    var checkWords = new Object();
    var questionElem = document.getElementById('slPollQuestion');
    checkWords.slPollQuestion = PluckSlWidgetHelper.trim(questionElem.value);

    var answers = [];
    for (var i = 0; i < 100; i++) {
        var id = 'slPollAnswer' + i;
        var answerElem = document.getElementById(id);
        if (!answerElem) {
            break;
        }
        checkWords[id] = PluckSlWidgetHelper.trim(answerElem.value);
    }
    var me = this;
    this.sendRequests([new CheckFilteredWords(checkWords)], function(response) {
        if (callBack) {
            me.clearErrorMessages();
            var hasError = false;
            var result = response.Responses[0].CheckFilteredWords.Results;
            var badWords = new Object();
            if (result.slPollQuestion) {
                var words = result.slPollQuestion.split(",");
                for (var i = 0; i < words.length; i++) {
                    if (words[i]) {
                        badWords[words[i]] = true;
                        hasError = true;
                    }
                }
            }
            for (var j = 0; j < 100; j++) {
                var id = 'slPollAnswer' + j;
                if (result[id]) {
                    var words = result[id].split(",");
                    for (var i = 0; i < words.length; i++) {
                        if (words[i]) {
                            badWords[words[i]] = true;
                            hasError = true;
                        }
                    }
                }
            }
            if (hasError) {
                var wordList = [];
                for (var w in badWords) { wordList.push(w); }
                var sp = document.getElementById(me.context.dirtyWordListErrorId);
                sp.innerHTML = wordList.join(", ");
                sp.style.display = 'inline';
                me.showErrorMessage('dirtyWord');
            }
            callBack(!hasError);
        }
    });
}

slCreatePollWidget.prototype.createPoll = function() {
    if (!this.validated) {
        var isValid = this.validate();
        if (!isValid) {
            return;
        }
    }
    this.sendRequests([new UpdatePollAction(this.createDaapiKey(this.context.options.pollOnKeyType, this.context.options.pollOnKey), this.question, this.answers)], function(response) {
        if (response.Messages.length !== 0) {
            if (response.Messages[0].Message !== 'ok') {
                thisWidget.showErrorMessage('serverErrorMessages', response.Messages);
                return;
            }
        }
        // retrieve the poll object to pass out in the event
        thisWidget.sendRequests([new PollKey(response.Responses[0].PollKey.Key)], function(response) {
            thisWidget.fireEvent('onPollCreated', {
                poll: response.Responses[0].Poll 
            });
        })
    })
    return false;
}

slCreatePollWidget.prototype.showMoreAnswers = function () {
    document.getElementById('slPoll_MoreAnswers').style.display = 'block';
    document.getElementById('slPoll_ShowMoreAnswers').style.display = 'none';
}

};
	    
    });
})();

var PLUCKSL_WIDGET_OPTIONS_DEFAULT = {"pollOnKey":"","pollOnKeyType":"","showResultsOnly":false,"urls":false,"templateId":"","remoteTemplateUrl":"","useDefaultStylesheet":"true","createPoll":{"pollOnKey":"_","pollOnKeyType":"_","urls":"_","templateId":"","remoteTemplateUrl":"","useDefaultStylesheet":"true"}};
if (typeof window.slDisplayPollWidget == 'undefined') {
	slDisplayPollWidget = function() { }
};

(function(){
	var widgetId = slwidgets.widgetLoader.addWidgetDiv();
var localOptions = {};
if (typeof(PLUCKSL_WIDGET_OPTIONS) !== 'undefined') { localOptions = PLUCKSL_WIDGET_OPTIONS; }
var localDefaultOptions = PLUCKSL_WIDGET_OPTIONS_DEFAULT;
var localEvents = {};
if (typeof(PLUCKSL_WIDGET_EVENTS) !== 'undefined') { localEvents = PLUCKSL_WIDGET_EVENTS; }
	slwidgets.widgetLoader.load([slwidgets.getServerBaseUrl(window.location.domain) +'/content/widgets/globalOptions.js'], function() {
	    if (typeof slDisplayPollWidget.__code === 'undefined') {

		    slDisplayPollWidget.__code = true;
var thisWidget;

// changes all boolean properties to real boolean properties.
var fixPollObject = function(widget, poll) {
    widget.context.poll = poll;
    poll.CurrentUserHasRecommended = (poll.CurrentUserHasRecommended === 'True');
    poll.CurrentUserHasReportedAbuse = (poll.CurrentUserHasReportedAbuse === 'True');
    poll.CurrentUserHasVoted = (poll.CurrentUserHasVoted === 'True');
    poll.IsClosed = (poll.IsClosed === 'True');
    // compute answer percentages
    var totalVotes = 0;
    for (var i = 0; i < poll.Answers.length; i++) {
        // fix answers to make them numbers
        poll.Answers[i].NumberOfVotes = new Number(poll.Answers[i].NumberOfVotes);
        totalVotes += poll.Answers[i].NumberOfVotes;
    }
    widget.context.totalVotes = totalVotes;
    // decorate answer objects with percentage field
    for (var i = 0; i < poll.Answers.length; i++) {
        poll.Answers[i].Percentage = totalVotes == 0 ? 0 : poll.Answers[i].NumberOfVotes / totalVotes;
        poll.Answers[i].PercentageStr = (poll.Answers[i].Percentage * 100).toFixed(1).toString();
    }
}

slDisplayPollWidget.prototype = new slwidgets.slWidgetBase();

slDisplayPollWidget.prototype.template = '{var error = !pollOnKeySpecified || moreThanOnePollForThisParent}\n{if error}\n\t{if !pollOnKeySpecified}\n\t\t<span class="slErrorText"\>pollOnKey not specified -- this parameter is required</span\>\n\t{elseif moreThanOnePollForThisParent}\n\t\t<span class="slErrorText"\>More than one poll for the given pollOnKey -- aborting</span\>\n\t{/if}\n{else}\n\t{var createMode = !poll}\n\t{var resultMode = (poll && poll.CurrentUserHasVoted) || (poll && poll.IsClosed) || (isAnonymous && !anonymousUsersCanVoteInPolls) || options.showResultsOnly}\n\t{var voteMode = !resultMode}\n\t{if createMode}\n\t\t${createPoll}\n\t{elseif resultMode || voteMode}\n\t\t{eval}\n\t\tswitchViews = function(showVoteView) {\n\t\t\tif (showVoteView) {\n\t\t\t\tdocument.getElementById(resultsId).style.display = \'none\';\n\t\t\t\tdocument.getElementById(voteId).style.display = \'block\';\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdocument.getElementById(voteId).style.display = \'none\';\n\t\t\t\tdocument.getElementById(resultsId).style.display = \'block\';\t\t\t\t\n\t\t\t}\n\t\t}\n\t\t{/eval}\n\t\t<div class="slPoll"\>\n\t\t\t<div class="slResults" {if voteMode}style="display:none;"{/if} id="${resultsId}"\>\n   \t\t\t\t{if (!isAnonymous || (isAnonymous && anonymousUsersCanVoteInPolls)) && !poll.CurrentUserHasVoted && !poll.IsClosed && !options.showResultsOnly}<a href="javascript:void(0)" onclick="switchViews(true); return false;" class="slVoteLink" id="${resultsId}_GoVote"\>Go vote!</a\>{/if}\n\t\t\t    <h3 id="${resultsId}_ResultsHeader"\>\n\t\t\t        Poll Results: ${totalVotes} Vote{if totalVotes != 1}s{/if}\n\t\t\t    </h3\>\n\t\t\t\t<h4\>${poll.Question}</h4\>\n\t            <table class="slAnswerStats" cellpadding="0" cellspacing="0" border="0"\>\t\n\t  \t\t\t{for answer in poll.Answers}\n\t\t\t\t\t{var answerPercent = Math.round(answer.Percentage * 100)}\n\t\t\t\t\t<tr class="slAnswerStat slAnswerStat_${answer_index}"\>\n                        <td id="${resultsId}_AnswerCount_${answer_index}" class="slAnswerCount"\>\n                            ${answer.NumberOfVotes} Vote{if answer.NumberOfVotes != 1}s{/if} (${answer.PercentageStr }%)\n                        </td\>\n                        <td class="slAnswerBarCell"\>\n                            <div class="slAnswerBar"\>\n                                <div class="slAnswerBarPercent slAnswerBarPercent_${answerPercent}" style="width: ${answerPercent}%;"\></div\>\n                            </div\>\n                        </td\>\n\t                    <td class="slAnswer"\>${answer.Answer}</td\>\n\t                </tr\>\n\t\t\t    {/for}\n\t\t\t\t</table\>\n\t\t\t</div\>\n\t\t\t<div class="slVote" {if resultMode}style="display:none;"{/if} id="${voteId}"\>\n\t\t\t\t<div class="slErrorText" id="${answerIsRequiredErrorId}"\>You must select one answer before submitting your vote.</div\>\n\t\t\t\t<a id="${voteId}_ViewResults" href="javascript:void(0)" onclick="switchViews(false); return false;" class="slResultsLink"\>View Results...</a\>\n\t\t\t\t<h4\>${poll.Question}</h4\>\n\t\t\t\t<table class="slAnswers" cellspacing="0" cellpadding="0" border="0"\>\n\t\t\t\t\t{for answer in poll.Answers}\n\t\t\t\t\t\t{var answerId = poll.PollKey.Key + \'.\' + answer_index}\n\t\t\t\t\t<tr\>\n\t\t\t\t\t\t<td class="slAnswerInput"\><input type="radio" name="answers" id="slPollAnswer${answer_index}" value="${answer_index}" id="${answerId}"/\></td\>\n\t\t\t\t\t\t<td class="slAnswerText"\><label for="${answerId}"\>${answer.Answer}</label\></td\>\n\t\t\t\t\t</tr\>\n\t\t\t\t\t{/for}\n\t\t\t\t</table\>\n\t\t\t\t<div class="slSendAnswer" style="padding-top: 10px;"\>\n\t\t\t\t<input id="${voteId}_VoteButton" class="slVoteButton" type="button" value="Vote" onclick="WIDGETINSTANCE.answerPoll(); return false;"/\>\n\t\t\t\t</div\>\n\t\t\t</div\>\n\t\t</div\>\n\t{/if}\n{/if}';

slDisplayPollWidget.prototype.addChildWidgets = function() {
    thisWidget = this;
    this.addChildWidget('slCreatePollWidget', 'createPoll');
    this.child['createPoll'].addEventCallback('onPollCreated', function(event, eventArgs) {
        fixPollObject(thisWidget, eventArgs.poll);
        thisWidget.rerender();
    });
    this.autoLoad = true;
    
    this.context.anonymousUsersCanVoteInPolls = (PLUCKSL_GLOBAL_OPTIONS.anonymousUsersCanVoteInPolls === 'True');
}

slDisplayPollWidget.prototype.buildRequests = function() {
    var requests = [];
    requests.push(new PollPage(this.createDaapiKey(this.context.options.pollOnKeyType, this.context.options.pollOnKey), 10, 1, "TimeStampAscending"));
    return requests;
}

slDisplayPollWidget.prototype.addRequests = function() {
    this.validated = false;
    if (!this.context.options.pollOnKey || !this.context.options.pollOnKeyType) {
        this.context.pollOnKeySpecified = false;
    }
    else {
        this.context.pollOnKeySpecified = true;
    }
    // if the poll key was specified, make the requests to the server
    if (this.context.pollOnKeySpecified) {
        // can't load this widget automatically if our parent is making paged requests also.
        // so if parent set us not to autoLoad, must wait for invocation of show method.
        if (this.autoLoad) {
	    	var requests = this.buildRequests();
	        for(i=0; i<requests.length; i++){
	    		this.addRequest(requests[i]);
	        }
		}
		else {
	    	this.autoRender = false;
		}
    }
    // set some basic stuff for the template to use
    this.context.currentUser = this.getCurrentUser();
    this.context.isAnonymous = this.context.currentUser.UserTier === 'Anonymous';
    this.context.isEditor = (this.context.currentUser.UserTier === 'Editor' || this.context.currentUser.AdministrativeTier !== 'None');
};

slDisplayPollWidget.prototype.show = function(pollOnKeyType, pollOnKey) {
    this.context.options.pollOnKey = pollOnKey;
    this.context.options.pollOnKeyType = pollOnKeyType;
    this.autoLoad = true;
    this.autoRender = true;
    this.redraw();
}

slDisplayPollWidget.prototype.buildContextFromResponses = function(responses) {
    // the error message displayed when the user clicks the vote button without choosing an answer
    this.context.answerIsRequiredErrorId = this.createErrorMessageId('answerIsRequired');
	this.context.resultsId = 'results-' + Math.random() + '-' + Math.random();
    this.context.voteId = 'vote-' + Math.random() + '-' + Math.random();
    
    this.context.poll = false;
    this.context.moreThanOnePollForThisParent = false;
    // iterate through responses building template context
    for (var i = 0; i < responses.length; i++) {
        var response = responses[i];
        // did anything come back at all?
        if (response) {
            if (response.PollPage) {
                if (response.PollPage.Polls.length > 1) {
                    this.context.moreThanOnePollForThisParent = true;
                }
                else if (response.PollPage.Polls.length === 1) {
                    fixPollObject(this, response.PollPage.Polls[0]);
                }
            }            
        }
    }
}

slDisplayPollWidget.prototype.answerPoll = function() {
    this.clearErrorMessages();
    var answerIndex = false;
    for (var i = 0; i < 100; i++) {
        var answer = document.getElementById('slPollAnswer' + i);
        if (!answer) break;
        if (answer.checked) {
            answerIndex = i;
            break;
        }
    }
    if (answerIndex === false) {
        this.showErrorMessage('answerIsRequired');
        return false;
    }
    this.sendRequests([new PostPollAnswerAction(new PollKey(this.context.poll.PollKey.Key), answerIndex)], function(responseBatch) {
        thisWidget.pollAnswered();
    })
    return false;
}

slDisplayPollWidget.prototype.validate = function() {
    this.clearErrorMessages();
    this.validated = false;
    var hasError = false;
    var questionElem = document.getElementById('slPollQuestion');
    if (!questionElem) {
        this.showErrorMessage('questionIsRequired');
        hasError = true;
    }
    var question = PluckSlWidgetHelper.trim(questionElem.value);
    if (question === null || question.length === 0) {
        this.showErrorMessage('questionIsRequired');
        hasError = true;
    }
    var answers = [];
    for (var i = 0; i < 100; i++) {
        var answerElem = document.getElementById('slPollAnswer' + i);
        if (!answerElem) {
            break;
        }
        var answer = PluckSlWidgetHelper.trim(answerElem.value);
        if (answer !== null && answer.length !== 0) {
            answers.push(answer);
        }
    }
    if (answers.length < 2) {
        this.showErrorMessage('notEnoughAnswers');
        hasError = true;
    }
    if (hasError) {
        return false;
    }
    this.question = question;
    this.answers = answers;
    this.validated = true;
    return true; 
}

slDisplayPollWidget.prototype.createPoll = function() {
    if (!this.validated) {
        var isValid = this.validate();
        if (!isValid) {
            return;
        }
    }
    this.sendRequests([new UpdatePollAction(this.context.options.pollOnKey, this.question, this.answers)], function(responseBatch) {
        thisWidget.pollCreated(responseBatch.Responses[0].PollKey);
    })
    return false;
}

slDisplayPollWidget.prototype.pollAnswered = function() {
    this.sendRequests([new PollKey(this.context.poll.PollKey.Key)], function(response) {
        fixPollObject(thisWidget, response.Responses[0].Poll);
        thisWidget.rerender();
    })
}

slDisplayPollWidget.prototype.pollCreated = function(pollKey) {
    this.sendRequests([new PollKey(pollKey.Key)], function(response) {
        fixPollObject(thisWidget, response.Responses[0].Poll);
        thisWidget.rerender();
    })
}};
	    PluckSlWidget.runWidget('slDisplayPollWidget', widgetId, localDefaultOptions, localOptions, localEvents);
    });
})();

