﻿var inn=0;    

//--------------
//document.cookie = 'killme' + escape('nothing');//"isLogin=false;";//

window.onload=function(){
//    if (document.cookie == "")
//    {
//　　    $("#chkCookie").show();
//    } 
   $("#userid").val($.cookie("dispUID")); 


	if ($.browser.msie){
		$("input[@type='text'], input[@type='password'], textarea").focus(function(){$(this).addClass("ie_focus")}).blur(function(){$(this).removeClass("ie_focus")});
	}
	
    $("#btnLogin").click( function() { login() } );
    $("#btnLogout").click( function() { btnLogout() } );
//    $("#Button2").click( function() { reg() } );
//    $("#Button3").click( function() { view() } );   
//    $("#getpwd").click( function() { getpwd();return false; } );  
    
    
    $("#userid").keypress( function(evt) { 
          var thisKey=(evt)?evt.which:window.even.KeyCode;
          if((thisKey ==13)) //
          { 
              $("#password")[0].focus();
              return false;                  
          } 
    } );     
    $("#password").keypress( function(evt) { 
          var thisKey=(evt)?evt.which:window.even.KeyCode;
          if((thisKey ==13)) //
          { 
              //alert("Hello     "+thisKey);	
              login();
              return false;                  
          } 
    } ); 	

    //$("#userid").val("10010004");//改变对象属性 //document.getElementById("userid").value="10010004"; // 
    //$("#password").val("0");//改变对象属性
   // $("#error_div").css({ visibility: "hidden"}); 
    
        $("#loading").ajaxStart(function(){
            $(this).show();        
        }).ajaxStop(function(){
            $(this).hide();     
        });
        
        //--------------------------
        var isLogin=$.cookie("isLogin");
        if(isLogin=="True")
        {
            $("#login_a").hide();
            $("#login_b").show();
            $("#dispUID").text($.cookie("dispUID"));
        } 
       
}
//--------------

//$(document).ready(function(){
//        
//});

function showMessage(msText){
        $("#error_div").text(">>"+msText);
        //$("#error_div").css({visibility: "visible"});
        $("#error_div").show();
        timeOut=setTimeout("clearMessage()",3000);
}

function clearMessage(){
    $("#error_div").text("");
    //$("#error_div").css({visibility: "hidden"});
    $("#error_div").hide();
}

function btnLogout(){
    //$.cookie("isLogin","False");    
        $.get("loginc.ashx", 
            { 
                cmd:"logout",
                duid: $("#userid").val(), 
                pwd:  $("#password").val() 
            }, 
            function(xml){            
                var resu_text = $("resu",xml).text(); //$(xml).find('resu').each(function(){//var resu_text = $(this).text();
                if(resu_text=="OK") 
                {                  
                    $("#login_a").show();
                    $("#login_b").hide();  
                    
                    return true;                                 
                }else
                {           
                    showMessage(resu_text);    
                }                    
            }
        );
    

}

function doLogin(){   
        if(inn++>=3){
            alert("三次尝试,登录失败!");
            return false;
        }
        
        $.get("loginc.ashx", 
            { 
                cmd:"login",
                duid: $("#userid").val(), 
                pwd:  $("#password").val() 
            }, 
            function(xml){            
                var resu_text = $("resu",xml).text(); //$(xml).find('resu').each(function(){//var resu_text = $(this).text();
                if(resu_text=="OK") 
                {                  
                    clearMessage();
                    $("#password").attr({ value: ""});//改变对象属性                              
                    //self.top.location.href="../LearnMain/learnIndex.htm";  
                    //self.top.location.href="../showFacePage/faceABC.htm";                     
 
                   $("#login_a").hide();
                   $("#login_b").show();                    
                  $("#dispUID").text($.cookie("dispUID"));   
                    
                    return true;                                 
                }else
                {           
                    showMessage(resu_text);    
                }                    
            }
        );
}

function fCheck(){

    $("#userid").val($.trim( $("#userid").val()));
    $("#password").val($.trim( $("#password").val()));    

	if($("#userid").val() =="") {
		showMessage("请输入你的帐号");   
		$("#userid")[0].focus(); 
		return false;
	}	
	
	if($("#password").val() =="") {
		showMessage("请输入相应的密码"); 
		$("#password")[0].focus(); 
		return false;
	}	

	return true;
}

function login() {
    if(fCheck()){
        doLogin();
        //alert("通过验证");
    }
}

//function reg() {
//    var regPage="../RegPage/DoRegest.aspx";
//    self.top.location.href=regPage;      
//}
//
//function view() {
//    var view="../learnMain/ViewLearningInfo.aspx?vid="+$("#userid").val();
//    self.top.location.href=view;      
//}
//
//function getpwd() {
//    var tohref=$("#getpwd").attr("href");
//    self.top.location.href=tohref+"?uid="+$("#userid").val();      
//}