<?php
if ($wo['loggedin'] == false) {
    header("Location: " . Wo_SeoLink('index.php?link1=welcome'));
    exit();
}
if (!empty($_GET['user']) && empty($_GET['page'])) {
    $user_id = Wo_Secure($_GET['user']);
    $user    = Wo_UserData($user_id);
    if (empty($user['user_id'])) {
        unset($user);
    }
}
?>
<div class="wo_kb_msg_page" id="wo_nw_msg_page">
	<div class="msg_under_hood">
		<div class="mobilerightpane" id="wo_msg_left_prt">
			<form method="post" class="messages-search-users-form">
				<div class="form-group inner-addon <?php echo Wo_RightToLeft('left-addon');?> messages-search-icon">
                    <div class="msg_srch_innr">
                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
                        <input type="text" name="query" id="query" onkeyup="Wo_GetMessagesUsers(this.value);" class="form-control" placeholder="<?php echo $wo['lang']['search'];?>" autocomplete="off">
                    </div>
					<button type="button" class="btn btn-main" title="<?php echo $wo['lang']['mark_all_as_read'] ?>" onclick="MarkAsReadAll();">
						<svg xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 24 24"><path fill="currentColor" d="M14,10H2V12H14V10M14,6H2V8H14V6M2,16H10V14H2V16M21.5,11.5L23,13L16,20L11.5,15.5L13,14L16,17L21.5,11.5Z"></path></svg>
					</button>
					<button type="button" class="btn btn-main" onclick="Wo_CreateGChat(event)">
						<span class="pointer" style="margin-right: 5px;">
							<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"><path fill="currentColor" d="M13,13C11,13 7,14 7,16V18H19V16C19,14 15,13 13,13M19.62,13.16C20.45,13.88 21,14.82 21,16V18H24V16C24,14.46 21.63,13.5 19.62,13.16M13,11A3,3 0 0,0 16,8A3,3 0 0,0 13,5A3,3 0 0,0 10,8A3,3 0 0,0 13,11M18,11A3,3 0 0,0 21,8A3,3 0 0,0 18,5C17.68,5 17.37,5.05 17.08,5.14C17.65,5.95 18,6.94 18,8C18,9.06 17.65,10.04 17.08,10.85C17.37,10.95 17.68,11 18,11M8,10H5V7H3V10H0V12H3V15H5V12H8V10Z" /></svg>
						</span>
					</button>
                </div>
				<ul class="nav nav-tabs wo_msg_tabs">
					<li class="active pointer"><a data-toggle="tab" data-target="#users-message" href="#"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M7.5,15C8.63,15 9.82,15.26 11.09,15.77C12.35,16.29 13,16.95 13,17.77V20H2V17.77C2,16.95 2.65,16.29 3.91,15.77C5.18,15.26 6.38,15 7.5,15M13,13H22V15H13V13M13,9H22V11H13V9M13,5H22V7H13V5M7.5,8A2.5,2.5 0 0,1 10,10.5A2.5,2.5 0 0,1 7.5,13A2.5,2.5 0 0,1 5,10.5A2.5,2.5 0 0,1 7.5,8Z" /></svg> <?php echo $wo['lang']['users'];?></a></li>
					<li class="pointer"><a data-toggle="tab" data-target="#groups-message" href="#"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M12,5A3.5,3.5 0 0,0 8.5,8.5A3.5,3.5 0 0,0 12,12A3.5,3.5 0 0,0 15.5,8.5A3.5,3.5 0 0,0 12,5M12,7A1.5,1.5 0 0,1 13.5,8.5A1.5,1.5 0 0,1 12,10A1.5,1.5 0 0,1 10.5,8.5A1.5,1.5 0 0,1 12,7M5.5,8A2.5,2.5 0 0,0 3,10.5C3,11.44 3.53,12.25 4.29,12.68C4.65,12.88 5.06,13 5.5,13C5.94,13 6.35,12.88 6.71,12.68C7.08,12.47 7.39,12.17 7.62,11.81C6.89,10.86 6.5,9.7 6.5,8.5C6.5,8.41 6.5,8.31 6.5,8.22C6.2,8.08 5.86,8 5.5,8M18.5,8C18.14,8 17.8,8.08 17.5,8.22C17.5,8.31 17.5,8.41 17.5,8.5C17.5,9.7 17.11,10.86 16.38,11.81C16.5,12 16.63,12.15 16.78,12.3C16.94,12.45 17.1,12.58 17.29,12.68C17.65,12.88 18.06,13 18.5,13C18.94,13 19.35,12.88 19.71,12.68C20.47,12.25 21,11.44 21,10.5A2.5,2.5 0 0,0 18.5,8M12,14C9.66,14 5,15.17 5,17.5V19H19V17.5C19,15.17 14.34,14 12,14M4.71,14.55C2.78,14.78 0,15.76 0,17.5V19H3V17.07C3,16.06 3.69,15.22 4.71,14.55M19.29,14.55C20.31,15.22 21,16.06 21,17.07V19H24V17.5C24,15.76 21.22,14.78 19.29,14.55M12,16C13.53,16 15.24,16.5 16.23,17H7.77C8.76,16.5 10.47,16 12,16Z" /></svg> <?php echo $wo['lang']['groups'];?></a></li>				
				</ul>
				<div class="tab-content messages-users-list">
					<div id="users-message" class="messages-chat-list tab-pane fade in active">
						<?php
							$chats = Wo_GetMessagesUsers($wo['user']['user_id']);
							$array = array();
					        if (!empty($chats)) {
					            foreach ($chats as $key => $value) {
					                $array[] = $value;
					            }
					        }
					        array_multisort( array_column($array, "chat_time"), SORT_DESC, $array );
							if (count($chats) == 0) {
								echo '<span class="no-online-users center-text empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>' . $wo['lang']['no_users_found'] . '</span>';
							}else{
								foreach($chats as $wo['recipient']) {
									if (!empty($wo['recipient']['message']['page_id'])) {
										$message = Wo_GetPageMessages(array(
	                                                'page_id' => $wo['recipient']['message']['page_id'],
	                                                'from_id' => $wo['recipient']['message']['user_id'],
	                                                'to_id'   => $wo['recipient']['message']['conversation_user_id'],
	                                                'limit' => 1,
	                                                'limit_type' => 1
	                                            ));
				                        $wo['page_message']['message'] = $message[0];
				                        
				                        echo Wo_LoadPage('messages/messages-page-list');
				                    }
				                    else{
				                    	echo Wo_LoadPage('messages/messages-recipients-list');
				                    }
								}
							}
						?> 
					</div>
					<div id="groups-message" class="messages-group-list tab-pane fade" >
						<?php 
							$chat_groups = Wo_GetChatGroups();
							if (count($chat_groups) == 0) {
								echo '<span class="no-online-users center-text empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-users"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M23 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path></svg>' . $wo['lang']['no_groups_found'] . '</span>';
							} 
							else {
								foreach ($chat_groups as $wo['group']) {
									echo Wo_LoadPage('messages/messages-group-list');
                    
								}
							}
						?>
					</div>
				</div>
			</form>
		</div>
   
		<div class="mobileleftpane" id="wo_msg_right_prt">
			<ul class="list-group text-sender-container">
				<li class="list-group-item msg_usr_info_top_list text-muted" contenteditable="false">
					<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-left mobilemsgclose"><polyline points="15 18 9 12 15 6"></polyline></svg>
					<div class="msg_usr_cht_usr_data">
						<span id="user-avatar-right">
							<img src="<?php echo $wo['user']['avatar'];?>" alt="avatar" width="45" height="45" class="hidden" />
						</span>
						<div>
							<div id="user-name" class="hidden"></div>
							<p id="user-last-seen" class="msg_usr_lst_sen_main"></p>
						</div>
					</div>
					<span class="msg_usr_cht_opts_btns">
						<span class="video-icon" id="audio-button"></span>
						<span class="video-icon" id="video-button"></span>
						<span class="delete-icon" title="Delete Conversation"></span>
					</span>
					<div class="msg_progress"><div class="indeterminate"></div></div>
				</li>
				<li class="messages-load-more-messages view-more-wrapper hidden nav-down"></li>
				<div class="messagejoint">
					<div class="messages-container">
						<div class="no-messages empty_state">
							<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" xml:space="preserve"> <path style="fill:#FFF1CD;" d="M388.542,78.183H53.014c-5.114,0-9.262,4.147-9.262,9.262v46.393L0,155.712l43.752,21.877v46.392 c0,5.115,4.146,9.263,9.262,9.263h335.528c5.115,0,9.262-4.147,9.262-9.263V87.443C397.802,82.329,393.656,78.183,388.542,78.183z" /> <path style="fill:#B4E5EA;" d="M512,356.285l-43.752-21.876v-46.393c0-5.114-4.146-9.262-9.262-9.262H123.459 c-5.115,0-9.262,4.147-9.262,9.262v136.538c0,5.115,4.146,9.263,9.262,9.263h335.528c5.114,0,9.262-4.147,9.262-9.263v-46.392 L512,356.285z"/> <g> <path style="fill:#609399;" d="M343.092,386.869H161.037c-4.714,0-8.533-3.82-8.533-8.533c0-4.714,3.82-8.533,8.533-8.533h182.056 c4.714,0,8.533,3.819,8.533,8.533C351.626,383.049,347.805,386.869,343.092,386.869z"/> <path style="fill:#609399;" d="M422.737,342.769h-261.7c-4.714,0-8.533-3.82-8.533-8.533s3.82-8.533,8.533-8.533h261.7 c4.714,0,8.533,3.82,8.533,8.533S427.449,342.769,422.737,342.769z"/> </g> <g> <path style="fill:#FFD24D;" d="M272.648,186.297H89.019c-4.714,0-8.533-3.82-8.533-8.533s3.82-8.533,8.533-8.533h183.629 c4.714,0,8.533,3.82,8.533,8.533S277.361,186.297,272.648,186.297z"/> <path style="fill:#FFD24D;" d="M352.292,142.197H89.019c-4.714,0-8.533-3.82-8.533-8.533s3.82-8.533,8.533-8.533h263.274 c4.714,0,8.533,3.82,8.533,8.533S357.005,142.197,352.292,142.197z"/> </g></svg>
							<?php echo $wo['lang']['choose_one_of_your_friends']; ?> <br/>
							<?php echo $wo['lang']['and_say_hello']; ?>
						</div>
					</div>
					<form method="post" class="sendMessages" enctype="multipart/form-data">
						<div class="input-group">
							<div class="msg_write_combo">
								<span class="message-option-btns"  style="margin-right: 10px; margin-left: 10px;">
									<span class="btn btn-file MS-File">
										<?php if($wo['config']['fileSharing'] == 1) { ?>
											<svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 512 512"><path fill="#6bcfef" d="M312 155h91c2.8 0 5-2.2 5-5 0-8.9-3.9-17.3-10.7-22.9L321 63.5c-5.8-4.8-13-7.4-20.6-7.4-4.1 0-7.4 3.3-7.4 7.4V136c0 10.5 8.5 19 19 19z"></path><path fill="#6bcfef" d="M267 136V56H136c-17.6 0-32 14.4-32 32v336c0 17.6 14.4 32 32 32h240c17.6 0 32-14.4 32-32V181h-96c-24.8 0-45-20.2-45-45z"></path></svg>
											<input type="file" id="sendMessasgeFile" name="sendMessageFile"  onchange="Wo_ShareFile();" />
										<?php } else { ?>
											<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="#4db3f6" d="M8.5,13.5L11,16.5L14.5,12L19,18H5M21,19V5C21,3.89 20.1,3 19,3H5A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19Z"></path></svg>
											<input type="file" id="sendMessasgeFile" name="sendMessageFile"  onchange="Wo_ShareFile();" accept="image/x-png, image/gif, image/jpeg" disabled />
										<?php } ?>
									</span>
								</span>
								<textarea name="textSendMessage" class="form-control custom-controls" id="sendMessage" onkeydown="Wo_SubmitForm(event);" onfocus="Wo_SubmitForm(event);" placeholder="<?php echo $wo['lang']['write_something'];?>" cols="10" rows="4" class="form-control" disabled></textarea>
								<div class="text-right charsLeft-message"><span id="charsLeft"></span></div>
								<span class="message-option-btns">
									<div class="dropup">
										<a href="#" class="emo-message dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" >
											<span class="btn btn-file">
												<svg xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 24 24"><path fill="#f3c038" d="M12,2C6.486,2,2,6.486,2,12s4.486,10,10,10c5.514,0,10-4.486,10-10S17.514,2,12,2z M8.5,8C9.328,8,10,8.896,10,10	s-0.672,2-1.5,2S7,11.104,7,10S7.672,8,8.5,8z M12,18c-1.905,0-3.654-0.874-4.8-2.399l1.599-1.201C9.563,15.417,10.73,16,12,16	c1.27,0,2.436-0.583,3.2-1.601l1.6,1.201C15.653,17.126,13.904,18,12,18z M15.5,12c-0.828,0-1.5-0.896-1.5-2s0.672-2,1.5-2	S17,8.896,17,10S16.328,12,15.5,12z"></path></svg>
											</span>
										</a>
										<div class="emo-message-container dropdown-menu mobileemojisnd dropdown-menu-right" role="menu" style="width: 100px">
											<?php  
												foreach ($wo['emo'] as $code => $name) {
												$code   = $code;
												echo  '<span style="float: left" onclick="Wo_AddEmoToMessageInput(\'' . $code . '\');"><i class="pointer twa-lg twa twa-' . $name . '"></i></span>'; 
												} 
											?>
										</div>
									</div>

									<?php if ($wo['config']['stickers_system'] == 1): ?>
									<span class="dropup chat_optns" id="chat-sticker-system" style="display: table-cell;">
										<span class="btn btn-file dropdown-toggle" data-toggle="dropdown" aria-expanded="true" role="button" style="padding: 15px 0px;">
											<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path fill="#31a38c" d="M5.5,2C3.56,2 2,3.56 2,5.5V18.5C2,20.44 3.56,22 5.5,22H16L22,16V5.5C22,3.56 20.44,2 18.5,2H5.5M5.75,4H18.25A1.75,1.75 0 0,1 20,5.75V15H18.5C16.56,15 15,16.56 15,18.5V20H5.75A1.75,1.75 0 0,1 4,18.25V5.75A1.75,1.75 0 0,1 5.75,4M14.44,6.77C14.28,6.77 14.12,6.79 13.97,6.83C13.03,7.09 12.5,8.05 12.74,9C12.79,9.15 12.86,9.3 12.95,9.44L16.18,8.56C16.18,8.39 16.16,8.22 16.12,8.05C15.91,7.3 15.22,6.77 14.44,6.77M8.17,8.5C8,8.5 7.85,8.5 7.7,8.55C6.77,8.81 6.22,9.77 6.47,10.7C6.5,10.86 6.59,11 6.68,11.16L9.91,10.28C9.91,10.11 9.89,9.94 9.85,9.78C9.64,9 8.95,8.5 8.17,8.5M16.72,11.26L7.59,13.77C8.91,15.3 11,15.94 12.95,15.41C14.9,14.87 16.36,13.25 16.72,11.26Z"></path></svg>
										</span>
										<ul class="dropdown-menu drop-up" style="left: -145px;width: 251px;" role="menu" onclick="event.stopPropagation()">
											<li>
												<div class="w100" id="chat-box-stickers">
													<div id="chat-box-stickers-cont">
														<?php 
															$stickers_system = Wo_GetAllStickers(50000);
															if( count( $stickers_system ) > 0 ){
																foreach ($stickers_system as $wo['stickerlist']) {
																	echo '<img alt="gif" src="'. Wo_GetMedia( $wo['stickerlist']['media_file'] ).'" data-gif="'.Wo_GetMedia( $wo['stickerlist']['media_file'] ).'" onclick="Wo_ChatStickerMessage(this);" autoplay loop>';
																}
															} else {
																echo '<p class="no_chat_gifs_found"><i class="fa fa-frown-o"></i> '. $wo['lang']['no_result'] .'</p>';
															}
														?>
													</div>
												</div>
											</li>
										</ul>
									</span>
									<?php endif; ?>
									<?php if ($wo['config']['audio_upload'] == 1) { ?>

									<span class="btn btn-file MS-File" disabled id="messages-record" data-record="0">
										<svg xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 24 24"><path fill="#ff3a55" d="M12,2A3,3 0 0,1 15,5V11A3,3 0 0,1 12,14A3,3 0 0,1 9,11V5A3,3 0 0,1 12,2M19,11C19,14.53 16.39,17.44 13,17.93V21H11V17.93C7.61,17.44 5,14.53 5,11H7A5,5 0 0,0 12,16A5,5 0 0,0 17,11H19Z"></path></svg>
									</span>
									<span class="btn btn-file MS-File messages-rtime hidden" style="padding: 14px 1px;">00:00</span>
									<?php } ?>
								</span>
							</div>
							<span class="input-group-btn">
								<button onclick="Wo_GetMRecordLink();"  class="btn-main btn btn-file MS-File send-button" type="button">
									<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-send"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>
								</button>
							</span>
						</div>
						<input type="hidden" id="user-id" name="user_id" value="0" />
						<input type="hidden" id="messages-group-id" name="group_id" value="0" />
						<input type="hidden" id="messages-page-id" name="page_id" value="0" />
						<input type="hidden" id="messages-from-id" name="to_id" value="0" />
						<input type="hidden" id="message-record-file" name="record-file" value="" />
						<input type="hidden" id="message-record-name" name="record-name" value="" />
						<input type="hidden" name="chatSticker" id="chatStickerMessage">
					</form>
				</div>
			</ul>
			<div class="wo_msg_user_dtl">
				<div class="wo_msg_dtl_top">
					<span class="user_nm" id="user-name-right"></span>
					<span class="delete-icon" title="Delete Conversation"></span>
				</div>
				<div class="wo_msg_dtl_mid">
					<!-- <span id="user-avatar-right">
						<img src="<?php echo $wo['user']['avatar'];?>" alt="avatar" class="hidden" />
					</span> -->
				</div>
				<div class="wo_msg_dtl_bottom">
					<span class="video-icon" id="audio-button-right"></span>
					<span class="video-icon" id="video-button-right"></span>
				</div>
				<div class="wo_msg_dtl_most_bottom" style="display: none">
					<span><a href="javascript:void(0);" id="user-chat-link"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-reactid="501"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path><circle cx="12" cy="12" r="3"></circle></svg> <?php echo $wo['lang']['view_profile'];?></a></span>
					<span><a href="javascript:void(0);" id="block-url"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"></circle><line x1="4.93" y1="4.93" x2="19.07" y2="19.07"></line></svg> <?php echo $wo['lang']['block'];?></a></span>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
function MarkAsReadAll() {
	$.post(Wo_Ajax_Requests_File() + '?f=mark_as_read', function(data, textStatus, xhr) {
		Wo_UpdateUsers();
		Wo_intervalUpdates();
	});
}
$(document).on('click','.mobileopenlist',function(){
	$('.mobileleftpane').fadeIn(100);
});

$('.mobilemsgclose').on('click',function (){
	$('.mobileleftpane').fadeOut(100);
});

$('.emo-message-container').click(function(e) {
    e.stopPropagation();
});

$(function () {
  <?php if (!empty($user['user_id'])) { ?>
    setTimeout(function () {
      Wo_GetUserMessages(<?php echo $user['user_id'] ?>, "<?php echo $user['name']?>", "<?php echo $user['username']?>");
    }, 1000);
  <?php } ?>

  <?php if (!empty($_GET['page']) && !empty($_GET['user'])) {
  	$page_info = Wo_PageData($_GET['page']);

  	$user_id = $_GET['page'].'_'.$_GET['user'];
	if ($page_info['user_id'] == $_GET['user']) {
	    $user_id = $_GET['page'].'_'.$_GET['to'];
	}

   ?>
    setTimeout(function () {
      Wo_GetPageMessages(<?php echo $_GET['page'] ?>, "<?php echo $_GET['user']?>","<?php echo($page_info['page_name']) ?>","<?php echo($user_id) ?>");
    }, 1000);
  <?php } ?>

  <?php if ($wo['config']['maxCharacters'] != 10000) { ?>
  $('#sendMessage').limit("<?php echo $wo['config']['maxCharacters']?>", '#charsLeft');
  <?php } ?>
  setTimeout(Wo_getNewMessages, 5000);
  setTimeout(Wo_UpdateUsers, 10000);
  <?php if ($wo['config']['message_seen'] == 1) { ?>
  setTimeout(Wo_getMessageSeen, 12000);
  <?php } ?>
  var main_hash_id   = $('.main_session').val();
  var file_uploading = false;

  $('form.sendMessages').ajaxForm({
    url: Wo_Ajax_Requests_File() + '?f=messages&s=send_message&hash=' + main_hash_id,
    beforeSend: function () {
    	chat_number = $('#user-id').val();
    	first_chat = $('.messages-recipients-list').first();
    	first_chat_id = $(first_chat).attr('id');
    	sending_text = $('.mobileleftpane .text-sender-container textarea').val();
    	if (sending_text.length  > 100) {
    		sending_text = jQuery.trim(sending_text).substring(0, 97)+'...';
    	}

    	$('#messages-recipient-'+chat_number).insertBefore( $( "#"+first_chat_id ) );

    	$('#messages-recipient-'+chat_number).find('p').text(sending_text);
    	$('#messages-recipient-'+chat_number).find('.messages-last-sent').text('<?php echo $wo['lang']['time_just_now'];?>');
    	$('#messages-recipient-'+chat_number).find('.messages-last-sent').attr('title', '0 seconds');



      $('.mobileleftpane .text-sender-container textarea').val('');
      $('.sendMessage').attr('disabled', true);
      var user_id_ = $('#user-id').val();
      $('body').attr('sending-' + user_id_, true);
      $('form.sendMessages').find('.send-button').html('<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-loader"><line x1="12" y1="2" x2="12" y2="6"></line><line x1="12" y1="18" x2="12" y2="22"></line><line x1="4.93" y1="4.93" x2="7.76" y2="7.76"></line><line x1="16.24" y1="16.24" x2="19.07" y2="19.07"></line><line x1="2" y1="12" x2="6" y2="12"></line><line x1="18" y1="12" x2="22" y2="12"></line><line x1="4.93" y1="19.07" x2="7.76" y2="16.24"></line><line x1="16.24" y1="7.76" x2="19.07" y2="4.93"></line></svg>');
    },
    uploadProgress: function () {
      if ($("#sendMessasgeFile").val() != '') {
        $('form.sendMessages').find('.send-button').html('<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-loader"><line x1="12" y1="2" x2="12" y2="6"></line><line x1="12" y1="18" x2="12" y2="22"></line><line x1="4.93" y1="4.93" x2="7.76" y2="7.76"></line><line x1="16.24" y1="16.24" x2="19.07" y2="19.07"></line><line x1="2" y1="12" x2="6" y2="12"></line><line x1="18" y1="12" x2="22" y2="12"></line><line x1="4.93" y1="19.07" x2="7.76" y2="16.24"></line><line x1="16.24" y1="7.76" x2="19.07" y2="4.93"></line></svg>');
        file_uploading = true;
      }
    },
    success: function (data) {
      if(data.status == 200) {
        $("#message-record-file").val('');
        $("#message-record-name").val('');
        $('#chatStickerMessage').val('');
        Wo_CleanRecordNodes();
        Wo_StopLocalStream();
        
        if($('.messages-container').length == 0) {
          $(".messages-container").html(data.html);
        } else {
          $(".no-messages").hide();
          $(".messages-container").append(data.html);
        }
        var user_id_ = $('#user-id').val();
        $('body').attr('sending-' + user_id_, false);
        $('form.sendMessages').clearForm();
        $('#sendMessage').val('').attr('disabled', false).keyup().focus();
        $(".messages-container").animate({
          scrollTop: $('.messages-container')[0].scrollHeight
        }, 500);
        if (data.invalid_file == 1) {
          $("#invalid_file").modal('show');
          Wo_Delay(function(){
              $("#invalid_file").modal('hide');
          },3000);
        }
        if (data.invalid_file == 2) {
          $("#file_not_supported").modal('show');
          Wo_Delay(function(){
              $("#file_not_supported").modal('hide');
          },3000);
        }
      }
      else if(data.status == 500 && data.invalid_file == 1){
        $("#invalid_file").modal('show');
        Wo_Delay(function(){
            $("#invalid_file").modal('hide');
        },3000);
      }
      else if(data.status == 500 && data.invalid_file == 2){
        $("#file_not_supported").modal('show');
        Wo_Delay(function(){
            $("#file_not_supported").modal('hide');
        },3000);
      }
      if (file_uploading) {
        file_uploading = false;
        $('form.sendMessages').find('.send-button').html('<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-send"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>');
      }
      $('form.sendMessages').find('.send-button').html('<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-send"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>');
    }
  });
});

function Wo_ChatStickerMessage(self){
  if (!self) {
    return false;
  }
  $('#chatStickerMessage').val($(self).attr('data-gif'));
  $('form.sendMessages').submit();
  $("#chat-sticker-system").removeClass("open");
}

function Wo_AddEmoToMessageInput(code) {
    inputTag = $('#sendMessage');
    inputVal = inputTag.val();
    if (typeof(inputTag.attr('placeholder')) != "undefined") {
        inputPlaceholder = inputTag.attr('placeholder');
        if (inputPlaceholder == inputVal) {
            inputTag.val('');
            inputVal = inputTag.val();
        }
    }
    if (inputVal.length == 0) {
        inputTag.val(code + ' ');
    } else {
        inputTag.val(inputVal + ' ' + code);
    }
    inputTag.keyup().focus();
    $(".emo-messages-container").slideUp('fast');
}
function Wo_GetMessagesUsers(query) {
  searchForm = $('.messages-search-users-form');
  Wo_progressIconLoader(searchForm.find('.messages-search-icon'));
  $.get(Wo_Ajax_Requests_File(), {
    f: 'search',
    s: 'recipients',
    query: query
  }, function (data) {
    if(data.status == 200) {
      if(data.html.length == 0) {
        $('.messages-users-list').find('.messages-chat-list').html('<span class="center-text"><?php $wo["lang"]["no_result"];?></span>');

      } else {
        $('.messages-users-list').find('.messages-chat-list').html(data.html);
      }
      scrollToTop();
    }
    Wo_progressIconLoader(searchForm.find('.messages-search-icon'));
  });
}

function Wo_UpdateUsers() {
  if ($('.messages-search-users-form #query').val().length > 0) {
       return false;
  }
  $.get(Wo_Ajax_Requests_File(), {
    f: 'messages',
    s: 'update_recipients'
  }, function (data) {
    setTimeout(Wo_UpdateUsers, 10000);
    if(data.status == 200) {
      $('.messages-users-list').find('.messages-chat-list').html(data.html);
    }
    else{
      $('.messages-users-list').find('.messages-chat-list').html('<span class="no-online-users center-text"><?php echo $wo['lang']['no_users_found']; ?></span>');
    }
  });
}

function Wo_DeleteConversation(user_id) {
  if (!confirm("<?php echo $wo['lang']['messages_delete_confirmation']?>")) {
    return false;
  }
  $('.text-sender-container').find('.ball-pulse').fadeIn(100);
  $('.text-sender-container').find('.msg_progress').fadeIn(100);
  $.get(Wo_Ajax_Requests_File(), {
    f: 'messages',
    s: 'delete_conversation',
    user_id: user_id,
  }, function (data) {
    if(data.status == 200) {
      alert(data.message);
      $('.messages-container').empty();
	  location.reload();
    }
    $('.text-sender-container').find('.ball-pulse').fadeOut(100);
	$('.text-sender-container').find('.msg_progress').fadeOut(100);
  });
}

function Wo_GetUserMessages(user_id, user_name, userlink) {
  view_more_wrapper = $('.view-more-wrapper');

  $('.text-sender-container').find('.ball-pulse').fadeIn(100);
  $('.text-sender-container').find('.msg_progress').fadeIn(100);
  
  if($('.messages-recipients-list').hasClass('active')) {
	$('.messages-recipients-list').removeClass('active');
	$('#messages-recipient-' + user_id).addClass('active');
  } else { 
	$('#messages-recipient-' + user_id).addClass('active');
  }
  $('#user-id').attr('value', user_id);
  $('#messages-group-id').attr('value', 0);
  $('#messages-recipient-' + user_id).find('.new-message-alert').fadeOut(200);
  $('#messages-recipient-' + user_id).find('.messages-last-sent').removeClass('new_msg_lst_lsent');
  $('#messages-recipient-' + user_id).find('p').removeClass('new_msg_active_list');
  $.get(Wo_Ajax_Requests_File(), {
    f: 'messages',
    s: 'get_user_messages',
    user_id: user_id
  }, function (data) {
    if(data.status == 200) {
      $('.wo_msg_user_dtl').css('display', 'none');

      $('.wo_msg_dtl_most_bottom').css('display', 'block');
      $('.send-button').css('background-color', data.color);
      $('.send-button').css('border-color', data.color);
      $('#user-chat-link').attr('href', data.url);
      $('#block-url').attr('href', data.block_url);
      $('#user-avatar-right img').attr('src', data.avatar).removeClass('hidden');

      $('#user-name').html('<a target="_blank" href="' + data.url + '">' + user_name + '</a>').removeClass('hidden');
      $('#user-name-right').html('<a target="_blank" href="'+ data.url + '">' + user_name + '</a>');
      $('#user-last-seen').html(data.lastseen);

	  $('.delete-icon').html('<svg xmlns="http://www.w3.org/2000/svg" width="27" height="27" viewBox="0 0 24 24" onclick="Wo_DeleteConversation(' + user_id + ')"><path fill="currentColor" d="M9,3V4H4V6H5V19A2,2 0 0,0 7,21H17A2,2 0 0,0 19,19V6H20V4H15V3H9M7,6H17V19H7V6M9,8V17H11V8H9M13,8V17H15V8H13Z" /></svg>');

      if(data.can_replay == true) {
        $('#sendMessage').val('').attr('disabled', false);
        $('#sendMessasgeFile').attr('disabled', false);
        $('#messages-record').attr('disabled', false);
      } else {
        $('#sendMessage').val('<?php $wo["lang"]["sorry_cant_reply"];?>').attr('disabled', true);
        $('#sendMessasgeFile').attr('disabled', true);
      }
      <?php if ($wo['config']['maxCharacters'] != 10000) { ?>
        $('#charsLeft').text("<?php echo $wo['config']['maxCharacters']?>");
      <?php }?>
      if(data.html.length == 0) {
        view_more_wrapper.hide();
        $('.messages-container').html('<div class="no-messages empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-info"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12" y2="8"></line></svg><?php echo $wo["lang"]["no_more_message_to_show"];?> </div>');
      } else {
        $('.messages-container').html(data.html);
        view_more_wrapper.html('<a href="javascript:void(0);" title="' + data.view_more_text + '"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M13,15L15.5,17.5L16.92,16.08L12,11.16L7.08,16.08L8.5,17.5L11,15V21H13V15M3,3H21V5H3V3M3,7H13V9H3V7Z" /></svg></a>').show();
        view_more_wrapper.attr('onclick', 'Wo_getOldMessages(' + user_id + ');').removeClass('hidden');
        $(".messages-container").animate({
          scrollTop: $('.messages-container')[0].scrollHeight
        }, 200);
      }
      <?php if ($wo['config']['message_seen'] == 1) { ?>
         Wo_getMessageSeen();
      <?php } ?>
      $('.emo-message').fadeIn(200);
      <?php if ($wo['config']['video_chat'] == 1) { ?>
      if (data.video_call == 200) {
		video_call = '<svg xmlns="http://www.w3.org/2000/svg" width="33" height="33" viewBox="0 0 24 24" onclick="Wo_GenerateVideoCall(<?php echo $wo['user']['user_id'];?>, ' + user_id + ')"><path fill="currentColor" d="M15,8V16H5V8H15M16,6H4A1,1 0 0,0 3,7V17A1,1 0 0,0 4,18H16A1,1 0 0,0 17,17V13.5L21,17.5V6.5L17,10.5V7A1,1 0 0,0 16,6Z" /></svg>';
      } else {
        video_call = '';
      }
      $('#video-button,#video-button-right').html(video_call);
      <?php } ?>
      <?php if ($wo['config']['audio_chat'] == 1) { ?>
      if (data.audio_call == 200) {
		audio_call = '<svg xmlns="http://www.w3.org/2000/svg" width="27" height="27" viewBox="0 0 24 24" onclick="Wo_GenerateVoiceCall(<?php echo $wo['user']['user_id'];?>, ' + user_id + ')"><path fill="currentColor" d="M20,15.5C18.8,15.5 17.5,15.3 16.4,14.9C16.3,14.9 16.2,14.9 16.1,14.9C15.8,14.9 15.6,15 15.4,15.2L13.2,17.4C10.4,15.9 8,13.6 6.6,10.8L8.8,8.6C9.1,8.3 9.2,7.9 9,7.6C8.7,6.5 8.5,5.2 8.5,4C8.5,3.5 8,3 7.5,3H4C3.5,3 3,3.5 3,4C3,13.4 10.6,21 20,21C20.5,21 21,20.5 21,20V16.5C21,16 20.5,15.5 20,15.5M5,5H6.5C6.6,5.9 6.8,6.8 7,7.6L5.8,8.8C5.4,7.6 5.1,6.3 5,5M19,19C17.7,18.9 16.4,18.6 15.2,18.2L16.4,17C17.2,17.2 18.1,17.4 19,17.4V19Z" /></svg>';
      } else {
        audio_call = '';
      }
      $('#audio-button,#audio-button-right').html(audio_call);
      <?php } ?>
      $('.text-sender-container').find('.ball-pulse').fadeOut(100);
	  $('.text-sender-container').find('.msg_progress').fadeOut(100);
    }
  });
}

function Wo_GetGroupMessages(group_id, group_name) {
  view_more_wrapper = $('.view-more-wrapper');
  
  $('.text-sender-container').find('.ball-pulse').fadeIn(100);
  $('.text-sender-container').find('.msg_progress').fadeIn(100);
  $('#user-name').text(group_name).removeClass('hidden');
  $('#user-name-right').html('<a target="_blank" href="javascript:void(0);">' + group_name + '</a>');
  if($('.messages-recipients-list').hasClass('active')) {
	$('.messages-recipients-list').removeClass('active');
	$('#messages-recipient-' + group_id).addClass('active');
  } else { 
	$('#messages-recipient-' + group_id).addClass('active');
  }
  $('#messages-group-id').attr('value', group_id);
  $('#user-id').attr('value', 0);
  $('#sendMessage').val('').attr('disabled', false);
  $('#sendMessasgeFile').attr('disabled', false);
  $('#messages-record').attr('disabled',false);
  $("#messages-group-"+ group_id).find('.group-lastseen').empty();
  $.get(Wo_Ajax_Requests_File(), {
    f: 'messages',
    s: 'get_group_messages',
    group_id: group_id
  }, function (data) {
    if(data.status == 200) {
    	$('.send-button').css('background-color', '#c45a5b');
        $('.send-button').css('border-color', '#c45a5b');
    	$('#user-last-seen').html('');
    	$('.wo_msg_user_dtl').css('display', 'none');
      <?php if ($wo['config']['maxCharacters'] != 10000) { ?>
      $('#charsLeft').text("<?php echo $wo['config']['maxCharacters']?>");
      <?php }?>

      if(data.html.length == 0) {
        view_more_wrapper.hide();
        $('.messages-container').html('<div class="no-messages empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-info"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12" y2="8"></line></svg><?php echo $wo["lang"]["no_more_message_to_show"];?> </div>');
      } 
      else {
        $('.messages-container').html(data.html);
		view_more_wrapper.html('<a href="javascript:void(0);" title="' + data.view_more_text + '"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M13,15L15.5,17.5L16.92,16.08L12,11.16L7.08,16.08L8.5,17.5L11,15V21H13V15M3,3H21V5H3V3M3,7H13V9H3V7Z" /></svg></a>').show();
        view_more_wrapper.attr('onclick', 'Wo_getOldGroupMessages(' + group_id + ');').removeClass('hidden');
        $(".messages-container").animate({
          scrollTop: $('.messages-container')[0].scrollHeight
        }, 200);
      }
      $('.text-sender-container').find('.ball-pulse').fadeOut(100);
	  $('.text-sender-container').find('.msg_progress').fadeOut(100);
    }
  });
}

function Wo_GetPageMessages(page_id, page_user_id,page_name,user_id) {
  view_more_wrapper = $('.view-more-wrapper');
  
  $('.text-sender-container').find('.ball-pulse').fadeIn(100);
  $('.text-sender-container').find('.msg_progress').fadeIn(100);
  $('#user-name').text(page_name).removeClass('hidden');
  $('#user-name-right').html('<a target="_blank" href="javascript:void(0);">' + page_name + '</a>');
  if($('.messages-recipients-list').hasClass('active')) {
	$('.messages-recipients-list').removeClass('active');
	$('#messages-recipient-' + user_id).addClass('active');
  } else { 
	$('#messages-recipient-' + user_id).addClass('active');
  }
  $('#user-avatar-right img').addClass('hidden');
  $('.msg_usr_lst_sen_main').html('');
  $('#messages-page-id').attr('value', page_id);
  $('#messages-from-id').attr('value', page_user_id);
  $('#user-id').attr('value', 0);
  $('#sendMessage').val('').attr('disabled', false);
  $('#sendMessasgeFile').attr('disabled', false);
  $('#messages-record').attr('disabled',false);
  $("#messages-group-"+ page_id).find('.group-lastseen').empty();
  $.get(Wo_Ajax_Requests_File(), {
    f: 'messages',
    s: 'get_page_messages',
    page_user_id: page_user_id,
    page_id: page_id
  }, function (data) {
    if(data.status == 200) {
    	$('.send-button').css('background-color', '#2e7be5');
        $('.send-button').css('border-color', '#2e7be5');
    	$('.wo_msg_user_dtl, .msg_srch_innr, .messages-search-icon').css('display', 'none');
      <?php if ($wo['config']['maxCharacters'] != 10000) { ?>
      $('#charsLeft').text("<?php echo $wo['config']['maxCharacters']?>");
      <?php }?>

      if(data.html.length == 0) {
        view_more_wrapper.hide();
        $('.messages-container').html('<div class="no-messages empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-info"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12" y2="8"></line></svg><?php echo $wo["lang"]["no_more_message_to_show"];?> </div>');
      } 
      else {
        $('.messages-container').html(data.html);
        view_more_wrapper.html('<a href="javascript:void(0);" title="' + data.view_more_text + '"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M13,15L15.5,17.5L16.92,16.08L12,11.16L7.08,16.08L8.5,17.5L11,15V21H13V15M3,3H21V5H3V3M3,7H13V9H3V7Z" /></svg></a>').show();
        view_more_wrapper.attr('onclick', 'Wo_getOldPageMessages(' + page_id + ','+page_user_id+');').removeClass('hidden');
        $(".messages-container").animate({
          scrollTop: $('.messages-container')[0].scrollHeight
        }, 200);
      }
      $('.text-sender-container').find('.ball-pulse').fadeOut(100);
	  $('.text-sender-container').find('.msg_progress').fadeOut(100);
    }
  });
}


function Wo_getNewMessages() {
  user_id = $('#user-id').val();
  group_id = $('#messages-group-id').val();
  page_id = $('#messages-page-id').val();
  from_id = $('#messages-from-id').val();
  to_id = $('#messages-to-id').val();
  message_id = $('.messages-container').find('.messages-wrapper:last').attr('data-message-id');
  if(user_id == 0 && group_id == 0) {
    return false;
  }
  if ($('body').attr('sending-' + user_id) == 'true' && group_id == 0) {
     return false;
  }
  if (message_id) {
    $.get(Wo_Ajax_Requests_File(), {
      f: 'messages',
      s: 'get_new_messages',
      user_id: user_id,
      group_id: group_id,
      page_id: page_id,
      from_id: from_id,
      to_id: to_id,
      message_id: message_id
    }, function (data) {
      if (data.color) {
          $(".text-sender-container .red-list").css('background', data.color);
      }
      if(data.status == 200) {
        $(".messages-container").append(data.html);
        $(".messages-container").animate({
          scrollTop: $('.messages-container')[0].scrollHeight
        }, 200);
        if(data.sender == user_id) {
          document.getElementById('message-sound').play();
          if(!$('.sendMessage').is(':focus')) {
            document.title = 'New Message ' + document_title;
          }
        }
      }
    });
  }
  setTimeout(Wo_getNewMessages, 5000);
}

function Wo_getMessageSeen() {
  var last_id = $('.messages-text:last').attr('data-message-id');
  if(!$('.messages-text:last').find('.message-seen').is(':empty')) {
    return false;
  }
  $.get(Wo_Ajax_Requests_File(), {
    f: 'messages',
    s: 'get_last_message_seen_status',
    last_id: last_id
  }, function (data) {
    setTimeout(Wo_getMessageSeen, 12000);
    if(data.status == 200) {
      $('.messages-text:last').find('.message-seen').hide().html('<i class="fa fa-check"></i> <?php echo $wo["lang"]["seen"];?> (<span class="ajax-time" title="' + data.time + '">' + data.seen + '</span>)').fadeIn(300);
      $(".messages-container").animate({
        scrollTop: $('.messages-container')[0].scrollHeight
      }, 200);
    }
  });
}

function Wo_SubmitForm(e) {

  document.title = document_title;
  <?php if ($wo['config']['maxCharacters'] != 10000) { ?>
  $('.charsLeft-message').fadeIn(200);
  <?php } ?>
  if(e.keyCode == 13 && e.shiftKey == 0) {
    e.preventDefault();
    Wo_GetMRecordLink();
  }
}

function Wo_getOldMessages(user_id) {
  view_more_wrapper = $('.view-more-wrapper');
  before_message_id = $('.messages-text:first').attr('data-message-id');
  $('.text-sender-container').find('.msg_progress').fadeIn(100);
  $.get(Wo_Ajax_Requests_File(), {
    f: 'messages',
    s: 'load_previous_messages',
    user_id: user_id,
    before_message_id: before_message_id
  }, function (data) {
    if(data.status == 200) {
      if(data.html.length == 0) {
		view_more_wrapper.html('<a href="javascript:void(0);" title="<?php echo $wo["lang"]["no_more_message_to_show"];?>"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M11,15H13V17H11V15M11,7H13V13H11V7M12,2C6.47,2 2,6.5 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20Z" /></svg></a>').show();
        view_more_wrapper.delay(2000).slideUp(200);
      } else {
        $('.messages-container').prepend(data.html);
      }
    } else {
      view_more_wrapper.hide();
    }
	$('.text-sender-container').find('.msg_progress').fadeOut(100);
  });
}
function Wo_getOldGroupMessages(group_id) {
  view_more_wrapper = $('.view-more-wrapper');
  before_message_id = $('.messages-text:first').attr('data-message-id');
  $('.text-sender-container').find('.msg_progress').fadeIn(100);
  $.get(Wo_Ajax_Requests_File(), {
    f: 'messages',
    s: 'load_previous_messages',
    group_id: group_id,
    before_message_id: before_message_id
  }, function (data) {
    if(data.status == 200) {
      if(data.html.length == 0) {
		view_more_wrapper.html('<a href="javascript:void(0);" title="<?php echo $wo["lang"]["no_more_message_to_show"];?>"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M11,15H13V17H11V15M11,7H13V13H11V7M12,2C6.47,2 2,6.5 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20Z" /></svg></a>').show();
        view_more_wrapper.delay(2000).slideUp(200);
      } else {
        $('.messages-container').prepend(data.html);
      }
    } else {
      view_more_wrapper.hide();
    }
	$('.text-sender-container').find('.msg_progress').fadeOut(100);
  });
}

function Wo_getOldPageMessages(page_id,from_id,to_id) {
  view_more_wrapper = $('.view-more-wrapper');
  before_message_id = $('.messages-text:first').attr('data-message-id');
  $('.text-sender-container').find('.ball-pulse').fadeIn(100);
  $('.text-sender-container').find('.msg_progress').fadeIn(100);
  $.get(Wo_Ajax_Requests_File(), {
    f: 'messages',
    s: 'load_previous_messages',
    page_id: page_id,
    from_id: from_id,
    to_id: to_id,
    before_message_id: before_message_id
  }, function (data) {
    if(data.status == 200) {
      if(data.html.length == 0) {
        view_more_wrapper.html('<a href="javascript:void(0);" title="<?php echo $wo["lang"]["no_more_message_to_show"];?>"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M11,15H13V17H11V15M11,7H13V13H11V7M12,2C6.47,2 2,6.5 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20Z" /></svg></a>').show();
        view_more_wrapper.delay(1000).slideUp(200);
      } else {
        $('.messages-container').prepend(data.html);
      }
    } else {
      view_more_wrapper.hide();
    }
    $('.text-sender-container').find('.ball-pulse').fadeOut(100);
	$('.text-sender-container').find('.msg_progress').fadeOut(100);
  });
}

function Wo_ShareFile() {
  document.title = document_title;
  $("#sendMessage").focus();
  $("form.sendMessages").submit();
}


function Wo_DeleteMessage(message_id) {
  $('.text-sender-container').find('.msg_progress').fadeIn(100);
  $.get(Wo_Ajax_Requests_File(), {
    f:'messages',
    s:'delete_message',
    message_id: message_id
  }, function (data) {
    if(data.status == 200) {
      $('#messageId_' + message_id).slideUp(200, function () {
        $(this).remove();
      });
    }
	$('.text-sender-container').find('.msg_progress').fadeOut(100);
  });
}
function Wo_ShowMessageOptions(id) {
    $('.deleteMessage').hide();
    $('#messageId_' + id).find('.deleteMessage').show();
}
function Wo_ResizeVideoPlayer(message_id) {
  var message_container = $('#messageId_' + message_id);
  message_container.find('.message-media').toggleClass('full-size');
}


// Hide Header on on scroll down
$(function(){
    var lastScrollTop = 0, delta = 5;
    $('.messages-container').scroll(function(event){
       var st = $(this).scrollTop();
       
       if(Math.abs(lastScrollTop - st) <= delta)
          return;
       
if (st > lastScrollTop){
       // downscroll code
    $(".messages-load-more-messages").addClass("above_header")
       .hover(
           function() {
               $(".messages-load-more-messages").removeClass("above_header");
           }
       )
   } else {
      // upscroll code
      $(".messages-load-more-messages").removeClass("above_header");
   }
       lastScrollTop = st;
    });
});
function Wo_CreateGChat(e){
    e.preventDefault();
    $('#create_group_chat').modal('show');
}
function Wo_GetGChatParticipants(name){
    if (!name) {
        return false;
    }
    $.ajax({
        url: Wo_Ajax_Requests_File(),
        type: 'GET',
        dataType: 'json',
        data: {f: 'chat',s:'get_parts',name:name},
    })
    .done(function(data) {
        if (data.status == 200) {
            $('.group_chat_mbr_list').html(data.html);
        }
        else{
          $('.group_chat_mbr_list').html('<p class="no_participant"><?php echo $wo['lang']['no_result']; ?></p>');
        }
    })
    .fail(function() {
        console.log("error");
    })   
}
var chat_part_array = [];
$(document).on('click', '.group_chat_mbr_part', function(event) {
        event.preventDefault();
        var self_id    = $(this).attr('id');
        if ($.inArray(self_id, chat_part_array) == -1) {
            chat_part_array.push(self_id);
            $("#group_chat_mbrs").text(chat_part_array.length);
            
            $(this).fadeOut(100,function(){
                $("#chat_group_users").val(chat_part_array.join());
                $(this).remove();
            })
        }
        else{
          $(this).addClass('disabled').removeAttr('title');
        }
    });

jQuery(document).ready(function($) {
	$('#insert-caht-parts').ajaxForm({
      url: Wo_Ajax_Requests_File() + '?f=chat&s=create_group',
      type:'POST',
      dataType:'json',

      beforeSend: function() {
        Wo_progressIconLoader($('#insert-caht-parts').find('button'));
		$('#insert-caht-parts').find('.modal-footer .ball-pulse').fadeIn(100);
      },
      success: function(data) {
        if (data['status'] == 200) {
            $("#create_group_chat").modal('hide');
            Wo_OpenChatTab(0,data.group_id);
            $("#insert-caht-parts").find('#reset').trigger('click');
            $(".group_chat_mbr_list").empty();
            $(".group_chat_avatar").empty();
            chat_part_array = [];
        }
        else if (data.status == 500){
            $("#insert-caht-alert").html('<div class="alert alert-danger">' + data['message'] + '</div>');
        } 
        $('#insert-caht-parts').find('.modal-footer .ball-pulse').fadeOut(100);
    }});
});

</script>
<style>.message-text a.hash{color: #a84849 !important;}</style>

<style>
@media(max-width:992px){
.text-sender-container{height:100%;}
.text-sender-container .messagejoint{position: fixed;bottom: 0;right: 0;left: 0;}
}
</style>
<div class="modal fade" id="create_group_chat" role="dialog">
	<div class="modal-dialog modal-sm">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg></span></button>
				<h4 class="modal-title">
					<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-users"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M23 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path></svg>
					<?php echo $wo['lang']['create_new_group']; ?>
				</h4>
			</div>
			<form id="insert-caht-parts" class="wo_create_chat_group">
				<div class="modal-body">
					<div id="insert-caht-alert"></div>
					<div class="form-group input-group">
						<span class="input-group-addon pointer" onclick="$('#group_chat_avatar').trigger('click');">
							<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-camera"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"></path><circle cx="12" cy="13" r="4"></circle></svg>
						</span>
						<input type="text" class="form-control" name="group_name" placeholder="<?php echo $wo['lang']['name']; ?>">
					</div>
					<div class="w100">
						<div class="group_chat_avatar"></div>
						<div class="clear"></div>
					</div>
					<div class="form-group input-group">
						<span class="input-group-addon" id="group_chat_mbrs">0</span>
						<input type="text" class="form-control" placeholder="<?php echo $wo['lang']['add_parts']; ?>" onkeydown="Wo_GetGChatParticipants(this.value)">
					</div>
					<div class="form-group">
						<div class="group_chat_mbr_list"></div>
					</div>
				</div>
				<div class="modal-footer">
					<div class="ball-pulse"><div></div><div></div><div></div></div>
					<button id="delete-all-post" type="submit" class="btn btn-main">
						<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-plus"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
						<?php echo $wo['lang']['create']; ?>
					</button>
				</div>
				<input type="hidden" name="parts" id="chat_group_users">
				<input type="reset" id="reset" class="hidden">
				<input type="file" name="avatar" class="hidden" id="group_chat_avatar" onchange="$('.group_chat_avatar').html('<img src=\'' + window.URL.createObjectURL(this.files[0]) + '\' alt=\'Picture\'>');" accept="image/jpeg,image/png,image/gif">
			</form>
		</div>
	</div>
</div>