﻿//留言簿相关操作!innerguestbook
function list_guestbook()
{
	//alert('ttts');
	var p;			
	((request('p')=="")||(isNaN(request('p'))))?p=1:p=request('p');	
	$.ajax({
		url:'Res/inner.php?action=guestbooklist&p='+p+'&r='+Math.random(),
		type:"get",
		dataType:"json",
		success:function (transport){	
			var tempstr=transport;
			var tempstrLen=tempstr.length;	
			
			if(tempstrLen<=1)
			{
				//$("#in_comment").html("<div class=\"tit\">网友评论：</div><div id=\"comm_list\">暂无评论</div>");
			}
			else
			{
			
				var totlePage,totleRecord,curPage,firstPage,prePage,nextPage,lastPage;
				var iB,iE;	
				curPage=p;			
				//第一步：初始化
				totleRecord=tempstr[tempstrLen-1].totleRecord;			
				totlePage=tempstr[tempstrLen-1].totlePage;			
				lastPage=Math.ceil(totleRecord/totlePage);	
				exactPage=totlePage;
				
				//第二步：当前页 小于1 或 大于lastPage 的处理程序
				prePage = curPage-1;
				nextPage = curPage-1+2;			
				if(curPage <= 1)
				{
					curPage = 1;
					prePage = 1;
					nextPage = 2;
				}
				if(curPage > lastPage)
				{
					curPage = lastPage;
					prePage = lastPage - 1;
					nextPage = lastPage;
				}
				if(curPage == lastPage)
				{
					nextPage = lastPage;
					exactPage = totleRecord - (curPage -1) * totlePage;
				}
				
				(curPage-4)<1?iB=1:iB=curPage-4;								
				(curPage-1+5)>lastPage?iE=lastPage:iE=curPage-1+5;		
				
				var tpl=new Ftemplate(Fid('tpl_comm_list').innerHTML);			
				tpl.setBlock('','comm_list','comm_lists');
				for(var i=0;i<tempstrLen-1;i++)
				{						
					tpl.setBlockVar('comm_list','id',i+1);				
					tpl.setBlockVar('comm_list','comm_author',tempstr[i].comm_author);				
					tpl.setBlockVar('comm_list','comm_content',tempstr[i].comm_content);				
					tpl.setBlockVar('comm_list','comm_posttime',tempstr[i].comm_posttime);				
					tpl.parseBlock('comm_list');				
				}
				var curr_url=window.location.pathname;
				tpl.setBlock('','page','pages');			
				tpl.setVar('firstPage', curr_url+'?p=1');			
				tpl.setVar('prePage', curr_url+'?p='+prePage);			
				tpl.setVar('nextPage',curr_url+'?p='+nextPage);			
				tpl.setVar('lastPage', curr_url+'?p='+lastPage);			
				iB>1?tpl.setVar('p1','<a href="'+curr_url+'?p='+(iB-1)+'">..</a>'):tpl.setVar('p1','');		
				iE<lastPage?tpl.setVar('p2','<a href="'+curr_url+'?p='+(iE+1)+'">..</a>'):tpl.setVar('p2','');	
				for(var j=iB;j<=iE;j++)			
				{				
					var tmp=(j==curPage)?''+j+'':'<a href="'+curr_url+'?p='+j+'">['+j+']</a>';				
					tpl.setBlockVar('page','pageNum',tmp);				
					tpl.parseBlock('page');
				}					
				
				tpl.parse();			
				tpl.show('in_comment');
			}
		}		
	});	
}

function guestbookadd()
{	
	
	var comm_author = $.trim($('#comm_author').val());
	var comm_email = $.trim($('#comm_email').val());
	var comm_content = $.trim($('#comm_content').val());
	var VerifyCode = $.trim($('#VerifyCode').val());
	
	$.ajax({
		url:'Res/inner.php?action=guestbookadd&r='+Math.random(),
		type:"post",
		dataType:"html",
		data: "comm_author="+comm_author+"&comm_content="+comm_content+"&comm_email="+comm_email+"&VerifyCode="+escape(VerifyCode),
		success:function (transport){
			if(parseInt(transport)==200)
			{
				alert('谢谢留言 :) ');					
				var curr_url=window.location.pathname;
				location.href=curr_url+'?r='+Math.random();
			}
			else
			{
				alert(unescape(transport));	
			}
		}		
	});		
}

