// ==UserScript==
// @name           EnableAutoLogin.uc.js
// @description    Enable Auto Login
// @compatibility  Firefox 2.0+
// @author         GOLF-AT
// @version        1.6.20101027

(function() {
    function ContentLoaded(event) {
        var items = event.target.getElementsByTagName('input');
        for(var i=0; i<items.length; i++) {
            var item = items.item(i);
            if (item.autocomplete == 'off')
                item.autocomplete = 'on';
            if (item.name=='username') item.value = '';
            if (item.form && item.form.autocomplete=='off')
                item.form.autocomplete = 'on';
            if (item.getAttribute('id')=='answer' && 'display:'
                ==item.getAttribute('style').substr(0,8))
                item.setAttribute('style', 'display:inline');
        }
    }

    function AutoCompleteOn(event) {
        try {
            var href  = event.target.getAttribute('href');
            var click = event.target.getAttribute('onclick');
            if (click.substr(0,9)=='floatwin(' || click.substr(
                0,10)=='showWindow') {
                var enable = 'logging.php?action=login'==href.
                    substr(0,24) || 'register.php'==href.substr
                    (0,12) || 'regist.php'==href.substr(0,10);
                if (!enable) {
                    var pos = href.indexOf('member.php?mod=');
                    if (pos>=0 && ('register'==href.substr(pos
                        +15,8)||'logging'==href.substr(pos+15,
                        7)))
                        enable = true;
                }
                if (enable) {
                    event.target.removeAttribute('onclick');
                    event.target.click();
                }
            }
        }catch(e) {}
    }

    try {
        document.addEventListener('mousedown', AutoCompleteOn, false);
        document.addEventListener("DOMContentLoaded", ContentLoaded, true);
    }catch(e) {}

})();