function BaseJavaScript(){

this.totalRow=0;			//记录总行数
this.totalPage=0;		//总页数
this.pageRow=20;		//每页显示行数 
this.currentPage=1;	//当前页数
this.largePageNo=1;//大页号
this.largePage=10;//大页包括小页的数量

this.rootXML=null;		//操作的XML
this.searchXML=null;					//地区的XML
this.resultXML=null;						//返回结果XML

this.listDivObj=null;		//显示记录的DIV
this.listXSL=null;			//显示记录的XSL

this.paramNode=null;	 //分页控制节点
this.navigationDivObj=null; //导航条
this.pageRowObj=null; //每页条数
this.totalRowObj=null; //总条数

this.CSID="Microsoft.XMLHTTP"; 
this.rowDelim=String.fromCharCode(1); //行分隔符
this.colDelim=String.fromCharCode(2);	//列分隔符

this.prevBtn=null;							//下一页按钮
this.nextBtn=null;							//上一页按钮
this.endBtn=null;							//下一页按钮
this.firstBtn=null;							//上一页按钮

this.selectRowNode=null;				//要修改的节点
this.cNode=null;								//增加,修改页面的节点
this.parentWin=null;						//修改页面的父窗口
this.schema=null;							//xsd,xsl文件的名称
this.layerPath="";
this.goPageObj=null;
this.selectCode="";
this.reqCode="";

this.showCDS=function(){					//将XML生成页面,填充到listDivObj中
	var temprow=Math.ceil(this.totalRow/this.pageRow);
	this.totalPage=(temprow==0)?1:temprow;
	if(this.currentPage>this.totalPage)this.currentPage=this.totalPage;
	if(this.paramNode!=null)this.paramNode.setAttribute("select","root/x[@id > "+(this.currentPage-1)*this.pageRow+" and @id <= "+this.currentPage*this.pageRow+"]");
	var content=this.rootXML.transformNode(this.listXSL.documentElement);
	content=content.replace(/&lt;sub&gt;/g,"<sub>");
	content=content.replace(/&lt;\/sub&gt;/g,"</sub>");
	content=content.replace(/&lt;sup&gt;/g,"<sup>");
	content=content.replace(/&lt;\/sup&gt;/g,"</sup>");
	this.listDivObj.innerHTML=content;
	if(this.navigationDivObj!=null)this.navigationDivObj.innerHTML="第"+this.currentPage+"/"+this.totalPage+"页";
	if(this.totalRowObj!=null)this.totalRowObj.innerText=this.totalRow;
	if(this.prevBtn!=null)this.judge();
	if(this.goPageObj!=null)this.formSelectOption(this.goPageObj,this.totalPage);
}

this.search=function(){	
	var node=this.searchXML.documentElement.selectSingleNode("largePageRow")
	if(node!=null)node.text=this.pageRow*this.largePage;
	node=this.searchXML.documentElement.selectSingleNode("largePageNo")
	if(node!=null)node.text=this.largePageNo;
	var xmlhttp=new ActiveXObject(this.CSID);
	xmlhttp.Open("POST",this.layerPath+"apparatus?reqCode="+this.selectCode,false);
	xmlhttp.Send(this.searchXML.xml);
//	this.rootXML.loadXML(xmlhttp.responseText);
	if(xmlhttp.responseXML.documentElement!=null)this.rootXML=xmlhttp.responseXML;
	else this.rootXML.loadXML(xmlhttp.responseText);
	this.totalRow=parseInt(this.rootXML.documentElement.getAttribute("count"));
}

this.searchAll=function(){	
	var xmlhttp=new ActiveXObject(this.CSID);
	xmlhttp.Open("POST",this.layerPath+"apparatus?reqCode="+this.selectCode,false);
	xmlhttp.Send(this.searchXML.xml);
	this.rootXML=xmlhttp.responseXML;
	this.totalRow=parseInt(this.rootXML.documentElement.getAttribute("count"));
}

this.searchNode=function(node,reqCode){	
	var xmlhttp=new ActiveXObject(this.CSID);
	xmlhttp.Open("POST",this.layerPath+"apparatus?reqCode="+reqCode,false);
	xmlhttp.Send(node.xml);
	return xmlhttp.responseXML;
}

this.execute=function(node){	
	if(node==null)node=this.cNode;
	var xmlhttp=new ActiveXObject(this.CSID);
	var src=this.layerPath+"apparatus?reqCode="+this.reqCode;
	xmlhttp.Open("POST",src,false);
	if(node!=null)xmlhttp.Send(node.xml);
	else xmlhttp.Send();
	this.resultXML=xmlhttp.responseXML.documentElement;
	this.resultStr=this.resultXML.selectSingleNode("content").text;
	return this.resultStr;
}

this.getRresultXML=function(node){	
	if(node==null)node=this.cNode;
	var xmlhttp=new ActiveXObject(this.CSID);
	var src=this.layerPath+"apparatus?reqCode="+this.reqCode;
	xmlhttp.Open("POST",src,false);
	if(node!=null)xmlhttp.Send(node.xml);
	else xmlhttp.Send();
	this.resultXML=xmlhttp.responseXML.documentElement;
	return this.resultXML;
}

this.judge=function(){									//判断上一个,下一个按钮是否disabled
	this.prevBtn.disabled="";
	this.prevBtn.className="boxback";
	this.nextBtn.disabled="";
	this.nextBtn.className="boxback";
	if(this.firstBtn!=null)
	{
		this.firstBtn.disabled="";
		this.firstBtn.className="boxback";
		this.endBtn.disabled="";
		this.endBtn.className="boxback";
	}
	if(this.currentPage==1)
	{
		this.prevBtn.disabled="true";
		this.prevBtn.className="boxdisabled";
		if(this.firstBtn!=null)
		{
			this.firstBtn.disabled="true";
			this.firstBtn.className="boxdisabled";
		}
	}
	if(this.currentPage==this.totalPage)
	{ 
		this.nextBtn.disabled="true";
		this.nextBtn.className="boxdisabled";
		if(this.endBtn!=null)
		{
			this.endBtn.disabled="true";
			this.endBtn.className="boxdisabled";
		}
	}
}

this.pagePrevCDS=function(){						//执行上一页功能
	if(this.currentPage > 1)	this.currentPage=this.currentPage-1;
	this.showPage();
}

this.pageNextCDS=function(){						//执行下一页功能
	if(this.currentPage < this.totalPage)	this.currentPage=this.currentPage+1;
	this.showPage();
}


this.resetID=function(resetNode){			//重新生成节点ID
	if(!resetNode) resetNode = this.rootXML.documentElement;
	var setNodes=resetNode.childNodes;
	for(var i=0;i<setNodes.length;i++)setNodes[i].setAttribute("id",i+1);
	return i;
}

this.createOption=function(obj,createXML){		//将createXML变成select框obj的option
	var createNodes=createXML.selectNodes("x");
	for(var i=0;i<createNodes.length;i++) {
		oOption= document.createElement("OPTION");
		oOption.text=createNodes[i].childNodes[1].text;
		oOption.value=createNodes[i].childNodes[0].text;
		obj.add(oOption);
		}
}

this.refreshCDS=function(){						//重新刷新页面
	this.rootXML.loadXML("<root/>");
	this.search();
	this.showCDS();
}

this.request=function(frm,fillNode){			//将frm中的值填充到cNode
	if(fillNode==null)fillNode=this.cNode;
	if(fillNode==null) return;
	var e=frm.all;
	for(var i=0;i<e.length;i++){
		if(typeof(e[i].ref)=="undefined") continue;
		var selectNode=null;
		if(fillNode.selectSingleNode(e[i].ref)==null)selectNode=fillNode.appendChild(this.rootXML.createElement(e[i].ref));
		else selectNode=fillNode.selectSingleNode(e[i].ref);

		if(e[i].type=="checkbox")selectNode.text=(e[i].checked)?1:0;
		else if(e[i].type=="radio")selectNode.text=(e[i].checked)?e[i].value:selectNode.text;
		else if(e[i].tagName=="SPAN"||e[i].tagName=="B"||e[i].tagName=="TD")selectNode.text=e[i].innerText
		else selectNode.text=e[i].value;
		if(e[i].tagName=="SELECT")selectNode.setAttribute("name",e[i].options(e[i].selectedIndex).text);
	}
}

this.populate=function(frm,fillNode){					//根据cNode向frm中填充数据
	if(fillNode==null)fillNode=this.cNode;
	if(fillNode==null) return;
	var e=frm.all;
	for(var i=0;i<e.length;i++) {
		if(typeof(e[i].ref)=="undefined") continue;
		if(e[i].tagName=="SPAN"||e[i].tagName=="B"||e[i].tagName=="TD") e[i].innerText=fillNode.selectSingleNode(e[i].ref).text
		else if (e[i].type=="checkbox") e[i].checked=(fillNode.selectSingleNode(e[i].ref).text==0)?false:true;
		else if (e[i].type=="radio") e[i].checked=(fillNode.selectSingleNode(e[i].ref).text==e[i].value)?true:false;
		else e[i].value=fillNode.selectSingleNode(e[i].ref).text;
	}
}

this.formSelectOption=function(obj,index){
	obj.innerText="";
	for(var i=1;i<=index;i++) {
		oOption= document.createElement("OPTION");
		oOption.text=i;
		oOption.value=i;
		obj.add(oOption);
		}
}

this.goPage=function(page){
	if(page==this.currentPage)return;
	this.currentPage=parseInt(page);
	if(this.currentPage < 1)this.currentPage=1;
	else if(this.currentPage>this.totalPage)this.currentPage=this.totalPage;
	this.showPage();
}

this.showPage=function(){
	if(Math.ceil(this.currentPage/this.largePage)!=this.largePageNo){
		this.largePageNo=Math.ceil(this.currentPage/this.largePage);
		this.search();
	}
	this.showCDS();
}

this.setScript=function(){
	if(event.ctrlKey){
		if(event.keyCode==80){
			var sel=document.selection.createRange()
			sel.text="<sup>"+sel.text+"</sup>";
			window.event.keyCode=0;
            window.event.returnValue=false;
		}
		else if(event.keyCode==66){
			var sel=document.selection.createRange()
			sel.text="<sub>"+sel.text+"</sub>";
			window.event.keyCode=0;
            window.event.returnValue=false;
		}
	}
}

}
