/*
    viewIndividualBio.js

*/

function show_bio(individualId, memberName) {
    // Build the dialog box for displaying a member bio

    // set up button click handler for dialog
    $('#cancel_button').click(clickedCancel);

    // set dialog to modal and style the overlay to grey
    $('#member_bio_dialog').dialog({modal: false,
        width: 540,
        title: ('Biography for <b>' + memberName + '</b>') });

    // Hide the standard close button
    $('.ui-dialog-titlebar-close').hide();

    // Fetch the Bio
    fetchBio(individualId);
}

function clickedCancel() {
    $('#member_bio_dialog').dialog("destroy");
}


function fetchBio(individualId) {
    $.ajax({
        type: 'GET',
        url: 'getBioForJquery',
        success: bioCompleted,
        error: bioFailed,
	dataType: "text",
        data: {
         individualId: individualId
        },
        timeout: 20000
        });
}

function bioFailed(XMLHttpRequest, textStatus, errorThrown) {
    // If the ajax request returns an error, we get here.
    // We probably timed out.
    $('#member_bio_dialog').dialog("destroy");
}


function bioCompleted(data, textStatus) {
    // Install the Bio in the dialog
    var devStringStart = '<!-- Templates used:'
    var devStringIndex = data.indexOf(devStringStart)
    if (devStringIndex < 0) {
        $("#bio_text").html(data);
    } else {
        $("#bio_text").html(data.substring(0,devStringIndex));
    }
    // Display the dialog
    $('#member_bio_dialog').show();
    $('#member_bio_dialog').show('open');
}


