function toggletab(tab) {
	$('.boxlist').hide();
	$('.morelink').hide();
	$('#user' + tab).show();
	$('#more' + tab).show();
	$('.rlink').removeClass('rcurrent');
	$('#toggle' + tab).addClass('rcurrent');
}

function frienddone(data, status) {
	if (data.success === true) notice(data.message, '#090');
	else notice(data.message, '#900');
	$('.addfriend').hide();
	loading();
}

function friend(username) {
	loading();
	$.post(webpath + "/ajax/friend.php", {username: username}, frienddone, "json");
}

function unfriend(username) {
	loading();
	$.post(webpath + "/ajax/unfriend.php", {username: username}, frienddone, "json");
}


function blockcommentsdone(data, status) {
	if (data.success === true) {
		notice(data.message, '#090');
		
		var search = '';
		var replace = '';
		if (data.message.toLowerCase().indexOf('unblock') !== -1) {
			search = '\\bUnblock';
			replace = 'Block';
		} else {
			search = '\\bBlock';
			replace = 'Unblock';
		}
		
		$('.block' + data.text + "text").each(function(i) {
			var newText = $(this).text();
			newText = newText.replace(new RegExp(search.toLowerCase()), replace.toLowerCase(), 'g');
			newText = newText.replace(new RegExp(search), replace, 'g');
			$(this).text(newText);
		});
		
		$('.block' + data.text).unbind('click');
		$('.block' + data.text).click(function() {
			blockcomments(data.text, replace.toLowerCase());
			return false;
		});
	} else {
		notice(data.message, '#900');
	}
	loading();
}

function blockcomments(username, action) {
	loading();
	$.post(webpath + "/ajax/blockcomments.php",
		{username: username, action: action}, blockcommentsdone, "json");
}

function removeaction(id) {
	function done(data, status) {
		if (data.success === true) {
			notice(data.message, '#090');
			$('#action' + id).fadeOut('slow');
		} else notice(data.message, '#900');
		loading();
	}
	loading();
	$.post(webpath + "/ajax/deleteevent.php", {id: id}, done, "json");
}


var type = 'user';

$(document).ready(function() {
	checkformlen("comment", 1000);

	$('#commentform').ajaxForm({
		beforeSubmit: function() { return checkform('comment', maxcommentlen); },
		dataType: 'json',
		success: addcomment
	});
});
