/**
 * @author Administrator
 */
/**
 * @李良
 */

var pageIndex = 1;
function ShowComm(pageIndex){
    var itemsID = $("#itemsID").val();
	$("#commList").html("正在加载评论....");
	$("#commPageList").html("");
    $.getJSON("/WebManage/Book/ItemsCommAjax.aspx?Temp=" + Math.random(), {
        Type: "GetComm",
        PageIndex: pageIndex,
        ItemsID: itemsID,
        PageSize: 5
    }, function(data){
        var strHtml = "";
        $.each(data.CommList, function(index, value){
		  
            var bookDate = value.AddTime;
            bookDate = bookDate.replace("/Date(", "");
            bookDate = bookDate.replace("+0800)/", "");
          　 bookDate = new Date(parseInt(bookDate));
            bookDate = bookDate.getFullYear() + "-" + (bookDate.getMonth() + 1) + "-" + bookDate.getDate()+"&nbsp;&nbsp;"+bookDate.getHours()+":"+bookDate.getMinutes()+":"+bookDate.getSeconds();
            
			if(value.Sex=="女")
			{
				
				strHtml+="<div class='play_txt6_female'>";
			}
			else
			{
				strHtml+="<div class='play_txt6'>";
			}
			strHtml+="<div class='itemsdiv1'><span class='itemsspan1'><b style='color:#d08900; ' >"
            strHtml+=value.UserName+"</b> </span>";
            strHtml+= "<span>发表于 &nbsp;&nbsp;";
			strHtml+=bookDate+"</span></div>";
			strHtml+="<div class='itemsdiv2'>";
			strHtml+=value.Content;
			strHtml+="</div></div>";
        });
		$("#commPageList").html(data.PageList);
		$("#commList").html(strHtml);
    });
}

function AddStaticComm(){
    var strName = $("#txtUserName").val();
    var strSex = $("input[@name=sex][@checked]").val();
    var strContent = $("#txtContent").val();
    var strItemsID = $("#itemsID").val();
	var strItemsName=$("#itemsName").val();
    
    if (strName == "") {
        alert("请输入您的姓名^_^");
        return false;
    }
    if (strContent == "") {
        alert("您还没有输入要留言的内容^_^");
        return false;
    }
    var objComm = {
    
        UserName: strName,
        Content: strContent,
        Sex: strSex,
        ItemsID: strItemsID,
		ItemsName:strItemsName};
    objComm = JSON.stringify(objComm);
    paramObj = {
        Comment: objComm,
        Type: "AddComm"
    };
    CommRequest(paramObj)
}

function CommRequest(parameter){
    $.post("/WebManage/Book/ItemsCommAjax.aspx?Temp=" + Math.random(), parameter, function(data){
        if (data == "strture") {
             $("#txtContent").val("");
			 $("#txtUserName").val("");
            alert("您的留言成功提交，谢谢!");
			ShowComm(1);//重新加载留言
        }
    });
}