		<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;
			}
			.select_cus_btn{
				    /* float: right; */
    margin-top: -6px;
    background-color: white;
    padding: 5px;
    margin-top: 14px;
    width: 140px;
    cursor: pointer;
    border-radius: 5px;
	font-weight:bolder;
	text-align:center;
			}
			.form-group {
  margin-bottom: 3px;
}
			</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"/>
<input type="hidden" value="<?php echo $addtype;?>" name="addtype" id="addtype"/>
<form role="form" class="form-horizontal" id="create_customer_form" action="#">

<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" style="display:none">
                        <h5>NIC No </h5>
                            <input type="text" class="form-control" name="cus_code" id="cus_code" <?php echo (isset($customer['cus_code']))?'value="'.$customer['cus_code'].'"':null;?> <?php if (isset($type)) if($type=='E') echo 'readonly';?>>
                       </div>
                       <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>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 class="form-group">
                        <h5>Customer Type * </h5>
                        <?php 
						$sel_ig='';
						$sel_ic='';
						$dis_ig='';
						$dis_ic='';
						if(isset($clickButton)){
							if($clickButton=='guaranter1' || $clickButton=='guaranter2'){
				$sel_ig='selected="selected"';	
					$dis_ig='disabled';		
								}
							else if($clickButton=='customer'){
				$sel_ic='selected="selected"';	
					$dis_ic='disabled';		
								}
								else{
									$sel_ig='';
									$dis_ig='';
									$sel_ic='';
									$dis_ic='';
									}
							}
							
						$dis_ic='';	
						
						//echo $customer['cus_type'];
						?>
                        
                            <select class="select2-container form-control" id="cus_type" name="cus_type" <?php echo $dis_ig; echo $dis_ic;?>>
                                <!-- 
                            <option value="">-- Select Customer Type--</option> -->                          
                             <?php
							            $sel_g='';
										$sel_w='';
										$sel_h='';
										$sel_n='';
										
							  if(isset($customer['cus_type'])){if($customer['cus_type']=='Guaranteer'){
								$sel_g='selected="selected"';
								}else if($customer['cus_type']=='Wholesale'){
									$sel_w='selected="selected"';
									}
								else if($customer['cus_type']=='Service'){
									$sel_h='selected="selected"';
									}
								else if($customer['cus_type']=='Normal'){
									$sel_n='selected="selected"';
									}else{
										$sel_g='';
										$sel_w='';
										
										$sel_n='';
										}
										
										
							 }else{
								$sel_h='selected="selected"'; 
							 }
							
							 
							 
							 ?>
                              <option value="Service"<?php echo $sel_h;?>>Service</option>
                         <!-- <option value="Guaranteer"<?php echo $sel_g; echo $sel_ig;?> >Guaranteer</option>-->
						 <!-- <option value="Wholesale" <?php echo $sel_w;?>>Wholesale</option>
                         
                          <option value="Normal" <?php echo $sel_n;?>>Normal</option>
                          -->
                           </select>
                        </div>
                       <!-- <div class="form-group">
                        <h5>Credit Limit</h5>
                       
                            <input type="text" class="form-control" name="cus_credit_limit" id="cus_credit_limit" <?php echo (isset($customer['cus_credit_limit']))?'value="'.$customer['cus_credit_limit'].'"':'0';?>>
                        </div>-->
                        
                      
                       
                       
                    </div>
                       
                    <div class="col-md-5 pull-right">
                     <div class="form-group">
                       <h5>Mobile Phone No</h5>
                      
                            <input type="text" class="form-control" name="cus_phone" id="cus_m_phone" <?php echo (isset($customer['cus_phone']))?'value="'.$customer['cus_phone'].'"':null;?>>
                        </div>
                     
                         <div class="form-group" style="display:none">
                      <h5>Home Phone No *</h5>
                      
                            <input type="text" class="form-control" name="cus_h_phone" id="cus_h_phone" <?php echo (isset($customer['cus_h_phone']))?'value="'.$customer['cus_h_phone'].'"':null;?>>
                        </div>
                         <div class="form-group" style="display:none">
                     <h5>Office Phone No</h5>
                      
                            <input type="text" class="form-control" name="cus_o_phone" id="cus_o_phone" <?php echo (isset($customer['cus_o_phone']))?'value="'.$customer['cus_o_phone'].'"':null;?> >
                        </div>
                        <div class="form-group" style="display:none">
                        <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>City </h5>
                      
                            <input type="text" class="form-control" name="city_name" id="city_name" <?php echo (isset($customer['city_name']))?'value="'.$customer['city_name'].'"':null;?>>
                        </div>
                        <div class="form-group">
                        <h5>State </h5>
                       
                            <input type="text" class="form-control" name="cus_state" id="cus_state" <?php echo (isset($customer['cus_state']))?'value="'.$customer['cus_state'].'"':null;?>>
                       </div>-->
                     <!--  <div class="form-group">
                        <h5>Postal Code </h5>
                        
                            <input type="text" class="form-control" name="cus_postal_code" id="cus_postal_code" <?php echo (isset($customer['cus_postal_code']))?'value="'.$customer['cus_postal_code'].'"':null;?>>
                        </div>-->
                        <!--<div class="form-group">
                        <h5>Country </h5>
                        
                            <select class="select2-container form-control search-select" id="country_id" name="country_id">
                            <option value="">-- Select Country --</option>
							<?php 
                            foreach ($country_list as $row)
                            {
								$sel='';
								$seldef='';
								if(isset($customer['country_id'])){
									if($customer['country_id']==$row['country_id']){
										$sel=' selected="selected"';
									}
								}else if($row['country_id']==251){
									$seldef=' selected="selected"';
								}
                            ?>       
                                <option<?php echo $sel;?><?php echo $seldef ?> value="<?php echo $row['country_id'];?>"><?php echo $row['country_short_name']; ?></option>
                             <?php }  ?>
                             </select>
                        </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();
			});
		</script>
        
        <input name="tmp_cus_name" id="tmp_cus_name" type="hidden" value=""/>
<script type="text/javascript">

function set_val(id,name){
	//alert(id+name);
		var app = $("<option/>",{value:id , text: name});
		//alert(id+name);
           $('#customer_id').append(app);
			$('#customer_id').select2("val", id).trigger('change');
			//});
}


function select_customer(cus_id){
	//alert(cus_id);
	var name=$("#tmp_cus_name").val();
	$("#tmp_cus_name").val('');
	//alert(name);
	set_val(cus_id,name);
	  $('div#ajax-modal').modal('hide');
}

function check_customer_allready_exists(){
	var fld='#cus_bill_no';
	var nic=$("#cus_code").val();
	var cus_m_phone=$("#cus_m_phone").val();
	var cus_h_phone=$("#cus_h_phone").val();
	var cus_o_phone=$("#cus_o_phone").val();
	$.post( "<?php echo base_url();?>sales/check_customer_allready_exists", {nic:nic,cus_m_phone:cus_m_phone,cus_h_phone:cus_h_phone,cus_o_phone:cus_o_phone})
	.done(function( data ) {
		var obj = $.parseJSON(data);
		if (obj.status) 
		{
			var msg='';
			$("#tmp_cus_name").val(obj.cus_name);
			msg=msg+'<p>Customer already registered</p>';
			msg=msg+'<p>Customer Name: '+obj.cus_name+'</p>';
			msg=msg+'<p>Customer NIC: '+obj.nic+'</p>';
			msg=msg+'<p>Mobile Phone No: '+obj.cus_m_phone+'</p>';
			msg=msg+'<p>Home Phone No: '+obj.cus_h_phone+'</p>';
			msg=msg+'<p>Office Phone No: '+obj.cus_o_phone+'</p>';
			msg=msg+'<p class="select_cus_btn" onclick="select_customer('+obj.cus_id+')">Select Customer </p>';
			
			$('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>'+msg+'</div>');
			
			displayNotice('Error','Customer already registered:');
			$(fld).val('');
		}
	});
return false;
}

function insertCustomerData(){
	//alert(1);
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_m_phone=$('#cus_m_phone').val();	
var cus_o_phone=$('#cus_o_phone').val();
var cus_h_phone=$('#cus_h_phone').val();	
var cus_address=$('#cus_address').val();
var cus_state=$('#cus_state').val();
var cus_postal_code=$('#cus_postal_code').val();
var cus_credit_limit=$('#cus_credit_limit').val();
var cus_type=$('#cus_type').val();
				 
	$.post( "<?php echo base_url('customers/save_customer_ser'); ?>", {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_m_phone:cus_m_phone,cus_o_phone:cus_o_phone,cus_h_phone:cus_h_phone,cus_type:cus_type,cus_address:cus_address, cus_state:cus_state, cus_postal_code:cus_postal_code,cus_credit_limit:cus_credit_limit })
	  .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');
	 // // load customer data
	  
	  if(obj.type=='E'){
		 displayNotice('page','Customer has been updated successfully!');
	  }
	  if(obj.type=='A'){
		displayNotice('page','Customer has been added successfully!')  ;
	  }
	  
	  $('.js-data-customer_id-ajax').select2('data', {id: obj.cus_id, text: obj.cus_name});
	  
	  	// alert(obj.cus_id);
		 
		// var app = $("<option/>",{value:obj.cus_id , text: obj.cus_name});
         //   $('#service_customer_id').append(app);
		//	$('#service_customer_id').select2("val", obj.cus_id).trigger('change');
		 
		 
	  if($('#addtype').val()=='ins'){
		var icus_id =cus_id;
		var refCus1=<?php echo $refCus1;?>;
		var refCus2=<?php echo $refCus2;?>;
		var clickButton='<?php echo $clickButton;?>';
		var termtype='<?php echo $termtype;?>';
		var sendUrl='';
		if(clickButton=='customer'){
		if(icus_id == 0){	
			//sendUrl='sales2/add_sales/'+obj.cus_id+'/'+refCus1+'/'+refCus2+'/'+termtype;
		}else{
			//sendUrl='sales2/add_sales/'+icus_id+'/'+refCus1+'/'+refCus2+'/'+termtype;	
			}
			
			 
	  		var app = $("<option/>",{value:obj.cus_id , text: obj.cus_name});
            $('#service_customer_id').append(app);
			$('#service_customer_id').select2("val", obj.cus_id).trigger('change');
			
		//	alert(obj.cus_name);
	  		
			//$('div#ajax-modal').modal('hide');
			
		}
		if(clickButton=='guaranter1'){
		if(refCus1 == 0){	
		sendUrl='sales2/add_sales/'+icus_id+'/'+obj.cus_id+'/'+refCus2+'/'+termtype;
		}else{
		sendUrl='sales2/add_sales/'+icus_id+'/'+refCus1+'/'+refCus2+'/'+termtype;	
			}
			window.location.href = "<?php echo base_url();?>"+sendUrl;
		}
		if(clickButton=='guaranter2'){
		if(refCus2 == 0){	
		sendUrl='sales2/add_sales/'+icus_id+'/'+refCus1+'/'+obj.cus_id+'/'+termtype;
		}else{
		sendUrl='sales2/add_sales/'+icus_id+'/'+refCus1+'/'+refCus2+'/'+termtype;	
			}
			window.location.href = "<?php echo base_url();?>"+sendUrl;
		}
		
		
		
		
		
		
		  }		
	//loadGrid();
	}
	  

	  });
return false;
}
    </script>