/**
 * login Javascript
 * 
 * @author: Chanel Munezero <chanel.munezero@escapemg.com>
 */
(function(){
    if(!window.gs) {
        return;
    }
    
    var login = window.gs.login = {
        // default options/settings
        userID: 0,
        _anonUser: 85144,
        
        empty: null
    };
    
    login.init = function()
    {
        $('input.active').each(function() {
            var self = this;
            var doBlur = function(event) {
                event = event || window.event;
                $(self).parent().removeClass('active');
            };
            var doFocus = function(event) {
                event = event || window.event;
                $(self).parent().addClass('active');
            }
            this.onblur = doBlur;
            this.onfocus = doFocus; 
        });
    };
    
    login.showForm = function(nextPage)
    {
        nextPage = nextPage || '';
        if(login.userID>0 && login.userID != login._anonUser) {
            location.href = '/my_widgets'; // if logged in, go to my widgets
            return;
        }
        var next = (nextPage=='') ? '' : '&next='+nextPage;
        var options = {
            ajax: '/login?action=lb'+next,
            onShow: function(hash) {
                // allow form to do its thing
                gs.modal_show(hash);
                gs.login.init();
            }
        };
        var divinfo = {
            newid: 'loginBox',
            newclass: 'modalbox'
        };
        gs.lbFactory.newModalBox(options, divinfo, true);
    }
    
    login.hideForm = function()
    {
        gs.lbFactory.disposeModalBox($("#loginBox"));
    }
    
})();