
var PageSize = 20;//每页计数
var CurrentPage = 1; //当前页
var status = 0;
var replyword = '点击回复';
var showurl = '../products/product-{id}.html';
var keyword = '';
var searchType = 0;

$(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); //设置内容区域的高度
    },100);
    $('input[@name=chkAll]').click(function(){$('input[@name=chkItem]').attr('checked',$(this).attr('checked'));});//全选
	
	status = getQueryStringRegExp('Status');
	if(status == 1){replyword = '已回复'};
	BindList('Page='+CurrentPage);
	
	$('#btnDelete').click(function(){
        var ids = '';
        $('input[name=chkItem][checked]').each(function(){ids += $(this).val() + ',';});
        if(ids != ''){
            if(confirm('确定要删除选中项吗?')){
                ids = ids.substring(0,ids.length-1);
                Delete(ids);
            }
        }else{
            alert('请选择要删除的项');return false;
        };
    }); 
    
    $("#txtStartTime").datepicker().click(function(){$(this).blur()});
    $("#txtEndTime").datepicker().click(function(){$(this).blur()});
    
    //搜索
    $('#btnSearch').click(function(){
        keyword = escape($('#txtKeyword').val());
        searchType = $('#ddlSearchType').val();
        BindList('Page=1');
    });
	
});


//绑定数据
function BindList(urldata){
    $('#template').hide();//将第一行模板隐藏
    $.ajax({
        type:"get",
        dataType:"json",
        url:'ShopEval.aspx?NoCopyRight=1&type=ajax&Action=GetList&PageSize=' + PageSize + '&Status=' + status + '&Keyword=' + keyword + '&SearchType=' + searchType + '&StartTime=' + escape($('#txtStartTime').val()) + '&EndTime=' + escape($('#txtEndTime').val()),
        data:urldata,
        cache:false,
        success:function(msg){
            $('tr:gt(0)','#datas').remove();
            var data = msg.ProductReview;
            $.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.ShopEvalID + '" />');
               row.find('#ID').text(n.ShopEvalID);
               row.find('#Title').html(n.Title);
               row.find('#SupplierName').html(n.SupplierName);
               row.find('#MemberName').text(n.MemberName);
               row.find('#AddTime').text(n.AddTime);
               row.find('#Detail')
                    .html('<span class="hand span_reply" id="click_reply_' + n.ShopEvalID + '">查看详细</span>')
                    .click(function(){
                        $('#frmdetail').attr('src','ShopEvalDetail.aspx?seid='+n.ShopEvalID);
                        $('#popupContact').popup({width:'80%',height:'500',popupHead:'popupHead',btnClose:'popupClose'});
                    });
               row.find('#Delete').html('<span class="hand">删除</span>').click(function(){
                    if(confirm('确定要删除吗?')){
                        Delete(n.ShopEvalID);
                    };
               });
               row.attr('id','item_'+i).appendTo($('#datas'));
            });
           
            //分页
            $('.sub_container_page').show();
            var pagerStyle = "flickr";//jPagerBar样式
            ShowPageBar("pageDataList1_Pager",//[containerId]
               "ShopEval.aspx",//[url]
               {style:pagerStyle,mark:"pageDataList1Mark",
               totalCount:msg.totalCount,showPageNumber:3,pageCount:PageSize,currentPageIndex:CurrentPage,noRecordTip:" 没有记录",preWord:"上一页",nextWord:"下一页",
               onclick:"CurrentPage={pageindex};BindList('Page={pageindex}');return false;"}//[attr]
            );
        },//end success
        error:function(XMLHttpRequest,textStatus){if(textStatus=='parsererror'){alert('身份已过期,请重新登陆!');}else{alert(textStatus)};}
    });//end ajax
};//end funciton

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

//获取URL中参数
function getQueryStringRegExp(name){    
	var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
	if (reg.test(location.href))
		return unescape(RegExp.$2.replace(/\+/g, " "));
		return "";
}

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