<?php

require_once '../incfiles/core.php';
require_once '../incfiles/auth.php';
require_once '../autoload/navigation.php';
require_once '../autoload/user.php';
require_once '../autoload/smiles.php';
require_once '../incfiles/user.php';

if (empty($user_id)) go(URL);

$rand = rand(0000,9999);

require_once 'incfiles/func.php';
require_once 'handler/msg.php';

$title = lang('Мини-Чат','Міні-Чат');
require_once '../incfiles/head.php';

	?>
	<script type="text/javascript">
	$(function(){
			$('#form').on('submit', function(e){
		    e.preventDefault();
		    var $that = $(this),
		        formData = new FormData($that.get(0));
		    $.ajax({
		      url: $that.attr('action'),
   		     type: $that.attr('method'),
		      contentType: false,
		      processData: false,
		      data: formData,
		      success: function(response){
 		       if(response){
					$('#content_chat').load($that.attr('action')+ '#content_chat .chat');
					$('#textarea').val('');
					$("#form_content").html('');
					$("#form_remsg").html('');
 		      }
		    }
		    });
		  });
		});
	</script>
	<?

echo '<div class="title">'.lang('Мини-Чат','Міні-Чат').'</div>
	<div class="block2">
	<form id="form" action="'.URL.'/chat/" method="post">
	<input id="textarea" class="input" name="msg" value=""/>
	<div id="form_remsg"></div>
	<input class="button2" type="submit" value="'.lang('Написать','Написати').'">
	<a class="button3" href="'.URL.'/ajax/smiles.php" onclick="FormContent.Smiles(this.href); return false"><img src="'.URL.'/design/img/smile.png"/></a>
	<a class="for_mobile button3" href="'.URL.'/chat/?r='.$rand.'" onclick="Page.Go(this.href); return false"><img src="'.URL.'/design/img/refresh.png"/></a>
	';
	require_once '../ajax/include_stiker.php';
	echo'
	</form>
	</div><div id="form_content"></div>
	<div id="content_chat"><div class="chat">';

	$result = mysql_query("SELECT * FROM `chat` ORDER by `time` DESC LIMIT 0,15");
	
	while ($arr = mysql_fetch_array($result)) echo '<div class="block"><a href="" onclick="Chat.reMsg('.$arr['user_id'].',\''.user_name3($arr['user_id']).'\'); return false"><b>'.user_name3($arr['user_id']).'</b></a> '.vtime($arr['time']).' '.(!empty($arr['for_id']) && $arr['for_id']==$user_id?'<font color="#E66916">'.links(smiles(hastag($arr['msg']))).'</font>':links(smiles(hastag($arr['msg'])))).'</div>';
	
	echo '</div></div>
	<div class="block"><a class="button_a" href="'.URL.'/chat/history.php" onclick="Page.Go(this.href); return false">'.lang('Просмотреть историю чата','Переглянути історію чату').'</a></div>';

	?>
	<script type="text/javascript">
	$(document).ready(function(){
		setInterval("$('#content_chat').load('/chat/index.php #content_chat .chat')",10000);
	});
	</script>
	<?

require_once '../incfiles/foot.php';


?>