<style type="text/css">
body .modal {
	/* new custom width */
	width: 750px;
	/* must be half of the width, minus scrollbar on the left (30px) */
	margin-left: -375px;
}
</style>
<form role="form" class="form-horizontal" id="create_customer_form" action="#" method="post">
<input type="hidden" value="<?php echo $type;?>" name="type" id="type"/>
<input type="hidden" value="<?php echo $cus_id;?>" name="cus_id" id="cus_id"/>
<form role="form" class="form-horizontal" id="create_customer_form" action="#">
  <input name="cus_type" value="loan"  type="hidden"/>
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title"><?php echo $pageName ?></h4>
    <font style="color:#333;">Please fill in the information below. The field labels marked with * are required input fields.</font> </div>
  <div class="modal-body">
    <div id="error"></div>
    <div class="row">
      <div class="col-md-12">
        <div class="col-md-5">
          <div class="form-group">
            <h5>Name *</h5>
            <input type="text" class="form-control" name="cus_name" id="cus_name" <?php echo (isset($customer['cus_name']))?'value="'.$customer['cus_name'].'"':null;?>>
          </div>
          <div class="form-group">
            <h5>NIC *</h5>
            <input type="text" class="form-control" name="cus_nic" id="cus_nic" <?php echo (isset($customer['cus_nic']))?'value="'.$customer['cus_nic'].'"':null;?>>
          </div>
          <div class="form-group">
            <h5>Email Address </h5>
            <input type="text" class="form-control" name="cus_email" id="cus_email" <?php echo (isset($customer['cus_email']))?'value="'.$customer['cus_email'].'"':null;?>>
          </div>
          <div class="form-group">
            <h5>Address *</h5>
            <input type="text" class="form-control" name="cus_address" id="cus_address" <?php echo (isset($customer['cus_address']))?'value="'.$customer['cus_address'].'"':null;?>>
          </div>
        </div>
        <div class="col-md-5 pull-right">
          <div class="form-group">
            <h5>Mobile 01  *</h5>
            <input type="text" class="form-control" name="cus_mobile" id="cus_mobile" <?php echo (isset($customer['cus_mobile']))?'value="'.$customer['cus_mobile'].'"':null;?>>
          </div>
          <div class="form-group">
            <h5>Mobile 02</h5>
            <input type="text" class="form-control" name="cus_mobile_2" id="cus_mobile_2" <?php echo (isset($customer['cus_mobile_2']))?'value="'.$customer['cus_mobile_2'].'"':null;?>>
          </div>
          <div class="form-group">
            <h5>Home Phone 01 </h5>
            <input type="text" class="form-control" name="cus_home_phone" id="cus_home_phone" <?php echo (isset($customer['cus_home_phone']))?'value="'.$customer['cus_home_phone'].'"':null;?>>
          </div>
          <div class="form-group" style="display:none">
            <h5>Route </h5>
            <select  id="route_id" class="form-control" name="route_id"  >
              <option value="">- Please Select -</option>
              <?php 		
foreach ($routes_list as $row)
{?>
              <option  value="<?php echo $row['route_id'];?>"       
 <?php  if(isset($customer['route_id'])&& $row['route_id']==$customer['route_id'])echo 'selected="selected"'?>> <?php echo $row['route_name'];?> </option>
              <?php }
							  ?>
            </select>
          </div>
          <div class="form-group">
            <?php
				$ss_group_id=$this->session->userdata('ss_group_id');
				 if ($ss_group_id==2) {?>
            <h5>Warehouse</h5>
            <?php
				   
				   ?>
            <select id="warehouse_id_c" class="form-control" name="warehouse_id_c">
              <!--<option value="">-- Select Warehouse --</option>-->
              <?php 
				$ss_warehouse_id=$this->session->userdata('ss_warehouse_id'); 
                 foreach ($warehouse_list as $row)
                 {
				  $sel='';
					if(isset($customer['warehouse_id'])){
					if($customer['warehouse_id']==$row->id){
					$sel=' selected="selected"'; }
					}?>
                    
              <option <?php echo $sel?> value="<?php echo $row->id; ?>"> <?php echo $row->name; ?> </option>
              <?php }?>
            </select>
            <?php } else if($ss_group_id==3){
					
					?>
            <input name="warehouse_id_c" id="warehouse_id_c" type="hidden" value="<?php echo $this->session->userdata('ss_warehouse_id');?>">
            <?php }?>
          </div>
        </div>
      </div>
    </div>
    <!--col-md-12--> 
  </div>
  <div class="modal-footer">
    <input type="submit" name="add_category" value="<?php echo $btnText; ?>" class="btn btn-primary">
  </div>
</form>
<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY VALIDATION --> 
<script src="<?php echo asset_url(); ?>js/form-validation-create_customer.js"></script> 
<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY  VALIDATION--> 

<script>
jQuery(document).ready(function() {
FormValidator.init();
$("#country_id").select2();
});
		
function insertCustomerData(){
var type=$('#type').val();
var cus_id=$('#cus_id').val();
var country_id=$('#country_id').val();
var city_name=$('#city_name').val();	
var cus_name=$('#cus_name').val();
var cus_code=$('#cus_code').val();
var cus_email=$('#cus_email').val();
var cus_phone=$('#cus_phone').val();	
var cus_address=$('#cus_address').val();
var cus_state=$('#cus_state').val();
var cus_postal_code=$('#cus_postal_code').val();
var cus_mobile=$('#cus_mobile').val();
var cus_mobile_2=$('#cus_mobile_2').val();
var cus_home_phone=$('#cus_home_phone').val();
var warehouse_id_c=$('#warehouse_id_c').val();
var route_id=$('#route_id').val();
var cus_nic=$('#cus_nic').val();

				 
$.post( "<?php echo base_url();?>customers/save_customer", {type:type, cus_id:cus_id, country_id:country_id, city_name:city_name, cus_name:cus_name, cus_code:cus_code, cus_email:cus_email, cus_phone:cus_phone, cus_address:cus_address, cus_state:cus_state, cus_postal_code:cus_postal_code,cus_mobile:cus_mobile,cus_mobile_2:cus_mobile_2,cus_home_phone:cus_home_phone,warehouse_id_c:warehouse_id_c,cus_nic:cus_nic,route_id:route_id })
	  .done(function( data ) {
		
	  var obj = jQuery.parseJSON(data);
	 if (obj.status==0) 
	{
		$('div#error').html('<div class="alert alert-block alert-danger fade in"><button type="button" class="close" data-dismiss="alert">×</button><h4 class="alert-heading"><i class="fa fa-times-circle"></i> Error!</h4>'+obj.validation+'</div>');
		$('body').modalmanager('removeLoading');
		$('body').attr('class','');
	} else {
	  // alert(obj.type); //last id	  
	  $('div#ajax-modal').modal('hide'); 
		
	  if(obj.type=='E'){
		 displayNotice('page','Customer has been updated successfully!');		 
	  }
	  if(obj.type=='A'){
		displayNotice('page','Customer has been added successfully!')  ;
	
	  }		
	  
	  <?php if(isset($btn_id)){ ?>
	  	var data = {
			id: obj.id,
			text: $('#cus_name').val()
		};
		//var newOption = new Option(data.text, data.id, false, false);
		
		<?php if($btn_id=="cus_id"){ ?>
		$(".js-data-cus_id-ajax").select2('data', {id:obj.id, text:$('#cus_name').val()});		
		<?php } ?>
		<?php if($btn_id=="g_cus_id"){ ?>
		$(".js-data-g_cus_id-ajax").select2('data', {id:obj.id, text:$('#cus_name').val()});		
		<?php } ?>
		
		
		
		//$('#<?php //echo $btn_id ?>').append(newOption);
		//$('#<?php //echo $btn_id ?>').val(data.id).trigger('change');

	  
	  <?php } ?>  
	  //loadGrid();// load customer data	
	}	
	  });
return false;
}
    </script>