<?php
$login_user_id    = Yii::app()->user->id;
$user_modal       = User::model()->find(array('condition'=>'t.id="'.$login_user_id.'"'));
$user_company     = $user_modal->company_id;
$modalMasCompany  = MasCompany::model()->find(array('condition'=>'t.id="'.$user_company.'"'));
if($modalMasCompany->billing_address !=''){
    $address   = $modalMasCompany->billing_address;
}
$masCompanyAddress = $address;
?>

<ul class="clearfix form-ul material">
    <li class="col-sm-6">
    <?php
    /*if($model->vendor_address == ''){
        $vendor_address  = $masCompanyAddress;
    }
    else{
        $vendor_address = $model->vendor_address;
    }*/
    ?>
    
        <?php echo $form->textArea($model, 'vendor_address', array('class' => 'tooltipster en-text-area', 'title' => 'Please enter address','data-label'=>'Address','onkeyup' => 'copyAddress()')); ?>
        <?php echo $form->error($model, 'vendor_address'); ?>
    </li>
    <li class="col-sm-6">
    <?php
    /*if($model->vendor_city == ''){
        $vendor_city  = $modalMasCompany->billing_city;
    }
    else{
        $vendor_city = $model->vendor_city;
    }*/
    ?>
        <?php echo $form->textField($model, 'vendor_city', array('class' => 'tooltipster', 'title' => 'Please enter City/Area','data-label'=>'City ','onkeyup' => 'copyAddress()')); ?>
        <?php echo $form->error($model, 'vendor_city'); ?>
    </li>
    <li class="col-sm-6">
    <?php
    /*if($model->vendor_state == ''){
        $billing_state  = $modalMasCompany->billing_state;
    }
    else{
        $billing_state = $model->vendor_state;
    }*/
    ?>
      
        <?php echo $form->textField($model, 'vendor_state', array('class' => 'tooltipster', 'title' => 'Please enter State/Province','data-label'=>'State ','onkeyup' => 'copyAddress()')); ?>
        <?php echo $form->error($model, 'vendor_state'); ?>
    </li>
    <li class="col-sm-6">
    <?php
    if($model->vendor_country == ''){
        $billing_country  = $modalMasCompany->billing_country;
    }
    else{
        $billing_country  = $model->vendor_country;
    }
    $option=  array($billing_country=>array('selected'=>'selected'));
    ?>
          <?php if(isset(Yii::app()->user->havePermissionOn['master_country_add']) || Yii::app()->user->authorised_user == 1 ){ ?>
                      <div class="new-cst">
                            <div class="toggle-cst"><span class="cst-btn">+</span>
                            <div class="content-cst">
                                <div class="head" ripple="ripple" ripple-color="#FFF">
                                  <h5>Add Country</h5>
                              </div>
                              <div class="body">
                                    <div class="row">
                                      <div class="col-sm-6">
                                        <?php echo CHtml::textField('country_name','',array('data-label'=>'Name <span style="color:red;">*</span>')); ?>
                                      </div>
                                       <div class="col-sm-6">
                                        <?php echo CHtml::textField('country_code','',array('data-label'=>'Code <span style="color:red;">*</span>')); ?>
                                      </div>
                                    </div>
                                    <div class="btn-wrap text-center">
                                        <a href="#" class="plan-add-btn btn btn-theme go" onclick="AddMaster('vendor','country')">SAVE</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                      </div>
                     <?php } ?>
          <div id="vendor_country_div">
              <?php echo $form->dropDownList($model, 'vendor_country', MasCountry::getCountry(), array('class' => '', 'prompt' => 'Select', 'title' => 'Select Country','data-label'=>'Country <span style="color:red;">*</span>','options' => $option,'value' => $country,'onChange' => 'copyAddress(); getEmiratesList(this.value);')); ?>
          </div>
    </li>
     <?php
      $style = "none";
      if (empty($model->id)) {
          $style = "";
      } else if ($model->vendor_country == '143') {
          $style = "";
      }
      ?>    
  <!-- <li class="col-sm-6" id="emirate_li" style="display : <?php echo $style; ?>">        
        <?php
          //  if(empty($model->id)){
          //  $model->vendor_emirates_name = MasEmiratesList::getDefault();
           // }
           // echo $form->dropDownList($model, 'vendor_emirates_name', MasEmiratesList::getEmiratesList('143'), array('class' => '','data-label' => 'Emirates'));
      ?>        
  
   </li>-->
    <li class="col-sm-6">
    <?php
    /*if($model->vendor_postal_code == ''){
        $vendor_postal_code  = $modalMasCompany->billing_postalcode;
    }
    else{
        $vendor_postal_code = $model->vendor_postal_code;
    }*/
    ?>
        <?php echo $form->textField($model, 'vendor_postal_code', array('class' => 'tooltipster', 'title' => 'Please enter post code','data-label'=>'P.O Box ','onkeyup' => 'copyAddress()')); ?>
        <?php echo $form->error($model, 'vendor_postal_code'); ?>
    </li>
</ul>
<?php 
$cs = Yii::app()->getClientScript();
$cs->registerScript("copyAddress", "function copyAddress()
        {
            var vendor = $('#Vendor_id').val();
            if(vendor  == ''){
                var adds = $('#Vendor_vendor_address').val();
                var city = $('#Vendor_vendor_city').val();
                var state = $('#Vendor_vendor_state').val();
                var pin = $('#Vendor_vendor_postal_code').val();
                var country = $('#Vendor_vendor_country').val();
                
                  for(i =0; i< 20 ; i++){
                        $('#VendorShippingDetails_'+i+'_street_address').val(adds);
                        $('#VendorShippingDetails_'+i+'_po_box').val(pin);
                        $('#VendorShippingDetails_'+i+'_city').val(city);
                        $('#VendorShippingDetails_'+i+'_state').val(state);
                        try{
                            document.getElementById('VendorShippingDetails_'+i+'_country_id').value = country;
                        }catch(e){}
                    }
            }
       
        
    }", CClientScript::POS_HEAD);
 $cs->registerScript("getEmiratesList", "function getEmiratesList(value)        
    {                        
        if(value  == '143'){                
            $('#emirate_li').show();            
        }            
        else{                
            $('#emirate_li').hide();            
        }                   
    }", CClientScript::POS_HEAD);