function translate_messages(mess){
    if (typeof window.allmess != 'undefined' && typeof window.allmess[mess] != 'undefined') {
        return window.allmess[mess];
    } else {
        return mess;
    }
}

function auth_automated(login, password) {
    if (typeof window.auth != 'undefined') {
        $("input[name='USER_LOGIN']").val(login);
        $("input[name='USER_PASSWORD']").val(password);
        $("input[name='USER_REMEMBER']").checked = true;
        auth.auth_passport();
    }
}

var window_is_active = true;
var pass_count = 0;
var ACTIVE_TIMEOUT = 60000;
var INACTIVE_TIMEOUT = 600000;

self.onfocus = function() {
    if (window_is_active == false) {
        window_is_active = true;
        active_onchange('active');
    }
}
self.onblur = function() {
    if (window_is_active == true) {
        window_is_active = false;
        active_onchange('inactive');
    }
}

function active_onchange(status) {
    if (typeof auth == 'object') {
        var now_ts = Math.round(new Date().getTime() / 1000);
        var diff_ts = now_ts - auth.last_active;
        if (status == 'active') {
            clearTimeout(auth.pm_timer);
            if (now_ts - auth.last_active > 60) {
                auth.check_new_pm_loop(ACTIVE_TIMEOUT);
            } else {
                auth.pm_timer = setTimeout(function() { auth.check_new_pm_loop(ACTIVE_TIMEOUT); }, ACTIVE_TIMEOUT);
            }
        } else if (status == 'inactive') {
            clearTimeout(auth.pm_timer);
            auth.pm_timer = setTimeout(function() { auth.check_new_pm_loop(INACTIVE_TIMEOUT); }, INACTIVE_TIMEOUT);
        }
    }
}

function jq_auth() {
    this.projects = {
        'http://www.gamexp.ru': {'name':translate_messages('project_gxp'), 'pid':38},
        'http://www.4sonline.ru': {'name':translate_messages('project_4s'), 'pid':41},
        'http://www.rzonline.ru': {'name':translate_messages('project_rz'), 'pid':34},
		'http://soul.gamexp.ru': {'name':translate_messages('project_ds'), 'pid':50},
        'http://sp.gamexp.ru': {'name':translate_messages('project_sp'), 'pid':9},
        'http://sphere.gamexp.ru': {'name':translate_messages('project_s1'), 'pid':12},
        'http://s2a.gamexp.ru': {'name':translate_messages('project_s2a'), 'pid':33},
        'http://www.webracing.ru': {'name':translate_messages('project_wr'), 'pid':25},
        'http://dom3.gamexp.ru': {'name':translate_messages('project_d3'), 'pid':23},
        'http://www.dragononline.ru': {'name':translate_messages('project_dk'), 'pid':42},
        'http://www.fantazium.ru': {'name':translate_messages('project_fantazium'), 'pid':44},
        'http://karos.gamexp.ru': {'name':translate_messages('project_karos'), 'pid':48},		
        'http://forum.gamexp.ru': {'name':translate_messages('project_forum'), 'pid':39},
        'http://shop.nikitaonline.ru': {'name':translate_messages('project_shop'), 'pid':2},
        'http://support.nikitaonline.ru': {'name':translate_messages('project_support'), 'pid':46}
    }
    
    this.pm_new_request = function() {
        var jq_obj = this;
        data = {
            type: 'GET',
            url: 'http://gc.gamexp.ru/auth/pm_new.php',
            dataType: 'script',
            timeout: 1500,
            cache: false,
            complete: function() {
                if (typeof window.pm_data == 'undefined') {
                    var loop_counter = 1;
                    
                    wait_loop = function() {
                        if (loop_counter < 10 && typeof window.pm_data == 'undefined') {
                            setTimeout(wait_loop, 1000);
                        } else {
                            if (typeof jq_obj.reload != 'undefined' && jq_obj.reload) {
                                jq_obj.reload_page();
                            }
                            jq_obj.show_bar_new_pm();
                        }
                        loop_counter++;
                    }
                    wait_loop();
                } else {
                    if (typeof jq_obj.reload != 'undefined' && jq_obj.reload) {
                        jq_obj.reload_page();
                    }
                    jq_obj.show_bar_new_pm();
                }
            }
        }
        
        return data;
    }
    
    this.balance_request = function() {
        var jq_obj = this;
        data = {
            type: 'POST',
            url: '/auth/balance.php',
            data: {},
            dataType: 'script',
            timeout: 1500,
            cache: false,
            complete: function() {
                if (typeof window.user.balance == 'undefined') {
                    var loop_counter = 1;
                    wait_loop = function() {
                        if (loop_counter < 10 && typeof window.user.balance == 'undefined') {
                            setTimeout(wait_loop, 1000);
                        } else {
                            if (typeof window.user.balance != 'undefined') {
                                $('.bar_gxp').html(window.user.balance);
                            } else {
                                $('.bar_gxp').html('N/A');
                            }
                        }
                        loop_counter++;
                    }
                    wait_loop();
                } else {
                    if (typeof window.user.balance != 'undefined') {
                        $('.bar_gxp').html(window.user.balance);
                    } else {
                        $('.bar_gxp').html('N/A');
                    }
                }
            }
        }
        
        return data;
    }
    
    this.passport_request = function() {
        var jq_obj = this;
        data = {
            action: 'none',
            type: 'GET',
            url: 'http://my.gamexp.ru/passport/auth.php',
            dataType: 'script',
            timeout: 1500,
            cache: false,
            error: function() {
                setTimeout(function() {
                    $("#bar_center").html('<span class="loading"><label id="loading_bar">' + translate_messages('loading_error') + '</label></span>');
                    setTimeout(jq_obj.login(), 60000);
                }, 1000);
            },
            complete: function() {
                window.ajaxcomplete = 1;
                if (!window.user) {
                    window.user = {'auth': 0};
                }
                if (window.user.auth == 1) {
                    if (getURLParam('sid') && (window.CONST_PID == 39 || window.CONST_PID == 34 || window.CONST_PID == 2)) {
                        window.ext_auth = 'mailrurz';
                        jq_obj.show_bar_hello();
                        if (typeof window.CONST_RELOAD != 'undefined' && CONST_RELOAD == true) {
                            window.location = window.location;
                        }
                    } else {
                        jq_obj.checktoken(this.action);
                    }
                } else if (this.action == 'logout') {
                    jq_obj.checktoken(this.action);
                } else {
                    jq_obj.show_form_login();
                }
            }
        }
        
        return data;
    }
    
    this.reload_page = function() {
        var arr = window.location.href.split('#', 2);
        if (typeof arr[0] != 'undefined') {
            window.location.href = arr[0];
        }
    }
    
    this.checktoken_request = function() {
        var jq_obj = this;
        data = {
            type: 'POST',
            url: '/auth/checktoken.php',
            dataType: 'script',
            timeout: 1500,
            cache: false,
            complete: function() {
                if (window.user.auth == true || window.user.authcheck == true ) {
                    if (typeof window.user.login == 'undefined') {
                        var loop_counter = 1;
                        wait_loop = function() {
                            if (loop_counter < 10 && typeof window.user.login == 'undefined') {
                                setTimeout(wait_loop, 1000);
                            } else {
                                jq_obj.show_bar_hello();
                                jq_obj.on_auth_complete(true);
                            }
                            loop_counter++;
                        }
                        wait_loop();
                    } else {
                        jq_obj.show_bar_hello();
                        jq_obj.on_auth_complete(true);
                    }
                    if (window.CONST_PID == '46' && typeof window.user.csid != 'undefined') {
                        window.location = '/form/index.html?CSID=' + window.user.csid;
                    }
                    if (typeof window.CONST_RELOAD != 'undefined' && window.CONST_RELOAD == true) {
                        jq_obj.reload = true;
                        setTimeout(jq_obj.reload_page, 10000);
                    }
                } else {
                    jq_obj.show_form_login();
                    if (typeof window.CONST_RELOAD != 'undefined' && CONST_RELOAD == true) {
                        window.location = window.location;
                    }
                    jq_obj.on_auth_complete(false);
                }
            }
        };
        
        return data;
    }
    
    this.token = '';
    
    this.checktoken = function(action) {
        if (typeof window.ext_auth != 'undefined') {
            window.ext_auth = 'mailrurz';
            this.show_bar_hello();
            if (typeof window.CONST_RELOAD != 'undefined' && CONST_RELOAD == true) {
                window.location = window.location;
            }
            return;
        }
        var jq_obj = this;
        data = this.checktoken_request();
        this.token = window.user.token;
        data.data = {'token': window.user.token, 'id': window.user.id};
        var checktoken_urls = {5:'/auth/checktoken.jsp', 3:'/cgi-bin/auth/checktoken.pl', 46:'/form/auth/checktoken.pl'};
        if (typeof checktoken_urls[window.CONST_PID] != 'undefined') {
            data.url = checktoken_urls[window.CONST_PID];
            data.data.format = 'ini';
        }
        var mailrurz_pids = {2:'', 34: '', 39:''};
        if (action != 'logout' && getURLParam('sid') && typeof mailrurz_pids[window.CONST_PID] != 'undefined') {
            data.data = {'sid':getURLParam('sid')};
            data.url = '/auth/checkmailru.php';
            window.ext_auth = 'mailrurz';
        }
        $.ajax(data);
    }
    
    this.auto_login = function() {
        this.loading();
        var jq_obj = this;
        data = this.passport_request();
        data.data = {'pid':window.CONST_PID};
        var mailrurz_pids = {2:'', 34:'', 38:'', 39:''};
        if (getURLParam("sid") && typeof window.CONST_PID != 'undefined' && typeof mailrurz_pids[window.CONST_PID] != 'undefined') {
            data.data = {'sid':getURLParam("sid")};
            data.url = "/auth/checkmailru.php";
            window.ext_auth = 'mailrurz';
        }
        $.ajax(data);
    }
    
    this.loading = function() {
        $("#bar_center").html('<span class="loading"><label id="loading_bar">' + translate_messages('loading') + '</label></span>');
    }
    
    this.logout = function() {
        this.loading();
        var jq_obj = this;
        data = this.passport_request();
        data.data = {'login':'', 'pass':'', 'remember':1};
        window.sent = {'login':'', 'pass':'', 'remember':1};
        data.action = 'logout';
        $.ajax(data);
    }
    
    this.auth_passport = function() {
        if (typeof window.user == 'undefined') {
            window.user = {'error': false};
        } else {
            window.user.error = false;
        }
        var regexp = /[^-\w\d_@\.]+/igm;
        login = $("input[name='USER_LOGIN']").val();
        login = login.replace(regexp, '');
        pass = $("input[name='USER_PASSWORD']").val();
        pass = pass.replace(regexp, '');
        remember = ($('#auth_remember').val() == 1 ? true : false);
        window.sent = {'login':login, 'pass':$("input[name='USER_PASSWORD']").val(), 'remember':remember};
        if (login.length == 0) {
            window.user.error = 'nologin';
        } else if (pass.length == 0) {
            window.user.error = 'nopass';
        } else if (login.length < 3 || pass.length < 6 || login.length > 50 || pass.length > 50) {
            window.user.error = 'lessthan6';
        }
        if (window.user.error) {
            this.show_form_login();
            return;
        }
        this.loading();
        data = this.passport_request();
        data.action = 'login';
        data.data = {
            'login': window.sent.login, 
            'pass': md5(window.sent.pass), 
            'remember': window.sent.remember,
            'url': window.location.href, 
            'pid': window.CONST_PID};
        $.ajax(data);
        $('.authorizing').css("z-index", 1000);
        $('.authorizing').css("width", "100%");
    }
    
    this.check_new_pm = function() {
        if (typeof window.ext_auth != 'undefined') {
            window.pm_data = [];
            return;
        }
        if (typeof window.user == 'undefined' || !window.user.auth) {
            window.pm_data = [];
            return;
        }
        this.check_new_pm_loop(ACTIVE_TIMEOUT);
    }
    
    this.check_new_pm_loop = function(timeout) {
        if (typeof window.user == 'undefined' || !window.user.auth) {
            window.pm_data = [];
            return;
        }
        var jq_obj = this;
        data = this.pm_new_request();
        if (this.token != '') {
            data.data = {'token': this.token, 'id': window.user.id};
        } else {
            data.data = {'id': window.user.id};
        }
        $.ajax(data);
        this.token = '';
        this.pm_timer = setTimeout(function() { jq_obj.check_new_pm_loop(timeout); }, timeout);
        this.last_active = Math.round(new Date().getTime() / 1000);
    }
    
    this.last_active = 0;
    this.pm_timer = 0;
    
    this.get_user_balance = function() {
        if (window.CONST_PID == 46) {
            window.user.balance = 'N/A';
            return;
        }
        if (typeof window.user.auth == 'undefined' || !window.user.auth) {
            return;
        }
        var jq_obj = this;
        data = this.balance_request();
        $.ajax(data);
        setTimeout(function() { jq_obj.get_user_balance(); }, 60000);
    }
    
    this.show_bar_new_pm = function() {
        if (typeof window.pm_data == 'undefined') {
            window.pm_data = {'pm_new':0, 'wannabefriends':0};
        }
        if (window.pm_data.pm_new == '1') {
            pm_html = "<a class='pm_new hint_hover_pm' href='http://gc.gamexp.ru/pm.php' ></a><span class='bar_hint_text'>" + translate_messages('pm_new_1') + "</span>";
        } else if (window.pm_data.wannabefriends == '1') {
            pm_html = "<a class='pm_new hint_hover_pm' href='http://gc.gamexp.ru/friends.php' ></a><span class='bar_hint_text'>" + translate_messages('pm_wannabefriends_1') + "</span>";
        } else {
            pm_html = "<a href='http://gc.gamexp.ru/pm.php' class='bar_mail hint_hover_pm'></a><span class='bar_hint_text'>" + translate_messages('pm_new_0') + "</span>";
        }
        $('li#pm').html(pm_html);
        var jq_obj = this;
        $('a.hint_hover_pm')
            .bind('mouseover', function(e) {
                var hovered_ele_pos = $(this).offset();
                var ele_next_txt = $(this).next().html();
                $('.bar_hint .bar_hint_bg').html(ele_next_txt);
                $('.bar_hint').css({'left':hovered_ele_pos.left + 'px'});
                jq_obj.hint_msg_show(true);
            })
            .bind('mouseout', function() {
                jq_obj.hint_msg_show(false);
            });
    }
    
    this.hint_msg_show = function(show) {
        function hint_msg_timer() {
            $('.bar_hint').show();
        }
        if (show) {
            timer = setTimeout(hint_msg_timer, 1000);
        } else {
            $('.bar_hint').hide();
            if (typeof window.timer != 'undefined') {
                clearTimeout(timer);
            }
        }
        
    }
    
    this.translate_messages = function(mess) {
        if (typeof window.allmess != 'undefined' && typeof window.allmess.mess != 'undefined') {
            return window.allmess[mess];
        } else {
            return mess;
        }
    }
    
    this.get_bar_select_project = function() {
        var t = $.template(tpl.bar_select_project);
        var vars = {};
        vars.link = 'GameXP';
        vars.select = '';
        for (i in this.projects) {
            if (this.projects[i].pid == window.CONST_PID) {
                    vars.link = this.projects[i].name;
            }
            vars.select += '<li><a href="' + i + '">' + this.projects[i].name + '</a></li>';
        }
        return $('<div></div>').html(t, vars).html();
    }
    
    this.init = function() {
        var t = $.template(tpl.bar_clear);
        var vars = {};
        vars.loading = this.translate_messages('loading');
        var browser = $.browser.version;
        if ($.browser.msie && browser == '7.0') {
            $('#bar').addClass('bar_ie_input');
        }
        var pids = {12:'', 33:'', 9:'', 38:''};
        if (typeof pids[window.CONST_PID] != 'undefined' && $.browser.msie && (browser == '7.0' || browser == '8.0')) {
            $('#bar').addClass('bar_ie');
        }
        
        var engine = '';
        if (window.navigator.appName == "Microsoft Internet Explorer") {
            if (document.documentMode) {
                engine = document.documentMode;
            } else {
                engine = 5;
                if (document.compatMode) {
                    if (document.compatMode == "CSS1Compat") {
                        engine = 7;
                    }
                }
            }
            if (engine == 5 && window.CONST_PID == 25) {
                $('#bar').addClass('bar_ie5');
            }
        }
        
        $('body').bind('click', function() {
            if ($('#bar_projects').css('display') == 'block') {
                $('#bar_projects').toggle();
                $('span.txt span.arrow').removeClass('t').addClass('b');
                $('#bar_projects').addClass('hidden');
            }
        });
        $("#bar").html(t, vars);
        $("#autherror").css("display","none");
        if (engine == 5) {
            $('#bar').addClass('bar_ie5');
        }
    }
    
    this.show_form_login = function() {
        if (!window.sent) {
            window.sent = {'login':'', 'pass':'', 'remember':false};
        }
        var t = $.template(tpl.form_login);
        var vars = {};
        vars.backurl = window.location.href;
        vars.login = translate_messages('login');
        vars.login_for_form = (window.sent.login == '' ? '' : window.sent.login);
        vars.password = translate_messages('password');
        vars.pass_for_form = (window.sent.pass == '' ? '' : window.sent.pass);
        vars.checked = 1;
        vars.remember = translate_messages('remember');
        vars.form_pass_recovery = translate_messages('form_pass_recovery');
        var reg_urls = {46:'http://my.gamexp.ru/help/projects.php', 25:'/community/reg.php'};
        vars.reg_url = 'http://my.gamexp.ru/auth.php?simple_registration=yes';//(typeof reg_urls[window.CONST_PID] == 'undefined' ? '/reg.php#register' : reg_urls[window.CONST_PID]);
        vars.form_register = translate_messages('form_register');
        vars.bar_select_project = this.get_bar_select_project();
        
        $('#bar div.bar_wrp').removeClass('logedin');
        $("#bar_center").html(t, vars);
        error = false;
        if (window.user.error) {
            error = translate_messages(window.user.error);
        }
        if (error) {
            if(window.user.error == 'need_captcha'){
                $.cookie('PHPSESSID', Math.floor(Math.random()*100000000));
            }
            this.show_bar_error(error);
        }
        $("span.txt").toggle(
            function(){
                $("#bar_projects").show();
            },
            function(){
                $("#bar_projects").hide(); 
            });
        
        this.on_auth_complete(false);
    }
    
    this.show_bar_hello = function() {
        var t = $.template(tpl.bar_hello);
        var vars = {};
        if (typeof window.user.balance == 'undefined' || window.user.balance != 'N/A') {
            this.get_user_balance();
            vars.balance = '';
        } else {
            vars.balance = window.user.balance;
        }
        jq_obj = this;
        if (window.user.group > 0) {
            var hint_discounts = {11:'5%', 12:'10%', 13:'15%', 14:'20%'};
            hint_discount = (typeof hint_discounts[window.user.group] == 'undefined' ? '' : hint_discounts[window.user.group]);
            
            if (window.user.group == 22) {
                vars.card = '\
                <li>\
                    <a onclick="jq_obj.bar_randomdiscount(); return false;" href="http://shop.nikitaonline.ru/personal/gamexpclub.php" target="_blank" class="hint_hover card group_' + window.user.group + '"></a>\
                    <span class="bar_hint_text">' + translate_messages('card_24_hint') + '</span>\
                </li>';
            } else {
                vars.card = '\
                <li>\
                    <a href="http://shop.nikitaonline.ru/personal/gamexpclub.php" target="_blank" class="hint_hover card group_' + window.user.group + '"></a>\
                    <span class="bar_hint_text">' + translate_messages('card_hint') + '<b>' + hint_discount + '</b></span>\
                </li>';
            }
        }
        vars.hello = translate_messages('hello');
        vars.login = window.user.login;
        vars.logout_url = (window.CONST_PID == 46 ? '/form/index.html?Action=Logout' : '');
        vars.logout_click = (window.CONST_PID != 46 ? 'onclick="jq_obj.logout(); return false;"' : '');
        vars.logout = translate_messages('logout');
        vars.bar_select_project = this.get_bar_select_project();
        vars.security = translate_messages('security');
        vars.gxp_hint = translate_messages('gxp_hint');
        
        $('#bar div.bar_wrp').addClass('logedin');
        $('#bar_center').addClass('clearfloat');
        $("#bar_center").html(t, vars);
        
        if (window.user.group == 22) {
            if ((typeof window.sent == 'undefined' || typeof window.CONST_RELOAD == 'undefined' || window.CONST_RELOAD == false) && !$.cookie('bar_randomdiscount')) {
                $.cookie('bar_randomdiscount', 'true', {expires: 1});
                if (CONST_PID == 39) {
                    if (!$.cookie('bar_randomdiscount39')) {
                        $.cookie('bar_randomdiscount39', 'true', {expires: 1});
                        $.cookie('bar_randomdiscount', 0, {expires: -1});
                    }
                }
                this.bar_randomdiscount();
            }
        }
        
        if (window.user.phone == 'none') {
            $('.bar_hint .bar_hint_bg ').text(translate_messages('security_alert'));
            $('#bar_phone a').removeClass('approved').addClass('unset');
        }
        if (window.user.phone == 'wait_set') {
            $('.bar_hint .bar_hint_bg ').text(translate_messages('security_alert'));
            $('#bar_phone a').removeClass('approved').removeClass('unset').addClass('process');
        }
        
        $('a.hint_hover')
            .bind('mouseover', function(e) {
                var hovered_ele_pos = $(this).offset();
                var ele_next_txt = $(this).next().html();
                $('.bar_hint .bar_hint_bg').html(ele_next_txt);
                $('.bar_hint').css({'left':'0'}).show().css({'left':hovered_ele_pos.left + 'px'});

            })
            .bind('mouseout', function() {
                $('.bar_hint').hide();
            });

        $("span.txt").toggle(
            function(){
                $("#bar_projects").show();
                $('span.txt span.arrow').removeClass('b').addClass('t');
            },
            function(){
                $("#bar_projects").hide();
                $('span.txt span.arrow').removeClass('t').addClass('b');
            });
        
        this.on_auth_complete(true);
         this.check_new_pm();
    }
    
    this.bar_randomdiscount = function() {
        var div = '<div id="bar_randomdiscount"><a class="close" href="#" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a><div class="inside">';
        div += '<a href="http://shop.nikitaonline.ru/personal/event_randomdiscount.php" target="_blank" class="card">';
        div += '<img src="http://www.gamexp.ru/auth/event/randomdiscount.jpg" /></a></div></div>';
        div += '<iframe src="" id="bar_randomdiscount_flashfix"></iframe>';

        $('#authad').html(div).show();
        $('#bar_randomdiscount a.close').bind('click', function() {
            $('#authad').html('').hide();
        });
    }
    
    this.show_bar_error = function(error) {
        var t = $.template(tpl.bar_error);
        var vars = {};
        vars.error_type = translate_messages('error');
        vars.error = error;
        $("#autherror").html(t, vars);
        $("#autherror").css('display', 'block');
    }
    
    this.on_auth_complete = function(status) {
        if (typeof on_auth_complete == 'function') {
            on_auth_complete();
        }
        var jq_auth = this;
        $("a[href='#jqauth']").bind('click', function() {
            var auth_form_exist = $('#page_auth_block').length;
			if (auth_form_exist == 0 && window.user.auth != 1) {
				jq_auth.auth_popupform();
            }
        });
        if (status == false) {
            $('.jqswitch_id.true').css('display', 'none');
            $('.jqswitch_id.false').css('display', 'inline');
            $('.jqswitch_auth.true').css('display', 'none');
            $('.jqswitch_auth.false').css('display', 'inline');
            $('.jqswitch_shop.true').css('display', 'none');
            $('.jqswitch_shop.false').css('display', '');
            $('#bar').removeClass('true');
        } else {
            color = 'green';
            $('.jqswitch_id.false').css('display', 'none');
            $('.jqswitch_id.true').css('display', 'inline');
            $('.jqswitch_id.true').text(window.user.id);
            $('.jqswitch_login.false').css('display', 'none');
            $('.jqswitch_login.true').css('display', 'inline');
            $('.jqswitch_login.true').text(window.user.login);
            $('.jqswitch_auth.true').css('display', 'inline');
            $('.jqswitch_auth.false').css('display', 'none');
            $('.jqswitch_shop.true').css('display', '');
            $('.jqswitch_shop.false').css('display', 'none');
            $('#bar').addClass('true');
        }
    }
    
    this.auth_popupform = function() {
        var body_h = $('body').height();
        var jq_auth = this;
        var t = $.template(tpl.form_popup);
        var vars = {};
        vars.login = translate_messages('login');
        vars.password = translate_messages('password');
        vars.remember = translate_messages('popup_remember');
        $('body').append(t, vars);
        $('#auth_popupform_bg').css('height', body_h + 'px');
        $('#auth_popupform_close').click(function() {
            $('#auth_popupform_bg').remove();
            $('#auth_popupform_block').remove();
        });
        $('#auth_popupform_bg').click(function() {
            $(this).remove();
            $('#auth_popupform_block').remove();
        });
        $('span.auth_popupform_remember').click(function() {
            var status = $('span.auth_popupform_remember').hasClass('selected');
            if (!status) {
                $('span.auth_popupform_remember').addClass('selected');
            } else {
                $('span.auth_popupform_remember').removeClass('selected');
            }
            jq_auth.auth_remember_click();
        });
    }
    
    this.auth_popupform_info_send = function() {
        var login = $('#auth_popupform_login').val();
        var pwd =  $('#auth_popupform_pwd').val();

        $('#auth_popupform_bg').remove();
        $('#bar #login').val(login);
        $('#bar .bar_password').val(pwd);

        $('#auth_popupform_block').remove();
        this.auth_passport();
        return false;
    }
    
    this.auth_remember_click = function() {
        var status = $('span.remember').hasClass('selected');
        if (!status) {
            $('span.remember').addClass('selected');
        } else {
            $('span.remember').removeClass('selected');
        }
        itis = $("#auth_remember").val();
        willbe = (itis == 1) ? 0 : 1;
        $("#auth_remember").val(willbe);
        return false;
    }
}
