var PageSize = 15;
var CurrentPage = 1;
$(document).ready(function(){
    $('#loadingContainer').ajaxStart(function()
    {
	    $(this).show();
	    $('#loadingbackground').show().css({"opacity": "0.5"});
	}).ajaxStop(function()
	{
	    $(this).hide();
	});    
    setInterval(function(){
        $('div.sub_container_page').css('top',$(window.parent.frames.right).height()-$('div.sub_container_page').height()-2); //设置底部分页区域的位置
    },100);

    var search_urldata = 'type=ajax&action=SearchPmtGoods&PageSize='+PageSize+'&Page='+CurrentPage+'&RuleID='+ruleid;
    BindRules('pmtgoods_tg_list.aspx',search_urldata);//绑定数据        
    
    //--添加活动
    $('#btnAdd').click(function(){
        location.href="pmtrule_tg.aspx";
    });
    
    //全选
    $('input[@name=chkAll]').click(function(){
        $('input[@name=chkItem]').attr('checked',$(this).attr('checked'));
    });
    
    
    //批量删除规则
    $('#btnDelete').click(function(){
        var rids = '';
        $('input[@name=chkItem][@checked]').each(function(){
            rids += $(this).val() + ',';
        });
        if(rids != ''){
            rids = rids.substring(0,rids.length-1);
            if(confirm('确定要删除选中的规则吗?删除将不可恢复'))
            {
				$.get('pmtgoods_tg_list.aspx?type=ajax&action=DeletePmtRule&rids=' + rids);
                location.href="pmtgoods_tg_list.aspx";
            }
        }else{
            alert('请选择要删除的规则');
        }
    });
});//end ready()

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.1+"px";
	var c2_width = pageWidth*0.1+"px";
	var c3_width = pageWidth*0.1+"px";
	var c4_width = pageWidth*0.05+"px";
	var c5_width = pageWidth*0.05+"px";
	var c6_width = pageWidth*0.05+"px";
	var c7_width = pageWidth*0.1+"px";
	var c8_width = pageWidth*0.1+"px";
	
	var c9_width = pageWidth*0.1+"px";
	var c10_width = pageWidth*0.1+"px";
	var c11_width = pageWidth*0.1+"px";	
	var c12_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);
	$('.c8').css("width",c8_width);
	$('.c9').css("width",c9_width);
	$('.c10').css("width",c10_width);
	$('.c11').css("width",c11_width);	
	$('.c12').css("width",c12_width);
	}

//绑定数据
function BindRules(weburl,urldata){
    $('#template').hide();//将第一行模板隐藏
    $.ajax({
        type:"get",
        dataType:"json",
        url:weburl+'?NoCopyRight=1',
        data:urldata,
        cache:false,
        success:function(msg)
        {
            $('input[@name=chkAll]').attr('checked','');
            $('tr:gt(0)','#datas').remove();
            var data = msg.PmtGoods;
            $.each(data,function(i,n){
                var row = $('#template').clone();
                row.find('#PName').html('<a href="'+webSite+'tgproduct-'+n.ID+'.html" target="_blank">'+n.ProductName+'</a>');
                row.find('#PNo').text(n.PNo);
//                row.find('#PImg').text(n.ProductImg);
                row.find('#PImg').html('<img height="50px" width="50px" src="'+webSite+'upload/productimg/'+n.ImgFolder+n.ProductImg+'"/>');
                row.find('#PmtPrice').text(n.PmtPrice);
                row.find('#MinValue').text(n.MinValue);
                row.find('#Purchased').text(n.Purchased);
                row.find('#RuleName').text(n.RuleName);
                row.find('#Grade').text(n.Grade);
                row.find('#View').html('<a href="MemberBookTG.aspx?gid=' + n.GoodsID + '">查看</a>');
                row.find('#BeginTime').text(n.BeginTime);    
                row.find('#EndTime').text(n.EndTime);    
                row.find('#Status').text(parseInt(n.Purchased)>parseInt(n.MinValue)? "已达到组团数量":"未达到组团数量");    
				row.attr("id","ready_" + n.ID);//改变绑定好数据的行的id
				row.show().mouseover(function(){$(this).css("cursor","pointer");}); //将复制的行显示出来并添加样式
				row.appendTo("#datas");//添加到模板的容器中
            });
            
//<img height="50px" width="50px" src="<%=webSite%>upload/productimg/<%=dtPmtGoods.Rows[i]["ImgFolder"]%><%=dtPmtGoods.Rows[i]["ProductImg"]%>">
//<a href="<%=webSite %>tgproduct-<%=dtPmtGoods.Rows[i]["ID"]%>.<%=config.html %>" target="_blank"><%=dtPmtGoods.Rows[i]["ProductName"]%></a>

            
            //分页
            $('.sub_container_page').show();
            var pagerStyle = "flickr";//jPagerBar样式
            ShowPageBar("pageDataList1_Pager",//[containerId]
               "Binding.aspx",//[url]
               {style:pagerStyle,mark:"pageDataList1Mark",
               totalCount:msg.totalCount,showPageNumber:3,pageCount:PageSize,currentPageIndex:CurrentPage,noRecordTip:" 没有记录",preWord:"上一页",nextWord:"下一页",
               onclick:"CurrentPage={pageindex};BindRules('pmtrule_tg_list.aspx','type=ajax&action=SearchPmtGoods&PageSize=" + PageSize + "&Page={pageindex}&BasicType=goods&SubType=tuangou');return false;"}
            );
        },
        error:function(XMLHttpRequest,textStatus){if(textStatus=='parsererror'){alert('身份已过期,请重新登陆!')}else{alert('error')};}
    });
}