function Chelp(){
	var _this = this;
	_this.waitWindow = null;
	_this.helpWindow = null;
	
	//显示帮助窗口
	var showHelpWindow = function(title, content, animobj){
		if (_this.helpWindow) {_this.helpWindow.close(); _this.helpWindow.destroy(); _this.helpWindow=null;}
		if (!_this.helpWindow) {
			_this.helpWindow = new Ext.Window({
				closeAction: 'hide', modal: true, plain: true, resizable: true, header: true,
				closable: true, maximizable: true, shadow: true,
				autoHeight: false, width: 766, height:400,
				autoScroll: true,
				title: title,
				html: '<div class="help_body">'+content+'</div>',
				buttons:[
					{xtype:'button', text:'确定', handler:hideHelpWindow}
				]
				
			});
		}
		_this.helpWindow.show(animobj);
	}
	//关闭帮助窗口
	var hideHelpWindow = function(){
		_this.helpWindow.hide();
	}
	
	//显示等待窗口
	var showWaitWindow = function(msgstr){
		if (_this.waitWindow) {_this.waitWindow.hide(); _this.waitWindow = null;}
		if (!_this.waitWindow) {
			if (typeof(msgstr)=='undefined') msgstr = '请稍候...';
			_this.waitWindow = new Ext.LoadMask(Ext.getBody(), {msg:msgstr, removeMask:true});
		}
		_this.waitWindow.show();
	}
	//关闭等待窗口
	var hideWaitWindow = function(){
		if (_this.waitWindow) _this.waitWindow.hide();
	}
	
	var refreshWin = function(){
		document.location.reload();
	}
	
	var getHelpContent = function(title, animobj){	
		//显示等待窗口
		showWaitWindow();
		
		//参数字符串
		var paras = "opr=getContent&title="+title;
		
		//提交
		Ext.Ajax.request({
	        url: g_path + 'com/help/help.php',
	        params: paras,
	        success: function(response, options){
	        	hideWaitWindow();		//隐藏进度条
	            try{
		        	var rjdata = Ext.util.JSON.decode(response.responseText);
	
		            if (rjdata.success==true) {
		            	animobj.attributes.helpdata.nodeValue = qpDHanzi(rjdata.data);
		            	
						//var cp = new Ext.state.CookieProvider();
						//var content = cp.encodeValue(qpDHanzi(rjdata.data));
						//cp.set('cn2live_help_'+title, content);
		            	
		            	showHelpWindow(title, qpDHanzi(rjdata.data), animobj);
		            }
		            else{
		            	Ext.Msg.show({minWidth:300, title:'帮助', msg:qpDHanzi(rjdata.data), buttons: Ext.Msg.OK, icon:Ext.MessageBox.WARNING});
		            }
				}
				catch(e){alert(e.message + "\r\n\r\n" + response.responseText);}
	        },
	        failure: function(){
	        	_this.waitWindow.hide();		//隐藏进度条
	        	alert('意外错误，请与管理员联系');
	        }
	    });
	}
	
	this.showHelp = function(animobj) {
		var srcobj = Ext.get(animobj);
		
		var content = srcobj.dom.attributes.helpdata.nodeValue;
		var title = srcobj.dom.attributes.helpkey.nodeValue;
		
		try{
			if (content.length>0) {
				showHelpWindow(title, content, animobj);
			}
			else{
				//var cp = new Ext.state.CookieProvider();
				//content = cp.get('cn2live_help_'+title);
				//content = cp.decodeValue(content);
				//
				//if (typeof(content)!='undefined') {
				//	showHelpWindow(title, content, animobj);
				//}
				//else{
				//	getHelpContent(title, animobj);
				//}
				getHelpContent(title, animobj);
			}
		}
		catch(e){
			alert(e.message);
		}
	}
	
	this.init = function(nameflag) {
		Ext.select('.'+nameflag).on('click',function(a,srcdom,c){
			//alert(srcdom.innerHTML);
			_this.showHelp(srcdom);
		});
	}
}

Ext.onReady(function(){
	var m_chelp = new Chelp();
	m_chelp.init('help');
});