BindReview('Page=1');	
PageSize=10;
$('#btnSubmit').click(function(){
	if($.trim($('#txtTitle').val()) == ''){
	    alert('请填写标题');return false;
	};
	if($.trim($('#txtContent').val()) == ''){
	    alert('请填写评论内容');return false;
	};
	if($('[@name=rblScore][@checked]').length == 0){
	    alert('请选择评分等级');return false;
	};
});

$('#btnSave').click(function(){
	if($.trim($('#txtWhere').val()) == ''){
	    alert('请填写看见该价格的地方');return false;
	}else if($.trim($('#txtPrice').val()) == ''){
	    alert('请填写价格');return false;
	}else if($.trim($('#txtData').val()) == ''){
	    alert('请填写您看到该价格的日期');return false;
	}else
	{
	    $.ajax({
	    type:"post",
	    cache:false,
	    url:baseUrl + "Show.aspx?NoCopyRight=1&type=ajax&PID="+productID+"&Action=SavePriceFB",
	    data:$('#txtWhere').serialize() + '&' + $('#txtPrice').serialize() + '&' + $('#txtData').serialize()+'&'+$('#txtRemark').serialize(),
	    success:function(msg){
	        if(msg=="1")
	        {
	            alert("价格填写有误，请重新输入！");
	            return false;
	        }
	        else if(msg=="2")
	        {
	            lert("日期填写有误，请重新输入！");
	            return false;
	        }
	        else if(msg=="ok")
	        {
	            alert("提交成功！");
	            return false;
	        }
	        else
	        {
	            alert("提交失败！");
	            return false;
	        }
	    },
	    error:function(){alert("error");return false;}
	    });
	}
});


//绑定评论
function BindReview(urldata){
    //$('#reviewtemplate').hide();//将第一行模板隐藏
    var currentComment=$('#review-'+ReviewID);
    if(ReviewID==0){
        ReviewID='';
    }
    else{
        ReviewID=6-ReviewID;
    }
	$.ajax({
        type:"get",
        dataType:"json",
        url:baseUrl + 'store/ProductReview.aspx?NoCopyRight=1&type=GetList&PID=' + productID + '&ReviewType=' + reviewType + '&PageSize=' + PageSize+'&score='+ReviewID,
        data:urldata,
        cache:false,
        success:function(msg){
            //$('div.item:gt(0)','#ReviewContent').remove();
            currentComment.empty();
            var data = msg.ProductReview;
            if(data.length==0){
				currentComment.append('<div class="noreview">暂无评价！</div>');
			}else{
				$.each(data,function(i,n){
				//var row = $('#reviewtemplate').clone().removeClass('hide');
				var row = $('#reviewtemplate').clone().show();
				row.find('.icon').find('img').attr('src',baseUrl +'upload/MemberGroupLogo/' + (n.Logo != '' ? n.Logo : 'nopic.gif'));
				row.find('.revtitle').text(n.Title);
				row.find('.star').addClass('store-review-star'+n.Score);
				row.find('.revtime').text(n.AddTime);
	               
				row.find('.username').text(n.MemberName);
				//row.find('.revscore').css('width',12*Number(n.Score) + 'px');
//				row.find('.star').addClass('star'+n.Score);
				row.find('.revbody').html(n.Body);
				row.find('.groupname').text(n.GroupName);

				/*
				var objyesNum = row.find('.yesnum').text(n.YesNum);
				var objnotNum = row.find('.notnum').text(n.NotNum);
				row.find('.vote_y').click(function(){
						var result = Vote(n.ProductReviewID,1);
						if(result == '1'){
							objyesNum.text(Number(objyesNum.text())+1);
						}else if(result == '2'){
							alert('不能重复投票!');
						};
				});
				row.find('.vote_n').click(function(){
						var result = Vote(n.ProductReviewID,0);
						if(result == '1'){
							objnotNum.text(Number(objnotNum.text())+1);
						}else if(result == '2'){
							alert('不能重复投票!');
						};
				});
				*/
				//绑定回复
				var replytemplate = row.find('#reptemplate');
				$.each(n.Reply,function(j,m){
						var replyRow = replytemplate.clone().show();
						replyRow.find('.replySerial').text((j+1));
						replyRow.find('.repname').html(n.GroupName+":<span>"+m.MemberName+"</span> 回复说");
						replyRow.find('.repbody').text(m.Body);
						replyRow.find('.reptime').text(m.ReplyTime);
						replyRow.attr('id','replyitem_'+(j+1));
						replytemplate.before(replyRow);
				});
				row.find('.btnreply').click(function(){
						var submitReplyContainer = $('#ReplySumbit').remove();
						submitReplyContainer.show().appendTo(row.find('.revinfo'));
						$('#hidden_reviewID').val(n.ProductReviewID);
						$('#txtReply').focus();
	                    
						$('#btnReply').click(function(){
							$.ajax({
								url:baseUrl + 'ProductReview.aspx?NoCopyRight=1&type=Reply',
								type:'post',
								data:$("#frmReply").serialize(),
								success:function(data){
									if(data == "NOLOGIN" && confirm('登录后才能回复,现在要登录吗?')){
									window.location.href = shopFolder + 'Login.aspx?ReturnUrl=' + returnUrl;
									}else if(data > 0){
										alert('回复成功');
										/*
										if(!row.find('.reply').is(':visible')){
											row.find('.btnviewrep').click();
										}
										row.find('.reply').show();
										*/
										$.ajax({
											url:baseUrl + 'ProductReview.aspx?NoCopyRight=1&type=GetReply',
											type:'post',
											dataType:'json',
											data:'hidden_reviewID='+$('#hidden_reviewID').val(),
											cache:false,
											success:function(replyData){
	//	                                        replytemplate.siblings().remove();
												while(replytemplate.siblings().length != 0){
													replytemplate.siblings().remove();
												}
	//	                                        row.find('.reply').children('.reptemplate:gt(0)').remove();
												$.each(replyData.Reply,function(j,m){
													var replyRow = replytemplate.clone().show();
													replyRow.find('.replySerial').text((j+1));
													replyRow.find('.repname').text(m.MemberName + '：');
													replyRow.find('.repbody').html(m.Body);
													replyRow.find('.reptime').text(m.ReplyTime);
													replyRow.attr('id','replyitem_'+(j+1));
													replytemplate.after(replyRow);
											});
											},
											error:function(){alert('error when get reply');}
										});
										$('#btnCancel').click();
									};
								},
								error:function(a,b){alert(b);}
							});
						});
		                
						$('#btnCancel').click(function(){
							submitReplyContainer.hide();
							$('#txtReply').val('');
						});
				});//点击回复结束
				/*
				row.find('.btnviewrep').click(function(){
						var replycontent = row.find('.reply');
						if(replycontent.is(':visible')){
							replycontent.hide();
							$(this).text('查看回复');
						}else{
							replycontent.show();
							$(this).text('关闭回复');
						}
				});
				*/
				//row.attr('id','item_'+i).appendTo($('#ReviewContent'));
				row.attr('id','item_'+i).appendTo(currentComment);
				});//end each                    
	           
			if(showpage){
					//分页
					alert(msg.totalCount);
					$('#revew-pager-'+ReviewID).show();
					var pagerStyle = "flickr";//jPagerBar样式
					ShowPageBar("revew-pager-"+ReviewID,//[containerId]
					"ProductReview.aspx",//[url]
					{style:pagerStyle,mark:"pageDataList1Mark",
					totalCount:msg.totalCount,showPageNumber:3,pageCount:PageSize,currentPageIndex:CurrentPage,noRecordTip:"",preWord:"上一页",nextWord:"下一页",
					onclick:"CurrentPage={pageindex};BindReview('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:shopFolder + 'ProductReview.aspx?NoCopyRight=1&type=Vote&PRID='+paid+'&val='+val + '&r='+Math.random(),
        async:false,
        success:function(data){
            if(data == 'NOLOGIN' && confirm('登录后才能投票,现在要登录吗?')){
                window.location.href = shopFolder+'Login.aspx?ReturnUrl=' + returnUrl;
                return false;
            };
            result = data;
        },error:function(){alert('error');}
    });
    return result;
};
function SetTab(tabID,showAll,callBack,options){
	var settings = {e:'click'};
	if(options){$.extend(settings,options)};
	var objTabMenu = $('#'+tabID).children('.menuconainer').children('.menuitem');
	var objTabItem = $('#'+tabID).children('.itemcontainer').children('.tabitem');
	if(!showAll)objTabItem.hide().eq(0).show();
	objTabMenu.each(function(index){
		$(this).bind(settings.e,function(){
			ReviewID = index;
			$(this).addClass('tabon').removeClass('tabout').siblings('.menuitem').removeClass('tabon').addClass('tabout');
			if(showAll){
				if(index==0)
				{
					objTabItem.show();
				}else{
					objTabItem.hide();
					objTabItem.eq(index).show();
				}
			}else{
				objTabItem.hide();
				objTabItem.eq(index).show();
				
			}
			if(callBack)
			{
				if($('#review-'+index).children().length==0){
					BindReview('Page=1');
				}
			}
		})//end bind
	});//end each
};//end function
function ShowPageBar(containerId , url , attr)
{
    var style = (attr["style"] == null)? "technorati" : attr["style"];//class样式
    var totalCount =( attr["totalCount"]==null ||  attr["totalCount"] == 0) ? 0 :  attr["totalCount"];;//parseInt()//总记录条数
    var pageCount = (attr["pageCount"] == null || attr["pageCount"] == 0) ? 20 : attr["pageCount"];//attr["pageCount"];//每页记录数
    var showPageNumber = (attr["showPageNumber"] == null || attr["showPageNumber"] == 0) ? 20 : attr["showPageNumber"];//attr["showPageNumber"];//显示页码数量
    var currentPageIndex = attr["currentPageIndex"];//当前页
    var onclick = attr["onclick"];//onclick参数，如果包含“return false”，则连接转为跳到barMark（暂留接口，其实return false后一般情况下href将失效。）
    var barMark = attr["mark"];//onclick后跳转到的<a name="barMark"></a>标签
    var noRecordTip = attr["noRecordTip"];//没有记录提示（支持HTML）
    var preWord = (attr["preWord"] == null)? " < " : attr["preWord"];//上一条记录文字，默认为“ < ”
    var nextWord = (attr["nextWord"] == null)? " > " : attr["nextWord"];//下一条记录文字，默认为“ > ”
    
    //输出设置
    var barID = containerId + "_pageBar";
    //var barDiv = $("#"+barID);
    //添加PageBar层
    $("#"+containerId).html("<div id=\"" + barID + "\" class=\"" + style + "\"></div>");
    //输出设置 结束
    
    //如果没有记录，返回空记录提示
    if(totalCount==0)
    {
        $("#"+barID).html(noRecordTip);
        return false;
    }
    
    pageCount = (pageCount == null || pageCount == 0) ? 20 : pageCount;//每页显示记录数
    var totalPage = parseInt((totalCount-1) / pageCount) +1;//总页数
    
    showPageNumber = (showPageNumber == null || showPageNumber == 0) ? 3 : showPageNumber;
    currentPageIndex = (currentPageIndex == null || currentPageIndex <= 0 || currentPageIndex > totalPage) ? 1 : currentPageIndex;

    var backPageStyle = (currentPageIndex <= 1) ? "disabled" : "";
    var nextPageStyle = (currentPageIndex >= totalPage) ? "disabled" : "";

    var firstDisplayPageEnd = 0;//从第1页显示到xx页
    var bodyDisplayPageStart = 0;//当前页临近最左页码
    var bodyDisplayPageEnd = 0;//当前页临近最右页码
    var endDisplayPageStart = 0;//从第xx页显示到最后一页

    //设定 bodyDisplayPageStart
    bodyDisplayPageStart = (currentPageIndex - showPageNumber <= 1) ? 1 : currentPageIndex - showPageNumber; // (ViewData.pageIndex - ViewData.showPageNumber <= ViewData.showPageNumber) ? ViewData.showPageNumber + 1 : ViewData.pageIndex - ViewData.showPageNumber;

    //设定 bodyDisplayPageEnd
    bodyDisplayPageEnd = (currentPageIndex + showPageNumber >= totalPage) ? totalPage : currentPageIndex + showPageNumber;


    //设定 firstDisplayPageEnd
    if(bodyDisplayPageStart > 1)
    {
        if(bodyDisplayPageStart - showPageNumber <= 1)
            firstDisplayPageEnd = bodyDisplayPageStart - 1;
        else
            firstDisplayPageEnd = showPageNumber;
    }
    else
    {
        firstDisplayPageEnd = 0;
    }
    
    //设定 endDisplayPageStart
    if(bodyDisplayPageEnd < totalPage)
    {
        if(bodyDisplayPageEnd + showPageNumber >= totalPage)
            endDisplayPageStart = bodyDisplayPageEnd + 1;
        else
            endDisplayPageStart = totalPage - showPageNumber + 1;
    }
    else
    {
        endDisplayPageStart = totalPage + 1;
    }
    
    if(currentPageIndex <= 1)
        $("<span class=\"" + backPageStyle + "\">" + preWord + "</span>").appendTo($("#"+barID));
    else
        $(GetPageLink(currentPageIndex-1,currentPageIndex,preWord,onclick,url,barMark)).appendTo($("#"+barID));
     
    //first
    for (var i = 1; i <= firstDisplayPageEnd; i++)
        $(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
        
    //省略号
    if (firstDisplayPageEnd + 1 < bodyDisplayPageStart)
        $("<span>...</span>").appendTo($("#"+barID));
        
    //body
    for (var i = bodyDisplayPageStart; i <= bodyDisplayPageEnd; i++)
        $(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
        
    //省略号
    if (bodyDisplayPageEnd + 1 < endDisplayPageStart)
        $("<span>...</span>").appendTo($("#"+barID));
   
    //end
     for (var i = endDisplayPageStart; i <= totalPage; i++)
        $(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
        
    // > 
    if(currentPageIndex >= totalPage)
        $("<span class=\"" + nextPageStyle + "\">" + nextWord + "</span>").appendTo($("#"+barID));
    else
        $(GetPageLink(currentPageIndex + 1 ,currentPageIndex,nextWord,onclick,url,barMark)).appendTo($("#"+barID));
    
    $('<span>记录数:' + totalCount + ',共' + totalPage + '页</span>').appendTo($("#"+barID));    
        
       
}

//页码标签链接
function GetPageLink(linkPageIndex ,currentPageIndex,text,onclick,url,barMark)
{
    var pageData = "?page=";//string.Format("{0}page=", (Request.QueryString.Count == 0) ? "?" : "&") + "{0}";//页码参数
    onclick = (onclick != null)? "onclick=\"" + onclick + "\"" : "";
    while(onclick.indexOf('{pageindex}') != -1)
    {
        onclick = onclick.replace("{pageindex}",linkPageIndex);
    }
    href = (onclick != null && onclick.indexOf("return false") != -1)?"href=\"#" + barMark + "\" ":"href=\"" + url + pageData + linkPageIndex + "\" ";
    
    var linkHTML = "";
    
    if(linkPageIndex == currentPageIndex)
        linkHTML =  "<span class=\"current\">" + text + "</span>";
    else
        linkHTML = "<a " + href + onclick + ">" + text + "</a>";
          
    return linkHTML;
}