var surveyID = 0;
  
function survey_vote(answer, lang, sID, redirect) 
{
    if(sID == null) sID = surveyID;
    
    $.ajax({
            url: '/survey.php?survey=' + sID + '&answer=' + answer + '&lang=' + lang,
            dataType: 'xml',
            type: 'GET',
            timeout: 2999,
            global: false,
            success: function(data) {
                         
                         if(redirect == '1')
                         {
                             window.location.reload(true);
                         }
                         else
                         {
                             surveyID = $('survey', data).attr('id');
                             var content = '';
                         
                             $('#survey_content').html('');
                             $('#survey_content').append('<p class="bold">' + $('survey question', data).text() + '</p>');
                         
                             $.each($('answer', data), function(i, item) {
                             
                                 if($('survey', data).attr('voteable') == '1') 
                                 {
                                     content += '<a class="answer" href="javascript:survey_vote(' + $(item).attr('id') + ', \'' + lang + '\'); void(0);">' + $(item).text() + ' - ' + $(item).attr('perc') + '%</a><span class="bar"><img class="surveyBar" src="/images/survey-bar' + i + '.png" alt="' + $(item).text() + '" style="width: ' + (Math.round(150 * $(item).attr('perc') / 100)) + 'px;"></span>'; 
                                 }
                                 else
                                 {
                                     content += '<span class="answer">' + $(item).text() + ' - ' + $(item).attr('perc') + '%</span><span class="bar"><img class="surveyBar" src="/images/survey-bar' + i + '.png" alt="' + $(item).text() + '" style="width: ' + (Math.round(150 * $(item).attr('perc') / 100)) + 'px;"></span>'; 
                                 }

                             });

                             $('#survey_content').append(content);
                             $('#survey_content').show();
                         }
                     }
           });
}
