/* 
    SBAA JavaScript
    Peter Beard -- January 31, 2010 -- pete13@pete13.com
 */
// Search for a person
function search()
{
    var term = $('#term').val();
    $('#loadbar').html('<p>Searching...</p>');
    $('#results').load('/ajax/find-alum.php?query=' + escape(term), function() {
        $('#results').animate({'height': '100%'}, 500);
        $('#loadbar').html('');
    });
}
// Toggle the message box
function toggle_message_form()
{
    $('#message_form').css('display', 'block');
}

// Send a private message
function send_private_message()
{
    var to = $('#alum_to_id').val();
    var subject = $('#subject').val();
    var msg = $('#msg').val();
    // POST the request to the server
    $('#alert_area').html('<p>Sending message... </p>');
    $.ajax({
        type: 'POST',
        url: '/ajax/send-message.php',
        data: {
            'to': to,
            'subject': subject,
            'message': msg
        },
        success: function (data, status, obj)
        {
            $('#message_form').css('display', 'none');
            $('#alert_area').html('<p>' + data + '</p>');
        }
    });
}

// Send a public message
function send_message()
{
    var to = $('#alum_to_id').val();
    var msg = $('#public_msg').val();
    // POST the request to the server
    $('#alert_area').html('<p>Saving message... </p>');
    $.ajax({
        type: 'POST',
        url: '/ajax/send-message.php',
        data: {
            'to': to,
            'type': 'public',
            'message': msg
        },
        success: function (data, status, obj)
        {
            $('#public_messages').load('/ajax/get-messages.php?alum=' + $('#alum_to_id').val());
            $('#alert_area').html('<p>' + data + '</p>');
        }
    });
}

// Clear the flash box
function clearFlash()
{
    setTimeout(function() {
        $('.flash').animate({opacity: 0}, 750, function() {
            $('.flash').remove();
        });
    }, 2000);
}

$(document).ready(clearFlash);
