<?php
  include('common/header.php');
  $country_name='';
  $country_code='';
  $country_id='';
  $std_code='';

?>
<?php 
if ($this->uri->segment(4)) {
   foreach ($country as  $value){
    $country_id=$value['country_id'];
    $country_name=$value['country_name'];
    $country_code=$value['country_code'];
    $std_code=$value['std_code'];
  }
}
 ?>
 <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">
          Country
          </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 COUNTRY;?>add_country"onsubmit="return validateForm()" id="manage_client">
                    <input type="hidden" value="<?php echo $country_id ?>" name="hidden" id="hidden">
                  <section class="panel panel-default">
                  <header class="panel-heading bg-info lt font-bold">Country 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" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required"><?php echo $cou_Country_Name; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                
                                <input type="text" name="country_name" value="<?php echo $country_name; ?>" id="country_name" placeholder="Country Name" class="form-control" maxlength="20" />
                              
                                <span id="country_name1" class="text-danger font-weight-bold"></span>
                                 <span><?php echo form_error('country_name'); ?></span>           
                              </div>
                            </div>
                            <p id="demo"></p>
                          </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 $cou_Country_Code; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                               
                                <input type="text" name="country_code" value="<?php echo $country_code; ?>" id="country_code" placeholder="Country Code" class="form-control" maxlength="3" />
                              
                                <span id="country_code1" class="text-danger font-weight-bold"></span> 
                                <span><?php echo form_error('country_code'); ?></span>          
                              </div>
                            </div>
                            <p id="demo"></p>
                          </div>
                        </div>
                            
                        <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"><?php echo $cou_STD_Code; ?>:<font style="color:red"></font></label>
                              <div class="col-sm-7">
                               
                                <input type="text" name="std_code" value="<?php echo $std_code; ?>" id="std_code"  placeholder="STD Code" class="form-control" maxlength="3" />
                              
                                <span id="std_code1" class="text-danger font-weight-bold"></span> 
                                <span><?php echo form_error('country_code'); ?></span>          
                              </div>
                            </div>
                            <p id="demo"></p>
                          </div>

                          <!-- <div class="col-sm-6">                            
                             <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required"><?php echo $cur_Currency_Name; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                
                                <select name="currency" id="currency">
                                    <option value="default">Select Currency Name</option>
                                     <?php  
                                          foreach ($currency as  $value1) {
                                           if ($currency_id == $value1['currency_id']) {?>
                                            <option value="<?php echo $value1['currency_id'] ?>"selected><?php echo $value1['currency_name'] ; ?></option>
                                            <?php
                                           }else{?>
                                           <option value="<?php echo $value1['currency_id'] ?>"><?php echo $value1['currency_name'] ; ?></option><?php 
                                          
                                          }
                                        }
                                         
                                      ?>
              
                                  </select> 
                                   <span id="currency1" class="text-danger font-weight-bold"></span>
                                   <span><?php echo form_error('currency'); ?></span>              
                              </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" id="ask">
        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(){
 
  $('#country_code').keyup(function()
  {
    var yourInput = $(this).val();
    re = /[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi;
    var isSplChar = re.test(yourInput);
    if(isSplChar)
    {
      var no_spl_char = yourInput.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
      $(this).val(no_spl_char);
    }
  });
 
});
 
    
function validateForm(){

  var error=false;  

  var country_name=$("#country_name").val();  
  if(country_name=='')
  {
    $("#country_name1").html("Please Enter Country Name");
    error=true; 
  }
  else if(!isNaN(country_name))
  {
    $("#country_name1").html("Only alphabets are allowed");
    error=true;      
  }else{
    $('#country_name1').html("");
  }

  //  var std_code=$("#std_code").val();  
  // if(std_code=='')
  // {
  //   $("#std_code1").html("Please Enter STD code");
  //   error=true; 
  // }
  // else if(isNaN(std_code))
  // {
  //   $("#std_code1").html("Only numbers are allowed");
  //   error=true;      
  // }else{
  //   $('#std_code1').html("");
  // }
  
  var country_code=$("#country_code").val();  
  if(country_code=='')
  {
    $("#country_code1").html("Please Enter Country Code");
    error=true; 
  }
  else if(!isNaN(country_code)){
    $("#country_code1").html("Only alphabets are allowed");
    error=true;
  }else
  {
    $('#country_code1').html("");
      
  }
  // var currency=$("#currency").val();  
  // if(currency=='default')
  // {
  //   $("#currency1").html("Select Currency Name");
  //   error=true; 
  // }
  // else
  // {
  //   $('#currency1').html("");
      
  // }
  var hidden=$("#hidden").val();  
  if(error==true)
  {
    return false;
  }
  else
  {
    if(hidden==''){
   var r = confirm("Are you sure you want to create Country!");
    if (r==true) {return true;}else{return false;} 
  }else{
    var r = confirm("Are you sure you want to Edit Country!");
    if (r==true) {return true;}else{return false;} 
  }
  }
}

 </script>
