function setHtmlLoading(el)
{
	el.html("<div class='loading_dialog'><div>Loading...</div><div><img src='images/loading_bar.gif' alt='' /></div></div>");
}

function clickVoteResult()
{
	$("#vote_result_btn").click();
	$("#vote_dialog").dialog("close");
}

$(document).ready(function(){

	// Vote
	var vote_file = "poll_vote.php";
	var vote_result_file = "poll_result.php";
	setHtmlLoading($("#vote_result_dialog"));
	
	$("#vote_dialog").dialog({
		autoOpen: false,
		modal : true,
		width: 270,
		height: 120,
		resizable: false,
		open : function(event, ui){
			hideSelectBox();
		},
		beforeclose : function(event, ui){
			showSelectBox();
		}
	});
	
	$("#vote_result_dialog").dialog({
		autoOpen: false,
		modal : true,
		width: 400,
		height: 440,
		resizable: false,
		open : function(event, ui){
			hideSelectBox();
		},
		beforeclose : function(event, ui){
			showSelectBox();
		}
	});
	
	$("#vote_result_btn").click(function(){
		setHtmlLoading($("#vote_result_dialog"));

		$("#vote_result_dialog").load(vote_result_file);
		$("#vote_result_dialog").dialog("open");

		return false;
	});
	
	$("#vote_btn").click(function(){
		setHtmlLoading($("#vote_dialog .message"));
		var vote_choice = (typeof $("input[name=vote_choice]:checked").val() != 'undefined') ? $("input[name=vote_choice]:checked").val() : 0;
		$("#vote_dialog .message").load(vote_file, { 'vote_choice' : vote_choice });
		$("#vote_dialog").dialog("open");
		
		return false;
	});
	// End Vote

});
