/*
    simple onload event that fires to make the global home page login box textfields grey with generic text
    it also adds blur and focus event handlers to toggle the generic text in the textfields
*/

Event.observe(window, 'load', function() {
    // don\'t do anything if these values are missing (user is logged in)
    if (! $('PHAuthpassword') || ! $('PHAuthusername') || ! $('PHAuthpassword_text')) return;
    $('PHAuthpassword').setStyle({color: '#000'});
    
    $('PHAuthusername').observe('focus', function() {
        var element = $('PHAuthusername');
        if (element.getValue() == 'username') {
            element.clear();
            element.setStyle({color: '#000'});
        }
    });

    $('PHAuthusername').observe('blur', function() {
        var element = $('PHAuthusername');
        if (! element.present()) {
            element.setStyle({color: '#888'});
            element.value = 'username';
        }
    });
    
    // _text is the plain text field version of the password input to allow us to show: password
    // IE won\'t allow javascript to change the input type from text to password and back so we 
    // have to show one and hide the other
    $('PHAuthpassword_text').observe('focus', function() {
        $('PHAuthpassword_text').hide();
        $('PHAuthpassword').show();
        $('PHAuthpassword').focus();
    });

    $('PHAuthpassword').observe('blur', function() {
        if (! $('PHAuthpassword').present()) {
            $('PHAuthpassword').hide();
            $('PHAuthpassword_text').show();
        }
    });
});

