function Poll() {
	AjaxModuleStatic.apply(this, arguments);
	this.voteHandler = '/mod/v3/util/pollVote.asp';
	this.minVoteInterval = 24; //hours
	this.pollID = null;
}
function Poll_doOnRequestsComplete() {
	AjaxModuleStatic.prototype.doOnRequestsComplete.apply(this, arguments);
	this.acquireElements();
}
function Poll_processStaticContent() {
	AjaxModuleStatic.prototype.processStaticContent.apply(this, arguments);
	this.acquireElements();
}
function Poll_vote(form) {
	if (!this._pollSubmitting) {

		this._poIDs = [];
		var inputs = Form.getInputs(form);
		for (var i = 0; i < inputs.length; i++) {
		    if (inputs[i].checked && inputs[i].name == 'po_id') this._poIDs.push(inputs[i].value);
		}
		
		new Ajax.Request(
			this.voteHandler,
			{
				method: 'get',
				parameters: 'pollID=' + this.pollID + '&poIDs=' + this._poIDs.join(","),
				onSuccess: this.voteComplete.bind(this),
				onFailure: this.doOnFailure.bind(this),
				onException: this.doOnException.bind(this)
			});
		this._pollSubmitting = true;

	}
}
function Poll_voteComplete(request) {
	this._pollSubmitting = false;
	var success = false;
	try {
		success = eval(request.responseText) == 1;
	}
	catch (e) {}
	if (success) {
		var expire = new Date();
		expire.setTime(expire.getTime() + Math.round(this.minVoteInterval * 60 * 60 * 1000));
		setCookie("poll" + this.pollID, this._poIDs.join(","), expire, "/");
		this.params["poIDs"] = this._poIDs.join(",");
		this.load();
	}
	else this.showVotes([]);
}
function Poll_acquireElements() {
	this.pollEl = $(this.uid + '_poll');
	this.resuEl = $(this.uid + '_result');
	var poIDs = getCookie("poll" + this.pollID);
	if (poIDs) this.showVotes(poIDs.split(","));
	else if (!navigator.cookieEnabled) this.showVotes(null);
	else {
		this.pollEl.style.display = '';
		this.resuEl.style.display = 'none';
	}
}
function Poll_showVotes(poIDs) {
	this.pollEl.style.display = 'none';
	this.resuEl.style.display = '';
}
Object.extend(Poll.prototype, AjaxModuleStatic.prototype);
Poll.prototype.doOnRequestsComplete = Poll_doOnRequestsComplete;
Poll.prototype.processStaticContent = Poll_processStaticContent;
Poll.prototype.acquireElements = Poll_acquireElements;
Poll.prototype.vote = Poll_vote;
Poll.prototype.voteComplete = Poll_voteComplete;
Poll.prototype.showVotes = Poll_showVotes;