﻿var insertclear=true;//新增后是否需要进行界面清空
var firstneedrefreshgrid=false;//第一次新增时需要清空底部表格后再新增
var recordperpageset=15;
//function document.oncontextmenu() { return false; }
var zindexcount = 1000;
var fieldsetterisshow=false;
var maincreatewindowmodel=0;//从main页面中edit窗体时的模式
function GetIEVersion()
{
	var browser=navigator.appName 
	var b_version=navigator.appVersion 
	var version=b_version.split(";"); 
	var trim_Version=version[1].replace(/[ ]/g,""); 
	if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") 
	{ 
		//alert("IE6"); 
		return 6;
	} 
	else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0") 
	{ 
		//alert("IE7"); 
		return 7;
	} 
	else
	{
		return 8;
	}
}
var IEVS=GetIEVersion();
/*@cc_on
	@set @inuser=true;//false;//
	@set @showerrdetail=false;//true;//
@*/
function GetIEVersion()
{
	var browser=navigator.appName 
	var b_version=navigator.appVersion 
	var version=b_version.split(";"); 
	var trim_Version=version[1].replace(/[ ]/g,""); 
	if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") 
	{ 
		//alert("IE6"); 
		return 6;
	} 
	else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0") 
	{ 
		//alert("IE7"); 
		return 7;
	} 
	else
	{
		return 7;
	}
}
var IEVS=GetIEVersion();
function wait() { }
function showfieldsetter()
{
	if(!fieldsetterisshow)upfieldsetter();
}
function hidefieldsetter()
{
	for(var r=0;r<cxtjszsetter.length;r++)
	{
		cxtjszsetter[r].style.display="none";
		cxtjszsetter[r].style.height="0px";
	}
	fieldsetterisshow=false;
}
function upfieldsetter()
{
	for(var r=0;r<cxtjszsetter.length;r++)
	{
		cxtjszsetter[r].style.display="inline";
		cxtjszsetter[r].style.height=(parseInt(cxtjszsetter[r].style.height)+100).toString()+"px";
	}
	fieldsetterisshow=true;
}
String.prototype.lenB   =   function()//调用时需要加括号
{
	return   this.replace(/[^\x00-\xff]/g,"**").length;
}
function outerwrite(S)
{
	document.write(S);
}
//███████████████████████████████████████████████████████████████████████
//setTimeout(查询2,1,sqls)
var _st = window.setTimeout;
window.setTimeout = function(fRef, mDelay) 
{
	 if(typeof fRef == 'function')
	 {
		  var argu = Array.prototype.slice.call(arguments,2);
		  var f = (function(){ fRef.apply(null, argu); });
		  return _st(f, mDelay);
	 }
	 return _st(fRef,mDelay);
}
//url中有些是特殊字符,当向服务器传递这些值的时候,需要替换,否则服务器会得到错误的值
function urlspecialreplace(url)
{
	var rval=url;
	rval=rval.replace(/\%/g,"%25");
	rval=rval.replace(/\+/g,"%2B");
	rval=rval.replace(/\ /g,"%20");
	rval=rval.replace(/\//g,"%2F");
	rval=rval.replace(/\?/g,"%3F");
	rval=rval.replace(/\#/g,"%23");
	rval=rval.replace(/\&/g,"%26");
	rval=rval.replace(/\=/g,"%3D");
	return rval;
}
//███████████████████████████████████████████████████████████████████████
//GetQueryValue(document.location.search,'xzy')
//对参数不区分大小写,但返回值是原始的大小写
function GetQueryValue(urls, segs)
{
    var urlStr = urls;
    var segStrs = segs;
    var vStr = "";
    var segStr = "";

    if (urlStr == null || urlStr == "" || segStrs == null || segStrs == "") return vStr;

    urlStr = urlStr.toLowerCase();
    segStrs = segStrs.toLowerCase();

    segStr = segStrs;
    segStr += "=";
    segStr = "?" + segStr;
    var itmp;
    itmp = urlStr.indexOf(segStr); //&id=10

    if (itmp < 0)
    {
        segStr = segStrs;
        segStr += "=";
        segStr = "&" + segStr;
        itmp = urlStr.indexOf(segStr);

    }
    if (itmp < 0) { return vStr; }

    //urlStr = urlStr.substr(itmp + segStr.length);//返回值全部是小写的
    urlStr = urls.substr(itmp + segStr.length); //返回值是原始大小写的.
    itmp = urlStr.indexOf("&");
    if (itmp < 0)
    {
        //return urlStr.replace(/%20/g, "").replace(/ /g, "").replace(/\'/g, "").replace(/\"/g, "");//后来有个参数要传递',所以把'的替换弃掉了
		return urlStr.replace(/%20/g, "").replace(/ /g, "").replace(/\"/g, "");
    }
    else
    {
        urlStr = urlStr.substr(0, itmp);
        return urlStr.replace(/%20/g, "").replace(/ /g, "").replace(/\"/g, "");
    }
}
//对参数区分大小写
function GetQueryValueDXX(sorStr,panStrs)
{
	
	var vStr="";
	var panStr="";
	
	if (sorStr==null || sorStr=="" || panStrs==null || panStrs=="") return vStr;

	//sorStr = sorStr.toLowerCase();
	//panStrs=panStrs.toLowerCase();
	
	panStr=panStrs;
	panStr += "=";
	panStr="?"+panStr;
	var itmp;
	itmp=sorStr.indexOf(panStr);//&id=10

	if(itmp<0)
	{
		panStr=panStrs;
		panStr += "=";
		panStr="&"+panStr;
		itmp=sorStr.indexOf(panStr);
				
	}
	if (itmp<0){return vStr;}
	

	sorStr = sorStr.substr(itmp + panStr.length);
	itmp=sorStr.indexOf("&");
	if (itmp<0)
	{
		return sorStr.replace(/%20/g,"").replace(/ /g,"").replace(/\"/g,"");
	}
	else
    {
		sorStr=sorStr.substr(0,itmp);
		return sorStr.replace(/%20/g,"").replace(/ /g,"").replace(/\"/g,"");
	}
}
function setfocus(obj)
{
	try{obj.focus();}catch(ex){;}
}
//███████████████████████████████████████████████████████████████████████
//获取当前网页的文件名
//如http://127.0.0.1/lhjc\test.htm?dd 则返回 test.htm
//测试样例:http://127.0.0.1/lhjc\test.htm?dd->test.htm
//         http://127.0.0.1/lhjc\test.htm?id=1&back=cctv.htm->test.htm
function GetPageName()
{
	var fn=location.href+"?";
	var wn=fn.indexOf("?");
	fn=fn.substring(0,wn);
	var rval=fn.replace(/^.+\/(.+)$/,'$1');
	
	fn=rval+"#";//处理锚点
	wn=fn.indexOf("#");
	fn=fn.substring(0,wn);
	rval=fn.replace(/^.+\/(.+)$/,'$1');
	
	return rval
}
//这个函数不是很可靠,对于http://127.0.0.1/lhjc/a.htm/a.htm就会出错
function GetUrlPath()//获取当前页面的路径,如:http://127.0.0.1/lhjc/jst_main.htm,返回http://127.0.0.1/lhjc/
{
	var fn=location.href+"?";
	var pagename=GetPageName();
	var ini=fn.indexOf(pagename);
	var rval="";
	if(ini>-1)
	{
		rval=(fn.substring(0,ini));
	}
	return rval;
}

//███████████████████████████████████████████████████████████████████████
function IsNumber(num)
{
	if(isNaN(Number((num))))
    {
        return false;   			
    }	
	else
	{
		if(num+""=="")return false;
		return true;
	}
}
//███████████████████████████████████████████████████████████████████████
//四舍五入,//最多支持6位小数的四舍五入
function MyRound(numberRound,roundDigit){
var sOffsetPara = 1000000 ;
return parseFloat(parseFloat(numberRound*sOffsetPara).toFixed(roundDigit)/sOffsetPara).toFixed(roundDigit) * 1.0;
}
//███████████████████████████████████████████████████████████████████████
function MyVal(num)
{
	if(isNaN(Number((num))))
    {
        return 0;   			
    }
	return Number((num));
}

//███████████████████████████████████████████████████████████████████████
//返回重复len次的c串
//如 alert(Space("c",5)); 返回 ccccc
function Space(c,len)
{
	var i;
	var rval;
	rval="";
	for(i=0;i<len;i++)
	{
		rval=rval+c;
	}
	return rval;
}
//███████████████████████████████████████████████████████████████████████
//去掉首尾的空格
function trim(str)
{
	return str.replace(/^\s*/,'').replace(/\s*$/,'');
}
function String.prototype.trim(){return this.replace(/(^\s*)|(\s*$)/g,"");}
//███████████████████████████████████████████████████████████████████████
//从xml的节点node,按照名称tagName获取该节点下的某个子节点的text,
function GetItemVal(node,tagName)
{
	//alert(Row.childNodes[0].tagName);
	//alert(node.childNodes.length);
	var i;
	for(i=0;i<node.childNodes.length;i++)
	{
		if(node.childNodes[i].tagName.toUpperCase()==tagName.toUpperCase())
		{
			return node.childNodes[i].text;
			break;
		}
	}
	if(i==node.childNodes.length)
	{
		throw("GetItemVal()★不存在["+tagName+"]的节点★");
	}
}
function recordset()
{
    this.callback = null;
    
	this.postpage=null;//向哪个页面提交,默认是本页
	this.type=null;//提交的action,不能为空
	this.columncount=0;//只读,反映结果集中有多少个列
	this.recordcount=0;//只读,反映结果集中有多少行数据
	this.resulttype=0;//0:把返回值写入到数组中 1:仅返回xml结果,不把xml编成数组,这种情况下open后没有rows,直接就返回了xml结果集
	
	//分页时,查询语句需要有一个不重复的排序列
	this.recordperpage=null;//每页显示的数据量,默认null表示不分页
	this.pageno=1;//显示的是第几页,默认是第一页
	this.pagecount=null;//只读,总共有多少页
    this.allpagerecordcount=null;//只读,总共有多少行数据(指不分页的情况下)
    this.tag=null;//当读取分页数据集的时候,能够获取服务器传回的tag,这个tag目前只支持从服务器发回,不支持向服务器发送
    
	this.errors="";
	
	var colarr=new Array();//存储列的名称,都是大写的,colarr[0]="姓名NAME",colarr[1]="性别GENTAL"......
	var coltypearr=new Array();//存储列的类型 C表示字符,N表示数字
	var rowarr=new Array();//存储结果集的二维数组
	var nametoimap={};//存储每个列的名字和列序号的对应关系
	this.close=function()//关闭,主要清理的数据,其他的还都保留着
	{
	    colarr.splice(0,100000000);
	    rowarr.splice(0,100000000);
	    coltypearr.splice(0,100000000);
	    nametoimap={};
		delete colarr;
		delete rowarr;
		delete coltypearr;
		delete nametoimap;
		this.columncount=0;
		this.recordcount=0;
		CollectGarbage();
	}
	//读取结果并设置各种值
	this.open = function()
	{
	    //alert(sqls);
	    //rowarr[0]=new Array(5);
	    //rowarr[1]=new Array(5);
	    var objDom;
	    var objRoot;
	    var objNode;
	    var objNodeValue;
	    var xmlsql;
		var colname;
	    this.errors = "";
	    this.columncount = 0;
	    this.recordcount = 0;
	    //objDom = new ActiveXObject("Microsoft.XMLDOM");
	    objDom = new ActiveXObject("Msxml2.DOMDocument");
	    objDom.async = false;
	    objDom.preserveWhiteSpace = true;
	    objRoot = objDom.createElement("root");
	    objDom.appendChild(objRoot); //添加根节点

	    objNode = objDom.createElement("params"); 
		var inputs;
	    if (arguments.length == 0)
	    {
	        inputs = new Array();
	        inputs[0] = "";
	    }
	    else if (arguments.length == 1)
	    {
	        //如果只有1个参数,那么判断这个参数是否为数组,函数支持数组为参数,这个数组把arguments代替了
	        //支持这么调用:rs.open(new Array("1\r\n'你好\\","2","3","4","5"));
			if (Object.prototype.toString.apply(arguments[0]).toLowerCase()=="[object array]")
	        {//是数组
	            inputs = arguments[0];
	        }
			else
			{
				inputs = new Array();
				inputs[0] = arguments[0];
			}
	    }
		else
		{//普通方式调用的,rs.open("a","b","c");
			inputs=new Array();
			for(var i=0;i<arguments.length;i++)
				inputs[i]=arguments[i];
		}
		//到这里inputs肯定是一个数组了.
	    for (colname in inputs)
	    {
	        inputs[colname] = inputs[colname].toString(); //转为字符串
			if(IsNumber(colname.toString().substring(0,1)))
				objNodeValue = objDom.createElement("para" + colname);
			else
				objNodeValue = objDom.createElement(colname);
			objNodeValue.text = inputs[colname];
	        
	        objNode.appendChild(objNodeValue);
	    }

	    objRoot.appendChild(objNode);

	    if (this.recordperpage != null)//有分页设置
	    {
	        objNode = objDom.createElement("pagesplit");

	        objNodeValue = objDom.createElement("recordperpage");
	        objNodeValue.text = this.recordperpage;
	        objNode.appendChild(objNodeValue);

	        objNodeValue = objDom.createElement("pageno");
	        objNodeValue.text = this.pageno;
	        objNode.appendChild(objNodeValue);

	        objRoot.appendChild(objNode);
	    }
	    xmlsql = objDom.xml;
	    if (this.postpage == null)
	    {
	        this.postpage = GetPageName();
	    }
	    //------------------------------------
	    //var oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    var oXmlHttp;
	    if (window.ActiveXObject)
	    {
	        try
	        {
	            oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	        }
	        catch (ex)
	        {
	            try
	            {
	                oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	            }
	            catch (ex)
	            {
	                var s = "recordset创建XMLHTTP失败:" + (ex.message == null ? ex : ex.message);
	                errmsg(s, 16, s)
	            }
	        }
	    }
	    else if (window.XMLHttpRequest)
	    {
	        oXmlHttp = new XMLHttpRequest();
	    }
	    //-----------------------------------
	    var tarurl;
	    var urlpara = location.search;

	    if (urlpara.indexOf("?") > -1)
	        urlpara = urlpara + "&xmlaction=" + this.type;
	    else
	        urlpara = "?xmlaction=" + this.type;

	    if (urlpara.lenB() != urlpara.length) urlpara = escape(urlpara);

	    urlpara = urlpara.replace(/%3F/g, "?").replace(/%26/g, "&").replace(/%3D/g, "=").replace(/%3A/g, ":");

	    tarurl = this.postpage + urlpara;
	    oXmlHttp.Open("POST", tarurl, this.callback == null ? false : true);
	    oXmlHttp.setRequestHeader("Content-Type", "text/xml")
	    oXmlHttp.Send(xmlsql);
	    //alert(oXmlHttp.responseText.substring(0, 100));
	    this.oXmlHttp = oXmlHttp;
	    if (this.callback == null)//同步调用
	    {
	        this.anarval();
	    }
	    else//异步调用
	    {
	        var rsfunctioncallback = function()
	        {
	            try
	            {
	                if (rsfunctioncallback.rsobject.oXmlHttp.readyState == 4)
	                {
	                    if (rsfunctioncallback.rsobject.oXmlHttp.status == 200)
	                    {
	                        rsfunctioncallback.rsobject.anarval();
	                        rsfunctioncallback.rsobject.callback(rsfunctioncallback.rsobject);
	                    }
	                }
	            }
	            catch (ex)
	            {
	                wait("closeall");
	                var s = "rsfunctioncallback:" + (ex.message == null ? ex : ex.message);
	                errmsg(s, 16, "意外错误!")
	            }
	        };
	        rsfunctioncallback.rsobject = this;
	        oXmlHttp.onreadystatechange = rsfunctioncallback;
	    }
	    delete objDom;
	    delete Xsldom
	    CollectGarbage();
	}
	this.anarval = function()
	{
	    var Xsldom = new ActiveXObject("Msxml2.DOMDocument");
	    Xsldom.async = false;
	    Xsldom.loadXML(this.oXmlHttp.responseText); //得到返回的xml结果
	    //alert(this.oXmlHttp.responseText);
	    var s = this.oXmlHttp.responseText.substring(7, 17);
	    if (s == "launchpage")
	    {
	        s = "登录信息已丢失,请重新登录,请重新登录";
	        alert(s);
	        throw s;
	    }
	    //3.解析xml并存储到数组中
	    var Table, row, col, n, i;

	    if (Xsldom.documentElement.tagName == "NewDataSet")//是正常返回的数据
	    {
	        if (this.resulttype == 1)
	        {
	            return this.oXmlHttp.responseText;
	        }
	        //Table=Xsldom.documentElement.childNodes;
	        Table = Xsldom.documentElement.selectNodes("//NewDataSet/cols"); //表的列名称
	        for (i = 0; i < Table.length; i++)
	        {
	            Row = Table.item(i);
	            Col = Row.childNodes;
	            this.columncount = Col.length;
	            for (n = 0; n < this.columncount; n++)
	            {
	                colarr[n] = Col.item(n).text.toUpperCase();
	                nametoimap[colarr[n]] = n; //从名字到列序号的反向映射
	            }
	        }
	        Table = Xsldom.documentElement.selectNodes("//NewDataSet/coltype"); //表的列类型
	        for (i = 0; i < Table.length; i++)
	        {
	            Row = Table.item(i);
	            Col = Row.childNodes;
	            for (n = 0; n < this.columncount; n++)
	            {
	                coltypearr[n] = Col.item(n).text;
	            }
	        }
	        Table = Xsldom.documentElement.selectNodes("//NewDataSet/pageset"); //分页结果
	        for (i = 0; i < Table.length; i++)
	        {
	            Row = Table.item(i);
	            Col = Row.childNodes;
	            for (n = 0; n < Col.length; n++)
	            {
	                if (Col.item(n).nodeName == "recordperpage") this.recordperpage = Col.item(n).text * 1;
	                if (Col.item(n).nodeName == "pageno") this.pageno = Col.item(n).text * 1;
	                if (Col.item(n).nodeName == "pagecount") this.pagecount = Col.item(n).text * 1;
	                if (Col.item(n).nodeName == "allpagerecordcount") this.allpagerecordcount = Col.item(n).text * 1;
	                if (Col.item(n).nodeName == "tag") this.tag = Col.item(n).text;
	            }
	        }
	        Table = Xsldom.documentElement.selectNodes("//NewDataSet/r"); //表的行数据
	        this.recordcount = Table.length;
	        for (i = 0; i < Table.length; i++)
	        {
	            Row = Table.item(i);
	            Col = Row.childNodes;
	            rowarr[i] = new Array(Col.length);
	            for (n = 0; n < Col.length; n++)
	            {
	                if (coltypearr[n] == "N")
	                {
	                    rowarr[i][n] = Col.item(n).text;
	                    if (rowarr[i][n] != "")
	                        rowarr[i][n] = MyVal(rowarr[i][n]); //去掉数字后面的.0000之类的东西
	                }
	                else
	                    rowarr[i][n] = Col.item(n).text;
	            }
	        }
	        //alert(this.recordcount);
	        //alert(rowarr[3][1]);
	        delete this.oXmlHttp;
	    }
	    else if (Xsldom.documentElement.tagName == "error")//返回了错误
	    {
	        delete this.oXmlHttp;
	        s = "recordset.open:发生了意外错误:\n" + Xsldom.documentElement.childNodes(0).text;
	        this.errors = s; 
	        throw s;
	    }
	}
	//根据列的编号,返回列的名称
	this.getcolnamebyno=function(col)
	{
		if(this.columncount>0 && col<this.columncount)
		{
			return colarr[col];
		}
		else
		{
			//alert ("列编号["+col+"]不在有效范围内");
			throw ("recordset.getcolnamebyno:★列编号["+col+"]不在有效范围内★");
			//return "";
		}
	}
	//根据列的名称,返回列的编号
	this.getcolnobyname=function(cname)
	{
		var i=nametoimap[cname.toUpperCase()];
		if(i==null)
		    throw "recordset.getcolnobyname:★列名["+cname+"]不存在★";
		else
		    return i;
	}
	//根据列的编号(或名字),返回列的类型,字符C,数字N
	this.getcoltype=function(col)
	{
	    if(IsNumber(col))//是数字
	    {
		    if(this.columncount>0 && col<this.columncount)
		    {
			    return coltypearr[col];
		    }
		    else
		    {
			    //alert ("列编号["+col+"]不在有效范围内");
			    throw ("recordset.getcoltype:★列编号["+col+"]不在有效范围内★");
			    //return "";
		    }
		}
		else
		{
		    return coltypearr[this.getcolnobyname(col)];
		}
	}	
	//返回结果集中的值,rows[0][1],
	this.rows=function(row,col)
	{
		if(IsNumber(col))//是数字
		{
			return rowarr[row][col];
		}
		else
		{
			return rowarr[row][this.getcolnobyname(col)];
		}
	}
}
//recordset end
//dbgrid start

function dbgrid()
{
    this.id=null;//表格的名字必须设置,而且不能重复,假设this.id=qt则表格中行的id形如qtr0,列id形如qtr0c0
    
	//this.tables="border='1' width='99%' bordercolorlight='#329DA0' bordercolordark='#FFFFFF' cellspacing='0' cellpadding='0'";
    this.tables="class='tt' border='1' bordercolorlight='#FFFFFF' bgcolor='#FFFFFF'";
    
	this.trshead="class=\"gridfieldname\" ";//"class='dbgridtrshead' style=''";
    this.trsodd="class='gridrowodd'";
    this.trseven="class='gridroweven'";
	
	this.tdhead="";
	this.tdodd="class='tdborder'";
	this.tdeven="class='tdborder'";
    
	this.showhead=true;//是否显示表头
	this.shownum=true;//显示记录总数
    this.autotomaodian=false;//行高亮时,跳转到行锚点上.
    
	this.showcheck=false;//是否显示checkbox列
    this.showpagedetail=true;//是否显示底部的翻页链接
    this.showexceltrans=true;//是否显示导入Excel链接
    
    this.startcolno=0;//从第几列开始列表
    this.rskeyname=null;//rs中哪个字段做为关键字,一般是IDS
    this.columnname=new Array();//对应列的名字,顺序和表头是对应的,columnname[i]中i从startcolno开始编号,所以可能没有0元素
    this.columntype=new Array();//对应列的数据类型,C或N,,columntype[i]中i从startcolno开始编号,所以可能没有0元素
    
    this.itemclick=null;//函数名(不带括号),点击表格中文字的时候,诱发的事件
    this.beforeshow=null;//函数名(不带括号),显示或翻页之前诱发的事件,调用方式 t.beforeshow=test1; test1就是某个函数
    this.aftershow=null;//函数名(不带括号),显示或翻页之后诱发的事件
    this.headclick=null;//字符串函数名(不带括号),点击标题后的事件,一般是做排序,要设置函数的名称的字符串
	this.headtitle=null;//鼠标放到列标题上的时候显示的title

    this.rs;//结果集,dbgrid就是把这个rs中的数据转换为表格显示
    this.maxrowid;//表格行编号,最大编到了多少
    this.container;
    //把创建的表格加载到 container 中
    this.createtable=function(container)   
    {
        if(this.beforeshow!=null)this.beforeshow();
        
        var htmls=new Array();
        var c,r;
        var rowid=-1,colid;
        var trid;
		var tds;
		var s;
        if(container==null && this.container==null)throw("dbgrid.createtable:★必须设置在哪个容器上创建★");

        if(container==null)container=this.container;
        if(this.container==null)this.container=container;
        
        if(this.id==null)throw("dbgrid.createtable:★必须先设置表格id★");
		htmls.push("<table style='width:97%;' cellspacing='0' cellpadding='0'><tbody><tr><td>");//外套★最外边套的表格,目的是为了让底部的bar能够和整体表格一起延长,到底部的div结束
        htmls.push("<table ");htmls.push(" id="+this.id+" "+this.tables+">");
        htmls.push("<tbody>");
        if(this.showhead)//创建表头
        {
            htmls.push("<tr id="+this.id+"_r"+(++rowid)+" "+this.trshead+"><a></a>");
            colid=0;
            if(this.showcheck)//显示check列
            {
                htmls.push("<td "+this.tdhead+" id="+this.id+"_r"+rowid+"c"+(colid++)+" width=15>");
                htmls.push("<input type='checkbox' onclick="+this.id+".dbgrid.choiceall('"+this.id+"_checkbox',this.checked) title='选中表格所有行'>"); 
                htmls.push("</td>");
            }
            for(c=this.startcolno;c<this.rs.columncount;c++)
            {
                //s=s+this.rs.getcolnamebyno(c)+"("+this.rs.getcoltype(c)+") | ";
				s=this.rs.getcolnamebyno(c);
                htmls.push("<td "+this.tdhead+" id="+this.id+"_r"+rowid+"c"+(colid++)+">");
				htmls.push("<a id="+this.id+"_c"+s+" value='"+s+"'");
				if(this.headclick!=null)
					htmls.push(" onclick="+this.headclick+"(this) title='"+this.headtitle+"' condition='' style='cursor:hand' ");
				htmls.push(">");//condition默认为'',点击后可能是asc或desc
                htmls.push(s);
				htmls.push("</a>");
                htmls.push("</td>");
                this.columnname[c]=this.rs.getcolnamebyno(c);
                this.columntype[c]=this.rs.getcoltype(c);
            }
            htmls.push("</tr>");
        }
        if(this.rs.recordcount>0)//创建数据
        {
            for(r=0;r<this.rs.recordcount;r++)
            {
                trid=this.id+"_r"+(++rowid);
                htmls.push("<tr id="+trid+" ");
                if(r % 2==0)
				{
                    htmls.push(this.trsodd);
					tds=this.tdodd;
                }
				else
				{
                    htmls.push(this.trseven);
					tds=this.tdeven
                }
				//每个数据行上有和行序号相关的rowno
                htmls.push(" rowno="+rowid);
				if(this.rskeyname!=null)//可以通过遍历tr的方法,找到rs(ids)对应的行
                    htmls.push(" rsid="+this.rs.rows(r,this.rskeyname));
                htmls.push(">");
				if(this.rskeyname!=null)htmls.push("<a id='a"+trid+"'></a>");//行锚点
                colid=0;
                if(this.showcheck)//显示check列
                {
                    htmls.push("<td "+tds+" id="+this.id+"_r"+rowid+"c"+(colid++)+" width=15>");
                    
                    htmls.push("<input type='checkbox'");
                    htmls.push(" onpropertychange='"+this.id+".dbgrid.checkboxchange(this)'");
                    htmls.push(" rowid="+trid);
                    if(this.rskeyname!=null)
                        htmls.push(" rsid="+this.rs.rows(r,this.rskeyname));
					//每个数据行的checkbox上都有和rs(id)相关的name属性,可以通过rs(id)找到对应的行
					if(this.rskeyname!=null)
						htmls.push(" id="+this.id+"_"+this.rs.rows(r,this.rskeyname));
                    htmls.push(" name="+this.id+"_checkbox>");
                    
                    htmls.push("</td>");
                }                
                for(c=this.startcolno;c<this.rs.columncount;c++)
                {
                    htmls.push("<td "+tds+" id="+this.id+"_r"+rowid+"c"+(colid++)+" rscolid="+c+">");//rscolid:说明的是本单元格对应的是rs中哪个列,columnname[rscolid]可以得到本单元格对应的字段名称
	                
	                if(this.itemclick!=null)
	                {
	                    htmls.push("<a onclick="+this.id+".dbgrid.cellclick('"+trid+"'");
	                    if(this.rskeyname!=null)htmls.push(",'"+this.rs.rows(r,this.rskeyname)+"'");
	                    htmls.push(") style='cursor:hand;'>");
	                }
					if(this.rs.rows(r,c)=="")
						htmls.push("&nbsp;");
					else
						htmls.push(this.rs.rows(r,c));
	                
	                if(this.itemclick!=null)
	                    htmls.push("</a>");
	                    
	                htmls.push("</td>");
                }
                htmls.push("</tr>");
                //alert(r+":"+this.rs.rows(r,5));
            }
        }     
        htmls.push("</tbody>");
        htmls.push("</table>");   
        
		htmls.push("<div id='"+this.id+"bottombar' class='tpg smallword'>");
        if(this.showpagedetail)
        {
            //数据总量:"+rs.allpagerecordcount+"\r\n每页显示:"+rs.recordperpage+"\r\n总页数:"+rs.pagecount+"\r\n当前页:"+rs.pageno
            
            if(this.showcheck)
				htmls.push("<input type='checkbox' onclick="+this.id+".dbgrid.choiceall('"+this.id+"_checkbox',this.checked) title='选中表格所有行'>全选"); 
            if(this.shownum)
				htmls.push("&nbsp;&nbsp;每页<a style='color:red;'>"+this.rs.recordperpage.toString()+"</a>条&nbsp;共:<a style='color:red;' id="+this.id+"_recordcountdisp>"+this.rs.allpagerecordcount+"</a>条&nbsp;");
            htmls.push("&nbsp;&nbsp;&nbsp;页次:"+this.rs.pagecount+"-");
            htmls.push("<input maxLength='10' value='"+this.rs.pageno+"' id='"+this.id+"_gopageno' style='font-family:宋体;height:12px;width:18px;border: 1px solid #000000; text-align:center;font-size:9pt;'>");
            htmls.push("<input type='button' value='Go' onclick="+this.id+".dbgrid.gotopage("+this.id+"_gopageno.value) style='cursor:hand;font-family:宋体;border:1px solid #000000; width:20;height:16;font-size:9pt;'>");
            
            htmls.push("&nbsp;&nbsp;");
            
            if(this.rs.allpagerecordcount>0 && this.rs.pageno>1)
                htmls.push("<a style='color:blue;cursor:hand' onclick=\""+this.id+".dbgrid.gotopage(1);\"><font face='webdings'>9</font>第一页</a>");
            else
                htmls.push("<a style=\"color:#999999;\"><font face='webdings'>9</font>第一页</a>");
            htmls.push("&nbsp;");
            if(this.rs.pageno>1)
                htmls.push("<a style='color:blue;cursor:hand' onclick=\""+this.id+".dbgrid.gotopage("+(this.rs.pageno-1)+");\"><font face='webdings'>7</font>上一页</a>");
            else
                htmls.push("<a style=\"color:#999999;\"><font face='webdings'>7</font>上一页</a>");
            htmls.push("&nbsp;");
            if(this.rs.pageno<this.rs.pagecount)
                htmls.push("<a style='color:blue;cursor:hand' onclick=\""+this.id+".dbgrid.gotopage("+(this.rs.pageno+1)+");\">下一页<font face='webdings' >8</font></a>");
            else
                htmls.push("<a style=\"color:#999999;\">下一页<font face='webdings' >8</font></a>");
            htmls.push("&nbsp;");
            if(this.rs.allpagerecordcount>0 && this.rs.pageno<this.rs.pagecount)
                htmls.push("<a style='color:blue;cursor:hand' onclick=\""+this.id+".dbgrid.gotopage("+this.rs.pagecount+");\">最末页<font face='webdings'>:</font></a>");
            else
                htmls.push("<a style=\"color:#999999;\">最末页<font face='webdings'>:</font></a>");
        }
		if(this.showexceltrans)
		{
			htmls.push("&nbsp;&nbsp;");
			htmls.push("<a style='color=blue;cursor:hand' onclick=\"gridtoexcel('"+this.id+"')\">※把当前显示表格数据导入Excel中※</a>");
		}
		htmls.push("</div>");
		htmls.push("</tbody></td></tr></table>");//外套■
        container.innerHTML=htmls.join("");
        htmls.splice(0,100000000);
        
        this.maxrowid=rowid;
        var obj=document.getElementById(this.id);
        if(obj!=null)//向表格上附加其它属性,可以通过表格id来访问
        {
            obj.dbgrid=this;
        }
        if(this.aftershow!=null)this.aftershow();
		
        //alert(container.innerHTML);
    }//createtable:end


	this.addrow=function(first,rskeyvalue)
	{
		var rs=new recordset();
		rs.type=this.id+"_defaultdbgrid";
		rs.recordperpage=1;
		rs.pageno=1;
		
		rs.where=this.rskeyname+"='"+rskeyvalue+"'";
		rs.fields=this.rs.fields;
		rs.order="";
		rs.showrow=true;
		rs.open(rs.showrow,rs.where,rs.fields,rs.order);
		//当first=true的时候,表格会重新创建,并且只显示新增的这一行
		if(!firstneedrefreshgrid)first=false;
		if(first)
		{
			this.rs=rs;
			this.createtable(QueryResultContent);
			this.hlightrow(this.id+"_r1");
			rs.close();
		}
		else//first=false的时候是向表格的底部追加一行
		{
			var rowid=this.maxrowid;
			var tableobj=document.getElementById(this.id);
			var tbodyobj=tableobj.childNodes[0];
			var trobj,tdobj;
			var sa=new Array();		
			var trid=this.id+"_r"+(++rowid);
			var colid=0;
			var aobj;
			var tds;
			if(rowid % 2==0)
			{
				trobj=document.createElement("<tr "+this.trseven+">");
				tds=this.tdeven;
			}
			else
			{
				trobj=document.createElement("<tr "+this.trsodd+">");
				tds=this.tdodd;
			}
			trobj.id=trid;
			trobj.rowno=rowid;
			if(this.rskeyname!=null)
				trobj.rsid=rs.rows(0,this.rskeyname);
			tbodyobj.appendChild(trobj);
			aobj=document.createElement("<a id='a"+trid+"'>");
			trobj.appendChild(aobj);
			if(this.showcheck)//显示check列
			{
				tdobj=document.createElement("<td "+tds+">");
				tdobj.width="15";
				tdobj.id=this.id+"_r"+rowid+"c"+(colid++);
				
				sa.push("<input type='checkbox'");
				sa.push(" onpropertychange='"+this.id+".dbgrid.checkboxchange(this)'");
				sa.push(" rowid="+trid);
				if(this.rskeyname!=null)
					sa.push(" rsid="+rs.rows(0,this.rskeyname));
				//每个数据行的checkbox上都有和rs(id)相关的name属性,可以通过rs(id)找到对应的行
				if(this.rskeyname!=null)
					sa.push(" id="+this.id+"_"+rs.rows(0,this.rskeyname));
				sa.push(" name="+this.id+"_checkbox>");
				
				tdobj.innerHTML=sa.join("");
				sa.splice(0,100);

				trobj.appendChild(tdobj);
			}
			for(var c=this.startcolno;c<rs.columncount;c++)
			{//修改这段代码时refreshrow中的相应程序也需要修改.
				tdobj=document.createElement("<td "+tds+">");
				tdobj.id=this.id+"_r"+rowid+"c"+(colid++)+" rscolid="+c;//rscolid:说明的是本单元格对应的是rs中哪个列,columnname[rscolid]可以得到本单元格对应的字段名称
				if(this.itemclick!=null)
				{
					sa.push("<a onclick="+this.id+".dbgrid.cellclick('"+trid+"'");
					if(this.rskeyname!=null)sa.push(",'"+rs.rows(0,this.rskeyname)+"'");
					sa.push(") style='cursor:hand;'>");
				}
				if(rs.rows(0,c)=="")
					sa.push("&nbsp;");
				else
					sa.push(rs.rows(0,c));
				if(this.itemclick!=null)
					sa.push("</a>");
				tdobj.innerHTML=sa.join("");
				sa.splice(0,100);
				trobj.appendChild(tdobj);
			}	
			this.maxrowid=rowid;
			this.hlightrow(trobj.id);
		}
		var obj=document.getElementById(this.id+"_recordcountdisp");
		if(obj!=null)obj.innerText="";//MyVal(obj.innerText)+1;
		rs.close();
	}
	
	this.refreshrow=function(rskeyvalue)
	{
		var rs=new recordset();
		var tableobj=document.getElementById(this.id);
		var tbodyobj=tableobj.childNodes[0];
		var trobj;	
		var i,c,ctd;
		var sa=new Array();
		var rrsid,rrskeyvalue;
		rrskeyvalue=rskeyvalue.toLowerCase();
		for(i=0;i<tbodyobj.childNodes.length;i++)
		{
			//找到了对应的行
			rrsid=tbodyobj.childNodes[i].rsid;
			if(rrsid!=null)
			{
				rrsid=rrsid.toLowerCase();
				if(rrsid==rrskeyvalue)
				{
					trobj=tbodyobj.childNodes[i];
					rs.type=this.id+"_defaultdbgrid";
					rs.recordperpage=1;
					rs.pageno=1;
					
					rs.where=this.rskeyname+"='"+rskeyvalue+"'";
					rs.fields=this.rs.fields;
					rs.order="";
					rs.showrow=true;
					rs.open(rs.showrow,rs.where,rs.fields,rs.order);
					if(this.showcheck)
						ctd=1;
					else
						ctd=0;
					if(this.rskeyname!=null)ctd++;//行锚点
					for(c=this.startcolno;c<rs.columncount;c++)
					{
						if(this.itemclick!=null)
						{
							sa.push("<a onclick="+this.id+".dbgrid.cellclick('"+trobj.id+"'");
							if(this.rskeyname!=null)sa.push(",'"+rs.rows(0,this.rskeyname)+"'");
							sa.push(") style='cursor:hand;'>");
						}
						if(rs.rows(0,c)=="")
							sa.push("&nbsp;");
						else
							sa.push(rs.rows(0,c));
						if(this.itemclick!=null)
							sa.push("</a>");
						trobj.childNodes[ctd++].innerHTML=sa.join("");
						sa.splice(0,100);
					}
					
					rs.close();
					this.hlightrow(trobj.id);
					break;
				}
			}
		}
	}
	
    //根据行号删除行,假设表格id为qt,调用方法为qt.dbgrid.deleterowbyrowno(5);
	//行号是按行号生成的 0,1,2,3,4
    this.deleterowbyrowno=function(rowno)
    {
        var trobj=document.getElementById(this.id+"_r"+rowno);
        if(trobj==null)
            throw("dbgrid.deleterowbyrowno:★以["+this.id+"_r"+rowno+"]为id的行没有找到,可能表格不存在或行不存在★");
        else
        {
            var tbody=document.getElementById(this.id).childNodes[0];
			tbody.removeChild(trobj);
			//this.hiderecordcountdisp();
			var obj=document.getElementById(this.id+"_recordcountdisp");
			if(obj!=null)obj.innerText="";//MyVal(obj.innerText)-1;
        }
    }
	//根据行上的checkbox的id来删除行,假设表格id为qt,那么每行都有(可能,this.showcheck=true时才创建)checkbox的name为qt_1188,1188是行的id
	//只有有this.showcheck=true的时候每个行才有这个id,一般都是和rs(id)相关的
    this.deleterowbycheckid=function(rskeyvalue)
    {
        var checkboxobj=document.getElementById(this.id+"_"+rskeyvalue);
		if(checkboxobj==null)throw("dbgrid.deleterowbycheckid:★以["+this.id+"_"+rskeyvalue+"]为id的checkbox没有找到,可能表格不存在或行不存在★");
        var trobj=document.getElementById(checkboxobj.rowid);
		if(trobj==null)
            throw("dbgrid.deleterowbycheckid:★以["+checkboxobj.rowid+"]为id的行没有找到,可能表格不存在或行不存在★");
        else
        {
            var tbody=document.getElementById(this.id).childNodes[0];
			tbody.removeChild(trobj);
			//this.hiderecordcountdisp();
			var obj=document.getElementById(this.id+"_recordcountdisp");
			if(obj!=null)obj.innerText="";//MyVal(obj.innerText)-1;
        }
    }
    //隐藏行,假设表格id为qt,调用方法为qt.dbgrid.rowdisplay(5);
    //hide:默认为none,也可以是inline(显示)
    this.rowdisplay=function(rowno,hide)
    {
        var trobj=document.getElementById(this.id+"_r"+rowno);
        if(hide==null)hide="none";
        if(trobj==null)
            throw("dbgrid.rowdisplay:★以["+this.id+"_r"+rowno+"]为id的行没有找到,可能表格不存在或行不存在★");
        else
        {
            trobj.style.display=hide;
        }
    }
    //隐藏列,qt.dbgrid.coldisplay(2)
    //hide:默认为none,也可以是inline(显示)
    this.coldisplay=function(colno,hide)
    {
        var tableobj=document.getElementById(this.id);
        var tbody=tableobj.childNodes[0];
        var rowcollect=tbody.childNodes;
        var tdobj;
        if(hide==null)hide="none";
        for(var r=0;r<rowcollect.length;r++)
        {
	        tdobj=document.getElementById(rowcollect[r].id+"c"+colno);
	        if(tdobj==null)
	            throw("dbgrid.hidecol:★以["+rowcollect[r].id+"c"+colno+"]为id的单元格没有找到,可能指定的列号不存在★");
	        else
	            tdobj.style.display=hide;
        }
    }
    //返回checkbox中选中的id串,如1,2,3
    //调用方法:s=qt.dbgrid.checkedkeys();
    this.checkedkeys=function(spliter)
    {
        var checkobjs=document.getElementsByName(this.id+"_checkbox");
        var ids=new Array();
        if(spliter==null)spliter=",";
        for(var i=0;i<checkobjs.length;i++)
        {
            if(checkobjs[i].checked)
            {
                ids.push(checkobjs[i].rsid);
            }
        }
        return ids.join(spliter);
    }
    //页面跳转
    this.gotopage = function(topageno)
    {
        /*@cc_on
        @if (@inuser)
		try
		{
	@end
        @*/

        var tableobj = document.getElementById(this.id);
        //var pagetoobj;
        if (tableobj != null)
        {
            tableobj.dbgrid.container.innerHTML = "";
            if (tableobj.dbgrid.rs.callback == null)
                wait("请稍候,查询进行中");
            else
                wait("请稍候,查询进行中", 1);
            tableobj.dbgrid.rs.close();
            tableobj.dbgrid.rs.pageno = topageno; //pagetoobj.value;
            //wait("查询中,请稍候...");
            //alert(tableobj.dbgrid.rs.where+":"+tableobj.dbgrid.rs.fields+":"+tableobj.dbgrid.rs.order);
            tableobj.dbgrid.rs.open(tableobj.dbgrid.rs.showrow, tableobj.dbgrid.rs.where, tableobj.dbgrid.rs.fields, tableobj.dbgrid.rs.order);
            if (tableobj.dbgrid.rs.callback == null)
            {
                tableobj.dbgrid.createtable(tableobj.dbgrid.container);
                wait("closeall");
            }
            //wait("closeall");
        }
        /*@cc_on
        @if (@inuser)
		}    
    catch(ex) 
    {
        var s="gotopage:"+(ex.message==null?ex:ex.message);
        errmsg(s,16,"意外错误!")
    }
	@end
        @*/

    }
	//隐藏记录总数显示的<a>
	this.hiderecordcountdisp=function()
	{
		var obj=document.getElementById(this.id+"_recordcountdisp");
		if(obj!=null)obj.style.display="none";
	}
    this.choiceall=function(checknames,corn)
    {
	    var objs=document.getElementsByName(checknames)
	    if(objs.length==0)
	    {
		    alert("没有可共选择的数据行");
		    return;
	    }
	    for(var i=0;i<objs.length;i++)
	    {
	        if(objs[i].checked!=corn)objs[i].checked=corn;
	    }
    } 
	this.hlightrow=function(trid,gotomaodian)
	{
		if(gotomaodian==null)gotomaodian=true;
		try
        {
			
            var tableobj=document.getElementById(this.id);
            var trobj=document.getElementById(trid);
            if(tableobj.lastclickrow!=null)
            {
                if(tableobj.lastclickrow.cloldbkcolor!=null)
                {
                    //tableobj.lastclickrow.bgColor=tableobj.lastclickrow.cloldbkcolor;
                    //tableobj.lastclickrow.cloldbkcolor=null;
					tableobj.lastclickrow.style.backgroundColor=tableobj.lastclickrow.cloldbkcolor;
                    tableobj.lastclickrow.cloldbkcolor=null;
                }
            }
			if(this.autotomaodian && gotomaodian)location.hash="#a"+trid;
            tableobj.lastclickrow=trobj;
            //trobj.cloldbkcolor=trobj.bgColor;
            //trobj.bgColor=1349375;//4390722;
			trobj.cloldbkcolor=trobj.style.backgroundColor;
			trobj.style.backgroundColor="#66FF66";//"#FFE7A2";//1349375;//4390722;//
        }
        catch(e){}
	}
	//已知行的IDS,高亮此行,要求this.rskeyname!=null
	this.hlightrow2=function(vids,gotomaodian)
	{
		if(this.rskeyname==null)return;
		vids=vids.toLowerCase();
		var tableobj=document.getElementById(this.id);
		var tbody = tableobj.childNodes[0];
		var rowcollect;
		var rtb;
		rowcollect=tbody.childNodes;
		for(rtb=0;rtb<rowcollect.length;rtb++)
		{
			if(rowcollect[rtb].rsid!=null)
			if(rowcollect[rtb].rsid.toLowerCase()==vids)
			{
				this.hlightrow(rowcollect[rtb].id,gotomaodian);
				break;
			}
		}		
	}
	//找到ids的下一行或上一行,返回下一行或上一行的ids,并高亮
	//如果没有rskeyname则不能用这个函数
	//direction:-1向上 1向下
	this.movenext=function(direction,ids)
	{
		var tableobj=document.getElementById(this.id);
		var tbody = tableobj.childNodes[0];
		var rowcollect;
		var r;
		var rval=new movenextval();
		var have=false;
		rval.ids="";
		rowcollect=tbody.childNodes;
		for(r=1;r<rowcollect.length;r++)
		{
			//colcollect=rowcollect[r].childNodes;
			//alert(rowcollect[r].rsid);
			if(ids==rowcollect[r].rsid)
			{
				have=true;
				break;
			}
		}
	//this.ids;
	//this.rowid;
	//this.havemore;
		if(have)
		{
			if(direction==1)//下一行
			{
				if(r<(rowcollect.length-1))
				{
					rval.ids=rowcollect[r+1].rsid;
					rval.rowid=rowcollect[r+1].id;
				}
				rval.havemore=(r<rowcollect.length-2);
			}
			else//上一行
			{
				if(r>1)
				{
					rval.ids=rowcollect[r-1].rsid;
					rval.rowid=rowcollect[r-1].id;
				}
				rval.havemore=(r>2);
			}
			if(rval.ids!="")this.hlightrow(rval.rowid);
		}
		return rval;
	}
    //tableid,trid,rskeyvalue,envokfunction
    this.cellclick=function(trid,rskeyvalue)
    {
		this.hlightrow(trid,false);
		
        this.itemclick(rskeyvalue);
    }       
    this.checkboxchange=function(checkboxobj)
    {
        if(event.propertyName=="checked")
        {
            var rowobj=document.getElementById(checkboxobj.rowid)
            if(rowobj!=null)
            {
                if(checkboxobj.checked)//选中 .style.backgroundColor
                {   
                    if(rowobj.cloldbkcolor!=null)
                    {
                        //rowobj.bgColor=rowobj.cloldbkcolor;
                        rowobj.style.backgroundColor=rowobj.cloldbkcolor;
						rowobj.cloldbkcolor=null;
                    }
                    //rowobj.chkoldbkcolor=rowobj.bgColor;
                    //rowobj.bgColor=8421504; 
					rowobj.chkoldbkcolor=rowobj.style.backgroundColor;
                    rowobj.style.backgroundColor=8421504;
                }
                else
                {
                    //rowobj.bgColor=rowobj.chkoldbkcolor;
					rowobj.style.backgroundColor=rowobj.chkoldbkcolor;
                    rowobj.cloldbkcolor=null;
                }
            }   
        }
    }    
}
function movenextval()
{
	this.ids;
	this.rowid;
	this.havemore;
}
function gridtoexcel(tableid)
{
	wait("数据传输中,请稍候...");
	var left,top,width,height;
	width=document.documentElement.clientWidth;
	height=document.documentElement.clientHeight;
	left=0;
	top=0;
    var xwin=new xwindow();
    var url="excel_printgrid.aspx?tableid="+tableid;
    xwin.create(left,top,width,height,url,"表格打印",1);
}
//dbgrid end
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//███████████████████████████████████████████████████████████████████████
//function getrsval(postpage,type,p1,p2,p3,p4,p5)
function getrsval()//头2个参数必须是 postpage和type ,后边的参数无限制 
{
	var rs=new recordset();
	var rval="";
	var postpage=arguments[0];
	var type=arguments[1];
	var inputs=new Array();
	rs.postpage=postpage;
	rs.type=type;
	/*
	if(p5!=null)rs.open(p1,p2,p3,p4,p5);
	else if(p4!=null)rs.open(p1,p2,p3,p4);
	else if(p3!=null)rs.open(p1,p2,p3);
	else if(p2!=null)rs.open(p1,p2);
	else if(p1!=null)rs.open(p1);
	else if(p1==null)rs.open("");
	*/
	if(arguments.length==2)
	{
		rs.open("");
	}
	else
	{
		for(var c=2;c<arguments.length;c++)
		{
			inputs.push(arguments[c]);
		}
		rs.open(inputs);
	}
	if(rs.recordcount>0)rval=rs.rows(0,0);
	rs.close();
	rs=null;
	return rval;
}

//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
function getpinpoint(oNode,pNode)
{
	if(!pNode)
		pNode = document.body

	var oCurrentNode=oNode;
	var iLeft=0;
	var iTop=0;
	while((oCurrentNode)&&(oCurrentNode!=pNode))
	{
		iLeft+=oCurrentNode.offsetLeft-oCurrentNode.scrollLeft;
		iTop+=oCurrentNode.offsetTop-oCurrentNode.scrollTop;
		oCurrentNode=oCurrentNode.offsetParent;
	}
	if(pNode == document.body)
	{
		if(document.documentElement.scrollTop)
		iTop+=document.documentElement.scrollTop;
		if(document.documentElement.scrollLeft)
		iLeft+=document.documentElement.scrollLeft;
	}
	return new Array(iLeft-parseInt(document.documentElement.scrollLeft),iTop-parseInt(document.documentElement.scrollTop));
}
function dropdown(boxobj, rs, closers, forcerenew, listclick, listwidth, listheight)//DIV
{
    //alert('d');
    var boxobjval = boxobj.value;
    if (boxobj.drophtml == null) boxobj.drophtml = "";

    var pinpoint = getpinpoint(boxobj);
    //mc.left=pinpoint[0];
    //mc.top=pinpoint[1];


    var lists;
    var s1, s2;
    var colc;
    var defaultselected = "";
    var htmls = new Array();
    var r;
    if (listwidth == null) listwidth = boxobj.clientWidth + 22;
    if (listheight == null) listheight = 150;
    if (boxobj.drophtml.length == 0 || forcerenew)
    {
        colc = rs.columncount;

        s1 = boxobj.id;
        if (boxobj.parentNode.id != "")
        {
            if (boxobj.parentNode.tagName.toUpperCase() != "TD")//有些标签不能作为容器出现
            {
                s1 = boxobj.parentNode.id + ".all." + s1;
            }
        }
        if (boxobj.parentNode.parentNode.id != "")
        {
            if (boxobj.parentNode.parentNode.tagName.toUpperCase() != "TD")
            {
                s1 = boxobj.parentNode.parentNode.id + ".all." + s1;
            }
        }
        if (boxobj.parentNode.parentNode.parentNode.id != "")
        {
            if (boxobj.parentNode.parentNode.parentNode.tagName.toUpperCase() != "TD")
            {
                s1 = boxobj.parentNode.parentNode.parentNode.id + ".all." + s1;
            }
        }
        //alert(s1);
        htmls.push("<select size='15' id='DropListsobj' style='border-style: solid; border-width: 1px;width=" + listwidth + "; height:" + listheight + "' ");
        htmls.push("onclick=\"document.all." + s1 + ".value=this.value;document.body.removeChild(document.all.dropdowndiv);"); //parent.document.focus();
        if (listclick != null)
        {
            //可以这么调用dropdown(boxobj,rs,true,forcerenew,"审查人员",150,200);
            //也可以dropdown(boxobj,rs,true,forcerenew,"审查人员set('勘察',@parame)",150,200);
            if (listclick.indexOf("@parame") > -1)
                htmls.push(listclick.replace(/@parame/g, 'this.value') + ";");
            else
                htmls.push(listclick + "(this.value);");
        }
        htmls.push("\">");
        //lists=lists+"<option value='&lt;ff&gt;'>&lt;ff&gt;</option><option value='bb'>bb</option>";
        htmls.push("<option value=\"" + "" + "\" >" + "" + "</option>");
        for (r = 0; r < rs.recordcount; r++)
        {

            s1 = (rs.rows(r, 0) + "").replace(/</g, "&lt;"); //特殊字符替换:  <变成&lt;  
            if (colc > 1)
            {
                s2 = (rs.rows(r, 1) + "").replace(/</g, "&lt;");
            }
            else
            {
                s2 = s1;
            }
            /*
            if(boxobjval==rs.rows(r,0))
            defaultselected="";//"selected";
            else
            defaultselected="";
            */
            htmls.push("<option value=\"" + s1.replace(/"/g, "&quot;") + "\" " + defaultselected + ">" + s2 + "</option>");
        }
        htmls.push("</select>");
        lists = htmls.join("");
        htmls.splice(0, 100000000);
        if (closers) { rs.close(); rs = null; }
    }
    else
    {
        lists = boxobj.drophtml;
    }


    //oPopBody.innerHTML=lists;
    boxobj.drophtml = lists;
    //alert(boxobj.drophtml);
    //oPopup.show(mc.left+2,mc.top+boxobj.clientHeight+4,listwidth,listheight, document.body);

    var divobj = document.getElementById("dropdowndiv");
    if (divobj != null) document.body.removeChild(divobj);
    divobj = document.createElement("<div id='dropdowndiv' style='position: absolute; z-index:999;left:" + (pinpoint[0]) + "px; top:" + (pinpoint[1] + boxobj.clientHeight + 3) + "px; width:" + listwidth + "px; height:" + listheight + "px;'>");
    document.body.appendChild(divobj);
    divobj.innerHTML = lists;
    DropListsobj.focus();
    if (listheight > 60)
    {
        for (r = 0; r < DropListsobj.length; r++)
        {
            if (DropListsobj.options[r].value == boxobj.value)
            {
                if (listheight > 130)
                {
                    if (r + 5 < DropListsobj.length)
                        DropListsobj.selectedIndex = r + 5;
                    else if (r + 4 < DropListsobj.length)
                        DropListsobj.selectedIndex = r + 4;
                    else if (r + 3 < DropListsobj.length)
                        DropListsobj.selectedIndex = r + 3;
                    else if (r + 2 < DropListsobj.length)
                        DropListsobj.selectedIndex = r + 2;
                    else
                        DropListsobj.selectedIndex = r + 1;
                }
                else
                {
                    if (r + 2 < DropListsobj.length)
                        DropListsobj.selectedIndex = r + 2;
                    else
                        DropListsobj.selectedIndex = r + 1;
                }
                DropListsobj.selectedIndex = r;
                break;
            }
        }
    }
    DropListsobj.onblur = function() { document.body.removeChild(document.all.dropdowndiv); }
}
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■

function getallcols()
{
    var rs=new recordset();
    rs.type="SearchContent_allcols";
    rs.open("");
    return rs;
}
function setheadordershow()
{
    var i;
    var heada;
    var fieldname,condition;
    var n=0;
    var needxh=false;
	if(OrderContent.oldorder.length>1)needxh=true;
    for(i=0;i<OrderContent.oldorder.length;i++)
    {
        fieldname=OrderContent.oldorder[i].fieldname;
        condition=OrderContent.oldorder[i].condition;
        if(fieldname!="")
        {
            heada=document.getElementById("QueryTable_c"+fieldname);
			n++;
            if(heada!=null)
            {
            	if(condition=="" || condition=="asc")
            	{
	            	heada.condition="asc";
	            	heada.innerHTML=heada.value+"<font color=red>↑"+(needxh?"<sup>"+n+"</sup>":"")+"</font>";
            	}
            	else
            	{
            		heada.condition="desc";
	            	heada.innerHTML=heada.value+"<font color=red>↓"+(needxh?"<sup>"+n+"</sup>":"")+"</font>";
            	}
            }
        }
    }
}
//OnMouseOver="funmin(this)" OnMouseOut="funout(this,'black','')"
function funmin(obj)
{
	obj.style.color='white';
	obj.style.background='darkblue';
}
function funout(obj,focolor,bkcolor)
{
	obj.style.color=focolor;
	obj.style.background=bkcolor;	
}
//cover_start----------------------------
cover.idcount = 0;
function cover()
{//作者:山西太原的邢志云,mail: ty258@163.com
    this.have = false;
    this.oDiv;
    this.create = function(coverid)
    {
        if (!this.have)
        {
            if (coverid == null) coverid = "xzycover" + (cover.idcount++);
            this.oDiv = document.createElement("<DIV id='" + coverid + "' style='DISPLAY: inline; Z-INDEX: " + (zindexcount++) + "; FILTER: alpha(opacity=60); POSITION: absolute; LEFT: 0px; TOP: 0px; WIDTH: 100%; HEIGHT: 100%; BACKGROUND-COLOR: #555555; '>");
            document.body.insertBefore(this.oDiv, document.body.firstChild);
            this.oDiv.style.width = "3000px";
            this.oDiv.style.height = document.documentElement.scrollHeight;
            this.oDiv.innerHTML = "<iframe style='width:100%;height:100%;FILTER: alpha(opacity=0);'></iframe>";
            this.have = true;
            return coverid;
        }
    }
    this.remove = function()
    {
        if (this.have)
        {
            if (this.oDiv != null)
            {
                document.body.removeChild(this.oDiv);
            }
            this.have = false;
        }
    }
}
//cover_end----------------------------
//xwindow_start---------------------------
xwindow.idcount = 0;
function xwindow()
{//作者:山西太原的邢志云.mail:ty258@163.com
    this.windowid;
    this.obj;
    this.left;
    this.top;
    this.width;
    this.height;
    this.url;
    this.caption;
    this.alreadycreate = false;
    this.cover = null;
    this.old = {}; this.old.left = 100; this.old.top = 100; this.old.width = 400; this.old.height = 300;
    this.move = {}; this.move.mousedown = false; this.move.obj = null; this.move.xdis = 0; this.move.ydis = 0; this.move.jo = 0;

    this.trigger = {}; //几个事件
    this.trigger.beforeclose = null; //beforeclose(xwinobj);关闭前执行,返回true表示允许关闭,false表示不允许关闭,
    //例子:xwin.trigger.beforeclose=function(xwinobj){return true;};
    this.trigger.afterclose = null; //afterclose(xwinobj);关闭后执行,利用xwinobj可以传递些参数
    //例子:xwin.tag='邢志云';xwin.trigger.afterclose=function(xwinobj){alert(xwinobj.tag+"已经关闭了");};
    this.trigger.windowresize = null; //windowresize(left,top,width,height);执行refresh之后出发此事件,
    //例子:function subwindowresize(left,top,width,height){};xwin.trigger.windowresize=subwindowresize;
    //创建后返回这个window的id(其实就是那个div的id)
    this.create = function(left, top, width, height, url, caption, modeltype)
    {
        this.windowid = "xwindow" + (xwindow.idcount++);
	    //if (left == null || left < document.documentElement.scrollLeft) left = document.documentElement.scrollLeft;
	    //if (top == null || top < document.documentElement.scrollTop) top = document.documentElement.scrollTop;
		if (left == null || left < 0) left = 0;
	    if (top == null || top < 0) top = 0;
        if (width > document.documentElement.clientWidth) width = document.documentElement.clientWidth;
        if (height > document.documentElement.clientHeight) height = document.documentElement.clientHeight;
        if (caption == null) caption = "";
        if (modeltype == null) modeltype = 0;
        if (modeltype == 1)
        {
            this.cover = new cover();
            this.cover.create();
        }
		if(IEVS<7)
		{
			top=top+document.documentElement.scrollTop;
			left=left+document.documentElement.scrollLeft;
		}
        var oDiv = document.createElement("<DIV id='" + this.windowid + "' onmousedown=\"this.style.zIndex = (zindexcount++);\" style='Z-INDEX: " + (zindexcount++) + ";POSITION: "+(IEVS>=7?"fixed":"absolute")+"; LEFT: " + left + "px; TOP: " + top + "px; WIDTH: " + width + "px; HEIGHT: " + height + "px;'>");
        document.body.insertBefore(oDiv, document.body.firstChild);
        oDiv.window = this;
        this.obj = oDiv;
        this.left = left;
        this.top = top;
        this.width = width;
        this.height = height;
        this.url = url;
        this.caption = caption;
        this.old.left = this.left;
        this.old.top = this.top;
        this.old.width = this.width;
        this.old.height = this.height;
        var sarr = new Array();
        var s;
        //sarr.push("<!--header-->");
        sarr.push("<div id=\"windowhead1\" style=\";position: absolute; left: 0px; top: 0px; width:30px;height:30px;background-image: url(images/window/lcorner.png);background-repeat: no-repeat;\"><img id=\"windowicon\" ondblclick=\"" + this.windowid + ".window.windowclose();\" style=\"margin-top:6px;margin-left:5px;border-style:none;\" src=\"images/window/icon.png\"></div>");
        sarr.push("<div id=\"windowhead2\" ondblclick=\"" + this.windowid + ".window.bardbclick()\" onmousedown=\"" + this.windowid + ".window.barmousedown(" + this.windowid + ")\" onMouseMove=\"" + this.windowid + ".window.barmousemove('all');\" onselectstart=\"return false\" style=\"position: absolute; left: 30px; top: 0px; width:" + (width - 85) + "px;height:30px;background-image: url(images/window/head.png);text-align:left;\">");
        sarr.push("<div id=\"windowcaption\" style=\"width:100%;margin-top:6px;font-size:14px;font-weight:bold;color:white;overflow:hidden;display:block;word-break:keep-all;white-space:nowrap;text-overflow:ellipsis;cursor:default;\">" + caption + "</div>");
        sarr.push("</div>");
        sarr.push("<div id=\"windowhead3\" style=\"position: absolute; left: " + (width - 55) + "px; top: 0px; width:55px;height:30px;background-image: url(images/window/rcorner.png);background-repeat: no-repeat;\">");
        sarr.push("<img id=\"windowmaxbutton\" onclick=\"" + this.windowid + ".window.windowmax();\" style=\"margin-top:5px;margin-left:5px;display:inline;border-style:none;\" src=\"images/window/windowmax.png\"><img id=\"windownormalbutton\" onclick=\"" + this.windowid + ".window.windownormal();\" style=\"display:none;margin-top:5px;border-style:none;\" src=\"images/window/windownormal.png\"><img id=\"windowclosebutton\" onclick=\"" + this.windowid + ".window.windowclose();\" style=\"margin-top:5px;margin-left:2px;border-style:none;\"  src=\"images/window/windowclose.png\">");
        sarr.push("</div>");

        //sarr.push("<!--area-->");
        sarr.push("<div id=\"windowvertical1\" style=\"position: absolute; left: 0px; top: " + 30 + "px; width:4px;height:" + (height - 34) + "px;background-image: url(images/window/lvertical.png);background-repeat: repeate-y;\"></div>");

        sarr.push("<div id=\"windowiframexwindow\" style=\"position: absolute; left: 4px; top: " + 30 + "px; width:" + (width - 8) + "px;height:" + (height - 34) + "px;\">");
        s = url;
        if(s!="")
		{
			if(s.indexOf("?")==-1)
				s=s + "?xwindowid="+this.windowid;
			else
				s=s + "&xwindowid="+this.windowid;
		}
        sarr.push("<iframe id=\"windowiframe\" align=\"center\" src=\"" + s + "\" frameborder=\"0\" scrolling=\"yes\" width=\"100%\" height=\"100%\"></iframe>");
        sarr.push("</div>");

        sarr.push("<div id=\"windowvertical2\" style=\"position: absolute; left: " + (width - 4) + "px; top: " + 30 + "px; width:4px;height:" + (height - 34) + "px;cursor:e-resize;background-image: url(images/window/rvertical.png);background-repeat: repeate-y;\" onmousedown=\"" + this.windowid + ".window.barmousedown(this)\" onMouseMove=\"" + this.windowid + ".window.barmousemove('horizontalr');\"></div>");
        //sarr.push("<!--bottom-->");
        sarr.push("<div id=\"windowbottom\" style=\"font-size:0;position: absolute; left: 0px; top: " + (height - 4) + "px;width:" + (width - 10) + "px;height:4px;cursor:s-resize;background-image:url(images/window/horizontal.png);background-repeat:repeat-x;\" onmousedown=\"" + this.windowid + ".window.barmousedown(this)\" onMouseMove=\"" + this.windowid + ".window.barmousemove('vertical');\"></div>");
        sarr.push("<div id=\"windowbottomcorner\" style=\"font-size:0;position: absolute; left: " + (width - 10) + "px; top: " + (height - 4) + "px;width:10px;height:4px;cursor:se-resize;background-image:url(images/window/brcorner.png);background-repeat:repeat-x;\" onmousedown=\"" + this.windowid + ".window.barmousedown(this)\" onMouseMove=\"" + this.windowid + ".window.barmousemove('allbr');\"></div>");
        oDiv.innerHTML = sarr.join('');
        this.alreadycreate = true;
        return this.windowid;
    }
    //改变url时,单独调用这里
    this.seturl = function(url)
    {
        this.url = url;
        var s = url;
        if (s.indexOf("?") == -1)
            s = s + "?xwindowid=" + this.windowid;
        else
            s = s + "&xwindowid=" + this.windowid;
        this.obj.all.windowiframexwindow.innerHTML = "<iframe id=\"windowiframe\" align=\"center\" src=\"" + s + "\" frameborder=\"0\" scrolling=\"yes\" width=\"100%\" height=\"100%\"></iframe>";
    }
    //窗口内容也可以不是地址,而直接是html内容
    this.sethtml = function(html)
    {
        this.url = null;
        this.obj.all.windowiframexwindow.innerHTML = html;
    }
    this.setcaption = function(caption)
    {
        this.caption = caption;
        this.obj.all.windowcaption.innerHTML = caption;
    }
    this.windowmax = function()
    {
        this.old.left = this.left;
        this.old.top = this.top;
        this.old.width = this.width;
        this.old.height = this.height;
		if(IEVS>=7)
		{
			this.left =0;
			this.top = 0;
		}
		else
		{
			this.left = document.documentElement.scrollLeft;
			this.top = document.documentElement.scrollTop;
		}
        this.width = document.documentElement.clientWidth;
        this.height = document.documentElement.clientHeight;
        this.refresh();
        this.obj.all.windowmaxbutton.style.display = "none";
        this.obj.all.windownormalbutton.style.display = "inline";
    }
    this.windownormal = function()
    {
        this.left = this.old.left;
        this.top = this.old.top;
        this.width = this.old.width;
        this.height = this.old.height;
        this.refresh();
        this.obj.all.windowmaxbutton.style.display = "inline";
        this.obj.all.windownormalbutton.style.display = "none";
    }
    this.windowclose = function()
    {
        if (!this.alreadycreate) return;
        var allow = true;
        if (this.trigger.beforeclose != null)
        {
            allow = this.trigger.beforeclose(this);
        }
        if (allow)
        {
            if (this.url != null) this.obj.all.windowiframe.src = "";
            document.body.removeChild(this.obj);
            if (this.cover != null)
            {
                this.cover.remove();
                this.cover = null;
            }
            if (this.trigger.afterclose != null)
            {
                this.trigger.afterclose(this);
            }
            this.alreadycreate = false;
        }
    }
    this.barmousedown = function(obj)
    {
        if (event.button == 1)
        {
            this.move.mousedown = true;
            //ready移动
            this.move.obj = obj;
            this.move.xdis = parseInt(this.move.obj.style.left) - parseInt(event.clientX) - parseInt(document.body.scrollLeft);
            this.move.ydis = parseInt(this.move.obj.style.top) - parseInt(event.clientY) - parseInt(document.body.scrollTop);
            if (this.move.obj.childNodes.length > 0)
                this.move.obj.childNodes[1].setCapture();
            else
                this.move.obj.setCapture();
        }
    }
    //all vertical horizontal
    this.barmousemove = function(direction)
    {
        if (event.button == 1)
        {
            var tmp, xmove = 0, ymove = 0;
            var maydo;
			var mouseX,mouseY;
			mouseX=event.clientX;
			mouseY=event.clientY;
			if(mouseX<0)mouseX=0;
			if(mouseY<0)mouseY=0;
			if(mouseX>parseInt(document.documentElement.clientWidth))mouseX=parseInt(document.documentElement.clientWidth);
			if(mouseY>parseInt(document.documentElement.clientHeight))mouseY=parseInt(document.documentElement.clientHeight);
            if (direction == null) direction = "all";
            if (direction == "all" || direction == "allbr" || direction == "horizontalr")
            {
                tmp = parseInt(mouseX) + this.move.xdis + parseInt(document.body.scrollLeft) - parseInt(this.move.obj.style.left);
                xmove = tmp;
                this.move.obj.style.left = parseInt(this.move.obj.style.left) + xmove;
            }
            if (direction == "all" || direction == "allbr" || direction == "vertical")
            {
                tmp = parseInt(mouseY) + this.move.ydis + parseInt(document.body.scrollTop) - parseInt(this.move.obj.style.top);
                ymove = tmp;
                this.move.obj.style.top = parseInt(this.move.obj.style.top) + ymove;
            }
			
			//if(parseInt(this.move.obj.style.top)<0)this.move.obj.style.top=0;
			//RecordPerPage.value=event.clientX;
            if (direction == "all")
            {
                this.left = this.obj.style.left;
                this.top = this.obj.style.top;
            }

            maydo = false;
            if (direction == "horizontalr" || direction == "allbr")
            {
                this.width = this.width + xmove;
                if (this.width < 100) this.width = 100;
                maydo = true;
            }
            if (direction == "vertical" || direction == "allbr")
            {
                if (this.move.jo == 0)//在IE6下,iframe的高度调整有问题,不得已这里有这一步
                {
                    this.move.jo = 1;
                    this.width = this.width + 1;
                }
                else
                {
                    this.move.jo = 0;
                    this.width = this.width - 1;
                }
                this.height = this.height + ymove;
                if (this.height < 100) this.height = 100;
                maydo = true;
            }
            if (maydo) this.refresh();
        }
        else
        {
            if (this.move.mousedown)
            {
                this.move.mousedown = false;
                if (this.move.obj.childNodes.length > 0)
                    this.move.obj.childNodes[1].releaseCapture();
                else
                    this.move.obj.releaseCapture();
                //alert("移动停止");
            }
        }

    }
    this.bardbclick = function()
    {
        this.move.mousedown = false;
        if (this.move.obj != null) { this.move.obj.childNodes[1].releaseCapture(); this.move.obj = null };
        if (this.obj.all.windowmaxbutton.style.display == "inline")
            this.windowmax()
        else
            this.windownormal();
    }
    this.refresh = function()
    {
        this.obj.style.left = this.left;
        this.obj.style.top = this.top;
        this.obj.style.width = this.width;
        this.obj.style.height = this.height;
        this.obj.all.windowhead2.style.width = this.width - 85;
        this.obj.all.windowhead3.style.left = this.width - 55;
        this.obj.all.windowvertical1.style.height = this.height - 34;
        this.obj.all.windowvertical2.style.left = this.width - 4;
        this.obj.all.windowvertical2.style.height = this.height - 34;

        this.obj.all.windowbottom.style.top = this.height - 4;
        this.obj.all.windowbottom.style.width = this.width - 10;

        this.obj.all.windowbottomcorner.style.top = this.height - 4;
        this.obj.all.windowbottomcorner.style.left = this.width - 10;

        this.obj.all.windowiframexwindow.style.width = this.width - 8;
        this.obj.all.windowiframexwindow.style.height = this.height - 34;
        if (this.trigger.windowresize != null)
        {
            this.trigger.windowresize(parseInt(this.left), parseInt(this.top), parseInt(this.width), parseInt(this.height));
        }
    }
}
//关闭xwindow
//同级页面关闭例子
/*
var xwinedit = new xwindow();
var winid=xwinedit.create(left, top, width, height, url, caption, 1);
alert(winid);
closexwindow(winid);
*/
//从子级页面执行,直接执行 closexwindow(); 即可
function closexwindow(xwindowid)
{
    getxwindow(xwindowid).windowclose();
}
//从字级页面执行, setxwindowcaption(s,null);
function setxwindowcaption(caption,xwindowid)
{
	getxwindow(xwindowid).setcaption(caption);
}
//返回xwindow对象
function getxwindow(xwindowid)
{
    var obj;
	if (xwindowid == null)
	{
        xwindowid = GetQueryValue(document.location.search, 'xwindowid');
		obj= eval("parent." + xwindowid);
	}
	else
	{
		obj=eval(xwindowid);
	}
	//if(obj.window.tag!=null)alert(obj.window.tag);
    return obj.window;
}
//xwindow_end




