<?php    $form = $this->beginWidget('CActiveForm', array( 
    'id' => 'building-details-form',
    'enableAjaxValidation' => false,  
    'enableClientValidation' => false, 
    )); 
    $display="style='display:none;'";
    if(isset($model->construction_status) && $model->construction_status==2)
    {
       $display="";
    }
?>     
<ul class="form-add clearfix">
    <input type="hidden" name="word" id="word" value="<?php echo $buying_value_inword;?>"> 
    <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 <span class="red">*</span>')); ?> 
                   <?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>      
    <li class="form-add col-sm-3">   
        <div class="icon-box  fa-calendar-check-o  material m1"> 
                    <?php 
                        if(!empty($model->buying_date)){
                            $date = $model->buying_date;
                        }
                    ?>
                   <?php echo $form->textField($model, 'buying_date', array('class'=>'date-picker','placeholder'=>'Buying Date <span class="red">*</span>','value'=>isset($date)?$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>        
    <?php 
      $selectedOptions=  array();
                if($model->id>0){
                    $selectedOptions[$model->country] = array('selected' => 'selected');
                }else{
                    $selectedOptions['228'] = array('selected' => 'selected');
                }
    ?>
    <li class="form-add col-sm-3">   
        <div class="icon-box fa-globe m-select m1">   
            <label>Country</label>
                  <?php  echo $form->dropDownList($model, 'country',MasterCountry::getCountry(),array('options' => $selectedOptions,'prompt'=>'--Select--','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','onkeyup'=>'findSquareRate();findAmountInJd();','onkeypress' => 'return isNumberKey(event)','value'=>isset($buying_value)?$buying_value:'')); ?>  
                  <?php echo $form->error($model, 'buying_value'); ?>   
        </div>           
    </li>      
    <li class="form-add col-sm-3"> 
        <div class="icon-box fa-usd material m1">   
        <?php   $model_settings     = Settings::model()->getSettings();
                $aed_jd_eqvnt       = $model_settings->aed_jd_eqvlnt;
                $buying_value= isset($model_building->buying_value)?$model_building->buying_value:'';  
                             if($buying_value != ''){ 
                                $buying_value_jd = $buying_value*5.20;   
                            } else {    
                                $buying_value_jd ='';    
                            } ?>
            <input type="hidden" name="aed_jd_eqvnt" id="aed_jd_eqvnt"  value="<?php echo $aed_jd_eqvnt; ?> " > 
            <input type="text" name="jd_value" id="jd_value"  value="<?php echo $buying_value_jd; ?> " readonly="" placeholder="Amount in JD"> 
        </div>  
    </li> 
    <?php if($model->id > 0){ ?> 
    <li class="form-add col-sm-6"> 
        <div class="icon-box fa-usd material m1">   
        
        
                             <?php $buying_value= $model_building->buying_value;  
                             if($model_building->buying_value != '0.00'){ 
                                 $buying_value_inword = $this->int_to_words($buying_value).' Only/-';   
                                 } else {    
                                     $buying_value_inword ='';    
                                     } ?>
            <input type="text" name="amountinwords"  value="<?php echo $buying_value_inword; ?> " readonly="" placeholder="Amount in words"> 
        </div>  
    </li>     
    <?php } ?>     
    <li class="form-add col-sm-3">  
        <div class="icon-box fa-th-list m-select m1">  
            <label>Construction Status</label>
                  <?php echo $form->dropDownList($model, 'construction_status', array("1"=>"ReadyToOccupy","2"=>"UnderConstruction"), array('prompt'=>'--Select--','placeholder'=>'Construction Status','onchange'=>'getExpectedDate()')); ?>  
                  <?php echo $form->error($model, 'construction_status'); ?>   
        </div> 
    </li>
    <div id="div_construction" <?php echo $display;?>>
        <li class="form-add col-sm-3">   
        <div class="icon-box  fa-calendar-check-o  material m1"> 
                   <?php echo $form->textField($model, 'expected_delivery_date', array('class'=>'date-picker','placeholder'=>'Expected Delivery Date <span class="red">*</span>')); ?>
                    <?php echo $form->error($model, 'expected_delivery_date'); ?>    
        </div> 
        </li>
    </div>
    <li class="form-add col-sm-3">  
        <div class="icon-box fa-th-list material m1">  
            <?php echo $form->textField($model, 'cmn_area_sqft', array('placeholder'=>'CommonArea(SqFt)','onkeyup'=>'findCmnSquareMetre(this.value);findSquareRate();','onkeypress' => 'return isNumberKey(event)')); ?>    
                <?php echo $form->error($model, 'cmn_area_sqft'); ?>   
        </div>        
    </li>         
    <li class="form-add col-sm-3">  
        <div class="icon-box fa-th-list material m1">  
                  <?php echo $form->textField($model, 'cmn_area_sqm', array('placeholder'=>'CommonArea(SqM)','onkeyup'=>'findCmnSquareFeet(this.value);findSquareRate();','onkeypress' => 'return isNumberKey(event)')); ?>  
                  <?php echo $form->error($model, 'cmn_area_sqm'); ?>   
        </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);findSquareRate();','onkeypress' => 'return isNumberKey(event)')); ?>    
                <?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);findSquareRate();','onkeypress' => 'return isNumberKey(event)')); ?>  
                  <?php echo $form->error($model, 'squaremetre'); ?>   
        </div> 
    </li>
    <li class="form-add col-sm-3">  
        <div class="icon-box fa-th-list material m1">  
                  <?php echo $form->textField($model, 'squarefeet_rate', array('placeholder'=>'Squarefeet Rate','onkeypress' => 'return isNumberKey(event)')); ?>                    
                      <?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(); ?>
<?php
$cs = Yii::app()->getClientScript();

$cs->registerScript("getExpectedDate",  "function getExpectedDate(){
    var construction_status=$('#Flat_construction_status').val();
    if(construction_status==2){
        $('#div_construction').show();
    }else{
        $('#div_construction').hide();
    }            
};", CClientScript::POS_HEAD);
?>
<script>
    $( document ).ready(function() {
    $('#Building_country,#Building_construction_status').multiselect({
                        enableClickableOptGroups: true,
                        enableCollapsibleOptGroups: true,
                        enableFiltering: true,
                        includeSelectAllOption: true,
                        enableCaseInsensitiveFiltering: true,
                    });
                });
</script>