/** 顶部登录条，调用方法是 <div id=ajaxLogon><script src=本js></script></div> */
with(document.getElementById('ajaxLogon')){ innerHTML=
    //-----未登录
    '<span class="off" '+(!document.cookie.match(/(^|; )common_session_id=[^;]+/)?'':'style="display:none"')+'>'+
    '<form method=post action="http://passport2.pconline.com.cn/passport2/passport/login.jsp" style="margin:0;display:inline"> '+
    (location.host.match(/pconline/)?'<select onchange="form.action=value"><option value="http://passport2.pconline.com.cn/passport2/passport/login.jsp" selected>PCclub</option><option value="http://eyp.pconline.com.cn/member/login.htm">商家</option></select> ':'')+
    '<input style="background:no-repeat url(http://www1.pconline.com.cn/script/ajaxLogon.gif);" name=username size=10 onfocus="style.backgroundPosition=\'0 -25px\'" onblur="if(value==\'\')style.backgroundPosition=\'0 0\';"> '+
    '<input style="background:no-repeat url(http://www1.pconline.com.cn/script/ajaxLogon.gif) 0 -50px;" name=password type=password size=6 onfocus="style.backgroundPosition=\'0 -25px\'" onblur="if(value==\'\')style.backgroundPosition=\'0 -50px\';"> '+
    '<input type=submit class=submit value="登录"> '+
    '<input type=button class=reg value="注册" onclick="window.open(\'http://userdb.pconline.com.cn/userdb/Register_adv.do\',\'register\')" title="可在此取回密码"></form> </span> '+
    //-----已登录
    '<span class="on" '+(!!document.cookie.match(/(^|; )common_session_id=[^;]+/)?'':'style="display:none"')+'>'+(
//*
    location.host.match(/pconline/)?'<a href="http://www.pconline.com.cn/pcclub/" target=_blank>太平洋社区</a>':
    location.host.match(/pcauto/)?'<a href="http://blog.pcauto.com.cn/member/accountIndex.htm" target=_blank>博客管理</a> ':
    location.host.match(/pcgames/)?'<a href="http://j.pcgames.com.cn/userAdm.jsp" target=_blank>jClub管理</a>':
    location.host.match(/pclady/)?'<a href="http://blog.pclady.com.cn/" target=_blank>博客管理</a>':
    location.host.match(/pckids/)?'<a href="http://blog.pckids.com.cn/kidsblog/MemberAdmin.do?method=index" target=_blank>博客管理</a>':
/**/
    '')+' <a href="http://space.pconline.com.cn/club/myadm.jsp" target=_blank>空间管理</a> <a href="http://userdb.pconline.com.cn/userdb/RegisterEdit_enter.do" target=_blank>帐号管理</a> <a href="http://pass.pconline.com.cn/permit/passport/exit_ajax.jsp" onclick=" try{jQuery.getScript(href,ajaxLogonRefresh);}catch(e){};return false;">退出</a>'+
    '</span>'};

function ajaxLogonRefresh() {
    if(!document.cookie.match(/(^|; )common_session_id=[^;]+/) != !jQuery('#ajaxLogon>span:last:visible').length)
        jQuery('#ajaxLogon>span')//.toggle() 改成下面一行以绕开jquery1.3.2的toggle在这里失效的BUG
            .each(function(){var a=$(this); if(a.css('display')=='none') a.show(); else a.hide(); });
}

function jQueryLoaded4Logon($) {
    var $ = jQuery;
    $('#ajaxLogon form').append('<input type="hidden" name="return" value="http://www1.pconline.com.cn/closeWindow.html"><input type="hidden" name="fail" value="http://www1.pconline.com.cn/closeWindow.html">')
    .submit(function(){
        var usr = this['username'].value, pwd = this['password'].value;
        if(usr==''||pwd=='') { alert('请填写用户名和密码'); return false; }
        if(this.action.match(/\/eyp\./)) return; //商家
        $('input[type=submit]',this).css('opacity',.5).attr('disabled',true);

        this.target='pconline_login'; var win=window.open('','pconline_login','height=1, width=1, top=9999, left=0, toolbar=no, menubar=no, scrollbars=no,resizable=no,location=no, status=no'); window.focus();

        var time=0; var fm = this;
        var checker = setInterval(function(){
            if(time++ < 600 && !win.closed) return;
            clearInterval(checker);
            if(win.closed) {
                if(document.cookie.match(/(^|; )common_session_id=[^;]+/)) ajaxLogonRefresh();
                else alert('登录失败! 请检查帐号和密码是否正确。');

            } else {
                win.close();
                alert('登录超时失败，请检查网络状况并再试一次。');
            }
            $('input[type=submit]',fm).css('opacity',1).attr('disabled',false);
        },100);

        //$.getScript(this.action+(this.action.match(/\?/)?"&":"?")+"username=" +usr+"&password="+pwd, ajaxLogonRefresh);
    }); /**/
}

setTimeout(function(){
    if(typeof jQuery!='undefined') return jQueryLoaded4Logon();
    var $_already_defined = typeof $ != 'undefined';
    needJS(window.jQuery,'http://www1.pconline.com.cn/script/jquery-pconline1.2.js',function(){
        if($_already_defined) jQuery.noConflict();
        jQueryLoaded4Logon();
    });
},1000); //等1秒，先显示页面其它内容

function needJS(fn,src,callback) {
    if(typeof callback != 'function') return; //非法回调函数
    if(typeof fn != 'undefined' && fn != null && fn != '') return callback(false); //功能早已载入
    var scripts = window.__needJS__ || (window.__needJS__ = []);
    var script = scripts[src] || (scripts[src] = {loaded:false,callbacks:[]});
    if(script.loaded) return callback(false); else script.callbacks.push(callback);
    if(script.callbacks.length == 1) { var js = document.createElement('script');
        js.src = src; js.onreadystatechange = js.onload = function() {
            if(!js.readyState || js.readyState == 'loaded' || js.readyState == 'complete') {
            script.loaded = true; for(var i=0; i<script.callbacks.length; i++) script.callbacks[i](true);
        }   }; document.getElementsByTagName('head')[0].appendChild(js);
}   } //needJS ()