function vote_form_onSuccess(t) {
  var result = t.responseJSON;
  
  if(result.success)
  {
    //fire another request to the server to produce the chart
    get_chart();
    //remove options and button from the form and display link
    $$('.vote_row').each(function(elm){
      elm.hide();
    });
    $('vote').hide();
    $('view_results').show();
  }
  else
  {
    if(result.error_code == 'no_select')
    {
      display_notification('You must select an item to vote on before voting.');          
    }
    else if(result.error_code == 'already_voted')
    {
      display_notification('You have already voted once in the last 7 days.');          
    }
    else
    {
      display_notification('There was a problem processing your vote, please try again');          
    }
  }
}

function vote_form_onFailure(t) {
  display_notification('There was a problem processing your vote, please try again');
}


function get_chart() {
  new Ajax.Request('/poll/chart', {asynchronous:true, onSuccess:chart_onSuccess, onFailure:chart_onFailure});
}


function chart_onSuccess(t) {
  $('vote_chart').update(t.responseText);
  pop_over($('vote_chart'));
}

function chart_onFailure(t) {
  //do nothing
}