//分页函数
function createPageHTML(_nPageCount, _nCurrIndex, _sPageName, _sPageExt){
	if(_nPageCount == null || _nPageCount<=1){
		return;
	}
	var nCurrIndex = _nCurrIndex || 0;
        // 输出上一页和首页
         // 当前页是首页
	if(nCurrIndex == 0){
		document.write("首页&nbsp;上一页&nbsp;1&nbsp;");
	}
        // 当前页不是首页
        else{
		var nPreIndex = nCurrIndex - 1;
		var sPreFileExt = nPreIndex == 0 ? "" : ("_" + nPreIndex);

		document.write("<a href=\""+_sPageName+"."+_sPageExt+"\">首页</a>&nbsp;");
		document.write("<a href=\"" + _sPageName + sPreFileExt + "."+_sPageExt+"\">上一页</a>&nbsp;");
                if(nCurrIndex < 5){
		      document.write("<a href=\""+_sPageName+"."+_sPageExt+"\">1</a>&nbsp;");
                }
	}
        // 确定起始页索引
        var startIndex = 1;
        // 结束页索引
        var endIndex = 10;
        // 当前页数小于5或只有10页，默认值，索引是从0开始的，0代表第1页
         if(nCurrIndex  < 5 || _nPageCount <= 10){
           if(_nPageCount <= 10){
              endIndex = _nPageCount;
           }
        }
        // 当前页数大于6，当前页数+5小于总页数，索引是从0开始的，0代表第1页
        else if(nCurrIndex  >= 5 && nCurrIndex +5 < _nPageCount){
           startIndex = nCurrIndex - 4;
           endIndex = nCurrIndex + 5;
        }
        // 如果当前页数在后十页
        else{
           startIndex = _nPageCount - 10;
           endIndex = _nPageCount;
        }
	for(var i=startIndex ; i<endIndex; i++){
	  if(nCurrIndex == i)
	    document.write((i+1) + "&nbsp;");
	  else
	    document.write("<a href=\""+_sPageName+"_" + i + "."+_sPageExt+"\">"+(i+1)+"</a>&nbsp;");
	}

	// 3 输出下一页和尾页
	// 3.1 当前页是尾页
	if(nCurrIndex == (_nPageCount-1)){
	    document.write("下一页&nbsp;尾页");
	}
	// 3.2 当前页不是尾页
	else{
		var nNextIndex = nCurrIndex + 1;
		var sPreFileExt = nPreIndex == 0 ? "" : ("_" + nPreIndex);

		document.write("<a href=\""+_sPageName+"_" + nNextIndex + "."+_sPageExt+"\">下一页</a>&nbsp;");
		document.write("<a href=\""+_sPageName+"_" + (_nPageCount-1) + "."+_sPageExt+"\">尾页</a>");
	}
}
//跳转函数
function createGoPageHTML(_nPageCount, _nCurrIndex, _sPageName, _sPageExt, _sGoPageTxtId){
    var goPageTxt = document.getElementById(_sGoPageTxtId);
	if(goPageTxt == null){
	   return;
	}
	var pageNum = goPageTxt.value;
	if(pageNum == '' || pageNum.length == 0){
	   return;
	}
	if(pageNum < 1){
	   alert("页数不能为小于零的整数");
	   goPageTxt.value = '';
	   return;
	}
	if(pageNum > _nPageCount){
	   alert("页数不能大于总页数");
	   goPageTxt.value = '';
	   return;
	}
    window.location.href = _sPageName + "_" + (pageNum - 1) + "."+_sPageExt;
}

