/**
 * Update user vote value
 */
function updateVoteValue(userVoteValue) {
	document.getElementById('voteValue').value = userVoteValue;
} // function


/**
 * Cast vote
 */
function castVote() {

	// make sure user picked a value
	if ( $F('voteValue') == "" ) {
		alert('Please choose a vote option!');
		return false;
	} // if

	var voteValue 	= $F('voteValue');
	var url 		= 'http://www.tcchamber.org/poll/poll.php';
	var pars 		= 'pollItemId='+ voteValue;
	var myAjax 		= new Ajax.Request( url, {method: 'post', parameters: pars, onComplete: showResponse} );
	
} // function


/**
 * Get the poll response.  Apparently this needs to be directly injected
 * into the innerhtml, otherwise it wasn't changing.
 */
function showResponse(originalRequest) {
	//put returned XML in the textarea
	$('voteContent').innerHTML = originalRequest.responseText;
} // function


/**
 * Get the poll for display to the user
 */
function getPoll(pollId) {
	
	if (! pollId) {
		updateVoteContent('Error, please pass a poll id!');
		return false;
	} // if
	
	var url 	= 'http://www.tcchamber.org/poll/poll.php';
	var pars 	= 'action=display&pollId='+ pollId;
	var myAjax 	= new Ajax.Updater( {success: 'voteContent'}, url, {method: 'get', parameters: pars, onFailure: reportError});

} // function


/**
 * Update the poll content area
 *
 * @param string content String to update in the content area
 */
function updateVoteContent(content) {
	$('voteContent').innerHTML = content;
} // function


/**
 * report error function
 */
function reportError(request) {
	updateVoteContent = 'Sorry. There was an error.';
} // function