var WindowUtil = Class.create({
	initialize: function(options,events){
		this.options = {
			type:""
		};
		this.events = {};
		this.url="/ajax/showwindow.html";
		Object.extend(this.options, options ||{});
		Object.extend(this.events, events ||{});
		(this.events["onInitialize"] || Prototype.emptyFunction)(this);
	},
	/**
	 * @alias WindowUtil.prototype.showWindow
	 */
	showWindow: function(){
		initRenheBox("<div id=window_" + this.options.type + "><table><tr><td><p class='padding10 center'>载入中...</p></td></tr></table></div>", null, false);
		this.initWindow();
	},
	initWindow: function(){
		var ajax=new Ajax.Request(this.url,{
			parameters: this.options,
			onSuccess: function(res){
				var value = null;
				if(res.responseText=="null"){
					hideLoadbox();
				}
				eval(res.responseText);
				if (value != "null" && value!="") {
					ajax.window.setValue(value);
				}else {
					hideLoadbox();
				};
			},
			onFailure: function(){
			    alert('页面载入出错，请与管理员联系。');
			    hideLoadbox();
			},
			onException: function(){
			   alert('页面载入出错，请与管理员联系。');
			   hideLoadbox();
			}
		})
		ajax.window=this;
	},
	setValue: function(value){
		$("window_" + this.options.type).update(value);
	},
	runEvent: function(eventFunction,options){
		(this.events["on"+eventFunction] || Prototype.emptyFunction)(options);
	}
});
