<?php
    foreach(Yii::app()->user->getFlashes() as $key => $message) {
        echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
    }
?>
<?php
Yii::app()->clientScript->registerScript('addremoveF',"
$('#addOneMoreFeature a').live('click',function()
{
$('#maintable tr:last').prev('tr').after($('#trCategory').clone().find('input').val('').end());
}
);
$('#removeOneFeature a').live('click',function()
{
if($('#maintable tr').length>4)
$(this).closest('tr').remove();
});

"); ?>
<div id="form_wrapper">
  <?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'product-category-form',
	'enableAjaxValidation'=>false,
)); ?>
  <div id="row"><br>
    <br>
    <table width="800" cellspacing="2" cellpadding="3" border="0" style="border:1px #999 solid" id="maintable">
      <tbody>
        <tr>
          <td width="400" align="right"><?php echo $form->labelEx($model,'user_group_id'); ?></td>
          <td width="400">
		  <?php echo $form->dropDownList($model,'user_group_id',UserGroup::getGroups(),
											 array(
												'style'=>'width:150px',
												'prompt'=>'Select user group',
												'ajax' => array(
												'type'=>'POST',
												'url'=>CController::createUrl('Product/updateProductGroup'), 
												'data'=>array('user_group_id'=>'js:this.value'), 
												'success'=>'js:function(data){
													$("#ProductType_product_group_id").html(data)
													}'
            ))); ?> 
			<?php echo $form->error($model,'user_group_id'); ?></td>
        </tr>
        <tr>
          <td width="400" align="right"><?php echo $form->labelEx($model,'product_group_id'); ?></td>
          <td width="400">
		  <?php echo $form->dropDownList($model,'product_group_id',ProductGroup::getProductGroup($model->user_group_id),array(
												'style'=>'width:150px',
												'prompt'=>'Select group',
												'ajax' => array(
												'type'=>'POST',
												'url'=>CController::createUrl('Product/updateProductCategory'), 
												'update'=>'#ProductType_category_id',
												'data'=>array(
															  'user_group_id'=>'js:$("#ProductType_user_group_id :selected").val()',  
															  'product_group_id'=>'js:this.value'
															  ),  
																		  ))); ?> 
		 <?php echo $form->error($model,'product_group_id'); ?></td>
        </tr>
        <tr>
          <td align="right"><?php echo $form->labelEx($model,'category_id'); ?></td>
          <td><?php echo $form->dropDownList($model,'category_id',ProductCategory::getProductCategory($model->user_group_id,$model->product_group_id),array(
												'style'=>'width:150px',
												'prompt'=>'Select category',
												)); ?> <?php echo $form->error($model,'category_id'); ?></td>
        </tr>
        <tr id="trCategory" class="trCategory">
          <td align="right"><?php echo $form->labelEx($model,'type_name'); ?></td>
          <td valign="top"><?php echo $form->textField($model,'type_name',array('name'=>'type_name[]','size'=>20,'maxlength'=>255)); ?> <?php echo $form->error($model,'type_name'); ?>
          <?php if($model->isNewRecord) : ?>
          <div class="addOneMore" id="addOneMoreFeature"> <a href="javascript:;"><img height="15" width="15" class="plus_position" alt="pluse" src="images/admin/green-plus-sign-md.png"></a></div>&nbsp;&nbsp;&nbsp;<div class="removeOne"  id="removeOneFeature"> <a href="javascript:;"><img height="15" width="15" src="images/admin/green--sign-md.png"></a> </div>
          <?php endif; ?>
          </td>
        </tr>
        <tr>
          <td align="right"><?php echo $form->labelEx($model,'show_in_partner'); ?></td>
          <td valign="top"><?php echo $form->dropDownList($model, 'show_in_partner',array('Y'=>'Yes','N'=>'No')); ; ?>

			<?php echo $form->error($model,'show_in_partner'); ?>
			</td>
        </tr>
        
        <tr>
          <td align="right">&nbsp;</td>
          <td><?php echo CHtml::submitButton($model->isNewRecord ? 'Submit' : 'Save'); ?></td>
        </tr>
      </tbody>
    </table>
  </div>
  <br>
  <br>
  <br>
  <?php $this->endWidget(); ?>
</div>
