(function(__global){

	/**
	 * 核心类包定义
	 * 在这里不直接定义为 WebAppEnvironment 的成员，主要目的是为了解决在当前的命名
	 * 空间内不可以直接通过 alz 引用脚本类的问题。
	 */
	var webappEnv = null;  //Web应用运行环境
	var alz = {};          //根包对象

/**
 * class WebAppEnvironment
 * WebIm 运行环境类
 */
function WebAppEnvironment(){this._init.apply(this, arguments);}
(function(){
	/**
	 * 构造函数
	 */
	this._init = function(){
		this.debug = true;
		this._version = "";        //WEBIM系统的版本号
		this._configVersion = "";  //配置文件的版本号，所有js和css文件都是用该配置版本号加载
		this._scriptVersion = "";  //脚本的版本号
		this._suffix = ".js";      //脚本的后缀名

		this._window = __global;
		this._doc = this._window.document;

		this.pathRoot  = "/webim/";  //WebIM系统的根路径
		this.pathRes   = this.pathRoot + "src/";      //图片资源
		this.pathSwf   = this.pathRoot + "src/swf/";  //swf文件
		this.pathCss   = this.pathRoot + "css/";      //CSS样式表
		//this.path    = this.pathRoot + "script/";   //脚本存储路径
		this.classpath = this.pathRoot + "classes/";  //脚本类路径
		this.pathlib   = this.pathRoot + "lib/";      //脚本库路径
		this.pathApp   = "";  //当前应用的路径

		this.alz = alz;  //在此将根类绑定为类的成员变量
		this._libs = {};
		this._classes = {};
		this._packages = {};

		this._ajax = null;  //异步调用引擎，所有的Web应用的数据交互都使用该引擎工作
											//如果能够跨域的话，则每个域一个引擎更好一些，不过已经不可能了
		this._apps = [];

		this._runMode = 0;
		this._domScript = null;  //导入本初始化文件所用的 script 对象
		this.domManager = null;
		this.guiManager = null;
		this._currentUniqueId = 1;
		this._locklist = {};
		this._wait = null;    //等待提示框
		this._logWin = null;  //日志窗口
		this._vbsCode = "Function VBS_bytes2BStr(vIn)"
			+ "\n  Dim strReturn, i, ThisCharCode, NextCharCode"
			+ "\n  strReturn = \"\""
			+ "\n  For i = 1 To LenB(vIn)"
			+ "\n    ThisCharCode = AscB(MidB(vIn, i, 1))"
			+ "\n    If ThisCharCode < &H80 Then"
			+ "\n      strReturn = strReturn & Chr(ThisCharCode)"
			+ "\n    Else"
			+ "\n      NextCharCode = AscB(MidB(vIn, i + 1, 1))"
			+ "\n      strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))"
			+ "\n      i = i + 1"
			+ "\n    End If"
			+ "\n  Next"
			+ "\n  VBS_bytes2BStr = strReturn"
			+ "\nEnd Function";
		//this.bEnabled = true;
		//this.connectedEvents = {};
	};
	/**
	 * 环境初始化代码
	 */
	this.init = function(){
		this.alz.core      = {};  // package alz.core
		this.alz.miniapp   = {};  // package alz.miniapp
		this.alz.im        = {};  // package alz.im
		this.alz.im.core   = {};  // package alz.im.core
		this.alz.im.wui    = {};  // package alz.im.wui
		this.alz.webim     = {};  // package alz.webim
		this.alz.lang      = {};  // package alz.lang
		this.alz.ui        = {};  // package alz.ui
		this.alz.ui.dialog = {};  // package alz.ui.dialog
		this.alz.ui.drag   = {};  // package alz.ui.drag
		this.alz.util      = {};  // package alz.util

		this._checkBrowser();
		this._checkEnv();
		this._ajax = new AjaxEngine(this);  //尽可能早的创建完成，供后面得初始化过程使用
		this.loadScriptFile1(this.pathlib + "config.js?" + new Date().getTime(), true);  //加载配置文件，后面追加当前时间，保证每次都重新加载
		this._configVersion = window.__config.curVersion;
		this._bindEvents();
	};
	this.dispose = function(){
		if(this._wait){
			this._wait.dispose();
			this._wait = null;
		}
		this._domScript = null;
		this._ajax.dispose();
		this._ajax = null;
	};

	/**
	 * getter and setter function
	 */
	this.getVersion = function(){return this._version;};
	this.setVersion = function(v){this._version = v;};
	this.setScriptVersion = function(v){this._scriptVersion = v;};
	this.setSuffix = function(v){this._suffix = v;};

	/**
	 * private function for environment check
	 */
	this._checkBrowser = function(){
		//下面的环境检测代码和GUIManager中的一样
		this.isSafari = this._isBrowser("Safari");
		this.isIE = this._isBrowser("MSIE");
		this.isNS = this._isBrowser("Netscape6/");
		this.isGecko = this._isBrowser("Gecko");
	};
	this._checkEnv = function(){
		var ol = this._doc.getElementsByTagName("script");
		this._domScript = ol[ol.length - 1];
		this.debug = this._domScript.getAttribute("debug") == "true";
		var rm = this._domScript.getAttribute("runmode");
		if(rm) this._runMode = parseInt(rm);
		//路径解析
		var sPathRoot = this._domScript.src.replace(/lib(\/|\\)__init__\.js.*$/, "");
		this._setPathRoot(sPathRoot);
		var resServer = this._domScript.getAttribute("resServer");
		if(resServer){
			this.pathRes = resServer + "webim/src/";
			this.pathCss = resServer + "webim/css/";
		}
		var arr = (/^(file:\/\/\/|http:\/\/)(.+)(\\|\/)([^\\\/]+)?$/ig).exec(this._window.location);
		if(arr){
			if(arr[1] == "file:///")
				this.pathApp = arr[2] + arr[3];
			else{
				//this.pathApp = arr[1] + arr[2] + arr[3];
				//if(this.pathApp.substr(this.pathApp.length - 5) == ".com/")
					this.pathApp = sPathRoot;
			}
		}else{
			this._window.alert("[ERROR]未能成功解析当前Web应用的路径");
		}
	};
	/**
	 * 绑定全局事件
	 */
	this._bindEvents = function(){
		var _this = this;
		function __DOMContentLoaded(){
			if(_this.isIE && _this._doc.readyState != "complete") return;
			_this.onContentLoaded();
		}
		function __load(ev){return _this.onload(ev || window.event);}
		function __resize(ev){return _this.onresize(ev || window.event);/*return _this._windowMgr.redraw();*/}
		function __beforeunload(ev){return _this.onbeforeunload(ev || window.event);}
		function __unload(ev){
			if(_this.isIE){  //IE
				_this._doc.detachEvent("onreadystatechange", __DOMContentLoaded);
				_this._window.detachEvent("onload", __load);
				_this._window.detachEvent("onresize", __resize);
				_this._window.detachEvent("onbeforeunload", __beforeunload);
				_this._window.detachEvent("onunload", __unload);
			}else{  //FF
				_this._doc.addEventListener("DOMContentLoaded", __DOMContentLoaded, false);
				_this._window.removeEventListener("load", __load, false);
				_this._window.removeEventListener("resize", __resize, false);
				_this._window.removeEventListener("beforeunload", __beforeunload, false);
				_this._window.removeEventListener("unload", __unload, false);
			}
			_this.onunload(ev || window.event);
			if(_this._window.application) _this._window.application = null;
			if(_this._window.miniApp) _this._window.miniApp = null;
			_this.dispose();
			_this = null;
			webappEnv = null;
		}
		//miniApp.window.onerror = function(){return true;};
		//window.onerror = function(){return true;};
		if(this.isIE){  //IE
			this._doc.attachEvent("onreadystatechange", __DOMContentLoaded);
			this._window.attachEvent("onload", __load);
			this._window.attachEvent("onresize", __resize);
			this._window.attachEvent("onbeforeunload", __beforeunload);
			this._window.attachEvent("onunload", __unload);
		}else{  //FF
			this._doc.addEventListener("DOMContentLoaded", __DOMContentLoaded, false);
			this._window.addEventListener("load", __load, false);
			this._window.addEventListener("resize", __resize, false);
			this._window.addEventListener("beforeunload", __beforeunload, false);
			this._window.addEventListener("unload", __unload, false);
		}
	};
	/**
	 * 全局事件响应
	 */
	this.onContentLoaded = function(){
		this.loadLibrary("im_init.jar", this, "_asyn_onload_iminit");  //默认引入的类库
		/*
		for(var i = 0; i < this._apps.length; i++){
			if(!this._apps[i]._inited)
				this._apps[i].onContentLoaded();
		}
		*/
	};
	this.onload = function(){
	};
	this.onresize = function(){
		for(var i = 0; i < this._apps.length; i++){
			if(this._apps[i].onResize)
				this._apps[i].onResize();
		}
	};
	this.onbeforeunload = function(){
	};
	this.onunload = function(){
		for(var i = this._apps.length - 1; i >= 0; i--){
			this._apps[i].dispose();
			delete this._apps[i];
		}
		this._apps = [];
	};
	/**
	 * tool function
	 */
	this.getUniqueId = function(){return ++this._currentUniqueId;};
	this.isDefined = function(obj){
		if(typeof(obj) == "undefined")
			return false;
		else
			return true;
	};
	this.isXPBrowserSP1 = function(){
		return this.isIE && window.navigator.appMinorVersion.indexOf("SP1") != -1;
	};
	this._isBrowser = function(name){
		var ua = this._window.navigator.userAgent;
		if((i = ua.indexOf(name)) >= 0){
			this._version = parseFloat(ua.substr(i + name.length));
			return true;
		}
		return false;
	};
	this._setPathRoot = function(pathroot){
		this.pathRoot  = pathroot;
		this.pathRes   = this.pathRoot + "src/";
		this.pathCss   = this.pathRoot + "css/";
		//this.path    = this.pathRoot + "script/";
		this.classpath = this.pathRoot + "classes/";
		this.pathlib   = this.pathRoot + "lib/";
		//this.pathApp = "";
	};
	/**
	 * 加锁和解锁支持，依赖的是下面方法的简洁和执行效率，并不是真正意义上的锁机制。
	 */
	/* nouse
	this.lock = function(key){
		if(this._locklist[key])
			return false;
		else{
			this._locklist[key] = true;
			return true;
		}
	};
	this.unlock = function(key){
		if(this._locklist[key])
			this._locklist[key] = false;
	};
	*/
	//this.getImgBase = function(){return application._config.getImageServer();};
	this.forIn = function(obj){
		var a = [];
		for(var k in obj)
			a.push(k + "=" + (
				typeof(obj[k]) == "function"
				? "[function]"
				: (k == "stack" ? "(stack)" : obj[k])
			)
		);
		return a;
	};
	this.showException = function(e, info){
		var a = this.forIn(e);
		if(info) a.push(info);
		this._window.alert(a.join("\n"));
	};
	this.createComObject = function(progid){
		return new ActiveXObject(progid);
	};
	this.getXmlHttp = function(){return this._ajax.getXmlhttpObject();};
	//下面的代码是跨窗口全局对象搜索函数的实现
	this.getWindow = (function(){
		var wins = [__global];
		function fn(hint){
			var doc = this.getDocument(hint);  //注意：this 就是 webappEnv 对象
			for(var i = 0; i < wins.length; ++i){
				if(wins[i].document === doc){
					return wins[i];
				}
			}
			var _3bd = doc.parentWindow || doc.defaultView;
			return _3bd || wins[0];
		}
		/* 没有用到，但不要删除
		fn.remember = function(owin){
			if(application.isDefined(owin._gWinPos)){
				return;
			}
			owin._gWinPos = wins.length;
			wins.push(owin);
		};
		fn.forget = function(owin){
			if(!application.isDefined(owin._gWinPos)){
				return;
			}
			wins = wins.slice(0, owin._gWinPos).concat(wins.slice(owin._gWinPos + 1));
			for(var i = owin._gWinPos; i < wins.length; ++i){
				wins[i]._gWinPos = i;
			}
			try{
				delete owin._gWinPos;
			}catch(IESUCKS){
			}
		};
		*/
		return fn;
	})();
	this.getDocument = function(hint){
		if(hint){
			if(hint.ownerDocument){
				return hint.ownerDocument;
			}else{
				if(typeof(hint.nodeName) == "string"){
					if(hint.nodeName.match(/document/i)){
						return hint;
					}else{
						if(hint.nodeName.match(/window/i)){
							return hint.document;
						}
					}
				}
			}
			var target = hint.srcElement || hint.target;
			if(target){
				return this.getDocument(target);
			}
		}
		return this._doc;
	};
	this.getElement = (function(){
		var docList = [__global.document];
		function dollar(){
			var arr = [];
			for(var i = 0; i < arguments.length; i++){
				var id = arguments[i];
				var results = [];
				if(typeof(id) != "string"){
					arr.push(id);
				}else{
					for(var j = 0; j < docList.length; ++j){
						try{
							var obj = docList[j].getElementById(id);
							if(obj) results.push(obj);  //找到的话，压入数组中
						}catch(windowMightHaveClosed){
						}
						if(results.length > 0){
							break;
						}
					}
					arr.push(results.length == 0 ? null : (results.length == 1 ? results[0] : results));
				}
			}
			if(arr.length == 1)
				return arr[0];
			else
				return arr;
		}
		/* 没有用到，但不要删除
		dollar.remember = function(doc){
			for(var i = 0; i < docList.length; ++i){
				if(doc === docList[i]){
					return;
				}
			}
			docList.push(doc);
		};
		dollar.forget = function(doc){
			var _4d = [];
			for(var i = 0; i < docList.length; ++i){
				if(docList[i] !== doc){
					_4d.push(docList[i]);
				}
			}
			docList = _4d;
		};
		*/
		return dollar;
	})();
	/**
	 * 使用 cookie 保存的信息有：
	 * mid         = 用户帐号
	 * state       = 登陆状态(invisible|online)
	 * qquid       = QQ帐号
	 * msnuid      = MSN帐号
	 * qqmsnstate  = QQ,MSN登录状态(invisible|online)
	 * minisitepos = minisite位置(x-y)
	 * lang        = 所使用的语言
	 * sound       = 是否开启声音(null||true|false)
	 * searchtype  = 搜索的类型索引(number)
	 * searchhide  = 是否隐藏搜索(true|false)
	 */
	this.loadCookie = function(name){
		var sCookie = window.document.cookie;
		if(sCookie.length == 0) return;
		var arr = sCookie.split(";");
		var key = name + "=";
		for(var i = 0; i < arr.length; i++){
			var item = arr[i];
			if(item.length == 0) continue;
			while(item.charAt(0) == " "){
				item = item.substring(1, item.length);
			}
			if(item.indexOf(key) == 0){
				return item.substring(key.length, item.length);
			}
		}
		return null;
	};
	this.saveCookie = function(name, value, bErase){
		var days = bErase ? -1 : 365;
		var date = new Date();
		date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
		var str = name + "=" + value + "; ";
		var expires = "expires=" + date.toGMTString() + "; ";
		var domain  = "domain=" + __config.domain + "; ";
		var path    = "path=/; ";
		window.document.cookie = str + expires + domain + path;
	};
	this.eraseCookie = function(name, path){
		this.saveCookie(name, "", true);
	};
	this.loadFile = function(url, _3c2){
		if(!url) return false;
		var _3c3 = (typeof url == "string") ? [url] : url;
		var _3c4 = _3c2 ? false : true;
		function innerLoadFile(_3c5){
			while(_3c3.length && webappEnv.findModule(_3c3[0], false)){
				_3c3.splice(0, 1);
			}
			if(_3c3.length){
				var url = _3c3[0];
				_3c3.splice(0, 1);
				webappEnv.require(url, function(){
					innerLoadFile(_3c2);
				}, _3c4);
				return false;
			}
			if(_3c5){
				_3c5();
			}
			return true;
		}
		return innerLoadFile(null);
	};
	this.getURLParam = function(strParamName){
		var sReturn = "";
		var sHref = window.location.href;
		if(sHref.indexOf("?") > -1 ){
			var sQueryString = sHref.substr(sHref.indexOf("?")).toLowerCase();
			var aQueryString = sQueryString.split("&");
			for(var i=0;i < aQueryString.length;i++ ){
				if(aQueryString[i].indexOf(strParamName + "=") > -1 ){
					var aParam = aQueryString[i].split("=");
					sReturn = aParam[1];
					break;
				}
			}
		}
		return sReturn;
	};

	/**
	 * old in dojo
	 */
	//propertys
	//this.path = "/jslib/";  //默认值将会被修改
	this.loadedUris = {};
	this.loadingUris = {};
	this.loaded_modules = {};
	this.loading_modules = {};
	//methods
	this.setPath = function(v){this.path = v;};
	this.raise = function(reason, error){application.log(reason);};
	this.loadUri = function(uri, cb, bSync){
		if(this.loadedUris[uri]) return 1;
		var text = this.getText(uri, cb, true, bSync);
		if(text == null) return 0;
		return this.loadText(text, uri);
	};
	this.loadText = function(text, uri){
		var obj = application.safeEval(text);
		if(obj){
			this.loadedUris[uri] = true;
			return true;
		}else{
			return false;
		}
	};
	this.findModule = function(moduleName, _e){
		var key = (new String(moduleName)).toLowerCase();
		if(this.loaded_modules[key] == 1){
			return this.loaded_modules[key];
		}
		return null;
	};
	/**
	 * simulate keyword import
	 */
	this.require = function(module, cb, bSync){
		if(!module) return;
		if(this.findModule(module, false)) return true;
		this.loading_modules[module] = 1;
		var uri = this.path + module.replace(/\./g, "/") + this._scriptVersion + this._suffix;
		var ok = this.loadUri(uri, cb, bSync);
		this.loading_modules[module] = 0;
		if(!ok){
			this.raise("Could not load '" + module + "'; last tried '" + uri + "'");
			return false;
		}
		module = this.findModule(module, false);
		if(!module){
			this.raise("symbol '" + module + "' is not defined after loading '" + uri + "'");
			return false;
		}
		return true;
	};
	/**
	 * simulate keyword package
	 */
	this.provide = function(moduleName){
		this.loading_modules[moduleName] = 0;
		this.loaded_modules[(new String(moduleName)).toLowerCase()] = 1;
	};
	this.getText = function(uri, callback, _1c, bSync){
		var http = this._ajax.getXmlhttpObject();
		if(!bSync){
			var _this = this;
			http.onreadystatechange = function(){
				//window.prompt("", uri);
				if(4 == http.readyState){
					if(!http.status || (200 <= http.status && 300 > http.status)){
						//application.log("LOADED URI: " + uri);
						if(_this.loadText(http.responseText, uri)){
							if(callback){
								callback();
							}else{
								application._windowMgr.createNotifyDlg(
									application.getUniqueId() + "networkError",
									application._lang.imtataMessage,
									application._lang.disruption + application._lang.pleaseCheck
								);
							}
						}
					}
				}
			};
		}
		http.open("GET", uri, !bSync);
		try{
			http.send(null);
			if(!bSync) return;  //异步的话，直接退出
			if(http.status && (200 > http.status || 300 <= http.status)){
				throw Error("Unable to load " + uri + " status:" + http.status);
			}
		}catch(e){
			webappEnv.showException(e, "[webappEnv.getText]");
			if(_1c && bSync){
				return null;
			}else{
				application.log(e);
			}
		}
		return http.responseText;
	};
	/*
	this.netInvoke_bak = function(classes, funCallback){
		if(!classes) return false;
		var modules = (typeof(classes) == "string") ? new Array(classes) : classes;
		var bSync = funCallback ? false : true;
		var _this = this;
		function innerLoadFile(callback){
			while(modules.length && _this.findModule(modules[0], false)){
				modules.splice(0, 1);
			}
			if(modules.length){
				var sUrl = modules[0].replace(/\./g, "/");
				modules.splice(0, 1);
				/-*
				 * _this.require(sUrl, function(){innerLoadFile(funCallback);}, bSync);
				 * return false;
				 *-/
				var xmlhttp = _this._ajax.getXmlhttpObject();
				var async = true;
				xmlhttp.onreadystatechange = function(){
					if(xmlhttp.readyState == 4){
						if(application.safeEval(xmlhttp.responseText)){
							innerLoadFile(funCallback);
						}
					}
				};
				xmlhttp.open("GET", _this.path + sUrl + _this._scriptVersion + _this._suffix, async);
				xmlhttp.send("");
				return bSync;
			}
			if(callback){
				callback();
			}
			return true;
		}
		return innerLoadFile(null);
	};
	*/
	this.netInvoke = function(){return this._ajax.netInvoke.apply(this._ajax, arguments);};
	this.netInvoke2 = function(){return this._ajax.netInvoke2.apply(this._ajax, arguments);};
	/**
	 * 使用模态对话框机制，模拟window.alert的功能，而且能够做更多的功能。
	 * 因为只有IE浏览器才有这个功能，所以有浏览器限制。
	 */
	this.alert = function(str){
		if(this.isIE){
			this._window.showModalDialog(
				"alert.htm?" + Math.random(),
				[this._window, str],
				"dialogWidth:800px;dialogHeight:200px;center:yes;help:no;status:no;title:no;scroll:no;resizable:yes;edge:sunken;"
			);
		}else{
			this._window.alert("[webappEnv.alert]" + str);
		}
	};
	this.showDebug = function(){
		//var win = this._window.showModelessDialog("debug.htm?" + Math.random(), [window], "dialogWidth:350px;dialogHeight:200px;center:yes;help:no;status:no;title:no;scroll:no;resizable:yes;edge:sunken;");
		var win = this._window.open("debug.htm", "debug", "width=350,height=200,toolbar=no,resizable=yes");
	};
	this.formatDate = function(d, bMsec){
		var hour = (d.getHours() < 10 ? "0" + d.getHours() : d.getHours());
		var minute = (d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes());
		var second = (d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds());
		var ms;
		if(bMsec)
			ms = " " + "000".substr(0, 3 - ("" + d.getMilliseconds()).length) + d.getMilliseconds();
		return hour + ":" + minute + ":" + second + (bMsec ? ms : "");
	};
	this.showLogWindow = function(){
		var win = this._window.open("about:blank", "_blank", "width=350,height=200,toolbar=no,resizable=yes,scrollbars=yes");
		win.document.open();
		win.document.writeln("<html>");
		win.document.writeln("<head>");
		win.document.writeln("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">");
		win.document.writeln("<title>test</title>");
		win.document.writeln("<style>BODY {font-size:12px;}</style>");
		this._logWin = win;
	};
	this.httplog = function(info){
		if(this._logWin && ! this._logWin.closed){
			info = ("" + info)
				.replace(/</g, "&lt;")
				.replace(/>/g, "&gt;")
				.replace(/&/g, "&amp;")
				.replace(/\"/g, "&quot;");
			this._logWin.document.writeln("<br /><nobr>[" + this.formatDate(new Date(), true) + "]" + info + "</nobr>");
		}
	};
	this.getWait = function(){
		if(!this._wait){
			this._wait = new alz.LogonWait();
			this._wait.create(this._doc.body);
		}
		return this._wait;
	};
	/**
	 * 动态载入 css 文件
	 */
	this.importStyleSheet = function(uriCss){
		//this._doc.write("<" + "link rel=\"stylesheet\" type=\"text/css\""
		//  + " href=\"" + uriCss + "\" />");
		var link = this._doc.createElement("link");
		link.setAttribute("rel", "stylesheet");
		link.setAttribute("type", "text/css");
		link.setAttribute("href", uriCss + "?" + this._configVersion);
		this._doc.getElementsByTagName("head")[0].appendChild(link);
	};
	this._toText = function(http, charset){
		if(this._window && charset == "utf-8"){
			/*
			if(uri.indexOf(".jar") != -1){
				var obj = this._doc.createElement("script");
				obj.type = "text/javascript";
				obj.charset = "utf-8";
				obj.text = http.responseText;
				this._domScript.parentNode.appendChild(obj);
			}
			*/
			return http.responseText;
		}else if(this.isIE){
			if(typeof(VBS_bytes2BStr) == "undefined"){
				this._window.execScript(this._vbsCode, "VBScript");
			}
			return VBS_bytes2BStr(http.responseBody);
		}else{
			return http.responseText;
		}
	};
	this.loadScriptFile1 = function(uri, bCompile){
		var data = this.netInvoke2("GET", uri);
		if(bCompile){
			this.compileCode(data);
		}else{
			var obj = this._doc.createElement("script");
			obj.type = "text/javascript";
			//obj.charset = "utf-8";
			//obj.src = uri;
			obj.text = data;
			this._doc.body.appendChild(obj);
		}
	};
	this.loadScriptFile = function(uri, cb, charset){
		var bAsyn = cb ? true : false;
		var http = this._ajax.getXmlhttpObject();
		http.open("GET", uri + "?" + this._configVersion, bAsyn);
		if(this.isNS) http.overrideMimeType("text/xml;charset=gb2312");
		http.send(null);
		if(bAsyn){
			var _this = this;
			function onload(){
				if(http.readyState != 4) return;
				cb(_this._toText(http, charset));  //调用回掉函数
				cb = null;
				http = null;
				_this = null;
			}
			http.onreadystatechange = onload;
			if(http.readyState == 4)  //如果启用了缓存，则会 == 4
				onload();
		}else{
			var code = "";
			if(http.readyState && http.readyState != 4)
				throw new Error("资源(" + uri + ")加载失败");
			else
				code = this._toText(http, charset);
			delete http;
			return code;
		}
	};
	this.compileCode = function(code){
		try{
			var g = new ClassEnvironment();
			//g.window = null;  //屏蔽外部的 window 对象，模拟沙箱的工作机制
			g.webappEnv = this;
			g.alz = this.alz;
			with(g){  //使暴露的接口可用
				eval(code);
			}
			return true;
		}catch(e){
			this.showException(e, "[webappEnv.compileCode]");
			return false;
		}
	};
	this.definePackage = function(sPackage){
		var arr = sPackage.split(".");
		var sPack = "";
		for(var i=0;i < arr.length;i++){
			sPack += (i == 0 ? "" : ".") + arr[i];
			//检查指定的包是否存在，如果不存在则定义之
			if(typeof(eval("this." + sPack)) == "undefined"){
				eval("this." + sPack + " = {};");
			}
		}
	};
	this.loadLibrary = function(libName, agent, funName){
		if(!this._libs[libName]){
			if(agent){  //异步加载
				var _this = this;
				this.loadScriptFile(this.pathlib + libName + ".js", function(code){
					_this._libs[libName] = code;
					_this.compileCode(code);
					agent[funName]();  //调用回掉函数
					agent = null;
					_this = null;
				}, "utf-8");
				return;
			}else{
				var code = this.loadScriptFile(this.pathlib + libName + ".js", null, "utf-8");
				if(code){
					this._libs[libName] = code;
					return this.compileCode(code);
				}else
					return false;
			}
		}
		return true;
	};
	this.loadClass = function(className){
		try{
			try{
				eval("var clazz = this." + className + ";");
				if(clazz) return;  //如果已经存在则返回
			}catch(e){
			}
			if(this._classes[className]) return;  //如果存在直接返回
			var url = this.classpath + className.replace(/\./g, "/").replace(/\*/g, "_package") + ".js";
			var code = this.loadScriptFile(url);
			if(code){  //资源加载成功
				this._classes[className] = true;  //不存储成功加载的类的文本代码
				this.compileCode(code);
				//log_ta.value += "\n" + className;
			}
		}catch(e){
			this.showException(e, className);
		}
	};
	this.inheritClass = function(fThis, fSuper, sName){
		if(!fThis._super)  //如果还没有定义父类指针
			fThis._super = fSuper.prototype;  //静态属性
		fThis._className = sName;
		var p = fThis.prototype = new fSuper();
		p._class = fThis;
		if(sName) p._className = sName;
		p.constructor = fThis;
		return p;
	};
	//----------------------------------------------------------------------------
	/**
	 * 初始化整个应用，需要在 window.onload 中调用。另外，注意在应用开始之前，类
	 * alz.LogonWait 就要保证可用。
	 * 1)正在加载应用核心代码...
	 * 2)正在初始化应用...
	 * 3)正在对密码进行加密...
	 * 4)正在登录，请等待...
	 */
	this.initApp = function(){
		this.importStyleSheet(this.pathCss + "mbcn.css");
		this.importStyleSheet(this.pathCss + "ttm.css");
		var wait = this.getWait();
		wait.showWait(true, "正在加载应用核心代码...");
		this.loadLibrary("webim.jar", this, "_asyn_onload_webim");  //异步加载核心库
		wait = null;
	};
	this.initApp3 = function(){
		var wait = this.getWait();
		wait.showWait(true, "正在初始化应用...");
		this.loadLibrary("webim2.jar", this, "_asyn_onload_webim2");  //异步加载核心库
		wait = null;
	};
	this._asyn_onload_iminit = function(){
		this.importStyleSheet(this.pathCss + "aui_init.css");  //加载初始的CSS样式
		//this.loadClass("alz.lang.Object");  //默认引入的类
		//this.loadClass("alz.DomManager");
		//this.loadClass("alz.GUIManager");
		//this.loadClass("alz.LogonWait");
		this.domManager = new alz.DomManager();
		this.guiManager = new alz.GUIManager(this);
		this.guiManager.init();
		this._startInit();
	};
	this._startInit = function(){
		switch(this._runMode){
		case 0:  //独立的旧版
			this.initApp();
			break;
		case 1:  //新旧版混合
			this.loadLibrary("miniapp.jar", this, "_asyn_onload_miniapp");
			break;
		case 2:  //im.php使用，[TODO]让表单提交的方式支持新版的登陆
			this.initApp();
			break;
		case 3:  //独立的新版
			this.initApp3();
			break;
		case 4:  //2.00版
			this.loadLibrary("webim2.00.jar", this, "_asyn_onload_webim4");
			break;
		}
	};
	this._asyn_onload_miniapp = function(){
		this.importStyleSheet(this.pathCss + "aui_style.css");
		this.loadClass("alz.miniapp.MiniApplication");
		var app = new alz.miniapp.MiniApplication();
		app.init();
		this._apps.push(app);
		this._window.miniApp = app;
		app.onContentLoaded();
		app = null;
	};
	this._asyn_onload_webim = function(){
		this.loadClass("alz.im.Language");  //加载语言包
		this.loadClass("alz.Application");
		var app = new alz.Application();
		this._window.application = app;  //暴露对象
		var wait = this.getWait();
		wait.showWait(true, "正在初始化应用...");
		app.init(true);
		//app.setupRemote();  //基本没有用处了
		//app.onContentLoaded();
		this._apps.push(app);
		app._logon._loginType = 0;
		app._logon._loginFormName = this._window.miniApp
			? this._window.miniApp.form.name  //frm_qqmsn|frm_imtata
			: "frm_imtata";
		app._logon.loginUser();
		app = null;
		wait.showWait(false);
		wait = null;
	};
	this._asyn_onload_webim2 = function(){
		this.importStyleSheet(this.pathCss + "wui_skin.css");
		var app = new alz.webim.Application();
		app.init();
		this._apps.push(app);
		this._window.application = app;  //暴露对象
		app.onContentLoaded(this._window.miniApp);
		//if(this._runMode != 3)  //如果不是独立新版
		//	app.onContentLoaded(this._window.miniApp);
		app = null;
		var wait = this.getWait();
		wait.showWait(false);
		wait = null;
	};
	this._asyn_onload_webim4 = function(){
		this.importStyleSheet(this.pathCss + "wui_skin2.00.css");
		var app = new alz.im.core.Application();
		app.init();
		this._apps.push(app);
		this._window.application = app;  //暴露对象
		app.onContentLoaded(this._window.miniApp);
		app = null;
		var wait = this.getWait();
		wait.showWait(false);
		wait = null;
	};
}).apply(WebAppEnvironment.prototype);

function AjaxEngine(host){this._init.apply(this, arguments);}
(function(){
	this._PROGIDS = [
		"Microsoft.XMLHTTP",
		"Msxml2.XMLHTTP",
		"Msxml2.XMLHTTP.4.0",
		"MSXML3.XMLHTTP",
		"MSXML.XMLHTTP",
		"MSXML2.ServerXMLHTTP"
	];
	this._msec = 10;
	this._init = function(host){
		this._host = host;
		this._http = null;
		this._queue = [];  //异步请求队列
		this._errHandle = null;
		this._timer = 0;
	};
	this.dispose = function(){
		if(this._timer != 0){
			this._host._window.clearTimeout(this._timer);
			this._timer = 0;
		}
		this._errHandle = null;
		this._http = null;
		for(var i = 0; i < this._queue.length; i++){
			delete this._queue[i];
		}
		this._queue = [];
		this._host = null;
	};
	this.getXmlhttpObject = function(){
		//return this._window.Event ? new XMLHttpRequest()
		//													: new ActiveXObject("Microsoft.XMLHTTP");
		var http;
		var error = null;
		if(typeof XMLHttpRequest != "undefined"){
			try{
				http = new XMLHttpRequest();
			}catch(e){}
		}
		if(!http){
			for(var i = 0; i < this._PROGIDS.length; ++i){
				var progid = this._PROGIDS[i];
				try{
					http = this._host.createComObject(progid);
				}catch(e){
					error = e;
				}
				if(http){
					this._PROGIDS = [progid];  //缓存，提高以后的创建速度
					break;
				}
			}
		}
		if(!http)
			this._host.showException(error, "XMLHTTP not available");
			//return this.raise("XMLHTTP not available", err);
		return http;
	};
	this.clearQueue = function(){
		if(this._timer != 0){
			this._host._window.clearTimeout(this._timer);
			this._timer = 0;
		}
		for(var i = 0; i < this._queue.length; i++){
			delete this._queue[i];
		}
		this._queue = [];
	};
	this.setErrHandle = function(oAgent, sFunName){
		if(typeof(oAgent) == "function" && sFunName != null){
			this._host.showException("如果oAgent是函数，则其后的参数sFunName必须是null", "[AjaxEngine.setErrHandle]");
			return;
		}else if(typeof(oAgent) == "object" && typeof(oAgent[sFunName]) != "function"){
			this._host.showException("如果oAgent是对象，则其后的参数sFunName必须是对象oAgent的某个方法名", "[AjaxEngine.setErrHandle]");
			return;
		}
		this._errHandle = {agent: oAgent, fun: sFunName};
	};
	this.checkError = function(http){
		if(http.readyState != 4) return false;
		if(http.status != 0 && http.status != 200){
			this._stopAjaxThread();
			if(this._errHandle){
				this._errHandle.agent[this._errHandle.fun]();
			}else{
				if(http.status == 404 || http.status == 500)
					this._host._window.alert("不能连接到服务器。");
				else
					this._host.showException("异步请求错误"
						+ "\nstatus=" + http.status
						+ "\nstatusText=" + http.statusText
					);
			}
			return false;
		}else
			return true;
	};
	/**
	 * 可以复用HTTP组件的网络调用，使用请求队列工作模式
	 * @param sMethod 异步请求的方法(GET|POST)
	 * @param sUrl 异步请求的地址
	 * @param sPostData （POST请求时）发送的请求数据  //args 请求参数
	 * @param sType 返回数据的类型(text|xml)
	 * @param oAgent 异步数据回调的代理对象
	 * @param sFunName 代理对象的回调方法名称
	 * @param cbArgs 传递给回调方法的参数
	 */
	this.netInvoke = function(sMethod, sUrl, sPostData, sType, oAgent, sFunName, cbArgs){
		if(!(/^(GET|POST)$/i).test(sMethod)){
			this._host.showException("回调方法必须是GET或POST之一", "[AjaxEngine.setErrHandle]");
			return;
		}else if(sMethod == "GET" && sPostData != null){
			this._host.showException("GET方法时，参数sPostData必须是null", "[AjaxEngine.setErrHandle]");
			return;
		}else if(typeof(oAgent) == "function" && sFunName != null){
			this._host.showException("如果oAgent是函数，则其后的参数sFunName必须是null", "[AjaxEngine.setErrHandle]");
			return;
		}else if(typeof(oAgent) == "object" && typeof(oAgent[sFunName]) != "function"){
			this._host.showException("如果oAgent是对象，则其后的参数sFunName必须是对象oAgent的某个方法名", "[AjaxEngine.setErrHandle]");
			return;
		}
		this._queue.push({
			method: sMethod,
			url   : sUrl,
			data  : sPostData,
			type  : sType,
			agent : oAgent,
			fun   : sFunName,
			args  : cbArgs
		});
		if(this._timer == 0) this._startAjaxThread();
		return;
	};
	this.netInvoke2 = function(sMethod, sUrl, sPostData, sType, oAgent, sFunName, cbArgs){
		try{
			var bAsyn = typeof(oAgent) == "function"
				|| typeof(oAgent) == "object" && typeof(oAgent[sFunName]) == "function";
			var http = this.getXmlhttpObject();
			http.open(sMethod, sUrl, bAsyn);
			if(this._host.isNS) http.overrideMimeType("text/xml;charset=gb2312");
			if(sMethod == "POST")
				http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.send(sPostData);
			if(bAsyn){
				var _this = this;
				http.onreadystatechange = function(){
					if(http.readyState != 4) return;
					if(_this.checkError(http)){
						var text = "" + http.responseText;
						if(_this._host._apps[1] && _this._host._apps[1].trace) _this._host._apps[1].trace(text);
						if(typeof(oAgent) == "function"){
							oAgent(text, cbArgs);  //无需检测oAgent[sFunName] == null
						}else if(typeof(oAgent) == "object" && typeof(oAgent[sFunName]) == "function")
							oAgent[sFunName](text, cbArgs);  //无需检测oAgent[sFunName] == null
						else
							_this._host.showException("回调函数类型检查失败，程序设计问题，请联系技术人员", "[AjaxEngine.netInvoke2]");
					}
					//此处导致的内存泄漏好难检查啊！！！
					//[TODO]仍然有内存泄漏问题
					oAgent = null;
					cbArgs = null;
					http = null;
				};
				return;
			}else{
				var ret = http.responseText;
				http = null;
				return ret;
			}
		}catch(e){
			this._host.showException(e, "[AjaxEngine.netInvoke2]");
			return;
		}
	};
	this._startAjaxThread = function(){
		var _this = this;
		this._timer = this._host._window.setTimeout(function(){
			_this._ajaxThread();
		}, this._msec);
	};
	this._stopAjaxThread = function(){
		this._queue.pop();  //清除队列最后一个元素(test请求)
		this._http.abort();
		this._host._window.clearTimeout(this._timer);
		this._timer = 0;
	};
	/**
	 * 异步调用线程是不应该有同步工作机制的，因为无法正常工作
	 */
	this._ajaxThread = function(){
		try{
			var req  = this._queue[0];
			var url = req.url.replace(/\?/, "?time=" + (new Date().getTime()) + "&");
			if(!this._http){
				this._http = this.getXmlhttpObject();
			}
			this._http.open(req.method, url, true);
			if(req.method == "POST")
				this._http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			if(this._host.isNS){  //FF
				/*
				var ext = url.substr(url.lastIndexOf("."));
				if(ext == ".xml" || ext == ".aul"){
					//用于将 UTF-8 转换为 gb2312
					//this._http.overrideMimeType("text/xml;charset=gb2312");
					this._http.overrideMimeType("text/xml");
				}else{
					this._http.overrideMimeType("text/xml");
				}
				*/
			}
			var _this = this;
			this._http.onreadystatechange = function(){_this._onreadystatechange();};
			this._http.send(req.data || null);
			req = null;
			return;
		}catch(e){
			this._host.showException(e, "[AjaxEngine._ajaxThread]");
			return;
		}
	};
	this._onreadystatechange = function(){
		if(this._http.readyState != 4) return;
		var req  = this._queue[0];
		if(req.url.indexOf("mfc/test") != -1 || this.checkError(this._http)){
			var o;
			switch(req.type){
			case "text":
				o = this._http.responseText;
				if(this._host._apps[1] && this._host._apps[1].trace) this._host._apps[1].trace(o);
				break;
			case "xml" :
			default    :
				if(this._host.isIE){
					var xmldoc = this._host.createComObject("Msxml.DOMDocument");
					xmldoc.async = false;
					xmldoc.loadXML(this._http.responseText);
					o = xmldoc;  //.documentElement
					//o = _this.createXml(http.responseText);
				}else
					o = this._http.responseXML;
				break;
			}
			//调用回调函数，因为前面已经做过检查，只可能这两种情况
			if(typeof(req.agent) == "function")
				req.agent(o, req.args);
			else  //if(typeof(req.agent) == "object" && typeof(req.agent[req.fun]) == "function")
				req.agent[req.fun](o, req.args);
			req = null;
			this._queue[0] = null;
			this._queue.shift();  //清除队列第一个元素
			if(this._queue.length != 0){
				this._startAjaxThread();
			}else{
				this._host._window.clearTimeout(this._timer);
				this._timer = 0;
			}
		}
		req = null;
	};
	/**
	 * 由字符串生成XMLDocument对象
	 */
	this.createXml = function(str){
		var xml;
		if(this._host.isIE){
			xml = new ActiveXObject("Microsoft.XMLDOM");
			xml.loadXML(str);
			xml.setProperty("SelectionLanguage", "XPath");
		}else
			xml = new DOMParser().parseFromString(str, "text/xml");
		return xml.documentElement;
	};
	/*
	this._callList = [];
	this.getXmlhttpArray = function(sUrl, funCallback){
		for(var i=0;i < this._callList.length;i++){
			if(this._callList[i] != null){
				//if(this._callList[i].callback == funCallback && !this._callList[i].isEnd){
				if(this._callList[i].url == sUrl){
					return this._callList[i];  //this._callList[i].xmlhttp;
				}
			}
		}
		var oXmlhttp = this._ajax.getXmlhttpObject();
		this._callList[this._callList.length] = {
			isEnd : false,
			xmlhttp : oXmlhttp,
			url : sUrl,
			callback : funCallback
		};
		return this._callList[this._callList.length - 1];
	};
	this.netInvoke1 = function(url, funCallback){
		var aaa = this.getXmlhttpArray(url, funCallback);
		if(!aaa.isEnd){
			var xmlhttp = aaa.xmlhttp;
			var async = true;
			xmlhttp.onreadystatechange = function(){
				if(xmlhttp.readyState == 4){
					aaa.isEnd = true;
					if(application.safeEval(xmlhttp.responseText)){
						funCallback();
					}
					return true;
				}
				return false;
			};
			xmlhttp.open("GET", this.path + url + this._scriptVersion + this._suffix, async);
			xmlhttp.send();
			return false;
		}else{
			return true;
		}
	};
	*/
}).apply(AjaxEngine.prototype);

/**
 * 该类的成员是暴露给其他标准类的接口，用于OOP机制的支持代码
 */
function ClassEnvironment(){/*this._init.apply(this, arguments);*/}
(function(){
	this.webappEnv = null;
	this.alz = null;
	this._p = null;
	this._s = null;
	this._package = function(sPackage){
		this.webappEnv.definePackage(sPackage);
	}
	this._import = function(moduleName){
		/**
		 * 对 arguments.callee.caller == this.compileCode 做出明确限定，可以规范模块
		 * 的语法，让 _import 只能在类文件的全局范围内使用。同理，对[^this]._进行检
		 * 查可以防止私有属性被随意的使用，注意 _this 的使用限制。
		 */
		this.webappEnv.loadClass(moduleName);
	}
	this._class = function(sName){
	};
	this._extends = function(fThis, fSuper, sName){
		return this.webappEnv.inheritClass(fThis, fSuper, sName);
	};
}).apply(ClassEnvironment.prototype);


	webappEnv = new WebAppEnvironment();
	webappEnv.init();  //初始化
	__global.webappEnv = webappEnv;  //暴露的变量 webappEnv

	/*
	_p.alz = webappEnv.alz;
	_p._p = null;
	_p._s = null;
	_p._package = function(sPackage){this.webappEnv.definePackage(sPackage);};
	_p._import = function(moduleName){this.webappEnv.loadClass(moduleName);};
	_p._class = function(sName){};
	_p._extends = function(fThis, fSuper, sName){return this.webappEnv.inheritClass(fThis, fSuper, sName);};
	_p.application = null;  //全局唯一应用对象
	_p.$ = function(){
		//return typeof(id) == "string" ? __global.document.getElementById(id) : id;
		return webappEnv.getElement(arguments);
	};
	*/
})(this);

//全局函数定义
(function(){
	this.UploadFileSizeOver = function(wid, fileid, filename, filelength){
		//var msgstr = sendFileOverSize
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			imDlg.uploadSelectFile--;
			imDlg.addHistoryIM(application._lang.sendFileOverSize, "", true, true);
			if((imDlg.m_uploadingFileNum + imDlg.m_uploadingFileNum) <= 0){
				imDlg.m_bHideAfterShow = true;
				//imDlg.hideOutlookBar(1);
				window.setTimeout("application._windows[\"" + wid + "\"].hideOutlookBar(1)", 200);
			}
		}
	};
	this.beginuploadFile = function(wid, fileid, filename, filelength){
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			imDlg.uploadSelectFile--;
			var msgstr = application._lang.startTransFile + "\"" + filename + "(" + filelength + ")\"";
			imDlg.addHistoryIM(msgstr, "", true, true);
			//imDlg.showOutlookBar(1, null);
			imDlg.m_uploadingFileNum++;
		}
	};
	this.endUploadFile = function(wid, fileid, filename, filelength){
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			var msgstr = application._lang.endTransFile + "\"" + filename + "\"";
			imDlg.addHistoryIM(msgstr, "", true, true);
			imDlg.m_uploadingFileNum--;
			if((imDlg.m_uploadingFileNum + imDlg.m_downloadingFileNum) <= 0){
				imDlg.m_bHideAfterShow = true;
				//imDlg.hideOutlookBar(1);
				window.setTimeout("application._windows[\"" + wid + "\"].hideOutlookBar(1)", 200);
			}
		}
	};
	this.cancelUploadFile = function(wid, fileid, filename, filelength){
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			var msgstr = application._lang.cancelTransFile + "\"" + filename + "\"";
			imDlg.addHistoryIM(msgstr, "", true, true);
			imDlg.m_uploadingFileNum--;
			if((imDlg.m_uploadingFileNum + imDlg.m_downloadingFileNum) <= 0){
				imDlg.m_bHideAfterShow = true;
				//此处必须延迟时间长些，等待flash对象取消动作全部完成，否则在传送多个文件时容易出现僵死数秒的问题
				window.setTimeout("application._windows[\"" + wid + "\"].hideOutlookBar(1)", 2000);
			}
		}
	};
	this.Cancel2Upload = function(wid, fileid){
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			imDlg.uploadSelectFile--;
			if((imDlg.m_uploadingFileNum + imDlg.m_downloadingFileNum) <= 0){
				imDlg.m_bHideAfterShow = true;
				window.setTimeout("application._windows[\"" + wid + "\"].hideOutlookBar(1)", 200);
			}
		}
	};
	/**
	 * 上传文件长度为0时或者文件被其他程序独占时
	 */
	this.UploadFileInvalid = function(wid, fileid, errorMsg){
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			imDlg.uploadSelectFile--;
			var msgstr = application._lang.invalidUploadFile;
			imDlg.addHistoryIM(msgstr, "", true, true);
			if((imDlg.m_uploadingFileNum + imDlg.m_downloadingFileNum) <= 0){
				imDlg.m_bHideAfterShow = true;
				window.setTimeout("application._windows[\"" + wid + "\"].hideOutlookBar(1)", 200);
			}
		}
	};
	this.UploadFileError = function(wid, fileid, filename, filelength, errorMsg){
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			var msgstr = application._lang.errorTransFile + "\"" + filename + "\"";
			if(errorMsg)
				msgstr += ",原因:"+errorMsg;
			imDlg.addHistoryIM(msgstr, "", true, true);
			imDlg.m_uploadingFileNum--;
			if((imDlg.m_uploadingFileNum + imDlg.m_downloadingFileNum) <= 0){
				imDlg.m_bHideAfterShow = true;
				//imDlg.hideOutlookBar(1);
				window.setTimeout("application._windows[\"" + wid + "\"].hideOutlookBar(1)", 200);
			}
		}
	};
	this.begindownloadFile = function(wid, acceptLinkID, fileid, filename, filelength){
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			var msgstr = application._lang.startDownloadFile + "\"" + filename + "\"";
			imDlg.addHistoryIM(msgstr, "", true, true);
			//if(imDlg._outlook._barHidden[1])
			//	imDlg.showOutlookBar(1, null);
			imDlg.m_downloadingFileNum++;
			var acceptLink = window.document.getElementById(acceptLinkID);
			if(acceptLink)
				imDlg.removeAnchorNode(acceptLink);
		}
	};
	this.endDownloadFile = function(wid, fileid, filename, filelength){
		//alert("endDownloadFile");
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			var msgstr = application._lang.endDownload + "\"" + filename + "\"";
			imDlg.addHistoryIM(msgstr, "", true, true, false, null, false, "openfile");
			imDlg.m_downloadingFileNum--;
			if((imDlg.m_uploadingFileNum + imDlg.m_downloadingFileNum) <= 0){
				imDlg.m_bHideAfterShow = true;
				//imDlg.hideOutlookBar(1);
				window.setTimeout("application._windows[\"" + wid + "\"].hideOutlookBar(1)", 200);
			}
		}
	};
	this.cancelDownloadFile = function(wid, fileid, filename, filelength){
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			var msgstr = application._lang.cancelDownload + "\"" + filename + "\"";
			imDlg.addHistoryIM(msgstr, "", true, true);
			imDlg.m_downloadingFileNum--;
			if((imDlg.m_uploadingFileNum + imDlg.m_downloadingFileNum)<=0){
				imDlg.m_bHideAfterShow = true;
				//imDlg.hideOutlookBar(1);
				window.setTimeout("application._windows[\"" + wid + "\"].hideOutlookBar(1)", 200);
			}
		}
	};
	this.Cancel2Download = function(wid, fileid){
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			if((imDlg.m_uploadingFileNum + imDlg.m_downloadingFileNum)<=0){
				//imDlg.hideOutlookBar(1);
				window.setTimeout("application._windows[\"" + wid + "\"].hideOutlookBar(1)", 200);
			}
		}
	};
	this.DownloadError = function(wid, fileid, filename, filelength, errorMsg){
		var nfileID = Number(fileid);
		var imDlg = application._windows[wid];
		if(nfileID > 0 && imDlg){
			var msgstr = application._lang.errorDownload + "\"" + filename + "\"";
			if(errorMsg)
				msgstr += ",原因:"+errorMsg;
			imDlg.addHistoryIM(msgstr, "", true, true);
			imDlg.m_downloadingFileNum--;
			if((imDlg.m_uploadingFileNum + imDlg.m_downloadingFileNum)<=0){
				imDlg.m_bHideAfterShow = true;
				//imDlg.hideOutlookBar(1);
				window.setTimeout("application._windows[\"" + wid + "\"].hideOutlookBar(1)", 200);
			}
		}
	};
	/**
	 * 即将挂断语音聊天
	 * onVoiceStop
	 */
	this.FlashVoiceStoped = function(){
		if(application.dlgHasFlash){
			//application.dlgHasFlash.hideOutlookBar(application.dlgHasFlash.lastState().index);
			window.setTimeout("application.dlgHasFlash.hideOutlookBar(application.dlgHasFlash.lastState().index)", 200);
		}
	};
	//查询title函数：getTTWTitle(string title)
	//cloaseTTW()
	//login("maliqun", "a2b5c2765b4ce3fb7e091a8afaf22369", true);
	//消息通知函数：
	//TTWflashReady(string wid)  flash装载完毕
	//TTWTitleChanged(string wid, string title)  title更改
	this.TTWflashReady = function(wid){
		var w = application._windows["tatawe_" + wid];
		if(w){
			var muser = application._logon.getUserLoginsWithProtocol("meebo");
			if(muser)
				w.flash._self.login(muser[0], application._browser.getSessionKey(), true);
		}
	};
	this.TTWTitleChanged = function(wid, title){
		var w = application._windows["tatawe_" + wid];
		if(w){
			w.setWindowCaption(title, null);
		}
	};
	//tatawe 回调函数
	this.ShowTTW = function(wid, username, userpassword){
		//alert("ShowTTW :" + wid + "/" + username + "/" + userpassword);
		var id = "tatawe_" + wid;
		if(application._windows[id]){
			application._windows[id].activateWindow();
			return ;
		}
		_import("alz.ui.dialog.BlankDlg");
		_import("alz.ui.FlashObject");
		var w = new alz.ui.dialog.BlankDlg();
		w.initContent = function(){
			//定义最小大小
			this.m_minX = 200;
			this.m_minY = 200;
			var body = this.getBody();
			this.m_content = this.m_win.document.createElement("div");
			this.m_content.className = "uiContent";
			this.m_content = body.appendChild(this.m_content);
			body.ptr = this;
			this.setWindowCaption("我的TataWe加载中……", null);
			this.flash = new alz.ui.FlashObject();
			this.flash.create(this.m_content, application.getNewFlashID(), 0, __config.tataweFlash + "?wid=" + wid + "&hidetitle=true", "tatawe", "340", "350", true);
			this.resize(body.offsetWidth, body.offsetHeight);
			var obj = this;
			this.m_onClose = [];
			this.m_onClose.push(function(){obj.onClose();});
			return true;
		};
		w.onResize = function(w, h){
			if(this.flash)
				this.flash.resize(this.m_content.offsetWidth, this.m_content.offsetHeight);
		};
		w.onClose = function(){
			if(this.flash){  //销毁 flash 组件
				this.flash._self.closeTTW();
				this.flash.dispose();
				delete this.flash;
			}
			application._windowMgr.unregisterWindow(this.m_id);
		};
		w = application._windowMgr.createDlg(w, id, "我的TataWe", "", null, 630, 100, 330, 400, true, true, "close");  //最后三个参数resizable, active, type
		return;
	};
	//发送信息后的回调函数
	this.js_sendresult = function(data){
		if(application.httplog)
			application.httplog(data);
		else
			application.user.sendResult = data;
	};
	//----miniApp和application都要使用的全局函数------------------------------------
	//----将下面的全局函数尽可能的转移到application中-------------------------------
	this.$ = function(obj){
		return typeof(obj) != "string" ? obj : window.document.getElementById(obj);
	};
	this.sortLogins = function(a, b){
		if(!a && !b) return 0;
		if(!a || !a.getName) return -1;
		if(!b || !b.getName) return 1;
		if(a.getName().toLowerCase() < b.getName().toLowerCase()) return -1;
		if(a.getName() > b.getName()) return 1;
		return 0;
	};
	this.sortBuddies = function(a, b){
		if(!a && !b) return 0;
		if(!a || !a.getAlias) return -1;
		if(!b || !b.getAlias) return 1;
		var aAlias = application.normalizeString(a.getAlias());
		var bAlias = application.normalizeString(b.getAlias());
		if(aAlias < bAlias) return -1;
		if(aAlias > bAlias) return 1;
		return 0;
		//return sortLogins(a, b);  //[alz]没有用到
	};
	this.sortGroups = function(a, b){
		if(!a && !b) return 0;
		if(!a) return -1;
		if(!b) return 1;
		if(a.toLowerCase() < b.toLowerCase()) return -1;
		if(a.toLowerCase() > b.toLowerCase()) return 1;
		return 0;
		//return sortLogins(a, b);  //[alz]没有用到
	};
	this.API_userRegister = function(){
		try{
			if(!application){
				webappEnv.initApp();
			}
			//application._windowMgr.createJoinDlg();
			application._windowMgr.createMyImtataWindow(true);
		}catch(e){
			webappEnv.showException(e, "API_userRegister");
		}
	};
}).apply(this);

	/**
	 * 扩展内建类 Date 的方法
	 */
	var _p = Date.prototype;
	/**
	 * 将日期对象格式化成指定格式的字符串
	 * @param type 格式编号
	 *        0 = 2007-2-2 0:01:05
	 *        1 = 2007年2月2日
	 *        2 = 2007-2-2
	 *        3 = 0:01:05
	 *        4 = 00:01
	 *        5 = 2007-02-02
	 *        6 = 0702
	 *        7 = 000105
	 *        8 = 00:01 123
	 */
	_p.toMyString = function(type){
		var y = this.getYear();
		var m = this.getMonth() + 1;
		var d = this.getDate();
		var h = this.getHours();
		var n = this.getMinutes();
		var s = this.getSeconds();
		var ms = this.getMilliseconds();
		switch(type){
		case 1:  //2007年2月2日
			return y + "\u5e74" + m + "\u6708" + d + "\u65e5";  //y + "年" + m + "月" + d + "日"
		case 2:  //2007-2-2
			return y + "-" + m + "-" + d;
		case 3:  //0:01:05
			return h + ":" + n + ":" + s;
		case 4:  //00:01
			return n + ":" + s;
		case 5:  //2007-02-02
			return y
				+ "-" + (m < 10 ? "0" + m : m)
				+ "-" + (d < 10 ? "0" + d : d);
		case 6:  //0702
			return ("" + y).substr(2) + (m < 10 ? "0" + m : m);
		case 7:  //000105
			return "" + (h < 10 ? "0" + h : h)
				+ (n < 10 ? "0" + n : n)
				+ (s < 10 ? "0" + s : s);
		case 8:  //00:01 123
			return n + ":" + s + " " + ms;
		case 9:  //0:00:01 123
			return h + ":" + n + ":" + s + " " + ms;
		case 0:  //2007-2-2 0:01:05
		default:
			return y + "-" + m + "-" + d + " " + h + ":" + n + ":" + s;
		}
	};