var settings = {
    formId       	   : 'poll_vote',
    processUrl         : '/ru/polls/ajaxvote'
};

function ajaxVote()
{
    var options = {
        method     : 'post',
        parameters : $(settings.formId).serialize(),
        onSuccess  : ajaxVoteSuccess,
        onFailure  : ajaxVoteFailure
    };

    new Ajax.Request(settings.processUrl, options);
}

function ajaxVoteFailure(transport)
{
	//alert('ajaxVoteFailure!');
}

function ajaxVoteSuccess(transport)
{
	//$('bottom_form').style.display = 'none';	
var percentage = 0;
var html = '';

html += '<div class="poll_res">'+transport.responseJSON.q.question+'<br />';
html += '<span class="quest_date_res">'+transport.responseJSON.q.start_date+'</span>';
html += '<br /><br />';

var answers = transport.responseJSON.a;
var res_count = 0;

//x=$new.results y=$item.results_sum

for(i=0; i<answers.length; i++){
percentage = round((answers[i].results / transport.responseJSON.q.results_sum)*100,1);
html += answers[i].text+'<br />';
html += '<span style="color: #888888"><img width="'+percentage+'" height="3" src="/images/res.gif" />&nbsp;&nbsp;'+percentage+'% ('+answers[i].results+')</span>';
html += '<br /><br />';
res_count = res_count+parseInt(answers[i].results);
}

html += 'Проголосовало: <strong>'+res_count+'</strong>';

$('questionary_txt').innerHTML = html;
}

function round ( val, precision ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // *     example 1: round(1241757, -3);
    // *     returns 1: 1242000
    // *     example 2: round(3.6);
    // *     returns 2: 4
 
    var precision = (round.arguments.length > 1) ? round.arguments[1] : 0;
    return Math.round(val * Math.pow(10, precision))/Math.pow(10, precision);
}


