$().ready(function(){
	
	$('.user-label-ajax a.contacts-icon.is-not-contact').click(function(event){
		
		event.preventDefault();
		
		$.ajax({
			async: true,
			url: $(this).attr('href'),
			type: 'post',
			dataType: 'json',
			data: {
				ajaxRequest:1
			},
			error: function(req, stat, error)
			{
				alert("Wystąpił błąd przy dodawaniu użytkownika do listy kontaktów. Przepraszamy.");
			},
			success:function(data)
			{
				if(data.success)
				{
					var userLabel = $('.user-label[name="client_'+data.id_added_client+'"]');
					
					userLabel.children('a.contacts-icon').removeClass('is-not-contact').addClass('is-contact')
					.attr('title', 'Użytkownik jest na Twojej liście kontaktów')
					.attr('href', "")
					.unbind('click');
				}
				else
				{
					alert("Wystąpił błąd: "+data.error);
				}
			}
		});
		
		
		
	});
	
	
	
});
