function addFriend(user_id){
	
	$j("#af_" + user_id).html("Sending request...");
	
	if(user_id!=""){
		$j.ajax({
			type: "POST",
			data: "data="+JSON.stringify({"user_id":user_id,"status":""}),
			url: g_webroot+"friends/ajax_addFriend",
			success: function(data){
				if( data == 1 ){
					$j("#af_" + user_id).html("<span class='user-div-request-sent'>Request sent.</span>");
					
				} else if( data == "PERMISSION_ERROR" ){
					showFlashMini("info","Start making friends.","To add a new friend please "+login_link(), "af_" + user_id);
					if( g_isLoggedIn ){
						$j("#af_" + user_id).html("Request failed");
					} else {						
						$j("#af_" + user_id).html("Login required");
					}
					
				} else {
					showFlashMini("error","Error!","Sorry we could not add this user as your friend. Please try again later.", "af_"+user_id);
					$j("#af_" + user_id).html("Request failed");
				}
			},
			error: ajax_communication_error
		});
	}
}

function endFriendship(user_id, username){
	
	if(!empty.test(user_id) && confirm("Are you sure you want to end your friendship with " + username + "?")){
		$j("#af_" + user_id).html("Ending friendship...");
		
		$j.ajax({
			type: "POST",
			data: "data="+JSON.stringify({"user_id":user_id,"status":""}),
			url: g_webroot+"friends/ajax_delFriend",
			success: function(data){
				if( data == 1 ){
					$j("#af_" + user_id).html("<span class='user-div-request-sent'>friendship ended</div>");
					showFlashMini("success","Friendship ended.","Your friendship with " + username + " has ended.", "af_"+user_id);
					
				} else if( data == "PERMISSION_ERROR" ){
					showFlashMini("info","Login required.","You must "+login_link() + " to end your friendship ", "af_" + user_id);
					if( g_isLoggedIn ){
						$j("#af_" + user_id).html("Request failed");
					} else {						
						$j("#af_" + user_id).html("Login required");
					}
					
				} else {
					showFlashMini("error","Error!","Sorry we could end your friendship with " + username + ". Please try again later", "wrapper_"+user_id);
					$j("#af_" + user_id).html("Request failed");
				}
			},
			error: ajax_communication_error
		});
	}
}

/*function processFriendRequest(user_id,selectElement){
	var status = selectElement.options[ selectElement.selectedIndex ].value;
	var statusLabel = selectElement.options[ selectElement.selectedIndex ].text;

	disableElement(selectElement);

modified by Yoav: Feb 23, 2008 - to allow for links instead of select input
*/
function processFriendRequest(user_id,status, statusLabel){
	
	$j("#af_" + user_id).html("Processing request...");
	
	if(!empty.test(user_id) && !empty.test(status) ){
		$j.ajax({
			type: "POST",
			data: "data="+JSON.stringify({"user_id":user_id,"status":status}),
			url: g_webroot+"friends/ajax_addFriend",
			success: function(data){
				if( data == 1 ){
					$j("#af_" + user_id).html("<span class='user-div-request-sent'>" + statusLabel+"d!</div>");
				
				} else if( data == "PERMISSION_ERROR" ){
					showFlashMini("info","Login required.","You must "+login_link()+ " to respond to a request ", "af_" + user_id);
					if( g_isLoggedIn ){
						$j("#af_" + user_id).html("Request failed");
					} else {						
						$j("#af_" + user_id).html("Login required");
					}
					
				} else {
					showFlashMini("error","Error!","Sorry we could not process your request. Please try again later.", "af_"+user_id);
					$j("#af_" + user_id).html("Request failed.");
				}
			},
			error: ajax_communication_error
		});
	}
}

function selectNotificationUser(user_id){
	$j.ajax({
		type: "POST",
		url: g_webroot + "users/ajax_getUserDetails/"+user_id,
		success: function(data){
			if( data == 0 ){
				alert('user not found!');
			} else {
				tb_remove();
				$j("#contributed_by_user").html(data);
				$j("#NotificationContributedBy").val(user_id);
				$j("#removeContributedBy").css("display", "block");
			}
		}
	});
}
