var news = {
	get: function () {
		$('#load_text > div').load('/faq/ #get_text:last')
	}
}
news.get();
chat = {
	reload: function () {
		$.get('/mchat/', function (data) {
			$('#chat_pole').html('');
			$('.number_chat:lt(40)', data).each(function () {
				$('#chat_pole').append($(this).html())
			});
		});
	},
	post: function () {
		if ($("#chat_mess").val().length >= 2) {
			$.post('/mchat/', {
				a: '18',
				ajax: '1',
				numa: '0',
				mcmessage: $("#chat_mess").val()
			},
			function (qwe) {
				$('#chat_mess').val('');
				_uWnd.alert('<font color="green">Отправка сообщения, пожалуйста подождите</font>', '', {
					tm: 1000,
					w: 300,
					h: 35
				});
				setTimeout(function () {
					chat.reload()
				},
				1000);
			});
		} else {
			_uWnd.alert('<font color="red">Не заполнен текст сообщения</font>', '', {
				tm: 3000,
				w: 300,
				h: 35
			});
		}
	}
};
chat.reload();
$('#chat_mess').keydown(function (e) {
	if (e.ctrlKey && e.keyCode == 13) {
		chat.post();
	}
});
setInterval(function () {
	_uWnd.alert('<font color="green">Чат обновлен</font>', '', {
		tm: 2000,
		w: 300,
		h: 35
	});
	chat.reload();
},
10000);


--------------------------------------------------------


function get_selection() {
	if (window.getSelection) {
		selection = window.getSelection();
		selection = selection.replace(/\r\n\r\n/gi, "_doublecaret_");
		selection = selection.replace(/\r\n/gi, " ");
		while (selection.indexOf(" ") != -1) selection = selection.replace(/ /gi, "");
		selection = selection.replace(/_doublecaret_/gi, "\r\n\r\n");
	} else selection = document.selection.createRange().text;
}
function add_comm(message) {
	var symbols = message.length;
	if (symbols == 0) {
		$('#message').css('height', '50px');
		$('#Length').animate({
			opacity: '0.0'
		},
		300);
		$('#message').focus();
	} else {
		$('#Length').animate({
			opacity: '1.0'
		},
		300);
		$('#Length').html('Введено символов: <b>' + symbols + '</b>');
	}
}

----------------------------------------------------------------------------------

function add_comm(message) {
	var symbols = message.length;
	if (symbols == 0) {
		$('#message').css('height', '50px');
		$('#Length').animate({
			opacity: '0.0'
		},
		300);
		$('#message').focus();
	} else {
		$('#Length').animate({
			opacity: '1.0'
		},
		300);
		$('#Length').html('Введено символов: <b>' + symbols + '</b>');
	}
}
function setCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	} else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}
function eraseCookie(name) {
	setCookie(name, "", -1);
}
function closeBlock(cls) {
	$('.' + cls).fadeOut(800);
	setCookie(cls, 'b', 365);
	$('#restore').fadeIn(800);
}
function returnBlocks() {
	$('#restore').fadeOut(800);
	for (i = 0; i <= numbl; i++) {
		eraseCookie('b_close' + i);
		$('.b_close' + i).fadeIn(800);
	}
}
function clear_Comm() {
	$('#message').val('');
}
function time(number, titles) {
	cases = [2, 0, 1, 1, 1, 2];
	return titles[(number % 100 > 4 && number % 100 < 20) ? 2 : cases[(number % 10 < 5) ? number % 10 : 5]];
}
