if(typeof($)=="undefined"){$=function(element) {return document.getElementById(element);}}
if(typeof(Function.prototype.bindAsEventListener)=="undefined"){
Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.call(object, event || window.event);
  }
}
}
function initRequest(){
	var req = null;try{
		req = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e){
		try{
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc){
			req = null;
		}
	}
	if (!req && typeof XMLHttpRequest != "undefined"){
		try{
			req = new XMLHttpRequest();
		}
		catch(fa){
			req = null;
		}
	}
	return req;
}
function fetchUrl(sUrl,sDiv){
	var objReq=initRequest();
	var objDiv=$(sDiv);
	if (null!=objReq){
		objReq.onreadystatechange = function (){
			if (objReq.readyState == 4 && objReq.responseText){
				if(typeof(objDiv)!="undefined")objDiv.innerHTML=objReq.responseText;
				return objReq.responseText;
			}
		};
		objReq.open("GET", sUrl, true);
        objReq.send(null);
	}
}
Pager=function(name,curP,totP,ajaxurl,div,cDiv){
	this._pages=Array();
	this._cP=parseInt(curP)<1?"1":parseInt(curP);
	this._tP=parseInt(totP)<=0?"0":parseInt(totP);
	this._au=ajaxurl;
	this._uDiv=div;
	this._cDiv=cDiv;
	this._name=name;
}
Pager.prototype.init=function(){
	if(this._tP==0)return false;
	cDiv=$(this._cDiv);
	if(!cDiv) return false;
	cDiv.innerHTML="";
	if(this._cP>1){_p=this._createPage(1,"|&lt;",i==this._cP);
	cDiv.appendChild(_p);}
	if(this._cP-1>=1){_p=this._createPage(this._cP-1,"&lt;&lt;",i==this._cP);
	cDiv.appendChild(_p);}
	for(i=1;i<=this._tP;i++){
		_p=this._createPage(i,i,i==this._cP);
		cDiv.appendChild(_p);
		this._pages[this._pages.length]=_p;
	}
	if(this._cP<this._tP){
		_p=this._createPage(this._cP+1,"&gt;&gt;",i==this._cP);
		cDiv.appendChild(_p);
	}
	if(this._cP<this._tP){
		_p=this._createPage(this._tP,"&gt;|",i==this._cP);
		cDiv.appendChild(_p);
	}

}
Pager.prototype._createPage=function(ip,text,isc){
	objA=document.createElement("span");
	objA.setAttribute("_page",ip);
	objA.style.display="inline";
	objA.style.styleFloat="left";
	objA.innerHTML=text;
	return this._setPage(objA,isc);
}
Pager.prototype._setPage=function(p,isc){
	if(isc){
		p.setAttribute("title","当前为第"+p.getAttribute("_page")+"页");
		p.onclick=null;
		p.className="curItem";
	}
	else{
		p.className="pageItem";
		p.setAttribute("title","转到第"+p.getAttribute("_page")+"页");
		p.onclick=this.handler.bindAsEventListener(this);
	}
	return p;
}
Pager.prototype.handler=function (evt){
		var elm = evt.srcElement? evt.srcElement : evt.target;
		this.visit(elm.getAttribute("_page"));
}
Pager.prototype.visit=function(iPage){
	this._cP=parseInt(iPage);
	this.init();
	sUrl=this._au.indexOf("?")!=-1?this._au+"&":this._au+"?";
	sUrl+="p="+this._cP;
	$(this._uDiv).innerHTML="页面载入中..."
	fetchUrl(sUrl,this._uDiv);


	
}