<div id="poll">
	<p><b>{$poll.question}<br /></b></p>
	{foreach from=$poll.answers item=item}
		<p>
			<input id="poll_answer_id{$item.poll_answer_id}" type="radio" name="poll_answer_id" value="{$item.poll_answer_id}">&nbsp;<label class="text" for="poll_answer_id{$item.poll_answer_id}">{$item.text}</label>
		</p>
	{/foreach}
	{if $poll.allow_comments}	
		<div id="poll_comment_div" style="display: none; padding-top:4px;">
			<textarea name="poll_comment" id="poll_comment{$from_poll}" cols="1" rows="1" onkeyup="BadWords('poll_comment{$from_poll}');" style="width: 100%; height: 30px;"></textarea>
            <div id="bad_div_poll_comment{$from_poll}" class="bad_div_left"></div>
		</div>
	{/if}
	<div style="overflow: hidden; margin-top: 10px;">
		<div class="float_left" align="{$default_left}">
			
				<input type="button" value="{$lang.button.vote}" onclick="votePoll('{$poll.poll_id}', this); return false;" class="float_left" style="margin-bottom: 5px;"/>
			     <br />
                <div style="display:table; width: 100%;">
                    <div style="height: 16px; width: 10px; padding: 0;" class="small_triangle_icon float_left"></div><a href="{$site_root}/{$seo.poll}?sel=polls&par=last_polls" >{$lang.button.view_all}</a><br />
                </div>
                <div style="margin: 5px 0;">
                    <div style="height: 16px; width: 10px; padding: 0;" class="small_triangle_icon float_left"></div><a href="" onclick="$(this).parents('#poll').find('#poll_comment_div').toggle();return false;">{$lang.homepage.poll_add_comment}</a><br />
                </div>
                <div style="margin: 5px 0;">
                    <div style="height: 16px; width: 10px; padding: 0;" class="small_triangle_icon float_left"></div><a href="" onclick="showAdvStats('{$poll_id}'); return false;">{$lang.button.view_result}</a>
                </div>
				<br />
				<span id="loading"></span>
			
		</div>		
	</div>
</div>
<script type="text/javascript">
	server = '{$server}';
	greybox = '{$greybox}';
	{literal}
	function votePoll(poll_id, obj){
		if (!poll_id) return false;

		poll_answer_id_val = $(obj).parents('#poll').find("input[name=poll_answer_id]:checked").val();

		if (!poll_answer_id_val){
			alert("{/literal}{$lang.poll_errors.choose_answer|escape:javascript}{literal}");
			return false;
		}

		ajaxLoadingImage(1, 'loading');
		if ($(obj).parents('#poll').find('#poll_comment_div').css('display') == 'none')
				$(obj).parents('#poll').find("textarea[name=poll_comment]").val('');
		str = 'ajax=1&poll_id='+poll_id+'&poll_answer_id='+poll_answer_id_val+'&poll_comment='+($(obj).parents('#poll').find("textarea[name=poll_comment]")?$(obj).parents('#poll').find("textarea[name=poll_comment]").val():'');

		$.post(SEO_SITE_ROOT+"/backend.php?sel=poll_vote",str,function(data){
			data = getJQData(data);
			ajaxLoadingImage(0, 'loading');
			if (data.succ == '1'){
				showStats(poll_id);
				return;
			}else{
				alert(data.msg);
			}
		});
	}

	function showStats(poll_id){
		if (!poll_id) return false;
		str = "ajax=1&poll_id="+poll_id;
		$.post(SEO_SITE_ROOT+"/backend.php?sel=poll_get_stats&greybox="+greybox, str,function(data){
			if($('#window').find("#poll").html() != null){
			$('#window').find("#poll").html(data);
			}
			else
			{
				$("#poll").html(data); 
			}
		});
	}
	{/literal}
</script>