﻿//el HTMLElement		The html element used to represent the fenye control
//tsize           page fen zu size
//tPageSize       one pages recordsize	 
//tallCount       all records count
//tclassname      classname
//tid			  function name
// bUseCookie : Boolean	Optional. Default is true. Used to determine whether to us persistance using cookies or not
//
function hasSupport() {

	if (typeof hasSupport.support != "undefined")
		return hasSupport.support;
	
	var ie55 = /msie 5\.[56789]/i.test( navigator.userAgent );
	
	hasSupport.support = ( typeof document.implementation != "undefined" &&
			document.implementation.hasFeature( "html", "1.0" ) || ie55 )
			
	// IE55 has a serious DOM1 bug... Patch it!
	if ( ie55 ) {
		document._getElementsByTagName = document.getElementsByTagName;
		document.getElementsByTagName = function ( sTagName ) {
			if ( sTagName == "*" )
				return document.all;
			else
				return document._getElementsByTagName( sTagName );
		};
	}

	return hasSupport.support;
}
function JEFF_fenye( el,el2,tsize,tPageSize,tallCount,tclassname,tid,bUseCookie) {
	if ( !hasSupport() || el == null ) return;
	
	this.element = el;
	this.el2 = el2;
	this.element.tabPane = this;	
	this.selectedIndex = null;
	this.useCookie = bUseCookie != null ? bUseCookie : true;
	this.classname=tclassname;

	this.size=tsize;
	this.PageSize=tPageSize;
	
	this.allCount=tallCount;
	this.PageCount=Math.ceil(this.allCount/this.PageSize);	
	this.SizeCount=Math.ceil(this.PageCount/this.size);	
	this.countSizeCount=1;	
	
	this.newid=tid;

	var tabIndex = 1;
	if ( this.useCookie ) {
		tabIndex = Number( JEFF_fenye.getCookie( "jeff_fy" + this.element.id ) );
		if ( isNaN( tabIndex ) )
			tabIndex = 1;
	}
	if(tabIndex>this.PageCount)
		tabIndex=this.PageCount;
	if (tabIndex <1)
	{
		tabIndex=1;
	}
	this.Index = tabIndex;	
	this.showthisPage(this.Index);
	
}

// Cookie handling
JEFF_fenye.setCookie = function ( sName, sValue, nDays ) {
	
	var expires = "";
	if ( nDays ) {
		var d = new Date();
		d.setTime( d.getTime() + nDays * 24 * 60 * 60 * 1000 );
		expires = "; expires=" + d.toGMTString();
	}

	document.cookie = sName + "=" + sValue + expires + "; path=/";
};

JEFF_fenye.getCookie = function (sName) {
	var re = new RegExp( "(\;|^)[^;]*(" + sName + ")\=([^;]*)(;|$)" );
	var res = re.exec( document.cookie );
	return res != null ? res[3] : null;
};

JEFF_fenye.removeCookie = function ( name ) {
	setCookie( name, "", -1 );
};

JEFF_fenye.prototype.getIndex = function () {
	return this.Index;
};


JEFF_fenye.prototype.showthisPage = function (tempIndex)
{
	
	this.PageCount=Math.ceil(this.allCount/this.PageSize);	
	this.SizeCount=Math.ceil(this.PageCount/this.size);
	
	if(tempIndex>this.PageCount && this.PageCount!=0)
		tempIndex=this.PageCount;
	
	this.Index=tempIndex;
	if(this.Index<1)
	{
		this.Index=1;
	}
	
	this.countSizeCount=Math.ceil(this.Index/this.size);
	
	if ( this.useCookie )
			JEFF_fenye.setCookie( "jeff_fy" + this.element.id, tempIndex );	// session cookie	
	document.getElementById(this.el2.id).innerHTML=this.showFenye();
	document.getElementById(this.element.id).innerHTML=this.showFenye2();
	
	
}


JEFF_fenye.prototype.strshowPage = function (setIndex)
{
	return "javascript:"+this.newid+"("+setIndex+")";
}



JEFF_fenye.prototype.showFenye = function ()
{
	
	
	var strFenyeHead,strFenyeBody,strFenyeEnd,strFenye;
	var tempP;
	if(this.PageCount>1)
	{
		strFenyeBody='';
		strFenyeHead='';
		strFenyeEnd='';
		
		var strDivStar='<div  class="'+this.classname+'" align="center">';	
		
		var j=((this.countSizeCount-1)*this.size+1);
		if(j<1)
			j=1;
		
		var tempmax=j+this.size;
		
		if(this.countSizeCount==this.SizeCount)
			tempmax=this.PageCount+1;
		
		if(this.Index==1)
		{
			strFenyeHead='';	
		}
		else
		{
			
			tempP=this.Index-1;
			strFenyeHead='<a class="'+this.classname+'" title="转到第'+tempP+'页" href="'+this.strshowPage(tempP)+'">上一页</a>&nbsp;&nbsp;';
			
			
			tempP=(this.countSizeCount-1)*this.size;
			if(this.countSizeCount>1)
				strFenyeHead+='<a class="'+this.classname+'" style="font-weight:Bold;font-size: 14px;" title="转到第1页" href="'+this.strshowPage(1)+'"> 1</a>&nbsp;<a class="bluef" href="'+this.strshowPage(tempP)+'" title="转到第'+tempP+'页">...</a>&nbsp;';
			
		}
		if(this.Index==this.PageCount)
		{
		
			strFenyeEnd='';
		}
		else
		{
			tempP=this.countSizeCount*this.size+1;
			
			if(this.countSizeCount<this.SizeCount)
				strFenyeEnd='&nbsp;<a class="'+this.classname+'" href="'+this.strshowPage(tempP)+'" title="转到第'+tempP+'页">...</a>&nbsp;<a class="'+this.classname+'" style="font-weight:Bold;font-size: 14px;" title="转到最后1页" href="'+this.strshowPage(this.PageCount)+'"> '+this.PageCount+'</a>&nbsp;';
			tempP=this.Index*1+1;
			strFenyeEnd+='&nbsp;<a class="'+this.classname+'" title="转到第'+tempP+'页" href="'+this.strshowPage(tempP)+'">下一页</a><IMG height="9" src="images/web_950_10.jpg" width="5">';
			
		}		
		
		
		
		if(this.allCount!=0)
		{
			for(var i=j;i<tempmax;i++)
			{
				if(i==this.Index)
					strFenyeBody=strFenyeBody+'<font style="font-weight:Bold;background-color: #ff7300;COLOR: WHITE;font-size: 16px;">'+i+'</font>&nbsp;';
				else
					strFenyeBody=strFenyeBody+'<a class="'+this.classname+'" style="font-weight:Bold;font-size: 14px;" title="转到第'+i+'页" href="'+this.strshowPage(i)+'">'+i+'</a>&nbsp;';
			}
			document.getElementById(this.element.id).style.display="";
			document.getElementById(this.el2.id).style.display="";
		}
		else
		{
			strFenyeEnd='&nbsp;<a disabled="true">下一页</a>';
			document.getElementById(this.element.id).style.display="none";
			document.getElementById(this.el2.id).style.display="none";
		}
		
		var strDivEnd='</div>';
		
		
		var strFenyCount='<span style="width:5px;"></span><font style="font-size: 12px;font-weight:Bold;">当前第</font><font style="font-size: 12px;font-weight:Bold;color:red;">'+this.Index+'</font><font style="font-size: 12px;font-weight:Bold;">页</font>';
		strFenyCount=strFenyCount+'/<font style="font-size: 12px;font-weight:Bold;">共'+this.PageCount+'页</font><span style="width:5px;"></span>';
		
	//		strFenye=strDivStar+strFenyCount+strFenyeHead+strFenyeBody+strFenyeEnd+strDivEnd;

		strFenye=strDivStar+strFenyeHead+strFenyeBody+strFenyeEnd+strDivEnd;
	}
	else
		strFenye="";
	
	return strFenye;
}


JEFF_fenye.prototype.showFenye2 = function ()
{
	
	
	var strFenyeHead,strFenyeEnd,strFenye;
	var tempP;
	
	if(this.PageCount>1)
	{
		strFenyeBody='';
		strFenyeHead='';
		strFenyeEnd='';

		var strDivStar='<div  class="'+this.classname+'" align="right">';
		if(this.Index>this.PageCount)
		{
			this.Index=this.PageCount;
		}
		if(this.Index<1)
		{
			this.Index=1;
		}
		
		if(this.Index==1)
		{
			strFenyeHead='';	
		}
		else
		{
			tempP=this.Index-1;
			strFenyeHead='<a class="'+this.classname+'" title="转到第'+tempP+'页" href="'+this.strshowPage(tempP)+'"><b>上一页</b></a>&nbsp;&nbsp;';	
			
		}
		if(this.Index==this.PageCount)
		{
		
			strFenyeEnd='';
		}
		else
		{
			tempP=this.Index*1+1;
			strFenyeEnd+='&nbsp;<a class="'+this.classname+'" title="转到第'+tempP+'页" href="'+this.strshowPage(tempP)+'"><b>下一页</b></a><IMG height="9" src="images/web_950_10.jpg" width="5">';
			
		}		
		
		
		var strDivEnd='</div>';
		
		
		var strFenyCount='<font style="font-size: 12px;">'+this.Index+'</font>';
		strFenyCount+='/<font style="font-size: 12px;">'+this.PageCount+'</font>&nbsp;';
		
		strFenye=strDivStar+strFenyCount+strFenyeHead+strFenyeEnd+strDivEnd;
	}
	else
		strFenye="";
	
	return strFenye;
}


