
var PageSize = 50;//每页计数
var CurrentPage = 1; //当前页

function setList()
{
	var pageWidth=document.documentElement.clientWidth-9;
	$(".sub_container_content").css("width",pageWidth);
	$(".sub_container_listhead").css("width",pageWidth);
	$(".llist").css("width",pageWidth);
	var c1_width = pageWidth*0.05+"px";
	var c2_width = pageWidth*0.1+"px";
	var c3_width = pageWidth*0.4+"px";
	var c4_width = pageWidth*0.15+"px";
	var c5_width = pageWidth*0.15+"px";
	var c6_width = pageWidth*0.1+"px";
	var c7_width = pageWidth*0.05+"px";

	$('.c1').css("width",c1_width);
	$('.c2').css("width",c2_width);
	$('.c3').css("width",c3_width);
	$('.c4').css("width",c4_width);
	$('.c5').css("width",c5_width);
	$('.c6').css("width",c6_width);
	$('.c7').css("width",c7_width);

}
$(document).ready(function() {
	$('#loadingContainer').ajaxStart(function(){$(this).show();}).ajaxStop(function(){$(this).hide();});
	setInterval(function(){
        $('div.sub_container_page').css('top',$(window.parent.frames.right).height()-$('div.sub_container_page').height()-2); //设置底部分页区域的位置
        $('div.sub_container_content').css('height',$(window.parent.frames.right).height()-$('div.sub_container_title').height()-$('div.sub_container_operation').height()-$('div.sub_container_listhead').height()-$('div.sub_container_page').height()-10); //设置内容区域的高度
        if($.browser.mozilla){setList();}
    },1000);
    
    $("#txtStartTime").datepicker().click(function(){$(this).blur();});
	$("#txtEndTime").datepicker().click(function(){$(this).blur();});
    $('[@name=chkAll]').click(function(){
        $('[@name=chkItem]').attr('checked',$(this).attr('checked'));
    });
    $('#btnDelete').click(function(){
        var IDs = '';
        $('input[@name=chkItem][@checked]').each(function(){
            IDs += $(this).val() + ',';
        });
        if(IDs != ''){
            if(!confirm('确定要删除选择的记录吗?')){return false;};
            IDs = IDs.substring(0,IDs.length-1);
            $.ajax({
                type:"get",
                url:'EventLog.aspx?NoCopyRight=1&type=ajax&Action=Delete&IDs=' + IDs,
                success:function(data){
                    if(!checkLoginStatus(data)){return false;};
                    if(data > 0){
                        BindList();
                    };
                },
                error:function(){alert('error');}
            });
        }else{
            alert('请选择要删除的记录');
        };
    });
    
    $('#btnSearch').click(function(){
        CurrentPage = 1;
        BindList();
    });
 
	BindList();		
});

//绑定数据
function BindList(){
    $('#template').hide();//将第一行模板隐藏
    $.ajax({
        type:"get",
        dataType:"json",
        url:'EventLog.aspx?NoCopyRight=1&type=ajax&Action=GetList&PageSize=' + PageSize + '&Page=' + CurrentPage + '&CatID='+$('#ddlCat').val() + '&MemberName=' + escape($('#txtMemberName').val()) + '&StartTime=' + escape($('#txtStartTime').val()) + '&EndTime=' + escape($('#txtEndTime').val()),
        cache:false,
        success:function(msg){
            $('tr:gt(0)','#datas').remove();
            $('input[@name=chkAll]').attr('checked',false);
            var data = msg.EventLog;
            $.each(data,function(i,n){
               var row = $('#template').clone();
               row.show().mouseover(function(){$(this).addClass('on')}).mouseout(function(){$(this).removeClass('on')});
               row.find('#checkbox').html('<input type="checkbox" name="chkItem" value="'+n.EventLogID+'" />');
               row.find('#ID').text(n.EventLogID);
               row.find('#CategoryName').html(GetEventType(n.SubCatID));
               row.find('#Description').html(n.Description);
               row.find('#AddTime').html(n.AddTime);
               row.find('#IP').html(n.IP);
               row.find('#MemberName').text(n.MemberName);

               row.attr('id','item_'+i).appendTo($('#datas'));
            });
           
            //分页
            $('.sub_container_page').show();
            var pagerStyle = "flickr";//jPagerBar样式
            ShowPageBar("pageDataList1_Pager",//[containerId]
               "EventLog.aspx",//[url]
               {style:pagerStyle,mark:"pageDataList1Mark",
               totalCount:msg.totalCount,showPageNumber:3,pageCount:PageSize,currentPageIndex:CurrentPage,noRecordTip:" 没有记录",preWord:"上一页",nextWord:"下一页",
               onclick:"CurrentPage={pageindex};BindList();return false;"}//[attr]
            );
        },//end success
        error:function(XMLHttpRequest,textStatus){if(textStatus=='parsererror'){alert('身份已过期,请重新登陆!');}else{alert(textStatus)};}
    });//end ajax
};//end funciton

function GetEventType(type){
    result = "&nbsp;";
    switch(type){
        case "1":
            result = "系统管理";
            break;
        case "11":
            result = "登录";
            break;
        case "12":
            result = "退出";
            break;
        case "13":
            result = "系统参数管理";
            break;
        case "2":
            result = "管理员管理";
            break;
        case "21":
            result = "添加用户";
            break;
        case "22":
            result = "添加用户组";
            break;
        case "23":
            result = "设置权限";
            break;
        case "3":
            result = "信息管理";
            break;
        case "31":
            result = "信息分类添加";
            break;
        case "32":
            result = "信息分类修改";
            break;
        case "33":
            result = "信息分类删除";
            break;
        case "34":
            result = "新闻添加";
            break;
        case "35":
            result = "新闻修改";
            break;
        case "36":
            result = "新闻删除";
            break;
        case "37":
            result = "新闻审核";
            break;
        case "38":
            result = "新闻推荐";
            break;
        case "4":
            result = "商品信息管理";
            break;
        case "41":
            result = "商品分类添加";
            break;
        case "42":
            result = "商品分类修改";
            break;
        case "43":
            result = "商品分类删除";
            break;
        case "44":
            result = "商品添加";
            break;
        case "45":
            result = "商品修改";
            break;
        case "46":
            result = "商品删除";
            break;
        case "47":
            result = "批量修改商品价格";
            break;
        case "48":
            result = "商品还原";
            break;
        case "5":
            result = "商品经营管理";
            break;
        case "51":
            result = "商品上架";
            break;
        case "52":
            result = "商品下架";
            break;
        case "53":
            result = "商品价格修改";
            break;
        case "54":
            result = "商品审核";
            break;
        case "55":
            result = "商品入库";
            break;
        case "56":
            result = "商品出库";
            break;
        case "57":
            result = "盘点库存";
            break;
        case "6":
            result = "订单管理";
            break;
        case "61":
            result = "订单状态修改";
            break;
        case "62":
            result = "订单删除";
            break;
        };
    return result;
};

function Delete(id){
    $.ajax({
        url:'Complaint.aspx?type=ajax&Action=Delete&CID=' + id,
        cache:false,
        success:function(data){
            if(!checkLoginStatus(data)){return false;}
            BindList('Page='+CurrentPage);
        },
        error:function(){alert('error');}
    });//end ajax
};

function checkLoginStatus(data){
    var result = true;
    if(data.indexOf('<!DOCTYPE') != -1){
        result = false;
        alert('身份已过期,请重新登陆!');
    };
    return result;
};