﻿

    function iniUser() {

        var IsDebug = false;

        if (IsDebug) { alert("初始化用户"); };

        var oUser = new Object();
        oUser.isLogin = false;
        oUser.AAID = 0;
        oUser.username = "";
        oUser.nickname = "";
        oUser.facePhotoURL_S = "http://www.freedom-game.com/uc2/images/nologo.gif";
        oUser.facePhotoURL_M = "http://www.freedom-game.com/uc2/images/nologo.gif";
        oUser.facePhotoURL_L = "http://www.freedom-game.com/uc2/images/nologo.gif";
        oUser.CFlag = "";
        oUser.FaceFileName = "";
        oUser.routType = 0;


        if (IsDebug) { alert("判断用户cookie FREEGAME_UserInfo2 是否存在"); };

        var vCookieInfo = $.cookie("FREEGAME_UserInfo2");


        if (vCookieInfo == null) {
            if (IsDebug) { alert("用户cookie FREEGAME_UserInfo2 为 null,因此返回未登录"); };
            oUser.isLogin = false;
            oUser.AAID = 0;
            oUser.username = "";
            oUser.nickname = "";
            oUser.facePhotoURL_S = "";
            oUser.facePhotoURL_M = "";
            oUser.facePhotoURL_L = "";
            oUser.CFlag = "";
            oUser.FaceFileName = "";
            oUser.routType = 0;
            return oUser;
        };


        if (IsDebug) { alert("用户cookie FREEGAME_UserInfo2 数据存在，数据如下"); };
        if (IsDebug) { alert(vCookieInfo); };


        //提取COOKIE内数据
        var arrayCookieItem = vCookieInfo.split("&");
        if (IsDebug) { alert("Cookie值数量：" + arrayCookieItem.length); };

        var theItem = new Object();
        for (var i = 0; i < arrayCookieItem.length; i++) {
            theItem[arrayCookieItem[i].split("=")[0]] = unescape(arrayCookieItem[i].split("=")[1]);
        }


        oUser.AAID = theItem['FREEGAME_AAID'];
        oUser.username = theItem['FREEGAME_UserName'];
        oUser.nickname = theItem['FREEGAME_NickName'];
        oUser.CFlag = theItem['FREEGAME_UserName'];
        oUser.routType = theItem['FREEGAME_routType'];
        var Fphoto = theItem['FREEGAME_FaceFileName'];

        oUser.FaceFileName = Fphoto;

        if (Fphoto != "") {
            oUser.facePhotoURL_S = "http://www.freedom-game.com/UserData/Users/" + jsleft(oUser.username, 1) + "/" + jsright(oUser.username, 1) + "/" + oUser.username + "/" + Fphoto + "_40x40.jpg";
            oUser.facePhotoURL_M = "http://www.freedom-game.com/UserData/Users/" + jsleft(oUser.username, 1) + "/" + jsright(oUser.username, 1) + "/" + oUser.username + "/" + Fphoto + "_80x80.jpg";
            oUser.facePhotoURL_L = "http://www.freedom-game.com/UserData/Users/" + jsleft(oUser.username, 1) + "/" + jsright(oUser.username, 1) + "/" + oUser.username + "/" + Fphoto + "_160x160.jpg";
        };

        oUser.isLogin = true;


        oUser.showUserName = function () {
            alert(this.username);
        }
        oUser.showfacePhotoURL_S = function () {
            alert(this.facePhotoURL_S);
        }


        return oUser;

    }




    function jsleft(lefts, leftn) {

        var sl = lefts;

        sl = sl.substring(0, leftn);

        return sl;
    }

    function jsright(rights, rightn) {

        var sr = rights;

        sr = sr.substring(sr.length - rightn, sr.length);

        return sr;
    }
