﻿function pageLoad()
{

}            

// This function sets and gets the default
// login completed callback function.
function SetDefaultLoginCompletedCallBack()
{
    // Set the default callback function.
    Sys.Services.AuthenticationService.set_defaultLoginCompletedCallback(OnLoginCompleted);
   
    // Get the default callback function.
    var callBack = Sys.Services.AuthenticationService.get_defaultLoginCompletedCallback();
}

function SetDefaultLogoutCompletedCallBack()
{
    // Set the default callback function.
    Sys.Services.AuthenticationService.set_defaultLogoutCompletedCallback(OnLogoutCompleted);
   
    // Get the default callback function.
    var callBack =  Sys.Services.AuthenticationService.get_defaultLogoutCompletedCallback();
}

function SetDefaultFailedCallBack()
{
    // Set the default callback function.
    Sys.Services.AuthenticationService.set_defaultFailedCallback(OnFailed);
   
    // Get the default callback function.
    var callBack =  Sys.Services.AuthenticationService.get_defaultFailedCallback();
}

function OnLogin(userName,pwd) 
{   
    SetDefaultLoginCompletedCallBack();
    SetDefaultLogoutCompletedCallBack();
    SetDefaultFailedCallBack(); 
    
    Sys.Services.AuthenticationService.login(userName,pwd, true,null,null,null,null,"User Context");
        
}

function OnClickLogout() 
{  
   Sys.Services.AuthenticationService.logout(null,null, null, null); 
} 

// if the authentication fails.      
function OnFailed(error, 
    userContext, methodName)
{    
	DisplayInformation("error:message = " + 
	    error.get_message());
	DisplayInformation("error:timedOut = " + 
	    error.get_timedOut());
	DisplayInformation("error:statusCode = " + 
	    error.get_statusCode());			
}

function OnLoginCompleted(validCredentials, 
    userContext, methodName)
{	
    document.getElementById('loginProgress').style.display = 'none';
    document.getElementById('txtUserName').value='';
    document.getElementById('txtPwd').value='';
    if (validCredentials == true) 
    {   
        document.getElementById('loginMsg').innerHTML = '';
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm._doPostBack('ctl00_UpdatePanel1', '');
        
        //prm.add_endRequest();              
    }
    else
    {    
            
        document.getElementById('loginMsg').innerHTML = '用户名或密码错误';
    }
}

function OnLogoutCompleted(result) 
{
    Sys.WebForms.PageRequestManager.getInstance()._doPostBack('ctl00_UpdatePanel1', '');
}                   
function DisplayInformation(text)
{
//    document.getElementById("FeedBackID").innerHTML = 
//        "<br/>" + text;

//    // Display authentication service information.
//    
//    
//	var userLoggedIn =
//	    Sys.Services.AuthenticationService.get_isLoggedIn();
//	
//    var authServiceTimeout =       
//        Sys.Services.AuthenticationService.get_timeout();
//   
//    var userLoggedInfo = 
//        "<br/> User logged in:                 " + userLoggedIn;
//        
//    var timeOutInfo = 
//        "<br/> Authentication service timeout: " + authServiceTimeout;
//        
//    document.getElementById("FeedBackID").innerHTML = 
//        userLoggedInfo + timeOutInfo; 
}
function OnClickLogin()
{
    var userName = document.getElementById('txtUserName').value;
    var pwd = document.getElementById('txtPwd').value;
    
    if(userName==''||userName==null)
    {
        document.getElementById('rfvUserName').innerHTML = '*';  
        return;      
    }
    else
    {
        document.getElementById('rfvUserName').innerHTML = '';      
    }
    if(pwd==''||pwd==null)
    {
        document.getElementById('rfvPwd').innerHTML = '*';      
        return;    
    }
    else
    {
        document.getElementById('rfvPwd').innerHTML = '';
        
    }
    document.getElementById('loginProgress').style.display = '';
    OnLogin(userName,pwd);
     
}
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
