var _main_panel = null;

var active_tree_menu = 'calling-card';
var active_tree_node = null;

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};

function popupWindowForAactiveService(atm) {
	if (authuser_info.memtype == 'P' || (!pininfo.pin || pininfo.pin == '')) { 
		return false;
	}
	
	if (atm == 'follow-me') {
		if (pininfo.followmeid == '' || pininfo.followmestatus  == 'K') {
			goto_serviceActivation('FLM');
			return true;
		}
	} else if (atm == 'conf') {
		if (pininfo.confid == ''  || pininfo.confstatus  == 'K') {
			if (authuser_info.memtype == 'P') {	// PBX extension user
				goto_extConfActivation();	// activate PBX extension conference
			} else {
				goto_serviceActivation('MET');
			}
			return true;
		}
	} else if (atm == 'biz-pbx') {
		if (pininfo.pbxid == ''  || pininfo.pbxstatus  == 'K') {
			goto_serviceActivation('PBX');
			return true;
		}
	} else if (atm == 'fax') {
		if (pininfo.faxid == ''  || pininfo.faxstatus  == 'K') {
			goto_serviceActivation('FAX');
			return true;
		}
	} else if (atm == 'ipphone') {
		if (pininfo.pc2phoneid == '') {
			goto_serviceActivation('P2P');
			return true;
		}
	} else if (atm == 'web800') {
		if (pininfo.w8bid == '') {
			goto_serviceActivation('W8B');
			return true;
		}
	} else {	//Calling Card
		if (canchangeani != 'y') {	//无管理ANI权限或最大主叫绑定数为0
			goto_serviceActivation('CAC');
			return true;
		}
	}
	
	return false;
	
}

function getServiceIDByActiveMenu(menu) {
	var sid = '';
	if (menu == 'calling-card') {
		if (service != 'CAC') {
			service = 'CAC';
		}
		if (ispinlogin) {
			serviceTab_initTitle = i18n_leftmenu.item_callingcard2 + ' » ' + i18n_leftmenu.item_callingcard2_sub_animan;
		} else {
			serviceTab_initTitle = i18n_leftmenu.item_callingcard + ' » ' + i18n_leftmenu.item_callingcard_sub_animan;
		}
	} else if (menu == 'follow-me') {
		sid = pininfo.followmeid;
		if (service != 'FLM') {
			service = 'FLM';
		}
		serviceTab_initTitle = i18n_leftmenu.item_followme + ' » ' + i18n_leftmenu.item_sub_setting;
	} else if (menu == 'fax') {
		sid = pininfo.faxid;
		if (service != 'FAX') {
			service = 'FAX';
		}
		serviceTab_initTitle = i18n_leftmenu.item_click2fax + ' » ' + i18n_leftmenu.item_sub_setting;
	} else if (menu == 'conf') {
		sid = pininfo.confid;
		if (service != 'MET') {
			service = 'MET';
		}
		if (ispinlogin) {	//卡登录用户
			serviceTab_initTitle = i18n_leftmenu.item_conf + ' » ' + i18n_leftmenu.item_conf_sub_passcode;
		} else {
			serviceTab_initTitle = i18n_leftmenu.item_conf + ' » ' + i18n_leftmenu.item_conf_sub_confman;
		}
	} else if (menu == 'biz-pbx') {
		sid = pininfo.pbxid;
		if (service != 'PBX') {
			service = 'PBX';
		}
		serviceTab_initTitle = i18n_leftmenu.item_pbx + ' » ' + i18n_leftmenu.item_pbx_sub_extman;
	} else if (menu == 'mmd') {	//Music-Broadcasting
		sid = '';
		if (service != 'GMS') {	//Music-Broadcasting
			service = 'GMS';
		}
		serviceTab_initTitle = i18n_leftmenu.item_groupsend + ' » ' + i18n_leftmenu.item_groupsend_sub_send;
	} else if (menu == 'toPhone') {	//Click2Phone
		sid = '';
		if (service != 'C2P') {	//Click2Phone
			service = 'C2P';
		}
		serviceTab_initTitle = i18n_leftmenu.item_click2phone + ' » ' + i18n_leftmenu.item_click2phone;
 	} else if (menu == 'ipphone') {
		sid = pininfo.pc2phoneid;
		if (service != 'P2P') {	//IPPhone
			service = 'P2P';
		}
		//serviceTab_initTitle = i18n_leftmenu.item_pc2phone + ' » ' + i18n_leftmenu.item_pc2phone_sub_setting;
		serviceTab_initTitle = i18n_leftmenu.item_pc2phone + ' » ' + i18n_leftmenu.item_pc2phone_sub_config
	} else if (menu == 'sms') {
		sid = '';
		if (service != 'SMS') {
			service = 'SMS';
		}
	} else if (menu == 'mms') {
		sid = '';
		if (service != 'MMS') {
			service = 'MMS';
		}
	} else if (menu == 'web800') {	// Web 800号
		sid = pininfo.w8bid;
		if (service != 'W8B') {
			service = 'W8B';
		}
 	}
 	
 	if (authuser_info.memtype != 'P') {
	 	if (sid && sid != '') {
	 		sid = '&nbsp;(' + sid + ')';
	 		return sid;
	 	} else {
	 		return '';
	 	}
 	} else {
 		return '';
 	}
}

function getNodeTitleByActiveMenu(menu) {
 	if (menu == 'calling-card') {
 		return i18n_leftmenu.item_callingcard;
 	} else if (menu == 'follow-me') {
 		return i18n_leftmenu.item_followme;
 	} else if (menu == 'conf') {
 		return i18n_leftmenu.item_conf;
 	} else if (menu == 'biz-pbx') {
 		return i18n_leftmenu.item_pbx;
	} else if (menu == 'fax') {
 		return i18n_leftmenu.item_click2fax;
 	} else if (menu == 'toPhone' || menu == 'ipphone') {
 		return i18n_leftmenu.item_pc2phone;
 	} else if (menu == 'web800') {
 		return i18n_leftmenu.item_web800;
 	} else if (menu == 'mmd') {
 		return i18n_leftmenu.item_groupsend;
 	} else if (menu == 'mms') {
 		return i18n_leftmenu.item_mms;
 	} else if (menu == 'sms') {
 		return i18n_leftmenu.item_sms;
 	}
}

function LocalActionExec(service_panel_id, service_action_tab_id) {
	var cmp = Ext.getCmp(service_panel_id);
	if (cmp != null) {
		_svcWorkContentPanel.setTitle(Ext.getCmp(service_panel_id).title + ' » ' + Ext.getCmp(service_action_tab_id).title + getServiceIDByActiveMenu(active_tree_menu)); 
		cmp.setActiveTab(service_action_tab_id);
	}
}

function LoadActionExec(url, active_menu) {
	active_tree_menu = active_menu;
	
	serviceTab_loadUrl = url;
	var serviceIdShow = getServiceIDByActiveMenu(active_menu);
	
	var activatedTabId = _svcTabPanel.getActiveTab().getId();
	if (activatedTabId == 'service-work-space') {
		if (_svcWorkContentPanel != null && (pininfo.pin && pininfo.pin.length > 0)) {
			_svcWorkContentPanel.setTitle(serviceTab_initTitle + serviceIdShow); 
			_svcWorkContentPanel.load({
				url: url,
				timeout: 120,
				scripts: true,
				nocache: true,
				callback: function(el, success, response, options){
				}
			});
			_leftMenuPanel.panel.activeMenu=active_menu;
		}
	} else {
		_svcTabPanel.activate('service-work-space');
	}
}

FeedPanel = function(cfg) {
	FeedPanel.superclass.constructor.call(this, {
		id: 'feed-tree',
		region: 'west',
		title: i18n_leftmenu.title,
		split: true,
		width: 190,
		minWidth: 190,
		height: wsHeight,
		margins: '0',
		rootVisible: false,
		lines: false,
		autoScroll: true,
		root: new Ext.tree.TreeNode('Feed Viewer'),
		disabledClass: 'x-tree-node-disabled',
		collapseFirst: false
    });
	
	this.activeMenu = cfg.activeId;
	
	this.getSelectionModel().on({
		'beforeselect': function(sm, node) {
			return node.isLeaf();
		},
		'selectionchange': function(sm, node) {
			/*
			active_tree_node = node;
			if (node.parentNode.attributes.id == this.activeMenu) {
				eval(node.local_action);
			} else {
				eval(node.load_action);
			}
			*/
		},
		scope: this
	});
	
	this.on({
		'click': function(node, e) {
			if (!node.isLeaf() ) {
				popupWindowForAactiveService(node.attributes.id);
			} else {
				active_tree_node = node;
				if (!popupWindowForAactiveService(node.parentNode.attributes.id)) {
					var activatedTabId = _svcTabPanel.getActiveTab().getId();
					if (activatedTabId == 'service-work-space') {
						if (node.parentNode.attributes.id == this.activeMenu) {
							eval(node.local_action);
						} else {
							eval(node.load_action);
						}
					} else {
						eval(node.load_action);
					}
				}
			}
		}
	});
};

Ext.extend(FeedPanel, Ext.tree.TreePanel, {
	showWindow: function(btn) {
		if(!this.win) {
			this.win = new FeedWindow();
			this.win.on('validfeed', this.addItem, this);
		}
		this.win.show(btn);
	},
	addMenu: function(id, title, tip) {
		var menu = new Ext.tree.TreeNode({
			id: id,
			text: title,
			qtip: title,
			singleClickExpand: true,
			cls: 'feeds-node',
			expanded: true,
			listeners: {beforeexpand: function(mnode,deep,anim){
				if (mnode.disabled) {
					return false;
				}
			}}
		});
		this.root.appendChild(menu);
		return menu;
	},
	setActiveItem: function(i_id) {
		var exists = this.getNodeById(i_id);
		if(exists) {
			exists.select();
			exists.ui.highlight();
		}
		var node = this.getNodeById(i_id);
		if (node != null && _svcWorkContentPanel != null) {
			_svcWorkContentPanel.setTitle(node.parentNode.attributes.text + ' » ' + node.attributes.text + getServiceIDByActiveMenu(active_tree_menu));
		}
		return;
	},
    addItem: function(menu, attrs, inactive, preventAnim) {
        var exists = this.getNodeById(attrs.id);
        if(exists){
            if(!inactive){
                exists.select();
                exists.ui.highlight();
            }
            return;
        }
        Ext.apply(attrs, {
            //iconCls: 'feed-icon',
            leaf: true,
            cls: 'feed',
            id: attrs.id,
            local_action: attrs.local_action,
            load_action: attrs.load_action,
            url: attrs.url,
            qtip: attrs.tip
        });
        var node = new Ext.ux.MenuItem(attrs);
        menu.appendChild(node);
        if(!inactive){
            if(!preventAnim){
                Ext.fly(node.ui.elNode).slideIn('l', {
                    callback: node.select, scope: node, duration: .4
                });
            }else{
                node.select();
            }
        }
        return node;
    }
});

Ext.ux.MenuItem = function(cfg) {
    Ext.ux.MenuItem.superclass.constructor.call(this, cfg);
	
	this.local_action = cfg.local_action;
	this.load_action = cfg.load_action;
	this.url = cfg.url;
}
Ext.extend(Ext.ux.MenuItem, Ext.tree.TreeNode, {});
	
LeftPanel = function(cfg){
	//LeftPanel.superclass.constructor.call(this, cfg);
    this.panel = new FeedPanel(cfg);
    this.panel.activeMenu = cfg.activeId;
    this.panel.render('content-left');
};
    
Ext.extend(LeftPanel, FeedPanel, {
	init: function() {
		if (ispinlogin) {
			i18n_leftmenu.item_callingcard = i18n_leftmenu.item_callingcard2;
			i18n_leftmenu.item_callingcard_tip = i18n_leftmenu.item_callingcard2_tip;
			i18n_leftmenu.item_callingcard_sub_chgpasswd = i18n_leftmenu.item_callingcard2_sub_chgpasswd;
			i18n_leftmenu.item_callingcard_sub_chgpasswd_tip = i18n_leftmenu.item_callingcard2_sub_chgpasswd_tip;
			i18n_leftmenu.item_callingcard_sub_animan = i18n_leftmenu.item_callingcard2_sub_animan;
			i18n_leftmenu.item_callingcard_sub_animan_tip = i18n_leftmenu.item_callingcard2_sub_animan_tip;
			i18n_leftmenu.item_sub_monthly_tip = i18n_leftmenu.item_sub_monthly2_tip;
		}
		// calling card
		if (authuser_info.memtype != 'M') {	// 非子会议室用户
			if (authuser_info.memtype != 'P') {
				var callingcard_menu = this.panel.addMenu('calling-card',i18n_leftmenu.item_callingcard, i18n_leftmenu.item_callingcard_tip);
				this.panel.addItem(callingcard_menu, {
					id: 'callingcard-animan',
					text: i18n_leftmenu.item_callingcard_sub_animan,
					tip: i18n_leftmenu.item_callingcard_sub_animan_tip,
					local_action: "LocalActionExec(callingcard_service_panel, callingcard_animan_tab)",
					load_action: "LoadActionExec(callingcard_animan_url, 'calling-card')"
				}, true);
				this.panel.addItem(callingcard_menu, {
					id: 'callingcard-monthly',
					text: i18n_leftmenu.item_sub_monthly,
					tip: i18n_leftmenu.item_sub_monthly_tip,
					local_action: "LocalActionExec(callingcard_service_panel, challingcard_monthly_tab)",
					load_action: "LoadActionExec(challingcard_monthly_url, 'calling-card')"
				}, true);
				
				if (this.panel.activeMenu != "calling-card") {
					callingcard_menu.collapse();
				}
			}
			// follow-me
			if ((authuser_info.memtype == 'P' || !(isCTEDomain() || ispinlogin)) && haveOpRight('FLM')) {
				var followme_menu = this.panel.addMenu('follow-me',i18n_leftmenu.item_followme, i18n_leftmenu.item_followme_tip);
				this.panel.addItem(followme_menu, {
					id: 'followme-msg',
					text: i18n_leftmenu.item_followme_sub_voicemail,
					tip: i18n_leftmenu.item_followme_sub_voicemail_tip,
					local_action: "LocalActionExec(followme_service_panel, followme_msg_tab)",
					load_action: "LoadActionExec(followme_msg_tab_url, 'follow-me')"
				}, true);
				this.panel.addItem(followme_menu, {
					id: 'followme-settings',
					text: i18n_leftmenu.item_sub_setting,
					tip: i18n_leftmenu.item_sub_setting_tip,
					local_action: "LocalActionExec(followme_service_panel, followme_settings_tab)",
					load_action: "LoadActionExec(followme_settings_tab_url, 'follow-me')"
				}, true);
				/* if (authuser_info.memtype != 'P' && !isCTEDomain()) {
					this.panel.addItem(followme_menu, {
						id: 'followme-monthly',
						text: i18n_leftmenu.item_sub_monthly,
						tip: i18n_leftmenu.item_sub_monthly,
						local_action: "LocalActionExec(followme_service_panel, followme_monthly_tab)",
						load_action: "LoadActionExec(followme_monthly_url, 'follow-me')"
					}, true);
				} */
				if (this.panel.activeMenu != "follow-me") {
					followme_menu.collapse();
				}
			}
			// fax
			if (!(isCTEDomain() || ispinlogin) && haveOpRight('FAX')) {
				var fax_menu = this.panel.addMenu('fax',i18n_leftmenu.item_click2fax, i18n_leftmenu.item_click2fax_tip);
				if (authuser_info.memtype != 'P') {
					this.panel.addItem(fax_menu, {
						id: 'fax-send',
						text: i18n_leftmenu.item_click2fax_sub_send,
						tip: i18n_leftmenu.item_click2fax_sub_send_tip,
	                			local_action: "LocalActionExec(fax_service_panel, fax_send_tab)",
						load_action: "LoadActionExec(fax_send_tab_url, 'fax')"
					}, true);
					this.panel.addItem(fax_menu, {
						id: 'fax-outbox',
						text: i18n_leftmenu.item_sub_outbox,
						tip: i18n_leftmenu.item_sub_outbox_tip,
						local_action: "LocalActionExec(fax_service_panel, fax_outbox_tab)",
						load_action: "LoadActionExec(fax_outbox_tab_url, 'fax')"
					}, true);
				}
				this.panel.addItem(fax_menu, {
					id: 'fax-inbox',
					text: i18n_leftmenu.item_sub_inbox,
					tip: i18n_leftmenu.item_sub_inbox_tip,
					local_action: "LocalActionExec(fax_service_panel, fax_inbox_tab)",
					load_action: "LoadActionExec(fax_inbox_tab_url, 'fax')"
				}, true);
				if (authuser_info.memtype != 'P') {
					this.panel.addItem(fax_menu, {
						id: 'fax-settings',
						text: i18n_leftmenu.item_sub_setting,
						tip: i18n_leftmenu.item_sub_setting_tip,
						local_action: "LocalActionExec(fax_service_panel, fax_settings_tab)",
						load_action: "LoadActionExec(fax_settings_tab_url, 'fax')"
					}, true);
				}
				
				if (this.panel.activeMenu != "fax") {
					fax_menu.collapse();
				}
			}
		}
		// conference
		if (authuser_info.memtype != 'P' && haveOpRight('MET')) {
			var conf_menu = this.panel.addMenu('conf',i18n_leftmenu.item_conf, i18n_leftmenu.item_conf_tip);
			if (isCTEDomain() || ispinlogin || authuser_info.memtype == 'M') {	//卡登录用户或子会议室用户
				this.panel.addItem(conf_menu, {
					id: 'conf-passcode',
					text: i18n_leftmenu.item_conf_sub_passcode,
					tip: i18n_leftmenu.item_conf_sub_passcode_tip,
                			local_action: "LocalActionExec(conference_service_panel, conference_passcode_tab)",
					load_action: "LoadActionExec(conference_passcode_tab_url, 'conf')"
				}, true);
				this.panel.addItem(conf_menu, {
					id: 'conf-report',
					text: i18n_leftmenu.item_conf_sub_confreport,
					tip: i18n_leftmenu.item_conf_sub_confreport_tip,
					local_action: "LocalActionExec(conference_service_panel, conference_report_tab)",
					load_action: "LoadActionExec(conference_report_tab_url, 'conf')"
				}, true);
				if (authuser_info.memtype != 'M') {	// 非子会议室用户
					this.panel.addItem(conf_menu, {	// add by zxj
						id: 'conf-roomman',
						text: i18n_leftmenu.item_conf_sub_confroomman,
						tip: i18n_leftmenu.item_conf_sub_confroomman_tip,
						local_action: "LocalActionExec(conference_service_panel, conference_roomman_tab)",
						load_action: "LoadActionExec(conference_roomman_tab_url, 'conf')"
					}, true);
				}
				/* this.panel.addItem(conf_menu, {
					id: 'conf-record',
					text: i18n_leftmenu.item_conf_sub_confrec,
					tip: i18n_leftmenu.item_conf_sub_confrec_tip,
					local_action: "LocalActionExec(conference_service_panel, conference_record_tab)",
					load_action: "LoadActionExec(conference_record_tab_url, 'conf')"
				}, true); */
			} else {
				this.panel.addItem(conf_menu, {
					id: 'conf-enter',
					text: i18n_leftmenu.item_conf_sub_enter,
					tip: i18n_leftmenu.item_conf_sub_enter_tip,
                			local_action: "LocalActionExec(conference_service_panel, conference_enter_tab)",
					load_action: "LoadActionExec(conference_enter_tab_url, 'conf')"
				}, true);
				this.panel.addItem(conf_menu, {
					id: 'conf-man',
					text: i18n_leftmenu.item_conf_sub_confman,
					tip: i18n_leftmenu.item_conf_sub_confman_tip,
					local_action: "LocalActionExec(conference_service_panel, conference_man_tab)",
					load_action: "LoadActionExec(conference_man_tab_url, 'conf')"
				}, true);
				this.panel.addItem(conf_menu, {
					id: 'conf-report',
					text: i18n_leftmenu.item_conf_sub_confreport,
					tip: i18n_leftmenu.item_conf_sub_confreport_tip,
					local_action: "LocalActionExec(conference_service_panel, conference_report_tab)",
					load_action: "LoadActionExec(conference_report_tab_url, 'conf')"
				}, true);
				this.panel.addItem(conf_menu, {
					id: 'conf-ctrl',
					text: i18n_leftmenu.item_conf_sub_confctrl,
					tip: i18n_leftmenu.item_conf_sub_confctrl_tip,
					local_action: "LocalActionExec(conference_service_panel, conference_ctrl_tab)",
					load_action: "LoadActionExec(conference_ctrl_tab_url, 'conf')"
				}, true);
				if (!(isCTEDomain() || authuser_info.memtype == 'P')) {	//etonecard和PBX分机没有会议录音功能
					this.panel.addItem(conf_menu, {
						id: 'conf-record',
						text: i18n_leftmenu.item_conf_sub_confrec,
						tip: i18n_leftmenu.item_conf_sub_confrec_tip,
						local_action: "LocalActionExec(conference_service_panel, conference_record_tab)",
						load_action: "LoadActionExec(conference_record_tab_url, 'conf')"
					}, true);
				}
				this.panel.addItem(conf_menu, {
					id: 'conf-infor',
					text: i18n_leftmenu.item_conf_sub_confinfor,
					tip: i18n_leftmenu.item_conf_sub_confinfor_tip,
					local_action: "LocalActionExec(conference_service_panel, conference_infor_tab)",
					load_action: "LoadActionExec(conference_infor_tab_url, 'conf')"
				}, true);
				/* this.panel.addItem(conf_menu, {
					id: 'conf-webconfset',
					text: i18n_leftmenu.item_conf_webconfset,
					tip: i18n_leftmenu.item_conf_webconfset_tip,
					local_action: "LocalActionExec(conference_service_panel, conference_webconfset_tab)",
					load_action: "LoadActionExec(conference_webconfset_tab_url, 'conf')"
				}, true); */
			}
			if (authuser_info.memtype != 'M') {	// 非子会议室用户
				this.panel.addItem(conf_menu, {
					id: 'conference-monthly',
					text: i18n_leftmenu.item_sub_monthly,
					tip: i18n_leftmenu.item_sub_monthly_tip,
					local_action: "LocalActionExec(conference_service_panel, conference_monthly_tab)",
					load_action: "LoadActionExec(conference_monthly_url, 'conf')"
				}, true);
			}
			
			if (this.panel.activeMenu != "conf") {
				conf_menu.collapse();
			}
		}
		if (authuser_info.memtype != 'M') {	// 非子会议室用户
			// Music-Broadcasting, Click2Phone/IPPhone
			if (!isCTEDomain() && !ispinlogin && authuser_info.memtype != 'P') {
				// music multi-delivery (GMS) -- Music-Broadcasting
				var mmd_menu = this.panel.addMenu('mmd',i18n_leftmenu.item_groupsend, i18n_leftmenu.item_groupsend_tip);
				this.panel.addItem(mmd_menu, {
					id: 'wmd-send-music',
					text: i18n_leftmenu.item_groupsend_sub_send,
					tip: i18n_leftmenu.item_groupsend_sub_send_tip,
					local_action: "LocalActionExec(wmd_service_panel, wmd_send_music_tab)",
					load_action: "LoadActionExec(wmd_send_music_tab_url, 'mmd')"
				}, true);
				this.panel.addItem(mmd_menu, {
					id: 'wmd-music-list',
					text: i18n_leftmenu.item_groupsend_sub_sended,
					tip: i18n_leftmenu.item_groupsend_sub_sended_tip,
					local_action: "LocalActionExec(wmd_service_panel, wmd_music_list_tab)",
					load_action: "LoadActionExec(wmd_music_list_tab_url, 'mmd')"
				}, true);
				/* this.panel.addItem(mmd_menu, {
					id: 'wmd-upload-excel',
					text: i18n_leftmenu.item_groupsend_sub_group,
					local_action: "LocalActionExec(wmd_service_panel, wmd_upload_excel_tab)",
					load_action: "LoadActionExec(wmd_upload_excel_tab_url, 'mmd')"
				}, true); */
				
				if (this.panel.activeMenu != "mmd") {
					mmd_menu.collapse();
				}
			
				// Click2Phone/IPPhone
				var toPhone_menu = this.panel.addMenu('toPhone',i18n_leftmenu.item_click2phone, i18n_leftmenu.item_click2phone_tip);
				this.panel.addItem(toPhone_menu, {
					id: 'toPhone-click2phone',
					text: i18n_leftmenu.item_click2phone,
					tip: i18n_leftmenu.item_click2phone_tip,
					local_action: "LocalActionExec(toPhone_service_panel, toPhone_click2phone)",
					load_action: "LoadActionExec(toPhone_click2phone_url, 'toPhone')"
				}, true);
				
				if (this.panel.activeMenu != "toPhone") {
					toPhone_menu.collapse();
				}
				
				var ipphone_menu = this.panel.addMenu('ipphone',i18n_leftmenu.item_pc2phone, i18n_leftmenu.item_pc2phone_tip);
				this.panel.addItem(ipphone_menu, {
					id: 'ipphone-setting',
					text: i18n_leftmenu.item_pc2phone_sub_setting,
					tip: i18n_leftmenu.item_pc2phone_sub_setting_tip,
					local_action: "LocalActionExec(ipphone_service_panel, ipphone_setting)",
					load_action: "LoadActionExec(ipphone_setting_url, 'ipphone')"
				}, true);
				this.panel.addItem(ipphone_menu, {
					id: 'ipphone-config',
					text: i18n_leftmenu.item_pc2phone_sub_config,
					tip: i18n_leftmenu.item_pc2phone_sub_config_tip,
					local_action: "LocalActionExec(ipphone_service_panel, ipphone_config)",
					load_action: "LoadActionExec(ipphone_config_url, 'ipphone')"
				}, true);
				
				if (this.panel.activeMenu != "ipphone") {
					ipphone_menu.collapse();
				}
			}
			// pbx
			if (authuser_info.memtype != 'P' && authuser_info.memtype != 'M' && haveOpRight('PBX')) {
				var pbx_menu = this.panel.addMenu('biz-pbx',i18n_leftmenu.item_pbx, i18n_leftmenu.item_pbx_tip);
				this.panel.addItem(pbx_menu, {
					id: 'pbx-extman',
					text: i18n_leftmenu.item_pbx_sub_extman,
					tip: i18n_leftmenu.item_pbx_sub_extman_tip,
	                		local_action: "LocalActionExec(pbx_service_panel, pbx_ext_tab)",
					load_action: "LoadActionExec(pbx_ext_tab_url, 'biz-pbx')"
				}, true);
				this.panel.addItem(pbx_menu, {
					id: 'pbx-ivrman',
					text: i18n_leftmenu.item_pbx_sub_ivrman,
					tip: i18n_leftmenu.item_pbx_sub_ivrman_tip,
					local_action: "LocalActionExec(pbx_service_panel, pbx_ivr_tab)",
					load_action: "LoadActionExec(pbx_ivr_tab_url, 'biz-pbx')"
				}, true);
				this.panel.addItem(pbx_menu, {
					id: 'pbx-dinman',
					text: i18n_leftmenu.item_pbx_sub_dinman,
					tip: i18n_leftmenu.item_pbx_sub_dinman_tip,
					local_action: "LocalActionExec(pbx_service_panel, pbx_din_tab)",
					load_action: "LoadActionExec(pbx_din_tab_url, 'biz-pbx')"
				}, true);
				this.panel.addItem(pbx_menu, {
					id: 'pbx-main2man',
					text: i18n_leftmenu.item_pbx_sub_main2man,
					tip: i18n_leftmenu.item_pbx_sub_main2man_tip,
					local_action: "LocalActionExec(pbx_service_panel, pbx_main2man_tab)",
					load_action: "LoadActionExec(pbx_main2man_tab_url, 'biz-pbx')"
				}, true);
				/* if (authuser_info.memtype != 'D' || !(pininfo.pintype == '0' || pininfo.pintype == '1' || pininfo.pintype < 2)) {	//分机转账记录：后付费用户无分机转账
					this.panel.addItem(pbx_menu, {
						id: 'pbx-exttranslog',
						text: i18n_leftmenu.item_pbx_sub_exttranslog,
						tip: i18n_leftmenu.item_pbx_sub_exttranslog_tip,
						local_action: "LocalActionExec(pbx_service_panel, pbx_exttranslog_tab)",
						load_action: "LoadActionExec(pbx_exttranslog_tab_url, 'biz-pbx')"
					}, true);
				} */
				this.panel.addItem(pbx_menu, {
					id: 'pbx-monthly',
					text: i18n_leftmenu.item_sub_monthly,
					tip: i18n_leftmenu.item_sub_monthly_tip,
					local_action: "LocalActionExec(pbx_service_panel, pbx_monthly_tab)",
					load_action: "LoadActionExec(pbx_monthly_url, 'biz-pbx')"
				}, true);
				
				if (this.panel.activeMenu != "biz-pbx") {
					pbx_menu.collapse();
				}
			}
			if (!isCTEDomain() && !ispinlogin && authuser_info.memtype != 'P' && authuser_info.memtype != 'M' && haveOpRight('W8B')) {
				var web800_menu = this.panel.addMenu('web800',i18n_leftmenu.item_web800, i18n_leftmenu.item_web800_tip);
				this.panel.addItem(web800_menu, {
					id: 'web800-msg',
					text: i18n_leftmenu.item_followme_sub_voicemail,
					tip: i18n_leftmenu.item_followme_sub_voicemail_tip,
					local_action: "LocalActionExec(web800_service_panel, web800_msg_tab)",
					load_action: "LoadActionExec(web800_msg_tab_url, 'web800')"
				}, true);
				this.panel.addItem(web800_menu, {
					id: 'web800-settings',
					text: i18n_leftmenu.item_sub_setting,
					tip: i18n_leftmenu.item_sub_setting_tip,
					local_action: "LocalActionExec(web800_service_panel, web800_settings_tab)",
					load_action: "LoadActionExec(web800_settings_tab_url, 'web800')"
				}, true);
				if (this.panel.activeMenu != "web800") {
					web800_menu.collapse();
				}
			}
		}
	},
	setActiveItem: function(i_id) {
		this.panel.setActiveItem(i_id);
	},
	setPanelHeight: function(height) {
		this.panel.setHeight(height);
	},
	setDisabled: function(disabled) {
		if (disabled) {
			if (!this.panel.disabled) {
				this.panel.disable(); 
			}
		} else {
			if (this.panel.disabled) {
				this.panel.enable(); 
			}
		}
	},
	expandAll: function() {
		this.panel.expandAll();
	},
	collapseAll: function() {
		this.panel.collapseAll();
	},
	resetActiveMenu: function(menuId) {
		this.panel.activeMenu = menuId;
		this.panel.collapseAll();
		var nodeCmp = this.panel.getNodeById(menuId);
		if (typeof(nodeCmp) != 'undefined' && nodeCmp) {
			nodeCmp.expand();
		}
		active_tree_menu = menuId;
	},
	setActiveMenu: function(menuId) {
		this.panel.activeMenu = menuId;
		var nodeCmp = this.panel.getNodeById(menuId);
		if (typeof(nodeCmp) != 'undefined' && nodeCmp) {
			nodeCmp.expand();
		}
		active_tree_menu = menuId;
	},
	disableItem: function(itemId) {
		var nodeCmp = this.panel.getNodeById(itemId);
		if (typeof(nodeCmp) != 'undefined' && nodeCmp) {
			nodeCmp.disable();
			nodeCmp.collapse();
		}
	},
	enableItem: function(itemId) {
		var nodeCmp = this.panel.getNodeById(itemId);
		if (typeof(nodeCmp) != 'undefined' && nodeCmp) {
			nodeCmp.enable();
			if (active_tree_menu == itemId) {
				nodeCmp.expand();
			}
		}
	},
	removeItem: function(itemId) {
		var nodeCmp = this.panel.getNodeById(itemId);
		if (typeof(nodeCmp) != 'undefined' && nodeCmp) {
			nodeCmp.remove();
		}
	},
	addItem: function(pitemId, attrs, inactive) {
		var nodeCmp = this.panel.getNodeById(attrs.id);
		if (typeof(nodeCmp) != 'undefined' && nodeCmp) {
			return;
		}
		var pnodeCmp = this.panel.getNodeById(pitemId);
		if (typeof(pnodeCmp) != 'undefined' && pnodeCmp) {
			this.panel.addItem(pnodeCmp, attrs, inactive);
		}
	}
});

function haveOpRight(service) {
	if (servicerights == '') {
		return true;
	}
	// String right：1:V-PBX,2:Conference,3:Follow-Me,4:IPPhone;5:FAX,6:WEB 800
	var strlen = servicerights.length;
	if (service == 'PBX') {
		if (strlen > 0) {
			if (servicerights.substring(0,1) == "1") {
				return true;
			} else {
				return false;
			}
		} else {
			return true;
		}
	} else if (service == 'MET') {
		if (strlen > 2) {
			if (servicerights.substring(1,2) == "1") {
				return true;
			} else {
				return false;
			}
		} else {
			return true;
		}
	} else if (service == 'FLM') {
		if (strlen > 0) {
			if (servicerights.substring(2,3) == "1") {
				return true;
			} else {
				return false;
			}
		} else {
			return true;
		}
	} else if (service == 'P2P') {
		if (strlen > 3) {
			if (servicerights.substring(3,4) == "1") {
				return true;
			} else {
				return false;
			}
		} else {
			return true;
		}
	} else if (service == 'FAX') {
		if (strlen > 1) {
			if (servicerights.substring(4,5) == "1") {
				return true;
			} else {
				return false;
			}
		} else {
			return true;
		}
	} else if (service == 'W8B') {
		if (strlen > 6) {
			if (servicerights.substring(5,6) == "1") {
				return true;
			} else {
				return false;
			}
		} else {
			return true;
		}
	} else {
		return true;
	}
}

