function loadPoll(id, placement) {
	/**
	 * id - poll id
	 * placement - left/right/center
	 */
	
	if (placement != 'left' && 
			placement != 'right' &&
			placement != 'center') {
		placement = 'center'; // default to center if placement is something else
	}
	
	document.write(
			'<div id="poll' + id + '" class="' + placement + 'Poll" style="display: none;">' +
			'<div class="pollHeader"></div>' +
			'<div class="pollLoading"><img src="/images/ajax-loader.gif" /></div>' +
			'<div class="pollContainer">' +
			'<div class="pollOptions"></div>' +
			'<div class="pollResults"></div>' +
			'</div>' +
			'<div class="pollFooter"></div>' +
			'</div>'
		);
	
	$.ajaxSetup({ cache: false });
	$('#poll' + id + ' .pollContainer .pollOptions').load('/poll/showPoll.do?pollId=' + id + ' div,p', 
			function() {
				if ($('#poll' + id + ' .poll-question').size() > 0) {
					$('#poll' + id).slideDown();
				}
			});
}

function submitPoll(pollform, pollId) {
	var isChecked = false;
	
	for (var i=0; i < pollform.optionId.length; i++) {
	   	if (pollform.optionId[i].checked) {
	      var optionVal = pollform.optionId[i].value;
	      isChecked = true;
		}
	}

	if (isChecked) {
		$('#poll-error-' + pollId).slideUp();
		$('#poll' + pollId + ' .pollContainer').css('min-height', $('#poll' + pollId + ' .pollOptions').css('height'));
		$('#poll' + pollId + ' .pollLoading').fadeIn();
		$('#poll-options-' + pollId).fadeOut(function() {
			$('#poll' + pollId + ' .pollResults')
					.hide()
					.css('opacity', 0)
					.load('/poll/votePoll.do div', {optionId: optionVal}, function() {
						$(this).slideDown('fast', function() { $(this).animate({ opacity: 1 }); });
						$('#poll' + pollId + ' .pollLoading').fadeOut();
					});
		});
					
	} else {
		$('#poll-error-' + pollId).empty().append('Please select an option.').fadeIn("slow");
	}
	
	return false;
}
