﻿var GD = { Version: '1.0.0.0' };
GD.Page = Class.create({
    initialize: function() {
        this.type = 0;
        this.ListDate = null;
        this.FCurrentPage = 1;
        this.FPageLine = 40;
        this.divPaginationID = null;

        this.WebSiteId = null;
        this.NKid = null;
        this.Nid = null;
        this.linkurl = null;
        this.WarID = null;
        this.ID = null;
    },
    GetEleByClientID: function(divPagination, wid, nkid, nid, url, Warid) {
        this.divPaginationID = divPagination;
        this.WebSiteId = wid == "" ? null : wid;
        this.NKid = nkid == "" ? null : nkid;
        this.Nid = nid == "" ? null : nid;
        this.linkurl = url == "" ? "http://10.0.0.4:8053" : url;
        this.WarID = Warid;
    },
    LoadData: function() {
        if (this.WarID != null && this.WarID != "") {
            this.ID = this.WarID;
        }
        else {
            this.ID = this.NKid;
        }
        this.ListDate = RXSG.GameData.NewsList.GetNewsList(this.WebSiteId, this.ID, this.Nid, this.type, this.FCurrentPage, this.FPageLine).value;
        this.Formate();
    },
    Formate: function() {
        if (this.ListDate == null || this.ListDate.IsSuccess == false) {
            $('newslist').innerHTML = "<ul class=\"lists\"><li><h3>系统忙，请稍候重试！</h3></li></ul>";
        }
        else {
            var DataList = this.ListDate.DataList;
            if (DataList == null || DataList.length == 0) {
                $('newslist').innerHTML = "<ul class=\"lists\"><li><h3>没有新闻信息！</h3></li></ul>";
            }
            else {
                var i = 0;
                var j = 0;
                var row = DataList[i];
                var html = "<ul class=\"lists\">";
                while (row != null) {
                    var typename = "";
                    if (row[3] == null || row[3] == "") { typename = row[2]; }
                    else { typename = row[3]; }
                   // var typename = row[3] == "" ? row[2] : row[3];
                    html += "<li><h3>[" + typename + "]<a href=\"" + this.linkurl + row[5] + "\" target=\"_blank\" title=\""+row[6]+"\">" + row[0] + "</a></h3>" + row[4] + "</li>";
                    i++;
                    j++;
                    row = DataList[i];
                    if (j == 5) {
                        html += "</ul><ul class=\"lists\">";
                        j = 0;
                    }
                }
                html += "</ul>";
                $('newslist').innerHTML = html;
            }
            var FSumCount = this.ListDate.Tag[0];
            var FCurrentPageLine = i;
            var FPageCount = Math.ceil(FSumCount / this.FPageLine);
            var pagingation = new Pagination("Pagination1", FPageCount, this.FCurrentPage, FSumCount, FCurrentPageLine, "page.PageChange", this.divPaginationID, 1)
        }
    },
    //分页调整
    PageChange: function(pNum) {
        this.FCurrentPage = parseInt(pNum);
        this.LoadData();
    },
    //更换排序类型
    ChangeType: function() {
        this.type = parseInt($F('SelectOrder'));
        this.FCurrentPage = 1;
        this.LoadData();
    }
})

//var type = 0; //排序类型
//var page = getUrlParam("pagenum") == "" ? 1 : getUrlParam("pagenum");//当前页码
//var rownumber = 5;//一页数据行数
//var Tag = null;//结果总数
//var Count=null;//当前页条数
//var divPaginationID = null;

//function GetElementById(divpagintion) {
//    divPaginationID = divpagintion;
//}

////加载页面
//function init() {
//    var Action = 'NKid=' + getUrlParam("NKid") + "&Nid=" + getUrlParam("Nid") + "&type=" + type + "&pagenum=" + page + "&rownum=" + rownumber;
//    var options = {
//        method: 'get',
//        asynchronous: true,
//        parameters: Action,
//        onComplete: function(transport) {
//            var result = transport.responseText.split("|");
//            alert(result.length);
//            if (result.length < 3) {
//                $('newslist').innerHTML = transport.responseText;
//            }
//            else {
//                $('newslist').innerHTML = result[0];
//                Tag = parseInt(result[1]);
//                Count = parseInt(result[2]);
//                var FSumCount = Tag;
//                var FCurrentPageLine = Count;
//                var FPageCount = Math.ceil(FSumCount / rownumber);
//                var pagingation = new Pagination("Pagination1", FPageCount, page, FSumCount, FCurrentPageLine, "PageChange", divPaginationID, 1)
//            }
//        }
//    };
//    new Ajax.Request('Ajax_NewsList.aspx?no-cache=' + Math.random(), options);
//}
////更换排序类型
//function ChangeType() {
//    type = parseInt($F('SelectOrder'));
//    page = 1;
//    init();
//}
////分页
//function PageChange(pnum) {
//    page = pnum;
//    init();
//}

////当前URL
//function getUrlParam(name) {
//    var _name = name.toLowerCase();
//    if (_name != null) {
//        var reg = new RegExp("(^|&)" + _name + "=([^&]*)(&|$)");
//        var r = window.location.search.substr(1).toLowerCase().match(reg);
//        if (r != null) { return unescape(r[2]); } return "";
//    }
//}

//构造一个函数
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;
}
