function showPoll( poll_id )
{
	var url = 'polls/?action=show&id=' + poll_id;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
		$('poll-viewport').innerHTML = transport.responseText;
	  }
	});
}

function vote( poll_id, choice )
{
	var url = 'polls?action=vote&id=' + poll_id + '&choice=' + encodeURIComponent(choice);
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			response = eval('(' + transport.responseText + ')');
			if ( response.success ) {
				$('poll-viewport').innerHTML = response.message;
				showResults(response.poll_id)
			} else {
				$('poll-viewport').innerHTML =
					'<p><strong>You have already voted.</strong></p><p>You may only vote once per poll.</p>'
					+ '<p>View the <a href="#" onclick="showResults('
					+ response.poll_id + ')">results of the poll</a>.</p>';
			}
		}
	});
}

function showResults( poll_id )
{
	var url = 'polls?action=results&id=' + poll_id;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
		$('poll-viewport').innerHTML = transport.responseText;
	  }
	});
}

function voteMC( poll_id )
{
	var choices = $('poll-form').choices
	for( var i = 0; i < choices.length; i++ ) {
		if ( choices[i].checked ) {
			vote(poll_id, choices[i].value);
			return;
		}
	}
}
