<script type="text/javascript">
/*<![CDATA[*/
jQuery('a.delete').live('click',function() {
	if(!confirm('Are you sure to delete this item?')) return false;
});
</script>

<script type="text/javascript">
function addTr(me)
{
	var html = '<tr>';
	html += '<td>[<a href="javascript:void(0)" onClick="addTr(this)">+</a>][<a href="javascript:void(0)" onClick="delTr(this)">-</a>]<input type="text" value="" name="newoptions[]" /></td>';
	html += '</tr>';

	$(me).parent().parent().before(html);
}

function delTr(me)
{
	$(me).parent().parent().remove();
}
</script>
<p>
<span class="required">*</span>为必填
</p>
<?php echo CHtml::errorSummary($model);?>
<?php echo CHtml::beginForm(); ?>
<table class="dataGrid">
	<tbody>
		<tr>
			<th><?php echo CHtml::activeLabelEx($model,'subject'); ?></th>
			<td><?php echo CHtml::activeTextField($model,'subject',array('size'=>30,'maxlength'=>255)); ?></td>
		</tr>
        
        <tr>
			<th><?php echo CHtml::activeLabelEx($model,'expire'); ?></th>
            <td>
                <?php
                    $this->widget('zii.widgets.jui.CJuiDatePicker',
                                   array(
                                       'name'=>'Vote[expire]',
                                       'options'=>array('dateFormat'=>'yy-mm-dd'),
                                       'value' => ($update ? date('Y-m-d', $model->expire) : ''),
                                   )
                                );
                ?>
            </td>
		</tr>

        <tr>
            <th><?php echo CHtml::activeLabelEx($model,'multiple');?></th>
            <td><?php echo CHtml::activeDropDownList($model, 'multiple', array(0=>'单选',1=>'多选'));?></td>
        </tr>
        
        <tr>
			<th><?php echo CHtml::activeLabelEx($model,'maxchoices'); ?></th>
			<td><?php echo CHtml::activeTextField($model,'maxchoices',array('value'=>1)); ?></td>
		</tr>

        <tr>
			<th><?php echo CHtml::activeLabelEx($model,'award'); ?></th>
			<td><?php echo CHtml::activeTextField($model,'award'); ?></td>
		</tr>

        <tr id="newTr">
            <td>选项</td>
            <td>
                <table>
                    <?php if ($update && !empty($options)):?>
                        <?php foreach($options as $option):?>
                            <tr>
                                <td>
                                    <?php echo CHtml::textField('options['.$option->id.']', $option->option);?> <?php echo $option->votes;?> [<?php echo CHtml::link('删除',array('deloption','vid'=>$_GET['id'],'id'=>$option->id),array('class'=>'delete'));?>]
                                </td>
                            </tr>
                        <?php endforeach;?>
                    <?php endif;?>
                    <tr>
                        <td>[<a href="javascript:void(0)" onClick="addTr(this)">+</a>][<a href="javascript:void(0)" onClick="delTr(this)">-</a>]<?php echo CHtml::textField('newoptions[]','');?></td>
                    </tr>
                </table>
            </td>
        </tr>

        <tr>
			<th><?php echo CHtml::activeLabelEx($model,'description'); ?></th>
            <td><?php echo CHtml::activeTextArea($model, 'description', array('cols'=>40,'rows'=>5));?></td>
        </tr>
		
        <?php if ($update):?>
            <tr>
                <th><?php echo CHtml::activeLabelEx($model,'createdate'); ?></th>
                <td><?php echo CHtml::activeTextField($model,'createdate'); ?></td>
            </tr>
        <?php endif;?>
	</tbody>
</table>
<?php echo CHtml::submitButton($update ? '修改' : '添加'); ?>
<?php echo CHtml::endForm(); ?>