﻿// JScript 文件
var bolAotu=false;
var bolLoginFlag=false;
var strLogin="";
 function login_check() {
        //用户名检查
        var username = document.getElementById("txtUserName").value;
        var password = document.getElementById("txtPassWord").value;
        var autoLogin = document.getElementById("chkAutoLogin").checked?1:0;
        
        if (username=="") {
            alert("请输入用户名！");
            document.getElementById("txtUserName").focus();
            return;
        }
        if (password == "") {
            alert("请输入密码！");
            document.getElementById("txtPassWord").focus();
            return;
        }
        
        var Ajax = new oAjax("./common/LoginCheck.aspx","LoginCheck",loginCheck,false);
        Ajax.Get("username=" + username + "&password=" + password +"&autoLogin="+autoLogin);
    }

function loginCheck(content) {
    var isSuccess = getTagValue(content,"Success");
   
    if(isSuccess && isSuccess =="True"){
    
        
        bolLoginFlag=true;
        bolAotu=false;
        //strLogin=$("tdLogin").innerHTML;
        document.getElementById("noLogin").style.display = "none";
        document.getElementById("isLogin").style.display = "";
        var tableTag=content.getElementsByTagName("Table");
        $("welname").innerHTML = getTagValue(tableTag[0],"nickname") + '，欢迎你';
        $("loginpic").innerHTML = '<img src="'+(getTagValue(tableTag[0],"babyphotopath")==""?"common/common_res/nophoto.gif":getTagValue(tableTag[0],"babyphotopath"))+'" />';
        if(getTagValue(tableTag[0],"userlevel")>="2"){
         $("homenavA").innerText="个人主页 >>";
        }
        $("homenavA").href = "baby/baby_main.aspx?babyid=" + getTagValue(tableTag[0],"babyid");
        
        $("welnavUpLoadpic").href = "baby/baby_main.aspx?goType=4|4&babyid=" + getTagValue(tableTag[0],"babyid");
        $("newFilm").href = "baby/baby_main.aspx?goType=3|3&t=0&babyid=" + getTagValue(tableTag[0],"babyid");
        $("wirteDairy").href = "baby/baby_main.aspx?goType=2|3&babyid=" + getTagValue(tableTag[0],"babyid");
        $("newFangle").href = "baby/baby_master.aspx?babyid=" + getTagValue(tableTag[0],"babyid");
        $("myMaster").href = "baby/baby_master.aspx?babyid=" + getTagValue(tableTag[0],"babyid");      
                  
    }else{
        bolLoginFlag=false;
        if(bolAotu){
        bolAotu=false;
        }
        else{
        alert("用户名或密码错误！");
        document.getElementById("txtUserName").focus();
        }
    }
}

function autoLogin()
{
var Ajax = new oAjax("./common/LoginCheck.aspx","AutoLoginCheck",loginCheck,false);
bolAotu=true;
Ajax.Get();
}

function Logout(){
var Ajax = new oAjax("./common/Logout.aspx","Logout",logoutReturn,false);
bolAotu=true;
Ajax.Get();
document.getElementById("showdenglu").style.display = "";
$("sLoginName").innerHTML=",访客";
}

function logoutReturn(content){
var isSuccess = getTagValue(content,"Success");
    
    if(isSuccess && isSuccess =="True"){
    //document.getElementById("tdLogin").innerHTML=strLogin;
    document.getElementById("noLogin").style.display = "";
        document.getElementById("isLogin").style.display = "none";
    
    }
    else{alert("网络错误！请稍后再试！")}

}