function addFriend()
{
	var dialog_buttons = {};

	dialog_buttons[sc.string("SC_COMMON_TEXT_NO")] = function() { 
		$(this).dialog("close"); 
	};

	dialog_buttons[sc.string("SC_COMMON_TEXT_YES")] = function() { 
		addFriendSave(); 
		$(this).dialog("close");
	};

	$('#confirm-dialog').dialog('option', 'buttons', dialog_buttons);
	
	showConfirmation(sc.string("SC_USER_PROFILE_FRIEND_REQ"), sc.string("SC_USER_PROFILE_AKS_TO_ADD_FRIEND"));
}

function addFriendSave()
{
	$.post(
		"/user/organize/add_friend",
		{"user_id" : sc.string("user_id")},
		function (json) {
		
			var dialog_buttons = {};
			
			dialog_buttons[sc.string("SC_COMMON_TEXT_OK")] = function () {
				$(this).dialog("close");
			};
		
			$('#confirm-dialog').dialog('option', 'buttons', dialog_buttons);
			
	    if (json && json.success) {
	    
	    	$('#friend_statatus').html(sc.string("SC_USER_ADDED_FRIEND"));	    	
	    	showConfirmation(sc.string("SC_USER_PROFILE_FRIEND_REQ"), sc.string("SC_USER_ADDED_FRIEND"));
	    	$("#add").remove();

			} else {
			
	    	showConfirmation(sc.string("SC_COMMON_TEXT_ERROR_OCCURED"), sc.string("SC_COMMON_TEXT_ERROR_OCCURED"));		
			}		
		},
		"json"
	);
}

$(function () {

	$("textarea#body").autogrow();
	$("#post-comment input[type='button']").click(function () {
		sendComment();
	});
	addCommentsBorder();
	
	$(".delete-comment a").live("click", function () {
	
		var that = this;
		var comment_id = $(this).attr("href").split("/").pop();
	
		$.post(
			"/user/ajax/deleteProfileComment",
			{comment_id: comment_id},
			function (json) {
				
				if (json && json.success) {
				
					$(that).closest(".comment-tr").fadeOut("fast", function () {

						$(this).remove();
						
						addCommentsBorder();
						
					});
				}
			},
			"json"		
		);

		return false;
	});
	
});

var defaultmsg = $("#post-comment #body").val();

function deletePhotoComment(obj)
{
		commentId = $(obj).attr('rel');
		
		if (commentId != '')
		{
			
			$.ajax({
				dataType: "json",
				url: '/user/ajax/deletePhotoComment/' + commentId,
				method: "POST",
				success: function (json) {
	
					if ( json.success) 	$(obj).parents('.comment-tr').fadeOut();
			
				}
			});
	
		
		}
		
		return;

}

function sendComment()
{
	if (defaultmsg != $("#post-comment #body").val()) {
	
		defaultmsg = $("#post-comment #body").val();
		
		$('#post-comment').ajaxSubmit({
			dataType: "json",
			success: function (json) {

				if ( ! json.success) {
		
					$('#post-comment .error').html(json.error);
				
				} else {
				
					$("#post-comment #body").val('');
					$('#post-comment .error').html('');
					$('#user-comments').append(json.html);
					addCommentsBorder();
									
				}
	
				return false;		
			}
		});
	}
		
	return false;
}

