function friends_add(id)
{
	if (ajax_load) return;
	
	ajax_load = true;
	xajaxRequestUri="/index.php/author.friends.js";
	xajax.call("friends_add", ['<xjxquery><q>id='+ id +'</q></xjxquery>'], 1);
	return false;
}

function friends_remove(id)
{
	if (ajax_load || !confirm('Вы действительно хотите удалить друга?')) return;
	
	ajax_load = true;
	xajaxRequestUri="/index.php/author.friends.js";
	xajax.call("friends_remove", ['<xjxquery><q>id='+ id + (arguments[1] ? '&req=1' : '') + '</q></xjxquery>'], 1);
	return false;
}

function friends_accept(id)
{
	if (ajax_load) return;
	
	ajax_load = true;
	xajaxRequestUri="/index.php/author.friends.js";
	xajax.call("friends_accept", ['<xjxquery><q>id='+ id + '</q></xjxquery>'], 1);
	return false;
}

function friends_reject(id)
{
	if (ajax_load) return;
	
	ajax_load = true;
	xajaxRequestUri="/index.php/author.friends.js";
	xajax.call("friends_reject", ['<xjxquery><q>id='+ id + '</q></xjxquery>'], 1);
	return false;
}

function friends_onload(response)
{
	ajax_load = false;
	switch(response)
	{
		case 'error' : alert('Произошла ошибка'); break;
		case 'added': 
			if (_$('friends_add_div')) _$('friends_add_div').style.display = 'none';
			if (_$('friends_remove_div')) _$('friends_remove_div').style.display = arguments[1] ? '' : 'none';
			if (_$('friends_request_div')) _$('friends_request_div').style.display = arguments[1] ? 'none' : '';
		break;
		case 'removed':
			if (_$('friends_add_div')) _$('friends_add_div').style.display = '';
			if (_$('friends_remove_div')) _$('friends_remove_div').style.display = 'none';
			if (_$('friends_request_div')) _$('friends_request_div').style.display = 'none';
			
			if (arguments[1])
			{
				if (_$('request_links_' + arguments[1]))
					hide(_$('request_links_' + arguments[1]))
				if (_$('friend_links_' + arguments[1]))
				{
					_$('friend_links_' + arguments[1]).innerHTML = 'участник удален';
					show(_$('friend_links_' + arguments[1]));
				}
			}
		break;
		case 'accepted':
			if (arguments[1])
			{
				if (_$('request_links_' + arguments[1]))
					hide(_$('request_links_' + arguments[1]))
				if (_$('friend_links_' + arguments[1]))
					show(_$('friend_links_' + arguments[1]));
			}
		break;
		case 'rejected':
			if (arguments[1])
			{
				if (_$('request_links_' + arguments[1]))
					hide(_$('request_links_' + arguments[1]))
				if (_$('friend_links_' + arguments[1]))
				{
					_$('friend_links_' + arguments[1]).innerHTML = 'заявка отклонена';
					show(_$('friend_links_' + arguments[1]));
				}
			}
		break;
	}
}
