<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- {if $vote} -->
{insert_scripts files='transport.js'}
<div id="ECS_VOTE">
<div class="mod1 mod2 blank" id="votelist">
	<span class="lt"></span><span class="lb"></span><span class="rt"></span><span class="rb"></span>
	<h1 class="mod2tit">{$lang.online_vote}</h1>
	<div class="mod2con">
	<form id="formvote" name="ECS_VOTEFORM" method="post" action="javascript:submit_vote()">
	<!-- {foreach from=$vote item=title} -->
	 <p align="center" class="f1"><b>{$title.vote_name}</b><br />
	 ({$lang.vote_times}:{$title.vote_count})</p>
	 <!-- {/foreach} -->
	 <!-- {foreach from=$vote item=title} -->
				<!-- {foreach from=$title.options item=item} -->
					<!-- {if $title.can_multi eq 0} -->
					<input type="checkbox" name="option_id" value="{$item.option_id}" />
					{$item.option_name} ({$item.percent}%)<br />
					<!-- {else} -->
					<input type="radio" name="option_id" value="{$item.option_id}" />
					{$item.option_name} ({$item.percent}%)<br />
					<!-- {/if} -->
					<!-- {/foreach} -->
					<input type="hidden" name="type" value="{$title.can_multi}" />
	 <!-- {/foreach} -->
	 <input type="hidden" name="id" value="{$vote_id}" />
	 <input type="submit" name="submit" value="{$lang.submit}" class="bnt_number2" />
	 <input type="reset" value="{$lang.reset}" class="bnt_number2" />
  </form>
	</div>
</div>
<script type="text/javascript">divheight("votelist");</script>
</div>
<script type="text/javascript">
{literal}
/**
 * 处理用户的投票
 */
function submit_vote()
{
  var frm     = document.forms['ECS_VOTEFORM'];
  var type    = frm.elements['type'].value;
  var vote_id = frm.elements['id'].value;
  var option_id = 0;

  if (frm.elements['option_id'].checked)
  {
    option_id = frm.elements['option_id'].value;
  }
  else
  {
    for (i=0; i<frm.elements['option_id'].length; i++ )
    {
      if (frm.elements['option_id'][i].checked)
      {
        option_id = (type == 0) ? option_id + "," + frm.elements['option_id'][i].value : frm.elements['option_id'][i].value;
      }
    }
  }

  if (option_id == 0)
  {
    return;
  }
  else
  {
    Ajax.call('vote.php', 'vote=' + vote_id + '&options=' + option_id + "&type=" + type, voteResponse, 'POST', 'JSON');
  }
}

/**
 * 处理投票的反馈信息
 */
function voteResponse(result)
{
  if (result.message.length > 0)
  {
    alert(result.message);
  }
  if (result.error == 0)
  {
    var layer = document.getElementById('ECS_VOTE');

    if (layer)
    {
      layer.innerHTML = result.content;
			divheight("votelist");
    }
  }
}
{/literal}
</script>
<!-- {/if} -->