<?php
session_start();
header("Content-type: text/html; charset=windows-1251");
define("PATH", $_SERVER['DOCUMENT_ROOT']);
include(PATH."/core/func.php");
include(PATH."/core/db.php");
include(PATH."/core/set.php");
include(PATH."/core/define.php");

	db_connect();
	$res = db_query("SELECT * FROM `".DBpref."chat` ORDER BY `id` DESC LIMIT 50");
	db_close();
	
	while($row = db_assoc($res)){
	     
		$row["text"] = str_replace("gif*", "gif'>", $row["text"]);
	    $row["text"] = str_replace("*", "<img src='img/cabinet/smiles/", $row["text"]);
	    $text = $row["text"];
		$text = str_replace("<img", "?img", $text);
		$text = htmlspecialchars($text,ENT_NOQUOTES, "windows-1251");
		$text = str_replace("?img", "<img", $text);
	    $dat0 = explode(" ", $row["dat"]);
$dat1 = explode(":", $dat0[1]);
		echo "<a target='_blank' href='/?p=wprofile&login=".htmlspecialchars($row["login"])."'><strong>".htmlspecialchars($row["login"])."</strong></a>";
        //echo htmlspecialchars($row["text"],ENT_NOQUOTES, "windows-1251");
		echo '('.$dat1[0].":".$dat1[1].'): '.$text.'<br /><br />';
		//echo '('.$dat1[0].":".$dat1[1].'): '.htmlspecialchars($row["text"],ENT_NOQUOTES, "windows-1251").'<br /><br />';
	}

?><script type="text/javascript">		
$(function(){
						
						$('#chat .cont a').click(function(){
							$('#fchat textarea').val($(this).text() + ', ' + $('#fchat textarea').val());
							return false;
						});
						});
	</script>	