function DBPageNavigator(parent){
	var pdiv,obj=document.createElement('div');//创建一个控制节点
	if(parent){pdiv=parent;}else pdiv=document.body;//获取父块
    pdiv.appendChild(obj);
	obj.pages;  //总页数
	obj.CurrentPos=1;//当前在哪页	
	obj.MaxRows=5;//每页显示多少条记录
	obj.SRecordCount=50;//总纪录数
	obj.fontsize=11;//字体大写
	obj.fontcolor=clBlack;//字体颜色
	obj.selectedcolor='red';//选择当前页面的字体颜色
	obj.disabledcolor='#DDDDDD';//
	obj.A=new Array();
	obj.Flag=0;//flag=-1 or flag==null时表示一页显示所有纪录
	obj.DataSet=null;	
	obj.HandleMessage=DBPN_handlemessage;	
	obj.Pagediv;//放页的块
	obj.SetfpTrue=DBPN_setfptrue;//设置第一页上一页不可选
	obj.SetfpFalse=DBPN_setfpfalse;//设置第一页上一页可选
	obj.SetnlTrue=DBPN_setnltrue;//设置下一页最后一页不可选
	obj.SetnlFalse=DBPN_setnlfalse;//设置下一页最后一页可选
	obj.CreateNavigator=DBPN_createnavigator;//生成上一页下一页
	obj.CreatePages=DBPN_createpages;//生成具体的页
	obj.Onclick=DBPN_selectpage;  	
	obj.Deletediv=DBPN_deletediv;//delete div
	obj.GetValue=DBPN_getvalue;	//从数据库中取纪录数
  if(isIE)
	obj.onpropertychange=DC_onpropertychange
  else
	addEventTimerListener(obj,DC_onpropertychange);
	obj.CreateNavigator();
    obj.oncontextmenu=div_oncontextmenu;
	obj.SetfpTrue();
	return obj;
}
function DBPN_onpropertychange()//属性变化处理
{
  var n=event.propertyName;
  switch(n){
	case 'DataSet':
	  if(this.OldDataSet)this.OldDataSet.RemoveLink(this);//从原来的DATASET中移除
      this.DataSet.LinkObj(this);
	  this.OldDataSet=this.DataSet;
	  break;
  }
}
function DBPN_createnavigator(){
	
	this.adiv=document.createElement('div');
	this.appendChild(this.adiv);
	var span;
	var space4='&nbsp;&nbsp;&nbsp;&nbsp';
	for(var i=1;i<=4;i++){
		this.A[i]=document.createElement('span');
		span=document.createElement('span');
		span.innerText=' ';
		this.A[i].name=i;
		this.A[i].style.cursor='pointer';
//		this.A[i].href='#';
		this.A[i].style.fontSize=this.fontsize;
		this.A[i].style.color=this.fontcolor;
		this.A[i].onclick=this.Onclick;
		this.A[i].setAttribute('parent',this);
		this.A[i].style.backgroundRepeat='no-repeat'; 
		setFont(this.A[i]);
		switch(i){
			case 1:this.A[i].innerHTML=space4;this.A[i].style.backgroundImage='url('+jcl_ResourceURL+'firstpage.gif)';break;
			case 2:this.A[i].innerHTML=space4;this.A[i].style.backgroundImage='url('+jcl_ResourceURL+'prevpage.gif)';break;
			case 3:this.A[i].innerHTML=space4;this.A[i].style.backgroundImage='url('+jcl_ResourceURL+'nextpage.gif)';break;
			case 4:this.A[i].innerHTML=space4;this.A[i].style.backgroundImage='url('+jcl_ResourceURL+'lastpage.gif)';break;
		}		
		this.adiv.appendChild(this.A[i]);
		this.adiv.appendChild(span);
	}	
	this.Pagediv=document.createElement('div');
	this.appendChild(this.Pagediv);
}

function DBPN_createpages(){	
	var span,left=0;
    this.numdiv=document.createElement('div');
    this.numdiv.style.position = 'relative';
	this.numdiv.style.overflow = 'auto';
	this.numdiv.style.left = 3;
	this.Pagediv.appendChild(this.numdiv);	
	if(this.MaxRows!=-1&&this.SRecordCount/this.MaxRows>1){ //如果maxrows为-1表示显示所有的纪录
		this.pages=Math.ceil(this.SRecordCount/this.MaxRows);
		for(var i=5;i<=this.pages+4;i++){
			this.A[i]=document.createElement('span');
			this.A[i].name=i;
			this.A[i].style.cursor='pointer';
//			this.A[i].href='#';
			this.A[i].style.fontSize=this.fontsize;
			this.A[i].style.color=this.fontcolor;
			this.A[i].onclick=this.Onclick;  //onclick事件
			this.A[i].setAttribute('parent',this);
			this.A[i].innerText=i-4;			
			span=document.createElement('span');
			span.innerHTML="&nbsp;";
			span.style.fontSize=9;
			this.numdiv.appendChild(this.A[i]);
			this.numdiv.appendChild(span);
		}
	}

}
function DBPN_setfptrue(){
	this.A[1].disabled=true;
	this.A[2].disabled=true;
	this.A[1].style.color=this.disabledcolor;
	this.A[2].style.color=this.disabledcolor;
	this.A[1].style.backgroundImage='url('+jcl_ResourceURL+'firstpage_disable.gif)';
	this.A[2].style.backgroundImage='url('+jcl_ResourceURL+'prevpage_disable.gif)';
}
function DBPN_setfpfalse(){
	this.A[1].disabled=false;
	this.A[2].disabled=false;
	this.A[1].style.color=this.fontcolor;
	this.A[2].style.color=this.fontcolor;
	this.A[1].style.backgroundImage='url('+jcl_ResourceURL+'firstpage.gif)';
	this.A[2].style.backgroundImage='url('+jcl_ResourceURL+'prevpage.gif)';
}
function DBPN_setnltrue(){
	this.A[3].disabled=true;
	this.A[4].disabled=true;
	this.A[3].style.color=this.disabledcolor;
	this.A[4].style.color=this.disabledcolor;
	this.A[3].style.backgroundImage='url('+jcl_ResourceURL+'nextpage_disable.gif)';
	this.A[4].style.backgroundImage='url('+jcl_ResourceURL+'lastpage_disable.gif)';
}
function DBPN_setnlfalse(){
	this.A[3].disabled=false;
	this.A[4].disabled=false;
	this.A[3].style.color=this.fontcolor;
	this.A[4].style.color=this.fontcolor;
	this.A[3].style.backgroundImage='url('+jcl_ResourceURL+'nextpage.gif)';
	this.A[4].style.backgroundImage='url('+jcl_ResourceURL+'lastpage.gif)';
}

function DBPN_selectpage(){
	var p=this.parent;
	if(!p)p=this;
	var sds=p.DataSet;
	if(!sds.Active)return;
	var pos=parseInt(this.name);	
	var cou=p.SRecordCount/p.MaxRows;
	switch(pos){
		case 1: if(p.CurrentPos!=1&&cou>1){
					if(p.CurrentPos==p.pages)
						p.SetnlFalse();
					p.CurrentPos=1;
					sds.GetPackage(0);	
					p.SetfpTrue();
					p.SetnlFalse();
					if(p.Flag!=null&&p.Flag!=-1)
						p.A[p.CurrentPos+4].style.color=p.selectedcolor;
				}
				break;
		case 2: if(p.CurrentPos!=1&&cou>1){
					if(p.CurrentPos==p.pages)
						p.SetnlFalse();
					p.CurrentPos--;//页数减一					
					sds.GetPackage((p.CurrentPos-1)*p.MaxRows);	
					if(p.CurrentPos==1)
						p.SetfpTrue();		
					if(p.Flag!=null&&p.Flag!=-1)
						p.A[p.CurrentPos+4].style.color=p.selectedcolor;
					}
				break;
		case 3: if(p.CurrentPos!=p.pages&&cou>1){
					if(p.CurrentPos==1)
						p.SetfpFalse();
					p.CurrentPos++;					
					sds.GetPackage((p.CurrentPos-1)*p.MaxRows);
					if(p.CurrentPos==p.pages)
						p.SetnlTrue();
					if(p.Flag!=null&&p.Flag!=-1)
						p.A[p.CurrentPos+4].style.color=p.selectedcolor;
				   }
				break;
		case 4: if(p.CurrentPos!=p.pages&&cou>1){		
					if(p.CurrentPos==1)
						p.SetfpFalse();
					p.CurrentPos=p.pages;
					sds.GetPackage((p.pages-1)*p.MaxRows);		
					p.SetnlTrue();
					p.SetfpFalse();
					if(p.Flag!=null&&p.Flag!=-1)
						p.A[p.CurrentPos+4].style.color=p.selectedcolor;
				}
				break;
	}
	if(pos>4){		//直接选择页的时候
		p.OldPos=p.CurrentPos; 		
		p.CurrentPos=pos-4;		
		sds.GetPackage((p.CurrentPos-1)*p.MaxRows);
		if(p.CurrentPos==1){
			p.SetfpTrue();
			p.SetnlFalse();
		}
		if(p.CurrentPos==p.pages){
			p.SetnlTrue();
			p.SetfpFalse();
		}
		if(p.CurrentPos!=1&&p.CurrentPos!=p.pages){
			p.SetfpFalse();
			p.SetnlFalse();
		}
		p.A[pos].style.color=p.selectedcolor;
	}	
}
function DBPN_handlemessage(sender,msg,recno){
		switch(msg){
			case 0://接受open消息
				this.GetValue();
				break;
			case 1:break;
			case 2:break;
			case 3:break;
			case 4:this.GetValue();break;
			case 5:this.GetValue();break;
			case 6:break;
			case 7:break;//关闭
			case 8:break;
			case 9:break;
		}	
}
function DBPN_getvalue(){   //取值
	this.Flag=this.DataSet.MaxRows;
	if(this.DataSet.MaxRows==null||this.DataSet.MaxRows==-1)
		this.MaxRows=this.DataSet.SRecordCount;
	this.MaxRows=this.DataSet.MaxRows;//alert('rows '+this.MaxRows);
	this.SRecordCount=this.DataSet.SRecordCount;//alert('re '+this.DataSet.SRecordCount);
	//this.SRecordCount=20;
	if(this.Flag==null||this.Flag==-1||this.SRecordCount/this.MaxRows<1){
		this.SetnlTrue();
	}
	if(this.Pagediv.childNodes.lenght!=0){  //判断是否是第一次调用
		this.Deletediv();			
	}
	this.CreatePages();
}
function DBPN_deletediv(){  //delete 页数
	var childno;
	while(this.Pagediv.childNodes.length!=0){
		childno=this.Pagediv.childNodes[0];
		this.Pagediv.removeChild(childno);
		//childno.removeNode(false);
	}
}