/* element: jQuery object representing a text input of array of text inputs.
   phrase: a string representing the initial phrase in the form input.
*/
function blankOnFocus(element, phrase) {
    if(element.val().length == 0) {
        element.val(phrase);
    }
    element.focus(function() {
        if($(this).attr('value')==phrase) {
            $(this).attr('value','');
        }
    });
    element.blur(function() {
        if($(this).attr('value')=='') {
            $(this).attr('value',phrase);
        }
    });
    element.parents('form').submit(function() {
        if(element.attr('value')==phrase) {
            element.attr('value','');
        }
    });
}

/* id: String. The ID of the alert element to close. */
function closeThisAlert(id) {
    $('#'+id).fadeOut(1000);
}

$(document).ready(function() {
    $('input[title]:text, input[title]:password').each(function() {
        blankOnFocus($(this), $(this).attr('title'));
    });
    if($('#popup_loggedin').length > 0) {
        window.setTimeout(function() {
            closeThisAlert('popup_loggedin');
        }, 3000);
    }
});
