		<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_supplier_form" action="#" method="post">
<input type="hidden" value="<?php echo $type;?>" name="type" id="type"/>
<input type="hidden" value="<?php echo $supp_id;?>" name="supp_id" id="supp_id"/>
<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>
                        <label class="control-label">
							Code *
						</label></h5>
                        <?php
							$ref_id = new Common_Model();
							$reference_no = $ref_id->gen_ref_number('supp_id','supplier','SP');
							?>
                            <input type="text" <?php echo (isset($suppliyer['supp_code']))?'value="'.$suppliyer['supp_code'].'"':'value="'.$reference_no.'"';?> class="form-control" name="supp_code" id="supp_code" <?php if (isset($type)) if($type=='E') echo 'readonly';?>>
                       
                    </div>
                    
                    <div class="form-group">
                        <h5>
                        <label class="control-label">
							Company Name*
						</label></h5>
                        
                            <input type="text" <?php echo (isset($suppliyer['supp_company_name']))?'value="'.$suppliyer['supp_company_name'].'"':null;?> class="form-control" name="supp_company_name" id="supp_company_name">
                       
                    </div>
                    <div class="form-group">
  						 <h5>Address </h5>
                        
                            <input type="text" <?php echo (isset($suppliyer['supp_address']))?'value="'.$suppliyer['supp_address'].'"':null;?>  class="form-control" name="supp_address" id="supp_address">
                      
                    </div>
                    <div class="form-group">
						<h5>Company Phone </h5>
                       
                            <input type="text" <?php echo (isset($suppliyer['supp_company_phone']))?'value="'.$suppliyer['supp_company_phone'].'"':null;?>  class="form-control" name="supp_company_phone" id="supp_company_phone">
                        
                        </div>
                        <div class="form-group">
 					<h5>Country *</h5>

                            <select class="select2-container form-control search-select" id="country_id" name="country_id">
                            <option value="">&nbsp;</option>
							<?php 
                            foreach ($country_list as $row)
                            {
								$sel='';
								if(isset($suppliyer['country_id'])){
									if($suppliyer['country_id']==$row['country_id']){
										$sel=' selected="selected"';
									}
								}else if(251==$row['country_id']){
										$sel=' selected="selected"';
									}
                            ?>       
                                <option<?php echo $sel;?> value="<?php echo $row['country_id'];?>"><?php echo $row['country_short_name']; ?></option>
                             <?php }  ?>
                             </select>
                        </div>
                        <div class="form-group">
                        <h5>City </h5>
                       <div id="city_data">
                            <!--<input type="text" <?php echo (isset($suppliyer['supp_city']))?'value="'.$suppliyer['supp_city'].'"':null;?>  class="form-control" name="supp_city" id="supp_city">-->
                            <select name="" id="supp_city">
                            <option id="1">1</option>
                            <option id="1">1</option>
                            </select>
                      </div>
                        </div>
                        <div class="form-group">
                        <h5>State </h5>
                       
                            <input type="text" <?php echo (isset($suppliyer['supp_state']))?'value="'.$suppliyer['supp_state'].'"':null;?> class="form-control" name="supp_state" id="supp_state">
                       
                        </div>
                        <div class="form-group">
                        <h5>Postal Code </h5>
                       
                            <input type="text" <?php echo (isset($suppliyer['supp_postal_code']))?'value="'.$suppliyer['supp_postal_code'].'"':null;?>  class="form-control" name="supp_postal_code" id="supp_postal_code">
                        
                        </div>
                        
                        <div class="form-group">
                         <h5>Fax </h5>
                            <input type="text" <?php echo (isset($suppliyer['supp_fax']))?'value="'.$suppliyer['supp_fax'].'"':null;?>  class="form-control" name="supp_fax" id="supp_fax">
                        </div>
                        
                        
                    </div>
                    <div class="col-md-5 pull-right">
                    <div class="form-group">
                        <h5>Email Address </h5>
                            <input type="text" <?php echo (isset($suppliyer['supp_email']))?'value="'.$suppliyer['supp_email'].'"':null;?>  class="form-control" name="supp_email" id="supp_email">
    				</div>
                    <div class="form-group">
                     <h5>Credit Limit </h5>
                            <select class="form-control" id="cr_limit_id" name="cr_limit_id">
                            <option value="">&nbsp;</option>
							<?php 
                            foreach ($cr_limit_list as $row)
                            {
								$sel='';
								if(isset($suppliyer['cr_limit_id'])){
									if($suppliyer['cr_limit_id']==$row->cr_limit_id){
										$sel=' selected="selected"';
									}
								}
                            ?>       
                                
                                <option<?php echo $sel;?> value="<?php echo $row->cr_limit_id; ?>"><?php echo $row->cr_limit_name; ?></option>
                             <?php }  ?>
                             </select>
                        
                            </div>
                            <div class="form-group">            
                        <h5>Bank </h5>
                        
                            <input type="text" <?php echo (isset($suppliyer['supp_bank']))?'value="'.$suppliyer['supp_bank'].'"':null;?>  class="form-control" name="supp_bank" id="supp_bank">
                      
                        </div>
                        <div class="form-group">
                         <h5>Branch </h5>
                       
                            <input type="text" <?php echo (isset($suppliyer['supp_bank_branch']))?'value="'.$suppliyer['supp_bank_branch'].'"':null;?>  class="form-control" name="supp_bank_branch" id="supp_bank_branch">
                        
                        </div>
                        <div class="form-group">
                         <h5>Account Number  </h5>
                       
                            <input type="text" <?php echo (isset($suppliyer['supp_account_number']))?'value="'.$suppliyer['supp_account_number'].'"':null;?>  class="form-control" name="supp_account_number" id="supp_account_number">
                       
                        </div>
                        <div class="form-group">
                          <h5>Credit Period </h5>
                      
                            <input type="text" <?php echo (isset($suppliyer['supp_credit_period']))?'value="'.$suppliyer['supp_credit_period'].'"':null;?>  class="form-control" name="supp_credit_period" id="supp_credit_period">
                       
                        </div>
                        <div class="form-group">
                         <h5>Contact Person Name </h5>
                       
                            <input type="text" <?php echo (isset($suppliyer['supp_contact_person_name']))?'value="'.$suppliyer['supp_contact_person_name'].'"':null;?> class="form-control" name="supp_contact_person_name" id="supp_contact_person_name">
                       
                        </div>
                        <div class="form-group">  
                         <h5>Contact Person Phone </h5>
                        
                            <input type="text" <?php echo (isset($suppliyer['supp_contact_person_phone']))?'value="'.$suppliyer['supp_contact_person_phone'].'"':null;?>  class="form-control" name="supp_contact_person_phone" id="supp_contact_person_phone">
                       
                        </div>
                        <div class="form-group">
                         <h5>Contact Person Email </h5>
                        
                            <input type="text" <?php echo (isset($suppliyer['supp_contact_person_email']))?'value="'.$suppliyer['supp_contact_person_email'].'"':null;?>  class="form-control" name="supp_contact_person_email" id="supp_contact_person_email">
                        
                        </div>                     
                    </div>
                </div>
            </div>
            <div class="modal-footer">
            <input type="submit" name="add_category" value="<?php echo $btnText; ?>" class="btn btn-primary">
            </div>
            </div> <!--/.col-md-12-->
</form>
 		<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY VALIDATION-->
		<script src="<?php echo asset_url(); ?>js/form-validation-create_supplier.js"></script>
		<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY  VALIDATION-->
        

                        
		<script>
			$('select#country_id').on('change', function(){
				var country_id = $(this).val();
				getCityListByCountryID(country_id,0);
			});		
		
	
	function getCityListByCountryID(country_id,supp_city){
		
				   		//var country_id = $(this).val();
					
					$.ajax({
					  type: "get",
					  async: false,
					 url: "<?php echo base_url('Suppliers/get_city_list_by_country_id'); ?>",
					  data: { country_id: country_id, supp_city: supp_city },
					  dataType: "html",
					  success: function(data) {
						 
						if(data != "") {
							$('#city_data').empty();
							$('#city_data').html(data);
							$("#supp_city").select2({allowClear: true});
						} else {
							$('#city_data').empty();
							var default_data = '<select name="supp_city" id="supp_city" class="form-control" data-placeholder="Select country to load cities"></select>';
							$('#city_data').html(default_data);
							//$("#supp_city").select2({allowClear: true});
							set_message("Product Info","No cities found for the select country.");
						}},
					  error: function(){
       					alert('Error occured while getting data from server.');
    				  }
					  
					});	
	}
		
		
			jQuery(document).ready(function() {
				$("#country_id").select2();
				
				<?php if ($type=='A'){ ?>
				getCityListByCountryID(251); //load srilanka city on load
				<?php }?>
				<?php if ($type=='E'){ ?>
				getCityListByCountryID(<?php echo $suppliyer['country_id'] ?>,<?php echo $suppliyer['supp_city'] ?>); //load srilanka city on load
				<?php }?>
				FormValidator.init();
				//
				//$("#supp_city").select2();
				
			});
			
		</script>
        
<script type="text/javascript">
function insertSupplierData(){
var type=$('#type').val();
var supp_id=$('#supp_id').val();
var cr_limit_id=$('#cr_limit_id').val();
var country_id=$('#country_id').val();	
var supp_company_name 	= $('#supp_company_name').val();
var supp_company_phone=$('#supp_company_phone').val();
var supp_city=$('#supp_city').val();
var supp_state=$('#supp_state').val();
var supp_fax=$('#supp_fax').val();
var supp_postal_code=$('#supp_postal_code').val();
var supp_address=$('#supp_address').val();
var supp_email=$('#supp_email').val();
var supp_contact_person_name=$('#supp_contact_person_name').val();
var supp_contact_person_phone=$('#supp_contact_person_phone').val();
var supp_contact_person_email=$('#supp_contact_person_email').val();
var supp_bank=$('#supp_bank').val();
var supp_bank_branch=$('#supp_bank_branch').val();
var supp_account_number=$('#supp_account_number').val();
var supp_credit_period=$('#supp_credit_period').val();
var supp_code=$('#supp_code').val();	
	 
	$.post( "suppliers/save_supplier", {type:type, supp_id:supp_id, cr_limit_id:cr_limit_id, country_id:country_id, supp_company_name:supp_company_name, supp_company_phone:supp_company_phone, supp_city:supp_city, supp_state:supp_state, supp_fax:supp_fax, supp_postal_code:supp_postal_code, supp_postal_code:supp_postal_code, supp_address:supp_address, supp_email:supp_email, supp_contact_person_name:supp_contact_person_name, supp_contact_person_phone:supp_contact_person_phone, supp_contact_person_email:supp_contact_person_email, supp_bank:supp_bank, supp_bank_branch:supp_bank_branch, supp_account_number:supp_account_number, supp_credit_period:supp_credit_period, supp_code:supp_code})
	  .done(function( data ) {
		
	  var obj = jQuery.parseJSON(data);
	  
	  
	    //alert(obj.status); //last id
	    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 {
	  
	 // $('#ajax-modal').modal('hide');
	   $('div#ajax-modal').modal('hide');

	  loadGrid();// load supplier data
		
	  if(obj.type=='E'){
		 displayNotice('page','Supplier has been updated successfully!');
	  }
	  if(obj.type=='A'){
		displayNotice('page','Supplier has been added successfully!'); 
		document.getElementById("create_supplier_form").reset();
	  }
	}
	  });
return false;
}
    </script>
