﻿/// <reference path="JsCommonFunction.js" />


$(document).ready(function(){
      CheckIsLogin();      
      CaptChaImage();
});
 
function CaptChaImage(){
    JSONWebService("http://www.urgamer.com/WebService/HomePageLoginWebService.asmx/GetCaptchaImage","{}",function(objJSON){
          $('span[id=lblCaptCha]').html(objJSON);
    });
}

function CheckIsLogin(){
    JSONWebService("http://www.urgamer.com/WebService/HomePageLoginWebService.asmx/CheckIsLogin","{}",function(objJSON){
        if(objJSON.retValue == "1"){
            $("div[id=login_in]").css("display","none");
            $("div[id=login_info]").css("display","inline");
            $('div[id=account]').html(objJSON.Account);
            $('div[id=nickName]').html(objJSON.nickName);
        }
    });
}
$("#btnLogout").click(function(){
    $("div[id=login_in]").css("display","inline");
    $("div[id=login_info]").css("display","none");
    JSONWebService("http://www.urgamer.com/WebService/HomePageLoginWebService.asmx/Logout","{}",function(objJSON){
    });
});
$("#btnLogin").click(function(){
    if($('#txtAccount').val().length < 4){
        jAlert("请填写通行证，通行证长度大于必须大于4位！","错误信息");
        return false;
    }
    
    if($('#txtPassword').val()==null || $('#txtPassword').val()==""){
        jAlert("请填写密码！","错误信息");
        return false;
    }
    
    if($('#txtValidate').val().length != 4){
        jAlert("请填写验证码！","错误信息");
        return false;
    }
    JSONWebService("http://www.urgamer.com/WebService/HomePageLoginWebService.asmx/LoginAccount","{account:'"+$('#txtAccount').val()+"',password:'"+$('#txtPassword').val()+"',validateCode:'"+$('#txtValidate').val()+"',retValue:''}",function(objJSON){
        var message = objJSON.Account;
        if(objJSON.retValue == null){
            jAlert("系统错误，请稍后再试!","错误信息");
        }
        else if(objJSON.retValue == "0"){
           jAlert(message,"错误信息");
        }
        else if(objJSON.retValues == "-1"){
           jAlert(message,"错误信息");
           window.location="http://www.urgamer.com";
        }
        else{
            $("div[id=login_in]").css("display","none");
            $("div[id=login_info]").css("display","inline");
            $('div[id=account]').html(objJSON.Account);
            $('div[id=nickName]').html(objJSON.nickName);
        }
    });
    return false;

});