<?php
  include('common/header.php');
  $currency_name='';
  $currency_code='';
  $currency_id='';
  $country_id='';
  $cur_Currency_Name = $this->_page_data['cur_Currency_Name'];
  $ci_Currency_Code = $this->_page_data['ci_Currency_Code'];
?>
<?php 
   if ($this->uri->segment(4)) {
   foreach ($currency as  $value){
    $currency_id=$value['currency_id'];
    $currency_name=$value['currency_name'];
    $currency_code=$value['currency_code'];
    $country_id=$value['country_id'];
   }
 }

 ?>
<!--  -->
 <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-body">
          <div class="widget-main">
            <div class="row">
              <div class="col-sm-12">  
                    <form class="form-horizontal" name="myForm" method="post" action="<?php echo base_url()?>index.php/<?php echo CURRENCY;?>add_currency" onsubmit="return validateForm()"  id="manage_currency">
                      <input type="hidden" value="<?php echo $currency_id ?>" name="hidden" id="hidden">
                  <section class="panel panel-default">
                  <header class="panel-heading bg-info lt font-bold">Currency 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="qc_name">
                            <label for="qc_name" class="col-sm-5 control-label required"><?php echo 'Country Name'; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">                             
                                <select name="country_id" id="country_id" class="form-control" >
                                 <option value="default">Select Country Name</option> 
                                          <?php  
                                          foreach ($country as  $co) {?>                                  
                                            <option value="<?php echo $co['country_id'];?>" <?php if ($co['country_id']==$country_id) {
                                             echo 'selected="selected"';
                                            } ?>><?php echo $co['country_name'] ; ?></option> <?php } ?> 
                                              
                                </select>  
                              <span id="country1" 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 $cur_Currency_Name; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                              
                                  <input type="text" name="currency_name" value="<?php echo $currency_name; ?>" id="currency_name" placeholder="Currency Name" class="form-control" maxlength="20"  /> 
                              <span id="currency_name1" class="text-danger font-weight-bold"></span>
                             <span><?php echo form_error('currency_name'); ?></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 $ci_Currency_Code; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                
                                <input type="text" name="currency_code" value="<?php echo $currency_code; ?>" id="currency_code" placeholder="Currency Code" class="form-control" maxlength="3" />
                                <!-- <span style="color: red;" ><?php echo form_error('currency_code');?></span> -->
                                <span id="currency_code1" class="text-danger font-weight-bold"></span>
                                <span><?php echo form_error('currency_code');?></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">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 currency_name=$("#currency_name").val();  
  if(currency_name=='')
  {
    $("#currency_name1").html("Please Enter Currency Name");
    error=true; 
  }
  else if(!isNaN(currency_name))
  {
    $("#currency_name1").html("Only alphabets are allowed");
    error=true;      
  }else{
    $('#currency_name1').html("");
  }
  
  var currency_code=$("#currency_code").val();  
  if(currency_code=='')
  {
    $("#currency_code1").html("Please Enter Currency Code");
    error=true; 
  }
  else if(!isNaN(currency_code)){
    $("#currency_code1").html("Only alphabets are allowed");
    error=true;
  }else
  {
    $('#currency_code1').html("");
      
  }
   var country_id=$("#country_id").val();  
  if(country_id=='default')
  {
    $("#country1").html("Please Select Country Name");
    error=true; 
  }
  else
  {
    $('#country1').html("");
      
  }
  
  var hidden=$("#hidden").val();  
  if(error==true)
  {
    return false;
  }
  else
  {
    if(hidden==''){
      var r = confirm("Are you sure you want to create Currency!");
      if (r==true) {return true;}else{return false;} 
    }else{
      var r = confirm("Are you sure you want to Edit Currency!");
      if (r==true) {return true;}else{return false;} 
    }
  
  }

}

  </script>