    <style>
    	ul li
		{
			margin:5px;
		}
		
		.modal 
		{
			display:    none;
			position:   fixed;
			z-index:    1000;
			top:        0;
			left:       0;
			height:     100%;
			width:      100%;
			background: rgba( 255, 255, 255, .8 ) 
						url('<?php echo base_url("assets/img/myicon/blueloading.gif");?>') 
						50% 50% 
						no-repeat;
		}
	
		body.loading 
		{
			overflow: hidden;   
		}
	
		body.loading .modal 
		{
			display: block;
		}
		
		#item
		{
			color:red;	
		}
		
		#messagewindow 
		{
			width:100%;
			height: 250px;
			border: 1px solid;
			padding: 5px;
			margin:5px;
			overflow: auto;
			border-radius: 4px;
		}
    </style>
    
	<div class="content-wrapper">
    	<!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Channellimo
            <small>Preview</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Forms</a></li>
            <li class="active">Car</li>
          </ol>
        </section>
        
        <section class="content">
        	<div class="box">
             <div class="box-header">
               <h3 class="box-title"><!--<a href="<?php //echo site_url("admin/car/add");?>">ADD CAR</a>--></h3>
             </div><!-- /.box-header -->
             <div class="box-body">
             	<div class="col-lg-12">
                	<div class="col-lg-3">
                    	<ul class="list-group" id="showuser">
						<?php 
                         $date = date('Y-m-d');
                         $sql = $this->db->query("SELECT `id`, `ip_address`, `sessionId`, `active`, `date` FROM `ci_sessions` WHERE date = '$date' AND active = 1");
                         foreach($sql->result() as $v)
                         {
                            if($sql->result  = 0)
                            {
                               $user = "Not Found";  
                            }
                            else
                            {
                               $user = "User"; 
                            }
                                
                             echo'<li id="'.$v->sessionId.'" value="'.$v->sessionId.'" onclick="newMsg(this.value)" class="list-group-item justify-content-between">
							 		<a href="#">User('.$v->sessionId.')</a>
								  </li>';
                         }
                         ?>    
                        </ul>
                    </div>
                    
                    <div class="col-lg-9">
                    	<?php echo validation_errors('<div class="error">', '</div>'); ?>
                        <?php 
						if ($this->session->flashdata('errors'))
						{ 
							echo "<div class='error'>";
							echo $this->session->flashdata('errors');
							echo "</div>";
						}
						?>

            			<?php echo form_open('');?>
                        	<p id="messagewindow">
								<?php echo $html; ?>
                            </p>
                    	<!--<form id="chatform" action="<?php //echo site_url("/admin/chat/add");?>" method="post">-->
                            <div id="user">
                                <input type="hidden" name="trn_user" id="trn_user"/>
                            </div>
                            
                            <div id="myid">
                                <input type="hidden" name="trn_id" id="trn_id" value="0"/>
                            </div>
                            
                            <div id="txt">
                                <label>Message</label><br>
                                <textarea cols="40" rows="4" class="form-control" placeholder="Type your message here" name="message" id="content"></textarea>
                            </div><br />
                            
                            <input type="hidden" name="html_redirect" value="true" />
                            <!--<input type="submit" class="btn btn-primary" value="Send" /><br/>-->
                            <input type="button"  class="btn btn-primary" value="Send" onclick="AddMsg();"/>
                        <?php echo form_close();?>
                    </div>
                </di>
             </div><!-- /.box-body -->
            </div><!-- /.box -->
             <div class="modal"><!-- Place at bottom of page --></div>	
        </section>
    </div>
	
    <script>
		/*$body = $("body");
		$(document).on({
			ajaxStart: function() { $body.addClass("loading"); },
			ajaxStop: function() { $body.removeClass("loading"); }    
		});*/
		
		$(document).ready(function()
		{
			loaduser();
			newMsg();
		});
		
		
		function AddMsg() 
		{
			var trn_user = $("#trn_user").val();
			var message = $("#content").val();	
			if (trn_user !== ""&&message !== "" )
			{
				$.post("<?php echo base_url("/admin/chat/add")?>",{ trn_user,message },
				function(data) {
					//location.reload(); 
					$("#content").val('')
				});
			}
		}
		
		
		function loaduser()
		{
			var id = $("#showuser").val();
			$(id).addClass("active");
			$.ajax({
				type: "POST",
				url: "<?php echo base_url(); ?>"+"admin/chat/show_user"
			}).done(function( data ) {
				
				var values;
				var show_values;
				$("#showuser option").each(function()
				{
					values = $(this).val();
				});
				
				$(data).each(function()
				{
					show_values = $(this).val();
				});		
				
				if(show_values !== values)
				{
					$('#showuser').html(data);	
				}
			});	
			setTimeout('loaduser()', 1000); 
		}
		
			
		<!--load-ajax-->
		function newMsg(str)
		{
			if (str == "" || str == undefined) {
				 var str = document.getElementById("myLi").value;
			}
			$("#trn_user").val(str);
			//document.getElementById("trn_user").value = str;
			$.ajax({
				type: "POST",
				url: "<?php echo base_url(); ?>"+"admin/chat/getMsg",
				data: {Id : str }
			}).done(function( data ) {
				$('#messagewindow').html(data);	
			});		
			//setTimeout('newMsg()', 1000); 
		}
		<!--exit-->
    </script>