function openWindow(url, name, w, h, features) {
      popupWin = window.open(url, name,'width=' + w + ',height=' + h + "," + 'status=yes,scrollbars=yes,resizable=yes');
}

$(document).ready(function() {
	var pollID = $("input[name='poll_id']").val(); // Get PollID
	
	$("#voteButton").click(function(e) {
		var answer = $("input[name='answer']:checked").val(); // Get answer

		if (answer == null) {
			alert("You must select an answer");
			e.preventDefault();
			return false;
		}

		$("#pollContainer").css("cursor", "wait"); // show wait cursor inside poll container while processing
		$("#voteButton").attr("disabled", "true") // disable the Vote button while processing

		var params = "poll_id=" + pollID + "&answer=" + answer; // Send data in parameters

		$.ajax({   //call the page handler
			type: "POST",
			url: "/tools/poll/poll_handler.aspx?" + params,
			success: function(result) {  //show the result    				
				$("#pollContainer").css("cursor", "default"); // remove the wait cursor
				$("#voteButton").attr("disabled", "") // enable the Vote button
				$("#pollResults").fadeOut("fast").html(result).fadeIn("fast", function() { animateResults(); });
			}
		});		
	});

	$("#viewResultsButton").click(function(e) {
		var params = "poll_id=" + pollID + "&results=true" // Send data in parameters
		$.ajax({   //call the page handler
			type: "POST",
			url: "/tools/poll/poll_handler.aspx?" + params,
			success: function(result) {  //show the result    							
				$("#pollResults").fadeOut("fast").html(result).fadeIn("fast", function() { animateResults(); });
			}
		});
	});

	function animateResults() {
		$("div[id$=pollAnswers] img").each(function() {
			var percentage = $(this).attr("val");
			$(this).css({ width: "0%" }).animate({ width: percentage }, 'slow');
		});
	}	
});

