﻿
if( typeof MAPBG == "undefined" ){
    /**
     * The MAPBG global namespace object.
     * @class MAPBG
     * @static
     */
    var MAPBG = {};
}


MAPBG.LoginManager = function(){

    var _host = window.location.protocol + "//" + window.location.host;
    var _registerWindow;
    var _passwordRecoveryWindow;
    var _changePasswordWindow;
    
    ///////////////////////////////////////////////////////////////////////////////////////
    
    function _openWindow(url, target, width, height, options) {
        var x = (screen.availWidth - width) * .5;
        var y = (screen.availHeight - height) * .5;
        
        if( !options ){
            options = "menubar=0,toolbar=0,titlebar=0,resizable=1,scrollbars=1";
        }
    
        var _width = "width=" + (width > 0 ? width: GetWindowWidth()) + ", ";
        var _height = "height=" + (height > 0 ? height: GetWindowHeight()) + ", ";
        
        var _left = "screenX=" + x + ", left=" + x + ", ";
        
        var _top = "screenY=" + y + ", top=" + y;
        
        var _window = window.open(url, target, options + ", " + _width + _height + _top + _left);
        
        if (_window != null){
            _window.focus();
        }
        
        return _window;
    }
    
    ///////////////////////////////////////////////////////////////////////////////////////

    return{
    
        ///////////////////////////////////////////////////////////////////////////////////
            
        openRegiserWindow : function(){
            var width = 680,
                height = 450,
                _target = "_blank",
                _url = [ _host, "/RegisterUser.aspx?forum=t"];
                
            _url = _url.join( "" );
                
            if( _registerWindow && !_registerWindow.closed ){
                _registerWindow.focus();
                return;
            }
            
            _registerWindow = _openWindow( _url, _target, width, height );
        },
        
        ///////////////////////////////////////////////////////////////////////////////////
        
        openPasswordRecoveryWindow : function(){
            var width = 680,
                height = 450,
                _target = "_blank",
                _url = [ _host, "/PasswordRecovery.aspx?forum=t"];
                
            _url = _url.join( "" );
                
            if( _passwordRecoveryWindow && !_passwordRecoveryWindow.closed ){
                _passwordRecoveryWindow.focus();
                return;
            }
            
            _passwordRecoveryWindow = _openWindow( _url, _target, width, height );        
        },
        
        ///////////////////////////////////////////////////////////////////////////////////
        
        openPasswordChangeWindow : function(){
            var width = 400,
                height = 250,
                _target = "_blank",
                _url = [ _host, "/Protected/ChangePassword.aspx?forum=t"];
                
            _url = _url.join( "" );
                
            if( _changePasswordWindow && !_changePasswordWindow.closed ){
                _changePasswordWindow.focus();
                return;
            }
            
            _changePasswordWindow = _openWindow( _url, _target, width, height );          
        }
        
        ///////////////////////////////////////////////////////////////////////////////////
    }

}();
