<?php
  include('common/header.php');
  $state_name='';
  $state_id='';
  $country_id='';
?>
<?php 
if ($this->uri->segment(4)) {
   foreach ($state as  $value1){
    $state_id=$value1['state_id'];
    $country_id=$value1['country_id'];
    $state_name = $value1['state_name'];

   }
 }
 ?>
<div id="messages" style="color: red;"><h5><?php echo $this->session->flashdata('message'); ?></h5></div>
  <div class="">
    <div class="col-xm-12">
      <div class="widget-box light-border">
        <!-- <div class="widget-header header-color-grey">
          <h4 class="smaller">
            State
          </h4>
        </div> -->
        <div class="widget-body">
          <div class="widget-main">
            <div class="row">
              <div class="col-sm-12">
                   <form class="form-horizontal" onsubmit="return validateForm()" method="post"  action="<?php echo base_url()?>index.php/<?php echo STATE;?>add_state" onsubmit="return validateForm()"  name="manage_client" id="manage_client">

                   <input type="hidden" value="<?php echo $state_id ?>" name="hidden" id="hidden">
              <section class="panel panel-default">
                  <header class="panel-heading bg-info lt font-bold">State Details</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">
                             <label for="client_code" class="col-sm-5 control-label required"> <?php echo $st_country; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                 
                                <select name="country_name" id="country_name" class="form-control" required>
                                    <option value="default">Select Country Name</option>
                                     <?php  
                                          foreach ($country as  $value) {
                                           if ($country_id == $value['country_id']) {?>
                                            <option value="<?php echo $value['country_id'] ?>"selected><?php echo $value['country_name'] ; ?></option>
                                            <?php
                                           }else{?>
                                           <option value="<?php echo $value['country_id'] ?>"><?php echo $value['country_name'] ; ?></option><?php 
                                          
                                          }
                                        }
                                         
                                      ?>
              
                                  </select>  
                                  <span id="country_name1" class="text-danger font-weight-bold"></span>        
                              </div>
                            </div>
                          </div>
                        

                          <div class="col-sm-6">
                           <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required"><?php echo  $st_State_Name; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                  <input type="text" name="state_name" value="<?php echo $state_name ?>" id="state_name" maxlength="45" placeholder="State Name" class="form-control"  />  

                                    <span id="state_name1" class="text-danger font-weight-bold"></span>
                                    <span><?php echo form_error('state_name'); ?></span> 
                                         
                              </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 type="text/javascript">
    
function validateForm(){

  var error=false;  

  var country_name=$("#country_name").val();  
  if(country_name=='default')
  {
    $("#country_name1").html("Please Select Country Name");
    error=true; 
  }
  else
  {
    $('#country_name1').html("");
      
  }

  var state_name=$("#state_name").val();  
  if(state_name=='')
  {
    $("#state_name1").html("Please Enter State Name");
    error=true; 
  }
  else if(!isNaN(state_name))
  {
    $("#state_name1").html("Only alphabets are allowed");
    error=true;      
  }else{
    $('#state_name1').html("");
  }
  var hidden=$("#hidden").val();  
  if(error==true)
  {
    return false;
  }
  else
  {
     if(hidden==''){
      var r = confirm("Are you sure you want to create State!");
      if (r==true) {return true;}else{return false;} 
    }else{
      var r = confirm("Are you sure you want to Edit State!");
      if (r==true) {return true;}else{return false;} 
    }
  }
}
</script>