<?
include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';
only_reg();
echo'<script type="text/javascript" src="/mail/jquery.js"></script>';
echo'<link rel="stylesheet" href="/mail/css/website.css " type="text/css" media="screen" />'; 
//echo'<script type="text/javascript"  src="/mail/shoutbox.js"></script>';
echo'<script type="text/javascript"  src="/mail/custom.js"></script>';
echo'<link rel="stylesheet" href="/mail/style.css" type="text/css" media="screen" />'; 
?>
<script>
jQuery(function()
 { 
jQuery('#message').click(function() 
{
 $.ajax({
type: "POST", url: "/mail/read.php",data: "id=<?echo"$ank[id]";?>",
});
});
 
});
function emoticon(text) {
	var txtarea = document.message.text;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}




$(document).ready(function(){
	//global vars
	var inputUser = $("#nick");
	var inputMessage = $("#message");
	var loading = $("#loading");
	var messageList = $(".content > p");
	
	
				

	
		
	function updateShoutbox(){

		//just for the fade effect
          loading.fadeIn("5");	
        messageList.fadeIn("5");
		
   
		//send the post to shoutbox.php







function reload(){

 
		$.ajax({

			type: "POST", url: "/mail/shoutbox.php", data: "action=update&id=<?echo"$ank[id]";?>",
			complete: function(data){
				loading.fadeOut("5");
				messageList.html(data.responseText);
				messageList.fadeIn("5");
			}
		});



}





setInterval(reload,7000);

	}

	

	
	//check if all fields are filled
	function checkForm(){
		if( inputMessage.attr("value"))
			return true;
		else
			return false;
	}
	
	//Load for the first time the shoutbox data
	updateShoutbox();
	
	//on submit event
	$("#form").submit(function(){
 
		if(checkForm()){
			var nick = inputUser.attr("value");
			var message = inputMessage.attr("value");
			//we deactivate submit button while sending

                       $("#message").val("");
                       
			$("#send").attr({ disabled:true, value:"Отправляю..." });
			$("#send").blur();
			//send the post to shoutbox.php
                           
			$.ajax({
				type: "POST", url: "/mail/shoutbox.php", data: "action=insert&id=<?echo"$ank[id]";?>&nick=" + nick + "&message=" + message,
				complete: function(data){
					messageList.html(data.responseText);
					updateShoutbox();
					//reactivate the send button
					$("#send").attr({ disabled:false, value:"Отправить" });
				}
			 });
		

}


		else alert("Пожалуйста, напишите сообщение");
		//we prevent the refresh of the page after submitting the form
		return false;
	});
});

jQuery(function()
 { 
jQuery('#send').click(function() 
{ 
jQuery('#messag').val("");

});
 
});
</script>
<?

echo'<div class="popupbox" id="popuprel">';



              

echo"<div id='menu'>";

echo "<div id='chat'>\n";



echo"<div id='container'>";
###############################################
//удаление всех сообщений
#####################################################
//$kol=mysql_result(mysql_query("SELECT COUNT(*) FROM `shoutbox`"), 0); 




#########################################################
echo"<div id='scroll'>";
echo"<div class='content'>";

echo"<div id='loading'><img src='/mail/loading.gif' alt='Загрузка...'/></div><p>";
echo"</div>";
echo"</div>";
echo"</div>";
echo"</div>";



######################################################
//форма отправки сообщения
########################################################

echo"<div id='submenu'>";
echo '<form method="post"  name="message" id="form">';

echo "<div id='soob'>Сообщение(мах 300)</div></a><br />\n<textarea name='text'  id='message'></textarea><br />\n";




echo '<input id="send" value="Отправить" type="submit">';


echo '</form>';


echo"</div>";
echo"</div>";

echo"</div>";
echo"</div>"; 
             
echo'<div id="fade"></div>';




echo'<img src="/img/tabor/leter.gif" alt="" class="icon"/><a href="javascript:void(0)" rel="popuprel" class="popup"> Диалоги</a></br>';  

?>