<?php
/* @var $this BranchController */
/* @var $model Branch */
/* @var $form CActiveForm */
?>

<div class="col-xs-12">

    <?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	'id'=>'branch-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

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

                    <?php echo $form->textFieldControlGroup($model,'name_ar',array('maxlength'=>500)); ?>
        
                    <?php echo $form->textFieldControlGroup($model,'name_en',array('maxlength'=>500)); ?>

                    <?php echo $form->textFieldControlGroup($model,'address',array('maxlength'=>300)); ?>

                    <?php echo $form->textFieldControlGroup($model,'address_en',array('maxlength'=>300)); ?>

                    <?php echo $form->textFieldControlGroup($model,'phone',array('maxlength'=>50)); ?>

                    <?php echo $form->textFieldControlGroup($model,'fax',array('maxlength'=>50)); ?>
        
                    <?php echo $form->textFieldControlGroup($model,'longitude'); ?>
        
                    <?php echo $form->textFieldControlGroup($model,'latitudes'); ?>

                    <?php echo $form->textFieldControlGroup($model,'atm'); ?>
        
                    <?php //echo $form->textFieldControlGroup($model,'governorate'); ?>

                    <?php echo $form->dropDownListControlGroup($model,'governorate',CHtml::listData(Governorate::model()->findAll(), 'id', 'name_ar'), array('empty'=>'Select a governorate'));
      
                    ?>
                  
                   <?php echo $form->dropDownListControlGroup($model,'area',CHtml::listData(Area::model()->findAll(), 'id', 'name_ar'),array('empty'=>'Select a area')); ?>
                  
                    <?php echo $form->dropDownListControlGroup($model,'type',array('branch'=>'branch','atm'=>'atm'),array('empty'=>'Select a area')); ?>

                    <?php echo $form->textFieldControlGroup($model,'sort'); ?>

    
    <?php
                            echo TbHtml::formActions(array(
                                    TbHtml::submitButton($model->isNewRecord ? Yii::t('admin', 'Create') : Yii::t('admin', 'Save'), array('color' => TbHtml::BUTTON_COLOR_PRIMARY)),
                                    TbHtml::resetButton(Yii::t('admin', 'Reset')),
                                ));
                            ?>    
    <?php $this->endWidget(); ?>




</div>

<script>
 
 
$('#Branch_governorate').on('change', function(){
var country_id = this.value;

$.ajax({
  dataType: "json",
  url: "<?php echo CController::createUrl('dynamiccities') ?>",
  data: {id: country_id},
 success: function( response){
               

var $el = $("#Branch_area");
$el.empty(); // remove old options
$.each(response, function(key,value) {
  $el.append($("<option></option>")
     .attr("value", key).text(value));
});
                },
                error: function( jqXhr, textStatus, errorThrown ){
                    console.log( errorThrown );
                }
});


  });

</script>