// 外部创建元素函数CreateElementFun  提供参数：显示内容的盒子,要显示的项目

//*********显示当前页数据类，参数说明****************
//dataSet------------------当前页数据列表
//url----------------------数据请示路径
//emptyFlag----------------返回数据是否为空
//pageSize-----------------分页大小，即每页多少条记录
//pages--------------------页数
//currentPage--------------当前页码
//elementNum---------------数据总数（共多少条记录）
//viewBox------------------数据显示区
//pageBox------------------页码显示区
//CreateElementFun---------数据处理函数

function pageObj(dataSet,emptyFlag,pageSize,pages,currentPage,elementNum,viewBox,pageBox,CreateElementFun,linkFun){	
	this.dataArray=dataSet;							//欲显示数据数组
	this.emptyFlag=emptyFlag						//是否为空
	this.viewBox=document.getElementById(viewBox);	//数据显示容器,盒子id
	this.pageBox=document.getElementById(pageBox);	//数据分页,盒子id
	this.nowPage=currentPage;			            //当前页码，默认为1
	this.pages=pages;								//页数
	this.pageSize=pageSize;							//分页大小						
	this.CreateElementFun=CreateElementFun; 		//创建显示元素,外部定义函数，基本li无素
	this.elementNum=elementNum;						//元素总数量
	this.emptyFlag=emptyFlag;						//空信息
	this.linkFun=linkFun;
	this.objInitialize();
		
}
pageObj.prototype={
	objInitialize:function(){	
		//this.saveCurrentObj();
		this.viewBox.innerHTML="";
		this.pageBox.innerHTML="";		
		this.viewBox.innerHTML="数据加载中....."
		this.setResponseData();
		//this.requestData(1);
		this.createPageControl();
	},	
	
	getValue:function(dataSet,itemName){
		var valueSet=dataSet.getElementsByTagName(itemName);
		return valueSet[0].childNodes[0].nodeValue;		
	},
	
	setResponseData:function(){
		var dataSet=this.dataArray;
		this.viewBox.innerHTML="";
		if(this.emptyFlag==1){
			this.viewBox.innerHTML="还没有相关数据。。。";
		}
		else{			
			for(var i=0;i<dataSet.length;i++){			
				this.CreateElementFun(this.viewBox,dataSet[i]);
			}						
		}
	},

	showPageAction:function(oEvent){		
		var pageObj=this.pageObj;
		var orderType=this.actionType;
		
		switch (orderType){			
			case "first":
				pageObj.nowPage=1;
				pageObj.nowPageInfo.innerHTML=pageObj.nowPage;				
				break;
			case "previous":
				pageObj.nowPage=pageObj.nowPage-1;
				if (pageObj.nowPage>=1){
					pageObj.nowPageInfo.innerHTML=pageObj.nowPage;
				}				
				break;	
			case "next":
				pageObj.nowPage=parseInt(pageObj.nowPage)+1;
				if (pageObj.nowPage<=pageObj.pages){
					pageObj.nowPageInfo.innerHTML=pageObj.nowPage;
				}								
				break;
			case "last":
				pageObj.nowPage=pageObj.pages
				pageObj.nowPageInfo.innerHTML=pageObj.nowPage;				
				break;
		}
		pageObj.linkFun(pageObj.nowPage,pageObj.pageSize);		
	},
	
	createPageControl:function(){
		var baseInfoBox=document.createElement("div");
		
		this.pagesInfo=document.createElement("span");	//总页数
		this.pagesInfo.innerHTML=this.pages;
		
		this.elementNumInfo=document.createElement("span");	//记录总条数
		this.elementNumInfo.innerHTML=this.elementNum;
		
		this.nowPageInfo=document.createElement("span");	//当前页
		this.nowPageInfo.innerHTML=this.nowPage;
		
		this.pageSizeInfo=document.createElement("span");	//分页大小
		this.pageSizeInfo.innerHTML=this.pageSize;
		
		var baseInfo1=document.createTextNode("共 ");		
		baseInfoBox.appendChild(baseInfo1);
		baseInfoBox.appendChild(this.pagesInfo);
											  
		var baseInfo2=document.createTextNode(" 页，共 ");		
		baseInfoBox.appendChild(baseInfo2);
		baseInfoBox.appendChild(this.elementNumInfo);
		
		var baseInfo3=document.createTextNode(" 条记录，每页 ");		
		baseInfoBox.appendChild(baseInfo3);
		baseInfoBox.appendChild(this.pageSizeInfo);
		
		var baseInfo4=document.createTextNode(" 条记录，当前第 ");		
		baseInfoBox.appendChild(baseInfo4);
		baseInfoBox.appendChild(this.nowPageInfo);		
		
		var baseInfo5=document.createTextNode(" 页");		
		baseInfoBox.appendChild(baseInfo5);
		
		this.pageBox.appendChild(baseInfoBox);
		
		var theFirstItem=document.createElement("div");
		var theFirstWord=document.createTextNode("第一页");
		theFirstItem.appendChild(theFirstWord);
		theFirstItem.style.cursor="pointer";
		theFirstItem.pageObj=this;
		theFirstItem.actionType="first";
		theFirstItem.onclick=this.showPageAction;
		this.pageBox.appendChild(theFirstItem);
		
		var thePreviousItem=document.createElement("div");
		var thePreviousWord=document.createTextNode("上一页");
		thePreviousItem.appendChild(thePreviousWord);
		thePreviousItem.style.cursor="pointer";
		thePreviousItem.pageObj=this;
		thePreviousItem.actionType="previous";
		thePreviousItem.onclick=this.showPageAction;
		this.pageBox.appendChild(thePreviousItem);
		
		var theNextItem=document.createElement("div");
		var theNextWord=document.createTextNode("下一页");
		theNextItem.appendChild(theNextWord);
		theNextItem.style.cursor="pointer";
		theNextItem.pageObj=this;
		theNextItem.actionType="next";
		theNextItem.onclick=this.showPageAction;
		this.pageBox.appendChild(theNextItem);
		
		var theLastItem=document.createElement("div");
		var theLastWord=document.createTextNode("最后一页");
		theLastItem.appendChild(theLastWord);
		theLastItem.style.cursor="pointer";
		theLastItem.pageObj=this;
		theLastItem.actionType="last";
		theLastItem.onclick=this.showPageAction;
		this.pageBox.appendChild(theLastItem);		
	},
	getFilterStyle:function(){
		var rNum=Math.floor(Math.random()*4);	
		switch (rNum){
			case (0):			
				return("progid:DXImageTransform.Microsoft.Fade();");
				break;
			case (1):
				return("progid:DXImageTransform.Microsoft.RandomBars();");
				break;
			case (2):
				return("progid:DXImageTransform.Microsoft.Spiral();");			
				break;
			case (3):
				return("progid:DXImageTransform.Microsoft.Pixelate (enabled='false');");
				break;		
		}	
	}
}