// Global variable definitions
// DB column numbers
var OPT_ID = 0;
var OPT_TITLE = 1;
var OPT_VOTES = 2;

var votedID;

$(document).ready(function(){
  $("#poll").submit(formProcess); // setup the submit handler
  
  if ($("#poll-results").length > 0 ) {
    animateResults();
  }
  
	if ($.cookie('vote_id'+pollid) || bactive == 0) {
	    $(".poll").html("<div id='pollLoader'><h4>Loading Results</h4><img src='/qld/wsimages/ajax-loader.gif' alt='' /></div>");
	    
	    votedID = $.cookie('vote_id'+pollid);
	    
		$.ajax({
			 type: "GET",
			 url: "/qld/ajax/enpPollster.cfm?pollId=" + pollid,
			 dataType: 'html',
			 success: function(response){
						loadResults(response);
					  }
		 });
	}
});

function formProcess(event){
  event.preventDefault();
  
  var id = $("input[@name='pollOption']:checked").attr("value");
  
  $(".poll").html("<div id='pollLoader'><h4>Loading Results</h4><img src='/qld/wsimages/ajax-loader.gif' alt='' /></div>");
  
  votedID = id;
	    
	$.ajax({
		 type: "GET",
		 url: "/qld/ajax/enpPollster.cfm?pollId=" + pollid + "&vote=" + id,
		 dataType: 'html',
		 success: function(response){
					loadResults(response);
				  }
	 });
    
    $.cookie('vote_id'+pollid, id, {expires: 365});

}

function animateResults(){
	$(".poll .pollbar div").each(function(){
		var percentage = $(this).css("width");
		$(this).css({width: "0%"}).animate({
		width: percentage}, 'slow');
	});
}

function loadResults(data) {

$(".poll").html(data).fadeIn("slow", function() {
    animateResults();
    });
}






















