<?php
  include('common/header.php');

?>
<?php 

  if ($this->uri->segment(4)) {
   foreach ($geography as  $value){
       $branch_salable_id=$value['branch_salable_geography_id'];
       $country_id=$value['country_ids'];
       $state_id=$value['state_ids'];
       $city_id=$value['city_ids'];
      // $stateid = implode(",",$state_id);
   }
  }
 ?>
<div id="messages" style="color: red;"><h5><?php echo $this->session->flashdata('message'); ?></h5></div>
<style>
  .autocomplete {
    position: relative;
   
  }
  .autocomplete-items {
   /* position: absolute;*/
    border: 1px solid #d4d4d4;
    border-bottom: none;
    border-top: none;
    z-index: 99;
    top: 100%;
    left: 0;
    right: 0;
  }
  .autocomplete-items div {
    padding: 10px;
    cursor: pointer;
    background-color: #fff; 
    border-bottom: 1px solid #d4d4d4; 
  }
  .autocomplete-items div:hover {
    background-color: #e9e9e9; 
  }
  .autocomplete-active {
    background-color: DodgerBlue !important; 
    color: #ffffff; 
  }
  </style>

  <div class="">
    <div class="col-xm-12">
      <div class="widget-box light-border">
        <!-- <div class="widget-header header-color-grey">
          <h4 class="smaller">
           
          </h4>
        </div> -->
        <div class="widget-body">
          <div class="widget-main">
            <div class="row">
              <div class="col-sm-12">
                  <form class="form-horizontal" method="post" action="<?php echo base_url()?>index.php/<?php echo GEOGRAPHY;?>add_geography" onsubmit="return validateForm()">

                    <input type="hidden" value="<?php echo $branch_salable_id ?>" name="hidden">
                  <section class="panel panel-default">
                  <header class="panel-heading bg-info lt font-bold">Branch Saleable Geography</header>
                  <!-- panel body start -->
                  <div class="panel-body bs-example form-horizontal">
                    <div class="">
                     <div class="hr hr12 dotted"></div>
                       <div class="">
                        <!-- main col-sm-12 -->
                      <div class="col-sm-12"> 
                           <div class="col-sm-6">
                            <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required">Saleable Geography Name:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                              
                                <input type="text" name="saleable_name" value="<?php echo $value['saleble_geography_name'];?>"maxlength="65" id="saleable_name" placeholder="Saleable Name" class="form-control"  />

                                  <span id="saleable_name1" class="text-danger font-weight-bold"></span>
                                  <?php echo form_error('saleable_name');?>             
                              </div>
                            </div>
                          </div>


                       <div class="col-sm-6">
                            <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required">Country:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <select name="country_name" id="country_name" onChange="" class="form-control">
                                   <option value="default">Select Country Name</option>
                                 <?php  
                                          foreach ($country  as  $value1) {
                                           if ($country_id == $value1['country_id']) {?>
                                            <option value="<?php echo $value1['country_id'] ?>"selected><?php echo $value1['country_name'] ; ?></option>

                                            <?php
                                           }else{?>
                                           <option value="<?php echo $value1['country_id'] ?>"><?php echo $value1['country_name'] ; ?></option><?php 
                                          
                                          }
                                        }
                                         
                                      ?>


                                </select> 
                                <span id="country1" class="text-danger font-weight-bold"></span>             
                              </div>
                            </div>
                          </div> 



                    </div>

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

                         <div class="col-sm-6">
                           <div class="form-group">
                            <label for="client_code" class="col-sm-5 control-label required">State Geography Name:<font style="color:red">*</font></label>
                              <div class="col-sm-7" id="state">
                                 <?php 

                                 if ($this->uri->segment(4)) {
                                     $state= fetch_states($state_id);
                                     //$stated = implode(",",$state);
                                      ?>
                                      <select class="js-example-basic-multiple" name="state[]" multiple="multiple" id="states" style="width: 250px;">

                                     <option value="<?php echo $state_id; ?>" selected ><?php echo $state; ?></option>

                                     </select> <?php }else{?> 
                              
                                     <select class="js-example-basic-multiple" name="state[]" multiple="multiple" id="states" style="width: 250px;">
                                     <!--  <option>Select State</option> -->

                                   
                                     </select><?php } ?>
                             
              
               
                              </div>  
                              <span id="state1" class="text-danger font-weight-bold"></span> 
                            </div>
                          </div>

                           <div class="col-sm-6">
                           <div class="form-group">
                            
                            <label for="client_code" class="col-sm-5 control-label required">City Geography Name:<font style="color:red">*</font></label>
                              <div class="col-sm-7" id="state">


                                 <?php 

                                 if ($this->uri->segment(4)) {
                                      
                                   
                                      ?>
                                <select class="js-example-basic-multiple" name="cities[]" multiple="multiple" id="city" style="width: 250px;">
										<?php fetch_cities($city_id); ?> 
                                   
                                </select><?php }else{?>
                                  <select class="js-example-basic-multiple" name="cities[]" multiple="multiple" id="city" style="width: 250px;">
										<?php fetch_cities($city_id); ?>
                                     </select><?php } ?>
                              </div>
                              <span id="city1" class="text-danger font-weight-bold"></span>
                            </div>
                          </div>
                        </div>



                           </div> 

                        
                    
                  </div>
                                                 
                      </div>

                       <!-- </div> -->
                         <!-- main col-sm-12  close-->
                       </div> <!-- blank close -->
        </div><!-- blank close -->
      </div>   <!-- panel body close -->
    </section> <!-- section close -->

              </div>
            </div>
          </div>  
        </div>
      </div>
    </div>
    
    <!-- /.col -->
  </div>
  <div class="clearfix form-actions">
    <div class="col-md-offset-5 col-md-5">
      
      <button class="btn btn-info" type="submit">
         Submit
      </button>
    </div>
  </div>
  </form>
  <div class="space-4"></div>
    <!-- /.page-row -->
        <!-- /.page-content --> 
    </div>
    <!-- /.main-content --> 
  </div>
    <!-- /#ace-settings-container --> 
  </div>
  <!-- /.main-container-inner --> 
<?php
  include('common/footer.php');
?>
<script>
function hide()
{
  document.getElementById("admin_type_code").style.display="none";
}
function show()
{
  document.getElementById("admin_type_code").style.display="";
}

$(document).ready(function(){
  $('#country_name').change(function(){
  var country_id = $('#country_name').val();
  if(country_id != '')
  {
   $.ajax({
    url:"<?php echo base_url();?>index.php/gc/geography/fetch_state",
    method:"POST",
   // / dataType: 'json',
    data:{
      country_id:country_id
    },

    success:function(data)
    {

      $('#states').html(data);

    }
   });
  }
  else
  {
   $('#states').html('<option value="">Select State</option>');
   //$('#city').html('<option value="">Select City</option>');
  }
 });

 $('#states').change(function(){
  var state_id = $('#states').val();
  if(state_id != '')
  {
   $.ajax({
    url:"<?php echo base_url();?>index.php/gc/geography/fetch_city",
    method:"POST",
    data:{
      state_id:state_id
    },
    success:function(data)
    {
     $('#city').html(data);
    }
   });
  }
  else
  {
   $('#city').html('<option value="">Select City</option>');
  }
 });

 });
 

</script>

<script type="text/javascript">
    function validateForm(){                                  
   
  var error=false;  
  var saleable_name=$("#saleable_name").val();  
  if(saleable_name=='')
  {
    $("#saleable_name1").html("Please Enter Branch Saleble Name");
    error=true; 
  }
  else if(!isNaN(saleable_name))
  {
    $("#saleable_name1").html("Only alphabets are allowed");
    error=true;      
  }else{
    $('#saleable_name1').html("");
  }
  
  var country_name=$("#country_name").val();  
  if(country_name=='default')
  {
    $("#country1").html("Please Select Country Name");
    error=true; 
  }
  else
  {
    $('#country1').html("");
      
  }

  var states=$("#states").val();  
  if(states=='default')
  {
    $("#state1").html("Select State Name");
    error=true; 
  }
  else
  {
    $('#state1').html("");
      
  }
  var city=$("#city").val();  
  if(city=='default')
  {
    $("#city1").html("Select City Name");
    error=true; 
  }
  else
  {
    $('#city1').html("");
      
  }
  if(error==true)
  {
    return false;
  }
  else
  {
  var r = confirm("Are you sure you want to Add Branch Saleble Geography!");
  if (r==true) {return true;}else{return false;} 
  }
      

    }
</script>
<script>
  $(document).ready(function(){
      
        $(".select2").select2();  
      $(".select2").prop("multiple", "multiple");
      
      /* var path='<?php echo base_url()?>index.php/<?php echo CUSTOMER_PATH;?>';
      auto_complete('<?php echo $company_id;?>',path,'company','company_list_id'); */

        });
</script>
<script>
$(document).ready(function() {
    $('.js-example-basic-multiple').select2();
});
</script>
