<?php
    $form = $this->beginWidget('CActiveForm', array(
                        'id' => 'building-details-form',
                        'enableAjaxValidation' => false,
                        'enableClientValidation' => false,
                    ));
        
        


    ?>            
            <ul class="form-add clearfix">

                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-building-o material m1">
                            <?php echo $form->hiddenField($model, 'id'); ?>
                    <?php echo $form->textField($model, 'building_name', array('placeholder'=>'Building Name')); ?>
                    <?php echo $form->error($model, 'building_name'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                        <div class="icon-box fa-building material m1">
                        <?php echo $form->textField($model, 'building_id', array('placeholder'=>'Building Id')); ?>
                        <?php echo $form->error($model, 'building_id'); ?>
                        </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-home material m1">
                    <?php echo $form->textField($model, 'makani', array('placeholder'=>'Makani')); ?>
                    <?php echo $form->error($model, 'makani'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-globe material m1">
                    <?php echo $form->textField($model, 'builder_name', array('placeholder'=>'Builder Name')); ?>
                    <?php echo $form->error($model, 'builder_name'); ?>
                            </div>
                    </li>
                    <?php
//                        $date   = date('d/m/Y');
                    if($model->id){
                        if($model->buying_date!='0000-00-00') {
                            $buying_date = $model->buying_date;
                            $date = DateTime::createFromFormat('Y-m-d', $buying_date);
                            $date = $date->format('d/m/Y');
                        }else{
                               $date = DateTime::createFromFormat('Y-m-d', date('Y-m-d'));
                            $date = $date->format('d/m/Y');
                        }
                    }else{
                               $date = DateTime::createFromFormat('Y-m-d', date('Y-m-d'));
                            $date = $date->format('d/m/Y');
                        }
                    ?>
                    <li class="form-add col-sm-3">
                            <div class="icon-box  fa-calendar-check-o  material m1">
                    <?php echo $form->textField($model, 'buying_date', array('class'=>'date-picker','placeholder'=>'Buying Date','value'=>$date)); ?>
                    <?php echo $form->error($model, 'buying_date'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-calendar material m1">
                    <?php echo $form->textField($model, 'location', array('placeholder'=>'Location')); ?>
                    <?php echo $form->error($model, 'location'); ?>
                            </div>
                    </li>
                    
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-location-arrow material m1">
                    <?php echo $form->textField($model, 'state', array('placeholder'=>'State')); ?>
                    <?php echo $form->error($model, 'state'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                           <div class="icon-box fa-globe material m1">
                     <?php  echo $form->dropDownList($model, 'country',MasterCountry::getCountry(),array('placeholder'=>'Country')); ?>
                    <?php echo $form->error($model, 'country'); ?>
                            </div>
                    </li>
                   <li class="form-add col-sm-3">
                            <div class="icon-box fa-phone material m1">
                    <?php echo $form->textField($model, 'telephone', array('placeholder'=>'Telephone')); ?>
                    <?php echo $form->error($model, 'telephone'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-mobile material m1">
                    <?php echo $form->textField($model, 'mobile', array('placeholder'=>'Mobile')); ?>
                    <?php echo $form->error($model, 'mobile'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-envelope material m1">
                    <?php echo $form->textField($model, 'email', array('placeholder'=>'Email')); ?>
                    <?php echo $form->error($model, 'email'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-usd material m1">
                                 <?php// $buying_value='';
//                                if($model->id > 0){
//                                    $buying_value = Yii::app()->numberFormatter->formatCurrency($model->buying_value,"");
//                                } ?>
                    <?php echo $form->textField($model, 'buying_value', array('placeholder'=>'Buying Value','onkeypress' => 'return isNumberKey(event)','value'=>$buying_value)); ?>
                    <?php echo $form->error($model, 'buying_value'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-th-list material m1">
                    <?php echo $form->textField($model, 'squarefeet', array('placeholder'=>'SquareFeet','onkeyup'=>'findSquareMetre(this.value);','onkeypress' => 'return isNumberKey(event)','value'=>0)); ?>
                    <?php echo $form->error($model, 'squarefeet'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-th-list material m1">
                    <?php echo $form->textField($model, 'squaremetre', array('placeholder'=>'SquareMetre','onkeyup'=>'findSquareFeet(this.value);','onkeypress' => 'return isNumberKey(event)','value'=>0)); ?>
                    <?php echo $form->error($model, 'squaremetre'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-th-large material m1">
                    <?php echo $form->textField($model, 'floors', array('placeholder'=>'No of Floors','onkeypress' => 'return isNumberKey(event)')); ?>
                    <?php echo $form->error($model, 'floors'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-building-o material m1">
                    <?php echo $form->textField($model, 'flats', array('placeholder'=>'No of Flats','onkeypress' => 'return isNumberKey(event)')); ?>
                    <?php echo $form->error($model, 'flats'); ?>
                            </div>
                    </li>

                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-calendar material m1">
                    <?php echo $form->textField($model, 'depreciation_months', array('onkeyup'=>'findDepreciationPercent();','placeholder'=>'Depreciation in Months','onkeypress' => 'return isNumberKey(event)')); ?>
                    <?php echo $form->error($model, 'depreciation_months'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-percent material m1">
                    <?php echo $form->textField($model, 'depreciation', array('onkeyup'=>'findDepreciationMonth();','placeholder'=>'Depreciation Percentage','onkeypress' => 'return isNumberKey(event)')); ?>
                    <?php echo $form->error($model, 'depreciation'); ?>
                            </div>
                    </li>
                    <li class="form-add col-sm-3">
                            <div class="icon-box fa-home material m1">
                    <?php echo $form->textArea($model, 'address', array('placeholder'=>'Address')); ?>
                    <?php echo $form->error($model, 'address'); ?>
                            </div>
                    </li>
                </ul>
            <div class="div-btn">
                <button type="button" class="btn btn-default" data-dismiss="modal" onclick=" location.href=$('#liveSite').val()+'administrator.php?r=purchasedbuilding/index';">Close</button>
                 <?php echo CHtml::ajaxSubmitButton('Save', Yii::app()->createUrl('purchasedbuilding/Save'), array(
                        'dataType' => 'json',
                        'type' => 'post',
                        'success' => 'function(data) {
                            if(data.status=="success"){
                                    location.href=$("#liveSite").val()+"administrator.php?r=purchasedbuilding/create&id="+data.id;
                                notification("Purchased Building saved!","success");
                            }
                            else
                            {
                                $.each(data, function(key, val) {
                                    //$("#"+key).addClass("error");
                                    notification(val,"error");
                                });
                            }
			}',
			'beforeSend' => 'function(){ 
                            /* var rowCount    = $("#tab_owner_details tr").length;
                            var totaladdition =0.00;
                            for(i=0;i<rowCount-1;i++){
                                var additionValue = $("#BuildingOwnerDetails_"+i+"_percentage").val();
                                //alert("additionValue "+additionValue);
                                if(additionValue != ""){
                                    totaladdition = parseFloat(totaladdition,10) + parseFloat(additionValue,10);
                                }
                                //alert("total "+totaladdition);
                            }
                            
                            if(totaladdition != 100){
                                jAlert("Percentage Sum should be 100","Alert");
                                return false;
                            }*/
                            $.pnotify_remove_all();
                            $("#building-details-form .maintenance-save-btn").prop("disabled", true);
                        }',
                        'complete' => 'function(){
                            $("#building-details-form .maintenance-save-btn").prop("disabled", false);
                        }'
		), array('id' => 'mybtn' . rand(), 'class' => 'maintenance-save-btn btn btn-primary')); ?>

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