/*--------------------------------------------------|
| PageNavigater 1.00 |   http://www.sinoprise.com   |
|---------------------------------------------------|
| Copyright (c) 2008 Kevin Yin                      |
|                                                   |
| This script can be used freely as long as all     |
| copyright messages are intact.                    |
|                                                   |
| Updated: 2008/01/24                               |
|--------------------------------------------------*/

// PageNavigater
function PageNavigater(pageSize, recordCount, currentPage, align, navigaterUrl) {
	this.pageSize  = pageSize;
	this.recordCount = recordCount;
	this.currentPage = currentPage;
	//this.width = 300;
	this.align = align;
	this.navigaterUrl = navigaterUrl;
	
	this.pageCount = 0;	
};

// Outputs the PageNavigater to the page
PageNavigater.prototype.toString = function() {
	
	this.pageCount = this.recordCount / this.pageSize; 
	if ( this.pageCount > parseInt(this.pageCount) )
		this.pageCount = parseInt(this.pageCount) + 1;
	
	var strBuilder=new String();
  	var p=( this.currentPage - ( this.currentPage % 10 ) ) / 10; //计算分页显示的页数  	
      	
    	strBuilder += "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" ";
    	//strBuilder += "   width=\""+this.width+"\";
     	strBuilder += "   align=\""+this.align+"\">";
     	strBuilder += " <tr> ";
     	
     	//显示分页信息
     	strBuilder += "<td valign=\"middle\">页次：[<b>"+this.currentPage+"</b>/<b>"+this.pageCount+"</b>]页 每页[<b>";
     	strBuilder += this.pageSize+"</b>]条 总记录数：[<b>"+this.recordCount+"</b>]条</td>" ;   	
     	
     	//显示分页列表
     	strBuilder+=" <td valign=\"middle\" align=\"right\">分页：";
        
        //首组为第0族
     	if ( 1 == this.currentPage ){
	   	strBuilder+="<font face=\"webdings\"  color=\"#ff0000\">9</font> "
	} else {
	   	strBuilder+="<a href=\""+this.navigaterUrl+"?pageindex=1\" title=\"首页\"><font face=\"webdings\">9</font></a>   "
	}
	  
     	//上十页
     	if ( p * 10 > 0 ){
       		strBuilder+="<a href=\""+this.navigaterUrl+"?pageindex=" + ( p * 10 ) + "\"  title=上十页><font face=\"webdings\">7</font></a>   "
     	}  
     	
     	strBuilder+="<b>"
      	//分页列表
     	for( var i = p * 10 + 1; i <= p * 10 + 10; i++ ){
        	if (i==this.currentPage){
			strBuilder+="<font color=\"#000000\">"+i+"</font> "
	    	} else {
			strBuilder+="<a href=\""+this.navigaterUrl+"?pageindex=" + i + "\" title=\"转到: 第"+i+"页\">" + i + "</a>   "
	    	}	
	   	if ( i >= this.pageCount ) break;
	 }  
	 strBuilder+= "</b>"
      	//显示下十页
      	if ( i < this.pageCount){
        	strBuilder+="<a href=\""+this.navigaterUrl+"?pageindex="+i+"\" title=\"下十页\"><font face=\"webdings\">8</font></a>   "
      	}  
       	//显示尾页
      	if (this.currentPage==this.pageCount){
	      strBuilder+= "<font face=\"webdings\" color=\"#000000\">:</font>   "
	}else{
	    strBuilder+= "<a href=\""+this.navigaterUrl+"?pageindex="+this.PageCount+"\" title=\"尾页\"><font face=\"webdings\">:</font></a>   "
	}  
     	strBuilder+= "</td></tr></table>"

	return strBuilder;
};
