function showWaitingLayer(){
	var _waitingDiv = document.all("_waitingDiv");
	if(_waitingDiv == null){
		_waitingDiv = document.createElement('<div id="_waitingDiv" style="display:none;position:absolute;left:0px;top:0px;width:100%;height:100%;"></div>');
		_waitingDiv.innerHTML = "<TABLE width=\"100%\" height=\"100%\"><TR><TD align=\"center\"><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"140\" height=\"30\" id=\"loadingbar\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"movie\" value=\"web/public/js/loadingbar.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><param name=\"bgcolor\" value=\"#ffffff\" /><embed src=\"web/public/js/loadingbar.swf\" quality=\"high\" wmode=\"transparent\" bgcolor=\"#ffffff\" width=\"140\" height=\"30\" name=\"loadingbar\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object></TD></TR></TABLE><div style=\"background:black;filter:alpha(opacity=0);width:100%;height:100%;position:absolute;left:0;top:0;z-index:10000;\"></div>";
		document.body.appendChild(_waitingDiv);
	}
	if(_waitingDiv != null){
		_waitingDiv.style.cursor = "wait";
		_waitingDiv.style.display = "block";
	}
}

function hideWaitingLayer(){
	var _waitingDiv = document.all("_waitingDiv");
	if(_waitingDiv!=null){
		_waitingDiv.style.cursor = "default";
		_waitingDiv.style.display = "none";
	}
}

///////////////// 带附件的Ajax提交 //////////////////////

/**
 * 带附件的Ajax提交
 */
function ajaxUploadRequest(uForm, options) {
	document.getElementById("uIframeID").options = options;

	var url = uForm.action;
	if (!url || url.trim().length == 0) {
		alert("请输入URL信息!");
		return;
	}

	if (options && options.params) {
		for (var name in options.params) {
			var value = options.params[name];

			if (typeof value != "function") {
				var _input = document.getElementById(name + "ID");
				_input = _input || document.createElement("input");
				_input.id = name + "ID";
				_input.name = name;
				_input.value = value;
				_input.type = "hidden";
				uForm.appendChild(_input);
			}
		}
	}
	
	uForm.action = mergeParameter(uForm.action, {formAjax: true});
	
	waiting = Waiting.instance();
	waiting.setWaitingInfo({process: 50, message: "正在处理数据..."});
	waiting.show();
	document.getElementById("uIframeID").waiting = waiting;
	
	uForm.method = "post";
	uForm.target = "uIframe";
	uForm.enctype = "multipart/form-data";
	uForm.submit();
}

function uploadSuccess() {
	var iframe = document.getElementById("uIframeID");
	if (!iframe.init) {
		iframe.init = true;
		return;
	}
	
	var options = iframe.options;
	if (!options || !options.onSuccess) 
		return;
	
	var result = eval("obj=" + toString(iframe.contentWindow.result));
	var event = {
		value: result
	};
	
	iframe.waiting.hide();
	if (!result.exception)
		options.onSuccess(event);
	else {
		if (typeof options.onFailed == "function") 
			options.onFailed();
		else 
			alert(result.exception);
	}
}

////////////////// 加载 /////////////////

function Waiting() {
	_this = this;
	
	this.ajax = null;
	
	this.element = document.createElement("div");
	this.element.className = "Waiting";

	var tab = document.createElement("div");
	tab.className = "tab1";
	this.element.appendChild(tab);
	
	this.title = document.createElement("div");
	this.title.style.height = "1em";
	this.title.align = "center";
	tab.appendChild(this.title);
	
	tab = document.createElement("div");
	tab.className = "tab2";
	this.element.appendChild(tab);
	
	var loading = document.createElement("div");
	loading.className = "loading";
	this.element.appendChild(loading);
	
	this.message = document.createElement("div");
	loading.appendChild(this.message);
	
	this.bar = document.createElement("div");
	this.bar.className = "bar";
	loading.appendChild(this.bar);
	
	Waiting.element.style.textAlign = "center";
	process.appendChild(this.element);
	
	this.process = "0%";
	
	this.show = function() {
		Waiting.element.style.display = "";
	}
	
	this.setWaitingInfo = function(info) {
		var process = info.process || "75%";
		if (typeof process == "number") process = process + "%";
		this.bar.style.width = process;
		this.process = process;
		
		var title = info.title || "";
		this.title.innerHTML = title + "(" + process + ")";
		
		var message = info.message || "正在处理数据...";
		this.message.innerHTML = message;
		
	}
	
	this.setAjax = function(_ajax) {
		this.ajax = _ajax;
		if (!this.ajax) return;
		
		this.title.onclick = function() {
			_this.ajax.abort();
			_this.hide();
		}
	}
	
	this.hide = function() {
		this.element.removeNode(true);
		Waiting.element.style.display = "none";
	}
	
}

Waiting.element = null;
Waiting.create = function() {
	var _waitingDiv = document.getElementById("_waitingDiv1");
	if (!_waitingDiv) {
		_waitingDiv = document.createElement('<div id="_waitingDiv1" style="display:none;position:absolute;left:0px;top:0px;width:expression(this.document.body.clientWidth);height:expression(this.document.body.clientHeight);"></div>');
		_waitingDiv.innerHTML = "<div style='color:red;width:50%;z-index:20000;' id='process'></div><div style=\"background:gray;filter:alpha(opacity=0);width:expression(this.document.body.clientWidth);height:expression(this.document.body.clientHeight);position:absolute;left:0;top:0;z-index:10000;\"></div>";
		document.body.appendChild(_waitingDiv);
	}
	
	var pHeight = parseInt(process.parentNode.style.height);
	process.style.position = "relative";
	process.style.textAlign = "center";
	process.style.top = pHeight / 2;
	
	Waiting.element = _waitingDiv;
}
window.attachEvent('onload', Waiting.create);

Waiting.instance = function() {
	if (Waiting.element == null) return;
	
	var _waiting = new Waiting();
	return _waiting;
}

/////////////// AJAX Request /////////////////////

function AjaxRequest(_method,_url,_async){
	var oThis = this;
	var value = null;
	var text = null;
	var xmlhttp=false;
	var parameters = new Object();
	this.waiting = null;

	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	}
	
	xmlhttp.open(_method,_url,_async);
	xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 1) {
			oThis.setWaitingInfo({process:50, message:"正在处理数据..."});

			oThis.oncreate();
			
		} else if (xmlhttp.readyState == 2) {
			oThis.setWaitingInfo({process:50, message:"正在处理数据..."});
			
			oThis.onsend();
			
		} else if (xmlhttp.readyState == 3) {
			oThis.setWaitingInfo({process:75, message:"正在接收数据..."});

			oThis.onprocess();
			
		} else if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200){
				text = xmlhttp.responseText;
				
				oThis.setWaitingInfo({process:95, message:"正在解析数据..."});

				oThis.onresult();

				if (typeof oThis.waiting == "object" && oThis.waiting)
					oThis.waiting.hide();
			} else {
				if (xmlhttp.status==404){
					alert("URL: (" + _url + ") doesn't exist!");
				} else {
					if (xmlhttp.status == 0) 
						alert("请求已被中止!");
					else
						alert("Status is " + xmlhttp.status);
				}
			}
		}
	}

	this.setParameter = function(name,value) {
		parameters[name]=value;
	}

	this.send = function(v){
		// 判断是否显示进度窗口
		if (this.waiting != false) {
			if (this.waiting == null || this.waiting == true)
				this.waiting = Waiting.instance();

			this.waiting.setAjax(this);
			this.waiting.show();
			
		}
		
		value = null;
		var info = [];
		info[0] = "ajax=true";
		for(key in parameters){
			var kv = parameters[key];
			if (typeof kv == "function") 
				continue;
			else if (typeof kv == "string") {
				kv = kv.replace(/%/g, "%25");
				kv = kv.replace(/&/g, "%26");
			}

			info[info.length] = key + "=" + kv;
		}
		var i = info.join("&");
		xmlhttp.send(i);
	}
	this.getValue = function(){
		if(value==null){
			try{
				var r = "value=" + text;
				value = eval(r);
			}catch(e){
				alert("exception throwed when eval:\n"+ text);
				value = {};
				value.exception = e;
			}
		}
		return value;
	}
	
	this.getText = function(){
		return text;
	}
	
	this.abort = function() {
		xmlhttp.abort();
	}
	
	/**
	 * 设置进程窗口信息
	 */
	this.setWaitingInfo = function(info) {
		var _waiting = oThis.waiting;
		if (typeof _waiting == "object" && _waiting != null)
			_waiting.setWaitingInfo(info);
	}
	
	this.oncreate = function() {}	// 请求已经建立
	this.onsend = function() {}		// 请求已经发送
	this.onprocess = function() {}	// 请求处理中
	this.onresult = function() {}	// 完成
 }