function open_auth_form()
{
	return false;
}

function open_signup_form()
{
	return false;
}

function servers_update()
{
	$.get(home+'templates/SquareLine/php/servers_update.php', function(){});

	return null;
}

function server_list(limit)
{
	$.ajax({
		type: 'POST',
		url: home+'templates/SquareLine/php/servers.php',
		data: 'token='+$('#token').val()+'&limit='+limit,
		success: function(data)
		{
			$('#servers').html(data);
		}
	});

	return null;
}

function news_list(s, c, l)
{
	$.ajax({
		type: 'POST',
		url: home+'templates/SquareLine/php/news.php',
		data: 'start='+s+'&class='+c+'&limit='+l+'&token='+$('#token').val(),
		success: function(data)
		{
			$('#news').html(data);
		}
	});

	return null;
}

function lastforum_list()
{
	$.ajax({
		type: 'POST',
		url: home+'templates/SquareLine/php/lastforum.php',
		data: 'limit=4&token='+$('#token').val(),
		success: function(data)
		{
			$('#lastforum').html(data);
		}
	});

	return null;
}

function lastsignup_list()
{
	$.ajax({
		type: 'POST',
		url: home+'templates/SquareLine/php/lastsignup.php',
		data: 'limit=4&token='+$('#token').val(),
		success: function(data)
		{
			$('#lastsignup').html(data);
		}
	});

	return null;
}

function topusers_list()
{
	$.ajax({
		type: 'POST',
		url: home+'templates/SquareLine/php/topusers.php',
		data: 'token='+$('#token').val(),
		success: function(data)
		{
			$('#topusers').html(data);
		}
	});

	return null;
}

function forums()
{
	$.ajax({
		type: 'POST',
		url: home+'templates/SquareLine/php/forums.php',
		data: 'token='+$('#token').val(),
		success: function(data)
		{
			$('#forums').html(data);
		}
	});

	return null;
}

function topics(s, id)
{
	$.ajax({
		type: 'POST',
		url: home+'templates/SquareLine/php/topics.php',
		data: 'start='+s+'&id='+id+'&token='+$('#token').val(),
		success: function(data)
		{
			$('#topics').html(data);
		}
	});

	return null;
}

function chatmsg_list_last()
{
	$.ajax({
		type: 'POST',
		url: home+'templates/SquareLine/php/chat.php',
		data: 'lastmsg=1&token='+$('#token').val(),
		success: function(data)
		{
			window.chat_interval = setInterval(chatmsg_list_update, 5000);

			$('#chatmsgs').html(data);
			$('#chatmsgs').append('<div class="clear"></div>');

			$('[tooltip="yes"]').tooltip();

			block = document.getElementById('chatmsgs');
			block.scrollTop = block.scrollHeight;
		}
	});

	return null;
}

function chatmsg_list_update(go)
{
	$.ajax({
		type: 'POST',
		url: home+'templates/SquareLine/php/chat.php',
		data: 'lastmsg='+$('#last_mess').val()+'&token='+$('#token').val(),
		success: function(data)
		{
			$('#chatmsgs').html(data);
			$('#chatmsgs').append('<div class="clear"></div>');

			$('[tooltip="yes"]').tooltip();

			block = document.getElementById('chatmsgs');

			if(chat_scroll_auto)
				setTimeout("block.scrollTop = block.scrollHeight", 2000);

			if(go)
				play_sound('#chat_sound_playes');
		}
	});

	return null;
}

function chatmsg_list_top()
{
	$.ajax({
		type: 'POST',
		url: home+'templates/SquareLine/php/chat.php',
		data: 'topmsg=1&token='+$('#token').val()+'&start='+load_val,
		success: function(data)
		{
			height = document.getElementById('chatmsgs').scrollHeight - document.getElementById('chatmsgs').scrollTop;

			$('#chatmsgs').prepend(data);

			$('[tooltip="yes"]').tooltip();

			document.getElementById('chatmsgs').scrollTop = document.getElementById('chatmsgs').scrollHeight - height;

			load_val = $('#load_val').val();
		}
	});

	return null;
}

function chatmsg_send(text)
{
	if($('#stop_sending').val() != '0')
		return false;

	msg = text != undefined ? text : encodeURIComponent($('#chatmsgtext').val());

	$.ajax({
		type: 'POST',
		url: home+'templates/SquareLine/php/chat.php',
		data: 'sendmsg=1&token='+$('#token').val()+'&text='+msg,
		success: function()
		{
			if(text == undefined)
				$('#chatmsgtext').val('');

			chatmsg_list_update(true);

			$('#stop_sending').val('1');

			setTimeout("$('#stop_sending').val('0')", 3000);
		}
	});

	return false;
}

function chatmsg_del(id)
{
	NProgress.start();

	$.ajax({
		type: 'POST',
		url: '../ajax/actions_b.php',
		data: 'phpaction=1&token='+$('#token').val()+'&dell_chat_message=1&id='+id,
		success: function()
		{
			$('#chat-message-'+id).fadeOut();

			NProgress.done();

			setTimeout(show_ok, 500);
		}
	});

	return false;
}

function chatmsg_edit(id)
{
	$('#message_text_'+id).hide();
	$('#message_text_e_'+id).show();
	$('#edit_message_'+id).attr('onclick', 'chatmsg_save('+id+'); return false');
	$('#edit_message_'+id).html('[сохранить]');
}

function chatmsg_save(id)
{
	NProgress.start();

	$.ajax({
		type: 'POST',
		url: '../ajax/actions_b.php',
		data: 'phpaction=1&token='+$('#token').val()+'&save_chat_message=1&id='+id+'&text='+encodeURIComponent($('#message_text_e_'+id).val()),
		dataType: 'json',
		success: function(result)
		{
			NProgress.done();

			if(result.status == 1)
			{
				$('#message_text_e_'+id).hide();
				$('#message_text_'+id).show();
				$('#edit_message_'+id).attr('onclick', 'chatmsg_edit('+id+'); return false');
				$('#edit_message_'+id).html('[редактировать]');
				$('#message_text_'+id).html(result.text);

				setTimeout(show_ok, 500);
			}else
				setTimeout(show_error, 500);
		}
	});
}

function new_comment_send(id, msg)
{
	NProgress.start();

	var text = msg != undefined ? msg : encodeURIComponent($.trim(tinymce.get('text').getContent()));

	$.ajax({
		type: 'POST',
		url: '../ajax/actions_a.php',
		data: 'phpaction=1&token='+$('#token').val()+'&send_new_comment=1&id='+id+'&text='+text,
		dataType: 'json',
		success: function(data)
		{
			NProgress.done();

			if(data.status == '1')
			{
				clean_tiny('text');

				load_new_comments(id);

				setTimeout(show_ok, 500);
			}else{
				$('#global_result span.result_error').html(data.reply);
				$('#global_result span.result_error_b').html(data.reply);

				setTimeout(show_error, 500);
				setTimeout(function() {$('#global_result span.result_error').html(''); $('#global_result span.result_error_b').html('')}, 2000);
			}
		}
	});
}

function remove_news(id, type)
{
	if(confirm('Вы уверены?'))
	{
		NProgress.start();

		$.ajax({
			type: 'POST',
			url: '../ajax/actions_c.php',
			data: 'phpaction=1&token='+$('#token').val()+'&dell_new=1&id='+id,
			dataType: 'json',
			success: function(data)
			{
				NProgress.done();

				if(data.status == '1')
				{
					setTimeout(show_ok, 500);

					if(type == '1') location.reload(); else location.href = 'index';
				}else
					setTimeout(show_error, 500);
			}
		})
	}

	return false;
}