var page       = 1; 
var mouseOnDiv = 0;
var VOTE_ACCEPT_MSG = 'Thank you for voting.';

function showHide(section1, section2, section)
{
   $(section1).style.display='block';
   $(section2).style.display='none';
}

function saveVote()
{
   var voteFormObj = document.voteForm;
   var pollId      = voteFormObj.poll_id.value;
   var optionId    = getSelectedRadioValue(voteFormObj.vote);

   if(optionId === null) return;

   var url    = '/run.php/Poll';
   var params = 'cmd=vote&poll_id='+pollId+'&option_id='+optionId;

   var myAjax  = new Ajax.Request(url,
                 {
                    method     : 'post'
                   ,parameters : params
                   ,onComplete : showSaveVoteResponse
                 });
                 
   if(OMNITURE == true) createPageView('Quizfarm');
}

function getSelectedRadioValue(radio)
{
   for(i = 0; i < radio.length; i++)
   {
      if(radio[i].checked == true) return radio[i].value;
   }

   return null;
}

function showSaveVoteResponse(transport)
{
   var container       = $('td_user_vote');   
   container.innerHTML = '';

   var resultDiv       = document.createElement('DIV');
   resultDiv.className = 'pollResult';
   resultDiv.innerHTML += '<span class="radio">'+VOTE_ACCEPT_MSG+'</span><br/>';

   imageURL = transport.responseText;
   var img  = document.createElement('IMG');
   img.src  = imageURL;
   resultDiv.appendChild(img);

   var legends          = showLegends();
   resultDiv.innerHTML += '<br/>'+legends;

   container.appendChild(resultDiv);
}

function showLegends()
{
   var legends  = '';
   var charCode = 65;

   for (var i = 0; i < optionsList.length; i++)
   {
      //Apply legends to the labels alphabetically: 
      //first one is A, next is B and so on
      legends += String.fromCharCode(charCode)+':'+optionsList[i]+'<br/>';
      charCode++;
   }

   return legends;
}