// Password field in user menu
var textStore = {};

function wipeTextOnFocus(input) {

    textStore[input.getAttribute('id')] = input.value;

    pDomApi.addEvent(input, 'focus', function(e) {
        if (input.value == textStore[input.getAttribute('id')]) {
            input.value = '';
        }
        pDomApi.setClassName(input, 'focus');
    });

    pDomApi.addEvent(input, 'blur', function(e) {
         if(input.value == '') {
            input.value = textStore[input.getAttribute('id')];
            pDomApi.setClassName(input, '', 'focus');
        }
    });
}

function replacePasswordBox(passwd) {
    var text = document.createElement('input'); // create new input element
    text.setAttribute('type', 'text'); // type = text
    text.setAttribute('value', passwd.getAttribute('value'));
    text.setAttribute('tabIndex', passwd.getAttribute('tabIndex'));
    text.className = passwd.className;
    text.setAttribute('readonly', 'readonly');
    passwd.setAttribute('value', '');
    passwd.parentNode.insertBefore(text, passwd);
    passwd.parentNode.removeChild(passwd);

    pDomApi.addEvent(text, 'focus', function (e) {
        text.parentNode.insertBefore(passwd, text);
        passwd.parentNode.removeChild(text);
        passwd.focus();
    });

    pDomApi.addEvent(passwd, 'blur', function(e) {
        if (passwd.value == '') {
            passwd.parentNode.insertBefore(text, passwd);
            passwd.parentNode.removeChild(passwd);
        }
    });
}

// Password field in user menu
pDomApi.addEvent(window, 'domload', function() {
    var passwd, email;

    if (passwd = eId('authUserPass')) {
        replacePasswordBox(passwd);
    }
    if (email = eId('authUserName')) {
        wipeTextOnFocus(email);
    }
});
