<div class="form">

    <?php
    /**
     * @var BHorizontalForm $form
     * @var TuningSet $model
     * @var TuningSetI18n[] $i18nModels
     */
    ?>

    <?php $form = $this->beginWidget('BHorizontalForm', array(
    'id' => 'tuning-set-form',
    'enableAjaxValidation' => false,
    'htmlOptions' => array(
        'enctype' => 'multipart/form-data',
    ),
)); ?>
    <!--
    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>

    -->

    <div class="control-group <?php echo ($model->hasErrors('hidden') ? ' error' : '') ?>">
        <?php echo $form->label($model, 'hidden', array('class' => 'control-label'))?>
        <div class="controls">
            <?php echo $form->checkBox($model, "hidden"); ?>
            <?php echo $form->error($model, 'hidden'); ?>
        </div>
    </div>

    <div class="control-group <?php echo ($model->hasErrors('tuning_model_id') ? ' error' : '') ?>">
        <?php echo $form->label($model, 'tuning_model_id', array('class' => 'control-label'))?>
        <div class="controls">
            <?php echo $form->dropDownList($model, 'tuning_model_id', $model->getTuningModels()); ?>
            <?php echo $form->error($model, 'tuning_model_id'); ?>
        </div>
    </div>

    <div class="control-group <?php echo ($model->hasErrors('link') ? ' error' : '') ?>">
        <?php echo $form->label($model, 'link', array('class' => 'control-label'))?>
        <div class="controls">
            <?php echo $form->textField($model, 'link', array('size' => 60, 'maxlength' => 64)); ?>
            <?php echo $form->error($model, 'link'); ?>
        </div>
    </div>


    <div class="control-group <?php echo ($model->hasErrors('contactIds') ? ' error' : '') ?>">
        <?php echo $form->label($model, 'contactIds', array('class' => 'control-label'))?>
        <div class="controls">
            <?php
            $this->widget('MultiSelect',array(
                'data'=>Contact::listWithSelected($model->getContactIds()),
                'model'=>$model,
                'attribute'=>'contactIds',
                'htmlOptions'=>array(
                    'style'=>'min-width:600px; min-height:200px;'
                )
            )); ?>
            <?php //echo Chosen::activeMultiSelect($model, 'contactIds', CHtml::listData(Contact::model()->findAll(), 'id', 'i18n.name')); ?>
            <?php echo $form->error($model, 'contactIds'); ?>
        </div>
    </div>


    <?php
    echo $form->controlGroup($model, 'image',
        $form->fileField($model, 'image') . '<br/>' .
            CHtml::image($model->imageBehavior->getFileUrl()));
    ?>
    <h2>Галерея комплекта тюнинга</h2>
    <?php
    if ($model->galleryBehavior->getGallery() === null) {
        ?>
        <p>Для управления галереей сохраните обьект</p>
        <?php
    } else {
        $this->widget('GalleryManager', array(
            'htmlOptions' => array('style' => 'float:left;'),
            'gallery' => $model->galleryBehavior->getGallery(),
        ));
        echo '<br style="clear: both;"/><br/><br/>';
    }
    ?>
    <?php
    /**
     * @var BTabs $tabs
     */
    $tabs = $this->beginWidget('BTabs');
    foreach ($i18nModels as $lang => $i18nModel):
        ?>
        <?php $tabs->beginTab(Yii::app()->params['languageNames'][$lang]) ?>
        <div class="control-group <?php echo ($i18nModel->hasErrors('name') ? ' error' : '') ?>">
            <?php echo $form->label($i18nModel, 'name', array('class' => 'control-label'))?>
            <div class="controls">
                <?php echo $form->textField($i18nModel, "[$lang]name", array('size' => 60, 'maxlength' => 512)); ?>
                <?php echo $form->error($i18nModel, 'name'); ?>
            </div>
        </div>

        <div class="control-group <?php echo ($i18nModel->hasErrors('page_name') ? ' error' : '') ?>">
            <?php echo $form->label($i18nModel, 'page_name', array('class' => 'control-label'))?>
            <div class="controls">
                <?php echo $form->textField($i18nModel, "[$lang]page_name", array('size' => 60, 'maxlength' => 512)); ?>
                <?php echo $form->error($i18nModel, 'page_name'); ?>
            </div>
        </div>

        <div class="control-group <?php echo ($i18nModel->hasErrors('content') ? ' error' : '') ?>">
            <?php echo $form->label($i18nModel, 'content', array('class' => 'control-label'))?>
            <div class="controls">
                <?php
                $this->widget('TinyMce', array(
                    'model' => $i18nModel,
                    'attribute' => "[$lang]content",
                    'htmlOptions' => array(
                        'rows' => 6,
                        'cols' => 60,
                    ),
                ));
                ?>
                <?php echo $form->error($i18nModel, 'content'); ?>
            </div>
        </div>

        <?php echo $form->beginFieldset('СЕО Параметры'); ?>

        <div class="control-group <?php echo ($i18nModel->hasErrors('title') ? ' error' : '') ?>">
            <?php echo $form->label($i18nModel, 'title', array('class' => 'control-label'))?>
            <div class="controls">
                <?php echo $form->textField($i18nModel, "[$lang]title", array('size' => 60, 'maxlength' => 512)); ?>
                <?php echo $form->error($i18nModel, 'title'); ?>
            </div>
        </div>

        <div class="control-group <?php echo ($i18nModel->hasErrors('keywords') ? ' error' : '') ?>">
            <?php echo $form->label($i18nModel, 'keywords', array('class' => 'control-label'))?>
            <div class="controls">
                <?php echo $form->textArea($i18nModel, "[$lang]keywords", array('rows' => 6, 'cols' => 50)); ?>
                <?php echo $form->error($i18nModel, 'keywords'); ?>
            </div>
        </div>

        <div class="control-group <?php echo ($i18nModel->hasErrors('description') ? ' error' : '') ?>">
            <?php echo $form->label($i18nModel, 'description', array('class' => 'control-label'))?>
            <div class="controls">
                <?php echo $form->textArea($i18nModel, "[$lang]description", array('rows' => 6, 'cols' => 50)); ?>
                <?php echo $form->error($i18nModel, 'description'); ?>
            </div>
        </div>
        <?php echo $form->endFieldset(); ?>

        <?php $tabs->endTab() ?>
        <?php
    endforeach;
    $this->endWidget();
    ?>

    <div class="form-actions">
        <button type="submit" class="btn btn-large btn-primary">
            <?php echo ($model->isNewRecord ? 'Создать' : 'Сохранить'); ?>
        </button>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- form -->
