1 //<![CDATA[
  2 
  3 
  4 /**
  5  * @name	Colorless echo JavaScript kit/library base framework
  6  * @fileoverview
  7  * 本檔案包含了呼叫其他 library 需要用到的 function,以及常用 base functions。<br/>
  8  * <br/>
  9  * Copyright (C) 2002-, kanashimi <kanasimi@gmail.com>. All Rights Reserved.<br/>
 10  * <br/>
 11  * This file is in tab wide of 4 chars, documentation with JsDoc Toolkit (<a href="http://code.google.com/p/jsdoc-toolkit/wiki/TagReference">tags</a>).<br/>
 12  * <br/>
 13  * <br/>Please visit <a href="http://lyrics.meicho.com.tw/program/">Colorless echo program room</a> for more informations.
 14  * @since	自 function.js 0.2 改寫
 15  * @since	JavaScript 1.2
 16  * @since	2009/11/17 01:02:36
 17  * @author	kanasimi@gmail.com
 18  * @version	$Id: ce.js,v 0.2 2009/11/26 18:37:11 kanashimi Exp $
 19  */
 20 
 21 
 22 /*
 23 引用:參照
 24 function addCode
 25 
 26 單一JS引用:
 27 //	[function.js]_iF
 28 function _iF(){}_iF.p='HKCU\\Software\\Colorless echo\\function.js.path';if(typeof WScript=="object")try{eval(getU((new ActiveXObject("WScript.Shell")).RegRead(_iF.p)));}catch(e){}
 29 function getU(p,enc){var o;try{o=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){o=new XMLHttpRequest();}if(o)with(o){open('GET',p,false);if(enc&&o.overrideMimeType)overrideMimeType('text/xml;charset='+enc);send(null);return responseText;}}
 30 //	[function.js]End
 31 
 32 
 33 初始化:參照
 34 initialization of function.js
 35 
 36 <script type="text/javascript" src="path/to/function.js"></script>
 37 <script type="application/javascript;version=1.7" src="path/to/function.js"></script>
 38 
 39 
 40 */
 41 
 42 
 43 //try{
 44 
 45 if (typeof CeL !== 'function')
 46 //void(
 47 (function(){
 48 
 49 var
 50 	/**
 51 	 * debug level
 52 	 * @ignore
 53 	 */
 54 	debug = 1
 55 
 56 	,global
 57 
 58 	//,window
 59 
 60 	/**
 61 	 * Will speed up references to undefined, and allows redefining its name. (from jQuery)
 62 	 * 用在 return undefined
 63 	 */
 64 	//,undefined
 65 
 66 	,_CeL
 67 
 68 	,CeL
 69 
 70 	,loaded_module
 71 
 72 	//,_base_function_to_extend
 73 	;
 74 
 75 
 76 //		members of library	-----------------------------------------------
 77 ;
 78 
 79 
 80 /**
 81  * Global Scope object<br/>
 82  * 於 CeL.eval 使用
 83  * @ignore
 84  */
 85 global = this;	//	isWeb()?window:this;
 86 
 87 
 88 /*
 89 var _Global=(function(){return this;})();
 90 _Global.JustANumber=2;	//	var _GlobalPrototype=_Global.constructor.prototype;_GlobalPrototype.JustANumber=2;
 91 if(typeof _Global=='undefined')_Global=this;
 92 for(i in _Global)alert(i);
 93 */
 94 
 95 //	若已經定義過,跳過。
 96 if(typeof (global.CeL) !== 'undefined')
 97 	return;
 98 
 99 
100 /**
101  * Will speed up references to DOM: window, and allows redefining its name. (from jQuery)
102  * @ignore
103  */
104 //window = this;
105 
106 
107 /**
108  * 本 JavaScript framework 的框架基本宣告<br/>
109  * base name-space declaration of JavaScript library framework
110  * @example
111  * //	判別是否已經 load 過
112  * if(typeof CeL !== 'function' || CeL.Class !== 'CeL')
113  * 	;	//	CeL has not been loaded
114  * @name	CeL
115  * @class	Colorless echo JavaScript kit/library: base name-space declaration
116  */
117 CeL = function(){
118 	//	function CeL	//	declaration for debug
119 	//this.global = arguments[0] || arguments.callee.ce_doc;
120 	return new (arguments.callee.init.apply(null, arguments));
121 };
122 
123 /**
124  * JavaScript library framework main class name.
125  * @see	<a href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf">ECMA-262</a>: Class: A string value indicating the kind of this object.
126  * @constant
127  */
128 CeL.Class = 'CeL';
129 
130 
131 /**
132  * Map over main name-space in case of overwrite (from jQuery)
133  * @ignore
134  */
135 _CeL = global.CeL;
136 global[CeL.Class] = CeL;
137 
138 
139 /**
140  * framework main prototype definition
141  * for JSDT: 有 prototype 才會將之當作 Class
142  */
143 CeL.prototype = {
144 };
145 
146 
147 
148 
149 // 取得執行script之path,在.hta中取代 WScript.ScriptFullName,%20的部分最好再加其他的…
150 CeL.get_script_full_name = function(){
151 	return	typeof WScript === 'object'? WScript.ScriptFullName
152 			: typeof location === 'object'? unescape(location.pathname)
153 			: '';
154 };
155 // 取得執行script之名稱
156 CeL.get_script_name = function(){
157 	var n, i, j;
158 
159 	if (typeof WScript === 'object') {
160 		n = WScript.ScriptName;
161 		i = n.lastIndexOf('.');
162 		return i == -1 ? n : n.slice(0, i);
163 	}
164 
165 	if (typeof location === 'object') {
166 		n = unescape(location.pathname), j = n.lastIndexOf('.');
167 		if (!(i = n.lastIndexOf('\\') + 1))
168 			i = n.lastIndexOf('/') + 1;	//	location.pathname在.hta中會回傳'\'形式的path
169 		return i < j ? n.slice(i, j) : n.substr(i);
170 	}
171 
172 	return typeof document === 'object' ? document.title : '';
173 };
174 
175 
176 
177 
178 /**
179  * 取得/設定環境變數 enumeration<br/>
180  * (雖然不喜歡另開 namespace,但以 2009 當下的 JsDoc Toolkit 來說,似乎沒辦法創造 enumeration。)
181  * @class	環境變數 (environment variables) 與程式會用到的 library 相關變數。
182  * @param name	環境變數名稱
183  * @param value	環境變數之值
184  * @return	舊環境變數之值
185  */
186 CeL.env = function(name, value) {
187 	if (!name)
188 		return undefined;
189 
190 	var _s = arguments.callee, v = _s[name];
191 	if (arguments.length > 1)
192 		_s[name] = value;
193 	return isNaN(v) ? '' + v : v;
194 };
195 
196 /**
197  * Setup environment variables
198  * @param	{string}[OS_type]	type of OS
199  * @return	environment variables set
200  */
201 CeL.initial_env = function(OS_type){
202 	//this.env = {};
203 	var OS, env = this.env;
204 
205 	/**
206 	 * library main file base name<br/>
207 	 * full path: {@link CeL.env.registry_path} + {@link CeL.env.main_script}
208 	 * @name	CeL.env.main_script
209 	 */
210 	env.main_script = 'ce.js';
211 
212 	/**
213 	 * module 中的這 member 定義了哪些 member 不被 extend
214 	 * @name	CeL.env.not_to_extend_keyword
215 	 */
216 	env.not_to_extend_keyword = 'no_extend';
217 
218 	/**
219 	 * 本 library source 檔案使用之 encoding<br/>
220 	 * 不使用會產生語法錯誤
221 	 * @name	CeL.env.source_encoding
222 	 */
223 	env.source_encoding = 'UTF-16';
224 
225 	/**
226 	 * default global object
227 	 * @name	CeL.env.global
228 	 */
229 	env.global = global;
230 
231 	/**
232 	 * creator group
233 	 * @name	CeL.env.company
234 	 */
235 	env.company = 'Colorless echo';
236 		env.registry_key = 'HKCU\\Software\\' + env.company + '\\' + this.Class
237 				+ '.path';
238 	//if(typeof WScript==='object')
239 	try {
240 		/**
241 		 * 存放在 registry 中的 path
242 		 * @name	CeL.env.registry_path
243 		 */
244 		env.registry_path = (WScript.CreateObject("WScript.Shell"))
245 				.RegRead(env.registry_key).replace(/[^\\\/]+$/, '');
246 		// this.log(env.registry_path);
247 	} catch (e) {
248 		// this.log(e.message);
249 	}
250 
251 
252 	//條件式編譯(条件コンパイル) for version>=4, 用 /*@ and @*/ to 判別
253 	/*@cc_on
254 	@if(@_PowerPC||@_mac)
255 	 OS='Mac';
256 	@else
257 	 @if(@_win32||@_win64||@_win16)
258 	  OS='DOS';
259 	 @else
260 	  OS='unix';	//	unknown
261 	 @end
262 	@end@*/
263 
264 	if (typeof OS_type === 'string')
265 			OS = OS_type;
266 
267 	/**
268 	 * 本次執行所在 OS 平台
269 	 * @name	CeL.env.OS
270 	 */
271 	env.OS = OS;	//='unix'	//	假如未設定則取預設值
272 
273 	/**
274 	 * 文件預設 new line
275 	 * @name	CeL.env.new_line
276 	 */
277 	env.new_line=		OS == 'unix' ? '\n' : OS == 'Mac' ? '\r' : '\r\n';	//	in VB: vbCrLf
278 	/**
279 	 * file system 預設 path separator<br/>
280 	 * platform-dependent path separator character, 決定目錄(directory)分隔
281 	 * @name	CeL.env.path_separator
282 	 */
283 	env.path_separator	=	OS == 'unix' ? '/' : '\\';
284 	/**
285 	 * 預設 module name separator
286 	 * @name	CeL.env.module_name_separator
287 	 */
288 	env.module_name_separator='.';
289 	/**
290 	 * path_separator in 通用(regular)運算式
291 	 * @name	CeL.env.path_separator_RegExp
292 	 */
293 	env.path_separator_RegExp = this.to_RegExp_pattern ? this
294 			.to_RegExp_pattern(env.path_separator)
295 			: (env.path_separator == '\\' ? '\\' : '') + env.path_separator;
296 	/**
297 	 * 預設語系
298 	 * 0x404:中文-台灣,0x0411:日文-日本
299 	 * @name	CeL.env.locale
300 	 * @see	<a href="http://msdn.microsoft.com/zh-tw/library/system.globalization.cultureinfo(VS.80).aspx">CultureInfo 類別</a>
301 	 */
302 	env.locale = 0x404;
303 
304 	/**
305 	 * script name
306 	 * @name	CeL.env.script_name
307 	 */
308 	env.script_name = this.get_script_name();
309 	/**
310 	 * base path of library
311 	 * @name	CeL.env.library_base_path
312 	 */
313 	env.library_base_path = this.get_script_full_name(); // 以reg代替
314 
315 	return env;
316 };
317 
318 
319 
320 
321 /**
322  * Tell if it's now debugging.
323  * @param {int}[debug_level]	if it's now in this debug level.
324  * @type	boolean
325  * @return	It's now debugging or in specified debug level.
326  */
327 CeL.is_debug = function(debug_level){
328 	return typeof debug_level === 'undefined' ? debug
329 				: debug == debug_level;
330 };
331 
332 /**
333  * Set debug level
334  * @param {int}[debug_level]	The debug level to set.
335  * @type	int
336  * @return	debug level now
337  */
338 CeL.set_debug = function(debug_level){
339 	if(typeof debug_level === 'undefined')
340 		debug_level = 1;
341 
342 	if(!isNaN(debug_level))
343 		debug = debug_level;
344 
345 	return debug;
346 };
347 
348 
349 /*
350 CeL.extend(function f_name(){}, object || string, initial arguments);
351 CeL.extend({name:function(){},.. }, object || string);
352 CeL.extend([function1,function12,..], object || string);
353 
354 set .name
355 */
356 
357 /**
358  * 延展物件 (learned from jQuery)
359  * @since	2009/11/25 21:17:44
360  * @param	variable_set	variable set
361  * @param	namespace	extend to what namespace
362  * @param	from_namespace	When inputing function names, we need a base namespace to search these functions.
363  * @return	CeL
364  * @see	<a href="http://blog.darkthread.net/blogs/darkthreadtw/archive/2009/03/01/jquery-extend.aspx" accessdate="2009/11/17 1:24" title="jQuery.extend的用法 - 黑暗執行緒">jQuery.extend的用法</a>
365  */
366 CeL.extend = function(variable_set, namespace, from_namespace){
367 /*
368 	if(this.is_debug())
369 		throw new Error(1, 'UNDO');
370 */
371 	var _s, i, l;
372 
373 	if(typeof namespace === 'undefined' || namespace === null)
374 		namespace = this;
375 
376 	if(typeof from_namespace === 'undefined')
377 		from_namespace = this;
378 
379 	if(typeof variable_set === 'function'){
380 		if(this.parse_function){
381 		}else{
382 			CeL.log('Warning: Please include ' + this.Class + '.parse_function() first!');
383 		}
384 
385 	}else if(typeof variable_set === 'string'){
386 		if(namespace === from_namespace)
387 			;
388 		else if(variable_set in from_namespace){
389 			//CeL.log('CeL.extend:\nextend (' + (typeof variable_set) + ') ' + variable_set + '\n=' + from_namespace[variable_set] + '\n\nto:\n' + namespace);
390 			namespace[variable_set] = from_namespace[variable_set];
391 		}else
392 			try{
393 				namespace[variable_set] = eval(variable_set);
394 				//CeL.log('CeL.extend:\n' + variable_set + ' = ' + namespace[variable_set]);
395 			}catch(e){
396 				CeL.log('CeL.extend:\n' + e.message);
397 			}
398 
399 	}else if(variable_set instanceof Array){
400 		for (_s = arguments.callee, i = 0, l = variable_set.length; i < l; i++) {
401 			_s(variable_set[i], namespace, from_namespace);
402 		}
403 
404 	}else if(variable_set instanceof Object){
405 		for(i in variable_set){
406 			namespace[i] = variable_set[i];
407 		}
408 	}
409 
410 	return this;
411 };
412 
413 
414 /**
415  * Get file resource<br/>
416  * 用於 include JavaScript 檔之類需求時,取得檔案內容之輕量級函數。<br/>
417  * 除 Ajax,本函數亦可用在 CScript 執行中。
418  * @example
419  * //	get contents of [path/to/file]:
420  * var file_contents = CeL.get_file('path/to/file');
421  * @param	{String} path	URI / full path. <em style="text-decoration:line-through;">不能用相對path!</em>
422  * @param	{String} [encoding]	file encoding
423  * @return	{String} data	content of path
424  * @return	{undefined}	when error occurred: no Ajax function, ..
425  * @throws	uncaught exception @ Firefox: 0x80520012 (NS_ERROR_FILE_NOT_FOUND), <a href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070227/#exceptions">NETWORK_ERR</a> exception
426  * @throws	'Access to restricted URI denied' 當 access 到上一層目錄時
427  * @see
428  * <a href=http://blog.joycode.com/saucer/archive/2006/10/03/84572.aspx">Cross Site AJAX</a><br/>
429  * <a href="http://domscripting.com/blog/display/91">Cross-domain Ajax</a>
430  */
431 CeL.get_file = function(path, encoding){
432 	//with(typeof window.XMLHttpRequest=='undefined'?new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest()){
433 
434 	/**
435 	 * XMLHttpRequest object
436 	 */
437 	var o;
438 
439 	try{
440 		o = new ActiveXObject('Microsoft.XMLHTTP');
441 	}catch(e){
442 		o = new XMLHttpRequest();
443 	}
444 
445 	if(o)with(o){
446 		open('GET', path, false);
447 
448 		if (encoding && o.overrideMimeType)
449 			/*
450 			 * old: overrideMimeType('text/xml;charset='+encoding);
451 			 * 但這樣會被當作 XML 解析,產生語法錯誤。
452 			 */
453 			overrideMimeType('application/json;charset=' + encoding);
454 
455 
456 		send(null);
457 		/*
458 		try {
459 			send(null);
460 		} catch (e) {
461 			//	file not found
462 			//	uncaught exception @ Firefox: 0x80520012 (NS_ERROR_FILE_NOT_FOUND)
463 			return undefined;
464 		}
465 		*/
466 
467 		return responseText;
468 	}//	else: This browser does not support XMLHttpRequest.
469 
470 	return undefined;	//	This function must return a result of type any
471 };
472 
473 /**
474  * 本 library 專用之 evaluate()
475  * @param code	code to eval
476  * @return	value that eval() returned
477  */
478 CeL.eval = function(code) {
479 	/*
480 		JSC eval() takes an optional second argument which can be 'unsafe'.
481 		Mozilla/SpiderMonkey eval() takes an optional second argument which is the scope object for new symbols.
482 
483 		use window.execScript(code,"JavaScript") in IE: window.execScript()將直接使用全局上下文環境,因此,execScript(Str)中的字符串Str可以影響全局變量。——也包括聲明全局變量、函數以及對象構造器。
484 	*/
485 	//this.log(global.eval);
486 	//this.log(global && global.eval && global.eval !== arguments.callee);
487 	//global.eval(code);
488 	return global && global.eval && global.eval !== arguments.callee ? global.eval.call(global, code) : eval(code);
489 };
490 
491 /*	得知相對basePath
492 <script type="text/javascript" src="../baseFunc.js"></script>
493 var basePath=getBasePath('baseFunc.js');	//	引數為本.js檔名	若是更改.js檔名,亦需要同步更動此值!
494 */
495 CeL.get_base_path = function(JSFN){
496 	if(!JSFN)
497 		return (typeof WScript === 'object'
498 					? WScript.ScriptFullName
499 					: location.href
500 				).replace(/[^\/\\]+$/, '');
501 
502 	if (typeof document!=='object')
503 			return '';
504 
505 	//	form dojo: d.config.baseUrl = src.substring(0, m.index);
506 	var i, j, b, o = document.getElementsByTagName('script');
507 
508 	for (i in o)
509 		try {
510 			j = o[i].getAttribute('src');
511 			i = j.indexOf(JSFN);
512 			if (i != -1)
513 				b = j.slice(0, i);
514 		} catch (e) {
515 		}
516 
517 	return b || '';	//	this.log()
518 };
519 
520 
521 /**
522  * get the path of specified module
523  * @param {String} module_name	module name
524  * @return	{String} module path
525  */
526 CeL.get_module_path = function(module_name){
527 	if(!module_name)
528 		return module_name;
529 
530 	//this.log(this.Class+'.get_module_path: load ['+module_name+']');
531 	var module_path = this.env.registry_path
532 				|| this.get_base_path(this.env.main_script)
533 				|| this.get_base_path()
534 				;
535 	module_path += this.split_module_name(module_name).join(/\//.test(module_path)?'/':'\\') + '.js';
536 	//this.log(module_path);
537 
538 	if (this.getFP)
539 		return this.getFP(module_path, 1);
540 
541 	//this.log(module_name+': '+module_path);
542 
543 	return module_path;
544 };
545 
546 
547 /*
548 sample to test:
549 
550 ./a/b
551 ./a/b/
552 ../a/b
553 ../a/b/
554 a/../b		./b
555 a/./b		a/b
556 /../a/b		/a/b
557 /./a/b		/a/b
558 /a/./b		/a/b
559 /a/../b		/b
560 /a/../../../b	/b
561 /a/b/..		/a
562 /a/b/../	/a/
563 a/b/..		a
564 a/b/../		a/
565 a/..		.
566 ./a/b/../../../a.b/../c	../c
567 ../../../a.b/../c	../../../c
568 
569 */
570 
571 //	2009/11/23 22:12:5
572 CeL.deprecated_simplify_path = function(path){
573 	if(typeof path === 'string'){
574 		path = path.replace(/\s+$|^\s+/,'').replace(/\/\/+/g,'/');
575 
576 		var p, is_absolute = '/' === path.charAt(0);
577 
578 		while( path !== (p=path.replace(/\/\.(\/|$)/g,function($0,$1){return $1;})) )
579 			path = p;
580 		CeL.log('1. '+p);
581 
582 		while( path !== (p=path.replace(/\/([^\/]+)\/\.\.(\/|$)/g,function($0,$1,$2){alert([$0,$1,$2].join('\n'));return $1 === '..'? $0: $2;})) )
583 			path = p;
584 		CeL.log('2. '+p);
585 
586 		if(is_absolute)
587 			path = path.replace(/^(\/\.\.)+/g,'');
588 		else
589 			path = path.replace(/^(\.\/)+/g,'');
590 		CeL.log('3. '+p);
591 
592 		if(!path)
593 			path = '.';
594 	}
595 
596 	return path;
597 };
598 
599 /**
600  * 轉化所有 /., /.., //
601  * @since	2009/11/23 22:32:52
602  * @param {string} path	欲轉化之 path
603  * @return	{string} path
604  */
605 CeL.simplify_path = function(path){
606 	if(typeof path === 'string'){
607 		var i, j, l, is_absolute, head;
608 
609 		path = path
610 			.replace(/^[\w\d\-]+:\/\//,function($0){head = $0; return '';})
611 			//.replace(/\s+$|^\s+/g,'')
612 			//.replace(/\/\/+/g,'/')
613 			.split('/');
614 
615 		i = 0;
616 		l = path.length;
617 		is_absolute = !path[0];
618 
619 		for(;i<l;i++){
620 			if(path[i] === '.')
621 				path[i] = '';
622 
623 			else if(path[i] === '..'){
624 				j=i;
625 				while(j>0)
626 					if(path[--j] && path[j]!='..'){
627 						path[i] = path[j] = '';	//	相消
628 						break;
629 					}
630 			}
631 		}
632 
633 		if(!is_absolute && !path[0])
634 			path[0] = '.';
635 
636 		path = path.join('/')
637 			.replace(/\/\/+/g,'/')
638 			.replace(is_absolute? /^(\/\.\.)+/g: /^(\.\/)+/g,'')
639 			;
640 
641 		if(!path)
642 			path = '.';
643 
644 		if(head)
645 			path = head + path;
646 	}
647 
648 	return path;
649 };
650 
651 
652 
653 
654 
655 /**
656  * 已經 include 之函式或 class
657  * @inner
658  */
659 loaded_module = {
660 };
661 
662 /**
663  * Include specified module<br/>
664  * 注意:以下的 code 中,CeL.warn 不一定會被執行(可能會、可能不會),因為執行時 code.log 尚未被 include。<br/>
665  * 此時應該改用 CeL.use('code.log', callback);<br/>
666  * code in head/script/:
667  * <pre>
668  * CeL.use('code.log');
669  * CeL.warn('a WARNING');
670  * </pre>
671  * @param	{String} module	module name
672  * @param	{Function} [callback]	callback function
673  * @param	{Object, Boolean} [extend_to]	extend to which namespace<br/>
674  * false:	just load, don't extend to CeL<br/>
675  * this:	extend to global<br/>
676  * object:	extend to specified namespace that you can use [namespace]._func_ to run it<br/>
677  * (others, including undefined):	extend to root of this library. e.g., call CeL._function_name_ and we can get the specified function.
678  * @return
679  * @example
680  * CeL.use('code.log', function(){..});
681  * CeL.use(['code.log', 'code.debug']);
682  */
683 CeL.use = function(module, callback, extend_to){
684 	var i, l, module_path;
685 
686 	if (!module)
687 		return;
688 
689 	/*
690 	if (arguments.length > 3) {
691 		l = arguments.length;
692 		namespace = arguments[--l];
693 		callback = arguments[--l];
694 		--l;
695 		for (i = 0; i < l; i++)
696 			this.use(arguments[i], callback, namespace);
697 		return;
698 	}
699 	*/
700 
701 	if (module instanceof Array) {
702 		for (i = 0,l=module.length; i < l; i++)
703 			this.use(module[i], callback, extend_to);
704 		return;
705 	}
706 
707 	if (!(module_path = this.get_module_path(module)) || this.is_loaded(module))
708 		return;
709 
710 	//this.log(this.Class+'.use ['+module+']:\ntry to load ['+module_path+'].');
711 
712 	try {
713 		if (callback && typeof window !== 'undefined')
714 			this.include_resource(module_path, {
715 				module : module,
716 				callback : callback,
717 				global : this
718 			});
719 		else
720 			//this.log('load ['+module_path+']'),
721 			//this.log('load ['+module_path+']:\n'+this.get_file(module_path, this.env.source_encoding)),
722 			this.eval(this.get_file(module_path,
723 							this.env.source_encoding));
724 	} catch (e) {
725 		//	http://www.w3.org/TR/DOM-Level-2-Core/ecma-script-binding.html
726 		//	http://reference.sitepoint.com/javascript/DOMException
727 		if(e.constructor == '[object DOMException]' && e.code === 1012)
728 			this.log(e.message+'\n'+module_path
729 				+'\n\n程式可能呼叫了一個不存在的,或是繞經上層目錄的檔案?\n請嘗試使用相對路徑或 '
730 				+this.Class+'.use(module, callback function, namespace)');
731 		else
732 			this.log(
733 				this.Class+'.use: Cannot load [' + module
734 				+ ']!\n['+(e.constructor)+'] '+(e.number||e.code)+': '+e.message
735 				+'\n抱歉!在載入其他網頁時發生錯誤,有些功能可能失常。\n重新讀取(reload),或是過段時間再嘗試或許可以解決問題。'
736 			);
737 		//this.log('Cannot load [' + module + ']!', this.log.ERROR, e);
738 
739 		return;
740 	}
741 
742 	//	處理 extend to namespace
743 	if (!extend_to && extend_to !== false
744 			|| typeof namespace !== 'function'
745 			|| !(extend_to instanceof Object))
746 		extend_to = this;
747 
748 	if (extend_to) {
749 		var ns = this.get_module(module), kw = this.env.not_to_extend_keyword, no_extend = {};
750 		// this.log(this.Class + '.use [' + module + ']:\nextend\n' + ns);
751 
752 		if (kw in ns) {
753 			l = ns[kw];
754 			if (typeof l === 'string') {
755 				no_extend[l] = 1;
756 			} else if (l instanceof Array) {
757 				for (i in l)
758 					no_extend[i] = 1;
759 			} else if (l instanceof Object) {
760 				no_extend = l;
761 			}
762 			no_extend[kw] = 1;
763 		}
764 
765 		//	'*': 完全不 extend
766 		if (!no_extend['*']) {
767 			no_extend.Class = 1;
768 			l = [];
769 			for (i in ns)
770 				if (!(i in no_extend))
771 					l.push(i);
772 
773 			//this.log(this.Class + '.use [' + module + ']:\nextend\n' + l + '\n\nto:\n' + (extend_to.Class || extend_to));
774 			this.extend(l, extend_to, ns);
775 		}
776 
777 	}
778 
779 };
780 
781 
782 /*
783 bad: sometimes doesn't work. e.g. Google Maps API in IE
784 push inside window.onload:
785 window.onload=function(){
786 include_resource(p);
787 setTimeout('init();',2000);
788 };
789 
790 way 3:	ref. dojo.provide();, dojo.require();
791 document.write('<script type="text/javascript" src="'+encodeURI(p)+'"><\/script>');
792 
793 TODO:
794 encode
795 
796 */
797 ;
798 /**
799  * include other JavaScript/CSS files
800  * @param {String} resource path
801  * @param {Function, Object} callback	callback function / 	{callback: callback function, module: module name, global: global object when run callback}
802  * @param {Boolean} [use_write]	use document.write() instead of insert a element
803  * @param {Boolean} [is_css]	is a .css file
804  */
805 CeL.include_resource = function(path, callback, use_write, is_css) {
806 	var _s = arguments.callee, s, t;
807 	//if(!_f.loaded)_f.loaded={},_f.count=0;
808 
809 	if (path instanceof Array) {
810 		for (s = 0, t = path.length; s < t; s++)
811 			_f(path[s], callback, use_write, is_css);
812 		return;
813 	}
814 
815 	if(path in _s.loaded)
816 		return;
817 
818 	if(typeof c==='undefined')
819 		is_css=/\.css$/i.test(path);
820 
821 	t='text/'+(is_css?'css':'javascript');
822 /*@cc_on
823 w=1;	//	IE hack
824 @*/
825 	if (!use_write)
826 		try {
827 			// Dynamic Loading
828 			// http://code.google.com/apis/ajax/documentation/#Dynamic
829 			s = document.createElement(is_css ? 'link' : 'script');
830 			s.type = t;
831 			if (is_css)
832 				s.href = path, s.rel = 'stylesheet';
833 			else
834 				s.src = path;
835 			(document.getElementsByTagName('head')[0] || document.body.parentNode
836 					.appendChild(document.createElement('head')))
837 					.appendChild(s);
838 			//this.log('include_resource: HTML:\n' + document.getElementsByTagName('html')[0].innerHTML);
839 		} catch (e) {
840 			use_write = 1;
841 		}
842 
843 	if (use_write)
844 		document.write(is_css ? '<link type="' + t
845 				+ '" rel="stylesheet" href="' + path + '"><\/link>'
846 				: '<script type="' + t + '" src="' + path
847 				+ '"><\/script>' //	language="JScript"
848 		);
849 
850 	_s.loaded[path] = _s.count++;
851 
852 	if(callback)
853 		_s.wait_to_call(callback);
854 };
855 
856 /**
857  * 已經 include_resource 了哪些 JavaScript 檔(存有其路徑)
858  * loaded{路徑} = count
859  */
860 CeL.include_resource.loaded = {};
861 
862 /**
863  * 已經 include_resource 了多少個 JavaScript 檔
864  * @type Number
865  */
866 CeL.include_resource.count = 0;
867 
868 CeL.include_resource.wait_to_call = function(callback) {
869 	//alert('include_resource.wait_to_call:\n' + CeL.to_module_name(callback.module));
870 
871 	if (typeof callback === 'function')
872 		//	不是 module,僅僅為指定 function 的話,直接等一下再看看。
873 		//	TODO: 等太久時 error handle
874 		window.setTimeout(callback, 200);
875 
876 	else if (callback.global.is_loaded(callback.module))
877 		callback.callback();
878 
879 	else {
880 		/**
881 		 * the function it self, not 'this'.
882 		 * @inner
883 		 * @ignore
884 		 */
885 		var _s = arguments.callee;
886 		window.setTimeout(function() {
887 			_s(callback);
888 		}, 10);
889 	}
890 };
891 
892 CeL.get_module = function(module_name) {
893 	module_name = this.split_module_name(module_name);
894 
895 	//	TODO: test module_name.length
896 	if(!module_name)
897 		return null;
898 
899 	var i = 0, l = module_name.length, namespace = this;
900 	//	一層一層 call namespace
901 	while (i < l)
902 		try {
903 			namespace = namespace[module_name[i++]];
904 		} catch (e) {
905 			return null;
906 		}
907 
908 	return namespace;
909 };
910 
911 /**
912  * 預先準備好下層 module 定義時的環境。<br/>
913  * 請盡量先 call 上層 namespace 再定義下層的。
914  * @param	{String} module_name	module name
915  * @param	{Function} code_for_including	若欲 include 整個 module 時,需囊括之 code。
916  * @return	null	invalid module
917  * @return	{Object}	下層 module 之 namespace
918  */
919 CeL.setup_module = function(module_name, code_for_including) {
920 	module_name = this.split_module_name(module_name);
921 
922 	//	TODO: test module_name.length
923 	if(!module_name)
924 		return null;
925 
926 	var i = 0, l = module_name.length - 1, namespace = this, name;
927 	//	一層一層準備好 namespace
928 	for (; i < l; i++) {
929 		if (!namespace[name = module_name[i]])
930 			namespace[name] = new Function(
931 					'//	module namespace of ' +
932 					this.to_module_name(module_name.slice(0, i + 1)));
933 		namespace = namespace[name];
934 	}
935 	//	namespace 這時是 modele 的 parent modele。
936 
937 	if (
938 			// 尚未被定義或宣告過
939 			!namespace[name = module_name[l]] ||
940 			// 可能是之前簡單定義過,例如被上面處理過。這時重新定義,並把原先的 member 搬過來。
941 			!namespace[name].Class) {
942 
943 		//	保留原先的 namespace,for 重新定義
944 		l = namespace[name];
945 
946 		// extend code, 起始 namespace
947 		//	TODO: code_for_including(this, load_arguments)
948 		namespace = namespace[name] = code_for_including(this);
949 
950 		// 把原先的 member 搬過來
951 		if (l) {
952 			delete l.Class;
953 			//	may use: this.extend() 
954 			for (i in l)
955 				namespace[i] = l[i];
956 		}
957 		namespace.Class = this.to_module_name(module_name);
958 	}
959 
960 /*
961 	l=[];
962 	for(i in namespace)
963 		l.push(i);
964 	WScript.Echo('Get members:\n'+l.join(', '));
965 */
966 
967 	this.set_loaded(namespace.Class, code_for_including);
968 
969 	return namespace;
970 };
971 
972 
973 //	並沒有對 module 做完善的審核!
974 CeL.split_module_name = function(module_name) {
975 	if (typeof module_name === 'string')
976 		module_name = module_name.replace(/\.\.+|\\\\+|\/\/+/g, '.').split(/\.|\\|\/|::/);
977 
978 	if (module_name instanceof Array) {
979 		//	去除 library name
980 		if (module_name.length>1 && this.Class == module_name[0])
981 			module_name.shift();
982 		return module_name;
983 	} else
984 		return null;
985 };
986 
987 
988 CeL.to_module_name = function(module, separator) {
989 	if (typeof module === 'function')
990 		module = module.Class;
991 
992 	if (typeof module === 'string')
993 		module = this.split_module_name(module);
994 
995 	var name = '';
996 	if (module instanceof Array) {
997 		if (typeof separator !== 'string')
998 			separator = this.env.module_name_separator;
999 		if (module[0] != this.Class)
1000 			name = this.Class + separator;
1001 		name += module.join(separator);
1002 	}
1003 
1004 	return name;
1005 };
1006 
1007 //	TODO
1008 CeL.unload = function(module, g){
1009 };
1010 
1011 
1012 /**
1013  * 判斷 module 是否存在,以及是否破損。
1014  * @param	{String} module_name	module name
1015  * @return	{Boolean} module 是否存在以及良好。
1016  */
1017 CeL.is_loaded = function(module_name) {
1018 	// var _s = arguments.callee;
1019 	//this.log('is_loaded: test ' + this.to_module_name(module_name));
1020 	return loaded_module[this.to_module_name(module_name)] ? true
1021 			: false;
1022 };
1023 
1024 
1025 
1026 CeL.set_loaded = function(module_name, code_for_including) {
1027 	//this.log('set_loaded: ' + this.to_module_name(module_name));
1028 	loaded_module[this.to_module_name(module_name)] = code_for_including || true;
1029 };
1030 
1031 
1032 
1033 //	initial
1034 
1035 //temporary decoration incase we call for nothing
1036 CeL.log = function(){
1037 if(debug)
1038 	//arguments.callee.function_to_call.apply(null,arguments);
1039 	arguments.callee.function_to_call.apply(global, arguments);
1040 };
1041 
1042 
1043 CeL.log.function_to_call =
1044 	typeof JSalert==='function'?JSalert:
1045 	typeof WScript==='object'?function(m){m=''+m;if(m.length>2000)m=m.slice(0,1000)+'\n\n..\n\n'+m.slice(-1000);WScript.Echo(m);}:
1046 	typeof alert==='object' || typeof alert==='function'? function(m){m=''+m;if(m.length>2000)m=m.slice(0,1000)+'\n\n..\n\n'+m.slice(-1000);alert(m);}:
1047 	function(){};
1048 
1049 CeL.initial_env();
1050 
1051 
1052 /*
1053 var test_obj=CeL(2,'test: initial');
1054 
1055 test_obj.test_print('OK!');
1056 */
1057 ;
1058 
1059 
1060 
1061 //setTool(),oldVadapter();	//	當用此檔debug時請執行此行
1062 //alert(ScriptEngine()+' '+ScriptEngineMajorVersion()+'.'+ScriptEngineMinorVersion()+'.'+ScriptEngineBuildVersion());
1063 
1064 
1065 
1066 /*	initialization of function.js
1067 	僅僅執行此檔時欲執行的程序。
1068 
1069 setTool(),oldVadapter();	//	當用此檔debug時請執行此行
1070 
1071 	利用.js加上此段與init(),以及.hta(<script type="text/javascript" src="~.js"></script>),可造出GUI/none GUI兩種可選擇之介面。
1072 	if(typeof args=='object')init();else window.onload=init;
1073 */
1074 //args=args.concat(['turnCode.js']);
1075 var _library_onload;
1076 if (typeof _library_onload === 'undefined')
1077 	_library_onload = function() {
1078 		//WScript.Echo(CeL.env.ScriptName);
1079 		//CeL.log(CeL.env.ScriptName);
1080 		if (1 && CeL.env.ScriptName === 'ce') {
1081 			//WScript.Echo(CeL.env.ScriptName);
1082 			CeL.use('OS.Windows.registry');
1083 			//CeL.log(CeL.registryF);
1084 
1085 			var _p = CeL.registryF.getValue(CeL._iF.p) || '(null)';
1086 			if (_p != CeL.env.library_base_path) {
1087 				CeL.log('Change path of [' + CeL.env.ScriptName + '] from:\n' + _p
1088 						+ '\n to\n' + CeL.env.library_base_path + '\n\n' + CeL._iF.p);
1089 				CeL.registryF.setValue.cid = 1;
1090 				CeL.registryF.setValue(CeL._iF.p, CeL.env.library_base_path, 0, 0, 1);
1091 				CeL.registryF.setValue.cid = 0;
1092 			}
1093 
1094 			if (typeof args === 'object') {// args instanceof Array
1095 				// getEnvironment();
1096 				// alert('Get arguments ['+args.length+']\n'+args.join('\n'));
1097 				if (args.length) {
1098 					var i = 0, p, enc, f, backupDir = dBasePath('kanashimi\\www\\cgi-bin\\program\\log\\');
1099 					if (!fso.FolderExists(backupDir))
1100 						try {
1101 							fso.CreateFolder(backupDir);
1102 						} catch (e) {
1103 							backupDir = dBasePath('kanashimi\\www\\cgi-bin\\game\\log\\');
1104 						}
1105 					if (!fso.FolderExists(backupDir))
1106 						try {
1107 							fso.CreateFolder(backupDir);
1108 						} catch (e) {
1109 							if (2 == alert(
1110 									'無法建立備份資料夾[' + backupDir + ']!\n接下來的操作將不會備份!',
1111 									0, 0, 1 + 48))
1112 								WScript.Quit();
1113 							backupDir = '';
1114 						}
1115 					// addCode.report=true; // 是否加入報告
1116 					for (; i < args.length; i++)
1117 						if ((f = dealShortcut(args[i], 1))
1118 								.match(/\.(js|vbs|hta|s?html?|txt|wsf|pac)$/i)
1119 								&& isFile(f)) {
1120 							p = alert(
1121 									'是否以預設編碼['
1122 											+ ((enc = autodetectEncode(f)) == simpleFileDformat ? '內定語系(' + simpleFileDformat + ')'
1123 													: enc) + ']處理下面檔案?\n' + f,
1124 									0, 0, 3 + 32);
1125 							if (p == 2)
1126 								break;
1127 							else if (p == 6) {
1128 								if (backupDir)
1129 									fso.CopyFile(f, backupDir + getFN(f), true);
1130 								addCode(f);
1131 							}
1132 						}
1133 				} else if (1 == alert('We will generate a reduced ['
1134 						+ CeL.env.ScriptName + ']\n  to [' + CeL.env.ScriptName
1135 						+ '.reduced.js].\nBut it takes several time.', 0, 0,
1136 						1 + 32))
1137 					reduceScript(0, CeL.env.ScriptName + '.reduced.js');
1138 			}//else window.onload=init;
1139 
1140 			//CeL._iF=undefined;
1141 		} //	if(1&&CeL.env.ScriptName==='function'){
1142 	}; //	_library_onload
1143 
1144 
1145 
1146 
1147 
1148 /*
1149 
1150 //	test WinShell	http://msdn.microsoft.com/en-us/library/bb787810(VS.85).aspx
1151 if (0) {
1152 	alert(WinShell.Windows().Item(0).FullName);
1153 
1154 	var i, cmd, t = '', objFolder = WinShell.NameSpace(0xa), objFolderItem = objFolder
1155 			.Items().Item(), colVerbs = objFolderItem.Verbs(); // 假如出意外,objFolder==null
1156 	for (i = 0; i < colVerbs.Count; i++) {
1157 		t += colVerbs.Item(i) + '\n';
1158 		if (('' + colVerbs.Item(i)).indexOf('&R') != -1)
1159 			cmd = colVerbs.Item(i);
1160 	}
1161 	objFolderItem.InvokeVerb('' + cmd);
1162 	alert('Commands:\n' + t);
1163 
1164 	// objShell.NameSpace(FolderFrom).CopyHere(FolderTo,0); // copy folder
1165 	// objFolderItem=objShell.NameSpace(FolderFrom).ParseName("clock.avi");objFolderItem.Items().Item().InvokeVerb([動作]);
1166 	// objShell.NameSpace(FolderFromPath).Items.Item(mName).InvokeVerb();
1167 
1168 	// Sets or gets the date and time that a file was last modified.
1169 	// http://msdn.microsoft.com/en-us/library/bb787825(VS.85).aspx
1170 	// objFolderItem.ModifyDate = "01/01/1900 6:05:00 PM";
1171 	// objShell.NameSpace("C:\Temp").ParseName("Test.Txt").ModifyDate =
1172 	// DateAdd("d", -1, Now()) CDate("19 October 2007")
1173 
1174 	// Touch displays or sets the created, access, and modified times of one or
1175 	// more files. http://www.stevemiller.net/apps/
1176 }
1177 
1178 //	測試可寫入的字元:0-128,最好用1-127,因為許多編輯器會將\0轉成' ',\128又不確定
1179 if (0) {
1180 	var t = '', f = 'try.js', i = 0;
1181 	for (; i < 128; i++)
1182 		t += String.fromCharCode(i);
1183 	if (simpleWrite(f, t))
1184 		alert('Write error!\n有此local無法相容的字元?');
1185 	else if (simpleRead(f) != t)
1186 		alert('內容不同!');
1187 	else if (simpleWrite(f, dQuote(t) + ';'))
1188 		alert('Write error 2!\n有此local無法相容的字元?');
1189 	else if (eval(simpleRead(f)) != t)
1190 		alert('eval內容不同!');
1191 	else
1192 		alert('OK!');
1193 }
1194 */
1195 
1196 
1197 if(_library_onload)
1198 	_library_onload();
1199 
1200 
1201 })()	//	(function(){
1202 //)	//	void(
1203 ;
1204 
1205 
1206 //}catch(e){WScript.Echo('There are some error in function.js!\n'+e.message);throw e;}
1207 
1208 
1209 
1210 
1211 
1212 //CeL.use('code.log');
1213 //CeL.warn('test_print: ' + CeL.code.log.Class);
1214 
1215 //]]>
1216 
1217 
1218 
1219 if (typeof CeL === 'function'){
1220 
1221 /**
1222  * 本 module 之 name(id),<span style="text-decoration:line-through;">不設定時會從呼叫時之 path 取得</span>。
1223  * @type	String
1224  * @constant
1225  * @inner
1226  * @ignore
1227  */
1228 var module_name = 'IO.Windows.file';
1229 
1230 //===================================================
1231 /**
1232  * 若欲 include 整個 module 時,需囊括之 code。
1233  * @type	Function
1234  * @param	{Function} library_namespace	namespace of library
1235  * @param	load_arguments	呼叫時之 argument(s)
1236  * @return
1237  * @constant
1238  * @inner
1239  * @ignore
1240  */
1241 var code_for_including = function(library_namespace, load_arguments) {
1242 
1243 
1244 /**
1245  * null module constructor
1246  * @class	Windows 下,檔案操作相關之 function。
1247  */
1248 CeL.IO.Windows.file
1249 = function() {
1250 	//	null module constructor
1251 };
1252 
1253 /**
1254  * for JSDT: 有 prototype 才會將之當作 Class
1255  */
1256 CeL.IO.Windows.file
1257 .prototype = {
1258 };
1259 
1260 
1261 
1262 /*
1263 	JScript only	-------------------------------------------------------
1264 */
1265 
1266 CeL.IO.Windows.file
1267 .
1268 /**
1269  * FileSystemObject Object I/O mode enumeration
1270  * @see	<a href="http://msdn.microsoft.com/en-us/library/314cz14s%28VS.85%29.aspx" accessdate="2009/11/28 17:42" title="OpenTextFile Method">OpenTextFile Method</a>
1271  */
1272 iomode = {
1273 	// * @_description <a href="#.iomode">iomode</a>: Open a file for reading only. You can't write to this file.
1274 	/**
1275 	 * Open a file for reading only. You can't write to this file.
1276 	 * @memberOf	CeL.IO.Windows.file
1277 	 */
1278 	ForReading : 1,
1279 	/**
1280 	 * Open a file for writing.
1281 	 * @memberOf	CeL.IO.Windows.file
1282 	 */
1283 	ForWriting : 2,
1284 	/**
1285 	 * Open a file and write to the end of the file.
1286 	 * @memberOf	CeL.IO.Windows.file
1287 	 */
1288 	ForAppending : 8
1289 };
1290 
1291 CeL.IO.Windows.file
1292 .
1293 /**
1294  * FileSystemObject Object file open format enumeration
1295  * @see	<a href="http://msdn.microsoft.com/en-us/library/314cz14s%28VS.85%29.aspx" accessdate="2009/11/28 17:42" title="OpenTextFile Method">OpenTextFile Method</a>
1296  */
1297 open_format = {
1298 	/**
1299 	 * Opens the file using the system default.
1300 	 * @memberOf	CeL.IO.Windows.file
1301 	 */
1302 	TristateUseDefault : -2,
1303 	/**
1304 	 * Opens the file as Unicode.
1305 	 * @memberOf	CeL.IO.Windows.file
1306 	 */
1307 	TristateTrue : -1,
1308 	/**
1309 	 * Opens the file as ASCII.
1310 	 * @memberOf	CeL.IO.Windows.file
1311 	 */
1312 	TristateFalse : 0
1313 };
1314 
1315 
1316 var path_separator = library_namespace.env.path_separator, path_separator_RegExp = library_namespace.env.path_separator_RegExp, new_line = library_namespace.env.new_line, WshShell,
1317 /**
1318  * FileSystemObject
1319  */
1320 fso = WScript.CreateObject("Scripting.FileSystemObject"),
1321 // XMLHttp,
1322 WinShell // initWScriptObj
1323 , args, ScriptHost;
1324 
1325 
1326 /*	↑JScript only	-------------------------------------------------------
1327 */
1328 
1329 
1330 
1331 
1332 /*
1333 
1334 return {Object} report
1335 	.list	files matched
1336 	.succeed	success items
1337 	.failed	failed items
1338 	.log	log text
1339 	.undo	undo data
1340 
1341 usage example:
1342 	move_file()	get file list array of current dir.
1343 	move_file(0,0,'dir')	get file list array of dir.
1344 	move_file('*.*','*.jpg','dir')	Error! Please use RegExp('.*\..*') or turnWildcardToRegExp('*.*')
1345 	move_file(/file(\d+).jpg/,0,'dir')	get file list array of dir/file(\d+).jpg
1346 	move_file(f1,move_file.f.remove)	delete f1
1347 	move_file('f1','f2')	[f1]->[f2]
1348 	move_file('f1','f2','.',move_file.f.copy|move_file.f.reverse)	copy [./f2] to [./f1]
1349 	move_file(/file(\d+).jpg/,/file ($1).jpg/,'dir')	[dir/file(\d+).jpg]->[dir/file ($1).jpg]	can't use fuzzy or reverse in this time
1350 
1351 prog example:
1352 	function move_file_filter(fn){var n=fn.match(/0000(\d+)\(\d\)\.pdf/);if(!n)return true;n=n[1];if(n!=0&&n!=1&&n!=7&&n!=10&&n!=13&&n!=15&&n!=26&&n!=28)return true;try{n=fn.match(/(\d+)\(\d\)\.pdf/);FileSystemObject.MoveFile(n[1]+'('+(n[1]?vol-1:vol-2)+').pdf',n[1]+'.pdf');}catch(e){}return;}
1353 	var vol=11,doMove=move_file(new RegExp('(\\d+)\\('+vol+'\\)\\.pdf'),'$1.pdf');
1354 	write_to_file('move.log','-'.x(60)+new_line+doMove.log,open_format.TristateTrue,ForAppending);
1355 	write_to_file('move.undo.'+vol+'.txt',doMove.undo,open_format.TristateTrue),write_to_file('move.undo.'+vol+'.bat',doMove.undo);//bat不能用open_format.TristateTrue
1356 	alert('Done '+doMove.succeed+'/'+doMove.list.length);
1357 
1358 	for Win98, turn lower case:
1359 	move_file(/^[A-Z\d.]+$/,function($0){return '_mv_tmp_'+$0.toLowerCase();},'.',move_file.f.include_folder|move_file.f.include_subfolder);
1360 	alert(move_file(/^_mv_tmp_/,'','.',move_file.f.include_folder|move_file.f.include_subfolder).log);
1361 
1362 
1363 for(var i=0,j,n,m;i<40;i++)
1364  if(!fso.FileExists(n='0000'+(i>9?'':'0')+i+'.pdf'))for(j=0;j<25;j++)
1365   if(fso.FileExists(m='0000'+(i>9?'':'0')+i+'('+j+').pdf')){try{fso.MoveFile(m,n);}catch(e){}break;}
1366 
1367 TODO:
1368 move newer	把新檔移到目的地,舊檔移到 bak。
1369 
1370 */
1371 CeL.IO.Windows.file
1372 .
1373 /**
1374  * move/rename files, ** use RegExp, but no global flag **<br/>
1375  * 可用 move_file_filter() 來排除不要的<br/>
1376  * 本函數可能暫時改變目前工作目錄!
1377  * @param from
1378  * @param to
1379  * @param base_path
1380  * @param flag
1381  * @param {Function} filter	可用 filter() 來排除不要的
1382  * @return	{Object} report
1383  * @since	2004/4/12 17:25
1384  * @requires	path_separator,fso,WshShell,new_line,Enumerator
1385  */
1386 move_file = function(from, to, base_path, flag, filter) {
1387 	var _s = arguments.callee, _f = _s.f
1388 	// '.?': 一定會match
1389 	default_from = new RegExp('.?'), t, CurrentDirectory, report = {};
1390 	// alert(typeof from+','+from.constructor);
1391 	if (flag & _f.reverse)
1392 		//flag-=_f.reverse,
1393 		t = from, from = to, to = t;
1394 	if (!from)
1395 		from = default_from;
1396 	else if (typeof from != 'string'
1397 		&& (typeof from != 'object' || !(from instanceof RegExp)
1398 				&& !(from = '' + from)))
1399 		from = default_from;
1400 	report.list = [], report.succeed = report.failed = 0,
1401 	report.undo = report.log = '';
1402 
1403 	if (!base_path)
1404 		base_path = '.' + path_separator;
1405 	else if (typeof get_folder === 'function')
1406 		base_path = get_folder(base_path);
1407 
1408 	if ((base_path = '' + base_path).slice(
1409 			// -1, or try: base_path.length-path_separator.length
1410 			-1) != path_separator)
1411 		base_path += path_separator;
1412 
1413 	if (typeof fso === 'undefined')
1414 		fso = new ActiveXObject("Scripting.FileSystemObject");
1415 	else if (typeof fso !== 'object')
1416 		throw new Error(1, 'fso was already seted!');
1417 	try {
1418 		dir = fso.GetFolder(base_path);
1419 	} catch (e) {
1420 		throw new Error(e.number,
1421 				'move_file(): 基準路徑不存在\n' + e.description);
1422 	}
1423 
1424 	// TODO: 對from不存在與為folder之處裡:fuzzy
1425 
1426 	if (flag & _f.include_subfolder) {
1427 		CurrentDirectory = WshShell.CurrentDirectory;
1428 		for ( var i = new Enumerator(dir.SubFolders); !i.atEnd(); i
1429 		.moveNext())
1430 			_s(from, to, i.item(), flag);
1431 		if (base_path)
1432 			// 改變目前工作目錄
1433 			WshShell.CurrentDirectory = base_path;
1434 	}
1435 	// if(flag&_f.include_folder){}
1436 	var i, f = new Enumerator(dir.Files), use_exact = typeof from === 'string', overwrite = flag
1437 	& _f.overwrite, not_test = !(flag & _f.Test), func = flag
1438 	& _f.copy ? 'copy' : to === _f.remove || flag & _f.remove
1439 			&& !to ? 'delete' : from != default_from || to ? 'move'
1440 					: 'list';
1441 	// if(func=='delete')to=_f.remove; // 反正不是用這個判別的
1442 	//alert('use_exact: '+use_exact+'\nbase_path: '+base_path+'\nfrom: '+from);
1443 	// BUG: 這樣順序會亂掉,使得 traverse (遍歷)不完全
1444 	for (; !f.atEnd(); f.moveNext())
1445 		if (i = f.item(), use_exact && i.Name == from || !use_exact
1446 				&& from.test(i.Name)) {
1447 			report.list.push(i.Name);
1448 
1449 			if (typeof filter == 'function' && !filter(i.Name))
1450 				continue;
1451 			t = func == 'copy' || func == 'move' ? i.Name.replace(from,
1452 					typeof to === 'object' ? to.source : to) : '';
1453 
1454 			if (t)
1455 				try {
1456 					report.log += func + ' [' + i.Name + ']'
1457 					+ (t ? ' to [' + t + '] ' : '');
1458 					var u = '';
1459 					t = (base_path == default_from ? base_path : '')
1460 					+ t;
1461 					if (func == 'delete') {
1462 						if (not_test)
1463 							i.Delete(overwrite);
1464 					} else if (!fso.FileExists(t) || overwrite) {
1465 						if (not_test) {
1466 							if (overwrite && fso.FileExists(t))
1467 								fso.DeleteFile(t);
1468 							if (func == 'copy')
1469 								//	Copy() 用的是 FileSystemObject.CopyFile or FileSystemObject.CopyFolder, 亦可用萬用字元(wildcard characters)
1470 								i.Copy(t, overwrite);
1471 							else
1472 								i.Move(t);
1473 						}
1474 						u = 'move	' + t + '	' + i.Name + new_line;
1475 					} else {
1476 						report.log += ': target existing, ';
1477 						throw 1;
1478 					}
1479 					report.log += 'succeed.' + new_line,
1480 					report.undo += u, report.succeed++;
1481 				} catch (e) {
1482 					report.log += 'failed.' + new_line, report.failed++;
1483 				}
1484 				//alert(i.Name+','+t);
1485 		}
1486 
1487 	if (flag & _f.include_subfolder && CurrentDirectory)
1488 		WshShell.CurrentDirectory = CurrentDirectory;
1489 	report.log += new_line + (not_test ? '' : '(test)') + func + ' ['
1490 	+ from + '] to [' + to + ']' + new_line
1491 	+ (typeof gDate == 'function' ? gDate() + '	' : '')
1492 	+ 'done ' + report.succeed + '/' + report.list.length
1493 	+ new_line;
1494 	return report;
1495 };
1496 
1497 //var move_file.f;
1498 //setObjValue('move_file.f','none=0,overwrite=1,fuzzy=2,reverse=4,include_folder=8,include_subfolder=16,Test=32,copy=64,remove=128','int');
1499 CeL.IO.Windows.file
1500 .
1501 /**
1502  * <a href="#.move_file">move_file</a> 的 flag enumeration
1503  * @constant
1504  */
1505 move_file.f = {
1506 		/**
1507 		 * null flag
1508 		 * @memberOf CeL.IO.Windows.file
1509 		 */
1510 		none : 0,
1511 		/**
1512 		 * overwrite target
1513 		 * @memberOf CeL.IO.Windows.file
1514 		 */
1515 		overwrite : 1,
1516 		/**
1517 		 * If source don't exist but target exist, than reverse.
1518 		 * @deprecated	TODO
1519 		 * @memberOf CeL.IO.Windows.file
1520 		 */
1521 		fuzzy : 2,
1522 		/**
1523 		 * reverse source and target
1524 		 * @memberOf CeL.IO.Windows.file
1525 		 */
1526 		reverse : 4,
1527 		/**
1528 		 * include folder
1529 		 * @memberOf CeL.IO.Windows.file
1530 		 */
1531 		include_folder : 8,
1532 		/**
1533 		 * include sub-folder
1534 		 * @memberOf CeL.IO.Windows.file
1535 		 */
1536 		include_subfolder : 16,
1537 		/**
1538 		 * Just do a test
1539 		 * @memberOf CeL.IO.Windows.file
1540 		 */
1541 		Test : 32,
1542 		/**
1543 		 * copy, instead of move the file
1544 		 * @memberOf CeL.IO.Windows.file
1545 		 */
1546 		copy : 64,
1547 		/**
1548 		 * 當 target 指定此 flag,或包含此 flag 而未指定 target 時,remove the source。
1549 		 * @memberOf CeL.IO.Windows.file
1550 		 */
1551 		remove : 128
1552 };
1553 
1554 CeL.IO.Windows.file
1555 .
1556 /**
1557  * move file
1558  * @requires	fso,get_folder,getFN,initWScriptObj
1559  */
1560 mv = function(from, to, dir, onlyFN, reverse) {
1561 	if (!from || !to || from == to)
1562 		return new Error(1, 'filename error.');
1563 	var e;
1564 	dir = get_folder(dir);
1565 
1566 	if (reverse)
1567 		e = from, from = to, to = e;
1568 	e = function(_i) {
1569 		return fso.FileExists(_i) ? _i : dir ? dir
1570 				+ (onlyFN ? getFN(_i) : _i) : null;
1571 	};
1572 
1573 	try {
1574 		// alert('mv():\n'+dir+'\n\n'+e(from)+'\n→\n'+e(to));
1575 		fso.MoveFile(e(from), e(to));
1576 		return;
1577 	} catch (e) {
1578 		e.message = 'mv():\n' + from + '\n→\n' 
1579 				+ to// +'\n\n'+e.message
1580 				;
1581 		return e;
1582 	}
1583 };
1584 
1585 
1586 /*
1587 function mv(from,to,dir,onlyFN,reverse){
1588  var e,_f,_t;
1589  dir=get_folder(dir);
1590 
1591  if(reverse)e=from,from=to,to=e;
1592  _f=from;
1593  _t=to;
1594  to=0;
1595  e=function(_i){
1596   return fso.FileExists(_i)?_i:dir&&fso.FileExists(_i=dir+(onlyFN?getFN(_i):_i))?_i:0;
1597  };
1598 
1599  try{
1600   if(!(_f=e(_f)))to=1;else if(!(_t=e(_t)))to=2;
1601   else{
1602    alert('mv():\n'+dir+'\n\n'+_f+'\n→\n'+_t);
1603    fso.MoveFile(_f,_t);
1604    return;
1605   }
1606  }catch(e){return e;}
1607  return e||new Error(to,(to==1?'移動するファイルは存在しない':'移動先が既存した')+':\n'+_f+'\n→\n'+_t);
1608 }
1609 
1610 
1611 function mv(from,to,dir,onlyFN,reverse){
1612  var e,_f,_t;
1613  dir=get_folder(dir);
1614 
1615  if(reverse)e=from,from=to,to=e;
1616  _f=from,_t=to,to=e=0;
1617 
1618  try{
1619   if(!fso.FileExists(_f)&&(!dir||!fso.FileExists(_f=dir+(onlyFN?getFN(_f):_f))))to=1;
1620   else if(fso.FileExists(_t)&&(!dir||fso.FileExists(_t=dir+(onlyFN?getFN(_t):_t))))to=2;
1621   else{
1622    alert('mv():\n'+dir+'\n'+_f+'\n→\n'+_t);
1623    //fso.MoveFile(_f,_t);
1624    return;
1625   }
1626  }catch(e){}
1627  return e||new Error(to,(to==1?'移動するファイルは存在しない':'移動先が既存した')+':\n'+_f+'\n→\n'+_t);
1628 }
1629 
1630 */
1631 
1632 
1633 /*
1634 
1635 下面一行調到檔案頭
1636 var get_file_details_items,get_file_details_get_object=-62.262;
1637 */
1638 _.
1639 /**
1640  * get file details (readonly)
1641  * @example
1642  * get_file_details('path');
1643  * get_file_details('file/folder name',parentDir);
1644  * get_file_details('path',get_file_details_get_object);
1645  * @see	<a href="http://msdn.microsoft.com/en-us/library/bb787870%28VS.85%29.aspx" accessdate="2009/11/29 22:52" title="GetDetailsOf Method (Folder)">GetDetailsOf Method (Folder)</a>
1646  * @memberOf	CeL.IO.Windows.file
1647  */
1648 get_file_details = function(fileObj, parentDirObj) {
1649 	var i, n, r;
1650 	// WinShell=new ActiveXObject("Shell.Application");
1651 	if (typeof WinShell == 'undefined' || !fileObj)
1652 		return;
1653 
1654 	// deal with fileObj & parentDirObj
1655 	if (parentDirObj === get_file_details_get_object)
1656 		parentDirObj = 0, n = 1;
1657 	// else n='';
1658 	if (!parentDirObj) {
1659 		// fileObj is path
1660 		if (typeof fileObj != 'string')
1661 			return;
1662 		if (i = fileObj.lastIndexOf('/') + 1)
1663 			parentDirObj = fileObj.slice(0, i - 1), fileObj = fileObj
1664 			.slice(i);
1665 		else
1666 			return;
1667 	}
1668 	if (typeof parentDirObj == 'string')
1669 		parentDirObj = WinShell.NameSpace(parentDirObj);
1670 	if (typeof fileObj == 'string' && fileObj)
1671 		fileObj = parentDirObj.ParseName(fileObj);
1672 	if (n)
1673 		// just get [(object)parentDirObj,(object)fileObj]
1674 		return [ parentDirObj, fileObj ];
1675 
1676 	// get item name
1677 	if (typeof get_file_details_items != 'object') {
1678 		get_file_details_items = [];
1679 		for (i = 0, j; i < 99; i++)
1680 			// scan cols
1681 			if (n = WinShell.NameSpace(0).GetDetailsOf(null, i))
1682 				get_file_details_items[i] = n;
1683 	}
1684 
1685 	// main process
1686 	//for(i=0,r=[];i<get_file_details_items.length;i++)
1687 	r = [];
1688 	for (i in get_file_details_items) {
1689 		//if(get_file_details_items[i])
1690 		r[get_file_details_items[i]] = r[i] = parentDirObj
1691 		.GetDetailsOf(fileObj, i);
1692 	}
1693 
1694 	return r;
1695 };
1696 
1697 
1698 
1699 
1700 _.
1701 /*
1702 TODO
1703 	未來:change_attributes(path,'-ReadOnly&-Hidden&-System')
1704 
1705 下面調到檔案頭
1706 setObjValue('Attribute','Normal=0,none=0,ReadOnly=1,Hidden=2,System=4,Volume=8,Directory=16,Archive=32,Alias=64,Compressed=128','int');
1707 setObjValue('AttributeV','0=Normal,1=ReadOnly,2=Hidden,4=System,8=Volume,16=Directory,32=Archive,64=Alias,128=Compressed');
1708 */
1709 /**
1710  * 改變檔案之屬性
1711  * @param	F	file path
1712  * @param	A	attributes, 屬性
1713  * @example
1714  * change_attributes(path,'-ReadOnly');
1715  * @memberOf	CeL.IO.Windows.file
1716  */
1717 change_attributes = function(F, A) {
1718 	if (!F)
1719 		return -1;
1720 	if (typeof F === 'string')
1721 		try {
1722 			F = fso.GetFile(F);
1723 		} catch (e) {
1724 			return -2;
1725 		}
1726 	var a;
1727 	try {
1728 		a = F.Attributes;
1729 	} catch (e) {
1730 		return -3;
1731 	}
1732 	if (typeof A === 'undefined')
1733 		A = a;
1734 	else if (A === '' || A == 'Archive')
1735 		A = 32;
1736 	else if (A == 'Normal')
1737 		A = 0;
1738 	else if (isNaN(A))
1739 		if (A.charAt(0) === 'x' || A.charAt(0) === '-')
1740 			if (A = -Attribute[A.substr(1)], A && a % (A << 2))
1741 				A = a + A;
1742 			else
1743 				A = a;
1744 		else if (A = Attribute[A], A && a % (A << 2) == 0)
1745 			A = a + A;
1746 		else
1747 			A = a;
1748 	else if (AttributeV[A])
1749 		if (a % (A << 2) == 0)
1750 			A = a + A;
1751 		else
1752 			A = a;
1753 	else if (AttributeV[-A])
1754 		if (a % (A << 2))
1755 			A = a + A;
1756 		else
1757 			A = a;
1758 	if (a != A)
1759 		try {
1760 			F.Attributes = A;
1761 		} catch (e) {
1762 			popErr(e);
1763 			//	70:防寫(沒有使用權限)
1764 			return 70 == (e.number & 0xFFFF) ? -8 : -9;
1765 		}
1766 	return F.Attributes;
1767 };
1768 
1769 
1770 
1771 
1772 
1773 _.
1774 /**
1775  * 開檔處理<br/>
1776  * 測試是否已開啟資料檔之測試與重新開啟資料檔
1777  * @param FN	file name
1778  * @param NOTexist	if NOT need exist
1779  * @param io_mode	IO mode
1780  * @return
1781  * @requires	fso,WshShell,iomode
1782  * @memberOf	CeL.IO.Windows.file
1783  */
1784 openDataTest = function(FN, NOTexist, io_mode) {
1785 	if (!FN)
1786 		return 3;
1787 	if (NOTexist && !fso.FileExists(FN))
1788 		return 0;
1789 	if (!io_mode)
1790 		io_mode = _.iomode.ForAppending;
1791 	for (;;)
1792 		try {
1793 			var Fs = fso.OpenTextFile(FN, ForAppending);
1794 			Fs.Close();
1795 			break;
1796 		} catch (e) {
1797 			// 對執行時檔案已經開啟之處理
1798 			//if(typeof e=='object'&&e.number&&(e.number&0xFFFF)==70)
1799 			if ((e.number & 0xFFFF) != 70) {
1800 				return pErr(e, 0,
1801 						'開啟資料檔 [<green>' + FN + '<\/>] 時發生錯誤!'),
1802 						6 == alert(
1803 								'開啟資料檔 [' + FN + ']時發生不明錯誤,\n	是否中止執行?',
1804 								0, ScriptName + ' 測試是否已開啟資料檔:發生不明錯誤!',
1805 								4 + 48) ? 1 : 0;
1806 			}
1807 			if (2 == WshShell.Popup(
1808 					'★資料檔:\n\	' + FN + '\n	無法寫入!\n\n可能原因與解決方法:\n	①資料檔已被開啟。執行程式前請勿以其他程式開啟資料檔!\n	②資料檔被設成唯讀,請取消唯讀屬性。',
1809 					0, ScriptName + ':資料檔開啟發生錯誤!', 5 + 48))
1810 				return 2;
1811 		}
1812 	return 0;
1813 };
1814 
1815 _.
1816 /**
1817  * 
1818  * @param FN
1819  * @param format
1820  * @param io_mode
1821  * @return
1822  */
1823 open_template = function(FN, format, io_mode) {
1824 	/**
1825 	 * file
1826 	 * @inner
1827 	 * @ignore
1828 	 */
1829 	var F,
1830 	/**
1831 	 * file streams
1832 	 * @inner
1833 	 * @ignore
1834 	 */
1835 	Fs;
1836 	if (!io_mode)
1837 		io_mode = _.iomode.ForReading;
1838 	if (!format)
1839 		//format=autodetectEncode(FN);
1840 		format = _.open_format.TristateUseDefault;// TristateTrue
1841 	try {
1842 		F = fso.GetFile(FN);
1843 		//Fs=_.open_file(FN,format,io_mode);
1844 		Fs = F.OpenAsTextStream(io_mode, format);
1845 	} catch (e) {
1846 		// 指定的檔案不存在?
1847 		pErr(e);
1848 		// quit();
1849 	}
1850 	return Fs;
1851 };
1852 
1853 //var openOut.f;	//	default format
1854 function openOut(FN,io_mode,format){
1855  var OUT,OUTs,_f=arguments.callee.f;
1856  if(!io_mode)io_mode=_.iomode.ForWriting;
1857  if(!format)format=_f=='string'&&_f?_f:_.open_format.TristateUseDefault;
1858  try{
1859   OUT=fso.GetFile(FN);
1860  }
1861  catch(e){try{
1862   //指定的檔案不存在
1863   var tmp=fso.CreateTextFile(FN,true);
1864   tmp.Close();
1865   OUT=fso.GetFile(FN);
1866  }catch(e){pErr(e);}}
1867 
1868  try{OUTs=OUT.OpenAsTextStream(io_mode,format);}catch(e){pErr(e);}
1869 
1870  return OUTs;
1871 }
1872 
1873 
1874 
1875 
1876 
1877 
1878 
1879 //	2007/5/31 21:5:16
1880 compressF.tool={
1881 	WinRAR:{path:'"%ProgramFiles%\\WinRAR\\WinRAR.exe"',ext:'rar'
1882 		,c:{cL:'$path $cmd $s $archive -- $files',cmd:'a'	//	cL:command line, c:compress, s:switch
1883 			,s:'-u -dh -m5 -os -r -ts'	// -rr1p -s<N> -ap -as -ep1 -tl -x<f> -x@<lf> -z<f>  -p[p] -hp[p]	//	rar等
1884 			//,l:'-ilog logFN'
1885 		}
1886 		,u:{cL:'$path $cmd $archive $eF $eTo',cmd:'e'}	//	uncompress
1887 		,t:{cL:'$path $cmd $archive',cmd:'t'}	//	test
1888 	}
1889 	,'7-Zip':{path:'"%ProgramFiles%\\7-Zip\\7zg.exe"',ext:'7z'
1890 		,c:{cL:'$path $cmd $s $archive $files',cmd:'u',s:'-mx9 -ms -mhe -mmt -uy2'}	//	compress
1891 		,u:{cL:'$path $cmd $archive $eF $_e',cmd:'e',_e:function(fO){return fO.eTo?'-o'+fO.eTo:'';}}	//	uncompress
1892 		,t:{cL:'$path $cmd $archive',cmd:'t'}	//	test
1893 	}
1894 }
1895 /*
1896 test:
1897 var base='C:\\kanashimi\\www\\cgi-bin\\program\\misc\\';
1898 compress(base+'jit','_jit.htm',{tool:'7-Zip',s:''});
1899 uncompress(base+'jit',base,{tool:'7-Zip'});
1900 
1901 
1902 fO={
1903 	tool:'WinRAR'	//	or '7-Zip'
1904 	,m:'c'	//	method
1905 	,s:''	//	switch
1906 	,archive:''	//	archive file
1907 	,files=''	//	what to compress
1908 	,eTo=''	//	where to uncompress
1909 	,eF=''	//	what to uncompress
1910 	,rcL=1	//	rebuild command line
1911 }
1912 */
1913 // solid, overwrite, compressLevel, password
1914 function compressF(fO){	//	flags object
1915  // 參數檢查: 未完全
1916  if(!fO)fO={};
1917  if(typeof fO!='object')return;
1918  if(!fO.tool)fO.tool='WinRAR';
1919  //if(!fO.m)fO.m='c';//method
1920  if(!fO.m||!fO.archive&&(fO.m!='c'||fO.m=='c'&&!fO.files))return;
1921  if(fO.m=='c'){
1922   if(typeof fO.files!='object')fO.files=fO.files?[fO.files]:fO.archive.replace(/\..+$/,'');
1923   if(!fO.archive)fO.archive=fO.files[0].replace(/[\\\/]$/,'')+_t.ext;
1924   fO.files='"'+fO.files.join('" "')+'"';
1925  }
1926  var i,_t=compressF.tool[fO.tool],_m,_c;
1927  if(!_t||!(_m=_t[fO.m]))return;
1928  else if(!/\.[a-z]+$/.test(fO.archive))fO.archive+='.'+_t.ext;
1929  //if(fO.bD)fO.archive=fO.bD+(/[\\\/]$/.test(fO.bD)?'':'\\')+fO.archive;	//	base directory, work directory, base folder
1930  if(!/["']/.test(fO.archive))fO.archive='"'+fO.archive+'"';
1931  //alert('compressF(): check OK.');
1932  // 構築 command line
1933  if(_m._cL&&!fO.rcL)_c=_m._cL;	//	rebuild command line
1934  else{
1935   _c=_m.cL.replace(/\$path/,_t.path);
1936   for(i in _m)if(typeof fO[i]=='undefined')_c=_c.replace(new RegExp('\\$'+i),typeof _m[i]=='function'?_m[i](fO):_m[i]||'');
1937   _m._cL=_c;
1938   //alert('compressF():\n'+_c);
1939  }
1940  for(i in fO)_c=_c.replace(new RegExp('\\$'+i),fO[i]||'');
1941  if(_c.indexOf('$')!=-1){alert('compressF() error:\n'+_c);return;}
1942  alert('compressF() '+(_c.indexOf('$')==-1?'run':'error')+':\n'+_c);
1943  // run
1944  WshShell.Run(_c,0,true);
1945 }
1946 //compress[generateCode.dLK]='compressF';
1947 function compress(archive,files,fO){	//	compress file path, what to compress, flags object
1948  if(!fO)fO={};else if(typeof fO!='object')return;
1949  if(!fO.m)fO.m='c';
1950  if(archive)fO.archive=archive;
1951  if(files)fO.files=files;
1952  return compressF(fO);
1953 }
1954 //uncompress[generateCode.dLK]='uncompressF';
1955 function uncompress(archive,eTo,fO){	//	compress file path, where to uncompress, flags object
1956  if(!fO)fO={};else if(typeof fO!='object')return;
1957  if(!fO.m)fO.m='u';
1958  if(!fO.eF)fO.eF='';
1959  if(archive)fO.archive=archive;
1960  if(eTo)fO.eTo=eTo;
1961  return compressF(fO);
1962 }
1963 
1964 
1965 
1966 
1967 
1968 
1969 
1970 /*
1971 	轉換捷徑, 傳回shortcut的Object. true path
1972 	http://msdn2.microsoft.com/en-us/library/xk6kst2k.aspx
1973 	http://yuriken.hp.infoseek.co.jp/index3.html
1974 */
1975 var p;
1976 //dealShortcut[generateCode.dLK]='initWScriptObj';//,parseINI
1977 function dealShortcut(path,rtPath){
1978  if(typeof path!='string')path='';
1979  else if(/\.(lnk|url)$/i.test(path)){
1980   var sc=WshShell.CreateShortcut(path),p=sc.TargetPath,_i;
1981   //	檔名有可能是不被容許的字元(不一定總是有'?'),這時只有.url以文字儲存還讀得到。
1982   if(/*(''+sc).indexOf('?')!=-1*/!p&&/\.url$/i.test(path)&&typeof parseINI=='function'){
1983    p=parseINI(path,0,1);
1984    sc={_emu:p};
1985    sc.TargetPath=(p=p.InternetShortcut).URL;
1986    for(_i in p)sc[_i]=p[_i];
1987 /*
1988 URL File Format (.url)	http://www.cyanwerks.com/file-format-url.html
1989 [DEFAULT]
1990 BASEURL=http://so.7walker.net/guide.php
1991 [DOC#n(#n#n#n…)]
1992 [DOC#4#5]
1993 BASEURL=http://www.someaddress.com/frame2.html
1994 [DOC_adjustiframe]
1995 BASEURL=http://so.7walker.net/guide.php
1996 ORIGURL=http://so.7walker.net/guide.php
1997 [InternetShortcut]
1998 URL=http://so.7walker.net/guide.php
1999 Modified=50A8FD7702D1C60106
2000 WorkingDirectory=C:\WINDOWS\
2001 ShowCommand=	//	規定Internet Explorer啟動後窗口的初始狀態:7表示最小化,3表示最大化;如果沒有ShowCommand這一項的話則表示正常大小。
2002 IconIndex=1	//	IconFile和IconIndex用來為Internet快捷方式指定圖標
2003 IconFile=C:\WINDOWS\SYSTEM\url.dll
2004 Hotkey=1601
2005 
2006 Hotkey:
2007 下面加起來: Fn 單獨 || (Fn || base) 擇一 + additional 擇2~3
2008 base:
2009 0=0x30(ASCII)
2010 9=0x39(ASCII)
2011 A=0x41(ASCII)
2012 Z=0x5a(ASCII)
2013 ;=0xba
2014 =
2015 ,
2016 -
2017 .
2018 /
2019 `=0xc0
2020 [=0xdb
2021 \
2022 ]
2023 '=0xde
2024 
2025 Fn:
2026 F1=0x70
2027 ..
2028 F12=0x7b
2029 
2030 additional:
2031 Shift=0x100
2032 Ctrl=0x200
2033 Alt=0x400
2034 
2035 */
2036    p=p.URL;
2037   }
2038   if(!rtPath)return sc;
2039   path=/^file:/i.test(p)?p.replace(/^[^:]+:\/+/,'').replace(/[\/]/g,'\\'):p;	//	/\.url$/i.test(path)?'':p;
2040  }
2041  return rtPath?path:null;
2042 }
2043 
2044 //filepath=OpenFileDialog();	基於安全,IE無法指定初始值或型態
2045 //OpenFileDialog[generateCode.dLK]='IEA';
2046 function OpenFileDialog(){
2047  var IE=new IEA,o;
2048  if(!IE.OK(1))return null;
2049  IE.write('<input id="file" type="file"/>');// value="'+dP+'"	useless
2050  with(IE.getE('file'))focus(),click(),o=value;
2051  //IE.setDialog(200,400).show(1);
2052  IE.quit();
2053  return o||null;
2054 }
2055 
2056 
2057 //	是否為檔案
2058 function isFile(p,c){//file path,create
2059  if(!p)return 0;
2060  if(typeof fso=='undefined')
2061   fso=new ActiveXObject("Scripting.FileSystemObject");
2062  if(fso.FileExists(p))
2063   return true;
2064 
2065  p=getFN(p);
2066  if(c)try{c=fso.CreateTextFile(p,true);c.Close();}catch(e){}
2067  return fso.FileExists(p);
2068 }
2069 //	是否為目錄
2070 function isFolder(p,c){if(!p)return 0;//path,create	return 0:not,1:absolute,2:relative path
2071  if(fso.FolderExists(p=turnToPath(p)))return isAbsPath(p)?1:2;
2072  if(c)try{fso.CreateFolder(p);return isAbsPath(p)?1:2;}catch(e){}
2073  return 0;
2074 }
2075 //	get directory name of a path
2076 function get_folder(FP,mode){	//	mode=0:path,1:filename
2077  if(typeof FP=='object'&&typeof FP.Path=='string')
2078   if(typeof FP.IsRootFolder!='undefined')return FP.Path;
2079   else FP=FP.Path;
2080  if(typeof FP!='string')return '';
2081  //else if(/^[a-z]$/i.test(FP))FP+=':\\';
2082  //if(FP.slice(-1)!='\\')FP+='\\';
2083  var i=FP.lastIndexOf('\\');
2084  if(i==-1)i=FP.lastIndexOf('/');
2085  return i==-1?FP:mode?FP.substr(i+1):FP.slice(0,i+1);
2086 }
2087 
2088 
2089 
2090 //	取得下一個序號的檔名,如輸入pp\aa.txt將嘗試pp\aa.txt→pp\aa[pattern].txt
2091 function getNextSerialFN(FP,bs,pattern){	//	FP:file path,bs:begin serial,pattern:增添主檔名的模式,包含Ser的部分將被轉換為序號
2092  if(!FP)return;if(isNaN(bs))if(!fso.FileExists(FP))return FP;else bs=0;
2093  var i=FP.lastIndexOf('.'),base,ext,Ser=':s:';
2094  if(i==-1)base=FP,ext='';else base=FP.slice(0,i),ext=FP.substr(i);	//fso.GetBaseName(filespec);fso.GetExtensionName(path);fso.GetTempName();
2095  if(!pattern)pattern='_'+Ser;i=pattern.indexOf(Ser);
2096  if(i==-1)base+=pattern;else base+=pattern.slice(0,i),ext=pattern.substr(i+Ser.length)+ext;
2097  for(i=bs||0;i<999;i++)if(!fso.FileExists(base+i+ext))return base+i+ext;
2098  return;
2099 }
2100 
2101 
2102 _.
2103 /**
2104  * 轉換以 adTypeBinary 讀到的資料
2105  * @example
2106  * //	較安全的讀檔:
2107  * t=translate_AdoStream_binary_data(read_all_file(FP,'binary'));
2108  * write_to_file(FP,t,'iso-8859-1');
2109  * @see
2110  * <a href="http://www.hawk.34sp.com/stdpls/dwsh/charset_adodb.html">Hawk's W3 Laboratory : Disposable WSH : 番外編:文字エンコーディングとADODB.Stream</a>
2111  */
2112 translate_AdoStream_binary_data=function(data,len,type){
2113 	var _s = arguments.callee,_i=0,charArray,val,DOM=_s.XMLDOM,pos,txt;
2114  if(!DOM)
2115   try{
2116 	DOM=_s.XMLDOM=(new ActiveXObject("Microsoft.XMLDOM")).createElement('tmp');	//	要素名は何でも良い
2117 	DOM.dataType='bin.hex';
2118   }catch(e){return;}
2119  if(data!==0)DOM.nodeTypedValue=data,txt=DOM.text,pos=0;//binary data
2120  else pos=_s.pos,txt=_s.text;
2121  if(isNaN(len)||len>txt.length/2)len=txt.length/2;
2122 
2123  if(type){
2124   for(val=0;_i<len;i++)val=0x100*val+parseInt(txt.substr(pos,2),16),pos+=2;
2125   _s.pos=pos;
2126   return val;
2127  }
2128 
2129 /*
2130  if(!(len>0)||len!=parseInt(len))
2131   alert(pos+','+_i+'==0~len='+len+','+txt.slice(0,8));
2132 */
2133  charArray=new Array(parseInt(len));	//	Error 5029 [RangeError] (facility code 10): 陣列長度必須是一有限的正整數
2134  for(;_i<len;_i++)	//	極慢!用charString+=更慢。
2135   try{
2136    //if(_i%100000==0)alert(i);
2137    //if(_i==40)alert(String.fromCharCode(parseInt(txt.substr(pos,2),16))+'\n'+charArray.join(''));
2138    charArray.push(String.fromCharCode(parseInt(txt.substr(pos,2),16))),pos+=2;
2139    //charArray[_i]=String.fromCharCode((t.charCodeAt(_i<<1)<<8)+t.charCodeAt((_i<<1)+1));
2140   }catch(e){
2141    e.description='translate_AdoStream_binary_data: 輸入了錯誤的資料:\n'+e.description;
2142    throw e;
2143   }
2144  if(!data)_s.pos=pos;
2145  return charArray.join('');
2146 };
2147 
2148 _.
2149 /**
2150  * 轉換以 adTypeBinary 讀到的資料
2151  * @param	data	以 adTypeBinary 讀到的資料
2152  * @param	pos	position
2153  * @since	2007/9/19 20:58:26
2154  * @memberOf	CeL.IO.Windows.file
2155  */
2156 Ado_binary = function(data,pos){
2157  this.newDOM();
2158 
2159  if(typeof data=='string'){
2160   if(!data||typeof getFP=='function'&&!(data=getFP(data)))return;
2161   this.newFS(data);
2162   this.setPos(pos||0);
2163  }else this.setData(data,pos);
2164 };
2165 _.
2166 /**
2167  * @memberOf	CeL.IO.Windows.file
2168  */
2169 Ado_binary.prototype={
2170 /**
2171  * 設定 data
2172  * 
2173  * @param data	binary data
2174  * @param pos
2175  * @return
2176  * @memberOf	CeL.IO.Windows.file
2177  */
2178 setData : function(data, pos) {
2179 	this.DOM.nodeTypedValue = data,// binary data
2180 	this.bt = this.DOM.text;// binary text
2181 	if (!this.AdoS)
2182 		this.len = this.bt.length / 2;
2183 	this.setPos(pos || 0);
2184 },
2185 setPos : function(p) {
2186 	if (!isNaN(p)) {
2187 		if (p < 0)
2188 			p = 0;
2189 		else if (p > this.len)
2190 			p = this.len;
2191 		this.pos = p;
2192 	}
2193 	return this.pos;
2194 },
2195 testLen : function(len) {
2196 	if (!len || len < 0)
2197 		len = this.len;
2198 	if (this.pos + len > this.len)
2199 		len = this.len - this.pos;
2200 	return len;
2201 },
2202 /**
2203  * read data
2204  * @private
2205  * @param len	length
2206  * @return
2207  * @memberOf	CeL.IO.Windows.file
2208  */
2209 readData : function(len) {
2210 	this.AdoS.Position = this.pos;
2211 	var _data = this.AdoS.Read(len);
2212 	//	讀 binary data 用 'iso-8859-1' 會 error encoding.
2213 	this.setData(_data, this.AdoS.Position);
2214 },
2215 read : function(len) {
2216 	var charArray = new Array(len = this.testLen(len)), _i = 0;
2217 	this.readData(len);
2218 	for (; _i < len; _i++)
2219 		try {
2220 			charArray.push(String.fromCharCode(parseInt(this.bt
2221 					.substr(2 * _i, 2), 16)));
2222 			// charArray[i]=String.fromCharCode((t.charCodeAt(i<<1)<<8)+t.charCodeAt((i<<1)+1));
2223 		} catch (e) {
2224 			this.retErr(e);
2225 		}
2226 		return charArray.join('');
2227 },
2228 readNum : function(len) {
2229 	len = this.testLen(len);
2230 	this.readData(len);
2231 	var val = 0, _i = len;
2232 	for (; _i > 0;)
2233 		try {
2234 			val = 0x100 * val
2235 			+ parseInt(this.bt.substr(2 * (--_i), 2), 16);
2236 		} catch (e) {
2237 			this.retErr(e);
2238 		}
2239 		return val;
2240 },
2241 readHEX : function(len) {
2242 	len = this.testLen(len);
2243 	this.readData(len);
2244 	return this.bt;
2245 },
2246 retErr : function(e) {
2247 	e.description = 'translate_AdoStream_binary_data: 輸入了錯誤的資料:\n' + e.description;
2248 	throw e;
2249 },
2250 /**
2251  * @private
2252  * @return
2253  * @memberOf	CeL.IO.Windows.file
2254  */
2255 newDOM : function() {
2256 	this.DOM = null;
2257 	// try{
2258 	this.DOM = (new ActiveXObject("Microsoft.XMLDOM"))
2259 	.createElement('tmp' + Math.random()); // 要素名は何でも良い
2260 	// }catch(e){return;}
2261 	this.DOM.dataType = 'bin.hex';
2262 },
2263 /**
2264  * @private
2265  * @param FP
2266  * @return
2267  * @memberOf	CeL.IO.Windows.file
2268  */
2269 newFS : function(FP) {
2270 	if (FP)
2271 		this.FP = FP;
2272 	else if (!(FP = this.FP))
2273 		return;
2274 	var _i = _.open_file.returnADO;
2275 	_.open_file.returnADO = true;
2276 	this.AdoS = _.open_file(FP, 'binary');
2277 	_.open_file.returnADO = _i;
2278 	if (!this.AdoS)
2279 		return;
2280 	this.AdoS.LoadFromFile(FP);
2281 	this.len = this.AdoS.Size;
2282 },
2283 /**
2284  * 實際上沒多大效用。實用解決法:少用 AdoStream.Write()
2285  * @return
2286  * @memberOf	CeL.IO.Windows.file
2287  */
2288 renew : function() {
2289 	this.bt = this.data = 0;
2290 	this.newDOM();
2291 	if (this.AdoS && this.FP) {
2292 		this.pos = this.AdoS.Position;
2293 		this.AdoS.Close();
2294 		this.AdoS = null;
2295 		this.newFS();
2296 	}
2297 },
2298 destory : function(e) {
2299 	if (this.AdoS)
2300 		this.AdoS.Close();
2301 	this.AdoS = this.pos = this.bt = this.data = 0;
2302 }
2303 }; //	Ado_binary.prototype={
2304 
2305 
2306 /*
2307 //	速度過慢,放棄。
2308 //_.open_file.returnADO=true;
2309 function dealBinary(FP,func,interval){
2310  var t,fs=_.open_file(FP,'binary',ForReading);
2311  if(!fs)return;
2312  AdoStream.LoadFromFile(FP);
2313  if(!interval)interval=1;
2314  //alert(fs.size)
2315  while(!fs.EOS)
2316   if(func(translate_AdoStream_binary_data(fs.Read(interval))))return;
2317  func();
2318  fs.Close();
2319 }
2320 */
2321 
2322 /*	配合simple系列使用
2323 http://thor.prohosting.com/~mktaka/html/utf8.html
2324 http://www.andrewu.co.uk/webtech/comment/?703
2325 http://www.blueidea.com/bbs/NewsDetail.asp?id=1488978
2326 http://www.blueidea.com/bbs/NewsDetail.asp?GroupName=WAP+%BC%BC%CA%F5%D7%A8%C0%B8&DaysPrune=5&lp=1&id=1524739
2327 C#	http://www.gotdotnet.com/team/clr/bcl/TechArticles/TechArticles/IOFAQ/FAQ.aspx
2328 http://www.sqlxml.org/faqs.aspx?faq=2
2329 http://www.imasy.or.jp/~hir/hir/tech/js_tips.html
2330 
2331 ADODB.Stream	最大問題:不能append
2332 http://msdn2.microsoft.com/en-us/library/ms808792.aspx
2333 http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoenumerations.asp
2334 http://study.99net.net/study/web/asp/1067048121.html	http://www.6to23.com/s11/s11d5/20031222114950.htm
2335 http://blog.csdn.net/dfmz007/archive/2004/07/23/49373.aspx
2336 */
2337 var AdoStream,AdoEnums;	//	ADO Enumerated Constants	http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoenumerations.asp
2338 /*	搬到前面
2339 setObjValue('AdoEnums','adTypeBinary=1,adTypeText=2'	//	StreamTypeEnum
2340 +',adReadAll=-1,adReadLine=-2'	//	StreamReadEnum	http://msdn2.microsoft.com/en-us/library/ms806462.aspx
2341 +',adSaveCreateNotExist=1,adSaveCreateOverWrite=2'	//	SaveOptionsEnum
2342 +',adCR=13,adCRLF=-1,adLF=10'	//	LineSeparatorsEnum
2343 ,'int');
2344 */
2345 AdoEnums = {
2346 	adTypeBinary : 1,
2347 	adTypeText : 2,
2348 	adReadAll : -1,
2349 	adReadLine : -2,
2350 	adSaveCreateNotExist : 1,
2351 	adSaveCreateOverWrite : 2,
2352 	adCR : 13,
2353 	adCRLF : -1,
2354 	adLF : 10
2355 };
2356 
2357 
2358 //_.open_file[generateCode.dLK]='AdoEnums,simpleFileErr,ForReading,ForWriting,ForAppending,TristateUseDefault';//AdoStream
2359 _.
2360 /**
2361  * 提供給 <a href="#.read_all_file">read_all_file</a>, <a href="#.write_to_file">write_to_file</a> 使用的簡易開檔函數
2362  * @param FN	file path
2363  * @param format	open format, e.g., open_format.TristateUseDefault
2364  * @param io_mode	open mode, e.g., iomode.ForWriting
2365  * @memberOf	CeL.IO.Windows.file
2366  */
2367 open_file=function(FN,format,io_mode){
2368  //if(!FN||typeof isAbsPath=='function'&&typeof getFN=='function'&&!isAbsPath(FN)&&!(FN=getFN(FN)))return;
2369  //if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return;
2370 	var _s = arguments.callee;
2371  if(typeof format=='string'){
2372   if(!_s.returnADO&&typeof AdoStream!='undefined')
2373    try{AdoStream.Close();AdoStream=null;}catch(e){}
2374   try{
2375    AdoStream=new ActiveXObject("ADODB.Stream");//var objStream=Server.CreateObject("ADODB.Stream");	//	ASPの場合,Err.Number=-2147221005表不支援
2376   }catch(e){simpleFileErr=e;AdoStream=null;}
2377   if(AdoStream){
2378    //AdoStream.Mode=3;	//	read write
2379    if(format=='binary')AdoStream.Type=AdoEnums.adTypeBinary;	//	以二進位方式操作
2380    else{
2381     AdoStream.Type=AdoEnums.adTypeText;
2382     try{AdoStream.Charset=format;}catch(e){throw new Error(e.number,'open_file: Error format:\n	('+typeof format+') ['+format+']\n'+e.description);}	//	UTF-8,unicode,shift_jis,Big5,GB2312,ascii=iso-8859-1,_autodetect,_autodetect_all..	HKEY_CLASSES_ROOT\MIME\Database\Charset
2383    }
2384    AdoStream.Open();
2385    //AdoStream.Position=0,AdoStream.LineSeparator=AdoEnums.adLF;
2386    if(_s.returnADO){var _A=AdoStream;AdoStream=null;return _A;}
2387    return 0;
2388   }
2389   format=0;
2390  }
2391  var fs;
2392  //	使用某些防毒軟體(如諾頓 Norton)時,.OpenTextFile() 可能會被攔截,因而延宕。
2393  try{
2394   if(io_mode==_.iomode.ForAppending&&!fso.FileExists(FN))io_mode=_.iomode.ForWriting;	//	無此檔時改 writing
2395   fs=fso.OpenTextFile(FN,io_mode||_.iomode.ForReading,io_mode==_.iomode.ForWriting/*create*/,format||_.open_format.TristateUseDefault);
2396  }catch(e){
2397   simpleFileErr=e;
2398   try{fs.Close();}catch(e){}
2399   return -1;
2400  }
2401  return fs;
2402 };
2403 _.open_file.returnADO=false;
2404 _.open_file.error;
2405 
2406 //	若是僅使用普通的開檔方法(_.open_format.TristateTrue/_.open_format.TristateFalse等,不使用ADODB.Stream),直接引用下兩函數與fso段定義即可。否則還需要引入_.open_file(),setObjValue(),dQuote()
2407 var simpleFileErr,simpleFileAutodetectEncode=-5.4,simpleFileDformat=_.open_format.TristateUseDefault;//_autodetect	autodetectEncode(file)
2408 //_.read_all_file[generateCode.dLK]=_.write_to_file[generateCode.dLK]='simpleFileErr,simpleFileAutodetectEncode,simpleFileDformat,initWScriptObj';//_.open_file,autodetectEncode,getFP,_.open_format.TristateUseDefault
2409 //_.read_all_file[generateCode.dLK]+=',ForReading';_.write_to_file[generateCode.dLK]+=',ForWriting';
2410 //_.read_all_file[generateCode.dLK]+=',translate_AdoStream_binary_data';	//	for _.read_all_file(FP,'binary')
2411 _.
2412 /**
2413  * 讀取檔案
2414  * @param FN	file path
2415  * @param format	open encode = simpleFileDformat
2416  * @param io_mode	open IO mode = ForReading
2417  * @param func	do this function per line, or [func, maxsize] (TODO)
2418  * @return {String} 檔案內容
2419  * @memberOf	CeL.IO.Windows.file
2420  */
2421 read_all_file=function(FN,format,io_mode,func){
2422  simpleFileErr=0;if(format==simpleFileAutodetectEncode)
2423   format=typeof autodetectEncode=='function'?autodetectEncode(FN):simpleFileDformat;
2424  if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return;
2425  //var a,fs;try{fs=fso.OpenTextFile(FN,io_mode||_.iomode.ForReading,false,format||simpleFileDformat),a=fs.ReadAll(),fs.Close();}catch(e){simpleFileErr=e;return;}
2426  var a,fs;//,i,s=0,t;
2427  if(typeof _.open_file!='function')
2428   //{if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return;
2429   try{fs=fso.OpenTextFile(FN,io_mode||_.iomode.ForReading,false/*create*/,format||simpleFileDformat);}
2430   catch(e){simpleFileErr=e;return;}
2431  else if(fs=_.open_file(FN,format||simpleFileDformat,io_mode||_.iomode.ForReading),fs===-1)return;
2432 
2433  //if(func instanceof Array)s=func[1],func=func[0];
2434  if(fs!==0)try{
2435   if(func)
2436    while(!fs.AtEndOfStream)func(fs.ReadLine());
2437 /*
2438    while(!fs.AtEndOfStream){
2439     for(t='',i=0;!fs.AtEndOfStream&&(!t||i<s);i++)
2440      t+=fs.ReadLine();
2441     a+=func(t);
2442    }
2443 */
2444   else a=fs.ReadAll();
2445   fs.Close();
2446  }catch(e){simpleFileErr=e;try{fs.Close();}catch(e){}return;}
2447  else if(typeof AdoStream!='undefined'&&AdoStream)
2448   try{
2449    AdoStream.LoadFromFile(FN);
2450    if(AdoStream.Type==AdoEnums.adTypeBinary){
2451     a=AdoStream.Read(AdoEnums.adReadAll);	//	讀 binary data 用 'iso-8859-1' 會 error encoding.
2452     if(_.read_all_file.turnBinToStr&&typeof translate_AdoStream_binary_data=='function')a=translate_AdoStream_binary_data(a);
2453    }else if(func)
2454     while(!AdoStream.EOS)func(AdoStream.ReadText(AdoEnums.adReadLine));
2455 /*
2456     while(!AdoStream.EOS){
2457      for(t='',i=0;!AdoStream.AtEndOfStream&&(!t||i<s);i++)
2458       t+=AdoStream.ReadText(AdoEnums.adReadLine);
2459      a+=func(t);
2460     }
2461 */
2462    else a=AdoStream.ReadText(AdoEnums.adReadAll);
2463    AdoStream.Close();
2464   }catch(e){
2465    simpleFileErr=e;
2466    try{AdoStream.Close();}catch(e){}
2467    return;
2468   }
2469  else simpleFileErr=new Error(1,'unknown error!'),simpleFileErr.name='unknownError';
2470  return a;
2471 };
2472 _.read_all_file.turnBinToStr=true;
2473 
2474 
2475 _.
2476 /**
2477  * 將 content 寫入 file
2478  * ** ADODB.Stream does not support appending!
2479  * @param FN	file path
2480  * @param content	content to write
2481  * @param format	open format = simpleFileDformat
2482  * @param io_mode	write mode = ForWriting, e.g., ForAppending
2483  * @param N_O	DO NOT overwrite
2484  * @return error No.
2485  * @memberOf	CeL.IO.Windows.file
2486  */
2487 write_to_file = function(FN, content, format, io_mode, N_O) {
2488 	simpleFileErr = 0;
2489 	if (format == simpleFileAutodetectEncode)
2490 		format = typeof autodetectEncode == 'function' ? autodetectEncode(FN)
2491 				: simpleFileDformat;
2492 		if (!FN || typeof getFP == 'function' && !(FN = getFP(FN)))
2493 			return 2;
2494 		//var fs;try{fs=fso.OpenTextFile(FN,iomode||ForWriting,true,format||TristateUseDefault);}catch(e){return 2;}if(!fs)return 3;
2495 		//try{fs.Write(content);}catch(e){return e.number&0xFFFF==5?5:4;}	//	5:content中有此local無法相容的字元,例如在中文中寫入日文假名
2496 		var fs;
2497 		if (typeof _.open_file != 'function')
2498 			// {if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return 2;
2499 			try {
2500 				fs = fso.OpenTextFile(FN, io_mode || _.iomode.ForWriting,
2501 						true/* create */, format || simpleFileDformat);
2502 				if (!fs)
2503 					return 3;
2504 			} catch (e) {
2505 				simpleFileErr = e;
2506 				return 2;
2507 			}
2508 			else if (fs = _.open_file(FN, format || simpleFileDformat, io_mode
2509 					|| _.iomode.ForWriting), fs === -1)
2510 				return 3;
2511 			else if (!fs && isNaN(fs))
2512 				return 2;
2513 		if (fs !== 0)
2514 			try {
2515 				fs.Write(content);
2516 				fs.Close();
2517 			} catch (e) {
2518 				simpleFileErr = e;
2519 				try {
2520 					fs.Close();
2521 				} catch (e) {
2522 				}
2523 				return simpleFileErr.number & 0xFFFF == 5 ? 5 : 4;
2524 			}
2525 			// AdoStream.SaveToFile()需在AdoStream.Write之後!
2526 			else if (typeof AdoStream != 'undefined' && AdoStream)
2527 				try {
2528 					if (AdoStream.Type == AdoEnums.adTypeText)
2529 						AdoStream.WriteText(content);
2530 					else
2531 						AdoStream.Write(content);
2532 					AdoStream.SaveToFile(FN, io_mode
2533 							|| AdoEnums.adSaveCreateOverWrite);
2534 					AdoStream.Close();
2535 				} catch (e) {
2536 					simpleFileErr = e;
2537 					try {
2538 						AdoStream.Close();
2539 					} catch (e) {
2540 					}
2541 					return 6;
2542 				}
2543 				else {
2544 					simpleFileErr = new Error(1, 'unknown error!'),
2545 					simpleFileErr.name = 'unknownError';
2546 					return 1;
2547 				}
2548 };
2549 
2550 //	TODO: unfinished
2551 //simpleDealFile[generateCode.dLK]='autodetectEncode,_.read_all_file,_.write_to_file';
2552 _.
2553 simpleDealFile=function(inFN,func,outFN,format,io_mode,N_O){
2554  if(!inFN)return;
2555  if(!outFN)outFN=inFN;
2556  var e=autodetectEncode(inFN),i=_.read_all_file(inFN,e),o=_.read_all_file(outFN,e),t=func(i,inFN);
2557  if(typeof t=='string'&&o!=t)return _.write_to_file(outFN,t,e,N_O);
2558 };
2559 
2560 /*
2561 var autodetectEncodeSP,autodetectEncodeCode;	//	特殊字元,各種編碼及判別所需最短長度
2562 setObjValue('autodetectEncodeSP','3005=J,3006=J,3402=J,3447=C,3468=J,3473=C,359e=C,360e=C,361a=C,3918=C,396e=C,39cf=C,39d0=C,39df=C,3a73=C,3b4e=C,3b77=J,3c6e=C,3ce0=C,3f57=J,4056=C,415f=C,42c6=J,4302=J,4337=C,43ac=C,43b1=C,43dd=C,44be=J,44d4=J,44d6=C,464c=C,4661=C,4723=C,4729=C,477c=C,478d=C,4947=C,497a=C,497d=C,'
2563 +'4982=C,4983=C,4985=C,4986=C,499b=C,499f=C,49b0=J,49b6=C,49b7=C,4c77=C,4c9f=C,4ca0=C,4ca1=C,4ca2=C,4ca3=C,4d13=C,4d14=C,4d15=C,4d16=C,4d17=C,4d18=C,4d19=C,4dae=C,4e12=J,4e13=C,4e1a=C,4e1b=C,4e1c=C,4e1d=C,4e24=C,4e25=C,4e27=C,4e28=J,4e2a=C,4e34=C,4e3a=C,4e3c=J,4e3d=C,4e3e=C,4e49=C,'
2564 +'4e4c=C,4e50=C,4e54=C,4e60=C,4e61=C,4e62=J,4e66=C,4e70=C,4e71=C,4e8f=C,4e9a=C,4ea7=C,4ea9=C,4eb2=C,4eb5=C,4ebf=C,4ec5=C,4ece=C,4ed0=J,4ed1=C,4ed3=C,4eea=C,4eec=C,4f17=C,4f1b=C,4f1d=J,4f1e=C,4f1f=C,4f20=C,4f24=C,4f25=C,4f26=C,4f27=C,4f2a=C,4f65=C,4f66=J,4fa0=C,4fa1=J,4fa4=J,4fa5=C,'
2565 +'4fa6=C,4fa7=C,4fa8=C,4fa9=C,4faa=C,4fac=C,4fb0=J,4fe3=J,4fe4=J,4fe5=J,4fe6=C,4fe7=J,4fe8=C,4fe9=C,4fea=C,4fed=C,5039=J,503a=C,503b=J,503e=C,5051=J,507b=C,507e=C,507f=C,50a5=C,50a7=C,50a8=C,50a9=C,50cd=J,50de=C,50f2=J,5170=C,5173=C,5174=C,517b=C,517d=C,5181=C,5188=C,5199=C,519b=C,'
2566 +'519c=C,51af=C,51b2=C,51bb=C,51e4=C,51e7=J,51e9=J,51ea=J,51eb=C,51ed=C,51ee=J,51ef=C,51fb=C,51ff=C,520d=C,5218=C,5219=C,521a=C,521b=C,522b=C,522c=C,522d=C,523d=C,523f=C,5240=C,5242=C,5250=C,5251=C,5257=C,5267=C,5273=C,529d=C,529e=C,52a1=C,52a8=C,52b1=C,52b2=C,52b3=C,52bf=C,52cb=C,'
2567 +'52da=C,5301=J,5302=J,5307=J,5326=C,532e=C,533b=C,534e=C,534f=C,5355=C,5356=C,5362=C,5364=C,536b=C,5385=C,5386=C,5389=C,538b=C,538c=C,538d=C,5395=C,53a0=C,53a3=C,53bf=C,53c2=C,53c6=C,53c7=C,53cc=C,53d1=C,53d8=C,53f6=C,53f7=C,53f9=C,53fa=J,53fd=C,540b=J,5413=C,5417=C,542f=C,544e=J,'
2568 +'544f=J,5452=C,5453=C,5455=C,5456=C,5457=C,5458=C,545b=C,545c=C,5484=J,5491=J,5499=C,549b=C,549c=J,549d=C,54cd=C,54d1=C,54d2=C,54d3=C,54d4=C,54d5=C,54d7=C,54d8=J,54d9=C,54dd=C,54df=C,54e9=J,5500=J,551b=C,551d=C,5520=C,5521=C,5522=C,5553=C,5567=C,556c=C,556d=C,556e=C,5570=C,5578=C,'
2569 +'55b0=J,55b7=C,55bd=C,55be=C,55eb=C,55f3=C,5624=C,5631=C,565c=C,565d=C,5678=J,567a=J,56a3=C,56c9=J,56ce=J,56e2=C,56ed=C,56f2=J,56f4=C,56f5=C,56fe=C,5706=C,5715=J,5726=J,5737=J,5738=J,5739=C,573a=C,5746=J,5757=C,575a=C,575b=C,575c=C,575d=C,575e=C,575f=C,5760=C,5784=C,5786=C,5788=J,'
2570 +'5789=J,5792=C,57a4=J,57a6=C,57a9=C,57ab=C,57ac=J,57ad=C,57b0=J,57b2=C,57b3=J,57d6=J,57d8=C,57d9=C,57da=C,5811=C,5815=C,5840=J,5870=J,5899=C,58b8=J,58b9=J,58d7=J,58e5=J,58ee=C,58f0=C,58f3=C,58f6=C,58f8=C,5904=C,5907=C,5934=C,5939=C,593a=C,5941=C,594b=C,5956=C,5986=C,5987=C,5988=C,'
2571 +'598b=J,599b=J,59a9=C,59aa=C,59ab=C,59c9=J,5a04=C,5a05=C,5a06=C,5a07=C,5a08=C,5a32=C,5a34=C,5a47=J,5a72=J,5a73=C,5a74=C,5a75=C,5a76=C,5aac=J,5ad2=C,5ad4=C,5af1=C,5b00=C,5b36=J,5b59=C,5b66=C,5b6a=C,5b93=J,5b9e=C,5ba0=C,5ba1=C,5baa=C,5bbd=C,5bbe=C,5bc9=J,5bdd=C,5bf9=C,5bfb=C,5bfc=C,'
2572 +'5bff=C,5c06=C,5c14=C,5c18=C,5c1d=C,5c27=C,5c34=C,5c3d=C,5c42=C,5c5e=C,5c61=C,5c66=C,5c76=J,5c7f=C,5c81=C,5c82=C,5c96=C,5c97=C,5c98=C,5c9a=C,5c9b=C,5cbc=J,5cbd=C,5cbe=J,5cbf=C,5cc3=C,5cc4=C,5cc5=J,5ce0=J,5ce1=C,5ce3=C,5ce4=C,5ce6=C,5d02=C,5d03=C,5d10=C,5d2c=C,5d2d=C,5d58=C,5d59=J,'
2573 +'5d5a=C,5d5d=C,5d76=J,5dc5=C,5de9=C,5def=C,5e01=C,5e05=C,5e08=C,5e0f=C,5e10=C,5e1c=C,5e26=C,5e27=C,5e2e=C,5e3b=C,5e3c=C,5e7f=C,5e83=J,5e86=C,5e90=C,5e91=C,5e93=C,5e94=C,5e99=C,5e9e=C,5e9f=C,5ebc=C,5f00=C,5f03=C,5f16=J,5f20=C,5f25=C,5f2f=C,5f39=C,5f41=J,5f45=J,5f52=C,5f53=C,5f55=C,'
2574 +'5f7b=C,5f84=C,5f95=C,5fa4=J,5fc6=C,5fdc=J,5fe7=C,5ff0=J,5ffe=C,6001=C,6002=C,6003=C,6004=C,6005=C,6006=C,603a=J,603b=C,603c=C,603f=C,604b=C,6073=C,6076=C,6077=J,6078=C,6079=C,607a=C,607b=C,607c=C,607d=C,60ab=C,60ac=C,60ad=C,60af=C,60e7=C,60e8=C,60e9=C,60eb=C,60ec=C,60ed=C,60ee=C,'
2575 +'60ef=C,6124=C,6126=C,6151=C,6164=C,61d1=C,61d2=C,6206=C,620b=C,620f=C,6217=C,6218=C,6256=J,6267=C,6268=J,6269=C,626a=C,626b=C,626c=C,629a=C,629f=C,62a0=C,62a1=C,62a2=C,62a4=C,62a5=C,62c5=C,62df=C,62e2=C,62e3=C,62e5=C,62e6=C,62e7=C,62e8=C,62e9=C,630a=J,6317=J,6318=J,631a=C,631b=C,'
2576 +'631c=C,631d=C,631e=C,631f=C,6320=C,6321=C,6322=C,6324=C,6325=C,6326=C,6327=J,635e=C,635f=C,6361=C,6363=C,6364=J,6386=C,63b3=C,63b4=C,63b5=J,63b7=C,63b8=C,63ba=C,63bc=C,63fd=C,63ff=C,6400=C,6401=C,6402=C,6405=C,643e=J,6444=C,6445=C,6446=C,6448=C,644a=C,6484=C,64b5=C,64b7=C,64ba=C,'
2577 +'64d3=C,64de=C,6512=C,654c=C,655b=C,6570=C,658b=C,6593=C,65a9=C,65ad=C,65e0=C,65e7=C,65f6=C,65f7=C,65f8=C,6619=C,663c=C,663d=C,663e=C,6653=C,6654=C,6655=C,6682=C,6683=J,66a7=C,66fb=J,6722=J,672f=C,6740=C,6741=J,6742=C,6743=C,6761=C,6762=J,6763=J,6764=J,6765=C,6766=J,6768=C,678c=J,'
2578 +'679e=C,67a0=J,67a1=J,67a2=C,67a3=C,67a5=C,67a6=J,67a7=C,67a8=C,67a9=J,67aa=C,67ab=C,67ad=C,67d5=J,67e0=C,67fd=C,67fe=J,6802=J,6803=J,6807=C,6808=C,6809=C,680a=C,680b=C,680c=C,680d=J,680e=C,680f=C,6811=C,682c=J,6837=C,683e=C,685b=J,685c=J,685d=J,6861=C,6862=C,6863=C,6864=C,6865=C,'
2579 +'6866=C,6867=C,6868=C,6869=C,6898=C,68a6=C,68ba=J,68bb=J,68c0=C,68c2=C,6917=J,6919=J,691a=J,691b=J,691f=C,6920=C,6921=J,6923=J,6924=C,6925=J,6926=J,6928=J,692a=J,692d=C,693f=J,697c=C,697e=J,697f=J,6980=J,6981=J,6984=C,6987=C,6988=C,6989=C,698a=J,69c7=J,69da=C,69db=C,69dd=J,69df=C,'
2580 +'69e0=C,6a2b=J,6a2e=J,6a2f=C,6a30=J,6a31=C,6a3b=J,6a67=J,6a72=J,6a73=J,6a78=J,6a79=C,6a7c=C,6ab0=J,6ae4=J,6b1f=J,6b22=C,6b24=C,6b27=C,6b7c=C,6b87=C,6b8b=C,6b92=C,6b93=C,6b9a=C,6ba1=C,6ba8=C,6bb4=C,6bbb=C,6bc2=C,6bd5=C,6bd9=C,6bdf=J,6be1=C,6bee=J,6bf5=C,6c07=C,6c17=J,6c22=C,6c29=C,'
2581 +'6c47=C,6c49=C,6c62=J,6c64=C,6c9f=C,6ca3=C,6ca4=C,6ca5=C,6ca6=C,6ca7=C,6ca8=C,6ca9=C,6caa=C,6cea=C,6cf7=C,6cf8=C,6cfa=C,6cfb=C,6cfc=C,6cfd=C,6cfe=C,6d43=C,6d45=C,6d46=C,6d47=C,6d48=C,6d49=C,6d4a=C,6d4b=C,6d4d=C,6d4e=C,6d4f=C,6d50=C,6d51=C,6d52=C,6d53=C,6d54=C,6d55=C,6d9b=C,6d9c=J,'
2582 +'6d9d=C,6d9e=C,6d9f=C,6da0=C,6da1=C,6da2=C,6da4=C,6da6=C,6da7=C,6da8=C,6da9=C,6e0a=C,6e0d=C,6e0e=C,6e10=C,6e11=C,6e14=C,6e17=C,6e7e=C,6e7f=C,6e82=J,6e83=C,6e85=C,6e87=C,6ed7=C,6ede=C,6edf=C,6ee0=C,6ee1=C,6ee4=C,6ee5=C,6ee6=C,6ee8=C,6ee9=C,6eea=C,6f47=C,6f4b=C,6f4d=C,6f57=J,6f59=C,'
2583 +'6f76=J,6f9c=C,6fbe=C,6fd1=C,6fd2=C,6ff9=J,704f=C,7067=C,706d=C,706f=C,7075=C,707e=C,707f=C,7080=C,7089=C,709c=C,709d=C,70b9=C,70bb=J,70bc=C,70bd=C,70c1=C,70c2=C,70c3=C,70db=C,70e6=C,70e7=C,70e8=C,70e9=C,70eb=C,70ec=C,70ed=C,7116=C,7118=C,7144=J,7173=J,7194=J,7195=J,71f5=J,7231=C,'
2584 +'7232=C,7237=C,7240=C,724d=C,7275=C,727a=C,728a=C,72b6=C,72b7=C,72b8=C,72b9=C,72c6=J,72c8=C,72de=C,72ec=C,72ed=C,72ee=C,72ef=C,72f1=C,72f2=C,7303=C,730e=C,7315=C,7321=C,732b=C,732e=C,7341=C,736d=C,7391=C,739b=C,73ae=C,73af=C,73b0=C,73b1=C,73ba=C,73c6=J,73d1=C,73f2=C,740e=C,740f=C,'
2585 +'7410=C,7411=J,743c=C,7443=J,7477=C,748e=C,74d2=C,74e7=J,74e9=J,74ea=J,74ef=C,74f0=J,74f1=J,74f2=J,74f8=J,74fc=J,7505=J,7523=C,7535=C,753b=C,753c=J,7545=C,7551=J,7560=J,7569=J,7573=J,7574=C,757d=J,7596=C,7597=C,759f=C,75a0=C,75a1=C,75ac=C,75ae=C,75af=C,75c7=J,75c8=C,75c9=C,75e8=C,'
2586 +'75eb=C,7605=C,7606=C,7617=C,7618=C,762a=C,762b=C,762e=C,763b=C,763e=C,763f=C,764c=J,765e=C,7663=C,7667=C,766a=J,766b=C,7691=C,76b1=C,76b2=C,76cf=C,76d0=C,76d1=C,76d6=C,76d8=C,770d=C,7750=C,7751=C,7792=C,7798=C,77a9=C,77eb=C,77f6=C,77fe=C,77ff=C,7800=C,7801=C,7816=C,7817=C,781a=C,'
2587 +'781c=C,783a=C,783b=C,783e=C,7840=C,7855=C,7856=C,7857=C,7859=C,785a=C,7872=J,7874=J,7877=C,788d=C,7897=J,789b=C,789c=C,78b5=J,78b8=C,7935=J,793c=C,794e=C,7962=C,796f=C,7977=C,7978=C,7985=C,79ef=C,79f0=C,79fd=C,7a23=C,7a2d=C,7a33=C,7a43=J,7a51=C,7a5d=J,7a77=C,7a83=C,7a8d=C,7a8e=C,'
2588 +'7a9c=C,7a9d=C,7aa5=C,7aa6=C,7aad=C,7ac8=C,7acd=J,7acf=J,7ad3=J,7ad5=J,7ad6=C,7ade=C,7ae1=J,7aea=C,7af0=J,7b02=J,7b03=C,7b0b=C,7b14=C,7b15=C,7b39=J,7b3a=C,7b3c=C,7b3d=J,7b3e=C,7b5a=C,7b5b=C,7b79=C,7b7e=C,7b80=C,7b93=C,7ba5=J,7ba6=C,7ba7=C,7ba8=C,7ba9=C,7baa=C,7bab=C,7bcf=J,7bd1=C,'
2589 +'7bd3=C,7bee=C,7c13=J,7c16=C,7c17=J,7c31=J,7c41=C,7c4f=J,7c74=C,7c75=J,7c7b=C,7c7e=J,7c81=J,7c82=J,7c8d=J,7c8f=J,7c90=J,7c9c=C,7c9d=C,7ca0=J,7ca8=J,7caa=C,7cab=J,7cad=J,7cae=C,7cc0=J,7cc1=C,7cce=J,7cd8=J,7d25=C,7d26=J,7d27=C,7d5d=C,7d76=C,7d77=C,7d89=C,7d9b=J,7dab=C,7db3=C,7dd1=C,'
2590 +'7dd5=J,7dfc=C,7e05=J,7e27=C,7e28=J,7e4a=J,7e67=J,7e6e=C,7e83=J,7e90=J,7ea0=C,7ea1=C,7ea2=C,7ea3=C,7ea4=C,7ea5=C,7ea6=C,7ea7=C,7ea8=C,7ea9=C,7eaa=C,7eab=C,7eac=C,7ead=C,7eaf=C,7eb0=C,7eb1=C,7eb2=C,7eb3=C,7eb4=C,7eb5=C,7eb6=C,7eb7=C,7eb8=C,7eb9=C,7eba=C,7ebc=C,7ebd=C,7ebe=C,7ebf=C,'
2591 +'7ec0=C,7ec1=C,7ec2=C,7ec3=C,7ec4=C,7ec5=C,7ec6=C,7ec7=C,7ec8=C,7ec9=C,7eca=C,7ecb=C,7ecc=C,7ecd=C,7ece=C,7ecf=C,7ed0=C,7ed1=C,7ed2=C,7ed3=C,7ed4=C,7ed5=C,7ed6=C,7ed7=C,7ed8=C,7ed9=C,7eda=C,7edb=C,7edc=C,7edd=C,7ede=C,7edf=C,7ee0=C,7ee1=C,7ee2=C,7ee3=C,7ee5=C,7ee6=C,7ee7=C,7ee8=C,'
2592 +'7ee9=C,7eea=C,7eeb=C,7eed=C,7eee=C,7eef=C,7ef0=C,7ef2=C,7ef3=C,7ef4=C,7ef5=C,7ef6=C,7ef7=C,7ef8=C,7efa=C,7efb=C,7efc=C,7efd=C,7efe=C,7eff=C,7f00=C,7f01=C,7f02=C,7f03=C,7f04=C,7f05=C,7f06=C,7f07=C,7f08=C,7f09=C,7f0a=C,7f0c=C,7f0e=C,7f11=C,7f12=C,7f13=C,7f14=C,7f15=C,7f16=C,7f17=C,'
2593 +'7f18=C,7f19=C,7f1a=C,7f1b=C,7f1c=C,7f1d=C,7f1e=C,7f1f=C,7f20=C,7f21=C,7f22=C,7f23=C,7f24=C,7f25=C,7f26=C,7f27=C,7f28=C,7f29=C,7f2a=C,7f2b=C,7f2c=C,7f2d=C,7f2e=C,7f2f=C,7f30=C,7f31=C,7f32=C,7f33=C,7f34=C,7f35=C,7f3c=J,7f42=C,7f4e=C,7f57=C,7f5a=C,7f62=C,7f74=C,7f81=C,7f9f=C,7faa=J,'
2594 +'7fd8=C,7fda=C,8022=C,8027=C,802e=C,8038=C,8042=C,804b=C,804c=C,804d=C,8054=C,8062=J,8069=C,806a=C,8083=C,80a0=C,80a4=C,80be=C,80bf=C,80c0=C,80c1=C,80c6=C,80e7=C,80e8=C,80ea=C,80eb=C,80f1=J,80f6=C,8109=C,810d=C,810f=C,8110=C,8111=C,8113=C,8114=C,8135=J,8136=C,8138=C,8156=C,8158=C,'
2595 +'817a=J,817b=C,817e=C,8191=C,81a4=J,81b5=J,81cd=J,81dc=C,8206=C,8220=J,822e=J,8230=C,8231=C,823b=C,8249=J,825d=J,8260=J,8270=C,8273=C,827a=C,8282=C,8297=C,829c=C,82a6=C,82c1=C,82c5=J,82c7=C,82c8=C,82cb=C,82cd=C,82cf=C,830e=C,830f=C,8311=C,8314=C,8315=C,834e=J,835a=C,835b=C,835c=C,'
2596 +'835e=C,835f=C,8360=C,8361=C,8363=C,8364=C,8365=C,8366=C,8367=C,8368=C,8369=C,836a=C,836b=C,836c=C,836d=C,836e=C,836f=C,83b1=C,83b2=C,83b3=C,83b4=C,83b7=C,83b8=C,83b9=C,83ba=C,83bc=C,8419=J,841a=C,841d=C,8421=J,8422=J,8424=C,8425=C,8426=C,8427=C,8428=C,8429=J,8464=C,8485=J,8487=C,'
2597 +'8489=C,848b=C,848c=C,8493=C,84d9=J,84da=J,84dc=J,84dd=C,84df=C,84e3=C,84e6=C,8534=C,8536=J,8537=C,8539=C,853a=C,853c=C,8552=C,8572=C,8574=C,85ae=C,85d3=C,85f4=C,8612=J,8630=J,8645=J,864f=C,8651=C,8672=J,867d=C,867e=C,867f=C,8680=C,8681=C,8682=C,86ab=J,86ac=C,86ca=C,86ce=C,86cf=C,'
2598 +'86ee=C,86ef=J,86f0=C,86f1=C,86f2=C,86f3=C,86f4=C,8717=C,8747=C,8748=C,8749=C,877c=C,877e=C,87a7=J,87a8=C,87a9=J,87cf=C,87d0=J,87f5=J,8845=C,8846=C,8854=C,8865=C,886c=C,8884=C,8885=C,889c=C,88ad=C,88b0=J,88c3=J,88c4=J,88c5=C,88c6=C,88e2=C,88e3=C,88e4=C,88e5=C,8902=J,8904=J,891b=C,'
2599 +'891c=J,8934=C,8947=C,8977=J,898e=C,89c1=C,89c2=C,89c3=C,89c4=C,89c5=C,89c6=C,89c7=C,89c8=C,89c9=C,89ca=C,89cb=C,89cc=C,89ce=C,89cf=C,89d0=C,89d1=C,89de=C,8a29=C,8a33=J,8a5f=C,8a89=C,8a8a=C,8aac=C,8aad=J,8aae=J,8ada=J,8b21=C,8b2d=C,8ba1=C,8ba2=C,8ba3=C,8ba4=C,8ba5=C,8ba6=C,8ba7=C,'
2600 +'8ba8=C,8ba9=C,8baa=C,8bab=C,8bad=C,8bae=C,8baf=C,8bb0=C,8bb2=C,8bb3=C,8bb4=C,8bb5=C,8bb6=C,8bb7=C,8bb8=C,8bb9=C,8bba=C,8bbb=C,8bbc=C,8bbd=C,8bbe=C,8bbf=C,8bc0=C,8bc1=C,8bc2=C,8bc3=C,8bc4=C,8bc5=C,8bc6=C,8bc7=C,8bc8=C,8bc9=C,8bca=C,8bcb=C,8bcc=C,8bcd=C,8bce=C,8bcf=C,8bd1=C,8bd2=C,'
2601 +'8bd3=C,8bd4=C,8bd5=C,8bd6=C,8bd7=C,8bd8=C,8bd9=C,8bda=C,8bdb=C,8bdd=C,8bde=C,8bdf=C,8be0=C,8be1=C,8be2=C,8be3=C,8be4=C,8be5=C,8be6=C,8be7=C,8be8=C,8be9=C,8beb=C,8bec=C,8bed=C,8bee=C,8bef=C,8bf0=C,8bf1=C,8bf2=C,8bf3=C,8bf4=C,8bf5=C,8bf6=C,8bf7=C,8bf8=C,8bf9=C,8bfa=C,8bfb=C,8bfc=C,'
2602 +'8bfd=C,8bfe=C,8bff=C,8c00=C,8c01=C,8c02=C,8c03=C,8c04=C,8c05=C,8c06=C,8c07=C,8c08=C,8c09=C,8c0a=C,8c0b=C,8c0c=C,8c0d=C,8c0e=C,8c0f=C,8c10=C,8c11=C,8c12=C,8c13=C,8c14=C,8c15=C,8c16=C,8c17=C,8c18=C,8c19=C,8c1a=C,8c1b=C,8c1c=C,8c1d=C,8c1e=C,8c1f=C,8c20=C,8c21=C,8c22=C,8c23=C,8c24=C,'
2603 +'8c25=C,8c26=C,8c27=C,8c28=C,8c29=C,8c2a=C,8c2b=C,8c2c=C,8c2d=C,8c2e=C,8c2f=C,8c30=C,8c31=C,8c32=C,8c33=C,8c34=C,8c35=C,8c36=C,8c6e=C,8cae=J,8ceb=C,8cec=J,8d0b=C,8d1c=C,8d1d=C,8d1e=C,8d1f=C,8d21=C,8d22=C,8d23=C,8d24=C,8d25=C,8d26=C,8d27=C,8d28=C,8d29=C,8d2a=C,8d2b=C,8d2c=C,8d2d=C,'
2604 +'8d2e=C,8d2f=C,8d30=C,8d31=C,8d32=C,8d33=C,8d34=C,8d35=C,8d36=C,8d37=C,8d38=C,8d39=C,8d3a=C,8d3b=C,8d3c=C,8d3d=C,8d3e=C,8d3f=C,8d41=C,8d42=C,8d43=C,8d44=C,8d45=C,8d46=C,8d48=C,8d49=C,8d4a=C,8d4b=C,8d4c=C,8d4d=C,8d4e=C,8d4f=C,8d50=C,8d52=C,8d53=C,8d54=C,8d55=C,8d56=C,8d57=C,8d58=C,'
2605 +'8d59=C,8d5a=C,8d5b=C,8d5c=C,8d5d=C,8d5e=C,8d60=C,8d61=C,8d62=C,8d63=C,8d6a=C,8d71=J,8d75=C,8d8b=C,8db1=C,8db8=C,8dc3=C,8dc4=C,8def=J,8df4=J,8df5=C,8df7=C,8df8=C,8df9=C,8dfb=C,8e0c=C,8e2c=C,8e2f=C,8e51=C,8e52=C,8e7f=C,8e8f=C,8e9c=C,8eae=J,8eaf=C,8eb5=J,8ebb=J,8ebe=J,8ec5=J,8ec8=J,'
2606 +'8ee4=C,8ef2=C,8f4c=J,8f66=C,8f67=C,8f68=C,8f69=C,8f6b=C,8f6c=C,8f6d=C,8f6e=C,8f6f=C,8f70=C,8f71=C,8f72=C,8f73=C,8f74=C,8f76=C,8f77=C,8f78=C,8f79=C,8f7a=C,8f7b=C,8f7c=C,8f7d=C,8f7e=C,8f7f=C,8f82=C,8f83=C,8f84=C,8f85=C,8f86=C,8f87=C,8f88=C,8f89=C,8f8a=C,8f8b=C,8f8d=C,8f8e=C,8f8f=C,'
2607 +'8f90=C,8f91=C,8f93=C,8f94=C,8f95=C,8f96=C,8f97=C,8f98=C,8f99=C,8f9a=C,8f9e=C,8fa9=C,8fab=C,8fb7=J,8fb9=C,8fbb=J,8fbc=J,8fbd=C,8fbe=C,8fc1=C,8fc7=C,8fc8=C,8fd0=C,8fd8=C,8fd9=C,8fda=J,8fdb=C,8fdc=C,8fdd=C,8fde=C,8fdf=C,8fe9=C,8ff9=C,9009=C,900a=C,9012=C,9026=C,9027=J,903b=C,9056=J,'
2608 +'9057=C,9093=C,909d=C,90ac=C,90ae=C,90b9=C,90ba=C,90bb=C,90cf=C,90d0=C,90d1=C,90d2=J,90d3=C,90e6=C,90e7=C,90f8=C,915b=J,915d=C,9171=C,917d=C,917e=C,917f=C,9196=C,91ca=C,91d7=J,91fa=C,91fb=J,91fe=C,9208=C,920e=C,9225=J,9226=J,9228=J,9229=J,922c=J,9239=J,923e=J,9255=C,9262=C,926b=J,'
2609 +'9274=C,9286=J,92ab=J,92ae=C,92af=J,92b1=C,92c5=J,92e5=C,92ed=C,92f2=J,9307=C,9332=C,9335=J,933a=J,933e=C,9340=C,9341=C,9344=J,9369=C,9384=C,9386=J,9387=C,93b8=C,93b9=J,93bf=C,93e5=J,93f0=C,941d=C,9420=J,9421=J,9426=C,9427=C,942f=C,9453=J,9454=C,9465=C,9479=C,9486=C,9487=C,9488=C,'
2610 +'9489=C,948a=C,948b=C,948c=C,948d=C,948e=C,948f=C,9490=C,9492=C,9493=C,9494=C,9495=C,9496=C,9497=C,9498=C,9499=C,949a=C,949b=C,949d=C,949e=C,949f=C,94a0=C,94a1=C,94a2=C,94a4=C,94a5=C,94a6=C,94a7=C,94a8=C,94a9=C,94aa=C,94ab=C,94ac=C,94ad=C,94ae=C,94af=C,94b0=C,94b1=C,94b2=C,94b3=C,'
2611 +'94b4=C,94b5=C,94b6=C,94b7=C,94b9=C,94ba=C,94bb=C,94bc=C,94bd=C,94be=C,94bf=C,94c0=C,94c1=C,94c2=C,94c3=C,94c4=C,94c5=C,94c6=C,94c8=C,94c9=C,94ca=C,94cb=C,94cc=C,94cd=C,94ce=C,94cf=C,94d0=C,94d1=C,94d2=C,94d3=C,94d5=C,94d7=C,94d9=C,94db=C,94dc=C,94dd=C,94de=C,94df=C,94e0=C,94e1=C,'
2612 +'94e2=C,94e3=C,94e4=C,94e5=C,94e7=C,94e8=C,94e9=C,94ea=C,94eb=C,94ec=C,94ed=C,94ee=C,94ef=C,94f0=C,94f1=C,94f2=C,94f3=C,94f5=C,94f6=C,94f7=C,94f8=C,94f9=C,94fa=C,94fc=C,94fd=C,94fe=C,94ff=C,9500=C,9501=C,9502=C,9503=C,9504=C,9505=C,9506=C,9507=C,9508=C,9509=C,950b=C,950c=C,950e=C,'
2613 +'950f=C,9510=C,9511=C,9512=C,9513=C,9514=C,9515=C,9517=C,9518=C,9519=C,951a=C,951b=C,951d=C,951e=C,951f=C,9521=C,9522=C,9523=C,9524=C,9525=C,9526=C,9527=C,9528=C,952b=C,952d=C,952e=C,952f=C,9530=C,9531=C,9532=C,9534=C,9535=C,9536=C,9537=C,9538=C,9539=C,953b=C,953c=C,953e=C,953f=C,'
2614 +'9540=C,9541=C,9542=C,9543=C,9544=C,9545=C,9547=C,9549=C,954a=C,954b=C,954c=C,954d=C,954e=C,954f=C,9550=C,9551=C,9552=C,9553=C,9554=C,9556=C,9557=C,9558=C,955a=C,955b=C,955c=C,955d=C,955e=C,9562=C,9563=C,9564=C,9565=C,9566=C,9567=C,9568=C,9569=C,956a=C,956b=C,956c=C,956d=C,956e=C,'
2615 +'956f=C,9570=C,9571=C,9572=C,9573=C,9574=C,9576=C,957f=C,9584=J,9587=J,958a=J,9596=J,95a0=J,95a7=C,95aa=J,95b2=C,95b8=J,95e6=J,95e8=C,95e9=C,95ea=C,95ed=C,95ee=C,95ef=C,95f0=C,95f1=C,95f2=C,95f4=C,95f5=C,95f7=C,95f8=C,95f9=C,95fa=C,95fb=C,95fc=C,95fd=C,95fe=C,95ff=C,9600=C,9601=C,'
2616 +'9602=C,9603=C,9604=C,9605=C,9606=C,9608=C,9609=C,960a=C,960b=C,960c=C,960d=C,960e=C,960f=C,9610=C,9611=C,9612=C,9614=C,9615=C,9616=C,9617=C,9619=C,961a=C,961f=C,9633=C,9634=C,9635=C,9636=C,9645=C,9646=C,9647=C,9648=C,9649=C,9655=C,9668=C,9669=C,968f=C,9690=C,96b6=C,96be=C,96cf=C,'
2617 +'96e0=C,96eb=J,96f3=C,96fe=C,9701=C,972d=C,974d=J,974e=J,974f=J,9753=C,9765=C,9779=J,9786=J,9790=J,9791=C,9792=C,979c=J,97af=C,97bd=C,97e6=C,97e7=C,97e8=C,97e9=C,97ea=C,97eb=C,97ec=C,97f5=C,983d=C,9854=C,986c=C,9875=C,9876=C,9877=C,9878=C,9879=C,987a=C,987b=C,987c=C,987d=C,987e=C,'
2618 +'987f=C,9880=C,9881=C,9882=C,9883=C,9884=C,9885=C,9886=C,9887=C,9888=C,9889=C,988a=C,988b=C,988c=C,988d=C,988f=C,9890=C,9891=C,9893=C,9894=C,9896=C,9897=C,9898=C,9899=C,989b=C,989c=C,989d=C,989e=C,989f=C,98a0=C,98a1=C,98a2=C,98a4=C,98a5=C,98a6=C,98a7=C,98aa=J,98ce=C,98d2=C,98d3=C,'
2619 +'98d4=C,98d5=C,98d7=C,98d8=C,98d9=C,98de=C,98e8=C,98ff=C,9904=C,990d=C,990e=C,990f=C,9919=J,991c=C,9936=C,9937=C,9942=J,994a=C,9962=C,9965=C,9966=C,9967=C,9968=C,9969=C,996a=C,996b=C,996c=C,996d=C,996e=C,996f=C,9970=C,9971=C,9972=C,9973=C,9974=C,9975=C,9976=C,9977=C,9978=C,9979=C,'
2620 +'997a=C,997b=C,997c=C,997d=C,997f=C,9981=C,9983=C,9984=C,9985=C,9986=C,9987=C,9988=C,9989=C,998a=C,998b=C,998d=C,998e=C,998f=C,9990=C,9991=C,9992=C,9993=C,9994=C,9995=C,99e1=C,99f2=J,9a6b=J,9a6c=C,9a6d=C,9a6e=C,9a6f=C,9a70=C,9a71=C,9a73=C,9a74=C,9a75=C,9a76=C,9a77=C,9a78=C,9a79=C,'
2621 +'9a7a=C,9a7b=C,9a7c=C,9a7d=C,9a7e=C,9a7f=C,9a80=C,9a81=C,9a82=C,9a84=C,9a85=C,9a86=C,9a87=C,9a88=C,9a8a=C,9a8b=C,9a8c=C,9a8e=C,9a8f=C,9a90=C,9a91=C,9a92=C,9a93=C,9a96=C,9a97=C,9a98=C,9a9a=C,9a9b=C,9a9c=C,9a9d=C,9a9e=C,9a9f=C,9aa0=C,9aa1=C,9aa2=C,9aa4=C,9aa5=C,9aa7=C,9ac5=C,9acb=C,'
2622 +'9acc=C,9aea=J,9b13=C,9b47=C,9b49=C,9b5d=J,9b5e=J,9b6c=J,9b74=J,9b78=J,9b79=J,9b81=C,9b84=J,9b8d=C,9b8e=C,9b95=J,9b96=J,9b97=J,9b98=J,9b9d=C,9b9f=J,9ba3=C,9bb1=J,9bb4=J,9bba=C,9bce=J,9bcf=J,9bd0=J,9bd1=J,9bd2=J,9be1=J,9bf0=J,9bf1=J,9bf2=J,9bf3=J,9bff=C,9c02=C,9c04=J,9c0c=C,9c10=C,'
2623 +'9c12=J,9c18=J,9c1f=C,9c21=J,9c27=C,9c2e=J,9c2f=J,9c30=J,9c35=C,9c39=J,9c45=C,9c47=J,9c48=J,9c5a=J,9c69=J,9c6a=J,9c6b=J,9c70=J,9c7c=C,9c7d=C,9c7f=C,9c81=C,9c82=C,9c85=C,9c86=C,9c87=C,9c88=C,9c8a=C,9c8b=C,9c8d=C,9c8e=C,9c8f=C,9c90=C,9c91=C,9c92=C,9c94=C,9c96=C,9c97=C,9c99=C,9c9a=C,'
2624 +'9c9b=C,9c9c=C,9c9d=C,9c9e=C,9c9f=C,9ca0=C,9ca1=C,9ca2=C,9ca3=C,9ca4=C,9ca5=C,9ca6=C,9ca7=C,9ca8=C,9ca9=C,9cab=C,9cad=C,9cae=C,9cb0=C,9cb1=C,9cb2=C,9cb3=C,9cb5=C,9cb6=C,9cb7=C,9cb8=C,9cbb=C,9cbd=C,9cbf=C,9cc1=C,9cc3=C,9cc4=C,9cc5=C,9cc6=C,9cc7=C,9cca=C,9ccc=C,9ccd=C,9cce=C,9ccf=C,'
2625 +'9cd1=C,9cd2=C,9cd3=C,9cd4=C,9cd5=C,9cd6=C,9cd7=C,9cd8=C,9cd9=C,9cdb=C,9cdc=C,9cdd=C,9cde=C,9cdf=C,9ce2=C,9ce3=C,9cec=C,9cf0=J,9cfe=C,9d2b=J,9d30=J,9d34=C,9d46=J,9d47=J,9d48=J,9d64=J,9d6e=C,9d93=C,9da5=C,9dab=J,9dc0=C,9dc4=C,9dc9=C,9e0a=C,9e1f=C,9e20=C,9e21=C,9e22=C,9e23=C,9e25=C,'
2626 +'9e26=C,9e27=C,9e28=C,9e29=C,9e2a=C,9e2b=C,9e2c=C,9e2d=C,9e2e=C,9e2f=C,9e30=C,9e31=C,9e32=C,9e33=C,9e35=C,9e36=C,9e37=C,9e38=C,9e39=C,9e3a=C,9e3b=C,9e3c=C,9e3d=C,9e3e=C,9e3f=C,9e41=C,9e42=C,9e43=C,9e44=C,9e45=C,9e46=C,9e47=C,9e48=C,9e49=C,9e4a=C,9e4b=C,9e4c=C,9e4f=C,9e50=C,9e51=C,'
2627 +'9e52=C,9e55=C,9e56=C,9e57=C,9e58=C,9e59=C,9e5a=C,9e5b=C,9e5c=C,9e5e=C,9e61=C,9e63=C,9e64=C,9e65=C,9e66=C,9e67=C,9e68=C,9e69=C,9e6a=C,9e6b=C,9e6c=C,9e6d=C,9e6f=C,9e70=C,9e73=C,9e7e=C,9e91=J,9ea6=C,9eaf=C,9eb8=C,9ebd=C,9ebf=J,9ec9=C,9ee1=C,9ee9=C,9efe=C,9f0b=C,9f0d=C,9f21=J,9f50=C,'
2628 +'9f51=C,9f7f=C,9f80=C,9f83=C,9f84=C,9f85=C,9f86=C,9f87=C,9f88=C,9f89=C,9f8a=C,9f8b=C,9f8c=C,9f99=C,9f9a=C,9f9b=C,9f9f=C,fa0f=J,fa13=J,fa20=J,fa21=J,fa24=J,fa29=J',1,16);
2629 //	HKEY_CLASSES_ROOT\MIME\Database\Charset
2630 //	將gb排在Big5前面是因為gb常用字在Big5中常常是0x8000之後的常用字,Big5常用字卻常常是gb中奇怪字碼與罕用字
2631 setObjValue('autodetectEncodeCode','GB2312=3000,Big5=3000,shift_jis=900,iso-8859-1=2000',1);
2632 
2633 
2634 TODO:
2635 只檢測常用的幾個字,無法判別才廣泛測試。
2636 */
2637 //var FN='I:\\Documents and Settings\\kanashimi\\My Documents\\kanashimi\\www\\cgi-bin\\game\\sjis.txt',enc=autodetectEncode(FN);alert('['+enc+'] '+FN+'\n'+_.read_all_file(FN,enc).slice(0,900));
2638 /*	自動判別檔案(或字串)之編碼	文字エンコーディング判定を行う
2639 	http://www.hawk.34sp.com/stdpls/dwsh/charset_adodb.html
2640 	http://www.ericphelps.com/q193998/
2641 	http://hp.vector.co.jp/authors/VA003334/ado/adostream.htm
2642 */
2643 //autodetectEncode[generateCode.dLK]='isFile,simpleFileDformat,_.open_file,autodetectStringEncode,autodetectHTMLEncode';
2644 _.
2645 autodetectEncode=function(FN,isHTML){
2646  var t,code;
2647  if(typeof ActiveXObject=='undefined'){alert("autodetectEncode: Can't find ActiveXObject!");return;}
2648  //if(typeof autodetectHTMLEncode!='function')isHTML=false;
2649  if(!isFile(FN))return FN.length<64?simpleFileDformat:(t=autodetectStringEncode(FN))?t:(isHTML||typeof isHTML=='undefined')&&(t=autodetectHTMLEncode(FN))?t:simpleFileDformat;
2650  _.open_file(FN,'iso-8859-1');	//	讀 binary data 用 'iso-8859-1' 會 error encoding.
2651  if(!AdoEnums||!AdoStream)return simpleFileDformat;
2652  AdoStream.LoadFromFile(FN);
2653  t=AdoStream.ReadText(3);//Read(3);//
2654  //alert(FN+'\n'+t.charCodeAt(0)+','+t.charCodeAt(1)+','+t.charCodeAt(2));
2655 
2656  //if(typeof t!='string')return simpleFileDformat;//t=''+t;	//	此時type通常是unknown,不能用+=
2657  //	Unicode的Byte Order Mark(BOM)在UTF-16LE(little endian)裏,它是以FF-FE這兩個bytes表達,在BE(big endian)裏,是FEFF。而在UTF-8裏,它是以EF-BB-BF這三個bytes表達。
2658  if(t.slice(0,2)=='\xFF\xFE')code='unicodeFFFE';
2659  else if(t.slice(0,2)=='\xFE\xFF')code='unicode';
2660  else if(t=='\xEF\xBB\xBF')code='UTF-8';
2661  else{
2662   // 即使是用OpenTextFile(_.open_format.TristateFalse),UTF-8還是會被轉換而判別不出來。
2663   //	from http://www.hawk.34sp.com/stdpls/dwsh/charset_adodb.html
2664   var l,codes={},reg=new RegExp(),stream=new ActiveXObject("ADODB.Stream");
2665   codes['iso-8859-1']='[\\x09\\x0a\\x0d\\x20-\\x7e]';
2666   codes['big5']=codes['iso-8859-1']+
2667 	'|[\\xa4-\\xc6\\xc9-\\xf9][\\x40-\\xfe]';	//	http://www.cns11643.gov.tw/web/word/big5/index.html
2668   codes['shift_jis']=codes['iso-8859-1']+
2669 	'|[\\x81-\\x9f\\xe0-\\xef\\xfa-\\xfc][\\x40-\\x7e\\x80-\\xfc]|[\\xa1-\\xdf]';	//	http://hp.vector.co.jp/authors/VA013241/misc/shiftjis.html
2670   codes['euc-jp']=codes['iso-8859-1']+
2671 	'|\\x8f[\\xa1-\\xfe][\\xa1-\\xfe]|[\\xa1-\\xfe][\\xa1-\\xfe]|\\x8e[\\xa1-\\xdf]';
2672   codes['utf-8']=codes['iso-8859-1']+
2673 	'|[\\xc0-\\xdf][\\x80-\\xbf]|[\\xe0-\\xef][\\x80-\\xbf]{2}|[\\xf0-\\xf7][\\x80-\\xbf]{3}'+
2674 	'|[\\xf8-\\xfb][\\x80-\\xbf]{4}|[\\xfc-\\xfd][\\x80-\\xbf]{5}';
2675   codes['gb2312']=codes['iso-8859-1']+	//	GBK
2676 	'|[\\xa1-\\xf7][\\xa1-\\xfe]';	//	http://zh.wikipedia.org/wiki/GB_18030	http://zh.wikipedia.org/wiki/GB_2312
2677 
2678   stream.type=AdoEnums.adTypeBinary;
2679   stream.open();
2680   stream.loadFromFile(FN);
2681   stream.position=0;
2682   t=stream.read();
2683   stream.close();
2684   stream=null;
2685 
2686   t=translate_AdoStream_binary_data(t,4e3);
2687 
2688   for(var _e in codes){
2689    reg=new RegExp('^(?:'+codes[_e]+')');
2690    var l=0,s=t;
2691    while(l!=s.length)l=s.length,s=s.replace(reg,"");
2692    if(s==""){code=_e;break;}
2693   }
2694 
2695  }
2696  //sl('autodetectEncode: coding: ['+code+'] in parse 1.');
2697 
2698  //	假如是HTML檔,判斷是否有charset設定。這個判別放在unicode之後,其他自動判別之前。
2699  if(isHTML||typeof isHTML=='undefined'&&/\.s?html?$/i.test(FN)){
2700   if(AdoStream.Type==AdoEnums.adTypeBinary)_.open_file(FN,'iso-8859-1');
2701   AdoStream.Position=0,AdoStream.Charset='iso-8859-1';	//	讀 binary data 用 'iso-8859-1' 會 error encoding.
2702   if(t=autodetectHTMLEncode(AdoStream.ReadText(4e3)))code=t;
2703  }
2704  //sl('autodetectEncode: coding: ['+code+'] in parse 2.');
2705 
2706  //autodetectEncodeCode.GB2312=900000;	// 4 test
2707  if(!code)for(var i in autodetectEncodeCode){
2708   if(AdoStream.Type==AdoEnums.adTypeBinary)_.open_file(FN,'iso-8859-1');
2709   if(AdoStream.Position=0,i==autodetectStringEncode(AdoStream.ReadText(autodetectEncodeCode[AdoStream.Charset=i]))){code=i;break;}
2710  }
2711 
2712  AdoStream.Close();
2713  return code||simpleFileDformat;	//	ascii=iso-8859-1,_autodetect,_autodetect_all
2714 };
2715 
2716 //	判斷HTML檔是否有charset設定
2717 function autodetectHTMLEncode(fc){	//	file contents
2718  var t;
2719  if( fc.match(/<\s*meta\s+([^>]+)>/i)
2720 	&& ((t=RegExp.$1).match(/content="([^"]+)"/i)||t.match(/content=([^\w]+)/i))
2721 	&& (t=RegExp.$1).match(/charset=([\w-]{2,})/i)
2722 	|| fc.match(/<\?\s*xml\s[^>]+\sencoding\s*=\s*["']([a-z\d\-]+)["']/i)
2723 	)
2724  return RegExp.$1;
2725 }
2726 _.
2727 /**
2728  * 靠常用字自動判別字串之編碼	string,預設編碼
2729  */
2730 autodetectStringEncode=function(str){
2731  if(typeof str!='string'||!(str=str.replace(/\s+/g,'')))return;
2732  var len=str.length,i=0,c,a,kana=0,jianhuazi=0,halfwidthKatakana=0,Hangul=0,ascii=0,asciiHigh=0,kanji=0,kokuji=0,symbol=0,unknown=0;
2733  //if(len>9000)len=9000;
2734  //var unknownC='';
2735 
2736  //	char分類
2737  for(;i<len;i++)
2738   if(c=str.charCodeAt(i),c<0x80)ascii++;
2739   else if(c<0x100)asciiHigh++;
2740   else if(c>0x3040&&c<0x30ff)kana++;
2741   else if(c==0x30fb||c>0xff65&&c<0xff9e)halfwidthKatakana++;
2742   else if(c>=0x1100&&c<0x11fa||c>=0xac00&&c<0xad00||c>=0xd700&&c<0xd7a4)Hangul++;
2743   else if(c>0x4dff&&c<0x9fa6){kanji++,a=autodetectEncodeSP[c];if(a=='C')jianhuazi++;else if(a=='J')kokuji++;}
2744   else if(c>0xfa00&&c<0xfa6b){if(autodetectEncodeSP[c]=='J')kokuji++;}
2745   else if(c>0x2010&&c<0x2610||c>=0xfe30&&c<0xfe70||c>0xff00&&c<0xff5f)symbol++;
2746   else if(c>=0x3000&&c<0x3400||c>0x33ff&&c<0x4db6)
2747    if(autodetectEncodeSP[c]=='J')kokuji++;else symbol++;
2748   else unknown++;//,unknownC+=str.charAt(i);
2749 
2750  //alert('len='+len+'\nkana='+kana+'\nkokuji='+kokuji+'\njianhuazi='+jianhuazi+'\nhalfwidthKatakana='+halfwidthKatakana+'\nHangul='+Hangul+'\nascii='+ascii+'\nasciiHigh='+asciiHigh+'\nkanji='+kanji+'\nsymbol='+symbol+'\nunknown='+unknown);
2751  //if(unknownC)alert('unknown:\n'+unknownC.slice(0,200));//alert(unknownC.slice(0,200)+'\n'+str.slice(0,1000));
2752  //	依各種常用字母之條件判別
2753  return ascii+asciiHigh==len?'iso-8859-1'
2754 	:unknown>.05*(len-ascii)?''//unicode	//	unknown不能太多
2755 	:kana>.2*len&&kanji+kana+symbol>3*halfwidthKatakana?'shift_jis'
2756 	:kanji+symbol>.7*(len-ascii)&&kana<.05*(len-ascii)?	jianhuazi>.1*kanji?'GB2312':'Big5'
2757 	:Hangul+symbol>.7*(len-ascii)?'korean'//ks_c_5601
2758 	:kanji>.2*(len-ascii)?	jianhuazi>.1*kanji?kokuji>.02*kanji?'unicode':'GB2312':kokuji>.02*kanji?'shift_jis':'Big5'
2759 	:'';//unicode
2760 }
2761 
2762 /*
2763 http://bbs.ee.ntu.edu.tw/boards/Linux/7/9/58.html	http://libai.math.ncu.edu.tw/~shann//Chinese/big5.html	http://wiki.debian.org.tw/index.php/Big5Variants	http://leoboard.cpatch.org/cgi-bin/topic.cgi?forum=20&topic=64&changemode=1
2764 http://www.theorem.ca/~mvcorks/cgi-bin/unicode.pl.cgi?start=F900&end=FAFF	http://homepage1.nifty.com/nomenclator/unicode/normalization.htm
2765 
2766 Unicode的漢字大致是以康熙部首排序,不過間中有部分字排錯部首筆劃
2767 第一批在1993年加進Unicode的,
2768 於中國內地、台灣、南韓及日本已有字集的漢字,
2769 編碼於U+4E00至U+9FA5,
2770 亦有部分南韓重覆漢字被編到U+F900至U+FA0B、
2771 兩個Big-5重覆漢字被編到U+FA0C至U+FA0D、
2772 日本廠商漢字被編到U+FA0E至U+FA2D
2773 
2774 全形符號(只限鍵盤上那94個)位於U+FF01至U+FF5E
2775 中日韓專用符號放到了U+3000至U+33FF內,
2776 其餘有部分符號放到了U+2XXX及U+FE30至U+FE6F
2777 
2778 第二批在1999年加進Unicode的,
2779 加進了新加坡用漢字、南韓PKS C 5700-2 1994、
2780 部分CNS11643第三、四、十五字面等用字、
2781 未包括在第一批字的數個GB字集用字,
2782 被編入U+3400至U+4DB5
2783 
2784 第三批在2001年加進Unicode的,
2785 加進了CNS11643第三、四、五、六、七、十五字面所有字、
2786 香港增補字集用字、四庫全書、辭海、辭源、康熙字典、
2787 漢語大字典、漢語大詞典內的所有用字,
2788 被編入U+20000至U+2A6D6
2789 JIS-X0213漢字被加到U+FA30至U+FA6A
2790 CNS11643重覆漢字被加到U+2F800至U+2FA1D
2791 
2792 简化字总表	http://cdns.twnic.net.tw/cjktable/	http://www.sxyw.cn/YuWenGongZuo/gfzs22.htm	http://huayuqiao.org/articles/xieshiya/Simplified/6_XinJiaPoTiaoZhengJianTiZi-XP.htm	http://www.hk-place.com/vp.php?board=2&id=333-9
2793 简化字分布似乎並無規範,只好以array判斷:
2794 
2795 <div id="dataGB">
2796 http://cdns.twnic.net.tw/cjktable/simtab.html
2797 簡化字總表之 UNICODE 碼表
2798 </div>
2799 <div id="dataJP">
2800 http://homepage2.nifty.com/TAB01645/ohara/index_j2.htm
2801 JIS区点索引
2802 </div>
2803 
2804 <script type="text/javascript">
2805 var i=0,c=0,autodetectEncodeSP=[],m=document.getElementById('dataGB').innerHTML.match(/\([0-9A-F]{4},\w*\)/g),t="setObjValue('autodetectEncodeSP','";
2806 for(;i<m.length;i++)//if(m[i].indexOf('C')!=-1&&m[i].slice(m[i].indexOf(',')+1).indexOf('T')==-1)t+=m[i].substr(1,5);
2807  if(m[i].indexOf('T')==-1)autodetectEncodeSP[parseInt(m[i].substr(1,4),16)]='C';
2808 for(i=0,m=document.getElementById('dataJP').innerHTML.match(/【.】/g);i<m.length;i++)
2809  autodetectEncodeSP[parseInt(m[i].charCodeAt(1))]=autodetectEncodeSP[parseInt(m[i].charCodeAt(1))]?0:'J';
2810 
2811 m=[];for(i in autodetectEncodeSP)m.push(parseInt(i));m.sort();
2812 for(i=0;i<m.length;i++)if(autodetectEncodeSP[m[i]]){t+=m[i].toString(16)+'='+autodetectEncodeSP[m[i]]+',',c++;if(c%40==0)t+="'<br/>+'";}
2813 alert(c+'字');
2814 document.getElementById('dataJP').innerHTML='';
2815 document.getElementById('dataGB').innerHTML=t.slice(0,-1)+"',1,16);";
2816 </script>
2817 
2818 
2819 和製漢字(国字)は、和語(ヤマトコトバ)に相当する漢字が無い場合に新規につくられたもので、奈良時代から作られた。ほとんどは訓読みしかない。魚篇や木篇が多い。
2820 http://homepage2.nifty.com/TAB01645/ohara/index.htm
2821 http://zh.wiktionary.org/wiki/%E8%BE%BB
2822 http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=8fbb
2823 http://jprs.jp/doc/rule/saisoku-1-wideusejp-furoku-4.html
2824 http://m2000.idv.tw/informer/zhi/char-root.htm
2825 http://www.ajisai.sakura.ne.jp/~dindi/chrc/ref/wincode2.txt
2826 http://cs-people.bu.edu/butta1/personal/hkscs/hkscs-oct.html
2827 http://www.nobi.or.jp/i/kotoba/kanji/wasei-kanji.html
2828 http://www.melma.com/mag/52/m00011552/a00000066.html
2829 
2830 
2831 韓語字母/諺文
2832 http://www.sinica.edu.tw/~cytseng/Korean%20reader/hangul.htm
2833 http://www.unicode.org/charts/normalization/
2834 
2835 old:
2836 //	自動判別檔案(或字串)之編碼
2837 function autodetectEncode(FN){
2838  if(!isFile(FN))return FN.length>64?autodetectStringEncode(FN):simpleFileDformat;
2839  _.open_file(FN,'iso-8859-1');
2840  if(!AdoEnums)return simpleFileDformat;
2841  //AdoStream.Type=AdoEnums.adTypeBinary;
2842  AdoStream.LoadFromFile(FN);
2843  var t=AdoStream.ReadText(3),code;
2844  //	Unicode的Byte Order Mark(BOM)在UTF-16LE(little endian)裏,它是以FF-FE這兩個bytes表達,在BE(big endian)裏,是FEFF。而在UTF-8裏,它是以EF-BB-BF這三個bytes表達。
2845  if(t.slice(0,2)=='\xFF\xFE')code='unicodeFFFE';
2846  if(t.slice(0,2)=='\xFE\xFF')code='unicode';
2847  if(t=='\xEF\xBB\xBF')code='UTF-8';
2848  if(code){AdoStream.Close();return code;}
2849 
2850  if(!code)with(AdoStream){
2851   //	將sjis排在gb與Big5前面是因為sjis常符合gb,且sjis之判定相當嚴。
2852   if(!code)Position=0,Charset='shift_jis',code=autodetectStringEncode(ReadText(900),Charset);
2853   //	將gb排在Big5前面是因為gb常用字在Big5中常常是0x8000之後的常用字,Big5常用字卻常常是gb中奇怪字碼與罕用字
2854   if(!code)Position=0,Charset='GB2312',code=autodetectStringEncode(ReadText(2000),Charset);
2855   if(!code)Position=0,Charset='Big5',code=autodetectStringEncode(ReadText(2000),Charset);
2856  }
2857 
2858  AdoStream.Close();
2859  return code||simpleFileDformat;	//	ascii=iso-8859-1,_autodetect,_autodetect_all
2860 }
2861 //	靠常用字自動判別字串之編碼	string,預設編碼
2862 function autodetectStringEncode(str,dcode){
2863  var code;
2864  if(str.length>9000)str=str.slice(0,9000);
2865 
2866  //	將sjis排在gb與Big5前面是因為sjis常符合gb,且sjis之判定相當嚴。
2867  if(dcode=='shift_jis'||!dcode&&!code){
2868   //	http://www.asahi-net.or.jp/~hc3j-tkg/unicode/	http://www.unicode.org/Public/UNIDATA/DerivedCoreProperties.txt
2869   var i=0,c,k=0,u=0,h=0;//h_=u_=k_='';
2870   for(;i<str.length;i++)if(c=str.charCodeAt(i),c>0xFF)
2871 	if(c==0x30FB||c>0xFF65&&c<0xFF9E)h++;//,h_+=str.charAt(i);//||c==0xE134	//	HALFWIDTH KATAKANA LETTER等可能不是日文文件中會出現的char
2872 	else if(c>0x3040&&c<0x30FF)k++;//,k_+=str.charAt(i);	//	kana
2873 	else u++;//,u_+=str.charAt(i);	//	unknown kanji
2874   //alert(k+','+u+','+h+'\n*'+k_+'\n*'+u_+'\n*'+h_);//alert(u_.charCodeAt(2));
2875   if(k+u>2*h)code='shift_jis';	//	HALFWIDTH KATAKANA LETTER數目比漢字少時判別為shift_jis
2876  }
2877 
2878 //	將gb排在Big5前面是因為gb常用字在Big5中常常是0x8000之後的常用字,Big5常用字卻常常是gb中奇怪字碼與罕用字
2879  if(dcode=='Big5'||dcode=='GB2312'||!dcode&&!code){
2880   var i=0,c,k=0,u=0;//k_=u_='';
2881   for(;i<str.length;i++)if(c=str.charCodeAt(i),c>0xFF)
2882 	if(c>0x4DFF&&c<0x9FA6||c>0xFF00&&c<0xFF5F||c>0x33ff&&c<0x4DB6||c==0x2605||c==0x2606)k++;//,k_+=str.charAt(i);	//	2605,6:★☆
2883 	else u++;//,u_+=str.charAt(i);
2884   //alert(k+','+u+'\n'+k_+'\n*'+u_);
2885   if(k>5*u)code=dcode||'Big5';	//	漢字比不認識的字多時判定
2886  }
2887 
2888  if(dcode=='iso-8859-1'||dcode=='ascii'||!dcode&&!code){
2889  }
2890 
2891  return code;
2892 }
2893 */
2894 
2895 
2896 /*	將 iso-8859-1 轉成utf-8
2897 To use:
2898 ..
2899 translated=turnBinStr(original);
2900 ..
2901 translated=turnBinStr();	//	delete temp file
2902 */
2903 turnBinStr.temp_file='turnBinStr.tmp';	//	temp file name
2904 function turnBinStr(t,_enc){
2905  if(typeof t!='undefined'){
2906   if(!turnBinStr.tmpF)turnBinStr.tmpF=getFP(turnBinStr.temp_file,1);
2907 
2908   //t+='';
2909   //if(t.replace(/[^\x00-\x7f]+/g,''))return t;
2910   //var _q=t.replace(/[^?]+/g,'').length,_t,_j=0;
2911   _.write_to_file(turnBinStr.tmpF,''+t,'iso-8859-1');
2912   //alert(turnBinStr.tmpF+'\n'+simpleFileErr.description+'\n'+t+'\n'+_.read_all_file(turnBinStr.tmpF,'utf-8'));
2913   return _.read_all_file(turnBinStr.tmpF,'utf-8');
2914 /*
2915   if(!_enc)_enc='utf-8,Big5,shift_jis,euc-jp,GB2312'.split(',');
2916   else if(!(_enc instanceof Array))_enc=[_enc];
2917   for(;_j<_enc.length;_j++)
2918    if((_t=_.read_all_file(turnBinStr.tmpF,_enc[_j])).replace(/[^?]+/g,'').length==_q)
2919     return _t;//'['+_enc[_j]+']'+
2920   return t;
2921 */
2922  }
2923  try{fso.DeleteFile(turnBinStr.tmpF);}catch(e){}	//	有時會出錯
2924 }
2925 
2926 
2927 
2928 
2929 
2930 //folder_info[generateCode.dLK]='initWScriptObj';
2931 //	需同時修改if(traverseSubDirectory==folder_info.f.noNewObj)段落之return!
2932 
2933 //setObjValue('folder_info.f','noNewObj=-1,files,dirs,fsize,size,Tsize=3,Tfiles,Tdirs',1);
2934 _.
2935 /**
2936  * Get the infomation of folder
2937  * @param folder_path	folder path
2938  * @param file_filter
2939  * @param traverseSubDirectory
2940  * @return
2941  * @example
2942  * var finfo=new folder_info(path or folder object,extFilter,0/1);
2943  * @deprecated	以 <a href="#.traverse_file_system">traverse_file_system</a> 代替
2944  * @memberOf	CeL.IO.Windows.file
2945  */
2946 folder_info=function(folder_path,file_filter,traverseSubDirectory){
2947  var dir,filesCount,subDirectorysCount,total_size_of_files,total_size_of_this_folder,total_filesCount,total_subDirectorysCount;
2948  filesCount=subDirectorysCount=total_size_of_files=total_size_of_this_folder=total_filesCount=total_subDirectorysCount=0;
2949  if(typeof traverseSubDirectory=='undefined')traverseSubDirectory=1;
2950 
2951  if(typeof folder_path=='object')dir=folder_path;
2952  else if(folder_path){
2953   if(!folder_path.slice(-1)!=path_separator)folder_path+=path_separator;
2954   try{dir=fso.GetFolder(folder_path);}catch(e){dir=0;}
2955  }
2956 
2957  if(dir){
2958   total_subDirectorysCount=subDirectorysCount=dir.SubFolders.Count;
2959   var i,t,f=new Enumerator(dir.SubFolders);
2960   if(traverseSubDirectory||traverseSubDirectory==folder_info.f.noNewObj)for(;!f.atEnd();f.moveNext()){
2961    i=f.item();
2962    t=folder_info(i,file_filter,folder_info.f.noNewObj);
2963    //alert(i.path+'\n'+t[folder_info.f.size]+','+t[folder_info.f.Tfiles]+','+t[folder_info.f.Tdirs]);
2964    total_size_of_this_folder+=t[folder_info.f.size];
2965    total_filesCount+=t[folder_info.f.Tfiles];
2966    total_subDirectorysCount+=(t[folder_info.f.Tdirs]||0);
2967   }
2968 
2969   //alert(dir.files.Count+'\n'+total_filesCount);
2970   total_filesCount+=(filesCount=dir.files.Count);
2971   f=new Enumerator(dir.files);
2972   for(;!f.atEnd();f.moveNext()){
2973    i=f.item();
2974    if(file_filter&&!file_filter.test(i.name))continue;
2975    //if(traverseSubDirectory!=folder_info.f.noNewObj)alert(i.name+': '+i.size+' / '+total_size_of_files);
2976    total_size_of_files+=i.size;
2977   }
2978 
2979   total_size_of_this_folder+=total_size_of_files;
2980  }
2981 
2982  //alert(dir.path+'\nfile filter: '+file_filter+'\n'+filesCount+','+subDirectorysCount+','+total_size_of_files+','+total_size_of_this_folder+','+total_filesCount+','+total_subDirectorysCount);
2983  if(traverseSubDirectory==folder_info.f.noNewObj)
2984   return [filesCount,subDirectorysCount,total_size_of_files,total_size_of_this_folder,total_filesCount,total_subDirectorysCount];
2985 
2986  this.files=this[folder_info.f.files]=filesCount;
2987  this.dirs=this[folder_info.f.dirs]=subDirectorysCount;
2988  this.fsize=this[folder_info.f.fsize]=total_size_of_files;
2989  this.size=this[folder_info.f.size]=total_size_of_this_folder;
2990  this.Tfiles=this[folder_info.f.Tfiles]=total_filesCount;
2991  this.Tdirs=this[folder_info.f.Tdirs]=total_subDirectorysCount;
2992  return this;
2993 };
2994 _.
2995 /**
2996  * <a href="#.folder_info">folder_info</a> 的 flag enumeration
2997  * @memberOf	CeL.IO.Windows.file
2998  * @constant
2999  */
3000 folder_info.f={
3001 	noNewObj:-1,
3002 	files:0,
3003 	dirs:1,
3004 	fsize:2,
3005 	size:3,
3006 	Tsize:3,
3007 	Tfiles:4,
3008 	Tdirs:5
3009 };
3010 
3011 
3012 /*	list files of folder	改編自 folder_info()
3013 	var files=new listFile(path or folder object,extFilter,flag);
3014 
3015 */
3016 //listFile[generateCode.dLK]='initWScriptObj';
3017 //	需同時修改if(flag==listFile.f.noNewObj)段落之return!
3018 
3019 //setObjValue('listFile.f','ignoreCase=1',1);
3020 listFile.f={
3021 	ignoreCase:1
3022 };
3023 
3024 function listFile(folder_path,file_filter,flag){
3025  var files=[];
3026  if(typeof flag=='undefined')flag=0;
3027 
3028  if(typeof folder_path=='object')dir=folder_path;
3029  else if(folder_path){
3030   if(!folder_path.slice(-1)!=path_separator)folder_path+=path_separator;
3031   try{dir=fso.GetFolder(folder_path);}catch(e){dir=0;}
3032  }
3033 
3034  if(dir){
3035   var i,f=new Enumerator(dir.files);
3036   for(;!f.atEnd();f.moveNext()){
3037    i=f.item();
3038    if(file_filter&&!file_filter.test(i.name))continue;
3039    files.push(i.name);
3040   }
3041  }
3042 
3043  return files;
3044 }
3045 
3046 
3047 
3048 
3049 
3050 
3051 /*
3052 in UNIX:
3053 iconv -l
3054 iconv -c -f UTF-16 -t BIG5-HKSCS function.js
3055 
3056 */
3057 /**
3058  * 將編碼為fromCode之檔案fileName中所有不合編碼toCode之char以encodeFunction轉換
3059  * @param fileName
3060  * @param toCode
3061  * @param fromCode
3062  * @param encodeFunction
3063  * @return
3064  * @memberOf	CeL.IO.Windows.file
3065  */
3066 function iconv_file(fileName,toCode,fromCode,encodeFunction){
3067  return iconv(_.read_all_file(fileName,fromCode),toCode,encodeFunction);
3068 }
3069 /*	將string text中所有不合編碼toCode之char以encodeFunction轉換
3070 
3071 TODO:
3072 一次寫入多 bytes
3073 */
3074 //var iconvError=[];
3075 function iconv(text,toCode,encodeFunction){
3076  if(!text)return '';
3077  //alert('iconv: ['+toCode+']\n'+text.slice(0,200));
3078  if(/utf-?(8|16)/i.test(toCode))
3079   return HTMLToUnicode(text,1);
3080  if(_.open_file(0,toCode||simpleFileDformat)!==0)
3081   return text;
3082  //AdoStream.Type=AdoEnums.adTypeText;
3083  if(!encodeFunction)encodeFunction=toHTML;
3084  //iconvError=[];
3085 
3086  var charToSet,i=0,t='';
3087  for(;i<text.length;i++)try{
3088   charToSet=text.charAt(i);
3089   if(charToSet.charCodeAt(0)<256){t+=charToSet;continue;}	//	對於過小的,直接匯入。
3090   AdoStream.Position=0;
3091   AdoStream.WriteText(charToSet);
3092   AdoStream.Position=0;
3093   t+=charToSet==AdoStream.ReadText(AdoEnums.adReadAll)?charToSet:encodeFunction(charToSet);
3094  }catch(e){
3095   //iconvError.push(e.description);
3096   t+=encodeFunction(charToSet);
3097  }
3098 
3099  try{AdoStream.Close();}catch(e){}
3100  return t;
3101 }
3102 
3103 
3104 
3105 //---------------------------------------------------
3106 
3107 
3108 /*
3109 var driverProperty,folderProperty,fileProperty;
3110 setObjValue('driverProperty','AvailableSpace,DriveLetter,DriveType,FileSystem,FreeSpace,IsReady,Path,RootFolder,SerialNumber,ShareName,TotalSize,VolumeName',1,setObjValueFlag.array);
3111 setObjValue('folderProperty','Attributes,DateCreated,DateLastAccessed,DateLastModified,Drive,Name,ParentFolder,Path,ShortName,ShortPath,Size,Type,Files,IsRootFolder,SubFolders',1,setObjValueFlag.array);//Files起為Folder property
3112 fileProperty=folderProperty.slice(0,12);//folderProperty.sort();
3113 */
3114 
3115 
3116 //var kkk='';_.traverse_file_system(function(fileItem,itemType){kkk+=(itemType==_.traverse_file_system.f.driver?fileItem.DriveLetter+':('+fileItem.VolumeName+')':fileItem.Name+(itemType==_.traverse_file_system.f.folder?path_separator:''))+'\n';},'I:\\Documents and Settings\\kanashimi\\My Documents\\kanashimi\\www\\cgi-bin\\program');_.write_to_file('tmp.txt',kkk,'unicode');
3117 /*
3118 
3119 _.traverse_file_system(FS_function_array)	省略path會當作所有Drives
3120 _.traverse_file_system(FS_function_array,'c:')	c:→c:\→sub dir of c:\
3121 _.traverse_file_system(FS_function_array,'c:\\')	c:\→sub dir of c:\
3122 _.traverse_file_system(FS_function_array,'c:\\cc')	c:\cc,cc為dir→sub dir of c:\cc\
3123 _.traverse_file_system(FS_function_array,'c:\\cc\\')	c:\cc\→sub dir of c:\cc\
3124 _.traverse_file_system(FS_function_array,['c:\\cc\\','d:\\dd'])	c:\cc\→sub dir of c:\cc\→d:\dd→sub dir of d:\dd
3125 _.traverse_file_system([,folderFunction],'.');
3126 
3127 
3128 _.traverse_file_system([,folderFunction],basePath);
3129 function folderFunction(folderItem){
3130  t=folderItem.Path.slice(same_length(basePath,folderItem.Path));
3131  //if(t==folderItem.Name)	//	僅單層subdir次目錄
3132  //if(t.indexOf(path_separator)==t.lastIndexOf(path_separator))	//	僅單層及次層subdir次目錄
3133  if(t.replace(new RegExp('[^'+path_separator_RegExp+']','g'),'').length<3)	//	僅3層subdir以下
3134   ;
3135 }
3136 
3137 
3138 //	itemType=0:file/1:folder/2:driver
3139 function fsoFunction(fsi,itemType){if(!itemType){}}
3140 function fileFunction(fileItem){}
3141 function folderFunction(folderItem){}
3142 function driverFunction(driverItem){}
3143 
3144 filter:
3145 	file_filter	僅單一 filter 時預設當作 file_filter, should has NO global flag.
3146 	[file_filter,folder_filter]
3147 file_filter	篩選檔案, should has NO global flag.
3148 folder_filter	篩選資料夾, should has NO global flag.
3149 
3150 
3151 tip:
3152 使用相對路徑,如'..'開頭時需用getFP()調整過。
3153 用folder.Size==0可判別是否為empty folder
3154 
3155 TODO:
3156 限定traverse深度幾層,sort=8,preOrder=0,widthFirst=0,postOrder=16,depthFirst=16
3157 */
3158 //_.traverse_file_system.stop=false;
3159 
3160 //_.traverse_file_system[generateCode.dLK]='initWScriptObj';
3161 _.
3162 /**
3163  * 巡覽 file system 的公用函數
3164  * @param FS_function_array	file system handle function array
3165  * @param path	target path
3166  * @param filter	filter
3167  * @param flag	see <a href="#.traverse_file_system.f">flag</a>
3168  * @return
3169  * @memberOf	CeL.IO.Windows.file
3170  * @see	<a href="http://msdn.microsoft.com/library/en-us/script56/html/0fa93e5b-b657-408d-9dd3-a43846037a0e.asp">FileSystemObject</a>
3171  */
3172 traverse_file_system = function(FS_function_array, path, filter, flag){
3173 	var _s = arguments.callee, _f = _s.f;
3174 
3175 	// initial
3176 	// 預設 flag
3177 	// if(isNaN(flag))flag=_f.traverse;
3178 
3179 	//library_namespace.log('traverse_file_system:\n[' + path + ']');
3180 	if (FS_function_array === _f.get_object)
3181 		// or FS_function_array=[,,]:	可以使用 Array 常值中的空白元素來建立零星稀疏的陣列。
3182 		FS_function_array = new Array(_f.func_length),
3183 		flag = _f.get_object;
3184 	else {
3185 		/*
3186 		if (FS_function_array instanceof Array && FS_function_array.length == 1)
3187 			FS_function_array = FS_function_array[0];
3188 		*/
3189 		if (typeof FS_function_array === 'function') {
3190 			var i = FS_function_array;
3191 			FS_function_array = [ i, i, i ];
3192 		}
3193 	}
3194 	//library_namespace.log('traverse_file_system: fso:\n[' + fso + ']');
3195 	if (typeof fso !== 'object' || !(FS_function_array instanceof Array)
3196 			|| !FS_function_array.length)
3197 		return;
3198 	//library_namespace.log('traverse_file_system: FS_function_array:\n[' + FS_function_array + ']');
3199 	if (!filter)
3200 		filter = [];
3201 	else if (filter instanceof RegExp)
3202 		// filter=[filter,filter]; 通常我們輸入的只會指定 file filter
3203 		filter = [ filter, ];
3204 	else if (typeof filter !== 'object')
3205 		filter = [ filter, ];
3206 
3207 	//library_namespace.log('traverse_file_system: FS_function_array:\n[' + FS_function_array + ']');
3208 	var item, iType, fc, i, traverse = !(flag & _f.no_traverse), objBuf = [], typeBuf = [], folder_filter = filter[1], testFilter = function(
3209 			f) {
3210 		try {
3211 			// f instanceof RegExp
3212 			f.test('');
3213 		}
3214 		catch (e) {
3215 			// throw new Error(e.number,'traverse_file_system: 錯誤的 filter:\n'+f+'\n'+e.description);
3216 			e.description = 'traverse_file_system: 錯誤的 filter:\n' + f + '\n'
3217 			+ e.description;
3218 			throw e;
3219 		}
3220 	};
3221 	if (filter = filter[0])
3222 		if (typeof filter === 'string')
3223 			filter = new RegExp(filter);
3224 		else
3225 			testFilter(filter);
3226 	if (folder_filter)
3227 		if (typeof folder_filter === 'string')
3228 			folder_filter = new RegExp(folder_filter);
3229 		else
3230 			testFilter(folder_filter);
3231 	// if(flag!=_f.get_object)alert(filter+'\n'+folder_filter);
3232 	// 至此 filter 代表 file_filter, vs. folder_filter
3233 
3234 
3235 	// 轉換輸入之各項成fso object
3236 	if (!path) { // 取得各個driver code
3237 		if (flag === _f.get_object)
3238 			return;
3239 		for ( var drivers = new Enumerator(fso.Drives); !drivers.atEnd(); drivers
3240 		.moveNext())
3241 			objBuf.push(drivers.item()), typeBuf
3242 			.push(_f.driver);
3243 		objBuf.reverse(), typeBuf.reverse();
3244 	} else if (typeof path === 'object')
3245 		if (path.length) {
3246 			for (i = 0; i < path.length; i++)
3247 				if (item = _s(_f.get_object,
3248 						'' + path[i], filter, flag))
3249 					objBuf.push(item[0]), typeBuf.push(item[1]);
3250 		} else {
3251 			item = typeof path.IsReady !== 'undefined' ? _f.driver
3252 					: typeof path.IsRootFolder !== 'undefined' ? _f.folder
3253 							: typeof path.Path !== 'undefined' ? _f.file
3254 									: _f.NULL;
3255 			if (_f.NULL != -1)
3256 				objBuf.push(path), typeBuf.push(item);
3257 		}
3258 	else {
3259 		i = true; // fault
3260 		if (i)
3261 			try {
3262 				objBuf.push(fso.GetFolder(path)), typeBuf
3263 				.push(_f.folder), i = false;
3264 			} catch (e) {
3265 			}// fso.FolderExists()
3266 			if (i)
3267 				try {
3268 					objBuf.push(fso.GetFile(path)), typeBuf
3269 					.push(_f.file), i = false;
3270 				} catch (e) {
3271 				}// fso.FileExists()
3272 				if (i && path == fso.GetDriveName(path))
3273 					try {
3274 						objBuf.push(fso.GetDrive(path)), typeBuf
3275 						.push(_f.driver), i = false;
3276 					} catch (e) {
3277 					}
3278 	}
3279 	if (flag == _f.get_object)
3280 		return objBuf[0] ? [ objBuf[0], typeBuf[0] ] : 0;
3281 
3282 		// FS_function_array.length=_f.func_length;
3283 		for (i = 0; i < _f.func_length; i++)
3284 			// 可以安排僅對folder或是file作用之function
3285 			if (typeof FS_function_array[i] !== 'function')
3286 				FS_function_array[i] = function() {};
3287 			//alert(objBuf.length+','+typeBuf.length+'\n'+typeBuf);
3288 			// main loop
3289 			while (!_s.stop && objBuf.length)
3290 				if (item = objBuf.pop()) // fsoFunction執行途中可能將此項目刪除
3291 					switch (iType = typeBuf.pop()) {
3292 					case _f.folder:
3293 						if (!folder_filter || folder_filter.test(item.Name))
3294 							FS_function_array[iType](item, iType);
3295 						// if(traverse||traverse!==0){
3296 						// if(!traverse)traverse=0; // 加上次一層: 會連這次一層之檔案都加上去。
3297 						if (traverse)
3298 							for (fc = new Enumerator(item.SubFolders); !fc.atEnd(); fc
3299 							.moveNext())
3300 								if (i = fc.item(), !folder_filter
3301 										|| folder_filter.test(i.Name))
3302 									objBuf.push(i), typeBuf
3303 									.push(_f.folder);
3304 						// }
3305 						// try 以防item已經被刪除
3306 						try {
3307 							fc = new Enumerator(item.Files);
3308 						} catch (e) {
3309 							fc = 0;
3310 						}
3311 						if (fc) {
3312 							// for(;!fc.atEnd();fc.moveNext())if(i=fc.item(),!filter||filter.test(i.Name))FS_function_array[_f.file](i,_f.file);
3313 							// 因為檔案可能因改名等改變順序,因此用.moveNext()的方法可能有些重複,有些漏掉未處理。
3314 							for (item = []; !fc.atEnd(); fc.moveNext())
3315 								item.push(fc.item());
3316 							for (i in item)
3317 								if (i = item[i], !filter || filter.test(i.Name))
3318 									FS_function_array[_f.file](i,
3319 											_f.file);
3320 						}
3321 						break;
3322 					case _f.file:
3323 						if (!filter || filter.test(item.Name))
3324 							FS_function_array[iType](item, iType);
3325 						break;
3326 					case _f.driver:
3327 						if (!item.IsReady)
3328 							break;
3329 						FS_function_array[iType](item, iType);
3330 						if (traverse)
3331 							objBuf.push(item.RootFolder), typeBuf
3332 							.push(_f.folder);
3333 						// break;
3334 						//default:break;
3335 					}
3336 
3337 };
3338 
3339 
3340 //setObjValue('traverse_file_system.f','get_object=-2,NULL=-1,file,folder,driver,func_length,traverse=0,no_traverse=4',1);//,sort=8,preOrder=0,widthFirst=0,postOrder=16,depthFirst=16
3341 _.
3342 /**
3343  * <a href="#.traverse_file_system">traverse_file_system</a> 的 flag enumeration
3344  * @memberOf	CeL.IO.Windows.file
3345  * @constant
3346  */
3347 traverse_file_system.f = {
3348 		/**
3349 		 * return object
3350 		 * @memberOf	CeL.IO.Windows.file
3351 		 */
3352 		get_object : -2,
3353 		/**
3354 		 * null flag
3355 		 * @private
3356 		 * @memberOf	CeL.IO.Windows.file
3357 		 */
3358 		NULL : -1,
3359 		/**
3360 		 * 用於指示 file
3361 		 * @private
3362 		 * @memberOf	CeL.IO.Windows.file
3363 		 */
3364 		file : 0,
3365 		/**
3366 		 * 用於指示 folder
3367 		 * @private
3368 		 * @memberOf	CeL.IO.Windows.file
3369 		 */
3370 		folder : 1,
3371 		/**
3372 		 * 用於指示 driver
3373 		 * @private
3374 		 * @memberOf	CeL.IO.Windows.file
3375 		 */
3376 		driver : 2,
3377 		/**
3378 		 * handle function 應有的長度
3379 		 * @private
3380 		 * @memberOf	CeL.IO.Windows.file
3381 		 */
3382 		func_length : 3,
3383 		/**
3384 		 * 深入下層子目錄及檔案
3385 		 * @memberOf	CeL.IO.Windows.file
3386 		 */
3387 		traverse : 0,
3388 		/**
3389 		 * 不深入下層子目錄及檔案
3390 		 * @memberOf	CeL.IO.Windows.file
3391 		 */
3392 		no_traverse : 4
3393 };
3394 
3395 
3396 return _;
3397 };
3398 
3399 //===================================================
3400 
3401 CeL.setup_module(module_name, code_for_including);
3402 
3403 };
3404 
3405 
3406 //WScript.Echo(this.Class);
3407 
3408 //	若 library base 尚未 load 或本 module 已經 loaded 則跳過。
3409 if (typeof CeL === 'function'){
3410 
3411 /**
3412  * 本 module 之 name(id),<span style="text-decoration:line-through;">不設定時會從呼叫時之 path 取得</span>。
3413  * @type	String
3414  * @constant
3415  * @inner
3416  * @ignore
3417  */
3418 var module_name = 'code.log';
3419 
3420 //var do_before_including = function() {};
3421 
3422 /*	to include:
3423 	include code_for_including
3424 	<div id="debug_panel"></div>
3425 	var SL=new Debug.log('debug_panel'),sl=function(){SL.log.apply(SL,arguments);},err=function(){SL.err.apply(SL,arguments);},warn=function(){SL.warn.apply(SL,arguments);};
3426 
3427 	http://www.comsharp.com/GetKnowledge/zh-CN/TeamBlogTimothyPage_K742.aspx
3428 
3429 	if possible, use Firebug Lite instead.
3430 	http://benalman.com/projects/javascript-debug-console-log/
3431 */
3432 
3433 
3434 //	===================================================
3435 /**
3436  * 若欲 include 整個 module 時,需囊括之 code。通常即 CeL。
3437  * @type	Function
3438  * @param	{Function} library_namespace	namespace of library
3439  * @param	load_arguments	呼叫時之 argument(s)
3440  * @return
3441  * @constant
3442  * @inner
3443  * @ignore
3444  */
3445 var code_for_including = function(library_namespace, load_arguments) {
3446 //WScript.Echo(this);
3447 
3448 var
3449 
3450 //	class private	-----------------------------------
3451 
3452 //	class name, 需要用到這個都不是好方法。
3453 //cn='Debug.log',
3454 
3455 /**
3456  * private storage pool
3457  * @ignore
3458  */
3459 p=[],
3460 
3461 /**
3462  * default write/show log function
3463  * @ignore
3464  * @param	{string} id	element id
3465  */
3466 w = function(id) {
3467 	var o, m, c, _p = p[id], _t = _p.instance,
3468 	/**
3469 	 * buffer
3470 	 */
3471 	b = _p.buf,
3472 	B = _p.board, F = _p.do_function, level;
3473 
3474 	if (_p.clean)
3475 		_t.clear(), _p.clean = 0;
3476 
3477 	if (!B && !F)
3478 		return;
3479 
3480 	while (b.length) {
3481 		m = b.shift(); // 預防 MP 時重複顯示
3482 		if (F)
3483 			F(m);
3484 
3485 		c = 0;
3486 		if ((m instanceof Object) && !(m instanceof Array))
3487 			c = m.l in _t.className_set ? _t.className_set[m.l] : 0,
3488 					m = m.m;
3489 		_p.lbuf.push(m);
3490 
3491 		if (B) { // && typeof document==='object'
3492 			o = _p.instance.log_tag;
3493 			if (o) {
3494 				o = document.createElement(o);
3495 				if (c)
3496 					o.className = c;
3497 				o.innerHTML = typeof m === 'string' ?
3498 						// for character (null)
3499 						m.replace(/\x00/g,
3500 						'<span class="control_character">\\x00</span>')
3501 						: m;
3502 			} else
3503 				o = document.createTextNode(m);
3504 			B.appendChild(o);
3505 		}
3506 	}
3507 
3508 	//if(_t.auto_hide)B.style.display=B.innerHTML?'block':'none';
3509 	if (B && _t.auto_scroll)
3510 		with (B)
3511 			scrollTop = scrollHeight - clientHeight;
3512 },
3513 
3514 
3515 /**
3516  * save log
3517  * @ignore
3518  * @param	m	message
3519  * @param	{string} id	element id
3520  * @param	force	force to clean the message area
3521  */
3522 s = function(m, id, force) {
3523 	var _p = p[id], _t = _p.instance, f = _p.logF, s = _t.save_log;
3524 	if (!s || typeof s == 'function' && !s(m, l))
3525 		return;
3526 
3527 	if (m)
3528 		_p.sbuf
3529 				.push(m = (_t.save_date && typeof gDate == 'function' ? _t.save_new_line
3530 						+ gDate() + _t.save_new_line
3531 						: '')
3532 						+ m);
3533 
3534 	if (force || _t.flush || _p.sbufL > _t.save_limit)
3535 		try {
3536 			if (f
3537 					|| _t.log_file
3538 					&& (f = _p.logF = fso.OpenTextFile(_t.log_file,
3539 							8/* ForAppending */, true/* create */,
3540 							_t.log_encoding)))
3541 				f.Write(_p.sbuf.join(_t.save_new_line)), _p.sbuf = [],
3542 						_p.sbufL = 0, _t.error_message = 0;
3543 		} catch (e) {
3544 			_t.error_message = e;// err(e);
3545 		}
3546 	else if (m)
3547 		_p.sbufL += m.length;
3548 },
3549 
3550 //	instance constructor	---------------------------
3551 //	(document object)
3552 /*
3553 
3554 _=this
3555 
3556 
3557 TODO:
3558 set class in each input
3559 input array
3560 show file path & directory functional	可從 FSO operation.hta 移植
3561 增加 group 以便在多次輸入時亦可 trigger 或排版
3562 
3563 count
3564 c.f.: GLog
3565 
3566 dependency:
3567 
3568 */
3569 /**
3570  * initial a log tool's instance/object
3571  * @class	log function
3572  * @see	usage: <a href="#.extend">CeL.code.log.extend</a>
3573  * @since	2008/8/20 23:9:48
3574  * @requires	gDate(),NewLine,fso
3575 
3576  * @constructor
3577  * @name	CeL.code.log
3578  * @param	{String, object HTMLElement} obj	message area element or id
3579  */
3580 _ = function(obj) {
3581 	// Initial instance object. You can set it yourself.
3582 	/**
3583 	 * 表示是 warning/error message 之 className
3584 	 * @name	CeL.code.log.prototype.className_set
3585 	 */
3586 	this.className_set = {
3587 			/**
3588 			 * @description	當呼叫 {@link CeL.code.log.prototype.warn} 時使用的 className
3589 			 * @name	CeL.code.log.prototype.className_set.warn
3590 			 */
3591 			warn : 'debug_warn',
3592 			/**
3593 			 * @description	當呼叫 {@link CeL.code.log.prototype.err} 時使用的 className
3594 			 * @name	CeL.code.log.prototype.className_set.err
3595 			 */
3596 			err : 'debug_err'
3597 	};
3598 
3599 	this.id = p.length;
3600 	p.push( {
3601 		instance : this,
3602 		/**
3603 		 * write buffer
3604 		 */
3605 		buf : [],
3606 		/**
3607 		 * save buffer when we need to save the messages
3608 		 */
3609 		sbuf : [],
3610 		/**
3611 		 * length of save buffer
3612 		 */
3613 		sbufL : 0,
3614 		/**
3615 		 * now logged buffer
3616 		 */
3617 		lbuf : []
3618 	}); 
3619 	this.set_board(obj);
3620 };
3621 
3622 
3623 
3624 //	class public interface	---------------------------
3625 
3626 _.
3627 /**
3628  * do the log action
3629  * @memberOf	CeL.code.log
3630  * @private
3631  */
3632 do_log = function(id) {
3633 /*	這段應該只在 module namespace 重複定義時才會發生
3634  var I=p[id];
3635  if(!I){
3636   alert('.do_log: not exist: ['+id+']');
3637   return;
3638  }
3639  I=I.instance;
3640 */
3641  var I=p[id].instance;
3642  if(I.do_log)I.do_log();
3643 };
3644 
3645 
3646 _.
3647 /**
3648  * new extend instance
3649  * @param	{String, object HTMLElement} [obj]	message area element or id
3650  * @return	{Array} [ log function, warning function, error function, instance of this module ]
3651  * @example
3652  * //	status logger
3653  * var SL=new CeL.code.log('log'),sl=SL[1],warn=SL[2],err=SL[3];
3654  * sl(msg);
3655  * sl(msg,clear);
3656  * @memberOf	CeL.code.log
3657  * @since	2009/8/24 20:15:31
3658  */
3659 extend = function(obj) {
3660 	//CeL.Log=new CeL.code.log(function(m){var F=typeof JSalert==='function'?JSalert:typeof alert==='function'?alert:WScript.Echo;F(typeof m==='object'?'['+m.l+'] '+m.m:m);});
3661 	/**
3662 	 * new instance
3663 	 * @type	CeL.code.log
3664 	 * @inner
3665 	 * @ignore
3666 	 */
3667 	var o = new _(
3668 			obj ||
3669 			//	預設以訊息框代替
3670 			new Function('m',
3671 					(typeof JSalert === 'function' ? 'JSalert':
3672 						typeof WScript === 'object' ? 'WScript.Echo':
3673 					'alert') +
3674 			"(typeof m==='object'?'['+m.l+'] '+m.m:m);"));
3675 
3676 	return [ o, function() {
3677 		o.log.apply(o, arguments);
3678 	}, function() {
3679 		o.warn.apply(o, arguments);
3680 	}, function() {
3681 		o.err.apply(o, arguments);
3682 	} ];
3683 
3684 };
3685 
3686 
3687 
3688 /*
3689 _.option_open=function(p){
3690 
3691 };
3692 
3693 _.option_file=function(p){
3694 };
3695 
3696 _.option_folder=function(p){
3697 };
3698 */
3699 
3700 //	class constructor	---------------------------
3701 
3702 
3703 _.prototype={
3704 
3705 //	instance public interface	-------------------
3706 
3707 /**
3708  * 當執行寫檔案或任何錯誤發生時之錯誤訊息。<br/>
3709  * while error occurred.. should read only
3710  * @name	CeL.code.log.prototype.error_message
3711  */
3712 error_message : '',
3713 
3714 /**
3715  * 超過這長度才 save。<=0 表示 autoflash,非數字則不紀錄。
3716  * @name	CeL.code.log.prototype.save_limit
3717  * @type	Number
3718  */
3719 save_limit : 4000,
3720 
3721 /**
3722  * 在 log 結束時執行,相當於 VB 中 DoEvent() 或 。
3723  * @name	CeL.code.log.prototype.do_event
3724  */
3725 do_event : library_namespace.DoNoting || null,
3726 
3727 
3728 /**
3729  * log 時使用之 tagName, 可用 div / span 等。若不設定會用 document.createTextNode
3730  * @name	CeL.code.log.prototype.log_tag
3731  */
3732 log_tag : 'div',
3733 
3734 
3735 /**
3736  * boolean or function(message, log level) return save or not
3737  * @name	CeL.code.log.prototype.save_log
3738  * @type	Boolean
3739  */
3740 save_log:false,
3741 /**
3742  * save log to this file path
3743  * @name	CeL.code.log.prototype.log_file
3744  * @type	Boolean
3745  */
3746 log_file:false,
3747 /**
3748  * auto save log. 若未設定,記得在 onunload 時 .save()
3749  * @name	CeL.code.log.prototype.flush
3750  * @type	Boolean
3751  */
3752 flush:false,
3753 /**
3754  * 在 save log 時 add date
3755  * @name	CeL.code.log.prototype.save_date
3756  * @type	Boolean
3757  */
3758 save_date:true,
3759 /**
3760  * 在 save log 時的換行
3761  * @name	CeL.code.log.prototype.save_new_line
3762  * @type	string
3763  */
3764 save_new_line : library_namespace.env.new_line || '\r\n',
3765 /**
3766  * 在 save log 時的 encoding
3767  * @name	CeL.code.log.prototype.log_encoding
3768  */
3769 log_encoding:-1,//TristateTrue
3770 
3771 
3772 /**
3773  * 自動捲動
3774  * @name	CeL.code.log.prototype.auto_scroll
3775  * @type	Boolean
3776  */
3777 auto_scroll:true,
3778 /**
3779  * 沒有內容時自動隱藏
3780  * @deprecated	TODO
3781  * @name	CeL.code.log.prototype.auto_hide
3782  * @type	Boolean
3783  */
3784 auto_hide:false,
3785 
3786 /**
3787  * 等待多久才顯示 log。若為 0 則直接顯示。<br/>
3788  * (WScript 沒有 setTimeout)
3789  * @name	CeL.code.log.prototype.interval
3790  */
3791 interval : typeof setTimeout === 'undefined' ? 0 : 1,
3792 
3793 /**
3794  * log function (no delay)
3795  * @name	CeL.code.log.prototype.do_log
3796  */
3797 do_log:function(level){
3798  //if(p[this.id].th)clearTimeout(p[this.id].th);
3799  p[this.id].th=0;	//	reset timeout handle
3800  w(this.id);
3801 },
3802 
3803 /**
3804  * class 預設作 log 之 function, (String message, clean)
3805  * @name	CeL.code.log.prototype.
3806  */
3807 log:function(m,clean,level){
3808  var t=this,_p=p[t.id];
3809  //var msg_head=(arguments.callee.caller+'').match(/function\s([^\(]+)/);if(msg_head)msg_head=msg_head[1]+' ';
3810  s(m,t.id,level);
3811 
3812  if(level)
3813   m={m:m,l:level};
3814 
3815  if(clean)_p.clean=1,_p.buf=[m];	//	clean log next time
3816  else _p.buf.push(m);
3817  //window.status=m;
3818 
3819  if(!t.interval)
3820   t.do_log();
3821  else if(!_p.th)
3822   if(typeof setTimeout==='undefined')
3823    t.interval=0,t.do_log();
3824   else
3825    //_p.th=setTimeout(cn+'.do_log('+t.id+');',t.interval);
3826    _p.th=setTimeout(function(){_.do_log(t.id);},t.interval);
3827 
3828  if(t.do_event)
3829   t.do_event();
3830 },
3831 
3832 /*
3833 TODO:
3834 other methods: INFO,DEBUG,WARNING,ERROR,FATAL,UNKNOWN
3835 */
3836 
3837 /**
3838  * save message
3839  * @name	CeL.code.log.prototype.save
3840  */
3841 save:function(){
3842  s('',this.id,1/*force*/);
3843 },
3844 
3845 //	** important ** 這邊不能作 object 之 initialization,否則因為 object 只會 copy reference,因此 new 時東西會一樣。initialization 得在 _() 中作!
3846 //className_set:{},
3847 
3848 /**
3849  * log a warning
3850  * @name	CeL.code.log.prototype.warn
3851  */
3852 warn:function(m,clean){
3853  this.log(m,clean,'warn');
3854 },
3855 
3856 /**
3857  * 表示是錯誤 error message
3858  * @name	CeL.code.log.prototype.error_prefix
3859  */
3860 error_prefix:'<em>!! Error !!</em> ',
3861 /**
3862  * deal with error object
3863  * @name	CeL.code.log.prototype.err
3864  */
3865 err:function(e,clean){
3866  //	from popErr()
3867  var NL=this.save_new_line,T=typeof e,m=e instanceof Error?'Error '+(e.number&0xFFFF)+(e.name?' ['+e.name+']':'')
3868 	+' (facility code '+(e.number>>16&0x1FFF)+'):'+NL+e.description.replace(/\r?\n/g,'<br/>')
3869 	+(!e.message||e.message==e.description?'':NL+NL+e.message.replace(/\r?\n/g,'<br/>')):!e||T=='string'?e:'('+T+')'+e;
3870 
3871  this.log(this.error_prefix+m,clean,'err');
3872 },
3873 
3874 
3875 /**
3876  * 設定寫入到哪<br/>set log board for each instance (document object)
3877  * @name	CeL.code.log.prototype.set_board
3878  */
3879 set_board:function(o){
3880  var _p=p[this.id];
3881  if(o)
3882   if(typeof o==='function')
3883    _p.do_function=o;
3884 
3885   else if(typeof o!=='object')
3886    if(o=typeof document==='object'?document.getElementById(o):0)
3887     _p.board=o;
3888 
3889  return _p.board;
3890 },
3891 
3892 /**
3893  * 獲取當前 buffer 中的 log
3894  * @name	CeL.code.log.prototype.get_log
3895  */
3896 get_log:function(){
3897  return p[this.id].lbuf;
3898 },
3899 
3900 /**
3901  * show/hide log board
3902  * @name	CeL.code.log.prototype.trigger
3903  */
3904 trigger:function(s){
3905  var _s=p[this.id].board.style;
3906  if(typeof s==='undefined')
3907   s=_s.display=='none';
3908  _s.display=s?'block':'none';
3909 },
3910 
3911 /**
3912  * clear log board
3913  * @name	CeL.code.log.prototype.clear_board
3914  */
3915 clear_board:function(b){
3916  b.innerHTML='';
3917 },
3918 
3919 /**
3920  * 清除全部訊息 clear message
3921  * @name	CeL.code.log.prototype.clear
3922  */
3923 clear:function(){
3924  var _p=p[this.id];
3925  if(_p.board)this.clear_board(_p.board);
3926  _p.lbuf=[];
3927 }
3928 
3929 };
3930 
3931 
3932 /**
3933  * 不 extend 的 member
3934  * @ignore
3935  */
3936 _.no_extend = '*';
3937 
3938 return _;
3939 };
3940 
3941 //	===================================================
3942 
3943 /**
3944  * modele namespace
3945  * @type	CeL.code.log
3946  * @inner
3947  * @ignore
3948  */
3949 var ns = CeL.setup_module(module_name, code_for_including);
3950 
3951 //WScript.Echo(n.extend);
3952 
3953 //code_for_including[generateCode.dLK]='*var Debug={log:code_for_including()};';
3954 
3955 
3956 //	為本 library 用
3957 if (!CeL.Log) {
3958 	var o = ns.extend();
3959 
3960 	// override CeL.log
3961 	CeL.Log=o[0];
3962 
3963 	CeL.log = o[1];
3964 	CeL.warn = o[2];
3965 	CeL.err = o[3];
3966 }
3967 
3968 }
3969 
3970