//var pageArgs={};
//pageArgs=getparameters("/B2C/modules/common/language/"+language+"/page_js.xml",pageArgs)




function PageList(divID,count, per){
	this.total 		= count;
	this.totalPage	= 0;						//???
	this.per   		= per == null ? 5 : per;	//?????????
	this.currPage 	= 0;						//????
	this.currCount 	= 0;    					//??????
	this.start		= 0;						//????
	this.end		= 0;						//????
	this.divID		= divID;					//??
	this.xmlDom 	;
	this.xslDoc		;
	
	if(typeof window.ActiveXObject != 'undefined'){
		
		this.xmlDom=new ActiveXObject("Microsoft.XMLDom");
		this.xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
		this.xsltTemp 	= new ActiveXObject("Msxml2.XSLTemplate");
	}else{
		this.xmlDom=document.implementation.createDocument("","",null);
		this.xslDoc=document.implementation.createDocument("","",null);
		this.xsltProcessor = new XSLTProcessor();
	}
	
	this.selectID	= null;
	this.searchtype = "1";
	
	this.isLast		= isLast;					//???????,??true, ????false
	this.isFirst	= isFirst;					//??????,??true, ????false
	this.setStart 	= setStart;
	this.setEnd		= setEnd;
	
	this.goNext		= goNext;					//???????
	this.goBack		= goBack;					//???????
	this.goToPage	= goToPage;					//??????
	this.renderList = renderList;
	this.init		= init;						//???
	
	this.getPageCount = getPageCount;			//?????
	this.getCurrCount = getCurrCount;
	this.setCurrPage  = setCurrPage;			//??????
	this.getInstance  = getInstance;			//????
	this.setInput	  = setInput;
	this.setRender	  = setRender;
	this.getparameters=	getparameters;
	
	this.args		=	{}						//??xsl???

	this.type = type;
	
	
	function type(type){
		this.searchtype = type;	
	}
	
	function isLast(){
		return (this.totalPage == this.currPage);
	}
	
	function isFirst(){
		return (this.currPage == 1)
	}
	
	function getPageCount(){
		if(this.total != 0)
			this.totalPage = Math.ceil(this.total/this.per);
		else 
			this.totalPage = 0;
		return this.totalPage;
	}
	
	function getCurrCount(){
		if(this.total == 0){
			this.currCount = 0;
		}else if(this.isLast()){
			this.currCount = this.total%this.per;
			if (this.currCount==0){
				this.currCount=this.per;
			}
		}
		else{ 
			this.currCount = this.per;
		}
		return this.currCount;
	}
	//count: ??
	function setStart(count){
		this.start = count == 0 ? 0 : ((count -1)*this.per + 1);
	}
	
	function setEnd(count){
		if(this.currPage == this.getPageCount())
			this.end = this.total;
		else
			this.end = (count)*this.per;
	}
	
	function setCurrPage(num){
		if(num >= this.totalPage)
			this.currPage = this.totalPage;
		else
			this.currPage = num;
	}
	
	function setInput(xmlDom){
		this.xmlDom = xmlDom;
	}
	
	function setRender(url){
		try{
			var xmlhttp_xsl = new ActiveXObject("Microsoft.XMLHTTP");
			xmlhttp_xsl.open("GET",url,false);
			xmlhttp_xsl.send();
			
			this.xslDoc.async = false;
			this.xslDoc.resolveExternals = false;
			this.xslDoc.loadXML(xmlhttp_xsl.responseXML.xml);
			
			xmlhttp_xsl = null;
		}catch(e){
			throw new Error("加载渲染文件时发生错误:" + e.message);
		}
		
		if (this.xslDoc.parseError.errorCode != 0) {
			this.divID.innerHTML ="初始化失败，服务器找不到xslt文件或其格式不正确......";
			throw Exception;
		}
		this.xsltTemp.stylesheet = this.xslDoc;
	}
	
	this.setRenderForFF = function(url){
		try{
			//var xmlhttp_xsl = new ActiveXObject("Microsoft.XMLHTTP");
			//xmlhttp_xsl.open("GET",url,false);
			//xmlhttp_xsl.send();
			
			this.xslDoc.async = false;
			//this.xslDoc.resolveExternals = false;
			this.xslDoc.load(url);  
			//xmlhttp_xsl = null;
   			this.xsltProcessor.importStylesheet(this.xslDoc);
    		//var result = xsltProcessor.transformToDocument(flightPricedom);
    	
		}catch(e){
			throw new Error("加载渲染文件时发生错误:" + e.message);
		}
		
		//if (this.xslDoc.parseError.errorCode != 0) {
		//	this.divID.innerHTML =pageArgs["initFail"];
		//	throw Exception;
		//}
		//this.xsltTemp.stylesheet = this.xslDoc;
	}	
	function init(xmlDom,url){
		var count = this.getPageCount();
		if(count != 0)
			this.setCurrPage(1);
		else
			this.setCurrPage(0);
		this.setInput(xmlDom);
		if(typeof window.ActiveXObject != 'undefined'){
			this.setRender(url);
		}else{
			this.setRenderForFF(url);
		}		
	}
	
	function getInstance(){
		return this;
	}
	
	function goNext(){
		if(this.isLast()) return;
		var newPage = this.currPage*1 + 1;
		this.setCurrPage(newPage);
		this.setStart(newPage);
		this.setEnd(newPage);
		this.renderList(this.getInstance());
	}
	
	function goBack(){
		if(this.isFirst()) return;
		var newPage = this.currPage - 1;
		this.setCurrPage(newPage);
		this.setStart(newPage);
		this.setEnd(newPage);
		this.renderList(this.getInstance());
	}
	
	function goToPage(num){
		if(num<1 || num > this.totalPage) return;
		this.setCurrPage(num);
		this.setStart(num);
		this.setEnd(num);
		this.renderList(this.getInstance());
	}
	
	function renderList(page){
		if(typeof window.ActiveXObject != 'undefined'){
			
			page.setStart(page.currPage);
			page.setEnd(page.currPage);
			var xslProc = page.xsltTemp.createProcessor();
			xslProc.input = page.xmlDom;
			
			//???
			for(var name in this.args){
					xslProc.addParameter(name,this.args[name]);
				}
			
			xslProc.addParameter("currentPage",page.currPage);
			xslProc.addParameter("currentPageCount",page.getCurrCount());
			xslProc.addParameter("totalPage", page.getPageCount());
			xslProc.addParameter("start", page.start);
			xslProc.addParameter("end", page.end);
			xslProc.addParameter("per", page.per);
			if(page.searchtype=="0")
				xslProc.addParameter("type", page.searchtype);
			xslProc.transform();
			page.divID.innerHTML = xslProc.output;
		}else{
		
			page.setStart(page.currPage);
			page.setEnd(page.currPage);
			
			//var xslProc = page.xsltTemp.createProcessor();
			//xslProc.input = page.xmlDom;
			
			//???
		/*
			for(var name in this.args){
			alert("aaa1");
					this.xsltProcessor.setParameter(null,name,this.args[name]);
			alert("aaa2");
				}
				//*/
				
			this.xsltProcessor.setParameter(null,"currentPage",page.currPage);
			this.xsltProcessor.setParameter(null,"currentPageCount",page.getCurrCount());
			this.xsltProcessor.setParameter(null,"totalPage", page.getPageCount());
			this.xsltProcessor.setParameter(null,"start", page.start);
			this.xsltProcessor.setParameter(null,"end", page.end);
			this.xsltProcessor.setParameter(null,"per", page.per);
			if(page.searchtype=="0")
				this.xsltProcessor.setParameter(null,"type", page.searchtype);
			var result=this.xsltProcessor.transformToDocument(page.xmlDom);
			
			
			var xmls = new XMLSerializer();  
			
	    	page.divID.innerHTML = xmls.serializeToString(result,"text/html");
			//xslProc.transform();
			//page.divID.innerHTML = xslProc.output;
		}
	}
	
	function getparameters(urlXml)			//???this.args
	{
		try{
				var Xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				var dom=new ActiveXObject("Msxml2.DOMDOCUMENT");
				Xmlhttp.open("GET",urlXml,false);
				Xmlhttp.setRequestHeader("Content-Type","text/xml");
				Xmlhttp.send();
				dom.loadXML(Xmlhttp.responseText);
				var names = dom.selectNodes("/CONFIG/PARAMETER/NAME");
				var values = dom.selectNodes("/CONFIG/PARAMETER/VALUE");
				for(var i=0; i<names.length; i++)
				{
					this.args[names.item(i).text] = values.item(i).text;
				}
			} catch(e)
			{
				alert(e.description);
			}
}

	
}

