<!-- Main content -->
                <section class="content">

                    <!-- Small boxes (Stat box) -->
                    <div class="row">
				
						
                                <form role="form" action="<?php echo site_url('aqadmin/add_service');?>" method="post" enctype="multipart/form-data" id="myForm">
                       <div class="col-md-6">
                            <!-- general form elements -->
                            <div class="box box-primary">
                                <div class="box-header">
                                    <h3 class="box-title">
                                        <?php

                                        if(empty($service_row))
                                        {
                                            echo "Add Service";
                                        }
                                        else
                                        {
                                            echo "Edit Service";
                                        }
                                        ?>
                                    </h3>
                                </div><!-- /.box-header -->
                                <!-- form start -->
                                <?php 
   if($this->session->flashdata('success_msg')){?>
     <div style="color:green"><?php echo $this->session->flashdata('success_msg');?></div>    
    <?php  } ?>
                                    <div class="box-body">
                                    <div class="form-group">
                                            <label for="exampleInputEmail1">Service Type</label>
                                            <input type="text" name="service_type" class="form-control" placeholder="Service Type" value="<?php if(empty($service_row)) { echo set_value('service_type'); } else{ echo $service_row->service_type; } ?>" data-validation="required alphanumeric" data-validation-allowing=" " autocomplete="off">
                                            <?php if(form_error('service_type') != ""){?>     
     <div style="color:red"><?php echo "Enter Service Type.";?></div>
       <?php } ?> 
                                        </div>
                                        
                                    
          
										<div class="row" id="readroot">
										<div class="form-group" >
										
                                            <label for="exampleInputEmail1">Booking Type <a href="<?php echo site_url('aqadmin/add_booking');?>"><button class="btn btn-success btn-sm " type="button" value="Active" name="fname">Add more(1) booking type </button></a></label>
                                            
											<input type="text" name="booking_type" class="form-control" placeholder="Booking Type" value="<?php if(empty($service_row)) { echo set_value('booking_type'); } else{ echo $service_row->main_caption; } ?>" data-validation="required alphanumeric" data-validation-allowing=" " autocomplete="off">
                                            <?php if(form_error('booking_type') != ""){?>     
     <div style="color:red"><?php echo "Enter Booking Type.";?></div>
       <?php } ?> 
	   <a id="moreFields" class=" moreFields btn btn-sm btn-primary waves-effect waves-light">Add Row</a>
	   
	    
                                        </div>
										 </div>
								<div class="row" id="writeroot"></div>		
										
          
                                        
                                    </div><!-- /.box-body -->
<div class="box-footer">
    <input type="hidden" name="id" value="<?php if(!empty($service_row)) { echo $service_row->id; } ?>">
                                        <button type="submit" class="btn btn-primary">Submit</button>
                                    </div>
                                    
                                
                            </div><!-- /.box -->

                            

                        
                    
                        </div>
                         
                               
                              
                                    
                                    
                                </form>
                            </div><!-- /.box -->

                            

                        </div>
                    
                        </div>
                    </div><!-- /.row -->

                    <!-- top row -->

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
        <script>
        var counter = 0;

//document.getElementById('moreFields').onclick = moreFields;

window.onload = loadEventListener();

function loadEventListener() {
  let addRowAnchorTags = document.getElementsByClassName('moreFields');

  for(i=0;i<addRowAnchorTags.length; i++) {
      addRowAnchorTags[i].onclick = moreFields;
  }
}

function moreFields() {
  counter++;
  var newFields = document.getElementById('readroot').cloneNode(true);
  newFields.id = '';
  newFields.style.display = 'row';
  var newField = newFields.childNodes;
  for (var i = 0; i < newField.length; i++) {
    var theName = newField[i].name
    if (theName)
      newField[i].name = theName + counter;
  }
  var insertHere = document.getElementById('writeroot');
  insertHere.parentNode.insertBefore(newFields, insertHere);
  setTimeout(function() {loadEventListener();})
}




        $(window).on("beforeunload", function() {
            return "Are you sure? You didn't finish the form!";
        });
        
        $(document).ready(function() {
            $("#myForm").on("submit", function(e) {
                
                $(window).off("beforeunload");
                return true;
            });
        });
        </script>             
                                        
                     
                    
                    
