<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/cms4j" prefix="cms4j" %>

<%@ page import = "cn.com.dekn.cms.util.*,cn.com.dekn.common.util.*" %>

<%
	//���²鿴ҳ��ҳ  ��һҳ  1 2 3 4 5 6 7 8 9 10 ��һҳ

/***********************************
* CSS��ʽ �����ʼ��
***********************************/
//��ǰҳ��ɫ
String CSS_CURR_PAGE = StrUtil.getNotNullStringValue(request.getParameter("CSS_CURR_PAGE"),"");

//����ҳ��ɫ
String CSS_OTHER_PAGE = StrUtil.getNotNullStringValue(request.getParameter("CSS_OTHER_PAGE"),"");

//����ҳ
String CSS_NEXT_PREV_PAGE = StrUtil.getNotNullStringValue(request.getParameter("CSS_NEXT_PREV_PAGE"),"");

//����ҳû������
String CSS_NEXT_PREV_PAGE_NOLINK = StrUtil.getNotNullStringValue(request.getParameter("CSS_NEXT_PREV_PAGE_NOLINK"),"");


/***********************************
* ��������߼�
***********************************/

	
	//��ǰҳ��
	int PN = StrUtil.getNotNullIntValue(request.getParameter("apn"),1);
	int PAGE_COUNT = StrUtil.getNotNullIntValue((String)request.getParameter("PAGE_COUNT"),1);
	
	if(PAGE_COUNT <= 1){
		return;
	}

	//��ҳ�������մ�ŵ�URL
	String pageCachedURL = request.getParameter("pageCachedURL");
	
	//��һҳ��URL�������ģ�
	String firstPageCachedURL = request.getParameter("firstPageCachedURL");
	
	//��̬�����������õķ�ҳ��
	int cachePageCount = StrUtil.getNotNullIntValue(request.getParameter("cachePageCount"));
	
	//��ǰ��ҳ��
	int CURRENT_PAGE_NUM = StrUtil.getNotNullIntValue((String)request.getAttribute("CURRENT_PAGE_NUM"),0);
	
	String PREV_PAGE_URL = "";
	String NEXT_PAGE_URL = "";
	
	if(null != pageCachedURL && !pageCachedURL.equals("")){
		//ȡ����վ��������
		String context = cn.com.dekn.cms.syscfg.vo.SiteConfig.getInstance("root").getCONTEXT_PATH();
		if(null != context && !context.equals("/")){
			pageCachedURL = context + pageCachedURL;
			firstPageCachedURL = context + firstPageCachedURL;
		}
	
		//��һҳ �����߼�
		if(PN == 1){	//���Ϊ��1ҳ
			PREV_PAGE_URL = firstPageCachedURL;
		}else if(cachePageCount+1 >= PN){
	 		PREV_PAGE_URL = StrUtil.replaceAll(pageCachedURL,"$pn",String.valueOf(PN -1));
		}else{
	 		PREV_PAGE_URL = URLUtil.addParam(request,"apn",String.valueOf(PN-1));
		}
		
		//��һҳ �����߼�
		if(PN >= PAGE_COUNT){	//���ǰҳΪ���һҳ
			NEXT_PAGE_URL = StrUtil.replaceAll(pageCachedURL,"$pn",String.valueOf(PAGE_COUNT));
		}else if(cachePageCount > PN||cachePageCount==PAGE_COUNT){
	 		NEXT_PAGE_URL = StrUtil.replaceAll(pageCachedURL,"$pn",String.valueOf(PN + 1));
		}else{
	 		NEXT_PAGE_URL = URLUtil.addParam(request,"apn",String.valueOf(PN + 1));
		}
	 	
	}else{
		//��һҳ �����߼�
		if(PN == 1){	//���Ϊ��1ҳ
			PREV_PAGE_URL = URLUtil.addParam(request,"apn","1");
		}else{
	 		PREV_PAGE_URL = URLUtil.addParam(request,"apn",String.valueOf(PN-1));
		}
		
		//��һҳ �����߼�
		if(PN >= PAGE_COUNT){	//���ǰҳΪ���һҳ
			NEXT_PAGE_URL = URLUtil.addParam(request,"apn",String.valueOf(PAGE_COUNT));
		}else{
	 		NEXT_PAGE_URL = URLUtil.addParam(request,"apn",String.valueOf(PN + 1));
		}
	}
	
	

%>

<% if(PN > 1){ %>
	<% if(PN == 2 && null != pageCachedURL && !pageCachedURL.equals("")){%>
		<a href="<%=firstPageCachedURL%>"><font class="<%=CSS_NEXT_PREV_PAGE%>">��һҳ</font></a>
	<% }else{ %>
		<a href="<%=PREV_PAGE_URL%>"><font class="<%=CSS_NEXT_PREV_PAGE%>">��һҳ</font></a>
	<% } %>
<% }else{ %>
	<font class="<%=CSS_NEXT_PREV_PAGE_NOLINK%>">��һҳ</font>
<% } %>

<%
for(int i = 1;i<=PAGE_COUNT;i++){
%>
	<% if(i == PN) { %><b><font class="<%=CSS_CURR_PAGE%>">[<%=i%>]</font></b>
	<% }else if(i == 1){ %>
		<%
		if(null != pageCachedURL && !pageCachedURL.equals("")){
		%>
		<a href="<%=firstPageCachedURL%>"><font class="<%=CSS_OTHER_PAGE%>">[<%=i%>]</font></a>
		<% }else{ %>
		<a href="<%=URLUtil.addParam(request,"apn",String.valueOf(1))%>"><font class="<%=CSS_OTHER_PAGE%>">[<%=i%>]</font></a>
		<% } %>
		
	<% }else{%>
		<%
		if(null != pageCachedURL && !pageCachedURL.equals("") && cachePageCount>= i){
		%>
		<a href="<%=StrUtil.replaceAll(pageCachedURL,"$pn",String.valueOf(i))%>"><font class="<%=CSS_OTHER_PAGE%>">[<%=i%>]</font></a>
		<% }else{ %>
		<a href="<%=URLUtil.addParam(request,"apn",String.valueOf(i))%>"><font class="<%=CSS_OTHER_PAGE%>">[<%=i%>]</font></a>
		<% } %>
	<% } %>
<%
}
%>

<% if(PN < PAGE_COUNT){ %>
	<a href="<%=NEXT_PAGE_URL%>"><font class="<%=CSS_NEXT_PREV_PAGE%>">��һҳ</font></a>
<% }else{ %> 
	<font class="<%=CSS_NEXT_PREV_PAGE_NOLINK%>">��һҳ</font>
<% } %>
