/**
* Javascript for Profiles Page
*
* @package js
* @author Tim Carr
* @version 1
* @copyright fish in a bottle 2009
*/

$(document).ready(function() {
    // Add Friend Link on profile
    $('a.addFriend').bind('click', function() { 
        var userID = $(this).attr("id").split("_")[1];
        
        softConfirm("<p>Do you want to add this person as a friend?</p>", 
                    function(){
                        // User clicked Yes - run jQuery POST
                        $.post(
                            "ajax/ajax.Friends.php",
                            {
                                action: 'addFriend',
                                userID: userID
                            },
                            function (data) {
                                if (eval(data)) {
                                    // Friend request successful
                                    // Change Add Friend Button to Application Pending
                                    $("#friendStatus").html("Friend Request Pending");
                                
                                    // Show Confirmation
                                    softAlert("<p>Friend Request Sent</p>", alertOff);
                                } else {
                                    // Already a friend / friend request pending
                                    softAlert("<p>You are either already friends with this person, or have a friend request pending.</p>", alertOff);
                                }
                            }
                        )
                        // Hide alert box
                        alertOff();
                    }, 
                    alertOff);
    });
});