var URL_U = "http://115.com";
var URL_PASS = "http://passport.115.com";
var URL_MY = "http://my.115.com";
var URL = "http://www.115.com";
var COM_LISTENLIST = [];
var COM_CacheDOM = {};

window.setInterval(function(){
    for(var i = 0, len = COM_LISTENLIST.length; i < len; i++){
        var label = COM_LISTENLIST[i];
        var input = label.nextSibling;
        if(input.value == ""){
            if(label.style.display == "none"){
                label.style.display = "";
            }
        }
        else{
            if(label.style.display != "none"){
                label.style.display = "none";
            }
        }
    }
}, 10);

var COM_ShowMsg = function(node){
    if(!COM_CacheDOM[node.id]){
        var msg = node.getAttribute("errmsg");
        var div = document.createElement("div");
        div.className = "popup-hint popup-min";
        div.style.display = "none";
        div.innerHTML = '<b class="sl"></b><span rel="txt">'+msg+'</span><b class="sr"></b>';
        document.body.appendChild(div);
        COM_CacheDOM[node.id] = div;
    }
    var input = $(node);
    var l = input.offset().left;
    var t = input.offset().top + input.height() + 12;
    var msgDom = COM_CacheDOM[node.id];
    msgDom.style.left = l + "px";
    msgDom.style.top = t + "px";
    msgDom.style.display = "";
}

var COM_HideMsg = function(node){
    if(COM_CacheDOM[node.id]){
        COM_CacheDOM[node.id].style.display = "none";
    }
}

var COM_BindResize = false;
var COM_OnLoginSubmit = function(){
    var account = document.getElementById("account");
    var res = true;
    if(account){
        var val = account.value.replace(/(^\s*)|(\s*$)/g, "");
        if(val == ""){
            COM_ShowMsg(account);
            account.focus();
            res = false;
            account.onblur = function(){
                if(this.value.replace(/(^\s*)|(\s*$)/g, "") != ""){
                    COM_HideMsg(account);
                }
            }
        }
        else{
            COM_HideMsg(account);
        }
    }
    var pwd = document.getElementById("passwd");
    if(pwd){
        var val = pwd.value.replace(/(^\s*)|(\s*$)/g, "");
        if(val == ""){
            COM_ShowMsg(pwd);
            if(res)
                pwd.focus();
            res = false;
            pwd.onblur = function(){
                if(this.value.replace(/(^\s*)|(\s*$)/g, "") != ""){
                    COM_HideMsg(pwd);
                }
            }
        }
        else{
            COM_HideMsg(pwd);
        }
    }

    if(!COM_BindResize){
        COM_BindResize = true;
        window.onresize = function(){
            COM_HideMsg(account);
            COM_HideMsg(pwd);
        }
    }
    return res;
}

document.write('<div class="header">' + 
    '<h1 class="logo"><a href="'+URL+'">115，我的网盘！ —— 爱分享 i生活</a></h1>' +
    '<div class="login-box">' +
        '<form vail="1" action="'+URL_PASS+'/?ac=login&goto=' + encodeURIComponent(URL_U) + '" method="post" onsubmit="return COM_OnLoginSubmit();" id="js_login_form">' +
            '<label for="account" class="text-hint">您的邮箱</label>' +
            '<input type="text" name="login[account]" id="account" class="text" value="" tabindex="1" errmsg="请输入邮箱"/>' +
            '<label for="passwd" class="text-hint pwd-hint">密码</label>' +
            '<input type="password"  name="login[passwd]" id="passwd" class="text" tabindex="2" errmsg="请输入密码" />' +
            '<button type="submit" tabindex="3">登录</button>' +
            '<input type="hidden" name="back" value="' + URL + '/?ct=index" />'+
            '<input type="checkbox" id="autologin" name="login[time]" class="checkbox" tabindex="4" />' +
            '<label for="autologin" rel="not">自动登录</label>' +
            '<a href="' + URL_MY + '/?ct=forgot_passwd">找回密码</a> ' +
        '</form>' +
    '</div>' +
'</div>'+
'<script type="text/javascript">'+
    'var loginForm = document.getElementById("js_login_form");'+
    'if(loginForm){'+
        'var labels = loginForm.getElementsByTagName("label");'+
        'for(var i = 0,len = labels.length; i < len; i++){'+
            'var label = labels[i];'+
            'if(label.getAttribute("rel") != "not"){'+
                'COM_LISTENLIST.push(label);'+
            '}'+
        '}'+
    '}'+
'<\/script>'
);
