var PageSize = 15;
var CurrentPage = 1;
var keyword = '';
var catID = '0';
var brandID = '0';
var searchType = '0';
var status = 0;

//列表查询条件
var search_urldata = 'type=ajax&Action=SearchProductsAjax&keyword=' + keyword + '&CatID=' + catID + '&BrandIDs=' + brandID + '&SearchType=' + searchType + '&PageSize='+PageSize+'&Page='+CurrentPage;

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.04+"px";
	var c2_width = pageWidth*0.18+"px";
	var c3_width = pageWidth*0.05+"px";
	var c4_width = pageWidth*0.10+"px";
	var c5_width = pageWidth*0.10+"px";
	var c6_width = pageWidth*0.30+"px";
	var c7_width = pageWidth*0.06+"px";
	var c8_width = pageWidth*0.06+"px";
	
	var cc1_width = pageWidth*0.05+"px";
	var cc2_width = pageWidth*0.10+"px";
	var cc3_width = pageWidth*0.10+"px";
	var cc4_width = pageWidth*0.30+"px";
	var cc5_width = pageWidth*0.45+"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);
	
	
}

//绑定数据
function BindCoupons(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.Coupons;
            $.each(data,function(i,n){
                var row = $('#template').clone();
                row.find('#checkbox').html('<input type="checkbox" name="chkItem" value="' + n.CouponID + '" />');//checkbox
                row.find('#CouponName').text(n.CouponName);
                row.find('#CouponValue').text(n.CouponValue);
                row.find('#Score').text(n.Score);
                row.find('#MinMoney').text(n.MinMoney);
                row.find('#BETime').text(n.BeginTime.split(' ')[0]+'至'+n.EndTime.split(' ')[0]); 
                row.find('#Status').text(n.Status);
                row.find('#Modify').html('<a href="ExchangeCoupons.aspx?Action=Modify&CouponID=' + n.CouponID + '">修改</a>')
                row.find('#Delete').html('<a href="#">删除</a>')
                   .find('a').click(function()
                   {
                        if(confirm('确定要删除该优惠券的兑换规则吗?'))
                        {
                            $.get('ExchangeCoupons.aspx?type=ajax&Action=DeleteExchangeCoupons&Cids=' + n.CouponID);
							$(this).parent().parent().remove();
                        }
                        return false;
                   });

				row.attr("id","ready_" + n.CouponID);//改变绑定好数据的行的id
				row.show();
				row.appendTo("#datas");//添加到模板的容器中
            });

            //分页
            $('.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};BindActivitys('Coupons.aspx','type=ajax&Action=SearchCouponsAjax&PageSize=" + PageSize + "&Page={pageindex}');return false;"}
            );
        },
        error:function(XMLHttpRequest,textStatus){if(textStatus=='parsererror'){alert('身份已过期,请重新登陆!')}else{alert('error')};}
    });
}


//获取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;
}