function PageDown(pageCount,QueryKey){

var newSearch
newSearch=""
if(location.search==""){
location.replace(location.pathname+location.search+"?"+QueryKey+"="+pageCount)
}else if(location.search=="?"){
location.replace(location.pathname+location.search+"page_count="+pageCount)
}else if(location.search.indexOf(QueryKey+"=")==-1){
location.replace(location.pathname+location.search+"&"+QueryKey+"="+pageCount)
}else{
   newSearch=location.search
   var re=new RegExp(QueryKey+"=[0-9]*","gim")

   newSearch=newSearch.replace(re,QueryKey+"="+pageCount)

   location.replace(location.pathname+newSearch)
}

}

function pageMenu(pageCount,stepSize,QueryKey,classname){

  var stepDown,stepUp,PageUp,PageDown,first,trail,current,stepCount 
  var j=1
  var duan=0
  stepCount=getStepCount(pageCount,stepSize)
  current=eval(QueryString(QueryKey))
  if(current>pageCount)current=pageCount  
  for(;j<=stepCount;j++){
	
    if(current<=stepSize*j)break	
  }
  duan= stepSize*(j-1)
  
  first="<a class='page' href='javascript:void  PageDown(1,\""+QueryKey+"\")'>首页</a>" 
  trail="<a class='page' href='javascript:void  PageDown("+pageCount+",\""+QueryKey+"\")'>尾页</a>" 
  PageUp= current>1? "<a class='"+classname+"' href='javascript:void PageDown("+(current-1)+",\""+QueryKey+"\")'>上页</a>":"上页" 
  PageDown= current<pageCount ? "<a class='"+classname+"' href='javascript:void PageDown("+(current+1)+",\""+QueryKey+"\")'>下页</a>":"下页"  
  if(eval(duan)>0){
    stepUp="<a class='"+classname+"' href='javascript:void PageDown("+eval(duan)+",\""+QueryKey+"\")'><<</a>"
  }else{
    stepUp="<<"
  }
  if(eval(duan+1+stepSize)<=pageCount){
    stepDown="<a class='"+classname+"' href='javascript:void PageDown("+eval(duan+1+stepSize)+",\""+QueryKey+"\")'>>></a>"
  }else{
    stepDown=">>"
  }
  document.open   
   document.write("<span id='pageMenu'>"+first+"&nbsp;"+PageUp+"&nbsp;"+PageDown+"&nbsp;"+trail)
   document.write("&nbsp;"+stepUp)
    for(i=1;i<=stepSize;i++){
	  var n=eval(duan+i)
	  if(n<=pageCount){		     
	     if(current==n){
		    document.write("&nbsp;<a class='"+classname+"' href='javascript:void PageDown("+n+",\""+QueryKey+"\")'>["+n+"]</a>")	   		   
		 }else{
		    document.write("&nbsp;<a class='"+classname+"' href='javascript:void PageDown("+n+",\""+QueryKey+"\")'>"+n+"</a>")	   
		 }
	  }else{
	    break;
      }	  
	}	
	document.write("&nbsp;"+stepDown+"</span>")
  document.close
}

function QueryString(key){
 var url=location.search
 var re=new RegExp(key+"{1}=[^&]*&{0,1}","gim") 
 index=url.match(re)
 if(index==null){
 current=1
 }else{
 index=index.toString() 
 current=index.substring(index.indexOf("=")+1)
 if(current==null || current=="")current=1
 else
 current=current.replace("&","")
 }
 return current 
}

function getStepCount(pageCount,stepSize){  
  var setpCount=1
  if(pageCount < stepSize)
    return setpCount
  var yu=pageCount % stepSize 
  setpCount=(pageCount-yu)/stepSize  
  if(yu>0)++setpCount

  return setpCount
}

