$(document).ready(function(){
	$("div[id^='vote_done_'] a").live("click",function() {
       		vote = $(this).parents("div[id^='vote_done_']").attr('id').substr(10,10);
		if (!$("div#vote_info_"+vote).hasClass("active"))
		{
               		$.ajax({
                 	   type: 'POST',
                 	   url: BaseDir+'includes/ajax_block.php',
        		   async: false,
                 	   data: {
        			action: 'vote_view',
        			vote_id: vote
        		   },
                 	   success: function(data){
                		var obj = jQuery.parseJSON(data);
              			if ((obj != null) && (obj.result == 'success'))
        			{
        				$('div#vote_info_'+vote).html(obj.table);
					$("div#vote_info_"+vote).slideToggle("fast");
				       	$("div#vote_info_"+vote).toggleClass("active");
        			}
                 	   }
                 	 });
		}
		else
		{
			$("div#vote_info_"+vote).slideToggle("fast");
		       	$("div#vote_info_"+vote).toggleClass("active");
		}
		return false;
	});

	$("input[type='button'][name^='vote_']").click(function() {
    		if (iMember == 0) {
		    	$(window).scrollTop(0);
		    	$('#user_login_button').click() ;
		    	return false;
	    	}
		vote = $(this).attr('name').substr(5,10);
		answers = new Array();
		$("input[name='vote_"+vote+"'][type='radio']:checked").each(function() {
			answers.push($(this).val());
		});
		$("input[name='vote_"+vote+"'][type='checkbox']:checked").each(function() {
			answers.push($(this).val());
		});
		if (answers.length==0)
		  $('#messageContainer').makeAlert(300, plocale['no_answer'], function(){}) ;
			//alert(plocale['no_answer']);
		else
		{
               		$.ajax({
                 	   type: 'POST',
                 	   url: BaseDir+'includes/ajax_block.php',
        		   async: false,
                 	   data: {
				action: 'vote',
				vote_id: vote,
				answers: answers
			   },
                 	   success: function(data){
                		var obj = jQuery.parseJSON(data);
              			if ((obj != null) && (obj.result == 'success'))
        			{
        				$('div#vote_done_'+vote).html(obj.params);
					$("input[name='vote_"+vote+"']").each(function() { $(this).attr("disabled","disabled");});
        			}
                 	   }
                 	 });
		}
	});

});
