/**
 * @author simonschmidt
 */
function load_box(url)
{
	$('#poll_ajax_box').html('<div align="center"><img src="http://www.alarie.de/templates/images/ajax-loader.gif" /></div>');
	
	 $.ajax({
	   type: "GET",
	   url: "http://www.alarie.de/boxes/poll/ajax/"+url,
	   success: function(msg){
	     $('#poll_ajax_box').html(msg);
	   }
	 });
}
$('.answer_radio').click(
	function()
	{
		$(this).addClass('selected');
		$('.selected').removeClass('selected');
		$(this).addClass('selected');
	}
);
function registerVote(questionid)
{
	var answerid = $("input:checked").filter(".answer_radio").val();
	answerid = answerid * 1;
	if(answerid=="NaN")
		alert("Make a selection!");
	$('#poll_ajax_box').html('');
	 $.ajax({
	   type: "POST",
	   url: "http://www.alarie.de/boxes/poll/ajax/vote.php",
	   data: "questionid="+questionid+"&answerid="+answerid,
	   success: function(msg){
	   		load_box("display.php");
	   }
	 });
}

function savePoll(a)
{
	
	var url = "savepoll.php?numanswers="+a;
	if ($('#poll_question').val() == "") {
		alert("Enter Question!");
		return;
	}
		
	url += "&question="+$('#poll_question').val();	
	for(i = 0; i < a; i++)
	{
		if($('#answer'+i).val() != "")
			url += "&answer"+i+"="+$('#answer'+i).val();
	}
	load_box(url);
}

