var PageSize = 10;
var CurrentPage = 1;
var status = -1;

$(document).ready(function() {
	$('#ddlStatus').change(function(){
	    status = $(this).val();
	    BindList('');
	});
	status = $('#ddlStatus').val()
	BindList('Page=1');
	
});

//绑定数据
function BindList(urldata){
    $('#template').hide();//将第一行模板隐藏
    $.ajax({
        type:"get",
        dataType:"json",
        url:'MyAsk.aspx?NoCopyRight=1&type=ajax&Action=GetList&Status=' + status + '&PageSize='+PageSize,
        data:urldata,
        cache:false,
        success:function(msg){
            $('div.item:gt(0)','#AskContent').remove();
            if(status == 0){
                $('.answ').hide();
                $('.askvote').hide();
            }else{
                $('.answ').show();
                $('.askvote').show();
            };
            var data = msg.ProductAsk;
            $.each(data,function(i,n){
               var row = $('#template').clone().show();
               row.find('.proname').html(row.find('.proname').html() + '<a href="products/product-' + n.ProductID + '.html" target="_blank">' + n.ProductName + '</a>');
               row.find('.name').text('网友：'+n.MemberName);
               row.find('.group').text(n.GroupName);
               row.find('.asktime').text(n.AddTime);
               row.find('.ask').html('<span style=font-weight:bold;>咨询内容：</span>'+n.Body);
               row.find('.answbody').html('<span style=font-weight:bold;>百悦回复：</span>'+n.Reply);
               row.find('.answtime').html(n.ReplyTime);
               var objYesNum = row.find('.yesnum').text(n.YesNum);
               var objNotNum = row.find('.notnum').text(n.NotNum);
               row.find('.vote_y').click(function(){
                    if(Vote(n.ProductAskID,1) == '1'){
                        objYesNum.text(Number(objYesNum.text())+1);
                    };
               });
               row.find('.vote_n').click(function(){
                    if(Vote(n.ProductAskID,0) == '1'){
                        objNotNum.text(Number(objNotNum.text())+1);
                    };
               });
               if((i%2)==1){row.addClass('itemeven');}else{row.addClass('itemodd');};
               
               row.attr('id','item_'+i).appendTo($('#AskContent'));
            });
           
            //分页
            $('.sub_container_page').show();
            var pagerStyle = "flickr";//jPagerBar样式
            ShowPageBar("pageDataList1_Pager",//[containerId]
               "ProductAsk.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){alert(textStatus);}
    });//end ajax
};//end funciton

function Vote(paid,val){
    var result = '0';
    $.ajax({
        type:"get",
        url:'ProductAsk.aspx?NoCopyRight=1&type=Vote&PAID='+paid+'&val='+val,
        async:false,
        success:function(data){
            if(data == 'NOLOGIN'){
                window.location.href = 'Login.aspx?ReturnUrl=' + returnUrl;
                return false;
            };
            result = data;
        },error:function(){alert('error');}
    });
    return result;
};