var poll_pathToImage = "/js/loadingAnimation.gif";

//on page load call tb_init
$(document).ready(function(){
	imgPollLoader = new Image();// preload image
	imgPollLoader.src = poll_pathToImage;
});

function poll_Vote(form, that)
{
    $('#' + that).append('<div id="poll_load"><img src="' + imgPollLoader.src + '" /></div>');
	$('#poll_load').show();

	inpts = form.getElementsByTagName('input');
	user_added = false;
	ans = -1;
	theSubmit = false;
	for (i = 0; i < inpts.length; i++) {
		cur = inpts[i];
		if (cur.type == 'radio' && cur.checked) {
			ans = cur.value;
			if (ans == 'newAnswer') {
			    user_added = true;
                ans = inpts[i+1].value;
            }
        }
		if (cur.name == 'poll_id') { poll_id = cur.value; }
        if (cur.name == 'poll_cookie_days') { cdays = cur.value; }
		if (cur.type == 'submit') { theSubmit = cur; }
	}
	
	// they haven't checked a box or they added a blank answer
	if (ans == -1 || ans == '') { 
		$('#poll_load').remove();
		return false;
	}

	path = form.action;
	path += '?poll_action=vote';
	path += '&poll_' + poll_id + '=' + ans;
	path += '&poll_id=' + poll_id;
	path += '&poll_ajax=true';

	$('#' + that).load(path, function() {
        $('#poll_load').remove();
	});

	return false;
}

function poll_getVotes(path, that)
{
    $('#' + that).append('<div id="poll_load"><img src="' + imgPollLoader.src + '" /></div>');
	$('#poll_load').show();

    $('#' + that).load(path, function() {
        $('#poll_load').remove();
	});

    return false;
}
