﻿var $j = jQuery.noConflict();
$j(document).ready(function() {
    //page.InitGeneral();
    //page.InitOtherGeneral();
    $j('#beginWar').bind('click', function() { GoToWarFirst(); });

    $j('#Search_FamousGeneral').bind('click', function() { page.SelectFamousGeneral(); }); //名将按钮
    $j('#BodyPart h1>a')
        .click(function(event) {
            page.ShowOperate(event, this);
            $j(this).unbind("mouseover");
            $j(this).unbind("mouseout");
        }); //A点击时间
    $j('#bt_Close').bind('click', function() {
        $j('#Operate_Div').hide();
        $j('#BodyPart h1>a')
        .click(function(event) {
            page.ShowOperate(event, this);
        }) //A点击时间
        .mouseover(function(event) {
            var operateindex = this.id.toString().split("_");
            if (page.OddEquipment[operateindex[1]]) {//该部位已有装备，则有详细信息
                $j('#OddDetail').show();
                page.ShowOddDetail(event, page.OddEquipment[operateindex[1]]);
            }
        })//A获得焦点
        .mouseout(function(event) { $j('#OddDetail').hide(); })//A失去焦点
    });
    $j('#bt_add').bind('click', function(event) { page.SearchEquipment(event); }); //装备操作
    $j('#bt_delete').bind('click', function() { page.DeleteEquipment(); }); //卸下操作
    $j('#btUpgrade').bind('click', function() { page.AddLevel(); }); //升级按钮
    $j('#btnDetermine').bind('click', function() { page.Determine(); }); //确定按钮
    $j('#GeneralLevel')
    .bind('keyup', function() {
        page.Upgrade();
    })
    .bind('change', function() {
        if ($j('#GeneralLevel').val() == "") {
            alert("请输入等级！");
            $j('#GeneralLevel').val(1);
            page.Upgrade();
        }
    }); //自定义升级
    $j('#GeneralName').bind('change', function() { page.UpdateName(); }); //更改名称
    $j('#GeneralCommand').bind('change', function() { page.UpdateCommand(); }); //更改名称
    $j('#GeneralSpeed').bind('change', function() { page.UpdateSpeed(); }); //更改速度//9.24 修改
    $j('#GeneralAttack').bind('change', function() { page.UpdateAttack(); }); //更改攻击//9.24 修改
    $j('#GeneralDefend').bind('change', function() { page.UpdateDefend(); }); //更改防御//9.24 修改
    $j('#Washpoints').bind('click', function() { page.Washpoints(); }); //洗点按钮
    $j('#reset').bind('click', function() { page.InitGeneral(); }); //重置按钮

    $j('#btnaddAffairs').bind('click', function() { page.AddAffairs(); }); //加内政1点
    $j('#btnDeleAffairs').bind('click', function() { page.DeleteAffairs(); }); //减内政1点

    $j('#btnaddForce').bind('click', function() { page.AddForce(); }); //加勇武1点
    $j('#btnDelForce').bind('click', function() { page.DeleteForce(); }); //减勇武1点

    $j('#btnaddIntelligence').bind('click', function() { page.AddIntelligence(); }); //加智谋1点
    $j('#btnDelIntelligence').bind('click', function() { page.DeleteIntelligence(); }); //减智谋1点

    $j('#btnSearchGeneral').bind('click', function() { page.PageChange2(1); }); //查询名将按钮
    $j('#btnSearchEquip').bind('click', function() { page.PageChange1(1); }); //查询装备按钮

    $j('#GeneralAffairs').bind('keyup', function() { $j('#btnDetermine').show(); }); //内政变化后显示确定按钮
    $j('#GeneralForce').bind('keyup', function() { $j('#btnDetermine').show(); }); //勇武变化后显示确定按钮
    $j('#GeneralIntelligence').bind('keyup', function() { $j('#btnDetermine').show(); }); //智谋变化后显示确定按钮

    $j('#GoToWarDiv').bind('click', function() { GoToWar(); }); //导入校场模拟器入口按钮
    $j('#GoBackToGen').bind('click', function() { GoBackToGeneral(page.NowGeneral); }); //校场导入层取消按钮
    $j('#GoToSchoolField').bind('click', function() { GoToSchoolField(); }); //进入校场模拟器按钮（确定）
    //    $j('#SchoolFClose').bind('click', function() { document.location.href = "Simulator.aspx?wartype=0"; }); //战场关闭按钮

    $j('#Def_DefenseConfig').bind('click', function() { Spage.OpenDiv(0); }); //打开城防配置（防守方）
    $j('#Def_ForceConfig').bind('click', function() { Spage.OpenDiv(1); }); //打开兵力配置（防守方）
    $j('#Def_TechnologyConfig').bind('click', function() { Spage.OpenDiv(3); }); //打开道具配置
    $j('#Att_TechnologyConfig').bind('click', function() { Spage.OpenDiv(2); }); //打开科技配置（攻击方）

    $j('#DefenseSubmit').bind('click', function() { Spage.InitForceDetail(0); }); //城防配置确定按钮
    $j('#DefenseDivClose').bind('click', function() { Spage.CloseDiv(0); }); //城防配置关闭按钮

    $j('#ForceSubmit').bind('click', function() { Spage.InitForceDetail(1); }); //兵力配置确定按钮
    $j('#ForceDivClose').bind('click', function() { Spage.CloseDiv(1); }); //兵力配置关闭按钮

    $j('#TechnologySubmit').bind('click', function() { Spage.InitForceDetail(2); }); //科技配置确定按钮
    $j('#TechnologyDivClose').bind('click', function() { Spage.CloseDiv(2); }); //科技配置关闭按钮

    $j('#PropsSubmit').bind('click', function() { Spage.InitForceDetail(4); }); //道具配置确定按钮
    $j('#CloseProps').bind('click', function() { Spage.CloseDiv(4); }); //道具配置关闭按钮
    //只能输入数字
    $j('#City :input,#Force :input,#Technology :input').onlypressnum();
    $j('#GeneralLevel,#GeneralAffairs,#GeneralForce,#GeneralIntelligence,#GeneralCommand,#GeneralSpeed,#GeneralAttack,#GeneralDefend').onlypressnum(); //9.24 修改
    $j('#txtstartlevel,#txtendlevel').onlypressnum();
    $j("#txtstartlevel,#txtendlevel").toggleVal();
    $j("#txtstartlevel,#txtendlevel").blur(function() {
        if ($j(this).val() == "") { $j(this).val(this.defaultValue); }
        if (parseInt($j(this).val()) > 100) { $j(this).val(100); }
    });
    $j('#Force :input,#City .divcen :input').each(function() {
        $j(this).bind("change", function() {
            if ($j(this).val() == "") {
                alert("数量不能为空！");
                $j(this).val(0);
            }
        });
    });

    $j('#Technology :input,#City .Cbom :input').each(function() {
        $j(this).bind("keyup", function() {
            if (parseInt($j(this).val()) > 10) {
                alert("等级最高只能为10！");
                $j(this).val(10);
            }
        })
        .bind("change", function() {
            if ($j(this).val() == "") {
                alert("请输入等级！");
                $j(this).val(0);
            }
        });

    }); //科技输入限制

    $j('#btnBegin').bind('click', function() { Spage.BeginWar(); });

    $j("#ReportTitle").toggleVal();
    $j('#Reportdiscuss').bind('keyup', function() {
        if ($j(this).val().length >= 200) {
            $j(this).val($j(this).val().substring(0, 200))
        }
    });
});

//直接进入战场
function GoToWarFirst() {
    Spage.WarRound = 0;
    Spage.BeInBatte = 0; //未进入过战场，1：已进入过战场
    Spage.WarDistanse = 0;
    $j('#warside').val(0);
    $j('#warenvironment').val(2);
    Spage.A_ForceConfig = new Array(); //攻击方兵力配置
    Spage.A_TechnologyConfig = new Array(); //攻击方科技配置

    Spage.D_ForceConfig = new Array(); //防守方兵力配置
    Spage.D_TechnologyConfig = new Array(); //防守方科技配置
    Spage.D_CityDefenseConfig = new Array(); //防守方城防配置
    Spage.WarDistanse = 0;
    Spage.AProps = new Array(0, 0, 0, 0, 0); //攻击方道具
    Spage.DProps = new Array(0, 0, 0, 0, 0); //防守方道具
    Spage.WinSide = null; //获胜方
    Spage.IsOver = false; //是否已结束

    Spage.ABeginForceNumber = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    Spage.DBeginForceNumber = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    Spage.DBeginDefenseNumber = new Array(0, 0, 0, 0, 0);


    $j('#Att_PicAdd').unbind();
    $j('#Def_PicAdd').unbind();
    $j('#SendReport').hide();

    $j('#battlefieldDistanse').html('战场距离0');
    $j('#Def_DefenseConfig').show();
    $j('#Def_ForceConfig').show();
    $j('#Def_TechnologyConfig').show();
    $j('#Att_ForceConfig').show();
    $j('#Att_TechnologyConfig').show();
    Spage.AttGeneral = null; //攻击方武将信息
    Spage.DefenseGeneral = null; //防守方武将信息
    $j('#City :input,#Force :input,#Technology :input,#Props :input').val(0);
    Spage.WarReport = "";
    $j('#WordWarReport').hide();
    $j('#WarReportText').val("");
    $j('#Generals').hide();
    $j('#SchoolDiv').hide();
    $j('#Genbomtext').hide();
    //初始化武将
    var json = {
        "picAdd": "images/picssss.jpg", "Pic": "", "Name": "战场", "Level": "1",
        "Potential": "—", "Experience": "0", "Command": "0", "Affairs": "0", "Chivalrous": "0", "Resourcefulness": "0", "Description": "0", "GEquips": "",
        "Attack": "0", "Defense": "0", "Support": "—", "Salary": "—", "Speed": "0", "Power": "0", "Energy": "0"
    }
    page.GeneralType = 0;
    page.NowGeneral = new Generals(json, page.GeneralType);
    //page.ShowDetail(page.NowGeneral);
    GoToWar();
}
var SClass = { Version: '1.0.0.0' };
SClass.Page = Class.create({
    initialize: function() {
        this.CurrentPage1 = 1;
        this.pageLine1 = 5;
        this.divPaginationID1 = null;

        this.CurrentPage2 = 1;
        this.pageLine2 = 5;
        this.divPaginationID2 = null;

        this.GeneralType = 0; //武将类型 0：自定义 1：名将
        this.NowGeneral = null; //当前武将对象
        this.NowOp_Id = null; //当前操作的A标签 ID
        this.index = null; //装备SubIndex
        this.OtherGeneral = null; //他方武将对象

        this.OddEquip_index = null; //原来已装备数组中索引 如Body_0中的0
        this.OddEquipment = new Array(); //已装备的装备数组

        this.w = 0; this.j = 0; this.k = 0;
        this.EquipmentArray = new Array(); //装备数组（强化后）
        this.FirstEquipmentArray = new Array(); //装备数组
        this.EquipmentDetialSort = new Array(); //装备属性排序

    },
    GetEleByClientID: function(divPagination1, divPagination2) {
        this.divPaginationID1 = divPagination1;
        this.divPaginationID2 = divPagination2;
    },
    //初始化武将（自定义）我方
    InitGeneral: function() {
        var json = {
            "picAdd": "images/picssss.jpg", "Pic": "", "Name": "自定义", "Level": "1",
            "Potential": "—", "Experience": "0", "Command": "0", "Affairs": "0", "Chivalrous": "0", "Resourcefulness": "0", "Description": "0", "GEquips": "",
            "Attack": "0", "Defense": "0", "Support": "—", "Salary": "—", "Speed": "0", "Power": "0", "Energy": "0"
        }
        this.GeneralType = 0;
        this.NowGeneral = new Generals(json, this.GeneralType);
        this.ShowDetail(this.NowGeneral);
     
    },
    //初始化他方一武将信息
    InitOtherGeneral: function() {
        var json = {
            "picAdd": "images/picssss.jpg", "Pic": "", "Name": "敌方", "Level": "1",
            "Potential": "—", "Experience": "0", "Command": "0", "Affairs": "0", "Chivalrous": "0", "Resourcefulness": "0", "Description": "0", "GEquips": "",
            "Attack": "0", "Defense": "0", "Support": "—", "Salary": "—", "Speed": "0", "Power": "0", "Energy": "0"
        }
        this.GeneralType = 0;
        this.OtherGeneral = new Generals(json, this.GeneralType);
    },
    //自定义升级操作
    Upgrade: function() {
        if (parseInt($j('#GeneralLevel').val()) > 100) {
            alert("等级最高只能为100！"); $j('#GeneralLevel').val(100);
        }
        else if ($j('#GeneralLevel').val() == "") {
            $('GeneralLevel').focus(); return;
        }
        this.NowGeneral.Upgrade(this.NowGeneral, $j('#GeneralLevel').val()); //9.24 修改加了NowGeneral参数
        this.ShowDetail(this.NowGeneral);
    },

    //点击升级操作
    AddLevel: function() {
        if (this.NowGeneral.NewLevel < 100) {
            this.NowGeneral.AddLevel(this.NowGeneral); //9.24 修改加了NowGeneral参数
            this.ShowDetail(this.NowGeneral);
            $j('#btnaddAffairs').show();
            $j('#btnaddForce').show();
            $j('#btnaddIntelligence').show();
        }
        else
            alert("已达到等级上限100");
    },
    //更改统率
    UpdateCommand: function() {
        this.NowGeneral.Addcommand($j('#GeneralCommand').val());
        this.ShowDetail(this.NowGeneral);
    },
    //更改速度
    UpdateSpeed: function() {
        this.NowGeneral.AddSpeed($j('#GeneralSpeed').val());
        this.ShowDetail(this.NowGeneral);
    },
    //更改攻击
    UpdateAttack: function() {
        this.NowGeneral.AddAttack($j('#GeneralAttack').val());
        this.ShowDetail(this.NowGeneral);
    },
    //更改防御
    UpdateDefend: function() {
        this.NowGeneral.AddDefend($j('#GeneralDefend').val());
        this.ShowDetail(this.NowGeneral);
    },

    //更改名称
    UpdateName: function() {
        this.NowGeneral.UpdateName($j('#GeneralName').val());
        this.ShowDetail(this.NowGeneral);
    },
    //洗点操作
    Washpoints: function() {
        if (this.NowGeneral.ClearPoint()) {
            this.ShowDetail(this.NowGeneral);
            $j('#btnaddAffairs').show();
            $j('#btnaddForce').show();
            $j('#btnaddIntelligence').show();
            this.w = 0; this.j = 0; this.k = 0;
        } else {
            alert("你不能洗点");
        }
    },

    //确定操作，传入修改后的武将内政等信息
    Determine: function() {
        if (this.CheckNum()) {
            this.NowGeneral.Update($j('#GeneralAffairs').val(), $j('#GeneralForce').val(), $j('#GeneralIntelligence').val(), $j('#GeneralPotential').val(), this.NowGeneral); //9.24 修改
            this.ShowDetail(this.NowGeneral);
            this.w = 0; this.j = 0; this.k = 0;
        }
    },
    //判断文本框值是否符合条件
    CheckNum: function() {
        if (!this.isInt($j('#GeneralAffairs').val())) {
            alert("内政必须为正整数！"); return false;
        }
        if (!this.isInt($j('#GeneralForce').val())) {
            alert("勇武必须为正整数！"); return false;
        }
        if (!this.isInt($j('#GeneralIntelligence').val())) {
            alert("智谋必须为正整数！"); return false;
        }
        return true;
    },
    //检查是否整数
    isInt: function(s) {
        var pattern = /^-?\d+$/;
        if (s.search(pattern) != 0) {
            return false;
        }
        return true;
    },
    //操作层 选择相应操作
    ShowOperate: function(e, obj) {
        $j('#OddDetail').hide();
        this.SetPosition(e, "Operate_Div"); //定位操作层
        $j('#Operate_Div').show();
        this.NowOp_Id = obj.id;
        var operateindex = this.NowOp_Id.toString().split("_");
        //this.OddEquip_index = operateindex[1];
        if (this.OddEquipment[operateindex[1]]) {//该部位已有装备，则有卸下功能

            //            $j('#bt_delete').attr('disabled', '');
            //            $j('#bt_add').attr('disabled', 'disabled');
            $j('#bt_delete').show();
            $j('#bt_add').hide();
        }
        else {
            //            $j('#bt_add').attr('disabled', '');
            //            $j('#bt_delete').attr('disabled', 'disabled');
            $j('#bt_delete').hide();
            $j('#bt_add').show();
        }
    },

    //选择相应的装备 装备列表
    SearchEquipment: function(e) {
        this.OddEquip_index = this.NowOp_Id.toString().split("_")[1];
        //卸下装备后再选择装备
        if (this.OddEquipment[this.OddEquip_index]) {
            alert("请先卸载装备！"); return;
        }
        $j('#geDivList').hide();
        $j('#eqDivList').hide();
        $j('#txtEquip').val("");
        var value = parseInt(this.OddEquip_index);
        $j('#Operate_Div').hide();
        this.CurrentPage1 = 1;
        var action = "action=EquipsBySub&pageNum=1&rowNum=" + this.pageLine1 + "&SubIndex=" + this.GetSubIndexByid(value);
        AjaxMethod(action, FomatEquipment);
    },
    //卸下装备
    DeleteEquipment: function() {
        this.OddEquip_index = this.NowOp_Id.toString().split("_")[1];
        var e = this.OddEquipment[this.OddEquip_index];
        this.OddEquipment[this.OddEquip_index] = null;
        //$("" + this.NowOp_Id + "").innerHTML = this.GetNameByKey();
        $j('#Operate_Div').hide();
        //卸下装备后改变武将详细信息
        this.NowGeneral.RemoveEquip(e, this.NowGeneral);
        this.ShowDetail(this.NowGeneral);
    },
    //装备分页
    PageChange1: function(pnw) {
        this.CurrentPage1 = parseInt(pnw);
        this.SearchEquip();
    },
    //查询装备
    SearchEquip: function() {
        var querystring = $j('#txtEquip').val();
        var startlevel = parseInt($j('#txtstartlevel').val());
        var endlevel = parseInt($j('#txtendlevel').val());
        if (startlevel <= endlevel) {
            var action = "action=EquipsBySub&pageNum=" + this.CurrentPage1 + "&rowNum=" + this.pageLine1 + "&SubIndex=" + this.index + "&querystring=" + querystring + "&SLevel=" + startlevel + "&ELevel=" + endlevel;
            AjaxMethod(action, FomatEquipment);
        }
        else {
            alert("起始等级不能大于截止等级！");
        }
    },
    //选择装备
    SelectEquipment: function(aindex) {
        var e = this.EquipmentArray[aindex];
        if (e.EquipLevel > this.NowGeneral.NewLevel) {
            alert("该装备等级过高，您无法装备");
            return;
        }
        $j('#table_Equipment').hide();
        $j('#eqDivList').hide();
        //$("" + this.NowOp_Id + "").innerHTML = "<img src=\"" + e.PictureAddress + "\" width=\"30\" height=\"30\" />";
        this.OddEquipment[this.OddEquip_index] = e;
        //装备上装备后，改变武将详细信息
        this.NowGeneral.AddEquip(e, this.NowGeneral); //9.24修改
        this.ShowDetail(this.NowGeneral);
        //$j('#Equiplist img').unbind('click');
    },
    //焦点移到待选装备上时，显示当前装备详情和该位置原装备详情（如果存在）
    mouseMove: function(e, aindex) {
        var equ = this.EquipmentArray[aindex];
        this.ShowNewDetail(e, equ);
    },
    //失去焦点
    mouseOut: function() {
        $j('#NowDetail').hide();
        $j('#OddDetail').hide();
    },
    //选择名将
    SelectFamousGeneral: function() {
        $j('#geDivList').hide();
        $j('#eqDivList').hide();
        $j('#txtGeneral').val("");
        var Action = "action=GeneralData&pageNum=1&rowNum=" + this.pageLine2;
        AjaxMethod(Action, FomatGeneral);
    },
    //名将分页
    PageChange2: function(pnw) {
        this.CurrentPage2 = parseInt(pnw);
        this.SearchGeneral();
    },
    //查询名将
    SearchGeneral: function() {
        var querystring = $j('#txtGeneral').val();
        var Action = "action=GeneralData&pageNum=" + this.CurrentPage2 + "&rowNum=" + this.pageLine2 + "&GeneralName=" + querystring;
        AjaxMethod(Action, FomatGeneral);
    },
    //确定选择名将
    SelectGeneral: function(Generalindex) {
        var Action = "action=OneGeneralData&GeneralIndex=" + Generalindex;
        AjaxMethod(Action, FomatGeneralDetail);
    },

    //直接返回到校场模拟器窗口
    BackToBattField: function() {
        if (Spage.SelectGeneral == 0) {
            Spage.AttGeneral = this.NowGeneral;
        }
        else {
            Spage.DefenseGeneral = this.NowGeneral;
        }
        $j('#Generals').hide();
        $j('#Genbomtext').hide();
        $j('#GenPop').hide();
        //$j('#SchoolDiv').show();
        $j('#SchoolDiv').fadeIn(0);
        Spage.InitSchoolFieldTitle();
    },

    //显示名将详细信息
    ShowDetail: function(general) {
        this.w = 0;
        this.j = 0;
        this.k = 0;
        if (general == null) {
            this.InitGeneral();
        }
        this.NowGeneral = general;

        $j('#Generals').show();
        $j('#GeneralPic').attr("src", this.NowGeneral.PicAdd);
        $j('#GeneralName').val(this.NowGeneral.Name);
        $j('#GeneralLevel').val(this.NowGeneral.NewLevel);
        $j('#GeneralExperience').val(this.NowGeneral.TotalExperience + "/" + this.NowGeneral.LevelExperience);

        if (general.NewSpeed != null) {
            $j('#GeneralSpeed').val(this.NowGeneral.NewSpeed);
        }
        else {
            $j('#GeneralSpeed').val(this.NowGeneral.Speed);
        }

        $j('#GeneralPower').val(this.NowGeneral.NewPower);

        $j('#GeneralEnergy').val(this.NowGeneral.NewEnergy);

        if (general.NewAttack != null) {
            $j('#GeneralAttack').val(this.NowGeneral.NewAttack);
        }
        else {
            $j('#GeneralAttack').val(this.NowGeneral.Attack);
        }
        if (general.NewDefense != null) {
            $j('#GeneralDefend').val(this.NowGeneral.NewDefense);
        }
        else {
            $j('#GeneralDefend').val(this.NowGeneral.Defense);
        }
        if (general.NewSalary != null) {
            $j('#GeneralSalary').val(this.NowGeneral.NewSalary);
        }
        else {
            $j('#GeneralSalary').val(this.NowGeneral.Salary);
        }
        if (general.NewSupport != null) {
            $j('#GeneralSupport').val(this.NowGeneral.NewSupport);
        }
        else {
            $j('#GeneralSupport').val(this.NowGeneral.Support);
        }
        if (general.NewCommand != null) {
            $j('#GeneralCommand').val(this.NowGeneral.NewCommand);
        }
        else {
            $j('#GeneralCommand').val(this.NowGeneral.Command);
        }

        $j('#GeneralPotential').val(this.NowGeneral.NewPotential);
        $j('#GeneralAffairs').val(this.NowGeneral.NewAffairs);
        $j('#GeneralForce').val(this.NowGeneral.NewChivalrous);
        $j('#GeneralIntelligence').val(this.NowGeneral.NewResourcefulness);
        $j('#btnDetermine').hide();
        this.GeneralType = parseInt(this.NowGeneral.Type);
        if (parseInt(this.NowGeneral.Type) == 0) {
            $j('#GeneralLeft :text').attr("readonly", "readonly");
            $j('#GeneralName').attr("readonly", "");
            $j('#GeneralLevel').attr("readonly", "");
            $j('#GeneralCommand').attr("readonly", ""); //9.24修改
            $j('#GeneralAffairs').attr("readonly", "");
            $j('#GeneralForce').attr("readonly", "");
            $j('#GeneralSpeed').attr("readonly", ""); //9.24修改
            $j('#GeneralAttack').attr("readonly", ""); //9.24修改
            $j('#GeneralDefend').attr("readonly", ""); //9.24修改
            $j('#GeneralIntelligence').attr("readonly", "");
            $j('#Washpoints').hide();
        }
        else {
            $j('#GeneralLeft :text').attr("readonly", "readonly");
            $j('#Washpoints').show();
            if (this.NowGeneral.NewPotential == 0) {
                $j('#btnaddAffairs').hide();
                $j('#btnaddForce').hide();
                $j('#btnaddIntelligence').hide();
            }
            else {
                $j('#btnaddAffairs').show();
                $j('#btnaddForce').show();
                $j('#btnaddIntelligence').show();
            }
        }
        $j('#btnDeleAffairs').hide();
        $j('#btnDelForce').hide();
        $j('#btnDelIntelligence').hide();
        var Gpage = this;
        for (var j = 0; j <= 15; j++) {
            Gpage.OddEquipment[j] = null;
            $j('#Body_' + j).html(Gpage.GetSubNameByid(j));
        }



        for (var j = 0; j <= Gpage.NowGeneral.Equips.size(); j++) {
            var thisEquip = Gpage.NowGeneral.Equips.get(j);
            if (thisEquip) {
                $j("#Body_" + parseInt(thisEquip.key)).html("<img src=\"" + thisEquip.PictureAddress + "\" width=\"30\" height=\"30\" />");

                Gpage.OddEquipment[parseInt(thisEquip.key)] = thisEquip;

                $j("#Body_" + parseInt(thisEquip.key))
                .mouseover(function(event) {
                    var operateindex = this.id.toString().split("_");
                    if (Gpage.OddEquipment[operateindex[1]]) {//该部位已有装备，则有详细信息
                        $j('#OddDetail').show();
                        page.ShowOddDetail(event, Gpage.OddEquipment[operateindex[1]]);
                    }
                })//A获得焦点
                .mouseout(function(event) { $j('#OddDetail').hide(); })//A失去焦点
            }
        }

    },

    //显示新装备详细信息
    ShowNewDetail: function(e, obj) {
        this.SetPosition(e, "NowDetail");
        var html = "<p class=\"pictext\"><img src=\"" + obj.PictureAddress + "\" width=\"64\" height=\"64\" /><b class=\"S22FF2B\">装备详情</b><br />";
        html += "<b class=\"S01D9F4\">装备名称：</b>" + obj.EquipName + "<br /><b class=\"SF27F20\">强化等级：</b>LV." + obj.EquipStrLevel + "</p>";
        html += "<ul class=\"listProp_1\">";
        html += "<li class=\"rights\"><b class=\"S22FF2B\">品质：</b></li><li class=\"lefts\">" + obj.QuailtyName + "</li>";
        html += "<li class=\"rights\"><b class=\"SF27F20\">属性：</b></li><li class=\"lefts\">";
        var i = 0, j = 0;
        if (obj.EquipCommand != null && obj.EquipCommand != 0) {
            html += "统帅：" + obj.EquipCommand + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipAffairs != null && obj.EquipAffairs != 0) {
            html += "内政：" + obj.EquipAffairs + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipForce != null && obj.EquipForce != 0) {
            html += "勇武：" + obj.EquipForce + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipIntelligence != null && obj.EquipIntelligence != 0) {
            html += "智谋：" + obj.EquipIntelligence + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipPower != null && obj.EquipPower != 0) {
            html += "体力：" + obj.EquipPower + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipEnergy != null && obj.EquipEnergy != 0) {
            html += "精力：" + obj.EquipEnergy + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipLife != null && obj.EquipLife != 0) {
            html += "生命：" + obj.EquipLife + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipAttack != null && obj.EquipAttack != 0) {
            html += "攻击：" + obj.EquipAttack + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipDefend != null && obj.EquipDefend != 0) {
            html += "防御：" + obj.EquipDefend + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipRange != null && obj.EquipRange != 0) {
            html += "射程：" + obj.EquipRange + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipSpeed != null && obj.EquipSpeed != 0) {
            html += "速度：" + obj.EquipSpeed + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipWeight != null && obj.EquipWeight != 0) {
            html += "负重：" + obj.EquipWeight + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (j == 0) {
            html += "资料暂缺";
        }
        html += "</li>";
        html += "<li class=\"rights\"><b class=\"S01D9F4\">装备等级：</b></li><li class=\"lefts\">" + obj.EquipLevel + "</li>";
        html += "<li class=\"rights\"><b class=\"S01D9F4\">装备来源：</b></li><li class=\"lefts\">" + obj.SourceName + "</li>";
        html += "<li class=\"rights\"><b class=\"S01D9F4\">套装：</b></li><li class=\"lefts\">" + obj.SuitName + "</li>";
        if (obj.SuitIndex != null) {
            var data = RXSG.GameData.Simulator.GetSuiteAttr(parseInt(obj.SuitIndex)).value;
            html += data;
        }
        html += "</ul>";
        $('NowDetail').innerHTML = html;
        $('NowDetail').show();
    },

    //显示已有装备详情
    ShowOddDetail: function(e, obj) {
        this.SetPosition(e, "OddDetail");
        var html = "<p class=\"pictext\"><img src=\"" + obj.PictureAddress + "\" width=\"64\" height=\"64\" /><b class=\"S22FF2B\">装备详情</b><br />";
        html += "<b class=\"S01D9F4\">装备名称：</b>" + obj.EquipName + "<br /><b class=\"SF27F20\">强化等级：</b>LV." + obj.EquipStrLevel + "</p>";
        html += "<ul class=\"listProp_1\">";
        html += "<li class=\"rights\"><b class=\"S22FF2B\">品质：</b></li><li class=\"lefts\">" + obj.QuailtyName + "</li>";
        html += "<li class=\"rights\"><b class=\"SF27F20\">属性：</b></li><li class=\"lefts\">";
        var i = 0, j = 0;
        if (obj.EquipCommand != null && obj.EquipCommand != 0) {
            html += "统帅：" + obj.EquipCommand + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipAffairs != null && obj.EquipAffairs != 0) {
            html += "内政：" + obj.EquipAffairs + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipForce != null && obj.EquipForce != 0) {
            html += "勇武：" + obj.EquipForce + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipIntelligence != null && obj.EquipIntelligence != 0) {
            html += "智谋：" + obj.EquipIntelligence + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipPower != null && obj.EquipPower != 0) {
            html += "体力：" + obj.EquipPower + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipEnergy != null && obj.EquipEnergy != 0) {
            html += "精力：" + obj.EquipEnergy + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipLife != null && obj.EquipLife != 0) {
            html += "生命：" + obj.EquipLife + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipAttack != null && obj.EquipAttack != 0) {
            html += "攻击：" + obj.EquipAttack + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipDefend != null && obj.EquipDefend != 0) {
            html += "防御：" + obj.EquipDefend + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipRange != null && obj.EquipRange != 0) {
            html += "射程：" + obj.EquipRange + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipSpeed != null && obj.EquipSpeed != 0) {
            html += "速度：" + obj.EquipSpeed + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (obj.EquipWeight != null && obj.EquipWeight != 0) {
            html += "负重：" + obj.EquipWeight + "；";
            ++i; ++j;
            if (i == 2) { html += "<br />"; i = 0; }
        }
        if (j == 0) {
            html += "资料暂缺";
        }
        html += "</li>";
        html += "<li class=\"rights\"><b class=\"S01D9F4\">装备等级：</b></li><li class=\"lefts\">" + obj.EquipLevel + "</li>";
        html += "<li class=\"rights\"><b class=\"S01D9F4\">装备来源：</b></li><li class=\"lefts\">" + obj.SourceName + "</li>";
        html += "<li class=\"rights\"><b class=\"S01D9F4\">套装：</b></li><li class=\"lefts\">" + obj.SuitName + "</li>";
        if (obj.SuitIndex != null) {
            var data = RXSG.GameData.Simulator.GetSuiteAttr(parseInt(obj.SuitIndex)).value;
            html += data;
        }
        html += "</ul>";
        $('OddDetail').innerHTML = html;
        $('OddDetail').show();
    },

    //获得小类序号
    GetSubIndexByid: function(value) {
        switch (value) {
            case 0: this.index = 1; break; //头部
            case 1: this.index = 3; break; //肩部
            case 2: this.index = 2; break; //颈部
            case 3: this.index = 46; break; //胸部
            case 4: this.index = 45; break; //背部
            case 5: this.index = 4; break; //腰部
            case 6: this.index = 7; break; //手指
            case 7: this.index = 7; break; //手指
            case 8: this.index = 5; break; //手臂
            case 9: this.index = 6; break; //脚部
            case 10: this.index = 8; break; //饰品
            case 11: this.index = 8; break; //饰品
            case 12: this.index = 10; break; //坐骑
            case 13: this.index = 9; break; //武器
            case 14: this.index = 9; break; //武器
            case 15: this.index = 9; break; //武器
            default: this.index = null; break;
        }
        return this.index;
    },
    //获得部位名称
    GetSubNameByid: function(value) {
        switch (value) {
            case 0: return "头部"; break;
            case 1: return "肩部"; break; //肩部
            case 2: return "颈部"; break; //颈部
            case 3: return "胸部"; break; //胸部
            case 4: return "背部"; break; //背部
            case 5: return "腰部"; break; //腰部
            case 6: return "手指"; break; //手指
            case 7: return "手指"; break; //手指
            case 8: return "手臂"; ; break; //手臂
            case 9: return "脚部"; break; //脚部
            case 10: return "饰品"; break; //饰品
            case 11: return "饰品"; break; //饰品
            case 12: return "坐骑"; break; //坐骑
            case 13: return "武器"; break; //武器
            case 14: return "武器"; break; //武器
            case 15: return "武器"; break; //武器
            default: return ""; break;
        }
    },
    //根据装备KEY获得位置名称
    GetNameByKey: function() {
        var name = null;
        switch (this.index) {
            case 1: name = "头部"; break;
            case 2: name = "颈部"; break;
            case 3: name = "肩部"; break;
            case 4: name = "腰部"; break;
            case 5: name = "手臂"; break;
            case 6: name = "脚部"; break;
            case 7: name = "手指"; break;
            case 8: name = "饰品"; break;
            case 9: name = "武器"; break;
            case 10: name = "坐骑"; break;
            case 46: name = "胸部"; break;
            case 45: name = "背部"; break;
            default: name = null; break;
        }
        return name;
    },
    //操作层定位
    SetPosition: function(e, obj) {
        var ev = window.event || e;
        var mousePos = mousePosition(ev);
        var a = window.document.getElementById(obj);
        $j("#" + obj).show();
        var height = $j('#' + obj).height();
        var winheight = document.documentElement.clientHeight;
        var scorllheight = document.body.scrollHeight;

        var al = parseInt(mousePos.x + 15); //指定层显示时其左上角的横向坐标（事件触发时的坐标偏移10）
        var atop = parseInt(mousePos.y + 15); //指定层显示时其左上角的纵向坐标（事件触发时的坐标偏移10）

        while (atop + height + 20 >= scorllheight) {
            atop = atop - 15;
        }
        a.style.left = al + "px"; //指定层显示时其左上角的横向坐标（事件触发时的坐标偏移10）
        a.style.top = atop + "px"; //指定层显示时其左上角的纵向坐标（事件触发时的坐标偏移10）

    },

    //加内政1点
    AddAffairs: function() {
        var Affair = parseInt($j('#GeneralAffairs').val());
        if (Affair >= 99999) {
            $j('#GeneralAffairs').val("99999");
            alert("内政不能大于99999");
            return;
        }
        var Potential = parseInt($j('#GeneralPotential').val());
        if (this.NowGeneral.Type == 1) {

            if (Potential <= 0) {
                alert("无潜力点可加！");
                return;
            }
            $j('#GeneralAffairs').val(Affair + 1);
            $j('#GeneralPotential').val(Potential - 1);
            this.w++;
            $('btnDeleAffairs').show();
        }
        else {
            $j('#GeneralAffairs').val(Affair + 1);
        }
        $j('#btnDetermine').show();
    },
    //减内政1点
    DeleteAffairs: function() {
        if (this.NowGeneral.Type == 1) {
            if (this.w > 0) {
                var Affair = parseInt($j('#GeneralAffairs').val());
                var Potential = parseInt($j('#GeneralPotential').val());
                $j('#GeneralAffairs').val(Affair - 1);
                $j('#GeneralPotential').val(Potential + 1);
                this.w--;
            }
            if (this.w <= 0) {
                $('btnDeleAffairs').hide(); //隐藏减按钮
            }
        }
    },
    //加勇武1点
    AddForce: function() {
        var Force = parseInt($j('#GeneralForce').val());
        if (Force >= 99999) {
            $j('#GeneralForce').val("99999");
            alert("勇武不能大于99999");
            return;
        }
        var Potential = parseInt($j('#GeneralPotential').val());
        if (this.NowGeneral.Type == 1) {
            if (Potential <= 0) {
                alert("无潜力点可加！");
                return;
            }
            $j('#GeneralForce').val(Force + 1);
            $j('#GeneralPotential').val(Potential - 1);
            this.j++;
            $('btnDelForce').show();

        }
        else {
            $j('#GeneralForce').val(Force + 1);
        }
        $j('#btnDetermine').show();
    },
    //减勇武1点
    DeleteForce: function() {
        if (this.NowGeneral.Type == 1) {
            if (this.j > 0) {
                var Force = parseInt($j('#GeneralForce').val());
                var Potential = parseInt($j('#GeneralPotential').val());
                $j('#GeneralForce').val(Force - 1);
                $j('#GeneralPotential').val(Potential + 1);
                this.j--;
            }
            if (this.j <= 0) {
                $('btnDelForce').hide(); //隐藏减按钮
            }
        }
    },
    //加智谋1点
    AddIntelligence: function() {
        var Intelligence = parseInt($j('#GeneralIntelligence').val());
        if (Intelligence >= 99999) {
            $j('#GeneralIntelligence').val("99999");
            alert("智谋不能大于99999");
            return;
        }
        var Potential = parseInt($j('#GeneralPotential').val());
        if (this.NowGeneral.Type == 1) {

            if (Potential <= 0) {
                alert("无潜力点可加！");
                return;
            }
            $j('#GeneralIntelligence').val(Intelligence + 1);
            $j('#GeneralPotential').val(Potential - 1);
            this.k++;
            $('btnDelIntelligence').show();
        }
        else {
            $j('#GeneralIntelligence').val(Intelligence + 1);
        }
        $j('#btnDetermine').show();
    },
    //减智谋1点
    DeleteIntelligence: function() {
        if (this.NowGeneral.Type == 1) {
            if (this.k > 0) {
                var Intelligence = parseInt($j('#GeneralIntelligence').val());
                var Potential = parseInt($j('#GeneralPotential').val());
                $j('#GeneralIntelligence').val(Intelligence - 1);
                $j('#GeneralPotential').val(Potential + 1);
                this.k--;
            }
            if (this.k <= 0) {
                $('btnDelIntelligence').hide(); //隐藏减按钮
            }
        }
    }
})



//显示装备搜索结果
function FomatEquipment(xmlhttprequest) {
    $j('#Equiplist').empty();
    var result = xmlhttprequest.responseText;
    if (result == "Err") {
        alert("查询出错！");
    }
    else {
        var json = eval("(" + result.replace(/\s/g, '') + ")").Equips.EquipsBySub;
        var i = 0;
        var row = json[i];
        while (row != null) {
            var html = "<tr><td><img src=" + row.sgdc_PictureAdress + " onmouseover=\"page.mouseMove(event," + i + ")\" onmouseout=\"page.mouseOut()\"  width=\"32\" height=\"32\" onclick=\"page.SelectEquipment(" + i + ");\" />";
            html += "" + row.sgdc_EquipName + "</td><td align=\"center\">" + row.sgdc_EquipLevel + "</td><td align=\"center\">" + row.sgdc_EquipQualityName + "</td>";
            var Levelhtml = InitLevelLabel(i, row.sgdc_EquipQualityName);
            html += "<td align=\"center\">" + Levelhtml + "</td></tr>";
            $j('#Equiplist').append(html);
            page.EquipmentArray[i] = new Equip(row, page.OddEquip_index, 0);
            page.FirstEquipmentArray[i] = new Equip(row, page.OddEquip_index, 0);
            //page.FirstEquipmentArray[i] = row;
            page.EquipmentDetialSort[i] = SortEquipmentDetial(i);
            i++;
            row = json[i];
        }

        if (i == 0) { var html = "<tr><td class=\"Gameli\" colspan=\"3\">无装备信息！</td></tr>"; $j('#Equiplist').append(html); }
        $j('#table_Equipment').show();
        $j('#eqDivList').show();
        $j('#txtEquip').focus();
        window.scroll(0, document.body.scrollHeight);
        $j('#SearchTitle').html("" + page.GetSubNameByid(parseInt(page.OddEquip_index)) + "装备搜索：");
        var FSumCount = parseInt(eval("(" + result.replace(/\s/g, '') + ")").EquipsBySubTag);
        var FCurrentPageLine = i;
        var FPageCount = Math.ceil(FSumCount / page.pageLine1);
        var pagingation = new Pagination("Pagination1", FPageCount, page.CurrentPage1, FSumCount, FCurrentPageLine, "page.PageChange1", page.divPaginationID1, 1)
    }
}

//对每个装备对象中的属性排序
function SortEquipmentDetial(index) {
    var newArray = [].concat(page.FirstEquipmentArray);
    //var obj = new Equip(newArray[index], page.OddEquip_index, 0);
    var obj = page.FirstEquipmentArray[index];
    var SortArray = new Array();
    var ValueArray = new Array();

    var i = 0;
    if (obj.EquipAttack != null && obj.EquipAttack != 0) {//攻击
        SortArray[i] = "EquipAttack";
        ValueArray[i] = parseInt(obj.EquipAttack);
        i++;
    }
    if (obj.EquipDefend != null && obj.EquipDefend != 0) {//防御
        SortArray[i] = "EquipDefend";
        ValueArray[i] = parseInt(obj.EquipDefend);
        i++;
    }
    if (obj.EquipPower != null && obj.EquipPower != 0) {//体力
        SortArray[i] = "EquipPower";
        ValueArray[i] = parseInt(obj.EquipPower);
        i++;
    }
    if (obj.EquipEnergy != null && obj.EquipEnergy != 0) {//精力
        SortArray[i] = "EquipEnergy";
        ValueArray[i] = parseInt(obj.EquipEnergy);
        i++;
    }
    if (obj.EquipAffairs != null && obj.EquipAffairs != 0) {//内政
        SortArray[i] = "EquipAffairs";
        ValueArray[i] = parseInt(obj.EquipAffairs);
        i++;
    }
    if (obj.EquipCommand != null && obj.EquipCommand != 0) {//统帅
        SortArray[i] = "EquipCommand";
        ValueArray[i] = parseInt(obj.EquipCommand);
        i++;
    }

    if (obj.EquipForce != null && obj.EquipForce != 0) {//勇武
        SortArray[i] = "EquipForce";
        ValueArray[i] = parseInt(obj.EquipForce);
        i++;
    }
    if (obj.EquipIntelligence != null && obj.EquipIntelligence != 0) {//智谋
        SortArray[i] = "EquipIntelligence";
        ValueArray[i] = parseInt(obj.EquipIntelligence);
        i++;
    }
    if (obj.EquipSpeed != null && obj.EquipSpeed != 0) {//速度
        SortArray[i] = "EquipSpeed";
        ValueArray[i] = parseInt(obj.EquipSpeed);
        i++;
    }
    if (obj.EquipLife != null && obj.EquipLife != 0) {//生命
        SortArray[i] = "EquipLife";
        ValueArray[i] = parseInt(obj.EquipLife);
        i++;
    }

    if (obj.EquipRange != null && obj.EquipRange != 0) {//射程
        SortArray[i] = "EquipRange";
        ValueArray[i] = parseInt(obj.EquipRange);
        i++;
    }
    if (obj.EquipWeight != null && obj.EquipWeight != 0) {//负重
        SortArray[i] = "EquipWeight";
        ValueArray[i] = parseInt(obj.EquipWeight);
        i++;
    }
    for (var j = 1; j < ValueArray.length; j++) {
        for (var w = 0; w < (ValueArray.length - j); w++) {
            if (ValueArray[w] < ValueArray[w + 1]) {
                var temp = ValueArray[w];
                ValueArray[w] = ValueArray[w + 1];
                ValueArray[w + 1] = temp;

                var temp = SortArray[w];
                SortArray[w] = SortArray[w + 1];
                SortArray[w + 1] = temp;
            }
        }
    }
    return SortArray;
}

//初始化装备强化等级A标签
function InitLevelLabel(index, QuailtyName) {
    var level = 1;
    if (QuailtyName == "灰色装备") {
        level = 3;
    }
    else if (QuailtyName == "白色装备") {
        level = 6;
    }
    else if (QuailtyName == "绿色装备") {
        level = 9;
    }
    else if (QuailtyName == "蓝色装备") {
        level = 10;
    }
    else {
        level = 3;
    }
    var html = "";
    for (var i = 1; i <= level; i++) {
        html += "<a href=\"javascript:void(0);\" onclick=\"EQAddLevel(" + index + "," + i + ")\">LV." + i + "</a>&nbsp&nbsp";
    }
    return html;
}

function clone(myObj) {
    if (typeof (myObj) != 'object') return myObj;
    if (myObj == null) return myObj;

    var myNewObj = new Object();

    for (var i in myObj)
        myNewObj[i] = clone(myObj[i]);

    return myNewObj;
}

//装备强化操作 i：装备序号，value:强化等级
function EQAddLevel(index, value) {
    //var newArray = [].concat(page.FirstEquipmentArray);
    //var equipment = new Equip(newArray[index], page.OddEquip_index, value);
    var equipment = clone(page.FirstEquipmentArray[index]);
    var AddValue = AddCount(value); //加成点数

    var ArrayLength = page.EquipmentDetialSort[index].length;
    if (AddValue <= 12) {
        if (ArrayLength >= 2) {
            for (var i = 0; i < 2; i++) {
                AddPoint(equipment, page.EquipmentDetialSort[index][i], AddValue / 2);
            }
        } else if (ArrayLength == 1) {
            AddPoint(equipment, page.EquipmentDetialSort[index][0], AddValue);
        }
    }
    else if (AddValue >= 15 && AddValue <= 21) {
        if (ArrayLength >= 3) {
            for (var n = 0; n < 2; n++) {
                AddPoint(equipment, page.EquipmentDetialSort[index][n], 6);
            }
            for (var n = 0; n < 3; n++) {
                AddPoint(equipment, page.EquipmentDetialSort[index][n], (AddValue - 12) / 3);
            }
        } else if (ArrayLength == 2) {
            AddPoint(equipment, page.EquipmentDetialSort[index][0], AddValue / 2 + 1);
            AddPoint(equipment, page.EquipmentDetialSort[index][1], AddValue / 2);
        }
        else if (ArrayLength == 1) {
            AddPoint(equipment, page.EquipmentDetialSort[index][0], AddValue);
        }

    }
    else if (AddValue >= 27) {
        if (ArrayLength == 1) {
            AddPoint(equipment, page.EquipmentDetialSort[index][0], AddValue);
        }
        else if (ArrayLength == 2) {
            AddPoint(equipment, page.EquipmentDetialSort[index][0], AddValue / 2 + 1);
            AddPoint(equipment, page.EquipmentDetialSort[index][1], AddValue / 2);
        } else if (ArrayLength >= 3) {
            AddPoint(equipment, page.EquipmentDetialSort[index][0], 6);
            AddPoint(equipment, page.EquipmentDetialSort[index][1], 6);
            for (var n = 0; n < 3; n++) {
                AddPoint(equipment, page.EquipmentDetialSort[index][n], (21 - 12) / 3);
            }
            var leavePoint = AddValue - 21;
            if (ArrayLength >= 6) {
                for (var n = 0; n < 6; n++) {
                    AddPoint(equipment, page.EquipmentDetialSort[index][n], 1);
                }
            } else {
            var everyOne = Math.floor(leavePoint / ArrayLength);
                for (var n = 0; n < ArrayLength; n++) {
                    AddPoint(equipment, page.EquipmentDetialSort[index][n], everyOne);
                }
                if (leavePoint % ArrayLength != 0) {
                    for (var n = 0; n < leavePoint % ArrayLength; n++) {
                        AddPoint(equipment, page.EquipmentDetialSort[index][n], 1);
                    }

                }
            }



        }


    }


    //    if (AddValue >= ArrayLength) {
    //        var AllAddValue = parseInt(AddValue / ArrayLength);
    //        for (var i = 0; i < ArrayLength; i++) {
    //            AddPoint(equipment, page.EquipmentDetialSort[index][i], AllAddValue);
    //        }
    //        var OtherAddValue = AddValue % ArrayLength;
    //        for (var i = 0; i < OtherAddValue; i++) {
    //            AddPoint(equipment, page.EquipmentDetialSort[index][i], 1);
    //        }
    //    }
    //    else {
    //        for (var i = 0; i < AddValue; i++) {
    //            AddPoint(equipment, page.EquipmentDetialSort[index][i], 1);
    //        }
    //    }
    equipment.EquipStrLevel = value;
    page.EquipmentArray[index] = equipment;
}

//加点操作
function AddPoint(obj, type, value) {
    switch (type) {
        case "EquipAttack": obj.EquipAttack += value; break;
        case "EquipDefend": obj.EquipDefend += value; break;
        case "EquipPower": obj.EquipPower += value; break;
        case "EquipEnergy": obj.EquipEnergy += value; break;
        case "EquipAffairs": obj.EquipAffairs += value; break;
        case "EquipCommand": obj.EquipCommand += value; break;
        case "EquipForce": obj.EquipForce += value; break;
        case "EquipIntelligence": obj.EquipIntelligence += value; break;
        case "EquipSpeed": obj.EquipSpeed += value; break;
        case "EquipLife": obj.EquipLife += value; break;
        case "EquipRange": obj.EquipRange += value; break;
        case "EquipWeight": obj.EquipWeight += value; break;
        default: break;
    }
}

//需要加的点数
function AddCount(value) {
    var AddValue = 0;
    switch (parseInt(value)) {
        case 1: AddValue = 2; break;
        case 2: AddValue = 4; break;
        case 3: AddValue = 6; break;
        case 4: AddValue = 8; break;
        case 5: AddValue = 10; break;
        case 6: AddValue = 12; break;
        case 7: AddValue = 15; break;
        case 8: AddValue = 18; break;
        case 9: AddValue = 21; break;
        case 10: AddValue = 27; break;
        default: AddValue = 0; break;
    }
    return AddValue;
}

//显示名将搜索结果
function FomatGeneral(xmlhttprequest) {
    $j('#GeneralList').empty();
    var result = xmlhttprequest.responseText;
    if (result == "Err") {
        alert("查询出错！");
    }
    else {
        var json = eval("(" + result.replace(/\s/g, '') + ")").Generals.StarGenerals;
        var i = 0;
        var row = json[i];
        while (row != null) {
            var html = "<ul><li class=\"listmj3\"><p><img src=\"" + row.sgdc_PictureAdress + "\" width=\"48\" height=\"48\" onclick=\"page.SelectGeneral(" + row.sgdc_FamousGeneralIndex + ");\" /></p>" + row.sgdc_FamousGeneralName + "</li>";
            html += "<li class=\"listmj5\">" + row.sgdc_GameDataSubTypeName + "(" + row.sgdc_FamousGeneralLevel + ")" + "</li>";
            html += "<li class=\"listmj4\">" + row.sgdc_FamousGeneralDescription + "</li></ul>";
            $j('#GeneralList').append(html);
            i++;
            row = json[i];
        }
        if (i == 0) { var html = "<ul><li class=\"listmj3\">无名将信息！</li></ul>"; $j('#GeneralList').append(html); }
        showDialog("geDivList");
        var FSumCount = parseInt(eval("(" + result.replace(/\s/g, '') + ")").StarGeneralsTag);
        var FCurrentPageLine = i;
        var FPageCount = Math.ceil(FSumCount / page.pageLine2);
        var pagingation = new Pagination("Pagination2", FPageCount, page.CurrentPage2, FSumCount, FCurrentPageLine, "page.PageChange2", page.divPaginationID2, 1)
    }
}

//初始化名将参数
function FomatGeneralDetail(xmlhttprequest) {
    var result = xmlhttprequest.responseText;
    if (result == "Err") {
        alert("初始化失败！");
    }
    else {
        var json = eval("(" + result + ")").StarGeneral[0];
        page.GeneralType = 1;
        page.NowGeneral = new Generals(json, page.GeneralType);
        page.ShowDetail(page.NowGeneral);
        //$j('#table_FamousGeneral').hide();
        $j('#geDivList').hide();
    }
}
//鼠标当前位置
function mousePosition(ev) {
    if (ev.pageX || ev.pageY) {
        return { x: ev.pageX, y: ev.pageY };
    }
    return {
        x: ev.clientX + document.documentElement.scrollLeft - document.documentElement.clientLeft,
        y: ev.clientY + document.documentElement.scrollTop - document.documentElement.clientTop
    };
}


//构造一个函数
function MergFunctionName() {
    var result = arguments[0] + "(", a = arguments;
    if (a.length > 1) {
        for (i = 1; i < a.length; i++) {
            result += "\'" + arguments[i] + "\'";
            if (i != (a.length - 1))
                result += ",";
        }
    }
    result += ")";
    return result;
}

//AJAX调用页面GeneralAjax.aspx action:参数 completefun:完成调用函数
function AjaxMethod(action, completefun) {
    var options = {
        method: 'get',
        asynchronous: true,
        parameters: action,
        onComplete: completefun,
        onFailure: function() {
            $j('#CoverDiv').removeClass();
            $j('#TipsDiv').hide();
            $j('#btnNextRound').bind('click', function() { Spage.NextRound(); });
            alert("请求超时，请重试！");
        }
    };
    new Ajax.Request('GeneralAjax.aspx', options);
}

//var handle = {
//    onCreate: function() {
//        ShowTripDiv('TipsDiv', "处理中，请稍候！");
//        $j('#CoverDiv').removeClass();
//        $j('#CoverDiv').addClass('tisxxdiv'); // 当创建Ajax请求时
//    },
//    onComplete: function() {
//        // 当请求成功返回时，如果当前没有其他正在运行中的Ajax请求，隐藏loading
//        if (Ajax.activeRequestCount == 0) {
//            $j('#CoverDiv').removeClass();
//            $j('#TipsDiv').hide();
//        }
//    }
//};

//// 将handle注册到全局的Ajax.Responders对象中，使其生效
//Ajax.Responders.register(handle);

//显示名将详细信息
function ShowGeneralDetail(e, obj) {
    page.SetPosition(e, "GeneralDetail");
    var html = "<p class=\"pictext\"><img src=\"" + obj.PicAdd + "\" width=\"64\" height=\"64\" /><b class=\"S22FF2B\">武将</b><br />";
    html += "<b class=\"S01D9F4\">名将名称：</b>" + obj.Name + "<br />";
    html += "<b class=\"S01D9F4\">名将等级：</b>" + obj.NewLevel + "</p>";
    html += "<ul class=\"listProp\">";
    html += "<li ><b class=\"S22FF2B\">体力：</b>" + (obj.NewPower != null ? obj.NewPower : obj.Power) + "</li>";
    html += "<li ><b class=\"S41A4FF\">精力：</b>" + (obj.NewEnergy != null ? obj.NewEnergy : obj.Energy) + "</li>";
    html += "<li ><b class=\"SF27F20\">统帅：</b>" + (obj.NewCommand != null ? obj.NewCommand : obj.Command) + "</li>";
    html += "<li ><b class=\"S22FF2B\">速度：</b>" + (obj.NewSpeed != null ? obj.NewSpeed : obj.Speed) + "</li>";
    html += "<li ><b class=\"SFF3939\">攻击：</b>" + (obj.NewAttack != null ? obj.NewAttack : obj.Attack) + "</li>";
    html += "<li ><b class=\"SF4CC1C\">防御：</b>" + (obj.NewDefense != null ? obj.NewDefense : obj.Defense) + "</li>";

    html += "<li ><b class=\"S22FF2B\">内政：</b>" + obj.NewAffairs + "</li>";
    html += "<li ><b class=\"S41A4FF\">勇武：</b>" + obj.NewChivalrous + "</li>";
    html += "<li ><b class=\"SF27F20\">智谋：</b>" + obj.NewResourcefulness + "</li>";

    html += "</ul>";
    $('GeneralDetail').innerHTML = html;
    $('GeneralDetail').show();
}

//显示提示层
function ShowTripDiv(did, str) {
    var el = $(did);
    var innerxy = getInnerXY();
    var offxy = getScrollXY();
    el.style.top = parseInt(((innerxy[1] - el.clientHeight) / 2 + offxy[1])) < 0 ? 0 : parseInt(((innerxy[1] - el.clientHeight) / 2 + offxy[1])) + "px";
    $j('#TipsDiv').html(str);
    $j('#TipsDiv').show();
}

//居中显示
function showDialog(did) {
    var el = $(did);

    $j('#' + did).fadeIn("fast");
    var innerxy = getInnerXY();
    var offxy = getScrollXY();
    el.style.top = parseInt(((innerxy[1] - el.clientHeight) / 2 + offxy[1])) < 0 ? 0 : parseInt(((innerxy[1] - el.clientHeight) / 2 + offxy[1])) + "px";
    el.style.left = ((innerxy[0] - el.clientWidth) / 2 + offxy[0]) + "px";

}

//窗口长宽的代码
function getInnerXY() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth, myHeight];
}

//scroller偏移的代码
function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}

//拖动
var tHeight, lWidth, obj;
function Down(e, a) {
    var event = window.event || e;
    obj = $(a);
    tHeight = event.clientY - parseInt(obj.style.top.replace(/px/, ""));
    lWidth = event.clientX - parseInt(obj.style.left.replace(/px/, ""));
    document.onmousemove = Move;
    document.onmouseup = Up;
}
function Move(e) {
    var event = window.event || e;
    var top = event.clientY - tHeight;
    var left = event.clientX - lWidth;
    //判断 top 和 left 是否超出边界
    top = top < 0 ? 0 : top;
    top = top > document.body.offsetHeight - 150 ? document.body.offsetHeight - 150 : top;
    left = left < 0 ? 0 : left;
    left = left > document.body.offsetWidth - 300 ? document.body.offsetWidth - 300 : left;
    obj.style.top = top + "px";
    obj.style.left = left + "px";
}
function Up() {
    document.onmousemove = null;
}

jQuery.fn.toggleVal = function(focusClass) {
    this.each(function() {
        $j(this).focus(function() {
            if ($j(this).val() == this.defaultValue) { $j(this).val(""); }
            if (focusClass) { $j(this).addClass(focusClass); }
        }).blur(function() {
            if ($j(this).val() == "") { $j(this).val("请输入战报标题！"); }
            if (focusClass) { $j(this).removeClass(focusClass); }
        });
    });
}

jQuery.fn.onlypressnum = function() {
    $(this).css({ imeMode: "disabled", '-moz-user-select': "none" });
    $(this).bind("keypress", function(e) {
        if (parseInt($j(this).val()) == 0) {
            $j(this).val("");
        }
        if (e.ctrlKey == true || e.shiftKey == true)
            return false;
        if ((e.which >= 48 && e.which <= 57 && e.ctrlKey == false && e.shiftKey == false) || e.which == 0 || e.which == 8)
            return true;
        else if (e.ctrlKey == true && (e.which == 99 || e.which == 118))
            return false;
        else
            return false;

    })
.bind("contextmenu", function() { return false; })
.bind("selectstart", function() { return false; })
.bind("paste", function() { return false; });
};
