var MAG = Object.extend({}, MAG || {});
MAG.ProgrammePoll = {
	Init: function(options)
	{
		this.options = {};
		Object.extend(this.options, options || {});

	},	
	
	submit_vote : function() {
		var poll_id = $F('poll_id');
		var section_id = $F('section_id');	  
	    
		$$('.radio').each(function(e,i){			
			if(e.checked ) { 
				var answer = $F(e);
				new Ajax.Updater('results', MAG.ProgrammePoll.options.url, {
					method: 'get',					
					parameters: {method: 'ajax_vote', poll_answer_id: answer, id:poll_id, section_id:section_id},
					insertion: Insertion.Bottom
				})
				$('poll_form').hide();	
			}		
		
		});				
			
	},	
	
	calculate: function() 
	{		
		var poll_id = $F('poll_id');
		var section_id = $F('section_id');
		new Ajax.Updater('results',  MAG.ProgrammePoll.options.url, {
			method: 'get',
			parameters: {method: 'calculate_poll_results', id: poll_id, section_id: section_id},
			insertion: Insertion.Bottom
		})	
		
		$('poll_form').hide();	
	}	
	
}

function results(){

	MAG.ProgrammePoll.calculate();
}

function vote() {
	
	MAG.ProgrammePoll.submit_vote();
}

