/*
[*表示过时，#表示未完成]

·全局变量，判断当前浏览器：
var isIE、isIE5、isNS、isMoz

·Macromedia Dreamweaver提供的一些函数，一般不推荐使用
function MM_findObj
function MM_showHideLayers
function MM_swapImage
function MM_preloadImages
function MM_swapImgRestore
function MM_jumpMenu
function MM_openBrWindow

·测试使用
function testObjectMembers == tom
function testWrite == tw

·异常处理
function throwError
function getErrorMessage

·自定义对象方法
Object.prototype.Extends
Object.prototype.getInstName
Object.prototype.getClassName

·判断对象
function isEmpty
function isUndefined
function isInstance

·函数相关
function invokeFunction
function getFunctionName

·自定义数组对象方法
Array.prototype.push	4 IE5
Array.prototype.splice	4 IE5（可用来删除元素、插入元素等）
Array.prototype.indexOf
Array.prototype.lastIndexOf
Array.prototype.contains
Array.prototype.trim
Array.prototype.unique
Array.prototype.toUpperCase
Array.prototype.toLowerCase
Array.prototype.sortAsc
Array.prototype.sortDesc
* function spliceArray

·自定义日期对象方法
# Date.prototype.format
Date.prototype.toText
Date.prototype.getDayText
Date.prototype.getDaysBetween
Date.prototype.getBusinessDays=Date.prototype.getDaysBetween
Date.prototype.getWeekdays
Date.prototype.adjust
* function timeNow

·自定义字符串对象方法
String.prototype.trim
String.prototype.countSubstr
String.prototype.right
String.prototype.left
String.prototype.rightback
String.prototype.leftback
String.prototype.begins
String.prototype.ends
String.prototype.contains
String.prototype.repeat
String.prototype.toDate
String.prototype.isDate
String.prototype.isNumber
String.prototype.isNumberP
String.prototype.isNumberN
String.prototype.isInteger
String.prototype.isIntegerP
String.prototype.isIntegerN
String.prototype.middle
String.prototype.crop
String.prototype.insert
String.prototype.replaceAll
String.prototype.lpad
String.prototype.replaceBetween
String.prototype.substrBetween
String.prototype.escapeXML
String.prototype.unescapeXML
String.prototype.stripHTMLTags
function GetUTF8 = getUTF8
* function trim
* function countSubstr
* function getStrRight
* function getStrLeft
* function getStrRightBack
* function getStrLeftBack
* function isStrEnds
* function isStrBegins

* function isDate
* function isNumber
* function isNumberP
* function isNumberN
* function isInteger
* function isIntegerP
* function isIntegerN

·和Notes相关的
function getWebDBName = getWebDbName = getWebDBPath
function getWebDBFolderPath
function getNotesDBPath
function getCurDocUNID
function NameCN
function isNewDoc
function isDocBeingEdited
function logout

·资源相关
function importScript
function importStyleSheet
function isStyleSheetRuleExists
function addStyleSheetRule

·取/设URL参数
function getUrlParaValue
function setUrlParaValue

·窗口/文档相关功能函数
function openWin
function getIframeDocument
function getParentIframe
function autofitParentIframe

·页面显示相关
function showImages 包含 swapImg、swapBackgroundImage
function switchTabSheet
function writeDate
class CTooltip，有全局变量Tooltip

·页面元素属性等
function createElement
function removeStyleProperty
function getAbsoluteLeft
function getAbsoluteTop
function moveToCenter
function moveToWinCenter
function showWindowedElements 包含CPoint、CRectangle

·取/设置页面元素值
function trimForm
function SelectCheckboxes
function getItemValueByName
function getItemValueById
function getItemValue
function setItemValueByName
function setItemValueById
function setItemValue

·XML相关
function SortXmlDom

·本地系统相关
class CIEDownloader，全局变量oDownload
function createLocalTextFile
function isLocalFileExists
function deleteLocalFile
function deleteLocalFolder
function getSpecialFolderPath

·扩展Mozzila（Gecko）兼容IE的函数
showModelessDialog
HTMLDocument.prototype.attachEvent=HTMLElement.prototype.attachEvent
HTMLDocument.prototype.detachEvent=HTMLElement.prototype.detachEvent
Event.prototype.returnValue
Event.prototype.cancelBubble
Event.prototype.srcElement
Event.prototype.fromElement
Event.prototype.toElement
Event.prototype.offsetX
Event.prototype.offsetY
HTMLElement.prototype.insertAdjacentElement
HTMLElement.prototype.insertAdjacentHTML
HTMLElement.prototype.insertAdjacentText
HTMLElement.prototype.outerHTML
HTMLElement.prototype.innerText
HTMLElement.prototype.outerText

*/

/**************************************************************************
 *	公共函数
 *************************************************************************/
var isIE  = ( navigator.appName.indexOf("Microsoft") != -1 );
var isIE5 = ( navigator.appVersion.indexOf("MSIE 5.0") != -1);
var isNS  = ( navigator.appName.indexOf("Netscape") != -1 );
var isMoz = isNS && ( navigator.product == "Gecko" );

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_openBrWindow(theURL,winName,winWidth,winHeight)  //v2.0
{
  para="scrollbars=yes, resizable=yes"
  winFeatures=para + ", width=" + winWidth + ", height=" + winHeight ;
  winName=open(theURL,winName,winFeatures);
  myX=((screen.width-winWidth)*0.5);
  myY=((screen.height-winHeight)*0.2);
  winName.moveTo(myX,myY);
}
//-----------------------------------------------------------------------


//异常处理：抛出一个错误消息、获取一个错误消息
function throwError( strMessage ) {
	if ( isIE5 ) {
		throw Error( 1, strMessage );
	} else {
		throw Error( strMessage );
	}
}
function getErrorMessage( e ) {
	return  (e.message) ? e.message : e.description;
}

//用于类的继承：在构造子类时，先调用this.Extends(父类,其它参数); xxli@2005.04.09
Object.prototype.Extends = function( BaseClass ) {
	if ( arguments.length >= 6 ) throwError('Only can supprot at most 5 parameters.');
	var base;
	if ( arguments.length > 1 ) {
		var a1 = arguments[1], a2 = arguments[2], a3 = arguments[3], a4 = arguments[4];
		base = new BaseClass(a1, a2, a3, a4);
	} else {
		base = new BaseClass();
	}
	for ( var key in base ) {
		if ( !this[key] ) {
		   this[key] = base[key];
		   if ( typeof(base[key]) != 'function' )
			  delete base[key];
		}
	}
	this.base = base;
};
//获得当前对象的随机的Instance名称，且这个名称将会作为一个指向当前对象的全局变量而存在并且可以调用
//主要用于在类的内部做evel或者使用计时器循环等待执行本对象的某些方法时使用
Object.prototype.getInstName = function() {
	if ( !this._m_strInstName ) {
		//将自己作为一个全局变量
		this._m_strInstName = "_" + Math.random().toString().substr(2);
		eval( "window." + this._m_strInstName + " = this" );
	}
	return this._m_strInstName;
}
//获取创建此对象的类的名称
Object.prototype.getClassName = function() {
	return this.constructor.toString().replace( /function +([\w]+) *\((.|\n)*/, "$1" ).replace(/^( |\r|\n)*/g,"").replace(/( |\r|\n)*$/g,"");
}

/* Returns if an object is an empty instance ("" or null)
 * @object: The object
 * Returns: Is the object an empty instance?
 */
function isEmpty(object) {
	return String(object) == "" || object == null || typeof(object) == "undefined";
}
//判断一个对象是否没有定义
function isUndefined( obj ) {
	return typeof(obj) == "undefined";
}
/* Returns if the object is an instance of the specified class
 * @object: The object
 * @clazz : The class
 * Returns: Is the object an instance of the class? */
function isInstance(object, clazz) {
	if ((object == null) || (clazz == null)) return false;
	//
	if (object instanceof clazz) return true;
	if ((clazz == String) && (typeof(object) == "string")) return true;
	if ((clazz == Number) && (typeof(object) == "number")) return true;
	if ((clazz == Array)  && (typeof(object) == "array" )) return true;
	if ((clazz == Function) && (typeof(object) == "function")) return true;
	//base class
	var base = object.base;
	while (base && base != null) {
		if (base == clazz) return true;
		base = base.base;
	}
	return false;
}
/* Invokes the function with the given arguments
 * @functionName: The function name
 * @args: The arguments. If is not an array, uses a single argument. If null, uses no arguments.
 * Returns: The invocation return value */
function invokeFunction( functionName, args ) {
	var arguments;
	if (args == null || isUndefined(args)) {
		arguments = "()";
	} else if (!isInstance(args, Array)) {
		arguments = "(args)";
	} else {
		arguments = "(";
		for (var i = 0; i < args.length; i++) {
			if (i > 0) arguments += ",";
			arguments += "args[" + i + "]";
		}
		arguments += ")";
	}
	return eval(functionName + arguments);
}
//获取函数的名称
function getFunctionName( func ) {
	if ( typeof(func) == "function" ) {
		return func.toString().replace( /function +([\w]+) *\((.|\n)*/, "$1" );
	} else if (typeof(func) == "object") {
		return func.getClassName();
	} else return null;
}

//Array.push for IE5-
if ( typeof(Array.prototype.push) == "undefined" ) {
	Array.prototype.push = function() {
		for( var i=0; i<arguments.length; i++ )
			this[this.length] = arguments[i];
	}
}
//Array.splice for IE5-
//从数组中删除从第nIdx个起的nRemoveCnt（可为0）个元素，并将其后的参数元素从第nIdx位置插入。
if ( typeof(Array.prototype.splice) == "undefined" ) {
	Array.prototype.splice = function(nIdx, nRemoveCnt) {
		var rgRemoved = new Array();
		nRemoveCnt = Number(nRemoveCnt);
		if ( nRemoveCnt < 0  ) return rgRemoved;
		if ( (nRemoveCnt==0) && (arguments.length==2) ) return rgRemoved;
		nIdx = Number(nIdx);
		if ( nIdx < 0 ) nIdx = this.length + nIdx;
		if ( nIdx+nRemoveCnt > this.length ) nRemoveCnt = this.length - nIdx;
		//记录被删除的元素
		for(var i=nIdx; i<nIdx+nRemoveCnt; i++ )
			rgRemoved[rgRemoved.length] = this[i];
		//删除从nIdx起的nRemoveCnt个元素，并保留要插入元素的空间
		var nInsertCnt = arguments.length - 2;
		if ( nInsertCnt < nRemoveCnt ) {
			for(var i=nIdx+nRemoveCnt-nInsertCnt; i<this.length; i++)
				this[i-nRemoveCnt+nInsertCnt] = this[i];
			this.length = this.length - nRemoveCnt + nInsertCnt;
		} else {
			this.length = this.length - nRemoveCnt + nInsertCnt;
			for(var i=this.length-1; i>nIdx+nRemoveCnt-nInsertCnt+1; i--)
				this[i] = this[i+nRemoveCnt-nInsertCnt];
		}
		//根据nRemoveCnt后的参数在位置nIdx插入元素
		for(var i=2; i<arguments.length; i++) {
			this[nIdx+i-2] = arguments[i];
		}
		//返回被删除的元素数组
		return rgRemoved;
	}
}
//some new method for 'Array'
Array.prototype.indexOf = function( v, bIgnoreCase ) {
	for ( var i=0; i<this.length; i++ ) {
		if ( bIgnoreCase && (typeof(v) == "string") ) {
			if ( v.toLowerCase() == String(this[i]).toLowerCase() )
				return i;
		} else if ( v == this[i] ) {
			return i;
		}
	}
	return -1;
}
Array.prototype.lastIndexOf = function(v) {
	for ( var i=this.length-1; i>=0; i-- )
		if ( v == this[i] ) return i;
	return -1;
}
Array.prototype.contains = function( v, bIgnoreCase ) {
	return (this.indexOf(v, bIgnoreCase) != -1);
}
Array.prototype.trim = function() {
	var rgNew = new Array();
	for ( var i=0; i<this.length; i++ )
		if ( this[i]!=null && this[i]!="" && typeof(this[i])!="undefined" )
			rgNew.push(this[i]);
	return rgNew;
}
Array.prototype.unique = function() {
	var rgNew = new Array();
	for ( var i=0; i<this.length; i++ )
		if ( !rgNew.contains(this[i]) )
			rgNew.push(this[i]);
	return rgNew;
}
Array.prototype.toUpperCase = function() {
	var rgNew = new Array();
	for ( var i=0; i<this.length; i++ )
		if ( typeof(this[i]) == "string" )
			rgNew.push(this[i].toUpperCase());
		else
			rgNew.push(this[i]);
	return rgNew;
}
Array.prototype.toLowerCase = function() {
	var rgNew = new Array();
	for ( var i=0; i<this.length; i++ )
		if ( typeof(this[i]) == "string" )
			rgNew.push(this[i].toLowerCase());
		else
			rgNew.push(this[i]);
	return rgNew;
}
Array.prototype.sortAsc = function() {	//升序
	return this.sort( function(a,b) {return (a>b)?1:((a<b)?-1:0)} )
}
Array.prototype.sortDesc = function() {	//降序
	return this.sort( function(a,b) {return (a>b)?-1:((a<b)?1:0)} )
}

//obsolete: 删除一维数组rg中从第nIdx起的nCnt个元素。相当与rg.splice()函数（IE6以下不支持此函数:(）
function spliceArray(rg, nIdx, nCnt){
	if(!nCnt) nCnt=1;
	for(var i=nIdx+nCnt; i<rg.length; i++) rg[i-nCnt] = rg[i];
	rg.length -= nCnt;
}

//TODO: 把日期对象格式化成字符串
Date.prototype.format = function( strMask ) {
}
//把日期对象格式化成字符串 xxli@2005.03.29
Date.prototype.toText = function( strFlag ) {
	var year = this.getFullYear().toString(),
	month = (this.getMonth()<9) ? ("0"+(this.getMonth()+1).toString()) : (this.getMonth()+1).toString(),
	day   = (this.getDate()<10) ? ("0"+this.getDate().toString()) : this.getDate().toString(),
	hour  = (this.getHours()<10) ? ("0"+this.getHours().toString()) : this.getHours().toString(),
	min   = (this.getMinutes()<10) ? ("0"+this.getMinutes().toString()) : this.getMinutes(),
	sec   = (this.getSeconds()<10) ? ("0"+this.getSeconds().toString()) : this.getSeconds(),
	msec  = (this.getMilliseconds()<10) ? ("00"+this.getMilliseconds().toString()) : (this.getMilliseconds()<100)?("0"+this.getMilliseconds().toString()) : this.getMilliseconds().toString();

	switch ( ((!strFlag)?"":strFlag).toString().toUpperCase()) {
	case "D0":	//Year, month, and day
		return year + "-" + month + "-" + day;
	case "D1":	//Month and day, year if it is not the current year
		return (((new Date()).getYear() != this.getYear)?(year+"-"):"") + month + "-" + day;
	case "D2":	//Month and day
		return month + "-" + day;
	case "D3":	//Month and year
		return year + "-" + month;
	case "D4":	//Year, month, and day
		return year + "年" + month + "月" + day + "日";
	case "T0":	//Hour, minute, and second
		return hour + ":" + min + ":" + sec;
	case "T1":	//Hour and minute
		return hour + ":" + min;
	case "T2":	//Hour, minute, second, and millisecond
		return hour + ":" + min + ":" + sec + "." + msec;
	case "S0":	//Date only == "D0"
		return year + "-" + month + "-" + day;
	case "S1":	//Time only == "T0"
		return hour + ":" + min + ":" + sec;
	case "S2":	//Date and time
		return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
	case "S3":	//Date and time with millisecond
		return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec + "." + msec;
	case "S4":	//Year, month, day and weekday
		return year + "-" + month + "-" + day + " " + this.getDayText(arguments[1]);
	case "S5":	//Month, day and weekday
		return month + "-" + day + " " + this.getDayText(arguments[1]);
	case "JA":	//join all
		return year + month + day + hour + min + sec + msec;
	default:	//=="S2"
		return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
	}
}
//返回getDay代表的星期几 xxli@2005.03.29
Date.prototype.getDayText = function(strLang) {
	strLang = (strLang) ? strLang: "CN";
	var EN  = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
	var ENS = ["Sun.", "Mon.", "Tues.", "Wed.", "Thurs.", "Fri.", "Sat."];
	var CN  = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
	return eval( strLang + "[" + this.getDay() + "]" );
}
/* 计算日期之间的间隔。包括开始和结束那天，若@date<this，则返回负数：
 *	返回到3.28的非周六周日的天数 (new Date()).getDaysBetween(new Date("2005/03/28"), [0,6])
 *	返回到4.09的非周六周日，且不包含4.2和今天的天数 (new Date()).getDaysBetween(new Date("2005/04/09"), [0,6], ["2005/04/02",new Date()])
 * xxli@2005.03.29
 */
Date.prototype.getDaysBetween = function( date, daysToExclude, datesToExclude ) {
	if (this>date) var s=new Date(date), e=new Date(this);
	else var s=new Date(this), e=new Date(date);
	e.setHours(0,0,0,0), s.setHours(0,0,0,0);
	//总相差天数
	var nDiffDays  = Math.floor((e - s) / 86400000) + 1;
	var nAdjust = 0;
	//排除星期**
	if ( daysToExclude ) {
		nAdjust = Math.floor(nDiffDays/7) * daysToExclude.length;
		for (var i=nDiffDays%7-1; i>=0; i--) {
			if ( daysToExclude.contains( (e.getDay()-i+7)%7 ) ) nAdjust ++;
		}
	}
	//排除日期
	if ( datesToExclude ) {
		for(var i=0,d=null; i<datesToExclude.length; i++,d=null) {
			if ( typeof(datesToExclude[i]) == "string" )
				d = datesToExclude[i].toDate();
			else if( (typeof(datesToExclude[i]) == "object") && datesToExclude[i].getBusinessDays )
				d = datesToExclude[i]
			if ( (d!=null) &&
				 !daysToExclude.contains(d.getDay()) &&
				 ((d>s && d<e) || (d.toString()==s.toString() || d.toString()==e.toString())) )
				nAdjust ++
		}
	}
	//返回
	return (s>e) ? (-(nDiffDays - nAdjust)) : (nDiffDays - nAdjust);
}
Date.prototype.getBusinessDays = Date.prototype.getDaysBetween;
//取两个日期之间的非周六周日的天数（包括开始和结束那天）
Date.prototype.getWeekdays = function( date ) {
	return this.getDaysBetween( date, [0,6] );
}
//Adjusts the time-date value and return a new Date object
Date.prototype.adjust = function ( years, months, days, hours, minutes, seconds, milliseconds ) {
	var dtNew = new Date(this);
	years = parseInt(years), months = parseInt(months), days = parseInt(days),
	hours = parseInt(hours), minutes = parseInt(minutes), seconds = parseInt(seconds), milliseconds = parseInt(milliseconds);
	years  = (years) ? (dtNew.getFullYear()+years) : dtNew.getFullYear();
	months = (months) ? (dtNew.getMonth()+months) : dtNew.getMonth();
	days   = (days) ? (dtNew.getDate()+days) : dtNew.getDate();
	hours  = (hours) ? (dtNew.getHours()+hours) : dtNew.getHours();
	minutes = (minutes) ? (dtNew.getMinutes()+minutes) : dtNew.getMinutes();
	seconds = (seconds) ? (dtNew.getSeconds()+seconds) : dtNew.getSeconds();
	milliseconds = (milliseconds) ? (dtNew.getMilliseconds()+milliseconds) : dtNew.getMilliseconds();
	dtNew.setFullYear( years, months, days );
	dtNew.setHours( hours, minutes, seconds, milliseconds );
	return dtNew;
}

/* obsolete: 几个常用字符串处理函数
 * Update: xxli@2004.11.19 */
function trim(s){return (s.replace(/^(( )|(　)|\r|\n|\t)*/g,"")).replace(/(( )|(　)|\r|\n|\t)*$/g,"")}/*v1.1 去除字串s头尾空格、回车、制表符*/
function countSubstr(s,x,i){var S=s;var X=x;if(i){S=s.toLowerCase();X=x.toLowerCase()}var count=0;var pos=S.indexOf(X);while(pos!=-1){count++;pos=S.indexOf(X,pos+X.length)}return count}/*计算字串s中x出现次数，i为是否区分大小写*/
function getStrRight(s,x,i){if(s==null)return"";var S=s;var X=x;if(i){S=s.toLowerCase();X=x.toLowerCase()}var i=S.indexOf(X);return(i==-1)?"":s.slice(i+x.length)}/*获得串s中x右边的串，没找到返回空""*/
function getStrLeft(s,x,i){if(s==null)return"";var S=s;var X=x;if(i){S=s.toLowerCase();X=x.toLowerCase()}var i=S.indexOf(X);return(i==-1)?"":s.substring(0,i)}/*获得串s中x左边的串*/
function getStrRightBack(s,x,i){if(s==null)return"";var S=s;var X=x;if(i){S=s.toLowerCase();X=x.toLowerCase()}var i=S.lastIndexOf(X);return(i==-1)?"":s.slice(i+x.length)}/*获得串s中x右边的串，从右往左搜*/
function getStrLeftBack(s,x,i){if(s==null)return"";var S=s;var X=x;if(i){S=s.toLowerCase();X=x.toLowerCase()}var i=S.lastIndexOf(X);return(i==-1)?"":s.substring(0,i)}/*获得串s中x右边的串，从右往左搜*/
function isStrEnds(s,x,i){if(s==null||x==null||s.length<x.length)return false;var S=s;var X=x;if(i){S=s.toLowerCase();X=x.toLowerCase()}return(S.lastIndexOf(X)==S.length-X.length)}/*判断串s是否以x结尾*/
function isStrBegins(s,x,i){if(s==null||x==null||s.length<x.length)return false;var S=s;var X=x;if(i){S=s.toLowerCase();X=x.toLowerCase()}return(S.indexOf(X)==0)}/*判断串s是否以x开头*/
var getStrBackRight=getStrRightBack;
var getStrBackLeft=getStrLeftBack;

//去除字串头尾空格、回车、制表符
String.prototype.trim = function() {
	return (this.replace(/^(( )|(　)|\r|\n|\t)*/g,"")).replace(/(( )|(　)|\r|\n|\t)*$/g,"");
}
//计算字串中x出现次数，i为是否区分大小写
String.prototype.countSubstr = function(x,i) {
	var S=this,X=x,count=0;
	if(i){S=S.toLowerCase();X=x.toLowerCase()}
	var pos=S.indexOf(X);
	while(pos!=-1){count++;pos=S.indexOf(X,pos+X.length)}
	return count;
}
//获得串中x右边的串，没找到返回空""
String.prototype.right = function(x,i) {
	var s=this;if(s==null)return"";var S=s;var X=x;if(i){S=s.toLowerCase();X=x.toLowerCase()}var i=S.indexOf(X);return(i==-1)?"":s.slice(i+x.length);
}
//获得串中x左边的串
String.prototype.left = function(x,i) {
	var s=this,S=s,X=x;if(i){S=s.toLowerCase();X=x.toLowerCase()}var i=S.indexOf(X);return(i==-1)?"":s.substring(0,i);
}
//获得串中x右边的串，从右往左搜
String.prototype.rightback = function(x,i) {
	var s=this,S=s,X=x;if(i){S=s.toLowerCase();X=x.toLowerCase()}var i=S.lastIndexOf(X);return(i==-1)?"":s.slice(i+x.length);
}
//获得串中x右边的串，从右往左搜
String.prototype.leftback = function(x,i) {
	var s=this,S=s,X=x;if(i){S=s.toLowerCase();X=x.toLowerCase()}var i=S.lastIndexOf(X);return(i==-1)?"":s.substring(0,i);
}
//判断串是否以x开头
String.prototype.begins = function(x,i) {
	var s=this,S=s,X=x;
	if(x==null||s.length<x.length) return false;
	if(i){S=s.toLowerCase();X=x.toLowerCase()}
	return(S.indexOf(X)==0);
}
//判断串是否以x结尾
String.prototype.ends = function(x,i) {
	var s=this,S=s,X=x;
	if(x==null||s.length<x.length) return false;
	if(i){S=s.toLowerCase();X=x.toLowerCase()}
	return(S.lastIndexOf(X)==S.length-X.length);
}
//判断串是否包含x
String.prototype.contains = function(x,i) {
	if(typeof(x)!="string") return false;
	if(i) return (this.toLowerCase().indexOf(x.toLowerCase()) != -1);
	return (this.indexOf(x) != -1);
}
//判断字符串是否是日期
String.prototype.isDate = function() {
	var s = this.replace(/-|\./g,"/").replace(/\/0*/g,"/").replace(/^0*/g,"");
	var a = new Date(s);
	var ns1 = a.getFullYear() + "/" + (a.getMonth()+1) + "/" + a.getDate();	// y/m/d
	var ns2 = (a.getMonth()+1) + "/" + a.getDate() + "/" + a.getFullYear();	// m/d/y
	var ns3 = a.getDate() + "/" + (a.getMonth()+1) + "/" + a.getFullYear();	// d/m/y
	return ( (ns1==s) || (ns2==s) || (ns3==s));
}
//转换为日期对象，失败则返回null
String.prototype.toDate = function () {
	if ( this.isDate() )
		return new Date( this.replace(/-|\./g,"/").replace(/\/0*/g,"/").replace(/^0*/g,"") );
	else
		return null;
}
//将当前串重复n次，返回新串
String.prototype.repeat = function(n) {
	if( n < 0 ) return "";
	for ( var i=0,s=""; i<n; i++ )
		s += this.valueOf();
	return s;
}
//判断字符串是否为数字、正负数字，整数、正负整数
String.prototype.isNumber = function() { return isFinite(this); } //!isNaN(s)
String.prototype.isNumberP = function() { return Number(this)>0; }
String.prototype.isNumberN = function() { return Number(this)<0; }
String.prototype.isInteger = function() { return /^[-|+]?\d+$/.test(this);	}	//暂不支持科学计数法的s
String.prototype.isIntegerP = function() { return this.isInteger() && this.isNumberP(); }
String.prototype.isIntegerN = function() { return this.isInteger() && this.isNumberN(); }
//与notes相应函数兼容。取s1和s2之间的字串。
//若s1找不到或s2<0返回空
//s1 字符串  s2 字符串 :  返回2串之间部分   s2找不到返回s1后的部分
//s1 字符串  s2 数字   :  返回s1 串后s2个字符
//s1 数字    s2 数字   :  第s1位后s2个字符
//s1 数字    s2 字符串 :  第s1位后 s2之前的部分 若s2找不到 返回所有s1位后的部分
String.prototype.middle = function(s1,s2) {
	var s = this;
	var	i = (typeof(s1)=="number") ? parseInt(s1):s.indexOf(s1);
	if( i == -1 ) return "";
	i += (typeof(s1) == "string") ? s1.length : 0;
	if( typeof(s2) == "number" ) {
		if( s2 < 0 ) return "";
		else return s.substring(i,i+s2);
	} else {
		var j = s.indexOf(s2,i);
		return s.substring(i,(j>=i)?j:s.length);
	}
}
//从pos位置，删除size个字符，包括pos位置的字符。
//若没有参数size，则删除pos位置以后的所有字符。
String.prototype.crop = function( pos, size ) {
	if ( typeof(size)=="undefined" ) size = this.length-1;
	if ( size<=0 || pos<0 ) return this;
	return this.substring(0,pos) + this.substring(pos+size);
}
//将字符串s插入到pos位置，原位置的及其以后的字符后移
String.prototype.insert = function( s, pos ) {
	if ( typeof(pos)=="undefined" || pos<0 || !s ) return "";
	return this.substring(0,pos) + String(s) + this.substring(pos);
}
//将字串用字c补充左部，到size长度
String.prototype.lpad = function( size, c ) {
	if ( this.length >= size ) return this;
	return String(c).repeat(size-this.length) + this;
}
//替换所有find串为replace串
String.prototype.replaceAll = function ( find, replace ) {
	if ( typeof(replace) == "undefined" ) replace = "";
	return this.split(String(find)).join(replace);
}
/* 替换sFindBegin和sBeginEnd之间的字符串为sReplace。
 * @bIncFind: 是否同时替换掉sFindBegin/End，默认为false
 * @bRestrictPair: 是否严格匹配开始和结束，默认为false
 * 这里先假设字符串中没有控制字符1/2/3，否则需要再多做点处理：（
 */
//这里先假设字符串中没有控制字符1/2/3，否则需要再多做点处理：（
String.prototype.replaceBetween = function( sFindBegin, sFindEnd, sReplace, bIncFind, bRestrictPair ) {
	//将sFind替换为特殊字符
	var c1 = String.fromCharCode(0x01);
	var c2 = String.fromCharCode(0x02);
	var c3 = String.fromCharCode(0x03);
	var s1, s = this.replaceAll(sFindBegin, c1).replaceAll(sFindEnd, c2);
	//将$字符替换成特殊的单个字符，以免正则表单式替换时错误。
	sFindBegin = String(sFindBegin).replace( /\$/g, c3 );
	sFindEnd   = String(sFindEnd).replace  ( /\$/g, c3 );
	sReplace   = String(sReplace).replace  ( /\$/g, c3 );
	//开始替换
	if ( bIncFind ) {
		if ( bRestrictPair ) {
			while ( s1 != s ) {
				if (s1) s = s1;
				s1 = s.replace( /([^\x01]*)\x01[^\x01\x02]*\x02([^\x01]*)/g, "$1"+sReplace+"$2");
			}
			s = s1;
		} else
			s = s.replace( /([^\x01]*)\x01(([^\x01]*\x01[^\x02]*\x02)|[^\x02])*(\x02|[^\x01])*\x02([^\x01]*)/g, "$1"+sReplace+"$5" );
	} else {
		if ( bRestrictPair ) {
			while ( s1 != s ) {
				if (s1) s = s1;
				s1 = s.replace( /([^\x01]*)\x01[^\x01\x02]*\x02([^\x01]*)/g, "$1"+sFindBegin+sReplace+sFindEnd+"$2");
			}
			s = s1;
		} else
			s = s.replace( /([^\x01]*\x01)(([^\x01]*\x01[^\x02]*\x02)|[^\x02])*(\x02|[^\x01])*(\x02[^\x01]*)/g, "$1"+sReplace+"$5" );
	}
	//恢复那几个特殊字符
	return s.replace( /\x01/g, sFindBegin).replace(/\x02/g, sFindEnd).replace(/\x03/g,"$");
}
/* 取出sBegin和sEnd之间的字符串，包括sFindBegin/End，中间以sDelimit（默认为,）分隔。
 * 这里先假设字符串中没有控制字符1/2，否则需要再多做点处理：（
 */
String.prototype.substrBetween = function( sFindBegin, sFindEnd, sDelimit ) {
	var rgstrRet = new Array();
	//默认分隔符为分号
	sDelimit = (!sDelimit) ? "," : String(sDelimit);
	//将sFind*替换为特殊字符
	var c1=String.fromCharCode(0x01), c2=String.fromCharCode(0x02);
	var s = this.replaceAll(sFindBegin, c1).replaceAll(sFindEnd, c2);
	if ( !isIE5 ) {
	//非IE5，可支持String.replace的第二个参数为function
		//可支持四层嵌套
		s.replace( /(\x01([^\x01\x02]|(\x01([^\x01\x02]|(\x01([^\x01\x02]|(\x01[^\x01\x02]*\x02))*\x02))*\x02))*\x02)/g,
					function(s,s1){ rgstrRet[rgstrRet.length]=s1; return ""; }
		);
	} else {
	//IE5，特殊处理。可无穷嵌套
		var nE, nB = s.indexOf( c1 );
		while ( nB != -1 ) {
			nE = getEndIndex( s, nB );
			if ( nE != -1 ) {
				rgstrRet[rgstrRet.length] = s.substring( nB, nE+1 );
				nB = s.indexOf( c1, nE+1 );
			} else break;
		}
		//函数：从nB位开始，取对应的c2结束符的位置，没有则返回-1
		function getEndIndex( s, nB ) {
			var nPair = 0, c;
			for ( var i=nB+1; i<s.length; i++ ) {
				c = s.charAt(i);
				if ( c == c1 ) {
					nPair ++;
				} else if ( c == c2 ) {
					if ( nPair == 0 ) return i;
					nPair --;
				}
			}
			return -1;
		}
	}
	//返回
	return rgstrRet.unique().join(sDelimit).replace(/\x01/g, sFindBegin).replace(/\x02/g, sFindEnd);
}
//将"<"等字符转换成转义字如"&lt;"
String.prototype.escapeXML = function() {
	return this.replace(/&/g, "&amp;")
		.replace(/</g, "&lt;")
		.replace(/>/g, "&gt;")
		.replace(/"/g, "&quot;")
		.replace(/'/g, "&apos;");
}
//将转义字如"&lt;"转换成"<"等字符
String.prototype.unescapeXML = function() {
	return this.replace( /&apos;/g, "'" )
        .replace( /&quot;/g, "\"" )
		.replace( /&gt;/g,   ">"  )
		.replace( /&lt;/g,   "<"  )
		.replace( /&amp;/g,  "&"  );
}
//简单的删除HTML标记
String.prototype.stripHTMLTags = function() {
	return this.replace( /<[^>]+>/g, "" ).unescapeXML().replace( /&nbsp;/g , " " );
}

//obsolete: 判断字符串是否为日期、数字、正负数字，整数、正负整数等格式
function isDate(s){ return s.isDate(); }
function isNumber(s) {	return isFinite(s); }
function isNumberP(s) {	return ( Number(s) > 0 );}
function isNumberN(s) {	return ( Number(s) < 0 ); }
function isInteger(s) {	return /^[-|+]?\d+$/.test(s); }
function isIntegerP(s) { return isInteger(s) && isNumberP(s); }
function isIntegerN(s) { return isInteger(s) && isNumberN(s); }

//为保持兼容性，escape语句均改为此
//为防止多次转换（%->%25），加bForce参数和isConverted函数，若bForce不真则判断一下
//Update: xxli@2004.07.05	[*] 增加数字0-9为保留字符
var getUTF8 = GetUTF8;
function GetUTF8( chsStr, bForce )
{
	//--------
	var hexToken = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
	function isReserve( code ) {
		flag = false;
		if( code > 64 && code < 91 ) flag = true;	//A-Z
		else if ( code > 96 && code < 123 ) flag = true;	//a-z
		else if ( code > 47 && code <58 ) flag = true;		//0-9
		else if ( code == 46 || code == 47 || code == 58 || code == 63 || code == 64) flag = true;	//./:?@
		return flag;
	}
	var strHexToken = hexToken.toString();
	function isConverted( str, idx ) {
		if ( bForce ) return false;
		if (str.charAt(idx)=='%') {
			if ( (strHexToken.indexOf(str.charAt(idx+1)) != -1) && (strHexToken.indexOf(str.charAt(idx+2)) != -1) )
				return true;
		}
		return false;
	}
	//----------
	var result = "";
	//if( typeof(encodeURI) == "function" ) {
	//	return encodeURI( chsStr );
	//}
	for( var i = 0; i < chsStr.length; i++ ) {
		var code = chsStr.charCodeAt( i );
		if( isReserve( code ) ) {
			result += chsStr.charAt(i);
		} else if ( isConverted(chsStr,i) ) {
			result += chsStr.substr(i, 3);
			i += 2;
		} else if ( code < 128 ) {
			result += '%' + hexToken[Math.floor( code / 16)] + hexToken[code % 16];
		} else if ( code < 2048 ) {
			var partA = Math.floor(code / 64);
			var partB = code % 64;
			result += '%' + hexToken[12 + Math.floor(partA / 16)] + hexToken[partA % 16];
			result += '%' + hexToken[8 + Math.floor(partB / 16)] + hexToken[partB % 16];
		} else {
			var partA = Math.floor(code / 4096);
			var partB = ( Math.floor(code / 64) ) % 64;
			var partC = code % 64;
			result += '%E' + hexToken[partA];
			result += '%' + hexToken[8 + Math.floor(partB / 16)] + hexToken[partB % 16];
			result += '%' + hexToken[8 + Math.floor(partC / 16)] + hexToken[partC % 16];
		}
	}
	return result;
}

//获得Web数据库路径：loc - 完整路径
//xxli@2004.10.22
var getWebDbName = getWebDBName;
var getWebDBPath = getWebDBName;
function getWebDBName( loc )
{
	if (!loc) loc = window.location.pathname;
	loc = GetUTF8( loc.substr( 0, loc.toLowerCase().indexOf(".nsf")+4 ) );
	return loc.replace(/%2F/gi, "/")
}
//获得Web数据库所在文件夹的路径：
//xxli@2005.03.03
function getWebDBFolderPath( loc )
{
	var strWebDBPath = getWebDBPath( loc );
	return strWebDBPath.substring( 0,(strWebDBPath.lastIndexOf('/') + 1) );
}

//根据Url获得Notes数据库的相对Data的路径
//xxli@2004.12.20
function getNotesDBPath( loc, bUTF8 )
{
	if (!loc) loc = window.location.pathname;
	loc = loc.substr( 0, loc.toLowerCase().indexOf(".nsf")+4 );
	loc = loc.substring( loc.indexOf("//")+2 );
	loc = loc.substring( loc.indexOf("/") +1 );
	return (bUTF8) ? getUTF8(loc) : loc;
}

//根据url获得当前正在打开的文档的unid
//xxli@2005.03.23
function getCurDocUNID(loc) {
	var s = (loc) ? loc : location.href;
	s = s.substring(0, s.indexOf("?"));
	s = s.substring(s.lastIndexOf("/")+1);
	return s;
}

//==Lotus公式@Name([CN];p)
function NameCN(p) {
	function getCN(s){var i=s.indexOf("/");var s1=s;if(i!=-1)s1=s.substring(0,i);i=s1.indexOf("CN=");return(i==-1)?s1:s1.slice(i+3)}
	if(typeof(p)=="string") return getCN(p);
	else{for(var i=0;i<p.length;i++)p[i]=getCN(p[i]); return p}
}

//判断当前文档是否是新文档
//==Lotus公式@IsNewDoc
function isNewDoc() {
	return (location.href.toUpperCase().indexOf("?OPENFORM") != -1);
}
//判断当前文档是否正处于编辑状态
//==Lotus公式IsDocBeingEdited
function isDocBeingEdited() {
	if ( location.href.toUpperCase().indexOf("?EDIT") != -1 ) return true;
	if ( document.forms.length > 0 )
		if ( document.forms[0].getAttribute("method") && document.forms[0].getAttribute("action") )
			return true;
	return false;
}

//注销（Domino HTTP登录）
function logout( strRedirectTo ) {
	var strUrl = "/names.nsf?logout";
	if ( strRedirectTo )
		strUrl += "&RedirectTo=" + GetUTF8(strRedirectTo);
	top.location = strUrl;
}

//Version: 2.07
//打开新窗口：标题为其父窗口的url_新窗口的url
//Created:	xxli@2003.12
//Updated:	xxli@2004.08.25	[*] 2.x版本同1.x版本主要改动在参数和返回值上
//			xxli@2005.01.12
//注：因为有返回值，在标记的href中调用时，务必在最后添加void(0)语句
function openWin(whref, wname, wfeatures, wwidth, wheight)
{
	whref = whref.replace(/^(( )|(　)|\r|\n|\t)*/g,"").replace(/(( )|(　)|\r|\n|\t)*$/g,"");
	var regExp = /\W/gi;	// \W = [^A-Za-z0-9_]
	if (!wname) wname= window.location.href.replace(regExp, "") + "_" + whref.replace(regExp,"");
	if ( wfeatures ) wfeatures = wfeatures.replace(/;/g, ",").replace(/ /g, "");
	if ( (typeof(wwidth)!="undefined") && (typeof(wheight)!="undefined") )	{
		wfeatures +=  ",width=" + wwidth + ",height=" + wheight;
		var x = parseInt( (screen.availWidth-wwidth-10)   * 0.5 );
		var y = parseInt( (screen.availHeight-wheight-30) * 0.5 );
		if (wfeatures.indexOf("left") == -1) {
			wfeatures +=  ",left=" + x;
			wfeatures +=  ",screenX=" + x;
		}
		if (wfeatures.indexOf("top") == -1) {
			wfeatures +=  ",top=" + y;
			wfeatures +=  ",screenY=" + y;
		}
	};
	var oWin = (wfeatures) ? window.open(whref,wname,wfeatures) : window.open(whref,wname);
	if ( wfeatures && x && y )
		oWin.moveTo( x, y );
	return oWin;
}

//obsolete: 获得当前精确时间（year.month.day-hour:min.sec.ms）－－> 可用Date.toText代替
function timeNow() {
	now = new Date();
	return now.getFullYear().toString() + "."
		 + ( (now.getMonth()<9)		? ("0"+(now.getMonth()+1).toString()) : (now.getMonth()+1).toString() ) + "."
		 + ( (now.getDate()<10)		? ("0"+now.getDate().toString())      : now.getDate().toString() ) + "-"
		 + ( (now.getHours()<10)	? ("0"+now.getHours().toString())     : now.getHours().toString() ) + ":"
		 + ( (now.getMinutes()<10)	? ("0"+now.getMinutes().toString())   : now.getMinutes() ) + "."
		 + ( (now.getSeconds()<10)	? ("0"+now.getSeconds().toString())   : now.getSeconds() ) + "."
		 + ( (now.getMilliseconds()<10)? ("00"+now.getMilliseconds().toString()) : (now.getMilliseconds()<100)?("0"+now.getMilliseconds().toString()) : now.getMilliseconds().toString() );
}

//打印当前日期
function writeDate( bYear ) { document.write( (new Date()).toText((bYear)?"S4":"S5") ); }

//Version: 1.00
//选中当前所有复选框
//Created:	xxli@2004.6.16
function SelectCheckboxes( sCheckboxName, bChecked )
{
  var rgic = document.getElementsByName( sCheckboxName )
  for ( var i=0; rgic.length>i; i++)
	  rgic[i].checked = bChecked
}

//根据名称，获取所有同名的域的域值（数组），若是checkbox/radio/select则返回被选中的值，若是div则返回innerHTML
function getItemValueByName( strName, bIncludeDisabled ) {
	var rgel = getElementsByName();
	if ( rgel.length == 0 ) return null;
	return getItemValue( rgel );
	//根据Name，取所有HTML元素。返回元素数组
	function getElementsByName() {
		var rgelRet = new Array();
		var rgel = document.getElementsByName( strName );
		for ( var i=0; i<rgel.length; i++ )
			if ( !(bIncludeDisabled && rgel[i].disabled) )
				rgelRet[rgelRet.length] = rgel[i];
		return rgelRet;
	}
}
//根据ID，获取域值（数组），若是checkbox/radio/select则返回被选中的值，若是div则返回innerHTML
function getItemValueById( strId, bIncludeDisabled ) {
	var el = document.getElementById(strId);
	if ( !el || (bIncludeDisabled && el.disabled) ) return null;
	return getItemValue( [el] );
}
//获取域（HTML元素）的值（数组），若是checkbox/radio/select则返回被选中的值，若是div则返回innerHTML
//xxli@2005.03.31
function getItemValue( rgel ) {
	if ( typeof(rgel.length) == "undefined" ) rgel = [rgel];
	var rgRet = new Array();
	for ( var i=0; i<rgel.length; i++ ) {
		var el = rgel[i];
		switch ( el.tagName.toUpperCase() ) {
		case "INPUT":
			switch (el.type) {
			case "checkbox":
			case "radio":
				if ( el.checked )
					rgRet[rgRet.length] = el.value;
				break;
			default:
				rgRet[rgRet.length] = el.value;
				break;
			}
			break;
		case "SELECT":
			if ( el.multiple ) {
				for ( var j=0; j<el.options.length; j++)
					if ( el.options[j].selected )
						rgRet[rgRet.length] = el.options[j];
			} else {
				rgRet[rgRet.length] = el.options[el.selectedIndex];
			}
			break;
		case "SPAN":
		case "DIV":
			rgRet[rgRet.length] = el.innerHTML;
			break;
		default:
			rgRet[rgRet.length] = el.value;
			break;
		}
	}
	return rgRet;
} //end of getItemValue

//根据名称，设置所有同名的域的域值，若是checkbox/radio/select则选中对应值的项，若是div则设置innerHTML，其它直接设置value
function setItemValueByName( strName, rgstrValue, bIncludeDisabled ) {
	var rgel = getElementsByName();
	if ( rgel.length == 0 ) return;
	return setItemValue( rgel, rgstrValue );
	//根据Name，取所有HTML元素。返回元素数组
	function getElementsByName() {
		var rgelRet = new Array();
		var rgel = document.getElementsByName( strName );
		for ( var i=0; i<rgel.length; i++ )
			if ( !(bIncludeDisabled && rgel[i].disabled) )
				rgelRet[rgelRet.length] = rgel[i];
		return rgelRet;
	}
}
//根据ID，设置域值（数组），若是checkbox/radio/select则选中对应值的项，若是div则设置innerHTML，其它直接设置value
function setItemValueById( strId, rgstrValue, bIncludeDisabled ) {
	var el = document.getElementById(strId);
	if ( !el || (bIncludeDisabled && el.disabled) ) return;
	return setItemValue( [el], rgstrValue );
}
//设置域（HTML元素）的值，若是checkbox/radio/select则选中对应值的项，若是div则设置innerHTML，其它直接设置value
//xxli@2005.03.31
function setItemValue( rgel, rgstrValue ) {
	if ( (typeof(rgstrValue) == "undefined") || (rgstrValue == null) ) return false;
	if ( typeof(rgel.length) == "undefined" ) rgel = [rgel];
	if ( typeof(rgstrValue) != "object" ) rgstrValue = [rgstrValue];
	for ( var i=0; i<rgel.length; i++ ) {
		var el = rgel[i];
		switch ( el.tagName.toUpperCase() ) {
		case "INPUT":
			switch (el.type) {
			case "checkbox":
			case "radio":
				if ( !el.checked && rgstrValue.contains(el.value) )
					el.click();
				break;
			default:
				el.value = rgstrValue.toString();
				break;
			}
			break;
		case "SELECT":
			if ( el.multiple ) {
				for ( var j=0; j<el.options.length; j++)
					if ( rgstrValue.contains(el.options[j].value) )
						el.options[j].selected = true;
			} else
				el.value = rgstrValue.toString();
			break;
		case "SPAN":
		case "DIV":
			el.innerHTML = rgstrValue.toString();
			break;
		default:
			el.value = rgstrValue.toString();
			break;
		}
	}
} //end of setItemValue

//获取一个HTML元素在整个页面中的x/y坐标
function getAbsoluteLeft ( el ) {
	var nLeft = el.offsetLeft;
	while ( el.offsetParent != null ) {
		el = el.offsetParent;
		nLeft += el.offsetLeft;
	}
	return nLeft;
}
function getAbsoluteTop ( el ) {
	var nTop = el.offsetTop;
	while ( el.offsetParent != null ) {
		el = el.offsetParent;
		nTop += el.offsetTop;
	}
	return nTop;
}

//把一个元素el移动到另一个元素elParent的中央
function moveToCenter( elParent, el, bVisible ) {
	try {
		var x = elParent.scrollLeft + (elParent.clientWidth-el.offsetWidth)/2;
		var y = elParent.scrollTop  + (elParent.clientHeight-el.offsetHeight)/2;
		el.style.left = ((x < 0) ? 0 : x) + "px";
		el.style.top  = ((y < 0) ? 0 : y) + "px";
		el.style.position = "absolute";
		if ( bVisible ) {
			if (el.style.visibility=="hidden") el.style.visibility = "visible";
			if (el.style.display=="none") el.style.display = "inline";
		}
	} catch (e) {}
}
//把一个Element如层/图片移到窗口中间
function moveToWinCenter( el, bVisible ) {
	moveToCenter( document.body, el, bVisible );
}

//把所有input和textarea控件trim一把
function trimForm()
{
	var rgInput = document.getElementsByTagName("input");
	for ( var i=0; i<rgInput.length; i++ ) {
		try {
			if ( !["password","file"].contains(rgInput[i].type,true) && rgInput[i].value ) {
				rgInput[i].value = rgInput[i].value.trim();
			}
		} catch (e) {}
	}
	rgInput = document.getElementsByTagName("textarea");
	for ( var i=0; i<rgInput.length; i++ ) {
		if ( rgInput[i].value ) {
			var s = rgInput[i].value.trim();
			//值的长度<500K，且trim后没有变化，再重新赋值
			if ( (s != rgInput[i].value) && s.length<500000 ) {
				rgInput[i].value = s;
			}
		}
	}
}

//Version 1.02
//切换页签（图片）
//参数：n－当前显示的页签号；图片id属性和此图片当前要显示的图名交叉传递
//例：<input type="image" id="img1" src="ybk1.gif" onclick="return switchTabsheet(1,'img1','ybk1.gif','img2','xxk2.gif')">
//Update: xxli@2004.12.20
function switchTabSheet(n)
{
	for ( var i=1; i<arguments.length; i+=2 ) {
		try {
			if ( arguments[i+1] ) {
				document.getElementById("lTabSheet"+((i+1)/2)).style.display = "none";
				document.getElementById(arguments[i]).src = g_strImgPath + arguments[i+1];
			}
		} catch(e) {}
	}
	try {
		document.getElementById("lTabSheet"+n).style.display = "block";
	} catch(e){}
	return false;
}

//Version 1.04
//图片的鼠标移入移出时间时，替换显示的图片：src1/src2
//called by `showImages`
function swapImg(elImg, n)
{
	var s = elImg.getAttribute("src" + n);
	if ( !s ) return;
	elImg.src = s;
}
//Version 1.03
//图片的鼠标移入移出时间时，替换显示的图片：background1/background2
//called by `showImages`
function swapBackgroundImage(el, n)
{
	var s = el.getAttribute("background" + n);
	if ( !s ) return;
	el.style.backgroundImage = "url(" + s  + ")";
}
/*Version 1.13
 * 显示所有图片
 * 注：一般情况下需要图片路径的全局变量 g_strImgPath
 * @src?：
 *     src1一般图片；src2，onmouseover事件显示的图片；src3，onmousedown显示的图片，暂未实现；src4，点击后的图片，自行处理
 * Update: xxli@2005.03.31
 */
function showImages()
{
	/* for "img" tags */
	var rgEl = document.images;
	for ( var i=0; i<rgEl.length; i++ )
		if (  ! rgEl[i].src ) setSrc( rgEl[i] );
	/* for "input type=image" tags */
	rgEl = document.getElementsByTagName("input");
	for ( var i=0; i<rgEl.length; i++ ) {
		if ( (rgEl[i].type == "image") && (!rgEl[i].src) )
			setSrc( rgEl[i] );
	}
	function setSrc( el ) {
		if ( el.getAttribute("src1") ) {
			el.src = getImgUrl( el.getAttribute("src1") );
			el.setAttribute( "src1", el.src );
		} else if ( el.name != "" )
			el.src = getImgUrl( el.name );
		//设置onmouseover/onmouseout属性
		if ( el.getAttribute("src1") && el.getAttribute("src2") ) {
			el.setAttribute( "src2", getImgUrl(el.getAttribute("src2")) );
			if ( !el.onmouseover )
				el.onmouseover = function() { swapImg(this,2) }
			if ( !el.onmouseout  )
				el.onmouseout  = function() { swapImg(this,1) }
		}
		//设置Border属性
		if ( !el.getAttribute("border") )
			el.setAttribute("border", 0);
	}
	/* for "background" */
	setBackground("body");
	setBackground("div");
	setBackground("table");
	setBackground("td");
	function setBackground( strTagName ) {
		var rgEl = document.getElementsByTagName( strTagName );
		for ( var i=0; i<rgEl.length; i++ ) {
			if ( !rgEl[i].getAttribute("background") && rgEl[i].getAttribute("background1") ) {
				rgEl[i].setAttribute( "background", getImgUrl(rgEl[i].getAttribute("background1")) );
			}
		}
	}
	/* for "input type=button" tags with "background" attribute */
	rgEl = document.getElementsByTagName("input");
	for ( var i=0; i<rgEl.length; i++ ) {
		var el = rgEl[i];
		if ( (el.type == "button") && el.getAttribute("background1") ) {
			el.setAttribute( "background1", getImgUrl(el.getAttribute("background1")) );
			el.style.backgroundImage = "url(" +el.getAttribute("background1") + ")";
			//设置onmouseover/onmouseout属性
			if ( el.getAttribute("background1") && el.getAttribute("background2") ) {
				el.setAttribute( "background2", getImgUrl(el.getAttribute("background2")) );
				if ( !el.onmouseover )
					el.onmouseover = function() { swapBackgroundImage(this,2) }
				if ( !el.onmouseout  )
					el.onmouseout  = function() { swapBackgroundImage(this,1) }
			}
		}
	}
	//---
	function getImgUrl( s ) {
		var strRet = s;
		if ( typeof(g_strImgPath) != "undefined" )
			strRet = g_strImgPath + s;
		//缓存
		if ( !document.__do_img_cache__ ) document.__do_img_cache__ = new Array();
		document.__do_img_cache__[document.__do_img_cache__.length] = new Image();
		document.__do_img_cache__[document.__do_img_cache__.length-1].src = strRet;
		//
		return strRet;
	}
}

//装载一个script资源文件
//·在header里、js资源、或doc中嵌入的js代码里调用
//xxli@2005.03.28
function importScript(strUrl, strLang) {
	if ( !strLang ) strLang = "JavaScript";
	if ( document.body == null ) {
		document.write( '<script language="'+ strLang + '" src="' + strUrl + '"></' + 'script>' );
	} else {
		var el = document.createElement("script");
		el.setAttribute( "language", strLang );
		el.setAttribute( "src", strUrl );
		document.body.appendChild( el );
	}
}

//装载一个样式表文件到head
//xxli@2005.03.04
function importStyleSheet( strUrl ) {
	var oStyleSheet = document.createElement( "link" );
	oStyleSheet.setAttribute( "rel", "stylesheet" );
	oStyleSheet.setAttribute( "type", "text/css" );
	oStyleSheet.setAttribute( "href", strUrl );
	document.getElementsByTagName("head")[0].appendChild( oStyleSheet );
}
/* 判断一个样式表规则是否存在
 *   @selectorText  规则选择文本。如规则".class{xxx}" 为 ".class"；"p{xxx}" 为 "p"
 * xxli@2005.01.11
 */
function isStyleSheetRuleExists( selectorText ) {
	for ( var i=0; i<document.styleSheets.length; i++ ) {
		var cssRules = (document.styleSheets[i].rules) ? document.styleSheets[i].rules : document.styleSheets[i].cssRules;
		for ( var j=cssRules.length-1; j>=0; j-- )
			if ( cssRules[j].selectorText.toUpperCase() == selectorText.toUpperCase() )
				return true;
	}
	return false;
}
/* 增加一个样式表规则
 *   @cssText   字符串。css规则文本，如“.class {xxxx}”
 *   @bReplace  布尔。是否替换已有的同名规则
 * xxli@2005.01.11
 */
function addStyleSheetRule( cssText, bReplace ) {
	var selectorText = cssText.substring(0, cssText.indexOf("{")).replace(/ /g,"");
	//先遍历一下所有的样式表
	for ( var i=0; i<document.styleSheets.length; i++ ) {
		var cssRules = (document.styleSheets[i].rules) ? document.styleSheets[i].rules : document.styleSheets[i].cssRules;
		for ( var j=cssRules.length-1; j>=0; j-- ) {
			if ( cssRules[j].selectorText.toUpperCase() == selectorText.toUpperCase() ) {
				if ( !bReplace ) return false;
				//删除重名规则
				try { document.styleSheets[i].removeRule(j); } catch(e) {} //IE
				try { document.styleSheets[i].deleteRule(j); } catch(e) {} //Moz
			}
		}
	}
	//取第一个StyleSheet
	var oStyleSheet = null;
	if ( document.styleSheets.length == 0 ) {
		//新建
		try { //IE
			oStyleSheet = document.createStyleSheet()
		} catch(e) { //Moz
			oStyleSheet = document.createElement( "style" );
			document.getElementsByTagName("head")[0].appendChild( oStyleSheet );
		}
	}
	oStyleSheet = document.styleSheets[0];
	//创建规则
	if ( oStyleSheet.addRule ) {	//IE
		cssText = cssText.substring( cssText.indexOf("{"), cssText.lastIndexOf("}") );
		oStyleSheet.addRule(selectorText, cssText);
	} else if ( oStyleSheet.insertRule ) {	//Moz
		oStyleSheet.insertRule(cssText, oStyleSheet.cssRules.length);
	}
}

/* Version 1.03
 * 小的提示窗口，显示方式类似Title。
 * 使用：1、随鼠标：<** onmouseover="Tooltip.show('内容',event)" onmouseout="Tooltip.hide()">..
 *       2、窗口中：Tooltip.show("内容")
 * 需要：公共函数 moveToWinCenter, addStyleSheetRule, getAbsoluteTop, createElement, showWindowedElements...
 * Update: xxli@2005.03.28
 */
var Tooltip = new CTooltip()
function CTooltip()
{
	this.toString = function () { return "[class CTooltip]"; }

	this.oLayer = null;
	this.hTimer = null;
	this.strDefaultCssClass = "Tooltip";

	//公共函数：显示层
	//  @strContent    要显示的内容
	//  @event         若提示随鼠标位置，则传onmouseover的鼠标事件event
	//  @nTimeDisplay  显示持续时间
	//  @strClassName  提示窗的样式，默认Tooltip
	this.show = function( strContent, event, nTimeDisplay, strClassName ) {
		if ( this.oLayer == null ) this._createLayer();
		if ( this.oLayer.style.visibility != "hidden" ) return;
		this.hide();
		//清除计时器
		window.clearTimeout( this.hTimer );
		//内容
		strContent = strContent.replace(/\r/g,"").replace(/\n/g,"<br>").replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;");
		this.oLayer.innerHTML = "<nobr>" + strContent + "</nobr>";  //TODO: Moz下怎么前面会自动添加一个"<>"？
		//className
		this.oLayer.className = ( strClassName ) ? strClassName : this.strDefaultCssClass;
		this._addDefaultCssClass();
		//设置Tooltip的位置
		if ( !event ) {
			//窗口正中
			moveToWinCenter( this.oLayer );
		} else {
			//随鼠标位置
			if ( event ) {
				var elSrc = (event.srcElement) ? event.srcElement : event.target; //Target Element
				var x = event.clientX;  //获取当前鼠标位置的X坐标
				//var y = event.clientY;  //获取当前鼠标位置的Y坐标
				var y = getAbsoluteTop(elSrc) + elSrc.offsetHeight; //获得对象元素的下沿的Y坐标
				//判断是否超出当前窗口
				if ( (x + this.oLayer.offsetWidth) > document.body.clientWidth + document.body.scrollLeft ) {
					x = document.body.clientWidth + document.body.scrollLeft - this.oLayer.offsetWidth;
				}
				if ( (y + this.oLayer.offsetHeight) > (document.body.clientHeight + document.body.scrollTop) ) {
					y = document.body.clientHeight + document.body.scrollTop - this.oLayer.offsetHeight;
				}
				//设置位置
				this.oLayer.style.left = x + document.body.scrollLeft;
				this.oLayer.style.top  = y;
			}
		}
		//显示Tooltip，隐藏重叠的select元素
		this.oLayer.style.visibility = "visible";
		showWindowedElements( this.oLayer, false );
		//设置隐藏事件的计时器
		if ( nTimeDisplay )
			this.hTimer = window.setTimeout(this.getInstName()+".hide()", nTimeDisplay);

	}

	//公共函数：隐藏
	this.hide = function() {
		if ( this.oLayer != null ) {
			this.oLayer.style.visibility = "hidden";
			this.oLayer.style.top  = 0;
			this.oLayer.style.left = 0;
			//显示曾被隐藏的重叠select元素
			showWindowedElements( this.oLayer, true );
		}
	}

	//私有函数：创建提示层
	this._createLayer = function() {
		this.oLayer = createElement('<div class="Tooltip"></div>');
		document.body.appendChild( this.oLayer )
		this.hide();
	}

	//私有函数：设置默认的CSS类Tooltip
	this._addDefaultCssClass = function () {
		if ( this.oLayer.className == this.strDefaultCssClass ) {
			addStyleSheetRule( "." + this.strDefaultCssClass + "{visibility: hidden; position: absolute; top: 34px; left: 10px; background-color: #ffffe6; color: black; font-size: 9pt; border: black 1px solid; padding-top: 2px; padding-bottom: 1px; padding-right: 2px; padding-left: 2px }" )
		}
	}
}

/* Version 1.0
 * XMLDom 排序
 * 参数：@oXmlDom - 需要排序的XmlDom对象
 *       @Nodes   - 排序的节点列表（通过selectNodes("xpath")获得），或者其选择条件（即xpath）
 *       @strOpts - 排序选项，基本同xsl。
 *                  包括select(xpath)、data-type(text/number/date)、order(ascending/descending)。
 *                  例 "select=SortDate data-type=date order=descending"
 * 更新：xxli@2004.12.05 Created
 */
function SortXmlDom( oXmlDom, Nodes, strOpts )
{
	//初始化节点列表
	if ( typeof(Nodes) == "string" ) {
		Nodes = oXmlDom.selectNodes(Nodes);
	}
	if ( Nodes.length == 0 ) return;
	//初始化节点数组
	var rgNodes = new Array();
	for( var i=0; i<Nodes.length; i++ ) {
		rgNodes[i] = Nodes.item(i);
	}
	//初始化排序选项
	var strCaseOrder = (getOpt("case-order")!="") ? getOpt("case-order") : "upper-first";	//lower-first（暂不支持）
	var strDataType = (getOpt("data-type")!="") ? getOpt("data-type") : "text";			//number, date
	var strOrder    = (getOpt("order")!="") ? getOpt("order") : "ascending";			//descending
	var strSelect   = (getOpt("select")!="") ? getOpt("select") : ".";
	if ( strSelect == "" ) return;
	var strSelectNode = getSelectNode();
	var strSelectAtt  = getSelectAtt();
	//数组排序
	rgNodes.sort(cp);
	//更新oXmlDom
	var oParentNode = Nodes.item(0).parentNode;
	var sXml = "";
	for ( var i=0; i<rgNodes.length; i++ ) {
		sXml += rgNodes[i].xml;
	}
	var oXmlDomTmp = Sarissa.getDomDocument();
	oXmlDomTmp.loadXML( '<?xml version="1.0"?><a>' + sXml + '</a>' );
	NewNodes = oXmlDomTmp.selectSingleNode("/a").childNodes;
	for ( var i=NewNodes.length-1; i>=0; i-- ) {
		//document.writeln( NewNodes.length + " - " + i + "<br>")
		//document.writeln( NewNodes.item(i).selectSingleNode(strSelectNode).text + "<br>")
		oParentNode.replaceChild( NewNodes.item(i), Nodes.item(i) );
	}
	//-----
	function cp(a,b) {
		var as = a.selectSingleNode(strSelectNode);
		as = (strSelectAtt=="") ? as.text : as.getAttribute(strSelectAtt);
		var bs = b.selectSingleNode(strSelectNode);
		bs = (strSelectAtt=="") ? bs.text : bs.getAttribute(strSelectAtt);
		if ( strDataType == "number" ) {
			//数字
			as = Number(as);
			bs = Number(bs);
		} else if ( strDataType == "date" ) {
			//日期
			as = new Date(Date.parse(as.replace(/-/g,"/")));
			bs = new Date(Date.parse(bs.replace(/-/g,"/")));
		}
		return (strOrder=="ascending") ? ((as>bs)?1:((as<bs)?-1:0)) : ((as>bs)?-1:((as<bs)?1:0));
	}
	function getSelectNode() {
		var i = strSelect.indexOf("/@");
		if ( i != -1 ) {
			return strSelect.substring(0, i)
		} else {
			return strSelect;
		}
	}
	function getSelectAtt() {
		var i = strSelect.indexOf("/@");
		if ( i != -1 ) {
			return strSelect.substring(i+2)
		} else {
			return "";
		}
	}
	function getOpt(sName) {
		var i = strOpts.indexOf(sName+"=");
		if ( i != -1 ) {
			var s = strOpts.substring(i+sName.length+1);
			var j = s.indexOf(" ");
			if ( j != -1 ) {
				return s.substring(0,j);
			} else {
				return s;
			}
		}
		return "";
	}
}

/* Get parameter value from url query string
 *	@strUrl			the url qruey string, default is `location.href`
 *	@strParaName	the parameter name
 * xxli@2004.12.13
 */
function getUrlParaValue( strUrl, strParaName ) {
	if (!strUrl) strUrl = location.href;
	var i = strUrl.toUpperCase().indexOf( "&"+strParaName.toUpperCase()+"=" );
	if ( i == -1 ) i = strUrl.toUpperCase().indexOf( "?"+strParaName.toUpperCase()+"=" );
	if ( i == -1 ) return "";
	var strRet = strUrl.substring(i + strParaName.length + 2);
	i = strRet.indexOf("&");
	if ( i == -1 )
		return strRet;
	else
		return strRet.substring(0, i);
}
/* Set parameter value to url query string
 *	@strUrl			the url string, default is `location.href`
 *	@strParaName	the parameter name
 *	@strParaValue	the new value of the parameter
 * xxli@2004.12.13
 */
function setUrlParaValue( strUrl, strParaName, strParaValue ) {
	if (!strUrl) strUrl = location.href;
	var i = strUrl.toUpperCase().indexOf( "&"+strParaName.toUpperCase()+"=" );
	if ( i == -1 ) {
		i = strUrl.toUpperCase().indexOf( "?"+strParaName.toUpperCase()+"=" );
		if ( i == -1 ) {
			if ( strUrl.indexOf("?") != -1 )
				return strUrl + "&" + strParaName + "=" + strParaValue;
			else
				return strUrl + "?" + strParaName + "=" + strParaValue;
		}
	}
	var oRegExp = eval( "/([&|?]" + strParaName + "=)[^&]*/gi" );
	return strUrl.replace( oRegExp, "$1"+strParaValue );
}

/* IE下载类 Version 1.01
 *	var oDownload = new CIEDownloader();
	oDownload.onDownloadDone = function () {
		if (oDownload.Error) return msg.alert(oDownload.Error);	//下载失败
		alert(oDownload.FilePath + "\n" + oDownload.Data);		//下载成功
	}
	oDownload.goDown( "/diiop_ior.txt", "diiop_ior.txt");
	if (oDownload.Error) msg.alert( oDownload.Error );
 * Update: xxli@2005.03.28
 */
var oDownload = new CIEDownloader();
function CIEDownloader()
{
	//公共
	this.Error = null;
	this.Data = null;		//下载结束的文件内容
	this.FilePath = null;	//下载结束后在本地IE缓存文件的路径
	this.onDownloadDone = null;	//下载结束自定义函数
	this.ondownloaddone = null;

	//私有
	this.oIEDownloader = null;
	this.strFileUrl = null;
	this.strFileName = null;
	this.strWinObjName = null;

	//公共：开始下载
	this.goDown = function( strFileUrl, strFileName ) {
		this.strFileUrl = strFileUrl;
		this.strFileName = strFileName;
		//
		if ( this.strFileUrl && this.strFileName ) {
			try {
				//创建IE下载对象
				this.oIEDownloader = document.createElement( '<IE:Download style="behavior:url(#default#download)" />' )
				document.body.appendChild( this.oIEDownloader );
				//将当前对象设为window的全局对象，其_onDone成员函数设为windows的全局函数
				var s = this.strFileUrl.replace(/\W/g,"");
				if ( s.length > 200 ) s = s.substring(s.length-200);
				s = "CIEDownloader" + s;
				eval( "window." + s + " = this" );
				eval( "window." + s + "Done = function(data) { " + s + "._onDone(data) }" );
				this.strWinObjName = s;
				//开始下载模板
				this.oIEDownloader.startDownload( this.strFileUrl, eval(this.strWinObjName+"Done") );
				return true;
			} catch(e) {
				this.Error = "此功能目前只支持Microsoft Internet Explorer浏览器，版本5.0及其以上。";
				return false;
			}
		}
	} //end of `this.goDown`
	//下载完毕 -> 从IE缓存查找下载的文件
	this._onDone = function ( data ) {
		try {
			var oFile = getFileInIECache( this.strFileName );
			this.Data = data;
			this.FilePath = (oFile) ? oFile.Path : null;
			this.Error= null;
		} catch(e) {
			this.Error = "如果要正确使用此功能，请将本站点添加到可信站点，并刷新本窗口。\n\n错误消息：" + getErrorMessage(e);
		}
		//回调下载完毕事件
		if ( typeof(this.ondownloaddone) == "function" ) {
			this.ondownloaddone();
		} else if ( typeof(this.onDownloadDone) == "function" ) {
			this.onDownloadDone();
		}
		//删除window函数
		eval( "window." + this.strWinObjName + " = null" );
		eval( "window." + this.strWinObjName + "Done = null" );
		//删除IE下载对象
		document.body.removeChild(this.oIEDownloader);
	} //end of `this._onDone`

	//从IE缓存里查找文件strFileName的最新版本并返回
	//xxli@2004.12.14
	function getFileInIECache( strFileName )
	{
		var oFile = null;
		//计算文件名匹配的正则表达式： 文件名[数字].扩展名
		var strPrefix = strFileName.substring( 0, strFileName.lastIndexOf(".") );
		var strSuffix = strFileName.substring( strFileName.lastIndexOf(".")+1 );
		var oRegExp = eval( '/^' + strPrefix + '\[[0-9]*\]\\.' + strSuffix + '$/gi' );
		//遍历缓存，取文件名匹配、且时间最新的文件 返回
		if ( typeof(fso) == "undefined" ) fso = new ActiveXObject("Scripting.FileSystemObject");
		var oCacheFolder = fso.GetFolder( getSpecialFolderPath("IECache") );
		var foc = new Enumerator(oCacheFolder.SubFolders);
		for(; !foc.atEnd(); foc.moveNext() ) {
			//直接查找[1]-[10]的文件是否存在，并删除过时的老文件，以加快查找速度
			var strFolderPath = foc.item().Path + "\\";
			for ( var i=1; i<10; i++ ) {
				try {
					var f = fso.GetFile( strFolderPath + strPrefix + "[" + i + "]." + strSuffix );
					if ( (oFile == null) || oFile.DateLastModified < f.DateLastModified ) {
						if ( oFile != null ) oFile.Delete(true);
						oFile = f;
					} else
						f.Delete(true);
				} catch(e){} //用try省得判断文件是否存在了：）
			}
			/* obsolete : 遍历所有文件，若缓存中文件太多，则严重影响速度
			var fc = new Enumerator(foc.item().files);
			for(; !fc.atEnd(); fc.moveNext() ) {
				if ( oRegExp.test(fc.item().Name)	//文件名匹配
				&& ((oFile == null) || (oFile.DateLastModified < fc.item().DateLastModified)) )	//修改日期最新
					oFile = fc.item();
			}
			*/
		}
		return oFile;
	} // end of `getFileInIECache`
} //end of `CIEDownlaoder`


//创建一个本地文本文件。成功则返回新文件的绝对路径
//@strFilePath: 文件路径，若只包含文件名或相对路径，则写到系统临时目录下
//@strContent:  内容
function createLocalTextFile( strFilePath, strContent ) {
	try {
		if ( typeof(fso) == "undefined" ) fso = new ActiveXObject("Scripting.FileSystemObject");
		//取完整文件路径
		strFilePath = strFilePath.replace(/\//g, "\\");
		if( strFilePath.indexOf(":") == -1 ) {
			strFilePath = getSpecialFolderPath("Temp") + "\\" + strFilePath;
		}
		strFilePath = strFilePath.replace(/\\+/g,"\\");
		//格式化内容中的\n为Windows回车\r\n
		strContent = strContent.replace(/([^\r])\n/g, "$1\r\n");
		//创建文件，并写内容
		var f = fso.CreateTextFile( strFilePath, true );
		f.WriteLine( strContent );
		f.Close();
		return strFilePath;
	} catch (e) {
		try { f.Close(); } catch (e) {}
		return false;
	}
}
//判断一个本地文件是否存在
function isLocalFileExists( strFilePath ) {
	try {
		if ( typeof(fso) == "undefined" ) fso = new ActiveXObject("Scripting.FileSystemObject");
		return fso.FileExists( strFilePath );
	} catch (e) {
		return false;
	}
}
//删除一个本地文件，成功返回true，失败返回false
function deleteLocalFile( File ) {
	try {
		if ( typeof(File) == "string" ) {
			if ( typeof(fso) == "undefined" ) fso = new ActiveXObject("Scripting.FileSystemObject");
			fso.DeleteFile( File, true );
		} else {
			File.Delete(true);
		}
		return true;
	} catch(e) {
		return false;
	}
}
//删除一个本地文件夹，成功返回true，失败返回false
function deleteLocalFolder( Folder ) {
	try {
		if ( typeof(Folder) == "string" ) {
			if ( typeof(fso) == "undefined" ) fso = new ActiveXObject("Scripting.FileSystemObject");
			fso.DeleteFolder( Folder, true );
		} else
			Folder.Delete(true);
		return true;
	} catch(e) {
		return false;
	}
}

/*获得一些win特殊文件夹的位置，如我的文档、临时目录、IE缓存目录等
 *	strFolderName = AllUsersDesktop, AllUsersStartMenu, AllUsersPrograms, AllUsersStartup, Desktop, Favorites, Fonts, MyDocuments, NetHood, PrintHood, Programs, Recent, SendTo, StartMenu, Startup, Templates
 *			Temp, IECache
 *Update: xxli@2005.03.28
*/
function getSpecialFolderPath( strFolderName )
{
	var WshShell = new ActiveXObject("WScript.Shell");
	if ( strFolderName.toLowerCase() == "temp" ) {
		var WshSysEnv = WshShell.Environment("Process");
		return WshSysEnv("TEMP");
	} else if ( strFolderName.toLowerCase() == "iecache" ) {
		return WshShell.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Cache") + "\\Content.IE5";
	} else {
		return WshShell.SpecialFolders( strFolderName )
	}
}

//获取iframe装载的页面的document对象。失败则返回null
//xxli@2005.03.03
function getIframeDocument( elIframe ) {
	if ( !elIframe ) return null;
	if ( elIframe.contentDocument ) {		// NS6
		return elIframe.contentDocument;
	} else if ( elIframe.contentWindow ) {	//IE5.5+
		return elIframe.contentWindow.document;
	} else if ( elIframe.Document ) {	//IE5
		return elIframe.Document;
	} else {
		return null;
	}
}
//根据当前页面，获得父iframe元素
//xxli@2005.03.03
function getParentIframe() {
	if ( !window.parent ) return null;
	var oDocParent = window.parent.document;
	var rgelIframe = oDocParent.getElementsByTagName("IFRAME");
	for ( var i=0; i<rgelIframe.length; i++ ) {
		var oIframeDoc = getIframeDocument(rgelIframe[i]);
		if ( compare(oIframeDoc, window.document) )
			return rgelIframe[i];
	}
	return null;
	//----
	function compare( doc1, doc2 ) {
		return (navigator.appVersion.indexOf("MSIE 5.0") == -1) ? (doc1==doc2) : (doc1.location == doc2.location)
	}
}
//根据当前页面，自动调整父iframe的高度
function autofitParentIframe()
{
	var elIframe = getParentIframe();
	if ( elIframe ) {
		if ( isIE )
			elIframe.style.height = (document.body.scrollHeight) + "px";
		else
			elIframe.style.height = (document.body.offsetHeight) + "px";
	}
}
//根据s创建一个页面元素。
//s是元素的完整描述，如'<input type="checkbox" id="dddd" />'
//xxli@2005.03.19
function createElement( s )
{
	if ( isIE ) {
		var elNew = document.createElement( s );
		if ( !elNew.innerHTML && (s.indexOf(">") < s.lastIndexOf("<")) ) {
			var strInnerHTML = s.substring( s.indexOf(">")+1, s.lastIndexOf("<") );
			if ( strInnerHTML )
				try { elNew.innerHTML = strInnerHTML; } catch(e) {}
		}
		return elNew;
	} else {
		//get/create the temp layer
		var elLayer = document.getElementById( "lCreateElementTemp" );
		if ( !elLayer ) {
			elLayer = document.createElement( "div" );
			elLayer.id = "lCreateElementTemp";
			//elLayer.style.display = "none";
			document.body.appendChild( elLayer );
		}
		//create the element
		elLayer.innerHTML = s;
		var elNew = elLayer.childNodes[0];
		elLayer.innerHTML = "";
		return elNew;
	}
}

//从el的style中删除一个参数，并且若style中不再有其它参数则删除el的整个style属性
//xxli@2005.03.28
function removeStyleProperty( el, strPropertyName ) {
	try {
		if ( el.style.removeAttribute ) { //IE
			el.style.removeAttribute( strPropertyName.replace(/-/g,""), false );
			for( e in el.style )
				if ( (el.style[e]!="") && !((e=="accelerator") && (el.style[e]=="false")) ) return;
			el.removeAttribute("style");
		} else  { //Moz
			el.style.removeProperty( strPropertyName );
			if ( el.getAttribute("style") == "" ) el.removeAttribute("style");
		}
	} catch(e) {}
}

//类：坐标点
function CPoint( x, y ) {
	this.toString = function() {return "[class CPoint]";}
	this.x = x;
	this.y = y;
}
//类：矩形
var Rectangle = new CRectangle();
function CRectangle( p00, p01, p10, p11 ) {
	this.toString = function() {return "[class CRectangle]";}
	this.p00 = p00;	//坐标：左上角
	this.p01 = p01;	//坐标：右上
	this.p10 = p10;	//坐标：左下
	this.p11 = p11;	//坐标：右下

	//---获取矩形的中点
	this.getMidpoint = function () {
		if ( this.p00 && this.p01 && this.p10 && this.p11 )
			return new CPoint( (this.p00.x + (this.p01.x-this.p00.x)/2), (this.p00.y + (this.p11.y-this.p00.y)/2) );
		else return null;
	}
	//--- 判断两个矩形是否有重合部分（@bContainsBorder，是否包含边框的重合）
	this.isOverlap = function( rec, bContainsBorder ) {
		return this.isContainsPoint(rec.p00,bContainsBorder) || this.isContainsPoint(rec.p01,bContainsBorder)
			|| this.isContainsPoint(rec.p10,bContainsBorder) || this.isContainsPoint(rec.p11,bContainsBorder)
			|| this.isContainsPoint(rec.getMidpoint(),true)
			|| rec.isContainsPoint(this.p00,bContainsBorder) || rec.isContainsPoint(this.p01,bContainsBorder)
			|| rec.isContainsPoint(this.p10,bContainsBorder) || rec.isContainsPoint(this.p11,bContainsBorder)
			|| rec.isContainsPoint(this.getMidpoint(),true);
	}
	//--- 判断矩形是否包含点 p
	this.isContainsPoint = function( p, bContainsBorder ) {
		if ( !p ) return false;
		return ( bContainsBorder ) ? (p.x >= this.p00.x) && (p.x <= this.p01.x) && (p.y >= this.p00.y) && (p.y <= this.p11.y) :
									 (p.x >  this.p00.x) && (p.x <  this.p01.x) && (p.y >  this.p00.y) && (p.y <  this.p11.y);
	}
	//---判断两个html元素是否有重合部分
	this.isHTMLElementsOverlap = function ( el1, el2 ) {
		try { return this.getHTMLElementRectangle(el1).isOverlap( this.getHTMLElementRectangle(el2) );
		} catch(e) { return false; }
	}
	//---根据html元素的位置，生成一个矩形对象
	this.getHTMLElementRectangle = function( el ) {
		var l=0,t=0,w=el.offsetWidth,h=el.offsetHeight;
		while(el) l+=el.offsetLeft,t+=el.offsetTop,el=el.offsetParent;
		return new CRectangle( new CPoint(l,t), new CPoint(l+w,t), new CPoint(l,t+h), new CPoint(l+w,t+h) );
	}
}
//隐藏/显示同el重叠的select/iframe/object/applet元素等
//暂时只处理select和iframe
//xxli@2005.03.27
function showWindowedElements( el, bVisible, bHideIframe ) {
	//Mozilla（Gecko）设置z-index即可，自己处理吧：）
	if ( navigator.product && navigator.product=="Gecko" ) return;
	try {
		//取自定义属性（存储被此函数隐藏的html元素列表）
		var rgelHidden = el.__HiddenWindowedElements__;
		if ( rgelHidden == null ) rgelHidden = new Array();
		if ( !bVisible ) {
		//隐藏
			var doc = (el.ownerDocument) ? el.ownerDocument : el.document;
			var rgel1 = doc.getElementsByTagName("SELECT");
			var rgel2 = (bHideIframe) ? doc.getElementsByTagName("IFRAME") : (new Array());
			var rgel = new Array();
			for( var i=0; i<rgel1.length; i++ ) rgel[rgel.length] = rgel1[i];
			for( var i=0; i<rgel2.length; i++ ) rgel[rgel.length] = rgel2[i];
			//
			for( var i=0; i<rgel.length; i++ ) {
				if ( (rgel[i].style.display != "none") && (rgel[i].style.visibility != "hidden") && Rectangle.isHTMLElementsOverlap(el,rgel[i]) ) {
					rgel[i].style.visibility = "hidden";
					rgelHidden.push( rgel[i] );
				}
			}
			el.__HiddenWindowedElements__ = rgelHidden;
		} else {
		//显示
			for ( var i=0; i<rgelHidden.length; i++ ) {
				if ( rgelHidden[i].style.visibility == "hidden" ) {
					removeStyleProperty( rgelHidden[i], "visibility" );
				}
			}
		}
	} catch (e) {};
}

//如果浏览器为Mozilla类的，则为其生成showModelessDialog函数，同IE的相同函数基本兼容
//xxli@2004.07.03
if ( isMoz )
{
window.showModelessDialog = function ( sURL, vArguments, sFeatures ) {
	//设置sFeatures
	sFeatures = (sFeatures) ? (sFeatures+",dependent") : "dependent";
	if ( sFeatures ) {
		//映射sFeatures
		sFeatures = sFeatures.replace(/;/g, ",")
		sFeatures = sFeatures.replace(/dialogHeight/g, "outerHeight");
		sFeatures = sFeatures.replace(/dialogWidth/g, "outerWidth");
		sFeatures = sFeatures.replace(/dialogLeft/g, "screenX");
		sFeatures = sFeatures.replace(/dialogTop/g, "screenY");
		//默认高度×宽度 ＝ 500×500
		if ( sFeatures.indexOf("outerHeight") == -1 )
			sFeatures += ",outerHeight=505px"	//Mozilla的标题栏和状态栏稍高
		if ( sFeatures.indexOf("outerWidth") == -1 )
			sFeatures += ",outerWidth=500px"
		//居中
		if ( (sFeatures.indexOf("screenX=") == -1) && (sFeatures.indexOf("screenY=") == -1) &&
			 (sFeatures.indexOf("center=0") == -1) && (sFeatures.indexOf("center=no") == -1) )
		{
			var nH = parseInt( getFeature(sFeatures, "outerHeight") );
			var nW = parseInt( getFeature(sFeatures, "outerWidth") );
			if ( nH>0 && nW>0 && window.screen ) {
				var x = parseInt( (screen.availWidth -nW-10) * 0.5 );
				var y = parseInt( (screen.availHeight-nH-30) * 0.5 );
				sFeatures += ",left=" + x + ",screenX=" + x;
				sFeatures += ",top="  + y + ",screenY=" + y;
			}
		}
		//状态栏
		if ( (sFeatures.indexOf("status=0") == -1) && (sFeatures.indexOf("status=no") == -1) )
			sFeatures += ",status=1"
	}
	//打开
	var oWin = window.open( sURL, "", sFeatures );
	//设置dialogArguments属性
	oWin.dialogArguments = vArguments;
	/* 当父窗口onunload后自动关闭 */
	//TODO: 打开多个MD窗口时，刷新父窗口后新打开的MD窗口无法获得焦点:(
	//在父窗口对象上新建属性rgModelessDialogs，存储打开的ModelessDialog对象
	if ( !this.rgModelessDialogs ) this.rgModelessDialogs = new Array();
	this.rgModelessDialogs[this.rgModelessDialogs.length] = oWin;
	if ( typeof(this.onunload_bak_for_showModelessDialog) != "function" ) {
	//若不存在父窗口的onunload备份，则备份之，并创建新的onunload事件
		//备份父窗口的onunload事件
		if ( typeof(this.onunload) == "function" )
			this.onunload_bak_for_showModelessDialog = this.onunload
		else
			this.onunload_bak_for_showModelessDialog = function(){}
		//父窗口设置新的onunload事件
		this.onunload = function() {
			for( var i=this.rgModelessDialogs.length-1; i>=0; i-- ) {
				try{
					this.rgModelessDialogs[i].close();
					this.rgModelessDialogs.length --;
				}catch(e){}
			}
			if ( typeof(this.onunload_bak_for_showModelessDialog) == "function" )
				this.onunload_bak_for_showModelessDialog()
		}
	}
	//返回窗口对象
	oWin.focus(); //dosn't work :(
	return oWin;
	//----
	function getFeature( sFeatures, sName ) {
		var s = sFeatures
		var i = s.indexOf( sName+"=" )
		if ( i == -1 ) return ""
		var s = s.substr( i+sName.length+1 )
		if ( s.indexOf(",") != -1 )
			s = s.substring( 0, s.indexOf(",") )
		return s
	}
	//----
}
}

//在Moz下模拟IE的部分方法和属性
//xxli@2005.03.28
if ( isMoz ) {
	//判断是否有接口方法sName
	function __hasMethod__ ( sClass, sName ) { return typeof(eval(sClass+".prototype."+sName)) != "undefined"; }
	//判断HTML元素是否有接口属性sName
	var __el__ = document.createElement("__hasElProperty__");
	function __hasElProperty__ ( sName ) { return typeof(eval("__el__."+sName)) != "undefined"; }

	//attachEvent
	//if ( typeof(HTMLDocument.prototype.attachEvent)=="undefined" && typeof(HTMLElement.prototype.attachEvent=="undefined") )
	if ( !__hasMethod__('HTMLDocument','attachEvent') && !__hasMethod__('HTMLElement','attachEvent') )
	HTMLDocument.prototype.attachEvent = HTMLElement.prototype.attachEvent = function (sType, fHandler) {
		var shortTypeName = sType.replace(/on/, "");
		fHandler._ieEmuEventHandler = function (e) {
			window.event = e;
			return fHandler();
		};
		this.addEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
	};
	//detachEvent
	if ( !__hasMethod__('HTMLDocument','detachEvent') && !__hasMethod__('HTMLElement','detachEvent') )
	HTMLDocument.prototype.detachEvent = HTMLElement.prototype.detachEvent = function (sType, fHandler) {
		var shortTypeName = sType.replace(/on/, "");
		if (typeof fHandler._ieEmuEventHandler == "function")
			this.removeEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
		else
			this.removeEventListener(shortTypeName, fHandler, true);
	};
	//Event
	Event.prototype.__defineSetter__("returnValue",  function (b) { if (!b) this.preventDefault(); return b; } );
	Event.prototype.__defineSetter__("cancelBubble", function (b) { if (b) this.stopPropagation(); return b; } );
	Event.prototype.__defineGetter__("srcElement", function () {
		var node = this.target;
		while (node.nodeType != 1) node = node.parentNode;
		return node;
	});
	Event.prototype.__defineGetter__("fromElement", function () {
		var node;
		if (this.type == "mouseover") node = this.relatedTarget;
		else if (this.type == "mouseout") node = this.target;
		if (!node) return;
		while (node.nodeType != 1) node = node.parentNode;
		return node;
	});
	Event.prototype.__defineGetter__("toElement", function () {
		var node;
		if (this.type == "mouseout") node = this.relatedTarget;
		else if (this.type == "mouseover") node = this.target;
		if (!node) return;
		while (node.nodeType != 1) node = node.parentNode;
		return node;
	});
	Event.prototype.__defineGetter__("offsetX", function () { return this.layerX; });
	Event.prototype.__defineGetter__("offsetY", function () { return this.layerY; });

	//insertAdjacentElement
	if ( !__hasMethod__('HTMLElement','insertAdjacentElement') )
	HTMLElement.prototype.insertAdjacentElement = function(sWhere,el) {
		switch (sWhere){
		case 'beforeBegin':
			this.parentNode.insertBefore(el, this);
			break;
		case 'afterBegin':
			this.insertBefore(el, this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(el);
			break;
		case 'afterEnd':
			if (this.nextSibling) this.parentNode.insertBefore(el,this.nextSibling);
			else this.parentNode.appendChild(el);
		}
	}
	//insertAdjacentHTML
	if ( !__hasMethod__('HTMLElement','insertAdjacentHTML') )
	HTMLElement.prototype.insertAdjacentHTML = function (sWhere,sHTML) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(sHTML);
		this.insertAdjacentElement(sWhere,parsedHTML)
	}
	//insertAdjacentText
	if ( !__hasMethod__('HTMLElement','insertAdjacentText') )
	HTMLElement.prototype.insertAdjacentText = function (sWhere,sText) {
		var tn = document.createTextNode(sText)
		this.insertAdjacentElement(sWhere,tn)
	}
	//outerHTML
	if ( !__hasElProperty__("outerHTML") )
	HTMLElement.prototype.__defineGetter__( "outerHTML", function () {
		var _emptyTags = { "IMG":true, "BR":true, "INPUT":true, "META":true, "LINK":true, "PARAM":true, "HR":true };
		var attrs = this.attributes;
		var str = "<" + this.tagName.toLowerCase();
		for (var i = 0; i < attrs.length; i++)
			str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";
		if (_emptyTags[this.tagName])
			return str + ">";
		return str + ">" + this.innerHTML + "</" + this.tagName.toLowerCase() + ">";
	});
	if ( !__hasElProperty__("outerHTML") )
	HTMLElement.prototype.__defineSetter__( "outerHTML", function (sHTML) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var df = r.createContextualFragment(sHTML);
		this.parentNode.replaceChild(df, this);
	});
	//innerText
	if ( !__hasElProperty__("innerText") )
	HTMLElement.prototype.__defineGetter__( "innerText", function () {
		var r = this.ownerDocument.createRange();
		r.selectNodeContents(this);
		return r.toString();
	});
	if ( !__hasElProperty__("innerText") )
	HTMLElement.prototype.__defineSetter__( "innerText",function (sText) {
		this.innerHTML = sText.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
	});
	//outerText
	if ( !__hasElProperty__("outerText") )
	HTMLElement.prototype.__defineGetter__( "outerText", function () { return this.innerText; } );
	if ( !__hasElProperty__("outerText") )
	HTMLElement.prototype.__defineSetter__( "outerText", function (sText) {
		this.outerHTML = sText.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
	});
}

//输出对象o的成员属性、方法到页面上，供测试用。
var tom = testObjectMembers;
function testObjectMembers( o, rgstrType ) {
	//textarea且display:none时，moz会报错?
	try {
		var bTextArea = false;
		if (o.tagName=="TEXTAREA" && o.style.display=="none") {
			o.style.removeProperty("display");
			bTextArea = true;
		}
	} catch (e) {}
	//get the member array
	if ( typeof(rgstrType) == "string" ) rgstrType = [rgstrType];
	var rgstrMembers = new Array();
	for ( e in o ) {
		if ( rgstrType ) {
			for ( var i=0; i<rgstrType.length; i++ ) {
				if ( typeof(o[e]) == rgstrType[i] )
					rgstrMembers[rgstrMembers.length] = "<tr><td>" + typeof(o[e]) + "</td><td><font color=\"blue\">" + e + "</font></td><td>" + ((o[e]=="")?"&nbsp;":o[e]) + "</td></tr>\n";
			}
		} else {
			rgstrMembers[rgstrMembers.length] = "<tr><td>" + typeof(o[e]) + "</td><td><font color=\"blue\">" + e + "</font></td><td>" + ((o[e]=="")?"&nbsp;":o[e]) + "</td></tr>\n";
		}
	}
	rgstrMembers.sort();
	//write to window.document
	var strMembers = "<hr/>\n<table style=\"font-size:12px\" border=\"1\" cellpadding=\"5\"><tr><th>类型</th><th>名称</th><th>当前值</th></tr>" + rgstrMembers.join("") + "</table>\n<hr/>\n";
	if ( document.body ) {
		var el = document.createElement( "div" );
		el.innerHTML = strMembers;
		if ( document.body.firstChild )
			document.body.insertBefore(el, document.body.firstChild);
		else
			document.body.appendChild( el );
	} else {
		document.write( strMembers );
	}
	//
	if ( bTextArea ) o.style.display = "none"
}
//可代替alert输出测试信息到页面上，方便处理结果，测试用。
//@bHtmlFormat：设为true则不转换html标记如左右尖括号等。
var tw = testWrite
function testWrite( s, bHtmlFormat ) {
	if ( typeof(s) == "undefined" ) s = "undefined";
	if ( typeof(s) != "string" ) s = s.toString();
	if ( document.body ) {
		var el = document.createElement( "div" );
		el.style.border = "black 1px solid";
		el.style.paddingTop = "1px";
		el.style.paddingBottom = "1px";
		el.style.paddingLeft = "3px";
		if ( bHtmlFormat ) {
			el.innerHTML = s;
		} else {
			el.innerHTML = s.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g,"<br>").replace(/ /g, "&nbsp;");
		}
		el.innerHTML += '<a onclick="this.parentElement.style.display=\'none\'; ">[关掉]</a>';
		if ( document.body.firstChild )
			document.body.insertBefore(el, document.body.firstChild);
		else
			document.body.appendChild( el );
	} else {
		document.write( s );
	}
}
