﻿//用户登录
function Login(obj){
    this.OBJ = obj;    
    this.GetLogin=function(){
        var username = document.getElementById('text_username').value.trim();
        var password = document.getElementById('text_password').value.trim();
        document.getElementById('UserType').value= getRadioValue("selectMember"); 
        var userType = document.getElementById('UserType').value.trim();
        if(username.length<1){
            alert("用户名不能为空!");
            document.getElementById('text_username').focus();
            return;
        }
        if(password.length<1){
            alert("密码不能为空!");
            document.getElementById('text_password').focus();
            return;
        }
        if(userType.value=="-1"){
            alert("请选择用户类型!");
            return;
        }
        document.getElementById('HidPassword').value = MD5(document.getElementById('text_password').value.trim());
        var hidPassword = document.getElementById('HidPassword').value.trim();
                       
        var returnVal = null;
        try{
            returnVal = this.OBJ.UserLogin(username, password, hidPassword, userType).value;
        }catch(ex){
            returnVal = null;       
        }
        
        if(returnVal == null){
            alert("用户名或密码错误.");
        }
        var url = arguments[0];
        if(url != null)
            if(url != ""){
                location.href=url;
                return;
            }            
        this.FillLoginInfo();
    }
    
    this.LoginOut = function(url){
        var returnVal = this.OBJ.UserLoginOut().value;
        if(returnVal){
//            if(url != ''){
//                window.location.href = url;
//            }
//            else
//            {
//                this.FillLoginInfo();   
//            }
            window.location.href = this.OBJ.GetRootPath().value + 'index.aspx';
        }     
    }
    
    this.FillLoginInfo = function(){
        var strUserLoginUrl = this.OBJ.GetRootPath().value + "UserControls/WUCLogin.aspx?cache=" + Math.random() + "";
        document.getElementById("divLoginInfo").innerHTML = getHttpHtml(strUserLoginUrl);
    }    
//    document.getElementsByTagName("form")[0].action="CommonLogin.aspx"
//    //document.form1.target="_top";
//    document.getElementsByTagName("form")[0].submit();
}

function keyDown(){
    var keycode = event.keyCode;
    if(keycode == 13){
        //var type = form1.selectMember.options[form1.selectMember.selectedIndex].value;   
        Login();
    }
}

document.onkeydown = keyDown;

function SetFocus(){
    if(document.getElementById("text_username")){
        document.getElementById('text_username').focus();
    }
}

