PageSourceSearch

https://lil20005.org.tw/ext-js/app/common/zyFunction.js?v=260208003031

js lil20005.org.tw collected 2026-10-07 13:37:09 UTC 198,713 bytes, 5,789 lines download raw bytes

1/*
2 * ZyXEL Library 1.0
3 * 09/12/2008
4 * Copyright(c) 2008-2010, ZyXEL cop.
5 * Jerry san
6 * [email protected]
7 * http://www.zyxel.com
8 */
9/* ext-js default images path */
10Ext.BLANK_IMAGE_URL = '/ext-js/ext/resources/ext-theme-classic/images/tree/s.gif';
11/* define CGI */
12var zyCGI = "/cgi-bin/zysh-cgi?filter=js2";
13var zyCGI_P = "/cgi-bin/zysh-cgi";
14var zyCGI2_P = "/cgi-bin/zysh-cgi2";
15var _zldAppGlobal = null;
16var zyBootModuleDebugFlag = false;
17var cp = new Ext.state.CookieProvider({
18	expires: new Date(new Date().getTime()+(1000*60*60*24*30)) //30 days
19});
20
21var wanqsbtnClick = null , vpnqsbtnClick = null , ravpnqsbtnClick = null;
22var DEFAULT_RULE_NO = 99999;
23/* var DEFAULT_PAGE_SIZE = 99999; */
24var GRID_DEFAULT_PAGE_SIZE = 50;
25var GRID_RECORD_CURRENT = null;
26var RADIO_INFO = [];
27//store selected grid
28var selectedGridIds=[];
29var product_name;
30var apmodel = '1';
31var apstatus = 0;
32var apkeyword = '';
33if(typeof ZLDSYSPARM_TOPN_SHOW_DAYS != "undefined"){
34	if (ZLDSYSPARM_TOPN_SHOW_DAYS==1){
35		var topn_select_day = 'logday0';
36	}else{
37		var topn_select_day = 'logday9';
38	}
39}
40var topn_start_day = '0000-00-00';
41var topn_end_day = '0000-00-00';
42var usageby ='2';
43var usagebystr = 'MB';
44var topn_usage_unit = 5*1024*1024*1024;
45//wireless health default value
46var radio_alert ='5G';
47var station_alert='all';
48var wirless_health_top=10;
49/* window click default value setup */
50var _clicked = true;
51/*lan provision setting */
52var virtual_data = 'no';
53/* help path defalut value setup */
54var help_path;
55var kb_path;
56
57/* URL update post tiomeout setting 3 minutes, Jerry san */
58//Ext.Updater.defaults.timeout = 3*60;
59
60//Ext.state.Manager.setProvider(cp);
61Ext.QuickTips.init();
62Ext.tip.Tip.prototype.minWidth = 'auto';
63Ext.form.Field.prototype.msgTarget = 'side';
64
65/* if a lot of pages call the same page A, the page A will use whoCallMe to get the caller.
66 * Note: whoCallMe is a relative path like 'license/update/idp', please refer to license/update/idp.js.
67 */
68var whoCallMe='';
69var whoOpenAry= [];
70var whoOpen ={};
71var errNo = 0;
72var zyshDead = false;
73/* user for auto execute updating date time
74 * Note: if you want this to do other task, please refer to dashboard.js or datetime.js.
75 */
76var runTask = new Ext.util.TaskRunner();
77var TimeRunTask = new Ext.util.TaskRunner();
78var secuReporterRunTask = new Ext.util.TaskRunner();
79var bufferRec = null; //used for buffer record, please refer to l2tp.js
80var keepMe = false;//keep session from triggerring onbeforeunload handler, see configfile.js for detail.
81var isAdmin = true;//Used to check login user type
82var uagProduct = /^(uag4100||uag5100)$/.test(ZLDSYSPARM_PRODUCT_NAME);
83var usgLocalAPProduct = /^(usg60w||usg40w)$/.test(ZLDSYSPARM_PRODUCT_NAME);
84var hybridMode = (uagProduct) ? 'controller' :null;
85var Exposed_Srv_Window_Close = 0;
86var SecuReporter_Conn_Status;
87var SecuReporter_Device_Info;
88var SecuReporter_Orgs_Store;
89var SecuReporter_Banner_Close = ((readCookie('secuRtBannerClsCookie')!=null)?readCookie('secuRtBannerClsCookie') == 'login'?0:readCookie('secuRtBannerClsCookie'):0);
90
91var _GUI_SHOW_ADVANCED = true;
92
93//CDR
94var CDR_IP = '';
95
96function gettooltip(targetID,html){
97	var tip = Ext.create('Ext.tip.ToolTip', {
98		target: targetID,
99		html: html
100	});
101	return tip;
102}
103function initTask() {
104	bufferRec = null;
105	runTask.stopAll();
106}
107function chkallprofilename(strpn){
108    if(strpn=='no-cli'||strpn=='wtp-cli'||strpn=='all'||strpn=='rule_count'||strpn=='cli'||strpn=='sub-cli'||strpn=='disable'){
109        return 1;
110    }
111}
112var CHFW_runTask = new Ext.util.TaskRunner();
113function CHFW_initTask() {
114	CHFW_runTask.stopAll();
115}
116
117
118/* dashboard interval timer default setting */
119var timerId = {
120	//T5App:{name:'T5AppTimer', t:0}, T5Sion: {name:'T5SionTimer', t:0}, portSts: {name:'portStsTimer', t:0},
121	vrpanel:{name: 'vrpanelTimer', t:0}, devInfo:{name: 'devInfoTimer', t:0}, sysRes:{name: 'sysResTimer', t:0},
122	sysSta:{name:'sysStaTimer', t:0}, LiceSt:{name: 'LiceStTimer', t:0}, T5AV:{name:'T5AVTimer', t:0},
123	T5IDP:{name: 'T5IDPTimer', t:0}, ifaceSta:{name: 'ifaceStaTimer', t:0}, extSlot:{name: 'extSlotTimer', t:0}, CFstat:{name: 'CFstatTimer',t:0},
124	apInfo:{name:'apInfoTimer', t:0}, T5STA:{name: 'T5STATimer', t:0}, ZyMeshAPInfo:{name:'ZyMeshAPInfoTimer', t:0},
125	T5FW:{name: 'T5FWTimer', t:0}, T5FW6:{name: 'T5FWTimer', t:0}, AlertLog:{name:'AlertLogTimer', t:0}
126};
127
128/* treePanel record's */
129var treeRec = {
130	monitor:{ tabId:'', treeNodeId:''},
131	config:{ tabId:'', treeNodeId:''},
132	maintenance:{ tabId:'', treeNodeId:''}
133};
134
135var treeItem = treeRec.monitor;
136
137/* default polling time, \sysstatus\port.js used */
138var defaultInterval =5;
139var btn_status = 1;//start
140
141/* FQDN */
142var deviceFQDN='';
143/* IPv4_ATTR_FLAG is IPv4, IPv6_ATTR_FLAG is IPv6, Common_ATTR_FLAG is IPv4+IPv6
144*/
145var IPv4_ATTR_FLAG = 1 << 0;
146var IPv6_ATTR_FLAG = 1 << 1;
147var Common_ATTR_FLAG = IPv4_ATTR_FLAG | IPv6_ATTR_FLAG;
148var filterFlag = Common_ATTR_FLAG;
149
150/* feature flags */
151var MON_PROFILE_SUPPORT = typeof ZLDCONFIG_WLAN_MON_MODE_SERVER_SUPPORT == "undefined" ? false : ZLDCONFIG_WLAN_MON_MODE_SERVER_SUPPORT;
152var MULTIPATH_TRUNK_SUPPORT = typeof ZLDCONFIG_MULTIPATH_TRUNK == "undefined" ? false : ZLDCONFIG_MULTIPATH_TRUNK;
153var PPP_SUPPORT = typeof ZLDCONFIG_PPP == "undefined" ? false : ZLDCONFIG_PPP;
154var AC_WTP_LOGS_SUPPORT = typeof ZLDCONFIG_CAPWAP_AC_WTP_LOGS_SUPPORT == "undefined" ? false : ZLDCONFIG_CAPWAP_AC_WTP_LOGS_SUPPORT;
155var dot1Q_VLAN_SUPPORT = typeof ZLDCONFIG_8021Q_VLAN_ENHANCE == "undefined" ? false : ZLDCONFIG_8021Q_VLAN_ENHANCE;
156var DISABLE_UTM_SUPPORT = false;/* ZLDCONFIG_USGX10_NO_UTM , hide the UTM*/		
157var TEMPORARILY_REMOVED_FOR_4_0 = true;/* ZLDCONFIG_USGX10_NO_UTM , hide the UTM*/
158var WLAN_SUPPORT = (typeof ZLDCONFIG_WLAN_ENABLE == "undefined") ? false : (uagProduct ? false : ZLDCONFIG_WLAN_ENABLE);
159var isUSGProductLine = (typeof ZLDSYSPARM_PRODUCT_LINE == "undefined") ? false : (typeof ZLD_PRODUCT_LINE_USG == "undefined") ? false :(ZLDSYSPARM_PRODUCT_LINE == ZLD_PRODUCT_LINE_USG);
160var CAPWAP_DAILY_REPORT_SUPPORT = typeof ZLDCONFIG_CAPWAP_DAILY_REPORT == "undefined" ? false : ZLDCONFIG_CAPWAP_DAILY_REPORT;
161var CONTENT_FILTER_SUPPORT = typeof ZLDCONFIG_CONTENT_FILTER == "undefined" ? false : ZLDCONFIG_CONTENT_FILTER;
162var ANTISPAM_SUPPORT = typeof ZLDCONFIG_ANTISPAM == "undefined" ? false : ZLDCONFIG_ANTISPAM;
163var ANTIVIRUS_SUPPORT = typeof ZLDCONFIG_ANTIVIRUS == "undefined" ? false : ZLDCONFIG_ANTIVIRUS;
164var ZLDIDP_SUPPORT = typeof ZLDCONFIG_IDP == "undefined" ? false : ZLDCONFIG_IDP;
165var SSLVPN_SUPPORT = typeof ZLDCONFIG_SSLVPN_SUPPORT == "undefined" ? false : ZLDCONFIG_SSLVPN_SUPPORT;
166var IPSEC_SUPPORT = typeof ZLDCONFIG_IPSEC_QUICKSEC == "undefined" ? false : ZLDCONFIG_IPSEC_QUICKSEC;
167var L2TP_SUPPORT = typeof ZLDCONFIG_L2TP_OVER_IPSEC == "undefined" ? false : ZLDCONFIG_L2TP_OVER_IPSEC;
168var IPSEC_SITE_TO_SITE_ONLY_SUPPORT = typeof ZLDCONFIG_IPSEC_SITE_TO_SITE_ONLY == "undefined" ? false : ZLDCONFIG_IPSEC_SITE_TO_SITE_ONLY;
169var APPPATROL_SUPPORT = typeof ZLDCONFIG_APP_PATROL == "undefined" ? false : ZLDCONFIG_APP_PATROL;
170var APPPATROL2_0_SUPPORT = typeof ZLDCONFIG_APP_PATROL20 == "undefined" ? false : ZLDCONFIG_APP_PATROL20;
171var EXTENSION_SLOT_SUPPORT = typeof ZLDCONFIG_EXTENSION_SLOT == "undefined" ? false : ZLDCONFIG_EXTENSION_SLOT;
172var BROADWEBIDP_SUPPORT = typeof ZLDCONFIG_SEARCH_ENGINE_SUPPORT_BROADWEB_IDP == "undefined" ? false : ZLDCONFIG_SEARCH_ENGINE_SUPPORT_BROADWEB_IDP;
173var AV_LAV_SUPPORT = typeof ZLDCONFIG_AV_LAV_STREAMBASED == "undefined" ? false : ZLDCONFIG_AV_LAV_STREAMBASED;
174var AV_KAV_SUPPORT = typeof ZLDCONFIG_AV_KAV_STREAMBASED == "undefined" ? false : ZLDCONFIG_AV_KAV_STREAMBASED;
175var IDP_SUPPORT = typeof ZLDSYSPARM_IDP_CLI_IDP_CLI == "undefined" ? false : ZLDSYSPARM_IDP_CLI_IDP_CLI;
176var IDP_SYS_SUPPORT = typeof ZLDSYSPARM_IDP_CLI_SYS_CLI == "undefined" ? false : ZLDSYSPARM_IDP_CLI_SYS_CLI;
177var ADP_SYS_SUPPORT = typeof ZLDSYSPARM_IDP_CLI_ADP_CLI == "undefined" ? false : ZLDSYSPARM_IDP_CLI_ADP_CLI;
178var DEVICE_HA_SUPPORT = typeof ZLDCONFIG_DEVICE_HA == "undefined" ? false : ZLDCONFIG_DEVICE_HA;
179var AUX_INTERFACE_SUPPORT = typeof ZLDCONFIG_AUX_INTERFACE_SUPPORT == "undefined" ? false : ZLDCONFIG_AUX_INTERFACE_SUPPORT;
180var BWM_SUPPORT = typeof ZLDCONFIG_APP_PATROL_BWM == "undefined" ? false : ZLDCONFIG_APP_PATROL_BWM;
181var VANTAGE_CNM_SUPPORT = typeof ZLDCONFIG_VANTAGE_CNM_AGENT == "undefined" ? false : ZLDCONFIG_VANTAGE_CNM_AGENT;
182var EPS_SUPPORT = typeof ZLDCONFIG_EPS == "undefined" ? false : ZLDCONFIG_EPS;
183var CELLULAR_IFACE_SUPPORT = typeof ZLDCONFIG_CELLULAR_IFACE_SUPPORT == "undefined" ? false : ZLDCONFIG_CELLULAR_IFACE_SUPPORT; 
184var CAPWAP_AC_SUPPORT = typeof ZLDCONFIG_CAPWAP_AC_SUPPORT == "undefined" ? false : ZLDCONFIG_CAPWAP_AC_SUPPORT; 
185var WLAN_ROGUEAP_SUPPORT = typeof ZLDCONFIG_WLAN_RAD_AC_SUPPORT == "undefined" ? false : ZLDCONFIG_WLAN_RAD_AC_SUPPORT; 
186var WLAN_ROGUEAP_CONTAINMENT_SUPPORT = typeof ZLDCONFIG_WLAN_ROGUEAP_CONTAINMENT_SUPPORT == "undefined" ? false : ZLDCONFIG_WLAN_ROGUEAP_CONTAINMENT_SUPPORT; 
187var LOAD_BALANCING_SUPPORT = typeof ZLDCONFIG_AP_LOAD_BALANCING_SERVER_SUPPORT == "undefined" ? false : ZLDCONFIG_AP_LOAD_BALANCING_SERVER_SUPPORT; 
188var WLAN_DCS_SUPPORT = typeof ZLDCONFIG_WLAN_DCS_AC_SUPPORT == "undefined" ? false : ZLDCONFIG_WLAN_DCS_AC_SUPPORT; 		
189var WLAN_PROFILE_SUPPORT = typeof ZLDCONFIG_WLAN_PROFILE_ENABLE == "undefined" ? false : ZLDCONFIG_WLAN_PROFILE_ENABLE; 		
190var DDNS_SUPPORT = typeof ZLDCONFIG_DDNS_CLIENT == "undefined" ? false : ZLDCONFIG_DDNS_CLIENT; 		
191var HTTP_REDIRECT_SUPPORT = typeof ZLDCONFIG_HTTP_REDIRECT == "undefined" ? false : ZLDCONFIG_HTTP_REDIRECT; 		
192var ISP_ACCOUNT_SUPPORT = typeof ZLDCONFIG_ISP_ACCOUNT == "undefined" ? false : ZLDCONFIG_ISP_ACCOUNT; 		
193var INBOUND_LB_SUPPORT = typeof ZLDCONFIG_INBOUND_LOAD_BALANCING == "undefined" ? false : ZLDCONFIG_INBOUND_LOAD_BALANCING;
194var LEGACY_HYBRID_MONITOR_SUPPORT = typeof ZLDCONFIG_LEGACY_HYBRID_DEVICE_MONITOR == "undefined" ? false : ZLDCONFIG_LEGACY_HYBRID_DEVICE_MONITOR; 		
195var IPV6_GLOBAL_SWITCH_SUPPORT = typeof ZLDCONFIG_IPV6_GLOBAL_SWITCH == "undefined" ? false : ZLDCONFIG_IPV6_GLOBAL_SWITCH;
196var MYZYXEL_DOT_COM_SUPPORT = typeof ZLDCONFIG_MYZYXEL_DOT_COM == "undefined" ? false : ZLDCONFIG_MYZYXEL_DOT_COM; 		
197var MYZYXEL_DOT_COM_SUPPORT_V2 = typeof ZLDCONFIG_MYZYXEL_DOT_COM_V2 == "undefined" ? false : ZLDCONFIG_MYZYXEL_DOT_COM_V2; 		
198var ALG_SUPPORT = typeof ZLDCONFIG_ALG_PWLAN_WORKAROUND == "undefined" ? false : ZLDCONFIG_ALG_PWLAN_WORKAROUND; 		
199var IPMAC_BIND_SUPPORT = typeof ZLDCONFIG_IPMAC_BINDING == "undefined" ? false : ZLDCONFIG_IPMAC_BINDING; 		
200var AUTH_SERVER_SUPPORT = typeof ZLDCONFIG_AAA_FREERADIUS_AUTH_SERVER == "undefined" ? false : ZLDCONFIG_AAA_FREERADIUS_AUTH_SERVER; 		
201var WLAN_HYBRID_SUPPORT = typeof ZLDCONFIG_ENTERPRISE_WLAN_HYBRID == "undefined" ? false : ZLDCONFIG_ENTERPRISE_WLAN_HYBRID; 		
202var FIREWALL_SUPPORT = typeof ZLDCONFIG_FIREWALL_SUPPORT == "undefined" ? false : ZLDCONFIG_FIREWALL_SUPPORT;
203var SECURE_POLICY_SUPPORT = typeof ZLDCONFIG_FIREWALL_SUPPORT == "undefined" ? false : ZLDCONFIG_FIREWALL_SUPPORT;
204var ZONE_SUPPORT = typeof ZLDCONFIG_ZONE_SUPPORT == "undefined" ? false : ZLDCONFIG_ZONE_SUPPORT; 		
205var AAA_OBJ_SUPPORT = typeof ZLDCONFIG_AAA_SERVER_SUPPORT == "undefined" ? false : ZLDCONFIG_AAA_SERVER_SUPPORT;
206var PROUT_SUPPORT = typeof ZLDCONFIG_POLICY_ROUTE_SUPPORT == "undefined" ? false : ZLDCONFIG_POLICY_ROUTE_SUPPORT; 	
207var SROUT_SUPPORT = typeof ZLDCONFIG_STATIC_ROUTE_SUPPORT == "undefined" ? false : ZLDCONFIG_STATIC_ROUTE_SUPPORT; 	
208var RIP_SUPPORT = typeof ZLDCONFIG_RIP == "undefined" ? false : ZLDCONFIG_RIP; 		
209var OSPF_SUPPORT = typeof ZLDCONFIG_OSPF == "undefined" ? false : ZLDCONFIG_OSPF; 		
210var NAT_SUPPORT = typeof ZLDCONFIG_VIRTUAL_SERVER_220_SUPPORT == "undefined" ? false : ZLDCONFIG_VIRTUAL_SERVER_220_SUPPORT; 		
211var MIX_LAN_SUPPORT = typeof ZLDCONFIG_AP_MIX_LAN == "undefined" ? false : ZLDCONFIG_AP_MIX_LAN; 
212var USB_STORAGE_SUPPORT = typeof ZLDCONFIG_USB_STORAGE_APP == "undefined" ? false : ZLDCONFIG_USB_STORAGE_APP; 
213var LOGIN_USR = typeof ZLDCONFIG_GUI_LOGIN_USERS_PWLAN_WORKAROUND == "undefined" ? false : ZLDCONFIG_GUI_LOGIN_USERS_PWLAN_WORKAROUND;
214var IPV6_SUPPORT = typeof ZLDCONFIG_IPV6 == "undefined" ? false : ZLDCONFIG_IPV6;
215var PBX_SUPPORT = typeof ZLDCONFIG_PBX_BASIC == "undefined" ? false : ZLDCONFIG_PBX_BASIC;
216var MULTI_LANGUAGE_SUPPORT = typeof ZLDCONFIG_GUI_MULTI_LANGUAGE_PWLAN_WORKAROUND == "undefined" ? false : ZLDCONFIG_GUI_MULTI_LANGUAGE_PWLAN_WORKAROUND; 
217var BWM20_SUPPORT = typeof ZLDCONFIG_BWM20 == "undefined" ? false : ZLDCONFIG_BWM20;
218var BWM_STANDALONE_SUPPORT = typeof ZLDCONFIG_BWM_STANDALONE == "undefined" ? false : ZLDCONFIG_BWM_STANDALONE;
219var BRI_TRUNK_SUPPORT = typeof ZLDCONFIG_PBX_TRUNK_BRI == "undefined" ? false : ZLDCONFIG_PBX_TRUNK_BRI;
220var FXO_TRUNK_SUPPORT = typeof ZLDCONFIG_PBX_TRUNK_FXO == "undefined" ? false : ZLDCONFIG_PBX_TRUNK_FXO;
221var DYNAMIC_GUEST_ACCOUNT = typeof ZLDCONFIG_DYNAMIC_GUEST_ACCOUNT == "undefined" ? false : ZLDCONFIG_DYNAMIC_GUEST_ACCOUNT;
222var ENC_AGENT = typeof ZLDCONFIG_ENC_AGENT == "undefined" ? false : ZLDCONFIG_ENC_AGENT;
223var MAC_AUTH_SUPPORT = typeof ZLDCONFIG_AAA_MAC_AUTH == "undefined" ? false : ZLDCONFIG_AAA_MAC_AUTH;
224var RSSI_THRESHOLD = typeof ZLDCONFIG_WLAN_RSSI_THRESHOLD == "undefined" ? false : ZLDCONFIG_WLAN_RSSI_THRESHOLD;
225var RTLS_SUPPORT = typeof ZLDCONFIG_RTLS_SUPPORT == "undefined" ? false : ZLDCONFIG_RTLS_SUPPORT; 
226var RTLS_EKAHAU_SUPPORT = typeof ZLDCONFIG_RTLS_EKAHAU_SUPPORT == "undefined" ? false : ZLDCONFIG_RTLS_EKAHAU_SUPPORT; 	
227var CAPTIVE_PORTAL_SUPPORT = typeof ZLDCONFIG_CAPTIVE_PORTAL == "undefined" ? false : ZLDCONFIG_CAPTIVE_PORTAL; 
228var WEBAUTH_SUPPORT = typeof ZLDCONFIG_WEBAUTH_SUPPORT == "undefined" ? false : ZLDCONFIG_WEBAUTH_SUPPORT;
229var ZYSSO_SUPPORT = typeof ZLDCONFIG_ZYSSO == "undefined" ? false : ZLDCONFIG_ZYSSO;
230var VPN_1TO1_MAP_SUPPORT = typeof ZLDCONFIG_VPN_1TO1_MAPPING == "undefined" ? false : ZLDCONFIG_VPN_1TO1_MAPPING;
231var SMTP_REDIR_SUPPORT = typeof ZLDCONFIG_SMTP_REDIR == "undefined" ? false :ZLDCONFIG_SMTP_REDIR;
232var USER_AGREMENT_SUPPORT = typeof ZLDCONFIG_USER_AGREEMENT == "undefined" ? false : ZLDCONFIG_USER_AGREEMENT;
233var DYNAMIC_USERS_SUPPORT = typeof ZLDCONFIG_DYNAMIC_GUEST_ACCOUNT_USERS == "undefined" ? false : ZLDCONFIG_DYNAMIC_GUEST_ACCOUNT_USERS;
234var UA_USERS_SUPPORT = typeof ZLDCONFIG_USER_AGREEMENT_USERS == "undefined" ? false : ZLDCONFIG_USER_AGREEMENT_USERS;
235var PAYMENT_SERVICE_SUPPORT = typeof ZLDCONFIG_PAYMENT_SERVICE == "undefined" ? false : ZLDCONFIG_PAYMENT_SERVICE;
236var PRINTER_MANAGER_SUPPORT = typeof ZLDCONFIG_PRINTER_MANAGER == "undefined" ? false : ZLDCONFIG_PRINTER_MANAGER;
237var WALLED_GARDEN_SUPPORT = typeof ZLDCONFIG_WALLED_GARDEN == "undefined" ? false : ZLDCONFIG_WALLED_GARDEN;
238var ADVERTISEMENT_SUPPORT = typeof ZLDCONFIG_ADVERTISEMENT == "undefined" ? false : ZLDCONFIG_ADVERTISEMENT;
239var WEBAUTH_DUE_TIME_SUPPORT = typeof ZLDCONFIG_WEBAUTH_DUE_TIME == "undefined" ? false : ZLDCONFIG_WEBAUTH_DUE_TIME;
240var RADIUS_ACCOUNTING_SUPPORT = typeof ZLDCONFIG_AAA_RADIUS_ACCT == "undefined" ? false : ZLDCONFIG_AAA_RADIUS_ACCT;
241var SMS_SUPPORT = typeof ZLDCONFIG_SMS_SERVICE == "undefined" ? false : ZLDCONFIG_SMS_SERVICE;
242var BILLING_PROFILE_SUPPORT = typeof ZLDCONFIG_BILLING_PROFILE == "undefined" ? false : ZLDCONFIG_BILLING_PROFILE;
243var IPNP_SUPPORT = typeof ZLDCONFIG_IPNP == "undefined" ? false : ZLDCONFIG_IPNP;
244var DDNS_DYNU_BASIC_SUPPORT=typeof ZLDSYSPARM_DDNS_NO_DYNU_TYPE == "undefined" ? false : ZLDSYSPARM_DDNS_NO_DYNU_TYPE;
245var CERTIFICATE_SCEP_SUPPORT=typeof ZLDSYSPARM_CERT_DISABLE_ENROLL_SCEP == "undefined" ? false : ZLDSYSPARM_CERT_DISABLE_ENROLL_SCEP;
246var UPNP_SUPPORT = typeof ZLDCONFIG_UPNP_NATPMP == "undefined" ? false : ZLDCONFIG_UPNP_NATPMP;
247var SMS_SUPPORT = typeof ZLDCONFIG_SMS_SERVICE == "undefined" ? false : ZLDCONFIG_SMS_SERVICE;
248var L2_ISOLATION_SUPPORT = typeof ZLDCONFIG_L2ISOLATION  == "undefined" ? false : ZLDCONFIG_L2ISOLATION;
249var TRUSTCER_OCSP_SUPPORT=typeof ZLDSYSPARM_CERT_DISABLE_VALIDATION_OCSP == "undefined" ? false : ZLDSYSPARM_CERT_DISABLE_VALIDATION_OCSP;
250var PORT_GROUP_SUPPORT = typeof ZLDCONFIG_ETHERNET_PORT_GROUPING == "undefined" ? false : ZLDCONFIG_ETHERNET_PORT_GROUPING;
251var BWM_PER_USER_SUPPORT = typeof ZLDCONFIG_BWM_PER_USER  == "undefined" ? false : ZLDCONFIG_BWM_PER_USER;
252var DATA_FORWARD_SRV_SUPPORT = typeof ZLDCONFIG_DATA_FORWARD_SERVER_SUPPORT == "undefined" ? false : ZLDCONFIG_DATA_FORWARD_SERVER_SUPPORT;
253var PKI_NO_CMP_SCEP = typeof ZLDCONFIG_PKI_NO_CMP_SCEP == "undefined" ? false : ZLDCONFIG_PKI_NO_CMP_SCEP;
254var PCI_DSS_SUPPORT = typeof ZLDCONFIG_PCI_DSS_SUPPORT == "undefined" ? false : ZLDCONFIG_PCI_DSS_SUPPORT;/*PCI-DSS 8.4 support*/
255var USB_LOG_KEEP_DURATION = typeof ZLDCONFIG_USB_LOG_KEEP_DURATION == "undefined" ? false : ZLDCONFIG_USB_LOG_KEEP_DURATION;
256var AD_SERVER_SUPPORT = typeof ZLDCONFIG_AAA_AD_SERVER == "undefined" ? false : ZLDCONFIG_AAA_AD_SERVER;
257var LDAP_SERVER_SUPPORT= typeof ZLDCONFIG_AAA_LDAP_SERVER == "undefined" ? false : ZLDCONFIG_AAA_LDAP_SERVER;
258var RADIUS_SERVER_SUPPORT = typeof ZLDCONFIG_AAA_RADIUS_SERVER == "undefined" ? false : ZLDCONFIG_AAA_RADIUS_SERVER;
259var AAA_FREERADIUS_SUPPORT = typeof ZLDCONFIG_AAA_FREERADIUS == "undefined" ? false : ZLDCONFIG_AAA_FREERADIUS;
260var IGMP_PROXY_SUPPORT = typeof ZLDCONFIG_IGMP_PROXY_ENABLE == "undefined" ? false : ZLDCONFIG_IGMP_PROXY_ENABLE;
261var SECUREPAY_SUPPORT = typeof ZLDSYSPARM_PAYMENT_SERVICE_SECUREPAY_SUPPORT == "undefined" ? false : ZLDSYSPARM_PAYMENT_SERVICE_SECUREPAY_SUPPORT;
262var AUTHORIZE_DOT_NET_SUPPORT = typeof ZLDSYSPARM_PAYMENT_SERVICE_AUTHORIZE_DOT_NET_SUPPORT == "undefined" ? false : ZLDSYSPARM_PAYMENT_SERVICE_AUTHORIZE_DOT_NET_SUPPORT;
263var IPSEC_CONN_CHECK_SUPPORT = typeof ZLDCONFIG_IPSEC_CONN_CHECK == "undefined" ? false : ZLDCONFIG_IPSEC_CONN_CHECK;
264var CUSTOMIZE_LOGINPAGE_UPLOAD = typeof ZLDCONFIG_CUSTOMIZE_LOGINPAGE_UPLOAD == "undefined" ? false : ZLDCONFIG_CUSTOMIZE_LOGINPAGE_UPLOAD;
265var USER_LOGOUT_PAGE_SUPPORT = typeof ZLDCONFIG_USER_LOGOUT_PAGE == "undefined" ? false : ZLDCONFIG_USER_LOGOUT_PAGE;
266var ONE_TIME_PASSWD = typeof ZLDCONFIG_WEBLOGIN_OTP == "undefined" ? false : ZLDCONFIG_WEBLOGIN_OTP;
267var MULTI_IMAGE_SUPPORT = typeof ZLDCONFIG_DUAL_IMAGE_SUPPORT == "undefined" ? false : ZLDCONFIG_DUAL_IMAGE_SUPPORT;
268var USER_GRP_SUPPORT = typeof ZLDCONFIG_USERGROUP_GROUP == "undefined" ? false : ZLDCONFIG_USERGROUP_GROUP; 
269var EXT_USR_SUPPORT = typeof ZLDCONFIG_USERGROUP_EXTERNAL_USER == "undefined" ? false : ZLDCONFIG_USERGROUP_EXTERNAL_USER; 
270var FREE_TIME_SUPPORT = typeof ZLDCONFIG_FREE_TIME_SUPPORT == "undefined" ? false : ZLDCONFIG_FREE_TIME_SUPPORT;
271var LICENSE_REMINDING_SUPPORT = typeof ZLDCONFIG_LICENSE_PROMOTION_NOTIFICATION == "undefined" ? false : ZLDCONFIG_LICENSE_PROMOTION_NOTIFICATION;
272var BWM_PER_IP_SUPPORT = typeof ZLDCONFIG_BWM_PER_IP == "undefined" ? false : ZLDCONFIG_BWM_PER_IP;
273var CF_COMMTOUCH_SUPPORT = typeof ZLDCONFIG_CF_COMMTOUCH == "undefined" ? false : ZLDCONFIG_CF_COMMTOUCH;
274var OUTGOING_LOCAWTP_SUPPORT = typeof ZLDCONFIG_DUALZYSH_LOCALWTP_SUPPORT == "undefined" ? false : ZLDCONFIG_DUALZYSH_LOCALWTP_SUPPORT;
275var DEFAULT_ZONE_SUPPORT = typeof ZLDCONFIG_ZONE_HAVEDEFAULT == "undefined" ? false : ZLDCONFIG_ZONE_HAVEDEFAULT; 
276var ACCOUNTING_SUPPORT = typeof ZLDCONFIG_WLAN_SECURITY_PROFILE_ACCOUNTING == "undefined" ? false : ZLDCONFIG_WLAN_SECURITY_PROFILE_ACCOUNTING;
277var PKI_SUPPORT = typeof ZLDCONFIG_PKI  == "undefined" ? false : ZLDCONFIG_PKI;
278var SNMPV3_SUPPORT = typeof ZLDCONFIG_SNMPV3_SUPPORT == "undefined" ? false : ZLDCONFIG_SNMPV3_SUPPORT; 		
279var SRV_CTRL_SUPPORT = typeof ZLDCONFIG_BUILTIN_SERVICE == "undefined" ? false : ZLDCONFIG_BUILTIN_SERVICE; 		
280var NAC_SUPPORT = typeof ZLDCONFIG_NAC == "undefined" ? false : ZLDCONFIG_NAC;
281var TUNNEL_IFACE_SUPPORT = typeof ZLDCONFIG_TUNNEL_IFACE_SUPPORT == "undefined" ? false : ZLDCONFIG_TUNNEL_IFACE_SUPPORT;
282var VPN_CONFPROV_SUPPORT = typeof ZLDCONFIG_VPN_CONFIGURATION_PROVISION == "undefined" ? false : ZLDCONFIG_VPN_CONFIGURATION_PROVISION;
283var VPN_CONCENTRATOR_SUPPORT = typeof ZLDCONFIG_IPSEC_VPN_CONCENTRATOR == "undefined" ? false : ZLDCONFIG_IPSEC_VPN_CONCENTRATOR;
284var SEARCH_ENGINE_BROADWEB_IDP_SUPPORT = (typeof ZLDCONFIG_SEARCH_ENGINE_SUPPORT_BROADWEB_IDP == "undefined" ? false : ZLDCONFIG_SEARCH_ENGINE_SUPPORT_BROADWEB_IDP);
285var AS_COMMTOUCH_SUPPORT = (typeof ZLDCONFIG_AS_COMMTOUCH == "undefined" ? false : ZLDCONFIG_AS_COMMTOUCH);
286var LOGOUT_IP = typeof ZLDCONFIG_LOGOUT_IP == "undefined" ? false : ZLDCONFIG_LOGOUT_IP;
287var PCAP_SUPPORT = typeof ZLDCONFIG_PCAP_MONITOR == "undefined" ? false : ZLDCONFIG_PCAP_MONITOR; 		
288var CUSTOMIZE_PAGE_SUPPORT = typeof ZLDCONFIG_CUSTOMIZED_LOGIN_PAGE == "undefined" ? false : ZLDCONFIG_CUSTOMIZED_LOGIN_PAGE; 		
289var TERMS_OF_SERVICE = typeof ZLDCONFIG_TERMS_OF_SERVICE == "undefined" ? false : ZLDCONFIG_TERMS_OF_SERVICE;
290var WLAN_FRAME_CAPTURE_SUPPORT = typeof ZLDCONFIG_WLAN_FRAME_CAPTURE_SERVER_SUPPORT == "undefined" ? false : ZLDCONFIG_WLAN_FRAME_CAPTURE_SERVER_SUPPORT; 		
291va
291r DEVICE_HA_LEGACY_MODE_SUPPORT = typeof ZLDCONFIG_DEVICE_HA_LEGACY_MODE_SUPPORT == "undefined" ? false : ZLDCONFIG_DEVICE_HA_LEGACY_MODE_SUPPORT; 		
292var CELLULAR_SUPPORT = typeof ZLDCONFIG_CELLULAR_IFACE_SUPPORT == "undefined" ? false : ZLDCONFIG_CELLULAR_IFACE_SUPPORT;
293var SESSION_LIMIT_SUPPORT = typeof ZLDCONFIG_SESSION_LIMIT == "undefined" ? false : ZLDCONFIG_SESSION_LIMIT;
294var USB_STORAGE_TRAFFIC_LOG = typeof ZLDCONFIG_USB_STORAGE_TRAFFIC_LOG == "undefined" ? false : ZLDCONFIG_USB_STORAGE_TRAFFIC_LOG;
295var TRAFFIC_REPORT_SUPPORT = typeof ZLDCONFIG_TRAFFIC_REPORT == "undefined" ? false : ZLDCONFIG_TRAFFIC_REPORT;
296var PRE_PRODUCTION_FW_UPDATE_WIZARD_SUPPORT = typeof ZLDCONFIG_PRE_PRODUCTION_FW_UPDATE_WIZARD == "undefined" ? false : ZLDCONFIG_PRE_PRODUCTION_FW_UPDATE_WIZARD; 		
297var SSL_INSPECTION_SUPPORT = typeof ZLDCONFIG_SSL_INSPECTION == "undefined" ? false : ZLDCONFIG_SSL_INSPECTION;
298var CF_SUPPORT_IPV6_SUPPORT = typeof ZLDCONFIG_CF_SUPPORT_IPV6 == "undefined" ? false : ZLDCONFIG_CF_SUPPORT_IPV6;
299var SSL_INSPECTION_IPV6_SUPPORT = typeof ZLDCONFIG_SSL_INSPECTION_SUPPORT_IPV6 == "undefined" ? false : ZLDCONFIG_SSL_INSPECTION_SUPPORT_IPV6;
300var UTM_FEATURE_PROMOTION_SUPPORT = typeof ZLDCONFIG_UTM_FEATURE_PROMOTION == "undefined" ? false : ZLDCONFIG_UTM_FEATURE_PROMOTION;
301var POLICY_ROUTE_CONN_CHECK_SUPPORT = typeof ZLDCONFIG_POLICY_ROUTE_CONN_CHECK == "undefined" ? false : ZLDCONFIG_POLICY_ROUTE_CONN_CHECK;
302var SECUEXTENDER_UPDATE_SUPPORT = typeof ZLDCONFIG_SECUEXTENDER_UPDATE == "undefined" ? false : ZLDCONFIG_SECUEXTENDER_UPDATE;
303var CELLULAR_CDC_ECM_SUPPORT = typeof ZLDCONFIG_CELLULAR_CDC_ECM == "undefined" ? false : ZLDCONFIG_CELLULAR_CDC_ECM;
304var _3G_MODE_SWITCH_SUPPORT = typeof ZLDCONFIG_3G_MODE_SWITCH_UPDATE == "undefined" ? false : ZLDCONFIG_3G_MODE_SWITCH_UPDATE;
305var INTRA_LINK_SUPPORT = typeof ZLDCONFIG_INTRA_LINK_SUPPORT == "undefined" ? false : ZLDCONFIG_INTRA_LINK_SUPPORT;
306var DHA_SUPPORT = typeof ZLDCONFIG_DEVICE_HA == "undefined" ? false : ZLDCONFIG_DEVICE_HA;		
307var ZLDCONFIG_IPV6_ENABLE = (typeof(ZLDCONFIG_IPV6) != "undefined");
308var FBSD_SUPPORT = typeof ZLDCONFIG_FALLBACK_SESSION_DISCONNECT == "undefined" ? false : ZLDCONFIG_FALLBACK_SESSION_DISCONNECT;
309var MULTI_PORTAL_SUPPORT = typeof ZLDCONFIG_MULTI_PORTAL== "undefined" ? false : ZLDCONFIG_MULTI_PORTAL;
310var ZLDSYSPARM_EZMODE_SUPPORT = typeof ZLDSYSPARM_EZMODE== "undefined" ? false : ZLDSYSPARM_EZMODE;
311var Russia_SUPPORT = false;
312var INTERNAL_EAP_PROXY_SUPPORT = typeof ZLDCONFIG_AAA_INTERNAL_EAP_PROXY == "undefined" ? false : ZLDCONFIG_AAA_INTERNAL_EAP_PROXY;
313var ZYMESH_SUPPORT = typeof ZLDCONFIG_ZYMESH_SUPPORT == "undefined" ? false : ZLDCONFIG_ZYMESH_SUPPORT; 
314var WLAN_CONTROLLER_SUPPORT = typeof ZLDCONFIG_WLAN_CONTROLLER_SUPPORT == "undefined" ? false : ZLDCONFIG_WLAN_CONTROLLER_SUPPORT;
315var UXG_STANDALONE_AP_SUPPORT = typeof ZLDCONFIG_UXG_STANDALONE_AP == "undefined" ? false : ZLDCONFIG_UXG_STANDALONE_AP;
316var ZLDSYSPARM_EZMODE_SUPPORT = typeof ZLDSYSPARM_EZMODE == "undefined" ? false : ZLDSYSPARM_EZMODE;
317var ANTENNA_SWITCH_SUPPORT = typeof ZLDCONFIG_ANTENNA_SWITCH_SUPPORT == "undefined" ? false : ZLDCONFIG_ANTENNA_SWITCH_SUPPORT;
318var SELECTABLE_ANTENNA_SUPPORT = typeof ZLDCONFIG_SELECTABLE_ANTENNA_SUPPORT == "undefined" ? false :ZLDCONFIG_SELECTABLE_ANTENNA_SUPPORT;
319var WLAN_11AX_SUPPORT = typeof ZLDCONFIG_WLAN_11AX_SUPPORT == "undefined" ? false: ZLDCONFIG_WLAN_11AX_SUPPORT;
320// -------------------------------------------------------------------------------------------------------------------------
321// For Capture on AP - to keep current AP ----------------------------------------------------------------------------------
322var Current_Query_AP = '';
323var Current_Query_AP_Mac = '';
324var Action_is_Query = false;
325// -------------------------------------------------------------------------------------------------------------------------
326// For Remote Capture - to keep current AP ----------------------------------------------------------------------------------
327var Remote_Capture_AP_Mac = '';
328// -------------------------------------------------------------------------------------------------------------------
329/* For Station Info do filtering*/
330var FILTER_IP = '', FILTER_AP = '', FILTER_SSID = '', FILTER_MAC = '', FILTER_SECURITY = '';
331var FILTER_ACCOUNT ='', FILTER_LOGIN = '', FILTER_BAND = '';
332/* Activate License */
333function getOneTimeServiceSuffix(formid,srv_name,cgi_name){
334	switch(srv_name.getAt(0).get('_Status')){ 
335		case 'Not Licensed':							
336			return '<a href=\"..\/..\/..\/'+cgi_name+'\" target=\"_blank\" class=\"hyper\">Buy</span></a>';	
337		break;
338		default:
339			return '';
340		break;
341	}
342}
343function getServiceSuffix(formid,srv_name,config_name,cgi_name){
344		var Buy_tpl = "<a href=\"..\/..\/..\/..\/{0}\" target=\"_blank\" class=\"hyper\">{1}</span></a>";
345		var Buy_html = Ext.String.format(Buy_tpl,							
346			cgi_name,
347			(srv_name.getAt(0).get('_Type') == "Standard")?"Renew":"Buy"
348		);
349		var actCmd = 'service-register _activate '+config_name;
350		var Act_tpl = "&nbsp;&nbsp;&nbsp;&nbsp<a href ='#' style='cursor:pointer;' onclick='licenseAct(\"{0}\",\"{1}\");'>Activate</a>";
351		var Act_html = Ext.String.format(Act_tpl,							
352			formid,
353			actCmd
354		);
355		switch(srv_name.getAt(0).get('_Status')){
356			case 'Not Activated':
357					return  Buy_html+Act_html;
358			break;
359			default:
360					return Buy_html;
361			break;
362		}	
363}
364function licenseAct(formID,actCmd) {
365	var form = Ext.getCmp(formID);
366	if(actCmd != ''){
367		Ext.MessageBox.show({
368				title: mlang['_Warning_Message'],
369				msg: mlang['_To_activate_both_license'],
370				buttons: Ext.MessageBox.OK,
371				icon: Ext.MessageBox.WARNING,
372				fn:function(btn, text){
373					if (btn == 'ok'){
374						Ext.getBody().mask(mlang['_Activating_Service'], 'x-mask-loading');
375						Ext.Ajax.request({
376							url: zyCGI_P,
377							method: 'POST',
378							params: { filter:'js2', cmd:composeCLI([actCmd])},
379							failure:function(response,options) {
380								Ext.Msg.alert('Error Message',response.responseText);
381								Ext.getBody().unmask();
382							},
383							callback: function(options, success, response) {
384								if(success) {
385									Ext.getBody().unmask();
386									var res = Ext.decode(js2json(response.responseText));
387									var result_code = res.zyshdata0[0]._Activation_result_code;
388									var result_message = res.zyshdata0[0]._Activation_result_message;
389									if(result_message == '"success"'){
390										if(formID == 'dashboardform')		
391											retrieveData.start(form, form.getCLICmd('LiceSt'), 'callback', 'LiceSt');
392										else{
393											form.removeAll();
394											retrieveData.start(form, form.showCmd);
395										}										
396									}else if(result_message != 'n/a'){
397										Ext.MessageBox.alert('Error Message',result_message.split('"')[1]);
398									}else{
399										Ext.MessageBox.alert('Error Message','Connect to myZyxel has failed.');
400									}
401								}
402							}
403						});
404					}
405				}
406		});
407	}
408}
409function getServiceGraceSize(srv_name){
410	switch(srv_name.getAt(0).get('_Status')){ 
411		case 'Grace Period':
412			return 35;
413		break;
414		default:
415			return 15;
416		break;
417	}
418}
419function getServiceGraceValue(srv_name){
420	switch(srv_name.getAt(0).get('_Status')){ 
421		case 'Grace Period':							
422			return srv_name.getAt(0).get('_Status')+"  (Remaining: "+srv_name.getAt(0).get('_Grace')+"days)";	
423		break;
424		default:
425			return srv_name.getAt(0).get('_Status');
426		break;
427	}
428}
429function getServiceBuyLink(cgi_name){
430		window.open("..\/..\/..\/..\/"+cgi_name, "_blank");
431}
432function getLicenseBar(cgi_name,status,path){
433	var cgi_name_tmp = "\'" + cgi_name + "\.cgi\'";
434	if(cgi_name == "myzyxel_APC"){
435		var msg_buy_info = 'Buy a Secure WiFi license.';//mlang['_License_Bar_Msg_Secure_WiFi_APC'];
436		var msg_see_info='See Secure WiFi license details.';//mlang['_License_Bar_Msg_Secure_WiFi_APC'];
437		var msg_buy_now = 'Buy Now.';//mlang['_License_Bar_Msg_Secure_WiFi_APC'];
438		var msg_see_details='See details.';//mlang['_License_Bar_Msg_Secure_WiFi_APC'];
439		var msg ='';
440		var msg1='';
441		if(path=='aplistedit'||path=='remoteapsetting'){
442			if(status == "Expired"){
443				var msg1 =((status == "Expired") ? 'Secure WiFi license has expired. ': (status == "Not Activated") ? mlang['_Secure_WiFi_license_Not_Activate']: mlang['_Secure_WiFi_license_is_required']);
444				var msg2 = (cgi_name == "myzyxel_GEOIP") ? mlang['_License_Bar_Msg_GeoIP'] : mlang['_License_Bar_Msg'];
445				var msg = Ext.String.format('{0} {1} {2}',msg1," ",msg2);
446			}else if((status == "Not Licensed")){
447
448			}
449		}else{
450			var idx_mgmtap = 1000;
451			for (var i = 0; i < showLiceSt.totalCount; i++){
452				if(showLiceSt.getAt(i).get('_Service')== 'Managed AP Service'){
453					idx_mgmtap = i;
454					break;
455				}
456			}
457			if(status == "Not Licensed"){
458				
459			}else if(status == "Expired"){
460				msg1 = 'Secure WiFi license has expired.  Your Managed AP service node limit is now {0} APs.';//mlang['_License_Bar_Msg_Secure_WiFi_APC'];
461				msg = Ext.String.format(msg1,showLiceSt.getAt(idx_mgmtap).get('_Count'));
462			}
463		}
464	}else{
465		var msg1 =((status == "Expired") ? mlang['_License_Expire']: (status == "Not Activated") ? mlang['_License_Not_Activate']: mlang['_Not_License']);
466		var msg2 = (cgi_name == "myzyxel_GEOIP") ? mlang['_License_Bar_Msg_GeoIP'] : mlang['_License_Bar_Msg'];
467		var msg = Ext.String.format('{0} {1} {2}',msg1," ",msg2);
468		//Not Licensed. Database cannot update.
469		//Not Licensed. The configuration will be saved but will not take effect.
470		
471	}
472	if(cgi_name == "myzyxel_APC"){
473		if(status == "Expired"){
474			var _tpl = '<div style="background:#E15240;"><div class="license_expired_warning_icon"></div><div class="license_expired_text">'+ msg +'&nbsp;&nbsp;</div><div class="license_expired_buy" data-qtip="'+""+'"onclick="getServiceBuyLink({0});"><u> '+ msg_buy_now +'</u>&nbsp;&nbsp;</div><div class="license_expired_see_more" data-qtip="'+""+'"onclick="window.open(\'https://www.zyxel.com/securewifi\');"><u>'+msg_see_details+'</u></div></div>';
475		}else if(status == "Not Licensed"){
476			if(path=='aplistedit'||path=='remoteapsetting'){
477				var _tpl = '<div style="background:#E15240;"><div class="license_expired_warning_icon"></div><div class="license_expired_buy">&nbsp;&nbsp;</div><div class="license_expired_buy" data-qtip="'+""+'"onclick="getServiceBuyLink({0});"><u> '+ msg_buy_info +'</u>&nbsp;&nbsp;</div><div class="license_expired_see_more" data-qtip="'+""+'"onclick="window.open(\'https://www.zyxel.com/securewifi\');"><u>'+msg_see_info+'</u></div></div>';
478			}else{
479				var _tpl = '<div style="background:#5D5D5D;"><div class="license_expired_buy">&nbsp;&nbsp;</div><div class="license_expired_buy" data-qtip="'+""+'"onclick="getServiceBuyLink({0});"><u> '+ msg_buy_info +'</u>&nbsp;&nbsp;</div><div class="license_expired_see_more" data-qtip="'+""+'"onclick="window.open(\'https://www.zyxel.com/securewifi\');"><u>'+msg_see_info+'</u></div></div>';
480			}
481		}
482	}else if(cgi_name == "myzyxel_NWPM"){
483		var _tpl = '<div class="license_expired">'+ msg +'</div><div class="license_expired_shopping_cart" data-qtip="'+"Buy license"+'"onclick="getServiceBuyLink({0});"></div><div class="license_expired_info" data-qtip="'+"More informotion"+'"onclick="window.open(\'https://www.zyxel.com/sso\');"></div>';
484	}	
485	else
486    	var _tpl = '<div class="license_expired">'+ msg +'</div><div class="license_expired_shopping_cart" data-qtip="'+"Buy license"+'"onclick="getServiceBuyLink({0});"></div><div class="license_expired_info" data-qtip="'+"More informotion"+'"onclick="window.open(\'https://www.zyxel.com/flex\');"></div>';
487	if(cgi_name == "myzyxel_DI")
488		var _tpl = '<div class="license_expired">'+ 'To unlock the service, please upgrade firmware and purchase a License.';
489		
490	var my_html = Ext.String.format(_tpl,cgi_name_tmp);
491	return my_html;
492}
493function getServiceStuBuyActLink(record,formID,value){
494	var myzyxel_cgi, NeedAct = false, NeedBuy = false, Quantity = false, actCmd = '';
495	switch(record.get('_Service')){
496		case 'IDP Signature':
497			myzyxel_cgi = 'myzyxel_IDP.cgi';
498			actCmd = 'service-register _activate idp';
499			NeedBuy = true;
500			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
501		break;
502		case 'Anti-Virus':
503		case 'Anti-Malware':
504		case 'Malware Blocker':	
505			myzyxel_cgi = 'myzyxel_AV.cgi';//FLEX
506			actCmd = 'service-register _activate av';
507			NeedBuy = true;
508			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
509		break;
510/*For 535 GUI Remove Anit-Spam*/ 
511		case 'Anti-Spam':
512			myzyxel_cgi = 'myzyxel_AS.cgi';
513			actCmd = 'service-register _activate as';
514			NeedBuy = true;
515			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
516		break;
517		case 'Web Filtering':
518			myzyxel_cgi = 'myzyxel_WEBF.cgi';
519			actCmd = 'service-register _activate web-filtering';
520			NeedBuy = true;
521			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
522		break;
523		case 'Hotspot Management Subscription Service':
524			myzyxel_cgi = 'myzyxel_HOTS.cgi';
525			actCmd = 'service-register _activate hotspot-service subscription';
526			NeedBuy = true;
527			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
528		break;
529		case 'Hotspot Management One-Time Service':
530			myzyxel_cgi = 'myzyxel_HOTSQ.cgi';
531			actCmd = '';
532			NeedBuy = record.get('_Status') == "Not Licensed" ? true : false;
533			Quantity = true;							
534		break;
535		case 'Device HA Pro':
536			myzyxel_cgi = 'myzyxel_HA.cgi';
537			actCmd = '';
538			NeedBuy = record.get('_Status') == "Not Licensed" ? true : false;
539			Quantity = true;
540		break;  
541		case 'SSL VPN':
542			myzyxel_cgi = 'myzyxel_SSLVPN.cgi';
543			actCmd = '';
544			NeedBuy = ((record.get('_Purchasable')== "N/A") || (new Number(record.get('_Purchasable'))>0))?true:false;
545			Quantity = true;
546		break;
547		case 'Zymesh Service':
548			myzyxel_cgi = 'myzyxel_ZYMESH.cgi';
549			actCmd = '';
550			NeedBuy = record.get('_Status') == "Not Licensed" ? true : false;
551			Quantity = true;
552		 break;
553		case 'Concurrent Device Upgrade':
554			myzyxel_cgi = 'myzyxel_EXU.cgi';
555			NeedAct = (new Number(record.get('_Activatable'))>0) ? true :false;
556			actCmd = 'service-register _activate concurrent-device-upgrade';
557			NeedBuy = ((record.get('_Purchasable')== "N/A") || (new Number(record.get('_Purchasable')) > 0) || (new Number(record.get('_Expiration')) > 0)) ? true : false;
558			Quantity = true;
559		break;
560		case 'Geo Enforcer':
561			myzyxel_cgi = 'myzyxel_GEOIP.cgi';
562			actCmd = 'service-register _activate geo-ip';
563			NeedBuy = true;
564			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
565		break;
566		case 'Geo Enforcer One-Time Service':
567			myzyxel_cgi = 'myzyxel_GEOIP.cgi';
568			actCmd = '';
569			NeedBuy = record.get('_Status') == "Not Licensed" ? true : false;
570			Quantity = true;
571		break;
572		case 'Managed AP Service':
573			myzyxel_cgi = 'myzyxel_APC.cgi';
574			actCmd = 'service-register _activate managed-ap-service';
575			NeedAct = (new Number(record.get('_Activatable'))>0) ? true :false;
576			if(new Number(record.get('_Expiration'))>0){
577				NeedBuy = false;
578			}else{
579				NeedBuy = false;
580				Quantity = false;
581			}
582		break;
583		case 'SecuReporter':
584			myzyxel_cgi = 'myzyxel_SECUR.cgi';
585			actCmd = 'service-register _activate secu-reporter';
586			NeedBuy = true;
587			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
588		break;
589		case 'SecuReporter Premium':
590			myzyxel_cgi = 'myzyxel_SECUR.cgi';
591			actCmd = 'service-register _activate secu-reporter';
592			NeedBuy = true;
593			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
594		break;
595		case 'Email Security':
596			myzyxel_cgi = 'myzyxel_AS.cgi';
597			actCmd = 'service-register _activate as';
598			NeedBuy = true;
599			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
600		break;
601		case 'Application Patrol':
602			myzyxel_cgi = 'myzyxel_APPPQM.cgi';
603			actCmd = 'service-register _activate application-patrol';
604			NeedBuy = true;
605			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
606		break;
607		case 'IPS':
608			myzyxel_cgi = 'myzyxel_IDP.cgi';
609			actCmd = 'service-register _activate idp';
610			NeedBuy = true;
611			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
612		break;
613		case 'Sandboxing':
614			myzyxel_cgi = 'myzyxel_SANDBOX.cgi';
615			actCmd = 'service-register _activate sandboxing';
616			NeedBuy = true;
617			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
618		break;
619		case 'Reputation Filter':
620			myzyxel_cgi = 'myzyxel_RF.cgi';
621			actCmd = 'service-register _activate reputation-filter';
622			NeedBuy = true;
623			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
624		break;
625		case "Collaborative Detection & Response":
626			myzyxel_cgi = 'myzyxel_CDR.cgi';
627			actCmd = 'service-register _activate cdr';
628			NeedBuy = true;
629			NeedAct = (record.get('_Status') == "Not Activated") ? true :false;
630		break;
631		case 'Secure WiFi':
632			myzyxel_cgi = 'myzyxel_APC.cgi';
633			actCmd = 'service-register _activate secure-wifi';
634			NeedBuy = true;
635            NeedAct = (new Number(record.get('_Activatable'))>0) ? true :false;
636		break;
637		case 'Network Premium':
638			myzyxel_cgi = 'myzyxel_NWPM.cgi';
639			actCmd = 'service-register _activate network-premium';
640			NeedBuy = true;
641            NeedAct = (new Number(record.get('_Activatable'))>0) ? true :false;
642		break;
643		default:
644			myzyxel_cgi = '';
645			actCmd = '';
646			NeedAct = false;
647			NeedBuy = false;
648		break;
649	}
650    if(!_ZYXEL_DEVICE_SUBSCRIPTION_Disable){
651    	NeedBuy = false;
652    }
653	var my_html = '';
654	var Act_tpl = "{2}<a href ='#' style='cursor:pointer;' onclick='licenseAct(\"{3}\",\"{4}\");'>Activate</a>";
655	var Buy_tpl = "<a href=\"\/{0}\" target=\"_blank\" class=\"hyper\">{1}</span></a>";
656	var _tpl = Ext.String.format("{0}{1}",	
657				NeedBuy ? Buy_tpl : '',
658				NeedAct ? Act_tpl : '');
659	if(NeedAct && NeedBuy){
660		my_html = Ext.String.format(_tpl,							
661			myzyxel_cgi,
662			Quantity ? "Buy" : (record.get('_Type') == "Standard")?"Renew":"Buy",
663			"&nbsp;&nbsp",
664			formID,
665			actCmd
666		);
667	}else if(NeedBuy){
668		my_html = Ext.String.format(_tpl,							
669			myzyxel_cgi,
670			Quantity ? "Buy" : (record.get('_Type') == "Standard")?"Renew":"Buy"
671		);
672	}
673	if(formID == 'winlicenseremind'){
674		switch(record.get('_Status')){
675			case 'Grace Period':
676				return '<font color=#ff0000>'+value+'&nbsp;  (Remaining: '+record.get('_Grace')+'days)&nbsp;&nbsp&nbsp;<\/font>'+my_html;
677			break;
678			case 'Expired':
679			case 'Not Activated':
680			case 'Not Licensed':
681                if(_ZYXEL_DEVICE_SUBSCRIPTION_Disable)
682			    	return '<font color=#ff0000>'+value+'<\/font>'+"&nbsp;&nbsp;&nbsp;"+my_html;
683                else
684			    	return '<font color=#ff0000>'+value+'<\/font>';
685			break;
686			default:
687				return '<font color=#ff0000>'+value+'<\/font>';
688			break;
689		}
690	}else{
691		return my_html;
692	}
693	
694}
695function getRegisterHTML(msg){
696    if(isAdmin){
697        var myhtml = '<a href="../../../myzyxel_registration.cgi" target="_blank">'+msg +'</a>';
698    }else{
699        var myhtml = '<a href="https://portal.myzyxel.com/" target="_blank">'+msg +'</a>'
700    }
701	return myhtml;
702}		
703function getServiceNoteHTML(msg){
704    if(isAdmin){
705        var myzyxel_html = Ext.String.format(" {0}portal.myzyxel.com{1} ", 	//Text:Register at {0}portal.myzyxel.com{1} to power up with auto firmware notification.		
706		/*0*/ "<a href=\"..\/..\/..\/myzyxel_registration.cgi\" target=_blank><i><u>",
707		/*1*/ "<\/u><\/i><\/a>");
708    }else{
709        var myzyxel_html = '<a href="https://portal.myzyxel.com/" target="_blank">portal.myzyxel.com</a>'
710    }	
711	var tpl = Ext.String.format('<div class="note">{0}</div>{1}', mlang['_Note1'],  msg); 
712	var myhtml = Ext.String.format(tpl, myzyxel_html);
713	return myhtml;
714}
715
716function getMarketPlaceNoteHTML(msg){
717        var myzyxel_html = Ext.String.format(" {0}Marketplace{1} ",		
718		/*0*/ "<a href=\"..\/..\/..\/myzyxel_NWE.cgi\" target=_blank><i><u>",
719		/*1*/ "<\/u><\/i><\/a>");
720	var myhtml = Ext.String.format(msg, myzyxel_html);
721	return myhtml;
722}	
723/* remove all child node */
724function removeAllChild(id){
725	var cell = document.getElementById(id);
726	while (cell.childNodes[0]){
727		cell.removeChild(cell.childNodes[0]);
728	}
729	cell = null;
730}	
731function refreshvd(){
732	var dashboardform = Ext.getCmp('DHGeneralform');	
733	retrieveData.start(dashboardform, dashboardform.getCLICmd('vrpanel'), 'callback', 'vrpanel');
734    var vdlink_class = document.getElementById('vdlink').className;
735	if(!dashboardform.Rear_Panel_Not_SUPPORT){
736        if (vdlink_class.indexOf("rear_panel") != -1){
737            Ext.get('vdlink').removeCls('rear_panel');
738            Ext.get('vdlink').addCls('front_panel');
739            
740            document.getElementById('vdlink').innerHTML = mlang['_Front_Panel']; //Text : 'Front Panel';
741			dashboardform.whichside = 'rear';
742				Ext.get('vd_icon').removeCls('icon_btn_arrowright');
743				Ext.get('vd_icon').addCls('icon_btn_arrowleft');
744        }else{
745            Ext.get('vdlink').removeCls('front_panel');
746            Ext.get('vdlink').addCls('rear_panel');
747            
748            document.getElementById('vdlink').innerHTML = mlang["_Rear_Panel"];//Text : 'Rear Panel';
749			dashboardform.whichside = 'front';
750				Ext.get('vd_icon').removeCls('icon_btn_arrowleft');
751				Ext.get('vd_icon').addCls('icon_btn_arrowright');
752        }
753	}
754	dashboardform.doVD();
755
756}
757function getCookie(objName){
758    var decodecookie = decodeURIComponent(document.cookie);
759    var arrStr = decodecookie.split("; ");
760    for(var i = 0;i < arrStr.length;i ++){
761        var temp = arrStr[i].split("=");
762        if(temp[0] == objName) return unescape(temp[1]);
763    }
764}
765function UpdateLangPanelTag(){
766    _Done =false;
767    var lang_cookie = getCookie('Language');
768    switch (lang_cookie) {
769        case 'EN':
770            setScriptTag2Head('language_panel', '/ext-js/app/common/multi-lang/language_panel_English.js');
771        break;
772        case 'FR':
773            setScriptTag2Head('language_panel', '/ext-js/app/common/multi-lang/language_panel_French.js');
774        break;
775        case 'DE':
776            setScriptTag2Head('language_panel', '/ext-js/app/common/multi-lang/language_panel_German.js');
777        break;
778        case 'PL':
779            setScriptTag2Head('language_panel', '/ext-js/app/common/multi-lang/language_panel_Polish.js');
780        break;
781        case 'PT':
782            setScriptTag2Head('language_panel', '/ext-js/app/common/multi-lang/language_panel_Portuguese.js');
783        break;
784        case 'RU':
785            setScriptTag2Head('language_panel', '/ext-js/app/common/multi-lang/language_panel_Russian.js');
786        break;
787        case 'CN':
788            setScriptTag2Head('language_panel', '/ext-js/app/common/multi-lang/language_panel_Simplified_Chinese.js');
789        break;
790        case 'ES':
791            setScriptTag2Head('language_panel', '/ext-js/app/common/multi-lang/language_panel_Spanish.js');
792        break;
793        case 'TW':
794            setScriptTag2Head('language_panel', '/ext-js/app/common/multi-lang/language_panel_Traditional_Chinese.js');
795        break;
796        case 'TR':
797            setScriptTag2Head('language_panel', '/ext-js/app/common/multi-lang/language_panel_Turkish.js');
798        break;
799    }
800}
801function CurrentLang(selectedLang){    
802    var lang_cookie = readCookie('Language') != null ? readCookie('Language') : selectedLang;
803    var current_lang;
804    switch (lang_cookie) {
805        case 'EN':
806        case 'English':
807            current_lang = 'English';
808        break;
809        case 'FR':
810        case 'French':
811            current_lang = 'French';
812        break;
813        case 'DE':
814        case 'German':
815            current_lang = 'German';
816        break;
817        case 'PL':
818        case 'Polish':
819            current_lang = 'Polish';
820        break;
821        case 'PT':
822        case 'Portuguese':
823            current_lang = 'Portuguese';
824        break;
825        case 'RU':
826        case 'Russian':
827            current_lang = 'Russian';
828        break;
829        case 'CN':
830        case 'Simplified_Chinese':
831            current_lang = 'Simplified_Chinese';
832        break;
833        case 'ES':
834        case 'Spanish':
835            current_lang = 'Spanish';
836        break;
837        case 'TW':
838        case 'Traditional_Chinese':
839            current_lang = 'Traditional_Chinese';
840        break;
841        case 'TR':
842        case 'Turkish':
843            current_lang = 'Turkish';
844        break;
845        default:
846            current_lang = 'English';
847        break;
848    }
849    return current_lang;
850}
851function UpdateLangTag(){
852    var lang_cookie = readCookie('Language');
853    var current_lang = CurrentLang();   
854    LangReady = false;//reset flag, prevent preloaded language affecting next new one.
855    setScriptTag2Head('zylang', '../../common/multi-lang/language_'+current_lang+'.js');
856    //Default Language store 
857    var dstore = new Ext.data.SimpleStore({
858        autoLoad: true, 
859        fields: ['code', 'language', 'charset'],
860        data : Ext.exampledata.languages // from languages.js
861    });        
862    /* check if there's really a language with that language code */
863    if (current_lang == 'French')
864        current_lang = 'France (France)';
865    dstore.data.find(function(item, key) {
866        if (item.data.language == current_lang) {
867            setScriptTag2Head('dlang', '../../../ext/source/locale/ext-lang-'+item.data.code+'.js');
868        }
869    });
870    Ext.Ajax.request({
871        url: zyCGI_P,
872        method: 'POST',
873        params: { filter:'js2', cmd:composeCLI(['show language use']), write:0 },
874        timeout: 3000,
875        callback: function(options, success, response){
876            if(success) {
877                var mydata1 = Ext.decode(js2json(response.responseText));
878                if(mydata1.zyshdata0[0]._enable_package_language == "yes"){ 
879                    if (Ext.getDom('zylang').src !== '../../common/multi-lang/language/language_'+current_lang+'.js') {
880                        LangReady = false;//reset flag, prevent preloaded language affecting next new one.
881                        setScriptTag2Head('zylang', '../../common/multi-lang/language/language_'+current_lang+'.js');
882                    }
883                }
884            }
885        }
886    });
887}
888/* Append script language to html head */
889function setScript2Head(id, text){
890	/* remove old child first */
891	var head= document.getElementsByTagName("head").item(0);
892	var o = document.getElementById(id);
893	if (o) head.removeChild(o);
894
895	/* create new child */
896	var n = document.createElement("script");
897	n.text = text;
898	n.setAttribute('language','javascript');
899	n.id = id;
900	head.appendChild(n);
901	head = o = n = null;
902}
903
904/* Append script tag to html head */
905function setScriptTag2Head(id, filename){
906	/* remove old script tag first */
907	var head= document.getElementsByTagName("head").item(0);
908	var o = document.getElementById(id);
909	if (o) head.removeChild(o);
910	/* create new script tag */
911	var n = document.createElement("script");
912	n.type = 'text/javascript';
913	n.id = id;
914	n.src = filename+"?_dc="+(new Date().getTime());
915	head.appendChild(n);
916	head = o = n = null;
917}
918
919function issueConfigCLI(cmd, nextPage, refreshTime, btnClick){
920	Ext.getBody().mask('Loading...', 'x-mask-loading');
921	var configCLI = composeMultiConfigCLI(cmd);
922	Ext.Ajax.request({
923		url: zyCGI_P,
924		method: 'POST',
925		params: { filter:'js2', cmd:configCLI },
926		failure: function(response,options) {
927			Ext.getBody().unmask();
928			if(response.status == -1 || response.status == 0){ /* request timeout */
929				Ext.Msg.alert('Device Error ','Wrong CLI command, device timeout or device logout.');
930			}
931			else {
932				Ext.Msg.alert('Error Message',response.responseText);
933			}
934		},		
935		callback: function(options, success, response) {
936			if(success) {
937				var headers = response.getAllResponseHeaders();
938				var res = Ext.decode(js2json(response.responseText, (headers['expires'] != undefined)));
939				if(Ext.isEmpty(nextPage)){
940					Ext.getBody().unmask();
941				}else{
942					var regular = /^zldapp/;
943					var openwin = regular.test(nextPage);//if openwin == true, it a case to open a window
944					var win = openwin? Ext.ComponentQuery.query('zywindow'):null;
945					var TopWin = (win != null) ? (win.length > 0 ? win[win.length-1] : null) : null;
946					if(refreshTime != undefined && refreshTime > 0) {
947						setTimeout(function(){
948							if(openwin){
949								if( TopWin != null && TopWin.title != 'CLI'){
950									btnClick = TopWin.which;			
951									TopWin.close();
952								}
953								callPage(nextPage, btnClick);
954							}else
955								resetPage(nextPage);
956						}, refreshTime);
957					}else{
958						if(openwin){
959							if( TopWin != null && TopWin.title != 'CLI'){
960								btnClick = TopWin.which;								
961								TopWin.close();
962							}
963							callPage(nextPage, btnClick);
964						}else					
965							resetPage(nextPage);
966					}
967				}
968			}
969		}
970	});
971}
972
973/* 1. Log return data status, i.e. error number and error message
974 * 2. Translate js format to json format
975 */
976function js2json(js, isExpired){
977	if (isExpired) {
978		keepMe = true;
979		top.location.href = '/';
980		return false;
981	}
982	var jsAry = js.match(/(zyshdata)+/g);//all string
983
984	if (jsAry != null) {
985		/* first count CLI # */
986		var ccnt = jsAry.length;
987
988		/* check error number and error massage */
989		for( var i = 0; i < ccnt; i++) {
990			var newJS = js.slice(js.search('errno'+i));
991			var errno = newJS.slice(newJS.search('=')+1, newJS.search('\;'));
992			errNo = errno;
993			if (errno == 0)  {
994				/* CLI return OK. Do nothing */
995			} else {
996				newJS = newJS.slice(newJS.search('errmsg'+i));
997				var errmsg = newJS.slice(newJS.search('=')+1, newJS.search('\;'));
998				/* replace js2 parser output "n\'t" to "n't". ex: can't */
999				errmsg = errmsg.replace(/n\\'t/, 'n\'t');
1000				if (errno > 0){
1001					/* warning message */
1002					Ext.Msg.alert('Warning Message', 'CLI Number: '+i+ '<br>Warning Number: '+ errno+'<br>Warning Message: '+errmsg);
1003					if(cliLog) Ext.zylog('### Warning Message', 'CLI Number: '+i+ ', Warning Number: '+ errno+', Warning Message: '+errmsg);
1004				}else{
1005					/* error message */
1006					if(errno == -999 && !zyshDead){
1007						var sec = 0;
1008						var initial = '10/25/2010 00:00:00 PM GMT+0800';
1009						
1010						Ext.getBody().unmask();
1011						zyshDead = true;
1012						var store = Ext.create('Ext.data.Store', {
1013							autoLoad: false,
1014							remoteSort: false,
1015							fields:['_Status'],
1016							proxy: {
1017								type: 'ajax',                     
1018								url: zyCGI_P,
1019								method: 'POST',      
1020								reader: new Ext.data.zyJsonReader({root:'zyshdata0'}),
1021								extraParams: { filter:'js2', cmd:composeCLI(['show diag-info status']), write:0}
1022							},                      
1023							listeners: {
1024								load: function() {
1025									/*if status involve btnKeywordstatus, Ok button will enabled.*/
1026									var progressMSG = store.getAt(0).get('_Status');
1027									var btnKeywordstatus = ['Done'];
1028									Ext.each(btnKeywordstatus, function(rec) {
1029										if(progressMSG.indexOf(rec) >= 0){
1030											//Ext.ComponentQuery.query('#licenseupdatewin> toolbar> button[text=no]')[0].enable();
1031											//runTask.stop(runTask.tasks[0]);
1032											runTask.stopAll();
1033											Ext.getBody().unmask();
1034											Ext.Msg.show({
1035												title: 'ERROR',
1036												msg: 'Error Message: '+errmsg+'<br/>'+
1037													  mlang['_Diag_Info_Collect_done']+'<br/>'+
1038													  mlang['_You_can_reboot_device'],
1039												minWidth: 250,
1040												modal: true,
1041												icon: Ext.Msg.ERROR,
1042												buttonText: {
1043													yes: mlang['_Reboot']
1044												},
1045								                buttons: Ext.Msg.YES,												
1046												fn:function(btn, text){
1047													switch(btn)
1048													{
1049														case "yes":
1050															ZYSHD_CLI_Check('no');
1051															Reboot_TimeCount();
1052															CHFW_RebootMonitor(1);							
1053														break;
1054														default:
1055														break;
1056													}
1057												}
1058											});
1059
1060											
1061											return false;
1062										}
1063									});
1064								}
1065							}
1066						});
1067
1068						Ext.Msg.show({
1069							title: 'ERROR',
1070							msg: 'Error Message: '+errmsg+'<br/>'+mlang['_Collect_Diag_Info_or_reboot'],
1071							minWidth: 250,
1072							modal: true,
1073							icon: Ext.Msg.ERROR,
1074							buttonText: {
1075								yes: mlang['_Collect_Diag_Info'],
1076								no: mlang['_Reboot']
1077							},
1078							fn:function(btn, text){
1079								switch(btn)
1080								{
1081									case "yes":
1082										ZYSHD_CLI_Check('yes');										
1083										task = {
1084											run: function() {
1085												Ext.getBody().mask("Collecting, please wait at lease 5 minutes: " + Ext.Date.format(Ext.Date.add(new Date(initial), Ext.Date.SECOND, sec), 'i:s'));
1086												store.reload();
1087												sec++;
1088											},
1089											interval: 1000
1090										}																
1091										runTask.start(task);
1092										break;
1093									case "no":
1094										ZYSHD_CLI_Check('no');
1095										break;
1096									default:
1097										break;
1098								}
1099							}
1100						});
1101
1102						return false;
1103
1104						
1105  					}else if(!zyshDead){							 
1106  						Ext.Msg.alert('Error Message', 'CLI Number: '+i+ '<br>Error Number: '+ errno+'<br>Error Message: '+errmsg);
1107						if(cliLog) Ext.zylog('### Error Message', 'CLI Number: '+i+ ', Error Number: '+ errno+', Error Message: '+errmsg);
1108						Ext.getBody().unmask();
1109						return false;
1110					}
1111				}
1112			}
1113		}
1114	}
1115	else {
1116		Ext.Msg.alert('Device Error ','Wrong CLI command, device timeout or device logout.');
1117		if(cliLog) { Ext.zylog('### Device Error ','Wrong CLI command, device timeout or device logout.');}
1118		Ext.getBody().unmask();
1119		return false;
1120	}
1121
1122	/* translate js to json format : replace "\{\}" to "" is dirty workaround */
1123	//js = js.replace(/var\s+/gi, '{"').replace(/;+/gi, '}').replace(/\=+/gi, '":').replace(/\}\s\{+/gi, ',').replace(/\{\}+/g, '');
1124	js = js.replace(/var\s+(\w+)\s*=\s*(.*);\n/gi, ',"$1":$2\n').replace(/,"zyshdata0"/, '{"zyshdata0"') + '}';
1125	if(debugLog) { Ext.zylog('### Response Start ', debugLog); Ext.zylog(js); Ext.zylog( '### Response End ');}
1126	return js;
1127}
1128
1129function composeCLI(CLIs){
1130	if(CLIs.length == 0) {Ext.zylog('### CLI is empty. '); return ''};
1131	if(cliLog){
1132		Ext.zylog('### CLI Start ');
1133		Ext.each(CLIs, function(r, i) {
1134			Ext.zylog('['+i+'] '+r);
1135		});
1136		Ext.zylog('### CLI End ')
1137	};
1138	return CLIs;
1139}
1140
1141
1142function composeMultiConfigCLI(configCLI){
1143	if(configCLI.length == 0) {Ext.zylog('### Configure CLI is empty.'); return ''};
1144
1145	if(cliLog) {
1146		Ext.zylog('### Configure CLI Start ');
1147		for (var i = 0; i < configCLI.length; i++) {
1148			Ext.zylog('['+i+'] '+configCLI[i]);
1149		}
1150		Ext.zylog('### Configure CLI End ');
1151	}
1152	return configCLI;
1153}
1154
1155var datePatterns = {//Date.patterns = {
1156	ISO8601Long:"Y-m-d H:i:s",
1157	ISO8601Short:"Y-m-d",
1158	ShortDate: "n/j/Y",
1159	LongDate: "l, F d, Y",
1160	FullDateTime: "l, F d, Y g:i:s A",
1161	MonthDay: "F d",
1162	ShortTime: "g:i A",
1163	LongTime: "g:i:s A",
1164	SortableDateTime: "Y-m-d\\TH:i:s",
1165	UniversalSortableDateTime: "Y-m-d H:i:sO",
1166	YearMonth: "F, Y",
1167	myDateTime: "Y-m-d / H:i:s",
1168	myClock: "H:i:s"
1169};
1170/* tree panel selecter */
1171function changeModule(moduleName, treeNodeId, tabId) {
1172		//reload the panel
1173		var treepanel = Ext.getCmp('tree-panel');
1174		var store;
1175 		var splitter = Ext.ComponentQuery.query('splitter')[0];		
1176		var treeNodeId = treeNodeId || null; 
1177		var tabId = tabId || null;
1178		switch(moduleName){
1179			case "config":
1180				Ext.getBody().mask('Loading...', 'x-mask-loading');
1181				store = Ext.data.StoreManager.lookup('treepanel.configPanel');
1182				
1183				setSplitterVisible(splitter);
1184				store.load({
1185			            scope : store,
1186			            callback : function(records, operation, success) {
1187							treepanel.reconfigure(store);
1188							setPanel(moduleName);
1189							treepanel.setTitle(mlang['_Configuration']);
1190							treeItem = treeRec.config;							
1191							if(Ext.isEmpty(treeItem.tabId)){// default path
1192									callDefaultTreePanelPage(treepanel,store,'interface','port-role');
1193							}
1194							else {
1195								callDefaultTreePanelPage(treepanel,store,treeItem.treeNodeId,treeItem.tabId);
1196									var node = store.getNodeById('r_Network');
1197									if(store.getNodeById(treeItem.treeNodeId).parentNode.internalId != 'r_Network')
1198										node.collapse();
1199							}
1200							top.document.title = deviceFQDN;							
1201							if (treeNodeId != null)
1202							{
1203								callMainPage(treeNodeId,tabId);
1204							}	
1205			            }
1206			     });
1207				break;
1208			case "monitor":
1209				Ext.getBody().mask('Loading...', 'x-mask-loading');								
1210				var store = Ext.data.StoreManager.lookup('treepanel.monitorPanel');
1211				setSplitterVisible(splitter);
1212				store.load({
1213			            scope : store,
1214			            callback : function(records, operation, success) {
1215							treepanel.reconfigure(store);		
1216							setPanel(moduleName);
1217							treepanel.setTitle(mlang['_Monitor']);
1218							treeItem = treeRec.monitor;							
1219							top.document.title = deviceFQDN;
1220							if(Ext.isEmpty(treeItem.tabId)){//default path 
1221									if(UTM_FEATURE_PROMOTION_SUPPORT){
1222										if(!utmsw_licensed){
1223											callDefaultTreePanelPage(treepanel,store,'sysstatus-port','port');
1224										}else{
1225											callDefaultTreePanelPage(treepanel,store,'atp-apstatistic','atp-appstatistic');
1226										}
1227									}else{
1228										callDefaultTreePanelPage(treepanel,store,'atp-apstatistic','atp-appstatistic');
1229									}
1230							}
1231							else {
1232								callDefaultTreePanelPage(treepanel,store,treeItem.treeNodeId,treeItem.tabId);
1233									var node = store.getNodeById('r_System_Status');
1234									if(store.getNodeById(treeItem.treeNodeId).parentNode.internalId != 'r_System_Status')
1235										node.collapse();
1236																
1237							}
1238							if (treeNodeId != null)
1239							{
1240								callMainPage(treeNodeId,tabId);
1241							}
1242						}
1243			        });				
1244				break;
1245			case "maintenance":
1246				Ext.getBody().mask('Loading...', 'x-mask-loading');								
1247				store = Ext.data.StoreManager.lookup('treepanel.maintenPanel');								
1248				setSplitterVisible(splitter);
1249				store.load({
1250					scope : store,
1251					callback : function(records, operation, success) {
1252						treepanel.reconfigure(store);		
1253						setPanel(moduleName);
1254						treepanel.setTitle(mlang['_Maintenance']);
1255						treeItem = treeRec.maintenance;						
1256						top.document.title = deviceFQDN;
1257						if(Ext.isEmpty(treeItem.tabId)){/* default path */
1258							callDefaultTreePanelPage(treepanel,store,'filemanager','configfile');
1259						}
1260						else 
1261							callDefaultTreePanelPage(treepanel,store,treeItem.treeNodeId,treeItem.tabId);				
1262						if (treeNodeId != null)
1263						{
1264							callMainPage(treeNodeId,tabId);
1265						}
1266					}
1267				});			
1268				break;
1269			case "dashboard":
1270				Ext.getBody().mask('Loading...', 'x-mask-loading');				
1271				treepanel.reconfigure(store);
1272				var contentPanel = Ext.ComponentQuery.query('viewport > panel[region="center"]')[0];					
1273				contentPanel.removeAll();
1274				Ext.Function.defer(function(){
1275					contentPanel.add({
1276						id: "dashboard",
1277						header:false,
1278						layout: 'fit',
1279						autoScroll:true,
1280						loader: {
1281							url: './app/view/dashboard/general/dashboard.js',
1282							renderer: 'component',
1283							autoLoad: true
1284						}                                  
1285					});
1286				}, 100);
1287				setPanel(moduleName);
1288				top.document.title = deviceFQDN;
1289				splitter.setVisible(false);
1290				break;
1291		}
1292		
1293		//treepanel.expandAll();
1294		if(moduleName == "dashboard")
1295			treepanel.collapse();
1296		else
1297			treepanel.expand();
1298		/*
1299			var myleftpanel = document.getElementById('leftPanel');
1300			var my_BGColor=(moduleName=="dashboard")?"#009aff;":"#009aff;";
1301			myleftpanel.setAttribute("style","background-color:"+my_BGColor);
1302		*/
1303}
1304
1305/* call edit/add object */
1306function callDefaultTreePanelPage(treepanel,store,treeNodeId, tabId){
1307	try {
1308		var node = store.getNodeById(treeNodeId);
1309		treepanel.selectPath(node.getPath());
1310		tabs = node.raw.tabs;	
1311		for (i = 0; i < tabs.length; i++) {
1312			tab = tabs[i];
1313			if (tab.id == tabId) {
1314				break;
1315			}
1316		}
1317		eOpts = {
1318			params : {
1319				tabIdx: i
1320			  }
1321		}
1322		treepanel.fireEvent('itemclick', treepanel.getSelectionModel(), node, i, eOpts);
1323	}catch(e){
1324		keepMe = true;
1325		top.location.href='/';
1326	}	 
1327}
1328
1329
1330function expandTree(){
1331	var treePtr = Ext.getCmp('tree-panel');
1332	treePtr.expand();
1333}
1334
1335/* setPanel */
1336function setPanel(className, fileName){
1337		document.getElementById("globalnav").className = className;
1338}
1339
1340/* check treepanel */
1341function checkPanel(ban){
1342	var treePtr = Ext.getCmp('tree-panel');
1343	if(Ext.fly('tree-panel-xsplit').isVisible()){
1344		treePtr.collapse();
1345		treePtr.on('collapse', function(){
1346			if(ban == 'dashboard'){
1347				Ext.fly('tree-panel-xcollapsed').setVisible(false);
1348			}
1349		});
1350	}
1351	if(Ext.get('tree-panel-xcollapsed').isVisible()){
1352		Ext.fly('tree-panel-xcollapsed').setVisible(false);
1353	}
1354}
1355
1356function setSplitterVisible(splitter){	
1357	if(!splitter.isVisible()){
1358		splitter.setVisible(true);					
1359	}		
1360}
1361
1362/* remove content panel */
1363/*
1364function rmCtPanel(id){
1365	Ext.getCmp(id).removeAll();
1366}
1367*/
1368/* browser cookie */
1369function createCookie(name,value,days) {
1370	if (days) {
1371		var date = new Date();
1372		date.setTime(date.getTime()+(days*24*60*60*1000));
1373		var expires = "; expires="+date.toGMTString();
1374	}
1375	else var expires = "";
1376	document.cookie = name+"="+value+expires+"; path=/";
1377}
1378
1379function readCookie(name) {
1380	var nameEQ = name + "=";
1381	var ca = document.cookie.split(';');
1382	for(var i=0;i < ca.length;i++) {
1383		var c = ca[i];
1384		while (c.charAt(0)==' ') c = c.substring(1,c.length);
1385		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
1386	}
1387	return null;
1388}
1389
1390function readParseCookie(name) {
1391	var myName = 'ext-' + name + "="; // ext-js format : ys-{cookiename}
1392	var c = document.cookie.split(';');
1393	var d = [];
1394	for (var i = 0, len = c.length; i < len; i++) {
1395		var eachCookie = c[i];
1396		while (eachCookie.charAt(0) == ' ')
1397			eachCookie = eachCookie.substring(1, eachCookie.length);
1398		if (eachCookie.indexOf(myName) == 0) {
1399			var mine = eachCookie;
1400			mine = mine.substring(myName.length + 4, mine.length); // 4 is s%3A
1401			myAry = mine.split('%20'); // since we use 'space' as delimitation
1402			return myAry;
1403		}
1404	}
1405	return null;
1406}
1407
1408function eraseCookie(name) {
1409	createCookie(name,"",-1);
1410}
1411
1412function callPage(winPath,btnClick){
1413		Ext.getBody().mask('Loading...', 'x-mask-loading');	
1414		try {
1415			TopicHistroty.push(Topic);			
1416			var win = Ext.create(winPath,{which: btnClick});
1417			win.show();	
1418			return win;
1419		}catch(e){
1420			keepMe = true;
1421			top.location.href='/';		
1422		}		
1423}
1424/* objec menu start */
1425function callPageNoMask(winPath,btnClick){
1426		//Ext.getBody().mask('Loading...', 'x-mask-loading');	
1427		try {
1428			TopicHistroty.push(Topic);			
1429			var win = Ext.create(winPath,{which: btnClick});
1430			win.show();	      
1431			return win;
1432		}catch(e){
1433			keepMe = true;
1434			top.location.href='/';		
1435		}		
1436}
1437/* This API mixd stores to be a big store which uses in comboBox
1438 * Note: It just combo Obj as well as Group Obj
1439 * Note: The Drop-Down menu can be sorted by this API 
1440 */
1441function mixStore3Obj(topOne, objStore, objItems, objTag, grpStore, grpMbrStore, grpItems, grpTag, objExcepSS) {
1442  	var d = [];
1443  	var found;
1444    var ANY = 1, OBJECT = 2, GROUP = 3;        
1445  	var objGet1, objGet2;
1446
1447    function mergeArrays() {
1448         return [].concat.apply([], arguments);
1449    }
1450  	if (topOne) {
1451      var fields = [];
1452      for(var i=1;i<objItems.length;i++){
1453        fields.push("");
1454      }      
1455  		Ext.each(topOne, function(val) {
1456        d.push(mergeArrays([d.length, val], fields, [ANY, 'Empty']));
1457  			/*type: 1 (any)*/
1458  		});
1459  	}	
1460  	/* Default sort by object and group object*/
1461  	if(typeof objStore == 'object') 
1462  		objStore.sort(objItems[0],'ASC');
1463
1464  	if(typeof grpStore == 'object') 
1465  		grpStore.sort(grpItems[0], 'ASC');
1466	
1467  	if (objStore) {
1468  		if (typeof objStore != 'string') {
1469  			objStore.each(function(rec) {
1470  				found = false;
1471          var objItemArray = []; 
1472          for(var i=0;i<objItems.length;i++){
1473            objItemArray.push(rec.get(objItems[i]));
1474          }
1475  				if (objExcepSS) {
1476  					objExcepSS.each(function(rec) {
1477  						if ( rec.get('_Name') == objItemArray[0] ) {
1478  							found = true;
1479  							return false;
1480  						}
1481  					});
1482                
1483  					if (!found)/*type: 2 (Object)*/
1484              d.push(mergeArrays([d.length], objItemArray, [OBJECT, objTag ? objTag : 'Empty']));
1485    				} else {
1486                d.push(mergeArrays([d.length], objItemArray, [OBJECT, objTag ? objTag : 'Empty']));            
1487    				}
1488  			});
1489  		}
1490  		else
1491          d.push(mergeArrays([d.length, objStore], fields, [OBJECT, objTag ? objTag : 'Empty']));
1492  	}
1493  	if (grpStore) {
1494  		if (typeof grpStore != 'string') {
1495  			grpStore.each(function(rec) {
1496  				found = false;
1497  				objGet = rec.get(grpItems[0]);
1498          var grpItemsArray = []; 
1499          for(var i=0;i<grpItems.length;i++){
1500            grpItemsArray.push(rec.get(grpItems[i]));
1501          }          
1502  				if (objExcepSS) {
1503  					objExcepSS.each(function(rec) {
1504  						if ( rec.get('_Name') == objGet ) {
1505  							found = true;
1506  							return false;
1507  						}
1508  					});
1509  					if (!found)/*type: 3 (Group)*/
1510              d.push(mergeArrays([d.length, objGet, grpMbrStore.findRecord('_Group_name',objGet).get('_Members')], grpItemsArray[1], [GROUP, grpTag ? grpTag : 'Empty']));
1511  				} else {
1512              d.push(mergeArrays([d.length, objGet, grpMbrStore.findRecord('_Group_name',objGet).get('_Members')], grpItemsArray[1], [GROUP, grpTag ? grpTag : 'Empty']));          
1513  				}
1514  			});
1515  		}
1516  		else
1517        d.push(mergeArrays([d.length, grpStore], fields, [GROUP, grpTag ? grpTag : 'Empty']));     
1518  	}
1519  	var bigStore = new Ext.data.SimpleStore({groupField: '_Obj_Type', fields: ['_ID', '_Name', '_Content', '_Type', '_Obj_Type', '_Tag'], data: d});
1520  	return bigStore;
1521}
1522/* objec menu end */
1523/* call edit/add object */
1524function resetPage(formid){
1525              Ext.getBody().mask('Loading', 'x-mask-loading');
1526		var activeTab = Ext.ComponentQuery.query('form#'+formid+'^zytab')[0].activeTab;
1527		if(activeTab != undefined)
1528			activeTab.getLoader().load();			
1529}
1530
1531/* call inline object, meanwhile, set null text and append to header */
1532function callInlineObj(btnClick){
1533		Ext.getBody().mask('Loading...', 'x-mask-loading');	
1534		try {		
1535			TopicHistroty.push(Topic);						
1536			var win = Ext.create(btnClick.winPath,{which: btnClick});
1537			win.show();		
1538			return win;	
1539		}catch(e){
1540			keepMe = true;
1541			top.location.href='/';		
1542		}			
1543}
1544/*function callInlineObj(filename, callerPath, position){
1545	var np = '../../common/page-store/'+filename+'.js';
1546	Ext.Ajax.request({
1547	   	url: np,
1548	   	method: 'GET',
1549	   	failure: function(response,options){
1550			Ext.Msg.alert('Error Message',response.responseText);
1551			Ext.getBody().unmask();
1552		},
1553		success: function(response,options){
1554			whoCallMe = callerPath;
1555			whoOpen = {oId: filename, pt: position};
1556			if (/^(radioedit|securityedit|macfilteredit|ssidedit|monprofedit)$/.test(filename)) 
1557				whoOpenAry.push(whoOpen);
1558			if (/html/.test(response.getResponseHeader['Content-Type'])) {
1559				keepMe = true;
1560				top.location.href = '/';
1561			} else
1562				eval(response.responseText);
1563		}
1564	});
1565}*/
1566
1567/* This API mixd stores to be a big store which uses in comboBox
1568 * Note: It just combo Obj as well as Group Obj
1569 */
1570function mixStore(topOne, objStore, objItem, objTag, grpStore, grpItem, grpTag, objExcepSS) {
1571	var d = [];
1572	var found;
1573	var objGet;
1574	if (topOne) {
1575		Ext.each(topOne, function(val) {
1576			d.push([d.length, val, 'Empty']);
1577		});
1578	}
1579	
1580	if (objStore) {
1581		if (typeof objStore != 'string') {
1582			objStore.each(function(rec) {
1583				found = false;
1584				objGet = rec.get(objItem);
1585				if (objExcepSS) {
1586					objExcepSS.each(function(rec) {
1587						if ( rec.get('_Name') == objGet ) {
1588							found = true;
1589							return false;
1590						}
1591					});
1592					if (!found)
1593						d.push([d.length, objGet, objTag ? objTag : 'Empty']);
1594				} else {
1595					d.push([d.length, objGet, objTag ? objTag : 'Empty']);
1596				}
1597			});
1598		}
1599		else
1600			d.push([d.length, objStore, objTag ? objTag : 'Empty']);
1601	}
1602	if (grpStore) {
1603		if (typeof grpStore != 'string') {
1604			grpStore.each(function(rec) {
1605				found = false;
1606				objGet = rec.get(grpItem);
1607				if (objExcepSS) {
1608					objExcepSS.each(function(rec) {
1609						if ( rec.get('_Name') == objGet ) {
1610							found = true;
1611							return false;
1612						}
1613					});
1614					if (!found)
1615						d.push([d.length, objGet, grpTag ? grpTag : 'Empty']);
1616				} else {
1617					d.push([d.length, objGet, grpTag ? grpTag : 'Empty']);
1618				}
1619			});
1620		}
1621		else
1622			d.push([d.length, grpStore, grpTag ? grpTag : 'Empty']);
1623	}
1624	var bigStore = new Ext.data.SimpleStore({fields: ['_ID', '_Name', '_Tag'], data: d});
1625	return bigStore;
1626}
1627/* This API mixd stores to be a big store which uses in comboBox
1628 * Note: It just combo Obj as well as Group Obj
1629 * Note: It can add top one and buttom one
1630 */
1631function mixStore_bottom(topOne, bottomOne, bottomTag, objStore, objItem, objTag, grpStore, grpItem, grpTag, objExcepSS) {
1632	var d = [];
1633	var found;
1634	var objGet;
1635	if (topOne) {
1636		Ext.each(topOne, function(val) {
1637			d.push([d.length, val, 'Empty']);
1638		});
1639	}
1640	
1641	if (objStore) {
1642		if (typeof objStore != 'string') {
1643			objStore.each(function(rec) {
1644				found = false;
1645				objGet = rec.get(objItem);
1646				if (objExcepSS) {
1647					objExcepSS.each(function(rec) {
1648						if ( rec.get('_Name') == objGet ) {
1649							found = true;
1650							return false;
1651						}
1652					});
1653					if (!found)
1654						d.push([d.length, objGet, objTag ? objTag : 'Empty']);
1655				} else {
1656					d.push([d.length, objGet, objTag ? objTag : 'Empty']);
1657				}
1658			});
1659		}
1660		else
1661			d.push([d.length, objStore, objTag ? objTag : 'Empty']);
1662	}
1663	if (grpStore) {
1664		if (typeof grpStore != 'string') {
1665			grpStore.each(function(rec) {
1666				found = false;
1667				objGet = rec.get(grpItem);
1668				if (objExcepSS) {
1669					objExcepSS.each(function(rec) {
1670						if ( rec.get('_Name') == objGet ) {
1671							found = true;
1672							return false;
1673						}
1674					});
1675					if (!found)
1676						d.push([d.length, objGet, grpTag ? grpTag : 'Empty']);
1677				} else {
1678					d.push([d.length, objGet, grpTag ? grpTag : 'Empty']);
1679				}
1680			});
1681		}
1682		else
1683			d.push([d.length, grpStore, grpTag ? grpTag : 'Empty']);
1684	}
1685	if (bottomOne) {
1686		Ext.each(bottomOne, function(val) {
1687			d.push([d.length, val, bottomTag ? bottomTag : 'Empty']);
1688		});
1689	}
1690	var bigStore = new Ext.data.SimpleStore({fields: ['_ID', '_Name', '_Tag'], data: d});
1691	return bigStore;
1692}
1693/* This API mixd stores to be a big store which uses in comboBox 
1694 * Note: It just combo Obj as well as Group Obj. It exludes the "ext-group-user" type user. 
1695 */
1696function mixStore2(topOne, objStore, objItem, objTag, grpStore, grpItem, grpTag) {
1697		var d = [];
1698		var found;
1699		var objGet;
1700		if (topOne) {
1701			Ext.each(topOne, function(val) {
1702				d.push([d.length, val, 'Empty']);
1703			});	
1704		}
1705	
1706		if (objStore) {
1707			if (typeof objStore != 'string') {
1708				objStore.each(function(rec) {
1709					found = false;
1710					objGet = rec.get(objItem);
1711					if(rec.get('_User_Type') != 'ext-group-user')
1712							d.push([d.length, objGet, objTag ? objTag : 'Empty']);
1713				});
1714			}else
1715				d.push([d.length, objStore, objTag ? objTag : 'Empty']);
1716		}
1717		if (grpStore) {
1718			if (typeof grpStore != 'string') {
1719				grpStore.each(function(rec) {
1720					found = false;
1721					objGet = rec.get(grpItem);
1722					d.push([d.length, objGet, grpTag ? grpTag : 'Empty']);
1723				});
1724			}
1725			else
1726				d.push([d.length, grpStore, grpTag ? grpTag : 'Empty']);
1727		}
1728		var bigStore = new Ext.data.SimpleStore({fields: ['_ID', '_Name', '_Tag'], data: d});
1729		return bigStore;
1730	}
1731
1732/* This API mixd stores to be a big store which uses in comboBox
1733 * Note: It just combo Obj as well as Group Obj
1734 * Note: The Drop-Down menu can be sorted by this API 
1735 */
1736function mixStore3(topOne, objStore, objItem, objTag, grpStore, grpItem, grpTag, objExcepSS) {
1737	var d = [];
1738	var found;
1739	var objGet;
1740	if (topOne) {
1741		Ext.each(topOne, function(val) {
1742			d.push([d.length, val, 'Empty']);
1743		});
1744	}
1745	
1746	/* Default sort by object and group object*/
1747	
1748	if(typeof objStore == 'object') 
1749		objStore.sort(objItem,'ASC');
1750
1751	if(typeof grpStore == 'object') 
1752		grpStore.sort(grpItem, 'ASC');
1753	
1754	if (objStore) {
1755		if (typeof objStore != 'string') {
1756			objStore.each(function(rec) {
1757				found = false;
1758				objGet = rec.get(objItem);
1759				if (objExcepSS) {
1760					objExcepSS.each(function(rec) {
1761						if ( rec.get('_Name') == objGet ) {
1762							found = true;
1763							return false;
1764						}
1765					});
1766					if (!found)
1767						d.push([d.length, objGet, objTag ? objTag : 'Empty']);
1768				} else {
1769					d.push([d.length, objGet, objTag ? objTag : 'Empty']);
1770				}
1771			});
1772		}
1773		else
1774			d.push([d.length, objStore, objTag ? objTag : 'Empty']);
1775	}
1776	if (grpStore) {
1777		if (typeof grpStore != 'string') {
1778			grpStore.each(function(rec) {
1779				found = false;
1780				objGet = rec.get(grpItem);
1781				if (objExcepSS) {
1782					objExcepSS.each(function(rec) {
1783						if ( rec.get('_Name') == objGet ) {
1784							found = true;
1785							return false;
1786						}
1787					});
1788					if (!found)
1789						d.push([d.length, objGet, grpTag ? grpTag : 'Empty']);
1790				} else {
1791					d.push([d.length, objGet, grpTag ? grpTag : 'Empty']);
1792				}
1793			});
1794		}
1795		else
1796			d.push([d.length, grpStore, grpTag ? grpTag : 'Empty']);
1797	}
1798	var bigStore = new Ext.data.SimpleStore({fields: ['_ID', '_Name', '_Tag'], data: d});
1799	return bigStore;
1800}
1801
1802function mixStore_ike(topOne, aStore, aItem, aTag, bStore, bItem, bTag, cStore, cItem, cTag, objExcepSS) {
1803	var d = [];
1804	var found;
1805	var objGet;
1806	if (topOne) {
1807		Ext.each(topOne, function(val) {
1808			d.push([d.length, val, 'Empty']);
1809		});
1810	}
1811	
1812	/* Default sort by object and group object*/
1813	
1814	if(typeof aStore == 'object') 
1815		aStore.sort(aItem,'ASC');
1816
1817	if(typeof bStore == 'object') 
1818		bStore.sort(aItem,'ASC');
1819    
1820	if(typeof cStore == 'object') 
1821		cStore.sort(cItem, 'ASC');
1822	
1823	if (aStore) {
1824		if (typeof aStore != 'string') {
1825			aStore.each(function(rec) {
1826				found = false;
1827				objGet = rec.get(aItem);
1828				if (objExcepSS) {
1829					objExcepSS.each(function(rec) {
1830						if ( rec.get('_Name') == objGet ) {
1831							found = true;
1832							return false;
1833						}
1834					});
1835					if (!found)
1836						d.push([d.length, objGet, aTag ? aTag : 'Empty']);
1837				} else {
1838					d.push([d.length, objGet, aTag ? aTag : 'Empty']);
1839				}
1840			});
1841		}
1842		else
1843			d.push([d.length, aStore, aTag ? aTag : 'Empty']);
1844	}
1845
1846	if (bStore) {
1847		if (typeof bStore != 'string') {
1848			bStore.each(function(rec) {
1849				found = false;
1850				objGet = rec.get(bItem);
1851				if (objExcepSS) {
1852					objExcepSS.each(function(rec) {
1853						if ( rec.get('_Name') == objGet ) {
1854							found = true;
1855							return false;
1856						}
1857					});
1858					if (!found)
1859						d.push([d.length, objGet, bTag ? bTag : 'Empty']);
1860				} else {
1861					d.push([d.length, objGet, bTag ? bTag : 'Empty']);
1862				}
1863			});
1864		}
1865		else
1866			d.push([d.length, bStore, bTag ? bTag : 'Empty']);
1867	}
1868    
1869	if (cStore) {
1870		if (typeof cStore != 'string') {
1871			cStore.each(function(rec) {
1872				found = false;
1873				objGet = rec.get(cItem);
1874				if (objExcepSS) {
1875					objExcepSS.each(function(rec) {
1876						if ( rec.get('_Name') == objGet ) {
1877							found = true;
1878							return false;
1879						}
1880					});
1881					if (!found)
1882						d.push([d.length, objGet, cTag ? cTag : 'Empty']);
1883				} else {
1884					d.push([d.length, objGet, cTag ? cTag : 'Empty']);
1885				}
1886			});
1887		}
1888		else
1889			d.push([d.length, cStore, cTag ? cTag : 'Empty']);
1890	}
1891	var bigStore = new Ext.data.SimpleStore({fields: ['_ID', '_Name', '_Tag'], data: d});
1892	return bigStore;
1893}
1894
1895function mixStore_apstatus(topOne, aStore, aItem, aTag, bStore, bItem, bTag, cStore, cItem, cTag, objExcepSS) {
1896	var d = [];
1897	var found;
1898	var objGet;
1899	if (topOne) {
1900		Ext.each(topOne, function(val) {
1901			d.push([d.length, val, 'Empty']);
1902		});
1903	}
1904	
1905	/* Default sort by object and group object*/
1906	
1907	if(typeof aStore == 'object') 
1908		//aStore.sort(aItem,'ASC');
1909
1910	if(typeof bStore == 'object') 
1911		//bStore.sort(aItem,'ASC');
1912    
1913	if(typeof cStore == 'object') 
1914		//cStore.sort(cItem, 'ASC');
1915	
1916	if (aStore) {
1917		if (typeof aStore != 'string') {
1918			aStore.each(function(rec) {
1919				found = false;
1920				objGet = rec.get(aItem);
1921				if (objExcepSS) {
1922					objExcepSS.each(function(rec) {
1923						if ( rec.get('_Name') == objGet ) {
1924							found = true;
1925							return false;
1926						}
1927					});
1928					if (!found)
1929						d.push([d.length, objGet, aTag ? aTag : 'Empty']);
1930				} else {
1931					d.push([d.length, objGet, aTag ? aTag : 'Empty']);
1932				}
1933			});
1934		}
1935		else
1936			d.push([d.length, aStore, aTag ? aTag : 'Empty']);
1937	}
1938
1939	if (bStore) {
1940		if (typeof bStore != 'string') {
1941			bStore.each(function(rec) {
1942				found = false;
1943				objGet = rec.get(bItem);
1944				if (objExcepSS) {
1945					objExcepSS.each(function(rec) {
1946						if ( rec.get('_Name') == objGet ) {
1947							found = true;
1948							return false;
1949						}
1950					});
1951					if (!found)
1952						d.push([d.length, objGet, bTag ? bTag : 'Empty']);
1953				} else {
1954					d.push([d.length, objGet, bTag ? bTag : 'Empty']);
1955				}
1956			});
1957		}
1958		else
1959			d.push([d.length, bStore, bTag ? bTag : 'Empty']);
1960	}
1961    
1962	if (cStore) {
1963		if (typeof cStore != 'string') {
1964			cStore.each(function(rec) {
1965				found = false;
1966				objGet = rec.get(cItem);
1967				if (objExcepSS) {
1968					objExcepSS.each(function(rec) {
1969						if ( rec.get('_Name') == objGet ) {
1970							found = true;
1971							return false;
1972						}
1973					});
1974					if (!found)
1975						d.push([d.length, objGet, cTag ? cTag : 'Empty']);
1976				} else {
1977					d.push([d.length, objGet, cTag ? cTag : 'Empty']);
1978				}
1979			});
1980		}
1981		else
1982			d.push([d.length, cStore, cTag ? cTag : 'Empty']);
1983	}
1984	var bigStore = new Ext.data.SimpleStore({fields: ['_ID', '_Name', '_Tag'], data: d});
1985	return bigStore;
1986}
1987
1988
1989/* This API will find the address content follows the object name in combobox */
1990function addrSuffixWithGeoIP(value, isdst) {
1991	var suffix = ' ', found = false;
1992	var typeRe = /^(SUBNET|INTERFACE SUBNET)$/;
1993	
1994	if(isdst){
1995		showAddressAll.clearFilter(true); 
1996		showAddressGrpAll.clearFilter(true); 
1997	}
1998	
1999	if ( value != '' && value != 'any') {
2000		showAddressAll.each(function(rec){
2001			if (rec.get('_Object_name') == value) {
2002				found = true;
2003				if (rec.get('_Type').match(typeRe))
2004					suffix = rec.get('_Type') + ', ' + rec.get('_Address')[0] + '/' + rec.get('_Address')[1];
2005				else if (rec.get('_Type') == "RANGE")
2006					suffix = rec.get('_Type') + ', ' + rec.get('_Address')[0] + '-' + rec.get('_Address')[1];
2007				else
2008					suffix = rec.get('_Type') + ', ' + rec.get('_Address');
2009				return false;
2010			}
2011		});
2012		if (!found) {
2013			showAddressGrpAll.each(function(rec) {
2014				if (rec.get('_Group_name') == value) {
2015					suffix = 'Group';
2016					if (!Ext.isEmpty(rec.get('_Description')))
2017						suffix = suffix + ', ' + rec.get('_Description');
2018					return false;
2019				}
2020			});
2021		}
2022	}
2023	return suffix;
2024}
2025function addrSuffix(value) {
2026	var suffix = ' ', found = false;
2027	var typeRe = /^(SUBNET|INTERFACE SUBNET)$/;
2028
2029	if ( value != '' && value != 'any') {
2030		showAddress.each(function(rec) {
2031			if (rec.get('_Object_name') == value) {
2032				found = true;
2033				if (rec.get('_Type').match(typeRe))
2034					suffix = rec.get('_Type') + ', ' + rec.get('_Address')[0] + '/' + rec.get('_Address')[1];
2035				else if (rec.get('_Type') == "RANGE")
2036					suffix = rec.get('_Type') + ', ' + rec.get('_Address')[0] + '-' + rec.get('_Address')[1];
2037				else
2038					suffix = rec.get('_Type') + ', ' + rec.get('_Address');
2039				return false;
2040			}
2041		});
2042		if (!found) {
2043			showAddressGrp.each(function(rec) {
2044				if (rec.get('_Group_name') == value) {
2045					suffix = 'Group';
2046					if (!Ext.isEmpty(rec.get('_Description')))
2047						suffix = suffix + ', ' + rec.get('_Description');
2048					return false;
2049				}
2050			});
2051		}
2052	}
2053	return suffix;
2054}
2055
2056function addr6Suffix(value) {
2057        var suffix = ' ', found = false;
2058        var typeRe = /^(SUBNET|INTERFACE SUBNET)$/;
2059
2060        if ( value != '' && value != 'any') {
2061                showAddress6.each(function(rec) {
2062                        if (rec.get('_Object_name') == value) {
2063                                found = true;
2064                                if (rec.get('_Type').match(typeRe))
2065                                        suffix = rec.get('_Type') + ', ' + rec.get('_Address')[0] + '/' + rec.get('_Address')[1];
2066                                else if (rec.get('_Type') == "RANGE")
2067                                        suffix = rec.get('_Type') + ', ' + rec.get('_Address')[0] + '-' + rec.get('_Address')[1];
2068                                else {
2069					if (typeof rec.get('_Address') == 'object')
2070						suffix = rec.get('_Type') + ', ' + rec.get('_Address')[0];
2071					else
2072						suffix = rec.get('_Type') + ', ' + rec.get('_Address');
2073				}
2074
2075				if (rec.get('_Address_Type'))
2076					suffix = suffix + '(' + rec.get('_Address_Type') + ')';
2077                                return false;
2078                        }
2079                });
2080                if (!found) {
2081                        showAddress6Grp.each(function(rec) {
2082                                if (rec.get('_Group_name') == value) {
2083                                        suffix = 'Group';
2084                                        if (!Ext.isEmpty(rec.get('_Description')))
2085                                                suffix = suffix + ', ' + rec.get('_Description');
2086                                        return false;
2087                                }
2088                        });
2089                }
2090        }
2091        return suffix;
2092}
2093
2094/* This API will find the Schedule content follows the object name in combobox */
2095function schSuffix(value) {
2096	var suffix = ' ', found = false;
2097	var _once = '{0}-{1}-{2} {3}:{4} / {5}-{6}-{7} {8}:{9}';
2098	var _recur = '{0}:{1}-{2}:{3}';
2099
2100	if (value != '' && value != 'none') {
2101		showSchedule.each(function(rec) {
2102			if (rec.get('_Object_name') == value) {
2103				found = true;
2104				var se = rec.get('_Start_End');
2105				if (rec.get('_Type') == 'Recurring') {
2106					_recur = String(_recur).replace(/\{(\d+)\}/g, function(m,i) {return se[i];});
2107					suffix = rec.get('_Type') + ', ' + _recur;
2108				} else {
2109					_once = String(_once).replace(/\{(\d+)\}/g, function(m,i) {return se[i];});
2110					suffix = rec.get('_Type') + ', ' + _once;
2111				}
2112				return false;
2113			}
2114		});
2115	}
2116	return suffix;
2117}
2118
2119/* This API will find the address content follows the object name in combobox */
2120function ifaceSuffix(value) {
2121	var suffix = ' ';
2122
2123	if ( value != '' && value != 'any') {
2124		showIfaceALL.each(function(rec) {
2125			if (rec.get('_Name') == value) {
2126				suffix = rec.get('_IP_Assignment') + ' -- ' + rec.get('_IP_Address') + '/' + rec.get('_Mask');
2127				return false;
2128			}
2129		});
2130	}
2131	return suffix;
2132}
2133
2134function iface6Suffix(value) {
2135        var tips = '';
2136	var _tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Address:</b> {1}';
2137	var v6if_record, isTunnel = false;
2138	var v6ifs_store_data_addr;	
2139
2140        if ( value != '' && value != 'any') {
2141		showIpv6IfaceAllEth.each(function(rec) {
2142                	if( rec.get('_interface_name') == value ) {
2143                        	v6if_record = rec;
2144                        	return false;
2145                	}
2146        	});
2147        	if( typeof(v6if_record) == "undefined" )
2148       			showIpv6IfaceAllPPP.each(function(rec) {
2149                		if( rec.get('_interface_name') == value ) {
2150                        		v6if_record = rec;
2151                        		return false;
2152                		}
2153        		});
2154        	if( typeof(v6if_record) == "undefined" )
2155        		showIpv6IfaceAllVlan.each(function(rec) {
2156                	if( rec.get('_interface_name') == value ) {
2157                        	v6if_record = rec;
2158                        	return false;
2159                	}
2160        	});
2161        	if( typeof(v6if_record) == "undefined" )
2162        		showIpv6IfaceAllBridge.each(function(rec) {
2163                	if( rec.get('_interface_name') == value ) {
2164                        	v6if_record = rec;
2165                        	return false;
2166                	}
2167        	});
2168		if( typeof(v6if_record) == "undefined" )
2169        		showIfaceTunnel.each(function(rec) {
2170                	if( rec.get('_interface_name') == value ) {
2171                        	isTunnel = true;
2172                        	v6if_record = rec;
2173                        	return false;
2174                	}
2175        	});
2176
2177		if( typeof(v6if_record) != "undefined" ) {
2178			if(isTunnel)
2179                        	var cnt = v6if_record.get('_ipv6_address_count');
2180                	else
2181                		var cnt = v6if_record.get('_address_count');
2182
2183			/* address list */
2184			v6ifs_store_data_addr = "";
2185                	if( cnt != 0 ) {
2186                        	for( i = 1 ; i <= cnt ; ++i ) {
2187                                	//if( i != cnt ) {
2188                                        	v6ifs_store_data_addr += '<\/br>';
2189                                	//}
2190                                	if(isTunnel)
2191                                        	v6ifs_store_data_addr += v6if_record.get('_ipv6_address'+i);
2192                                	else
2193                                		v6ifs_store_data_addr += v6if_record.get('_address'+i);
2194                        	}
2195                	} else {
2196                        	v6ifs_store_data_addr = '::';
2197                	}
2198
2199			tips = Ext.String.format(_tips, value, v6ifs_store_data_addr);
2200		}		
2201        }
2202	if (tips != "")
2203		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
2204                                '<img src="/ext-js/images/usg/others/i_tooltip.gif">' + "IPv6 address" + '</a>';
2205        else
2206		return value;
2207}
2208
2209function vpnGWSuffix(value) {
2210	var suffix = ' ';
2211	if ( value != '' && value != 'any') {
2212		showIkePolicy.each(function(rec) {
2213			if (rec.get('__name') == value) {
2214				suffix = rec.get('_my_address').__name + '&nbsp&nbsp&nbsp' + rec.get('_secure_gateway_address')[0]._address + ', ' + rec.get('_secure_gateway_address')[1]._address;
2215				return false;
2216			}
2217		});
2218		if (suffix == ' ') {
2219			showIkePolicy6.each(function(rec) {
2220                        	if (rec.get('__name') == value) {
2221                                	suffix = rec.get('_my_address').__name + '&nbsp&nbsp&nbsp' + rec.get('_secure_gateway_address')[0]._address /* + ', ' + rec.get('_secure_gateway_address')[1]._address */;
2222                               		return false;
2223                        	}
2224                	});
2225		}
2226	}
2227	return suffix;
2228}
2229
2230function vpnGWIKEversion(phase1_name) {
2231	var suffix = ' ';
2232	if ( phase1_name != 'manual key' ) {
2233		showIkePolicy.each(function(rec) {
2234			if (rec.get('__name') == phase1_name) {
2235				suffix = rec.get('_IKE_version');
2236				return false;
2237			}
2238		});
2239		if (suffix == ' ') {
2240			showIkePolicy6.each(function(rec) {
2241                        	if (rec.get('__name') == phase1_name) {
2242                                suffix = 'IKEv2';
2243                                return false;
2244                        	}
2245                	});
2246		}
2247	}else{
2248        suffix = 'IKEv2';
2249    }
2250	return suffix;
2251}
2252
2253function vpnCryptRuleType(phase2_name) {
2254	var type = ' ';
2255	showCryptMap.each(function(rec) {
2256		if (rec.get('__name') == phase2_name) {
2257			type = 'v4';
2258			return false;
2259		}
2260	});
2261	if (type == ' ') {
2262		showCryptMap6.each(function(rec) {
2263			if (rec.get('__name') == phase2_name) {
2264				type = 'v6';
2265				return false;
2266			}
2267		});
2268	}
2269	return type ;
2270}
2271
2272function BWMServiceSuffix(value) {
2273	var suffix = ' ';
2274
2275	if ( value != '' && value != 'any') {
2276		showAppAllDefault.each(function(rec) {
2277			if (rec.get('_Service') == value) {
2278				suffix = '( Port: '+ rec.get('_Members') +' )';
2279				return false;
2280			}
2281		});
2282		
2283		showService.each(function(rec) {
2284			if (rec.get('_Object_name') == value) {
2285				suffix = '( Protocol: ' + rec.get('_Protocol') +' '+ rec.get('_Minmum_port') +'-'+  rec.get('_Maxmum_port') +' )';
2286				return false;
2287			}
2288		});
2289
2290		showServiceGrpMems.each(function(rec) {
2291			if (rec.get('_Group_name') == value) {
2292				suffix = '( Members: ' + rec.get('_Members') +' )';
2293				return false;
2294			}
2295		});
2296	}
2297	return suffix;
2298}
2299
2300/* finRecord use to find correspond record. It uses only in comboBox */
2301function findIndex(store, which) {
2302	var idx;
2303	store.each(function(r) {
2304		if (r.data['_Name'] == which) {
2305			idx = r.data['_ID'];
2306			return false;
2307		}
2308	});
2309	return idx;
2310}
2311
2312function findColumnIndex (columns, dataIndex) {
2313    var index;
2314    for (index = 0; index < columns.length; ++index) {
2315        if (columns[index].dataIndex == dataIndex) { break; }
2316    }
2317    return index == columns.length ? -1 : index;
2318}
2319
2320
2321/* help */
2322var theHelp;
2323var Context='Help';
2324var Topic='Dashboard';
2325var TopicHistroty=[];
2326var helpStr = '';
2327function openOnLineHelp(context, topic) {
2328    var helpLink;
2329    var http_prefix = 'http://';
2330    var webhelpDomain = 'http://aptest2.zyxel.tw';
2331    var onlineHelp;
2332	var topic_name;
2333	var isStr = isNaN(topic);                                                      
2334	if (isStr) {
2335		topic_name =  '&hash=context/' + Context + '/' + topic + '&help_version=2';
2336	} else {                    
2337		topic_name = '';
2338	}      
2339    // Process URL parameters
2340    Ext.Ajax.request({
2341            url: zyCGI_P,
2342            method: 'POST',
2343            params: { filter:'js2', cmd:['exit','show _gui webhelp redirect'], write:0},
2344            callback: function(options, success, response){
2345                if (success){
2346                        var data = response.responseText;
2347                        data = data.replace(/var\s+(\w+)\s*=\s*(.*);\n/gi, ',"$1":$2\n').replace(/,"zyshdata0"/, '{"zyshdata0"') + '}';
2348                        var mydata=Ext.decode(data);
2349                        webhelpDomain = mydata.zyshdata1[0]._Webhelp_redirect;
2350                    	helpLink = http_prefix + webhelpDomain + help_path + topic_name;                                                              
2351                    	onlineHelp = window.open(helpLink, 'helps', 'height='+window.screen.availHeight+', width='+window.screen.availWidth+ ', location=yes, status=no, scrollbars=yes, resizable=yes');                                    
2352                }
2353          }
2354    });
2355    
2356}
2357
2358function openHelp(context, topic){
2359	var str;
2360        if((context=='')&&(topic=='')){
2361                str = '';
2362        }else{
2363                str =  '#context/' + context + '/' + topic;
2364        }
2365
2366        if((theHelp == undefined)||(theHelp.closed)){
2367                theHelp = window.open('/ext-js/helps/index_help.html'+str, 'helps', 'width=920, height=600, location=no, status=no, scrollbars=yes, resizable=yes');
2368        }else{
2369            		// Firefox 1.0+
2370            		var isFirefox = typeof InstallTrigger !== 'undefined';
2371            		// Internet Explorer 6-11
2372            		var isIE = /*@cc_on!@*/false || !!document.documentMode;
2373                // Edge 20+
2374                var isEdge = !isIE && !!window.StyleMedia;        
2375                theHelp.location.href = '/ext-js/helps/index_help.html'+str;
2376          			if(isFirefox){         
2377          				  theHelp[0].location.replace(theHelp.location.href);  
2378          			}else if(isIE){                                 
2379          				  theHelp.access.location.reload(true);                    
2380          			}else if(isEdge){
2381                    theHelp.access.src = theHelp.location.href;
2382                    theHelp.access.replaceChild(theHelp.access.src); 
2383                }	                
2384        }
2385	      helpStr = str+'@'+help_path+'@'+kb_path;
2386}
2387
2388/* findPosition use to find id position. It uses in web page */
2389function findPosition() {
2390	var args = Array.prototype.slice.call(arguments, 0);
2391	for (var k in args[0]) {
2392		if (args[0][k].aliasId) {
2393			if (args[0][k].aliasId == args[1])
2394				return k;
2395		} else if (args[0][k].id == args[1])
2396			return k;
2397	}
2398}
2399
2400/* findALTPosition use to find id in second level position */
2401/* Used to alternate original one - findPosition(). */
2402/* It uses in web page cmds contained cmd array */
2403function findALTPosition() {
2404	var ret = '';
2405	var args = Array.prototype.slice.call(arguments, 0);
2406	for (var k in args[0]) {
2407		var sublist = args[0][k].id;
2408		if ( sublist instanceof Array ){
2409			for (var j in sublist) {
2410				if (sublist[j].id == args[1]){
2411					/* Note: Returned format 'k , j' of level 1 / 2 cmd idx */
2412					ret = k + ',' + j;
2413					return ret;
2414				}
2415			}
2416		}
2417	}
2418	return ret;
2419}
2420
2421/* used for handle field is changed or not */
2422function handleFn(record, field, newVal, oldVal) {
2423	record.set(field, newVal);
2424	if (newVal == oldVal) {
2425		if (record.modified)
2426			delete record.modified[field];
2427	}
2428	if(record.store!=undefined)	
2429		record.store.fireEvent("update", record.store, record, Ext.data.Model.EDIT); 
2430	var m = record.modified, doRemove = true;
2431	for (var n in m) {
2432		if (m.hasOwnProperty(n)) {
2433			doRemove = false;
2434			break;
2435		}
2436	}
2437	if(doRemove && (record.store!=undefined)){
2438		var modifiedRec = record.store.getModifiedRecords();
2439		//record.store.getModifiedRecords().remove(record); fran: no this method now
2440		for(var i =0; i < modifiedRec.length; i ++){
2441			if(record == modifiedRec[i])
2442				Ext.Array.splice(modifiedRec, i, 1);
2443		}			
2444	}
2445}
2446
2447function deepCloneStore(source) {
2448	    var target = Ext.create ('Ext.data.Store', {
2449	        model: source.model
2450	    });
2451
2452	    Ext.each (source.getRange (), function (record) {
2453	        var newRecordData = Ext.clone (record.copy().data);
2454	        var model = new source.model (newRecordData, newRecordData.id);
2455	        target.add (model);
2456	    });
2457	    return target;
2458}
2459
2460function recoverRecord(record, bkRecord) {
2461	var m = record.modified;
2462	for (var n in m) {
2463		record.set(n, bkRecord.get(n));
2464	}
2465	record.commit();
2466}
2467
2468function recover(record) {
2469	record.commit();
2470}
2471
2472function doubleQuateConvert(str) {
2473	return String(str).replace(/["]/g, '&#34;');//"
2474}
2475
2476/* mouse over usergroup */
2477function mouseOverUsergrp(data, metaData, record){
2478	var tips = '', d;
2479	var _tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Description:</b><br>{1}<br><b>Members:</b><br>';
2480	showUsersGrp.each(function(rec) {
2481		if (rec.get('__name') == data) {
2482			tips = Ext.String.format(_tips, rec.get('__name'), doubleQuateConvert(rec.get('_description')));
2483			if(typeof rec.get('_member') == 'string'){
2484				tips += rec.get('_member');
2485			}else{
2486				for(var i = 0; i < rec.get('_member').length; i++){
2487					if(i == rec.get('_member').length){
2488						tips += rec.get('_member')[i];
2489					}else{
2490						tips += rec.get('_member')[i] + '<br>';
2491					}
2492				}
2493			}
2494			return false;
2495		}
2496	});
2497
2498	if(tips != ""){
2499		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
2500				'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ data + '</a>';
2501	}else{
2502		return data;
2503	}
2504}
2505
2506/* mouse over Zone object */
2507function mouseOverZone(value, metaData, record, rowIndex, colIndex, store){
2508	if(value != '' && value != 'any' && value != ((ODM_CONFIG_ACTIVATE) ? ODM_SYSPARM_PRODUCT_SERIES_NAME : 'ZyWALL')){
2509		var tips = '';
2510		var _tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Members:</b><br>';
2511
2512		showZone.each(function(rec) {
2513			if (rec.get('_Name') == value) {
2514				tips = Ext.String.format(_tips, rec.get('_Name'));
2515				if(typeof rec.get('_Member') == 'string'){
2516					tips += rec.get('_Member');
2517				}else{
2518					for(var i = 0; i < rec.get('_Member').length; i++){
2519						if(i == rec.get('_Member').length){
2520							tips += rec.get('_Member')[i];
2521						}else{
2522							tips += rec.get('_Member')[i] + '<br>';
2523						}
2524					}
2525				}
2526				return false;
2527			}
2528		});
2529
2530		if(tips != ""){
2531			return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
2532					'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ value + '</a>';
2533		}else{
2534			return value;
2535		}
2536	}else{
2537		if(value == ''){
2538			return 'any';
2539		}else{
2540			return value;
2541		}
2542	}
2543}
2544function mouseOverSNAT(data, metaData, record, rowIndex, colIndex, store){
2545	var tips = '', _tips = '', Iface=[];
2546	_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Members:</b><br>';
2547
2548    switch(data){
2549        case 'External Interface':
2550            if(rowIndex==0)
2551    		    var Iface = showSnatExternal.getAt(0).get('_External_Interfaces');        
2552            else if(rowIndex==1) 
2553    		    var Iface = showVPNSnatExternal.getAt(0).get('_External_Interfaces');            
2554        break;
2555        case 'Internal Interface':
2556    		var Iface = showSnatInternal.getAt(0).get('_Internal_Interfaces');
2557        break;     
2558        case 'Remote Access VPN':
2559    		var Iface = showVPNSnatInternal.getAt(0).get('_Remote_Access_VPN');
2560        break;                        
2561    }
2562	tips = Ext.String.format(_tips, data);
2563    if (typeof Iface === 'undefined') {
2564    		tips += Iface + '<br>';        
2565    }else{
2566    	Ext.each(Iface, function(rec) {
2567    		tips += rec + '<br>';
2568    	});
2569    }
2570	
2571	if (tips != ""){
2572		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
2573			'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ data + '</a>';
2574	}else{
2575		return data;
2576	}
2577}
2578/* mouse over next-Hop Info Trunk object */
2579function mouseOverNexthopInfo(data, metaData, record, rowIndex, colIndex, store){
2580	var tips = '', _tips = '';
2581	var val, d, m, s, found = false;
2582	var typeRe = /^(SUBNET|INTERFACE SUBNET)$/;
2583	/* Trunk */
2584	if(store.getAt(rowIndex).get('_Trunk') != undefined){
2585		_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Algorithm:</b><br>{1}<br><b>Member/Mode/Status:</b><br>';
2586		showIfaceGrpSelf.each(function(rec) {
2587			if (rec.get('_Interface_Group') == data) {
2588				if(rec.get('_Algorithm') == 'llf') val = 'Least Load first';
2589				else if(rec.get('_Algorithm') == 'wrr') val = 'weighted Round Robin';
2590				else val = 'Spillover';
2591				tips = Ext.String.format(_tips, rec.get('_Interface_Group'), val);
2592				showIfaceGrpInfo.each(function(r, i) {
2593					tips += r.get('_Interface')+'/'+((r.get('_Passive')=='0')? 'Active':'Passive')+'/'+r.get('_Status')+'<br>';
2594				});
2595				return false;
2596			}
2597		});
2598	}
2599	if(store.getAt(rowIndex).get('_Nexthop_Type') == 'Trunk'){
2600		_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Algorithm:</b><br>{1}<br><b>Member/Mode/Status:</b><br>';
2601		showIfaceGrpMems.each(function(rec) {
2602			if (rec.get('_Interface_Group') == data) {
2603				d = rec.get('_Members').split(',');
2604				m = rec.get('_Passive').split(',');
2605				s = rec.get('_Status').split(',');
2606				if(rec.get('_Algorithm') == 'llf') val = 'Least Load first';
2607				else if(rec.get('_Algorithm') == 'wrr') val = 'weighted Round Robin';
2608				else val = 'Spillover';
2609				tips = Ext.String.format(_tips, rec.get('_Interface_Group'), val);
2610				for(var i = 0; i < d.length; i++){
2611					if( i == d.length ){
2612						tips += d[i]+'/'+((m[i]=='0')? 'Active':'Passive')+'/'+s[i];
2613					}else{
2614						tips += d[i]+'/'+((m[i]=='0')? 'Active':'Passive')+'/'+s[i]+'<br>';
2615					}
2616				}
2617				return false;
2618			}
2619		});
2620	}
2621	/* Auto */  
2622	if(store.getAt(rowIndex).get('_Nexthop_Type') == 'Auto'){
2623		return Ext.String.format('<a href="#" onClick="packetflow.routing.extraLink(\'{0}\');" >{0}</a>', data );
2624	}
2625	/* Interface */
2626	if(store.getAt(rowIndex).get('_Nexthop_Type') == 'Interface'){
2627		_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Assignment:</b> {1}<br><b>IP Address:</b> {2}<br><b>Mask:</b> {3}<br><b>Status:</b> {4}';
2628		showIfaceSumALL.each(function(rec) {
2629			if (rec.get('_Name') == data) {
2630				tips = Ext.String.format(_tips, rec.get('_Name'), rec.get('_IP_Assignment'), rec.get('_IP_Address'), rec.get('_Mask'), rec.get('_Status'));
2631				return false;
2632			}
2633		});
2634	}
2635	/* Address */
2636	if(store.getAt(rowIndex).get('_Nexthop_Type') == 'Gateway'){
2637		showAddress.each(function(rec) {
2638			if (rec.get('_Object_name') == data) {
2639				found = true;
2640				if (rec.get('_Type').match(typeRe)){
2641					_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Subnet:</b> {1}/{2}';
2642					tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2643				}else if (rec.get('_Type') == 'RANGE'){
2644					_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Range:</b> {1}-{2}';
2645					tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2646				}else{
2647					_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Address:</b> {1}';
2648					tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address'));
2649				}
2650				return false;
2651			}
2652		});
2653		if (!found) {
2654			showAddressGrpMems.each(function(rec) {
2655				if (rec.get('_Group_name') == data) {
2656					d = rec.get('_Members').split(',');
2657					_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Description:</b><br>{1}<br><b>Members:</b><br>';
2658					tips = Ext.String.format(_tips, rec.get('_Group_name'), doubleQuateConvert(rec.get('_Description')));
2659					for (var i = 0; i < d.length; i++) {
2660						if( i == d.length ){
2661							tips += d[i];
2662						}else{
2663							tips += d[i] + '<br>';
2664						}
2665					}
2666					return false;
2667				}
2668			});
2669		}
2670	}
2671	if (tips != ""){
2672		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
2673				'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ data + '</a>';
2674	}else
2675		return data;
2676}
2677var function_sourcelink = '';
2678var AP_decription = '';
2679function linkfortopNusage(treeNodeId, tabId, pagemodule, sourcelink, APdescrip){
2680	treeItem = treeRec.monitor;
2681	treeItem.treeNodeId = treeNodeId;
2682	treeItem.tabId = tabId;
2683	changeModule(pagemodule);
2684	function_sourcelink = sourcelink;
2685	AP_decription = APdescrip;
2686}
2687
2688/*
26891 = SNMP; 2 = CPU; 3 = Memory; 4 = Session; 5 = AP; 6 = Zymesh; 7 = Station;  8 = Login User; 9 = Radio List; 10 = Controller Log;
2690*/
2691var Log_filter = [];
2692var record4Filter = {};
2693function zylinkgoto(linkobj, record){
2694	switch(linkobj.toString()){
2695		case '1':
2696			treeItem = treeRec.config;
2697			treeItem.treeNodeId = 'system-snmp';
2698			treeItem.tabId = 'snmp';
2699			changeModule('config');
2700			break;
2701		case '2':
2702			subWin('app/view/dashboard/cpu', 'cpuWin', 600, 450);
2703			break;
2704		case '3':
2705			subWin('app/view/dashboard/memory', 'memWin', 600, 450);
2706			break;
2707		case '4':
2708			subWin('app/view/dashboard/session', 'sesWin', 600, 450);
2709			break;
2710		case '5':
2711			treeItem = treeRec.monitor;
2712			treeItem.treeNodeId = 'wirelessmonitor-apinfo-aplistmonito';
2713			treeItem.tabId = 'aplistmonitor';		
2714			if (record != undefined){
2715				record4Filter = record 
2716			}
2717			changeModule('monitor');
2718			break;
2719		case '6':
2720			treeItem = treeRec.monitor;
2721			treeItem.treeNodeId = 'wirelessmonitor-zymeshinfo';
2722			treeItem.tabId = 'zymesh';		
2723			changeModule('monitor');
2724			break;
2725		case '7':
2726			treeItem = treeRec.monitor;
2727			treeItem.treeNodeId = 'wirelessmonitor-stationinfo';
2728			treeItem.tabId = 'assoc';		
2729			if (record != undefined){
2730				record4Filter = record 
2731			}
2732			changeModule('monitor');
2733			break;
2734		case '8':
2735			treeItem = treeRec.monitor;
2736			treeItem.treeNodeId = 'sysstatus-loginuser';
2737			treeItem.tabId = 'loginuser';	
2738			GRID_RECORD_CURRENT = record;
2739			function_sourcelink = 'stationInfo';
2740			changeModule('monitor');
2741			break;
2742		case '9':
2743			treeItem = treeRec.monitor;
2744			treeItem.treeNodeId = 'wirelessmonitor-apinfo-aplistmonitor';
2745			treeItem.tabId = 'radiolist';	
2746			function_sourcelink = 'aplist';
2747			changeModule('monitor');
2748			break;
2749          	case '10':
2750			treeItem = treeRec.monitor;
2751			treeItem.treeNodeId = 'r_viewlog';
2752			function_sourcelink = 'aplistmonitor';
2753			treeItem.tabId = 'viewlog';
2754			Log_filter = record;
2755			changeModule('monitor');
2756			break;
2757	}
2758}
2759/* mouse over Trunk object */
2760function mouseOverNexthop(data, metaData, record, rowIndex, colIndex, store){
2761	var tips = '', _tips = '';
2762	var val, d, found = false;
2763	var typeRe = /^(SUBNET|INTERFACE SUBNET)$/;
2764
2765	/* Trunk */
2766	if(store.getAt(rowIndex).get('_nexthop_type') == 'Trunk'){
2767		_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Algorithm:</b><br>{1}<br><b>Member/Mode/Status:</b><br>';
2768		showIfaceGrpMems.each(function(rec) {
2769			if (rec.get('_Interface_Group') == data) {
2770				d = rec.get('_Members').split(',');
2771				m = rec.get('_Passive').split(',');
2772				s = rec.get('_Status').split(',');
2773				if(rec.get('_Algorithm') == 'llf') val = 'Least Load first';
2774				else if(rec.get('_Algorithm') == 'wrr') val = 'weighted Round Robin';
2775				else val = 'Spillover';
2776				tips = Ext.String.format(_tips, rec.get('_Interface_Group'), val);
2777				for(var i = 0; i < d.length; i++){
2778					if( i == d.length ){
2779						tips += d[i]+'/'+((m[i]=='0')? 'Active':'Passive')+'/'+s[i];
2780					}else{
2781						tips += d[i]+'/'+((m[i]=='0')? 'Active':'Passive')+'/'+s[i]+'<br>';
2782					}
2783				}
2784				return false;
2785			}
2786		});
2787	}
2788	/* Interface */
2789	if(store.getAt(rowIndex).get('_nexthop_type') == 'Interface'){
2790		        return gridtooltip.getIface(data, metaData, record);
2791	}
2792	/* Address */
2793	if(store.getAt(rowIndex).get('_nexthop_type') == 'Gateway'){
2794		showAddress.each(function(rec) {
2795			if (rec.get('_Object_name') == data) {
2796				found = true;
2797				if (rec.get('_Type').match(typeRe)){
2798					_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Subnet:</b> {1}/{2}';
2799					tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2800				}else if (rec.get('_Type') == 'RANGE'){
2801					_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Range:</b> {1}-{2}';
2802					tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2803				}else{
2804					_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Address:</b> {1}';
2805					tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address'));
2806				}
2807				return false;
2808			}
2809		});
2810		if (!found) {
2811			showAddressGrpMems.each(function(rec) {
2812				if (rec.get('_Group_name') == data) {
2813					d = rec.get('_Members').split(',');
2814					_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Description:</b><br>{1}<br><b>Members:</b><br>';
2815					tips = Ext.String.format(_tips, rec.get('_Group_name'), doubleQuateConvert(rec.get('_Description')));
2816					for (var i = 0; i < d.length; i++) {
2817						if( i == d.length ){
2818							tips += d[i];
2819						}else{
2820							tips += d[i] + '<br>';
2821						}
2822					}
2823					return false;
2824				}
2825			});
2826		}
2827	}
2828	if (tips != "")
2829		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
2830				'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ data + '</a>';
2831	else
2832		return data;
2833}
2834/* mouse over Trunk object */
2835function mouseOverNexthop6(data, metaData, record, rowIndex, colIndex, store){
2836	/* Interface */
2837	if(store.getAt(rowIndex).get('_nexthop_type') == 'Interface'){
2838        return gridtooltip.getIface6(data, metaData, record);
2839	}
2840	/* Address */
2841	if(store.getAt(rowIndex).get('_nexthop_type') == 'Gateway'){
2842		return mouseOverAddr6(data);
2843	}
2844	return data;
2845}
2846/* mouse over address object / group */
2847function mouseOverAddr(data, metaData, record) {
2848	var tips = '', _tips = '';
2849	var found = false;
2850	var typeRe = /^(SUBNET|INTERFACE SUBNET)$/;
2851	showAddress.each(function(rec) {
2852		if (rec.get('_Object_name') == data) {
2853			found = true;
2854			if (rec.get('_Type').match(typeRe)){
2855				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Subnet:</b> {1}/{2}';
2856				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2857			}else if (rec.get('_Type') == 'RANGE'){
2858				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Range:</b> {1}-{2}';
2859				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2860			}else{
2861				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Address:</b> {1}';
2862				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address'));
2863			}
2864			return false;
2865		}
2866	});
2867	if (!found) {
2868		var d;
2869		showAddressGrpMems.each(function(rec) {
2870			if (rec.get('_Group_name') == data) {
2871				d = rec.get('_Members').split(',');
2872				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Description:</b><br>{1}<br><b>Members:</b><br>';
2873				tips = Ext.String.format(_tips, rec.get('_Group_name'), doubleQuateConvert(rec.get('_Description')));
2874				for (var i = 0; i < d.length; i++) {
2875					if( i == d.length ){
2876						tips += d[i];
2877					}else{
2878						tips += d[i] + '<br>';
2879					}
2880				}
2881				return false;
2882			}
2883		});
2884	}
2885	if (tips != "")
2886		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
2887				'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ data + '</a>';
2888	else
2889		return data;
2890}
2891
2892/* mouse over address object / group and show Geo type */
2893function mouseOverAddrAll(data, metaData, record) {
2894	var tips = '', _tips = '';
2895	var found = false;
2896	var typeRe = /^(SUBNET|INTERFACE SUBNET)$/;
2897	showAddressAll.each(function(rec) {
2898		if (rec.get('_Object_name') == data) {
2899			found = true;
2900			if (rec.get('_Type').match(typeRe)){
2901				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Subnet:</b> {1}/{2}';
2902				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2903			}else if (rec.get('_Type') == 'RANGE'){
2904				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Range:</b> {1}-{2}';
2905				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2906			}else{
2907				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Address:</b> {1}';
2908				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address'));
2909			}
2910			return false;
2911		}
2912	});
2913	if (!found) {
2914		var d;
2915		showAddressGrpMemsAll.each(function(rec) {
2916			if (rec.get('_Group_name') == data) {
2917				d = rec.get('_Members').split(',');
2918				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Description:</b><br>{1}<br><b>Members:</b><br>';
2919				tips = Ext.String.format(_tips, rec.get('_Group_name'), doubleQuateConvert(rec.get('_Description')));
2920				for (var i = 0; i < d.length; i++) {
2921					if( i == d.length ){
2922						tips += d[i];
2923					}else{
2924						tips += d[i] + '<br>';
2925					}
2926				}
2927				return false;
2928			}
2929		});
2930	}
2931	if (tips != "")
2932		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
2933				'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ data + '</a>';
2934	else
2935		return data;
2936}
2937
2938/* mouse over address6 object / group and show Geo type */
2939function mouseOverAddr6All(data, metaData, record) {
2940	var tips = '', _tips = '';
2941	var found = false;
2942	var typeRe = /^(SUBNET|INTERFACE SUBNET)$/;
2943	showAddress6All.each(function(rec) {
2944		if (rec.get('_Object_name') == data) {
2945			found = true;
2946			if (rec.get('_Type').match(typeRe)){
2947				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Subnet:</b> {1}/{2}';
2948				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2949			}else if (rec.get('_Type') == 'RANGE'){
2950				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IPv6 Range:</b> {1}-{2}';
2951				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2952			}else{
2953				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IPv6 Address:</b> {1}';
2954				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address'));
2955			}
2956			return false;
2957		}
2958	});
2959	if (!found) {
2960		var d;
2961		showAddress6GrpMemsAll.each(function(rec) {
2962			if (rec.get('_Group_name') == data) {
2963				d = rec.get('_Members').split(',');
2964				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Description:</b><br>{1}<br><b>Members:</b><br>';
2965				tips = Ext.String.format(_tips, rec.get('_Group_name'), doubleQuateConvert(rec.get('_Description')));
2966				for (var i = 0; i < d.length; i++) {
2967					if( i == d.length ){
2968						tips += d[i];
2969					}else{
2970						tips += d[i] + '<br>';
2971					}
2972				}
2973				return false;
2974			}
2975		});
2976	}
2977	if (tips != "")
2978		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
2979				'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ data + '</a>';
2980	else
2981		return data;
2982}
2983
2984/* mouse over address6 object / group */
2985function mouseOverAddr6(data, metaData, record) {
2986	var tips = '', _tips = '';
2987	var found = false;
2988	var typeRe = /^(SUBNET|INTERFACE SUBNET)$/;
2989	showAddress6.each(function(rec) {
2990		if (rec.get('_Object_name') == data) {
2991			found = true;
2992			if (rec.get('_Type').match(typeRe)){
2993				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Subnet:</b> {1}/{2}';
2994				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2995			}else if (rec.get('_Type') == 'RANGE'){
2996				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IPv6 Range:</b> {1}-{2}';
2997				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address')[0], rec.get('_Address')[1]);
2998			}else{
2999				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IPv6 Address:</b> {1}';
3000				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Address'));
3001			}
3002			return false;
3003		}
3004	});
3005	if (!found) {
3006		var d;
3007		showAddress6GrpMems.each(function(rec) {
3008			if (rec.get('_Group_name') == data) {
3009				d = rec.get('_Members').split(',');
3010				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Description:</b><br>{1}<br><b>Members:</b><br>';
3011				tips = Ext.String.format(_tips, rec.get('_Group_name'), doubleQuateConvert(rec.get('_Description')));
3012				for (var i = 0; i < d.length; i++) {
3013					if( i == d.length ){
3014						tips += d[i];
3015					}else{
3016						tips += d[i] + '<br>';
3017					}
3018				}
3019				return false;
3020			}
3021		});
3022	}
3023	if (tips != "")
3024		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
3025				'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ data + '</a>';
3026	else
3027		return data;
3028}
3029
3030/* mouse over BWM Service (App Patrol Service/Service object/Service Object group) */
3031function mouseOverBWMService(data, metaData, record) {
3032	var tips = '', _tips = '';
3033	var found = false;
3034	var str;
3035	
3036	str = data.split(':');
3037	if(str[0] == 'Obj'){/* for Obj Service */
3038        return gridtooltip.getSrv(str[1], metaData, record, true);
3039	}else{/* for App Obj */
3040		if(APPPATROL_SUPPORT){
3041			return str[0] + ':' + str[1];
3042		}
3043    	if (tips != "")
3044    		return str[0] + ':<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
3045    				'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ str[1] + '</a>';
3046    	else
3047    		return data;        
3048	}
3049	
3050}
3051
3052/* mouse over service object / group */
3053function mouseOverSrv(data, metaData, record) {
3054	var tips = '', _tips = '';
3055	var found = false;
3056	showService.each(function(rec) {
3057		if (rec.get('_Object_name') == data) {
3058			found = true;
3059			if(rec.get('_Protocol') == 'TCP' || rec.get('_Protocol') == 'UDP' || rec.get('_Protocol') == 'ICMP'){
3060				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Protocol:</b> {1}<br><b>Starting Port:</b> {2}<br><b>Ending Port:</b> {3}';
3061				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Protocol'), rec.get('_Minmum_port'), rec.get('_Maxmum_port'));
3062			}else{
3063				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Protocol Number:</b> {1}';
3064				tips = Ext.String.format(_tips, rec.get('_Object_name'), rec.get('_Protocol'));
3065			}
3066			return false;
3067		}
3068	});
3069	if (!found) {
3070		var d;
3071		showServiceGrpMems.each(function(rec) {
3072			if (rec.get('_Group_name') == data) {
3073				d = rec.get('_Members').split(',');
3074				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Description:</b><br>{1}<br><b>Members:</b><br>';
3075				tips = Ext.String.format(_tips, rec.get('_Group_name'), doubleQuateConvert(rec.get('_Description')));
3076				for (var i = 0; i < d.length; i++) {
3077					if( i == d.length ){
3078						tips += d[i];
3079					}else{
3080						tips += d[i] + '<br>';
3081					}
3082				}
3083				return false;
3084			}
3085		});
3086	}
3087	if (tips != "")
3088		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
3089				'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ data + '</a>';
3090	else
3091		return data;
3092}
3093
3094/* mouse over service object / group */
3095function mouseOverSch(data, metaData, record) {
3096	var tips = '', found = false;
3097	var _tips = '<font size=2><b>{0}</b></font><hr noshade align=left>';
3098	var tips_header = '';
3099	var tip_once = 'Start Day/Time {0}-{1}-{2} {3}:{4}<br>Stop Day/Time {5}-{6}-{7} {8}:{9}';
3100	var tip_recur = 'Start Time {0}:{1}<br>Stop Time {2}:{3}';
3101	showSchedule.each(function(rec) {
3102		if (rec.get('_Object_name') == data) {
3103			found = true;
3104			var se = rec.get('_Start_End');
3105			tips_header = Ext.String.format(_tips, rec.get('_Object_name'));
3106			if (rec.get('_Type') == 'Once')
3107				tips = tips_header + String(tip_once).replace(/\{(\d+)\}/g, function(m,i) {return se[i];});
3108			else
3109				tips = tips_header + String(tip_recur).replace(/\{(\d+)\}/g, function(m,i) {return se[i];});
3110			return false;
3111		}
3112	});
3113	if (!found) {
3114		var d;
3115		showScheduleGrpMems.each(function(rec) {
3116			if (rec.get('_Group_name') == data) {
3117				d = rec.get('_Members').split(',');
3118				_tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>Description:</b><br>{1}<br><b>Members:</b><br>';
3119				tips = Ext.String.format(_tips, rec.get('_Group_name'), doubleQuateConvert(rec.get('_Description')));
3120				for (var i = 0; i < d.length; i++) {
3121					if( i == d.length ){
3122						tips += d[i];
3123					}else{
3124						tips += d[i] + '<br>';
3125					}
3126				}
3127				return false;
3128			}
3129		});
3130	}
3131	if (tips != "")
3132		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
3133				'<img src="/ext-js/images/usg/others/i_tooltip.gif">'+ data + '</a>';
3134	else
3135		return data;
3136}
3137
3138/* mouse over interface */
3139function mouseOverIface(data, metaData, record) {
3140	var tips = '';
3141	var _tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Assignment:</b> {1}<br><b>IP Address:</b> {2}<br><b>Mask:</b> {3}<br><b>Status:</b> {4}';
3142
3143    showIfaceSumALL.each(function(rec) {
3144		if (rec.get('_Name') == data) {
3145			tips = Ext.String.format(_tips, rec.get('_Name'), rec.get('_IP_Assignment'), rec.get('_IP_Address'), rec.get('_Mask'), rec.get('_Status'));
3146			return false;
3147		}
3148	});
3149	if (tips != "")
3150		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
3151				'<img src="/ext-js/images/usg/others/i_tooltip.gif">' + data + '</a>';
3152	else
3153		return data;
3154}
3155function mouseOverIface6(data, metaData, record) {
3156	var tips = '';
3157	var _tips = '<font size=2><b>{0}</b></font><hr noshade align=left><b>IP Address:</b><br> {1}<br><b>Status:</b> {2}';
3158	var v6if_record, isTunnel = false;
3159	var isVti= false;
3160	var v6ifs_store_data_addr;
3161	var v6ifs_store_data_st;
3162	//var v6ifs_store_data_srv;
3163	v6if_record = undefined;
3164	showIpv6IfaceAllEth.each(function(rec) {
3165		if( rec.get('_interface_name') == data ) {
3166			v6if_record = rec;
3167			return false;
3168		}
3169	});
3170	if( typeof(v6if_record) == "undefined" )
3171	showIpv6IfaceAllPPP.each(function(rec) {
3172		if( rec.get('_interface_name') == data ) {
3173			v6if_record = rec;
3174			return false;
3175		}
3176	});
3177	if( typeof(v6if_record) == "undefined" )
3178	showIpv6IfaceAllVlan.each(function(rec) {
3179		if( rec.get('_interface_name') == data ) {
3180			v6if_record = rec;
3181			return false;
3182		}
3183	});
3184	if( typeof(v6if_record) == "undefined" )
3185	showIpv6IfaceAllBridge.each(function(rec) {
3186		if( rec.get('_interface_name') == data ) {
3187			v6if_record = rec;
3188			return false;
3189		}
3190	});
3191	if( typeof(v6if_record) == "undefined" )
3192	showIfaceTunnel.each(function(rec) {
3193		if( rec.get('_interface_name') == data ) {
3194			isTunnel = true;
3195			v6if_record = rec;
3196			v6ifs_store_data_st = rec.get('_status');
3197			return false;
3198		}
3199	});
3200	if( typeof(v6if_record) == "undefined" )
3201		showIfaceVti.each(function(rec) {
3202			if( rec.get('_interface_name') == data ) {
3203				isVti = true;
3204				v6if_record = rec;
3205				return false;
3206			}
3207		});
3208		/* Summarized the store data */
3209	if( typeof(v6if_record) != "undefined" ) {
3210		if(isTunnel)
3211			var cnt = v6if_record.get('_ipv6_address_count');
3212		else if(isVti)
3213			var cnt = 0;
3214		else
3215			var cnt = v6if_record.get('_address_count');
3216
3217		/* address list */
3218		v6ifs_store_data_addr = "";
3219		if( cnt != 0 ) {
3220			for( i = 1 ; i <= cnt ; ++i ) {
3221				if(isTunnel)
3222					v6ifs_store_data_addr += v6if_record.get('_ipv6_address'+i);
3223				else
3224				v6ifs_store_data_addr += v6if_record.get('_address'+i);
3225				if( i != cnt ) {
3226					v6ifs_store_data_addr += '<\/br>';
3227				}
3228			}
3229		} else {
3230			v6ifs_store_data_addr = '::';
3231		}
3232		if(!isTunnel){
3233		/* link status */	
3234		showIfaceSumALL.each(function(rec) {
3235			if (rec.get('_Name') == data) {
3236				v6ifs_store_data_st = rec.get('_Status');
3237				return false;
3238			}
3239		});
3240		//v6ifs_store_data_st = r.get('_Status');
3241		if (!/^(Inactive|Down|Disconnected)$/.test(v6ifs_store_data_st)) {
3242			/* If Up case */
3243			if( v6if_record.get('_enable_ipv6') == "no" ) {
3244				v6ifs_store_data_st = "Inactive";
3245			} else {
3246				if( v6ifs_store_data_st == 'Connected' ) {
3247					/* pppv6 */
3248					if( v6if_record.get('_connected') == "no" ) {
3249						v6ifs_store_data_st = "Disconnected";
3250					}
3251				}
3252			}
3253		} 
3254		}
3255		tips = Ext.String.format(_tips, data, v6ifs_store_data_addr, v6ifs_store_data_st);
3256	}
3257	if (tips != "")
3258		return '<a href="#" class="grid-tip"  data-qtip="' + tips + '">'+
3259				'<img src="/ext-js/images/usg/others/i_tooltip.gif">' + data + '</a>';
3260	else
3261		return data;
3262}
3263var initFun = false;
3264/* private function */
3265/* ZLDCONFIG_IPV6 */
3266function init_dynamic_fields() {
3267	/* ZLDCONFIG_IPV6 */
3268	var ZLDCONFIG_IPV6_ENABLE = IPV6_SUPPORT;
3269
3270	/* Init ipv6 CLIs - dynamic address field */
3271	if( ZLDCONFIG_IPV6_ENABLE ) {
3272		var i,maxcnt;
3273		/* show ipv6 interface xxx */
3274		maxcnt = 16;
3275		for( i = 1 ; i <= maxcnt ; ++i ) {
3276			showCLI['showIpv6IfaceAllEth'][0].fields.push('_address'+i);
3277			showCLI['showIpv6IfaceAllPPP'][0].fields.push('_address'+i);
3278			showCLI['showIpv6IfaceAllVlan'][0].fields.push('_address'+i);
3279			showCLI['showIpv6IfaceAllBridge'][0].fields.push('_address'+i);
3280			showCLI['showIpv6IfaceAllBridge'][0].fields.push('_address'+i);
3281			showCLI['showIpv6IfaceName'][0].fields.push('_address'+i);
3282		}
3283		/* show ipv6 nd ra status xxx */
3284		maxcnt =  ZLDCONFIG_MAX_IPVVI_RA_OPTIONS_PREFIX;
3285		for( i = 1 ; i <= maxcnt ; ++i ) {
3286			showCLI['showIpv6NdRaStatusName'][0].fields.push('_prefix_option'+i+'_prefix');
3287			showCLI['showIpv6NdRaStatusName'][0].fields.push('_prefix_option'+i+'_lifetime');
3288		}
3289		/* ==show ipv6 nd ra status*/
3290		maxcnt =  ZLDSYSPARM_MAX_DHCP6_PD_ADDRESS_NUM;
3291		for( i = 1 ; i <= maxcnt ; ++i ) {
3292			showCLI['showIpv6StaticAddressIfaceName'][0].fields.push('_dhcp6_address_object'+i);
3293			showCLI['showIpv6StaticAddressIfaceName'][0].fields.push('_dhcp6_suffix'+i);
3294			showCLI['showIpv6StaticAddressIfaceName'][0].fields.push('_dhcp6_address'+i);
3295		}
3296		
3297		maxcnt =  ZLDSYSPARM_MAX_DHCP6_PD_RA_NUM;
3298		for( i = 1 ; i <= maxcnt ; ++i ) {
3299			showCLI['showIpv6NdRaStatusName'][0].fields.push('_prefix_delegation_option'+i+'_object');
3300			showCLI['showIpv6NdRaStatusName'][0].fields.push('_prefix_delegation_option'+i+'_suffix');
3301			showCLI['showIpv6NdRaStatusName'][0].fields.push('_prefix_delegation_option'+i+'_address');
3302		}
3303		
3304		/* ==show ipv6 nd ra status*/	
3305		/* show ipv6 static address interface xxx */
3306		maxcnt =  ZLDCONFIG_MAX_STATIC_IPVVI_ADDRESS;
3307		for( i = 1 ; i <= maxcnt ; ++i ) {
3308			showCLI['showIpv6StaticAddressIfaceName'][0].fields.push('_address'+i);
3309			showCLI['showIpv6StaticAddressIfaceName'][0].fields.push('_gateway_list'+i);
3310			showCLI['showIpv6StaticAddressIfaceName'][0].fields.push('_metric_list'+i);
3311		}
3312	}
3313
3314}
3315/* ZLDCONFIG_IPV6 */
3316function beforeInit(id){
3317	if(initFun) return;
3318	initFun = true;
3319/* ZLDCONFIG_IPV6 */
3320	init_dynamic_fields();
3321/* ZLDCONFIG_IPV6 */
3322
3323	/* debug log */
3324	var rightcnt = 0;
3325	Ext.fly(id).on({
3326		'contextmenu': function() {
3327			rightcnt++;
3328			if(rightcnt == 2){
3329				debugLog = true;
3330				cliLog = true;
3331				Ext.zylog('### Debug Log = '+debugLog);
3332				Ext.zylog('### CLI Log = '+cliLog);
3333				rightcnt=0;
3334			}
3335		},
3336		scope:this,
3337		preventDefault:true
3338	});
3339	/*  Logout  Window  Beginning  */
3340	Ext.fly('logout').on('click', function(){
3341		/*Ext.Msg.confirm(
3342			mlang['_Device_Log_Out'], 
3343			mlang['_Sure_Logout_Message'], gotoLogin);*/
3344			
3345		Ext.MessageBox.show({
3346			title: mlang['_Device_Log_Out'], 
3347			msg: mlang['_Sure_Logout_Message'],
3348			buttonText: {
3349				yes: mlang['_Yes'],
3350				no: mlang['_No']
3351			},
3352			icon: Ext.Msg.QUESTION,
3353			fn: function(btn){
3354				if(btn == 'yes'){
3355					if(readParseCookie('regCookie') != null){
3356						cp.clearCookie('regCookie');
3357					}
3358					Ext.Ajax.request({
3359						url: '/setuser.cgi?perform=logout',
3360						method: 'GET',
3361						success: function(response,options){
3362							keepMe = true;
3363							top.location.href='/';
3364						},
3365						failure: function(response,options){
3366							//Ext.Msg.alert('Error Message',response.responseText);
3367						}
3368					});
3369				}
3370			}
3371		});
3372	});
3373
3374	/*  Help  Window  Beginning  */
3375	Ext.fly('help-btn').on('click', function(){
3376		if(!_clicked) return;
3377		chkClick();
3378		openOnLineHelp(Context, Topic);
3379	});
3380	/*  Notification  Menu  Beginning  */
3381	Ext.fly('notification-btn').on('click', function(){
3382		if(!_clicked) return;
3383		chkClick();
3384        notification_menu.showNtMenu();    
3385	});	 
3386	/*  About  Window  Beginning  */
3387	Ext.fly('about-btn').on('click', function(){
3388		if(!_clicked) return;
3389		chkClick();
3390		var win = callPage('zldapp.view.index.about');
3391		win.putData2Store(win);
3392	});	
3393	/*  Site Map  Window  Beginning  */
3394	Ext.fly('map-btn').on('click', function(){
3395		if(!_clicked) return;
3396		chkClick();
3397		callPage('zldapp.view.index.sitemap');
3398	});
3399	/*  Forum  Beginning  */
3400	Ext.fly('forum-btn').on('click', function(){
3401		if(!_clicked) return;
3402		chkClick();
3403		window.open('https://community.zyxel.com/categories/security');
3404	});
3405	/*  Console  Window  Beginning  */
3406	Ext.fly('console-btn').on('click', function(){
3407		if(!_clicked) return;
3408		if (top.location.protocol == 'http:') return;
3409		chkClick();
3410		window.open('/webconsole/');
3411	});
3412	/*  CLI  Window  Beginning  */
3413	Ext.fly('cli-btn').on('click', function(){
3414		if(!_clicked) return;
3415		chkClick();
3416		debugLog = false;
3417		cliLog = true;
3418		Ext.zylog('### CLI start ');
3419	});
3420	/*  object reference  Window  Beginning  */
3421	Ext.fly('objref-btn').on('click', function(){
3422		if(!_clicked) return;
3423        if(Ext.getCmp('objectRefAll') == undefined){
3424            chkClick();
3425			var btnClick = {type:'objrefall', 'winPath': 'zldapp.view.pagestore.objrefall','caller':'objrefallform'};
3426			callInlineObj(btnClick);
3427		}
3428	});
3429	Ext.fly('secureporter-btn').on('click', function(){
3430	if(!_clicked) return;
3431
3432	chkClick();
3433    getSecuRepoterUrl();   
3434    
3435  });
3436	Ext.fly('content-panel').on('click', function(){
3437		Ext.each(selectedGridIds, function(rec){
3438			if (Ext.getCmp(rec) != undefined)
3439				Ext.getCmp(rec).getSelectionModel().deselectAll();
3440		})
3441		selectedGridIds = [];
3442	});
3443}
3444function chkClick(){
3445	_clicked = false;
3446	setTimeout('_clicked = true;', 500);
3447}
3448function getSecuRepoterUrl(){
3449	var url = getSecuReporterLoginURL(secureporter_inspect_site);
3450    var MAC = showMac.getAt(0).get('_MAC_address')[0], SN = showSN.getAt(0).get('_serial_number');
3451    var form = document.createElement("form");
3452    form.setAttribute("method", "post");
3453    form.setAttribute("action", url);
3454
3455    form.setAttribute("target", "SecuReporter");
3456
3457    var h1 = document.createElement("input"); 
3458    h1.setAttribute("type", "hidden");
3459    h1.setAttribute("name", "mac_address");
3460    h1.setAttribute("value", MAC);
3461    
3462    var h2 = document.createElement("input"); 
3463    h2.setAttribute("type", "hidden");
3464    h2.setAttribute("name", "serial_no");
3465    h2.setAttribute("value", SN);    
3466    
3467    form.appendChild(h1);
3468    form.appendChild(h2);    
3469    document.body.appendChild(form);
3470
3471    window.open('', 'SecuReporter');
3472
3473    form.submit();
3474}
3475function getSecuReporterActionableURL(type){
3476	if (type == "official"){
3477		return 'https://secureporter.cloudcnm.zyxel.com/device/actionable/configure';
3478	}else if (type == "alpha"){
3479		return 'https://alpha.secureporter.cloudcnm.zyxel.com/device/actionable/configure';
3480	}else{
3481		return 'https://beta.secureporter.cloudcnm.zyxel.com/device/actionable/configure';
3482	} 
3483}
3484function getSecuRepoterActionableUrl(feature){
3485	var url = getSecuReporterActionableURL(secureporter_inspect_site);
3486    var MAC = showMac.getAt(0).get('_MAC_address')[0], SN = showSN.getAt(0).get('_serial_number');
3487    var form = document.createElement("form");
3488    form.setAttribute("method", "post");
3489    form.setAttribute("action", url);
3490
3491    form.setAttribute("target", "SecuReporter");
3492
3493    var h1 = document.createElement("input"); 
3494    h1.setAttribute("type", "hidden");
3495    h1.setAttribute("name", "mac_address");
3496    h1.setAttribute("value", MAC);
3497    
3498    var h2 = document.createElement("input"); 
3499    h2.setAttribute("type", "hidden");
3500    h2.setAttribute("name", "serial_number");
3501    h2.setAttribute("value", SN);
3502
3503	var h3 = document.createElement("input"); 
3504    h3.setAttribute("type", "hidden");
3505    h3.setAttribute("name", "feature");
3506    h3.setAttribute("value", feature); 
3507    
3508    form.appendChild(h1);
3509    form.appendChild(h2); 
3510	form.appendChild(h3);	
3511    document.body.appendChild(form);
3512
3513    window.open('', 'SecuReporter');
3514
3515    form.submit();
3516}
3517/* dashboard pop window */
3518var wins;
3519function subWin(file_name, win_name, wide, high) {
3520	if (win_name == "") win_name = file_name;
3521	if (wide == "") wide = 700;
3522	if (high == "") high = 340;
3523	wins = window.open(file_name + '.html', win_name,'width=' + wide + ', height=' + high + ', status=no, scrollbars=yes, resizable=yes, toolbar=no');
3524}
3525
3526/* call edit/add object */
3527function callMainPage(treeNodeId, tabId){
3528	var treepanel = Ext.ComponentQuery.query('treepanel')[0];					
3529	var node = treepanel.getStore().getNodeById(treeNodeId);
3530	treepanel.selectPath(node.getPath());
3531	tabs = node.raw.tabs;
3532
3533	for (i = 0; i < tabs.length; i++) {
3534	    tab = tabs[i];
3535	    if (tab.id == tabId) {
3536	        break;
3537	    }
3538	}
3539
3540	eOpts = {
3541		params : {
3542              	tabIdx: i
3543              }
3544	}
3545	var activeWin = Ext.WindowMgr.getActive();
3546	if (activeWin != undefined){
3547		/* the exception of object reference and debug window, Jerry san */
3548		if(activeWin.getId() != 'debug_cli' && activeWin.getId() != 'objectRefAll')
3549			activeWin.close();
3550	}
3551	treepanel.fireEvent('itemclick', treepanel.getSelectionModel(), node, i, eOpts);
3552}
3553
3554function CIDR_Netmask_Transfer(str, category){
3555	switch(category) {
3556		case 'netmask' ://for example: transfer 255.255.255.0 to 24
3557			var num = "";
3558			var bitNum = 0;
3559			var temp = str.split('.');
3560			for(var i = 0; i < temp.length; i++) {
3561				num += parseInt(temp[i]).toString(2);
3562			}
3563			for(var j = 0; j < num.length; j++) {
3564				if(num.charAt(j) != 0) { // just count "1"
3565					bitNum++;
3566				}
3567			}
3568			str = bitNum;
3569		break;
3570		case 'cidr' ://for example: transfer 24 to 255.255.255.0
3571			var bitNum = "";
3572			for(var j = 0; j < str; j++) {
3573				bitNum += "1";
3574			}
3575			while(bitNum.length != 32) {
3576				bitNum += "0";
3577			}
3578			var subBit = "";
3579			var subip = 0;
3580			var start = 0;
3581			while(start < 32) {
3582				for(var j = start; j < start+8; j++) {
3583					subip += parseInt(bitNum.charAt(j)) * (1 << ((7+start) - j));
3584				}
3585				if((32 - start) > 8) {
3586					subBit += (subip+".");
3587				}else {
3588					subBit += subip;
3589				}
3590				start+=8;
3591				subip = 0;
3592			}
3593			str = subBit;
3594		break;
3595	}
3596	return str;
3597}
3598
3599/* disable amount of components
3600 * Usage: setDisable(['id1', 'id2', 'id3', ...], this.checked (or true/false))
3601 */
3602function setDisable(ary, flag) {
3603	Ext.each(ary, function(id) {
3604		var obj = Ext.getCmp(id);
3605		obj.setDisabled(flag);
3606		
3607		if(obj.getSuffixLabel!=undefined){
3608			var my_suffix = obj.getSuffixLabel();
3609			if (my_suffix.length != 0)
3610			{
3611				if(obj.updateSuffixColor!=undefined)
3612					obj.updateSuffixColor(Ext.getCmp(id).suffix);
3613			}
3614		}
3615	});
3616}
3617
3618/* show amount of components
3619 * Usage: setShow(['id1', 'id2', 'id3', ...])
3620 */
3621function setShow(ary) {
3622	Ext.each(ary, function(id) {
3623		Ext.getCmp(id).show();
3624	});
3625}
3626
3627/* hide amount of components
3628 * Usage: setHide(['id1', 'id2', 'id3', ...])
3629 */
3630function setHide(ary) {
3631	Ext.each(ary, function(id) {
3632		Ext.getCmp(id).hide();
3633	});
3634}
3635/* validate amount of components
3636 * Usage: setValidate(['id1', 'id2', 'id3', ...])
3637 */
3638function setValidate(ary) {
3639	Ext.each(ary, function(id) {
3640		Ext.getCmp(id).validate();
3641	});
3642}
3643/* set value amount of components
3644 * Usage: setValues([{id:'id1', val:'val1'}, {id:'id2', val:'val2'}, {id:'id3',val:'val3'}, ...])
3645 */
3646function setValues(ary) {
3647	Ext.each(ary, function(item) {
3648		Ext.getCmp(item.id).setValue(item.val);
3649	});
3650}
3651function setFieldStyle(ary) {
3652	Ext.each(ary, function(item) {
3653		Ext.getCmp(item.id).setFieldStyle(item.style);
3654	});
3655}
3656/* disable and validate amount of components and subcomponents, 
3657 * * Usage: setDisableValidate(['id1', 'id2', 'id3', ...], this.checked (or true/false))
3658 */
3659function setDisableValidate(ary, flag){
3660	Ext.each(ary, function(aryid) {
3661		var obj = Ext.getCmp(aryid);
3662		if(obj.items != "undefined" && obj.items != null){ 
3663			obj.items.each( function(subobj){
3664				setDisableValidate(subobj.id, flag);			
3665			});
3666		}else{ //only have no subcomponents do
3667			obj.setDisabled(flag);
3668			
3669			if(obj.getSuffixLabel!=undefined){
3670				var my_suffix = obj.getSuffixLabel();
3671				if (my_suffix.length != 0)
3672				{
3673					if(obj.updateSuffixColor!=undefined)
3674						obj.updateSuffixColor(Ext.getCmp(obj.id).suffix); 
3675				}
3676			}
3677		
3678			if(obj.validate != "undefined" && obj.validate != null)
3679				obj.validate();
3680		}
3681	});
3682}
3683/* Management IP should be in the same subnet with interface.*/
3684function chkIPSubnet( TargetAddr, SourceAddr, SourceMask ){
3685	var addr1Split = TargetAddr.split(".");
3686	var addr2Split = SourceAddr.split(".");
3687	var maskSplit = SourceMask.split(".");
3688	var tmp1 = 0;
3689	var tmp2 = 0;
3690	var tmp3 = 0;
3691
3692	for( var i = 3 ; i >= 0 ; i-- ){
3693		tmp1 = parseInt(addr1Split[i], 10 );
3694		tmp2 = parseInt(addr2Split[i], 10 );
3695		tmp3 = parseInt(maskSplit[i], 10 );
3696		if( (tmp1 & tmp3) != (tmp2 & tmp3 ) ){
3697			return false ;
3698		}
3699	}
3700	return true;
3701}
3702
3703/* call edit/add object without close window in screen*/
3704function callPageWithoutCloseWin(treeNodeId, tabId,treemode){
3705	//var treepanel = Ext.ComponentQuery.query('treepanel')[0];					
3706	//var node = treepanel.getStore().getNodeById(treeNodeId);
3707	var splitter = Ext.ComponentQuery.query('splitter')[0];
3708	setSplitterVisible(splitter);
3709	var moduleName;
3710	var title;
3711	switch(treemode){
3712		case "configPanel":
3713			moduleName = "config";
3714			title = mlang['_Configuration'];
3715		break;
3716		case "maintenPanel":
3717			moduleName = "maintenance";
3718			title = mlang['_Maintenance'];			
3719		break;
3720		case "monitorPanel":
3721			moduleName = "monitor";
3722			title = mlang['_Monitor'];
3723		break;
3724	}		
3725	var treepath = "treepanel."+treemode;
3726	var store = Ext.data.StoreManager.lookup(treepath);
3727		
3728	store.load({
3729		scope : store,
3730		callback : function(records, operation, success) {
3731			var treepanel = Ext.getCmp('tree-panel');
3732			treepanel.reconfigure(store);		
3733			setPanel(moduleName);
3734			treepanel.setTitle(title);
3735			var node = store.getNodeById(treeNodeId);
3736			treepanel.selectPath(node.getPath());
3737			tabs = node.raw.tabs;
3738
3739			for (i = 0; i < tabs.length; i++) {
3740				tab = tabs[i];
3741				if (tab.id == tabId) {
3742					break;
3743				}
3744			}
3745			eOpts = {
3746				params : {
3747						tabIdx: i
3748					  }
3749			}
3750			treepanel.fireEvent('itemclick', treepanel.getSelectionModel(), node, i, eOpts);
3751		}
3752	});			
3753}
3754
3755function isIP(address){
3756	var ipRe = /^((([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))\.){3}(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))$/;
3757	return ipRe.test(address);
3758}
3759
3760//Return 1:v4, 2:v6, 0: not ipv4 and ipv6
3761function isIP_v4_or_v6(address){
3762	var ipv4 = address;
3763	var ipRe = /^((([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))\.){3}(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))$/;
3764	if(ipRe.test(ipv4)) {
3765		return 1;
3766	} else if(test_ipv6(address)){
3767		return 2;
3768	}
3769	return 0;
3770}
3771
3772/* render tooltip in grid cell */
3773function renderCellTip(data, metadata, record, rowIndex, columnIndex, store){
3774	metadata.tdAttr = ' data-qtip="' + data + '"';
3775	return data;
3776}
3777function renderSrcGeoCellTip(data, metadata, record, rowIndex, columnIndex, store){
3778    if ((record.get('_Source_CountryCode') != 'N/A') && (record.get('_Source_CountryCode') != '')) {
3779        var countryFlag = '<img src=/ext-js/images/usg/others/country-flags/' + record.get('_Source_CountryCode') + '.png />'
3780        metadata.tdAttr = ' data-qtip="' + record.get('_Source_Country') + ', ' + data + '"';
3781        return countryFlag + ' ' + data;
3782    }
3783    else {
3784        metadata.tdAttr = ' data-qtip="' + data + '"';
3785        return data;
3786    }
3787}
3788
3789function renderDstGeoCellTip(data, metadata, record, rowIndex, columnIndex, store){
3790    if ((record.get('_Destination_CountryCode') != 'N/A') && (record.get('_Destination_CountryCode') != '')) {
3791        var countryFlag = '<img src=/ext-js/images/usg/others/country-flags/' + record.get('_Destination_CountryCode') + '.png />'
3792        metadata.tdAttr = ' data-qtip="' + record.get('_Destination_Country') + ', ' + data + '"';
3793        return countryFlag + ' ' + data;
3794    }
3795    else {
3796        metadata.tdAttr = ' data-qtip="' + data + '"';
3797        return data;
3798    }
3799}
3800
3801/* use for file upload */
3802function dumpFailureMsg(action, form) {
3803	if (form && typeof form.clearInvalid != 'undefined') form.clearInvalid();// clear validate of (Firefox) browser, Jerry san
3804	switch (action.failureType) {
3805		case Ext.form.Action.CLIENT_INVALID:
3806			Ext.Msg.alert("Failure", "Form fields may not be submitted with invalid values");
3807			break;
3808		case Ext.form.Action.CONNECT_FAILURE:
3809			Ext.Msg.alert("Failure", "Ajax communication failed");
3810			break;
3811		case Ext.form.Action.SERVER_INVALID:
3812			Ext.Msg.alert('Error Message', 'errno: '+ action.result.errno0+'<br>errmsg: '+action.result.errmsg0);
3813			break;
3814	}
3815}
3816/* Create default Record */
3817var createRec = function(store, defFields){
3818
3819	tempStore = Ext.create('zldapp.store.common.cmdStore', {
3820		fields: store.model.getFields()
3821		
3822	});
3823	var rec = Ext.create(store.model.getName());
3824
3825	rec.fields.each(function(field, idx) {
3826		rec.data[field.name] = defFields[field.name];
3827	});
3828	
3829	tempStore.add(rec);
3830	
3831	return {store: tempStore, rec: rec};
3832	
3833}
3834
3835var dumpMsgIfLimitedAdmin = function() {
3836	if (!isAdmin) {
3837		Ext.MessageBox.show({
3838			title: 'Warning',
3839			msg: "This action is not allowed due to insufficient privilege of current limited-admin login account.",
3840			buttons: Ext.MessageBox.OK,
3841			icon: Ext.MessageBox.WARNING
3842		});
3843	}
3844	return !isAdmin;
3845}
3846/* ZLDCONFIG_IPV6 */
3847/**********************************************************/
3848/* From : http://ipv6blog.net/ipv6-validation-javascript/ */
3849/**********************************************************/
3850function substr_count (haystack, needle, offset, length)
3851{
3852    var pos = 0, cnt = 0;
3853
3854    haystack += '';
3855    needle += '';
3856    if (isNaN(offset)) {offset = 0;}
3857    if (isNaN(length)) {length = 0;}
3858    offset--;
3859
3860    while ((offset = haystack.indexOf(needle, offset+1)) != -1){
3861        if (length > 0 && (offset+needle.length) > length){
3862            return false;
3863        } else{
3864            cnt++;
3865        }
3866    }
3867
3868    return cnt;
3869}
3870
3871function test_ipv4(ip)
3872{
3873   var match = ip.match(/(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|255[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/);
3874   return match != null;
3875}
3876
3877function test_ipv6(ip)
3878{
3879  // Test for empty address
3880  if (ip.length<3)
3881  {
3882    return ip == "::";
3883  }
3884  // Check if part is in IPv4 format
3885  if (ip.indexOf('.')>0)
3886  {
3887        lastcolon = ip.lastIndexOf(':');
3888
3889        if (!(lastcolon && test_ipv4(ip.substr(lastcolon + 1))))
3890            return false;
3891
3892        // replace IPv4 part with dummy
3893        ip = ip.substr(0, lastcolon) + ':0:0';
3894  }
3895
3896  // Check uncompressed
3897  if (ip.indexOf('::')<0)
3898  {
3899    var match = ip.match(/^(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}$/i);
3900    return match != null;
3901  }
3902  // Check colon-count for compressed format
3903  if (substr_count(ip, ':') < 8)
3904  {
3905    var match = ip.match(/^(?::|(?:[a-f0-9]{1,4}:)+):(?:(?:[a-f0-9]{1,4}:)*[a-f0-9]{1,4})?$/i);
3906    return match != null;
3907  }
3908  // Not a valid IPv6 address
3909  return false;
3910}
3911function check_ipv6_with_Prefix(ip6_addr, prefixLength)
3912{
3913	var ip6_addr_apply_prfix = "";
3914	var ip6_addr_apply_org = "";
3915	
3916	/* check IPv6 format */
3917	if (!test_ipv6(ip6_addr))
3918	{
3919	  return false;
3920	}
3921	/* reserve org addr for complete format */
3922	ip6_addr_apply_org = get_ipv6_address_apply_prefix(ip6_addr, 128);
3923	ip6_addr_apply_prfix = get_ipv6_address_apply_prefix(ip6_addr, prefixLength);
3924	
3925	if(ip6_addr_apply_org != ip6_addr_apply_prfix) {
3926		return false;
3927	}
3928	return true;
3929}
3930/****************************************************************/
3931/* End - From : http://ipv6blog.net/ipv6-validation-javascript/ */
3932/****************************************************************/
3933function is_valid_ipv6_addr( addr ) {
3934	/* The addr should be checked with chkIPv6 | chkIPv6WithPfx */
3935	/* Can't be link-local/site-local/multicast */
3936    var match = addr.match(/^(f[a-f0-9][a-f0-9][a-f0-9])/);
3937    return match == null;
3938}
3939function get_complete_ipv6_addr(ip6_addr) {
3940	var ip4_addr,offset,cnt;
3941	var part_ipv6 ="",complete_ipv6="";
3942	// format check
3943	if( test_ipv6( ip6_addr ) != true ) {
3944		return "null";
3945	}
3946	// ::
3947	if (ip6_addr.length<3) {
3948		return "0000:0000:0000:0000:0000:0000:0000:0000";
3949	}
3950
3951	//translate the partial ipv4 to ipv6 i.e. 1.2.3.4 => 0102:0304
3952    // Check if part is in IPv4 format
3953	if (ip6_addr.indexOf('.')>0)
3954	{
3955		lastcolon = ip6_addr.lastIndexOf(':');
3956		ip4_addr = ip6_addr.substr(lastcolon+1);
3957		ipsp = ip4_addr.split('.');
3958		for(var i = 0 ; i < 4 ; ++i ) {
3959			var hex = Number(ipsp[i]).toString(16);
3960			if( hex.length < 2 ) {
3961				hex = "0" + hex;
3962			}
3963			part_ipv6+=hex;
3964			if( i == 1 ) {
3965				part_ipv6 += (":");
3966			}
3967		}
3968		ip6_addr = ip6_addr.substr(0, lastcolon+1) + part_ipv6;
3969	 }
3970
3971	//expand the compact portion , :: ==> 0000:0000:...
3972	offset = -1;
3973	cnt = 0;
3974	while((offset = ip6_addr.indexOf( ":" , offset+1)) != -1){
3975       	 	cnt++;
3976   	}
3977	if( cnt != 7 ) {
3978		cnt = (7 - cnt + 1);
3979		part_ipv6 ="";
3980		for( var i = 0 ; i < cnt-1 ; ++i ) {
3981			part_ipv6+="0000:";
3982		}
3983		part_ipv6+="0000";
3984		offset = ip6_addr.indexOf("::");
3985		complete_ipv6 = ip6_addr.substr( 0 , offset + 1 );
3986		complete_ipv6 += part_ipv6;
3987		if( ip6_addr.length != (offset+2) ) {
3988			// Not xxxxx:: case
3989			complete_ipv6 += ip6_addr.substr(offset+1);
3990		}
3991		ip6_addr = complete_ipv6;
3992	}
3993
3994	return ip6_addr;
3995}
3996
3997function get_ipv6_prefix_mask( prefix_len ) {
3998	var mask_ip=[],cnt,i,j;
3999	var ip6_addr,hex;
4000	if( prefix_len < 0 || prefix_len > 128 ) {
4001		return "null";
4002	}
4003	for( i = 0 ; i < 16 ; ++i ) {
4004		mask_ip[i] = 0;
4005	}
4006	for( i = prefix_len , cnt =0 ; i > 7 ; i-=8 , ++cnt ) {
4007		mask_ip[cnt] =0xff;
4008	}
4009	mask_ip[cnt]=( ( 0xff << ( 8 - i ) ) & 0x00ff );
4010
4011	ip6_addr = "";
4012	for( i = 0  ; i < 16 ; ++i ) {
4013		hex = Number(mask_ip[i]).toString(16);
4014		if( i != 0 && !(i&1) ) {
4015			ip6_addr += ":";
4016		}
4017		if( hex.length < 2 ) {
4018			hex = "0" + hex;
4019		}
4020		ip6_addr += hex;
4021	}
4022	return ip6_addr;
4023}
4024
4025function get_ipv6_address_apply_prefix ( ip6_addr , prefix_len ) {
4026	var cip6_addr = get_complete_ipv6_addr( ip6_addr );
4027	var maskip6_addr = get_ipv6_prefix_mask( prefix_len );
4028	var ipsp = cip6_addr.split(':');
4029	var mipsp = maskip6_addr.split(':');
4030	var i,val,ret_v6addr;
4031
4032	if( test_ipv6( ip6_addr ) != true ) {
4033		return "null";
4034	}
4035
4036	ret_v6addr = "";
4037	for( i = 0  ; i < 8 ; ++i ) {
4038		val = parseInt( "0x"+ipsp[i] ) & parseInt( "0x"+mipsp[i] );
4039		hex = Number( val ).toString(16);
4040		ret_v6addr+=hex;
4041		if( i != 7 ) {
4042		ret_v6addr+=":";
4043		}
4044	}
4045
4046	return ret_v6addr;
4047}
4048function getDHCPv6ObjBindIf( ifst){
4049		var dd = [], count = 0;
4050		ifst.each(function(r){
4051			ift=r.data['_interface_Type'];
4052			if(ift=='tunnel'||ift =='aux'){
4053				;/* don't add tunnel/aux interface type */
4054			}else{
4055				dd.push([count, r.data['_Name']]);
4056				count++;
4057			}
4058		});
4059		var ts = new Ext.data.SimpleStore({
4060			fields:['_ID', '_Name'],
4061			data: dd
4062		});
4063		return ts;
4064}
4065/* ZLDCONFIG_IPV6 */
4066/* switch IPv4/IPv6 view */
4067function filterIP(obj, show){
4068	obj.items.each(function(item) {
4069		var hide;
4070		if(show == IPv4_ATTR_FLAG)
4071			hide = IPv6_ATTR_FLAG;
4072		else if(show == IPv6_ATTR_FLAG)
4073			hide = IPv4_ATTR_FLAG;
4074
4075		if(show == Common_ATTR_FLAG){
4076			if(item.ipProType != Common_ATTR_FLAG){
4077				item.show();
4078			}
4079		}else{
4080			if(item.ipProType == show){
4081				item.show();
4082			}else if(item.ipProType == hide){
4083				item.hide();
4084			}
4085		}
4086		if (typeof item.items != 'undefined') {
4087			filterIP(item, show);
4088		}
4089	});
4090}
4091/* zyhyper page */
4092function getlinkToPage(linkid, treeRecModule, treeItemID, isLeaf, pagemodule , treeNodeId, tabId) {
4093	Ext.get(linkid).on('click', function(){		
4094		if (!(Ext.isEmpty(tabId))) 
4095			changeModule(pagemodule,treeNodeId, tabId);
4096		else
4097			changeModule(pagemodule);
4098	});
4099}
4100/* store copy by '_Name' field name, in-line object  */
4101var cpyStore = function(srcStore, TagId){
4102	var targetStore =  TagId.store  || (TagId.fromStore || TagId );
4103	srcStore.each(function(rec, idx){
4104		var find = false;
4105		targetStore.each(function(r, i){
4106			if (r.get('_Name') == rec.get('_Name')){
4107				find = true;
4108				return false;
4109			}
4110		});
4111		if(!find) targetStore.insert(idx, rec);
4112	});
4113	if(typeof TagId.view != 'undefined' ){
4114		TagId.view.setStore(targetStore);
4115	}
4116	if( TagId.xtype == 'zyitemselector'){
4117		targetStore.sort('_Tag', 'DESC');		
4118		TagId.fromField.bindStore(targetStore);
4119	}
4120}
4121
4122/* combine two stores as one store */
4123var combineStore = function(Store1, Store2, Store3){
4124	Store2.each(function(rec, idx){
4125		rec.data['_ID'] = Store1.getCount()+idx;
4126		Store3.insert(idx, rec);
4127	});
4128	Store1.each(function(rec, idx){
4129		Store3.insert(idx, rec);
4130	});
4131	
4132}
4133
4134/* format "X-name:value" */
4135function getXHeaderField(xheader, field) {
4136	if (xheader.length <= 2)
4137		return '';
4138	if (xheader.substring(0, 2) != 'X-')
4139		return '';
4140
4141	xheader = xheader.substring(2, xheader.length);
4142	fieldstr = xheader.split(':');
4143	if (field == 'name') {
4144		if (!Ext.isEmpty(fieldstr[0]))
4145			return fieldstr[0];
4146	} else if (field == 'value') {
4147		if (!Ext.isEmpty(fieldstr[1]))
4148			return fieldstr[1];
4149	}
4150
4151	return '';
4152}
4153
4154/* check current hybrid mode. (need ZLD_PRODUCT_LINE_ENTERPRISE_WLAN support) */
4155function isHybrid(mode){
4156		return true;
4157}
4158/* check white space */
4159function hasWhiteSpace(strg) {
4160	var whiteSpaceExp=/^[\s]+$/;
4161	if( whiteSpaceExp.test(strg)){
4162		Ext.MessageBox.show({
4163			msg: 'White space is not allowed.',
4164			buttons: Ext.MessageBox.OK,
4165			icon: Ext.MessageBox.ERROR
4166		});
4167		return true;
4168	}
4169	return false;
4170}
4171/* DHCP Pool Subnet Check(ethernet, vlan, bridge, wlan) */
4172function toMaskBin(dec, len) {
4173	var bits = "", rebits = "";
4174	var dividend = dec;
4175	var remainder = 0;
4176
4177	if (dividend==0) {
4178		return "0";
4179	}
4180	while (dividend > 0) {
4181		remainder = dividend % 2;
4182		bits+=remainder;
4183		dividend = (dividend - remainder) / 2;
4184	}
4185	for (var x = (len-1); x >=0; x--){
4186		rebits += bits.charAt(x);
4187	}
4188	return rebits;
4189}
4190function getOffset(CIDR, ipv4_addr) {
4191	var sp = ipv4_addr.split('.');
4192	var offRange = 0, ntoi = 0;
4193
4194	if(CIDR >= 24){ //Class D
4195		offRange = parseInt(toMaskBin(sp[3], 32-CIDR), 2);
4196	} else if (CIDR >= 16) { //class C
4197		offRange = parseInt(toMaskBin(sp[2], 24-CIDR), 2) * 256 + parseInt(toMaskBin(sp[3], 8), 2); 
4198	} else if (CIDR >= 8) { //class B
4199		offRange = parseInt(toMaskBin(sp[1], 16-CIDR), 2) * 256 * 256 +parseInt(toMaskBin(sp[2], 8), 2) * 256 + parseInt(toMaskBin(sp[3], 8), 2); 
4200	} else { //class A
4201		offRange = parseInt(toMaskBin(sp[0], 8-CIDR), 2) * 256 *256 *256 + parseInt(toMaskBin(sp[1], 8), 2) * 256 * 256 +parseInt(toMaskBin(sp[2], 8), 2) * 256 + parseInt(toMaskBin(sp[3], 8), 2); 
4202	}
4203	return (offRange + 1);	
4204}
4205function chkRangeOver(subnetmask){
4206	var CIDR = parseInt(CIDR_Netmask_Transfer(subnetmask, "netmask"));
4207	var endRange = Math.pow(2, 32 - CIDR) - 3;
4208	if(endRange > 65535) return true;
4209
4210	return false;
4211}		
4212function getEndRange(subnetmask, address){
4213	var CIDR = parseInt(CIDR_Netmask_Transfer(subnetmask, "netmask"));
4214	var endRange = Math.pow(2, 32 - CIDR) - getOffset(CIDR, address);
4215	if(endRange > 65535) {
4216		endRange = 65535; 
4217	}
4218	return endRange;
4219}
4220var applychkRange = function(value, min, max, msg){
4221	if((parseInt(value) < parseInt(min))||(parseInt(value) > parseInt(max))){
4222		Ext.Msg.alert('Error ', "The "+msg+" should be between "+ min+" and "+max);
4223		return false;
4224	}
4225	return true;
4226}
4227
4228/* Common functions for CF and please keep consistent with zysh CLI REs */
4229function __chkIPv4(val) {
4230	var result = /^((([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))\.){3}(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))$/;
4231	return result.test(val);
4232}
4233function __chkIPv4Range(val) {
4234	var result = /^((([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))\.){3}(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))-((([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))\.){3}(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))$/;
4235	return result.test(val);
4236}
4237function __chkIPv4CIDR(val) {
4238	var result = /^((([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))\.){3}(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))\/([1-9]|[1-2][0-9]|3[0-2])|0\.0\.0\.0\/0$/
4239	return result.test(val);
4240}
4241
4242var __chkVPNconnSelNotNone = function(val) {
4243        var l2tpenable = Ext.getCmp('_Enable_L2TP_Over_IPSec').checked;
4244        var indexCrypto= Ext.getCmp('_VPN_Connection').getValue();
4245        var stringCrypto = Ext.getCmp('_VPN_Connection').getRawValue();
4246        
4247        if (stringCrypto === 'none' && indexCrypto === 0) {
4248            if (l2tpenable) {
4249                return false;
4250            } 
4251        }
4252        return true;
4253}
4254
4255var __chkIpAddrPoolSelNotNone = function(val) {
4256        var l2tpenable = Ext.getCmp('_Enable_L2TP_Over_IPSec').checked;
4257        var indexPool = Ext.getCmp('addrPool').getValue();
4258        var stringPool = Ext.getCmp('addrPool').getRawValue();
4259        
4260        if (stringPool === 'none' && indexPool === 0) {
4261            if (l2tpenable) {
4262                return false;
4263            } 
4264        }
4265        return true;
4266}
4267
4268function __chkPrefixListGE(val) {
4269	var rec = Ext.getCmp('pfruleGrid').getSelectionModel().selected.first(), result = true;
4270
4271	var ge = parseInt(val);
4272	var le =  parseInt(rec.get('_Less_Equal'));
4273	var subnet = rec.get('_IP_Address')!= null? parseInt(rec.get('_IP_Address').split("/")[1]) : null;
4274
4275	if(subnet ==null || (subnet !=null && ge < subnet) || (le != null &&  ge > le))
4276		result = false;		
4277	
4278	return result;
4279}
4280
4281function __chkPrefixListLE(val) {
4282	var rec = Ext.getCmp('pfruleGrid').getSelectionModel().selected.first(), result = true;
4283
4284	var ge = parseInt(rec.get('_Greater_Equal'));
4285	var le =  parseInt(val);
4286	var subnet = rec.get('_IP_Address')!= null? parseInt(rec.get('_IP_Address').split("/")[1]) : null;
4287
4288	if(subnet ==null || (subnet !=null && subnet > le)  || (ge != null && ge > le))
4289		result = false;		
4290		
4291	return result;
4292}
4293
4294/* BEGIN_ZLDCONFIG_IPV6 */
4295function __chkIPv6Range(val) {
4296	var idx = val.indexOf("-");
4297	if (idx == -1) {
4298		return false;
4299	}
4300	if (test_ipv6(val.substring(0, idx)) && test_ipv6(val.substring(idx + 1))) {
4301		return true;
4302	}
4303	return false;
4304}
4305function __chkIPv6CIDR(val) {
4306	var result = /^([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$/;
4307	var lastslash = val.indexOf("/");
4308
4309	if (lastslash == -1) {
4310		return false;
4311	}
4312	else {
4313		/* Prefix validation */
4314		if (!result.test(val.substring(lastslash + 1))) {
4315			return false;
4316		}
4317		else {
4318			/* IPv6 validation */
4319			return test_ipv6(val.substring(0, lastslash));
4320		}
4321	}
4322}
4323function getGatewayIface(exceptType, isAny, isNone) { 
4324/*1. Each page should prepares stores: showIfaceProperty, showSnatExternal, showSnatInternal, showIfaceALL, showIfaceVti
4325  2. exceptType: An array for unnecessary interface type in this list
4326  3. isAny: If add a "Any" item at the beginning of the list
4327  4. isNone: If add a "None" item at the end of the list
4328  5. DropInLAN, DropInWAN: for UAG product using.*/
4329
4330		//isAny: add 'any' in the end of list, isNone: add 'none' in the beginning of list
4331		//var dd = [], externalIface = [], finalList = [], count = 0;		
4332		var rec, dd = [], externalIface = [], generalIface = [], internalIface = [], others = [], IfaceList = [], finalList = [];		
4333
4334		externalIface = showSnatExternal.getAt(0).data['_External_Interfaces'];
4335		
4336		//get general interface 		
4337		showIfaceProperty.each(function(r){
4338			if (/^(general)$/.test(r.get('_Property'))){
4339				generalIface.push(r.get('_System_Name'));
4340			}
4341		});
4342
4343		IfaceList = externalIface.concat(generalIface);
4344
4345		internalIface = showSnatInternal.getAt(0).data['_Internal_Interfaces'];		
4346
4347		IfaceList = IfaceList.concat(internalIface);
4348		
4349		//get other interface(s) (vti) 
4350		if(exceptType.indexOf('vti') == -1){
4351			showIfaceVti.each(function(r){
4352				others.push(r.data['_interface_name']);
4353			});
4354		}
4355
4356		IfaceList = IfaceList.concat(others);
4357
4358		//remove exception type interface
4359		var index = isNone?1:0;
4360		for (var i = 0; i < IfaceList.length; i++) {
4361			rec = showIfaceALL.findRecord('_Name',IfaceList[i]);
4362			if(rec != null){
4363				if(	exceptType.indexOf(rec.data['_Interface_Type']) != -1 
4364				){
4365					// don't add this interface type 
4366				}
4367				else{
4368					finalList.push([index , IfaceList[i]]);
4369					index++;
4370				}		
4371			}else{
4372				console.log("[Interface Menu]: Interface Type Not Found");
4373			}	
4374		}
4375
4376		//Add a item "None" at the beginning of list			
4377		if(isNone){
4378			finalList.splice( 0, 0, [0, 'none'] );		
4379		}
4380
4381		//Add a item "Any" at the end of list			
4382		if(isAny){
4383			finalList.push([finalList.length, 'any']);
4384		}		
4385
4386		var temp = new Ext.data.SimpleStore({
4387			fields:['_ID', '_Name'],
4388			data: finalList
4389		});
4390		
4391		return temp
4392	
4393}
4394
4395/* END_ZLDCONFIG_IPV6 */
4396function __chkSSLWildcardDomain(val) {
4397	var result = /^([0-9a-zA-Z`~!@#$%\^&*()\-_=+\[\]{}\\\|;:',\./? ]){1,127}$/;
4398	return result.test(val);
4399}
4400function __chkWildcardDomain(val) {
4401	var result = /^(([*a-z0-9\-]){1,63}\.)+([*a-z0-9\-]){1,63}$/;
4402	return result.test(val);
4403}
4404function __chkTLD(val) {
4405	var result = /^\.[a-z]{2,63}$/;
4406	return result.test(val);
4407}
4408function __chkCertEmail(val) {
4409	var result = /^[\.a-zA-Z0-9@_-]{1,63}$/;
4410	return result.test(val);
4411}
4412
4413function __chkEmail(val) {
4414	var result = /^[\w\-]+(\.[\w\-]+)*@(([\w\-])+\.)+[\w\-]+$/;
4415	return result.test(val);
4416}
4417
4418function __chkSSLWebSite(val) {
4419	if (__chkSSLWildcardDomain(val)) {
4420		return true;
4421	}
4422
4423	if (val.indexOf("/", 0) > 0) {
4424		return __chkIPv4CIDR(val);
4425	}
4426	else {
4427		if (val.indexOf("-", 0) != -1) {
4428			return __chkIPv4Range(val);
4429		}
4430		else {
4431			return __chkIPv4(val);
4432		}	
4433	}
4434}
4435/* BEGIN_ZLDCONFIG_SSL_INSPECTION_SUPPORT_IPV6 */
4436function __chkSSLWebSiteWithIPv6(val) {
4437	if (__chkSSLWebSite(val)) {
4438		return true;
4439	}
4440
4441	if (val.indexOf("/", 0) > 0) {
4442		return __chkIPv6CIDR(val);
4443	}
4444	else if (val.indexOf("-", 0) > 0) {
4445		return __chkIPv6Range(val);
4446	}
4447	else {
4448		return test_ipv6(val);
4449	}
4450}
4451/* END_ZLDCONFIG_SSL_INSPECTION_SUPPORT_IPV6 */
4452
4453function __chkWebSite(val) {
4454	var IPsplit = val.split(".");
4455	if (isNaN(IPsplit[IPsplit.length - 1])) {
4456		if (IPsplit[IPsplit.length - 1].indexOf("/", 0) == -1) {
4457			return __chkWildcardDomain(val) || __chkTLD(val);
4458		}
4459		else {
4460			return __chkIPv4CIDR(val);
4461		}
4462	}
4463	else {
4464		if (val.indexOf("-", 0) != -1) {
4465			return __chkIPv4Range(val);
4466		}
4467		else {
4468			return __chkIPv4(val);
4469		}	
4470	}
4471}
4472function __chkDNSDuplicate(val, dnsAry) {
4473    var valid = true;
4474    for(var idx=0; idx < dnsAry.length; idx++){
4475		if (Ext.getCmp(dnsAry[idx]).getValue() != '' &&  val == Ext.getCmp(dnsAry[idx]).getValue()){
4476			return false;
4477		}
4478	}
4479    return valid;
4480}
4481/* BEGIN_ZLD_CONFIG_CF_SUPPORT_IPV6 */
4482function __chkWebSiteWithIPv6(val) {
4483	if (val.indexOf(":", 0) == -1) {
4484		return __chkWebSite(val);
4485	}
4486	else {
4487		if (val.indexOf("/", 0) > 0) {
4488			return __chkIPv6CIDR(val);
4489		}
4490		else if (val.indexOf("-", 0) > 0) {
4491			return __chkIPv6Range(val);
4492		}
4493		else {
4494			return test_ipv6(val);
4495		}
4496	}
4497}
4498/* END_ZLD_CONFIG_CF_SUPPORT_IPV6 */
4499
4500/* Used by CF GUI */
4501var chkIPv4 = function (val, fieldname, str) {
4502	if (str == undefined) {
4503		if (val == '0.0.0.0') {
4504			Ext.MessageBox.alert('Error Message', val + ' is IP format error.');
4505			return false;
4506		}
4507	}
4508	if (fieldname == undefined) {
4509		fieldname = "";
4510	}
4511	if (!val) {
4512		Ext.MessageBox.alert('Error Message', fieldname + ' is empty.');
4513		return false;
4514	}
4515	else if (!__chkIPv4(val)) {
4516		Ext.MessageBox.alert('Error Message', val + ' is IP format error.');
4517		return false;
4518	}
4519	return true;
4520}
4521var chkIPv4Range = function(val, fieldname) {
4522	if (!val) {
4523		Ext.MessageBox.alert('Error Message', fieldname + ' is empty.');
4524		return false;
4525	}
4526	else if (!__chkIPv4Range(val)) {
4527		Ext.MessageBox.alert('Error Message', val + ' is range error.');
4528		return false;
4529	}
4530	return true;
4531}
4532var chkIPv4CIDR = function(val, fieldname) {
4533	if (!val) {
4534		Ext.MessageBox.alert('Error Message', fieldname + ' is empty.');
4535		return false;
4536	}
4537	else if (!__chkIPv4CIDR(val)) {
4538		Ext.MessageBox.alert('Error Message', val + ' is IP subnet in CIDR format error.');
4539		return false;
4540	}
4541	return true;
4542}
4543/* BEGIN_ZLDCONFIG_IPV6 */
4544var chkIPv6Range = function(val, fieldname) {
4545	if (!val) {
4546		Ext.MessageBox.alert('Error Message', fieldname + ' is empty.');
4547		return false;
4548	}
4549	else if (!__chkIPv6Range(val)) {
4550		Ext.MessageBox.alert('Error Message', val + ' is range error.');
4551		return false;
4552	}
4553	return true;
4554}
4555var chkIPv6CIDR = function(val, fieldname) {
4556	if (!val) {
4557		Ext.MessageBox.alert('Error Message', fieldname + ' is empty.');
4558		return false;
4559	}
4560	else if (!__chkIPv6CIDR(val)) {
4561		Ext.MessageBox.alert('Error Message', val + ' is IPv6 subnet in CIDR format error.');
4562		return false;
4563	}
4564	return true;
4565}
4566/* END_ZLDCONFIG_IPV6 */
4567var chkDomain = function(val, fieldname) {	/* Including wildcard domain & TLD check */
4568	/* Note: Max length of val is 127 (cf: MAX_CF_ITEM_BUF_SIZE in cf.h and __config_cf_profile in zysh_config_cf_profile.c) */
4569	if (!val) {
4570		Ext.MessageBox.alert('Error Message', fieldname + ' is empty.');
4571		return false;
4572	}
4573	else if (!__chkWildcardDomain(val) && !__chkTLD(val)) {
4574		Ext.MessageBox.alert('Error Message', '<div style="word-wrap:break-word">' + val + ' is invalid.</div>');
4575		return false;
4576	}
4577	return true;
4578}
4579var chkWebSite = function(val, fieldname) {
4580	if (!val) {
4581		Ext.MessageBox.alert('Error Message', fieldname + ' is empty.');
4582		return false
4583	}
4584	else {
4585		/* Note: Max length of val is 127 (cf: MAX_CF_ITEM_BUF_SIZE in cf.h and __config_cf_profile in zysh_config_cf_profile.c) */
4586		if (val.length > 127) {
4587			Ext.MessageBox.alert('Error Message', 'The length of ' + val + ' is more than 127.');
4588			return false;
4589		}
4590		var IPsplit = val.split(".");
4591		if (isNaN(IPsplit[IPsplit.length - 1])) {
4592			if (IPsplit[IPsplit.length - 1].indexOf("/", 0) == -1) {
4593				return chkDomain(val, fieldname);
4594			}
4595			else {
4596				return chkIPv4CIDR(val, fieldname);
4597			}
4598		}
4599		else {
4600			if (val.indexOf("-", 0) != -1) {
4601				return chkIPv4Range(val, fieldname);
4602			}
4603			else {
4604				return chkIPv4(val, fieldname);
4605			}	
4606		}
4607	}
4608} 
4609/* BEGIN_ZLDCONFIG_IPV6 */
4610var chkWebSiteWithIPv6 = function(val, fieldname) {
4611	if (!val) {
4612		Ext.MessageBox.alert('Error Message', fieldname + ' is empty.');
4613		return false
4614	}
4615	else {
4616		/* Note: Max length of val is 127 (cf: MAX_CF_ITEM_BUF_SIZE in cf.h and __config_cf_profile in zysh_config_cf_profile.c) */
4617		if (val.length > 127) {
4618			Ext.MessageBox.alert('Error Message', 'The length of ' + val + ' is more than 127.');
4619			return false;
4620		}
4621		if (val.indexOf(":", 0) == -1) {
4622			return chkWebSite(val);
4623		}
4624		else {	/* IPv6 address type */
4625			if (val.indexOf("/", 0) > 0) {
4626				return chkIPv6CIDR(val, fieldname);
4627			}
4628			else if (val.indexOf("-", 0) > 0) {
4629				return chkIPv6Range(val, fieldname);
4630			}
4631			else {
4632				if (!test_ipv6(val)) {
4633					Ext.MessageBox.alert('Error Message', val + ' is IPv6 format error.');
4634					return false;
4635				}
4636				return true;
4637			}
4638		}
4639	}
4640}
4641/* END_ZLDCONFIG_IPV6 */
4642/* Solve Javascript float computing error issue. ex:11.2 * 1.101 = 12.3311999999999 */
4643var floatCal = function (op, x, y, p) {
4644	var n = {
4645		'*': x * y,
4646		'-': x - y,
4647		'+': x + y,
4648		'/': x / y
4649	}[op];
4650	var x = Math.pow(10, p || 6);
4651	return Math.round(n * x)/x;
4652}
4653var chgDateFormat = function(store, data){
4654	var chr = /\w+/g;
4655	var result = store.getAt(0).get('_current_date').match(chr);
4656
4657	if(isNaN(data)) {
4658		return "";
4659	}
4660
4661	if(result[1].charAt(0) == "0") {
4662		var mon = result[1].substring(1,result[1].length);
4663	}else {
4664		var mon = result[1];
4665	}
4666	var total = new String(new Number(result[2])+new Number(data));
4667
4668	var str = new Date();
4669	str.setUTCFullYear(result[0]);
4670	str.setUTCMonth(mon-1);
4671	str.setUTCDate(total);
4672
4673	var year = str.getUTCFullYear();
4674	var mo = ((str.getUTCMonth() + 1)<10)?"0"+(str.getUTCMonth() + 1):(str.getUTCMonth() + 1);
4675	var day = (str.getUTCDate()<10)?"0"+str.getUTCDate():str.getUTCDate();
4676	
4677	return year+'-'+mo+'-'+day;	
4678}
4679function CHFW_CLI_showFirmwareBootOption(callback) {
4680	Ext.Ajax.request({
4681		url: zyCGI_P,
4682		method: 'POST',
4683		params: { filter:'js2', cmd: showCLI['showFirmwareBootOption'][0].cli, write:0 },
4684		timeout: 1500,
4685		failure:function(response,options){},
4686		success:function(response){
4687			var mydata=Ext.decode(js2json(response.responseText));
4688			callback && callback(mydata.zyshdata0[0]._boot_option);
4689		}
4690	});
4691}
4692function CHFW_NotRebootMonitor(delay){
4693	var MyForm = Ext.getCmp('firmwareform');
4694	Ext.Ajax.request({
4695		url: zyCGI_P,
4696		method: 'POST',
4697		params: { filter:'js2', cmd:composeCLI(['show cloud-helper firmware download-status']), write:0},
4698		timeout: 1500,
4699		callback: function(options, success, response){
4700			if (success){
4701				/*
4702				responseText:
4703				var zyshdata0=[];var errno0=-1000;var errmsg0='ZySH daemon is busy now.';
4704				*/
4705				if (response.responseText.indexOf("daemon") != -1)
4706				{	
4707					var timeoutID =  window.setTimeout(function(){
4708						CHFW_NotRebootMonitor(0);
4709					}, 2000);
4710				}else{
4711					if( parseInt(delay, 10) == 0){
4712						runTask.stopAll();
4713						
4714						var timeoutID =  window.setTimeout(function(){
4715							CHFW_CLI_CleanDownload();
4716							CHFW_GetDownloadStatus(function(_myshowCHFWDownloadStatus){
4717								showCHFWDownloadStatus = _myshowCHFWDownloadStatus;		
4718							});
4719							Ext.getBody().unmask();
4720							if (MyForm != undefined){
4721								MyForm.removeAll();
4722								MyForm.putData2Store(MyForm);
4723							}
4724						}, 3000);	
4725					}else{							
4726						var timeoutID =  window.setTimeout(function(){
4727							CHFW_NotRebootMonitor(delay);
4728						}, 1000);
4729					}
4730				}
4731			}else{
4732				var timeoutID =  window.setTimeout(function(){
4733						CHFW_NotRebootMonitor(1);
4734				}, 2000);
4735			}
4736		}
4737	});
4738}	
4739function CHFW_RebootMonitor(delay){
4740	Ext.Ajax.request({
4741		url: '/ext-js/index.html',
4742		method: 'GET',
4743		timeout: 1500,
4744		callback: function(options, success, response){
4745			if(!success){
4746				Ext.defer(function(){
4747					CHFW_RebootMonitor(0);
4748				}, 2000);
4749			} else {
4750				if( parseInt(delay, 10) == 0){
4751					runTask.stopAll();
4752					window.location.href='/';
4753				}else{							
4754					Ext.defer(function(){
4755						CHFW_RebootMonitor(delay);
4756					}, 2000);
4757				}
4758				
4759			}
4760		}
4761	});
4762}	
4763function CHFW_TimeCount(){
4764		var waitMsg = (ZLDSYSPARM_PRODUCT_LINE_NAME=='Device') ? mlang['_warning_message1_uag'] : mlang['_warning_message1'] + '<br>' + mlang['_warning_message2'] + mlang['_Please_Wait'] + '<br>' + mlang['_warning_message3'] + '<br>' + mlang['_warning_message5'];
4765		var initial = '10/25/2010 00:00:00 PM GMT+0800';
4766		var prestr, poststr;
4767		var sec = 0;
4768		if(Ext.getCmp('DHGeneralform') != undefined) Ext.getCmp('DHGeneralform').stopAlltask();
4769		
4770		this.task = {
4771			run: function() {
4772				sec++;
4773				if(waitMsg.lastIndexOf('<br>') != -1) {
4774					prestr = waitMsg.substr(0, waitMsg.lastIndexOf('<br>'));
4775					poststr = waitMsg.substr(waitMsg.lastIndexOf('<br>'));
4776					Ext.getBody().mask(prestr + Ext.Date.format(Ext.Date.add(new Date(initial), Ext.Date.SECOND, sec), 'i:s')+ poststr);
4777				}
4778				else {
4779					Ext.getBody().mask(waitMsg + Ext.Date.format(Ext.Date.add(new Date(initial), Ext.Date.SECOND, sec), 'i:s'));
4780				}
4781			},
4782			interval: 1000
4783		}
4784		runTask.start(this.task);
4785}
4786
4787function CHFW_Update(){
4788
4789	CHFW_TimeCount();
4790	
4791	CHFW_CLI_showFirmwareBootOption(function(Myres){
4792		if (Ext.getCmp('fwcloudstatus') != undefined) 
4793		{	
4794			Ext.getCmp('fwcloudstatus').close();
4795		}
4796		
4797		if (parseInt(Myres, 10) == 0){
4798			CHFW_RebootMonitor(1);
4799		}else{
4800			CHFW_NotRebootMonitor(1);
4801		}
4802	});
4803
4804}
4805
4806function CHFW_CheckDownloadStatus() {
4807	if ( parseInt(showCHFWDownloadStatus.getAt(0).get('_Status'),10) >= 7 ){
4808		CHFW_runTask.stopAll();
4809		CHFW_Update();
4810	} else if( parseInt(showCHFWDownloadStatus.getAt(0).get('_Status'),10) == 5 ||
4811			(parseInt(showCHFWDownloadStatus.getAt(0).get('_Result'),10) != 0)) {
4812		CHFW_runTask.stopAll();		
4813		if (Ext.getCmp('fwcloudstatus') == undefined){
4814			var boot_status = (showCHFWDownloadStatus.getAt(0).get("_Option") == "1")?"Running":"Standby";
4815			var btnClick = {caller:'zyfunc',boot_status:boot_status};
4816			callPage("zldapp.view.filemanager.fw_cloud_status", btnClick);
4817		} 
4818	}
4819}
4820function CHFW_GetDownloadStatus(callback) {
4821	this.task = {
4822		run: function() {
4823			Ext.Ajax.request({
4824				url: zyCGI_P,
4825				method: 'POST',
4826				params: { filter:'js2', cmd: showCLI['showCHFWDownloadStatus'][0].cli, write:0 },
4827				timeout: 1500,
4828				failure:function(response,options){},
4829				success:function(response){
4830					//Create Store
4831					var mydata=Ext.decode(js2json(response.responseText));
4832					var showCHFWDownloadStatus_tmp = [[mydata.zyshdata0[0]._Action, mydata.zyshdata0[0]._Option, mydata.zyshdata0[0]._Status, mydata.zyshdata0[0]._Result, mydata.zyshdata0[0]._Description, mydata.zyshdata0[0]._Filesize, mydata.zyshdata0[0]._Currentsize]];
4833					var showCHFWDownloadStatus = Ext.create('Ext.data.SimpleStore', {                                             
4834							fields:['_Action', '_Option', '_Status', '_Result', '_Description', '_Filesize', '_Currentsize'],
4835							data:showCHFWDownloadStatus_tmp
4836					});
4837					
4838					callback && callback(showCHFWDownloadStatus);
4839					
4840					//Check Download Status
4841					if ((showCHFWDownloadStatus.getAt(0).get("_Status") == "") || 
4842//						(parseInt(showCHFWDownloadStatus.getAt(0).get('_Result'),10) != 0) || //Cloud Helper error
4843//						(showCHFWDownloadStatus.getAt(0).get('_Status') == "5") ||		//Cloud Helper pause by user
4844						(showCHFWDownloadStatus.getAt(0).get('_Status') == "8")){		//Cloud Helper is done
4845						CHFW_runTask.stopAll();
4846					}
4847					else{//Downloading
4848						CHFW_CheckDownloadStatus();
4849					}
4850					
4851				}
4852			});	
4853		},
4854		interval: 1500
4855	}
4856	CHFW_runTask.start(this.task);
4857}
4858function CHFW_CLI_GetFirmware(mybootstatus, callback) {
4859	var cmd = Ext.String.format("cloud-helper get firmware {0}", mybootstatus);/*mybootstatus: 1:running; 2:standby*/
4860	Ext.Ajax.request({
4861		url: zyCGI_P,
4862		method : 'POST',
4863		params: { filter:'', cmd: cmd, write:0 },
4864		scope : this,
4865		success: function(response) {
4866			callback && callback("success");
4867		},
4868		failure: function(response) {
4869			callback && callback("failure");
4870		}
4871	});
4872}
4873function CHFW_CLI_CleanDownload(callback) {
4874	Ext.Ajax.request({
4875		url: zyCGI_P,
4876		method : 'POST',
4877		params: { filter:'', cmd: "cloud-helper clean-download firmware", write:0 },
4878		scope : this,
4879		success: function(response) {
4880			callback && callback("success");
4881		},
4882		failure: function(response) {
4883			callback && callback("failure");
4884		}
4885	});
4886}
4887function CHFW_CLI_ResumeDownload(callback) {
4888	var cmd = Ext.String.format("cloud-helper get firmware {0}", showCHFWDownloadStatus.getAt(0).get('_Option'));
4889	Ext.getBody().mask('Loading', 'x-mask-loading');
4890	Ext.Ajax.request({
4891		url: zyCGI_P,
4892		method : 'POST',
4893		params: { filter:'', cmd: cmd, write:0 },
4894		scope : this,
4895		success: function(response) {
4896			callback && callback("success");
4897		},
4898		failure: function(response) {
4899			callback && callback("failure");
4900		}
4901	});
4902}
4903function CHFW_CLI_PauseDownload(callback) {
4904	var cmd = Ext.String.format("cloud-helper pause-download firmware {0}", showCHFWDownloadStatus.getAt(0).get('_Option'));
4905	Ext.getBody().mask('Loading', 'x-mask-loading');
4906	Ext.Ajax.request({
4907		url: zyCGI_P,
4908		method : 'POST',
4909		params: { filter:'', cmd: cmd, write:0 },
4910		scope : this,
4911		success: function(response) {
4912			callback && callback("success");
4913		},
4914		failure: function(response) {
4915			callback && callback("failure");
4916		}
4917	});
4918}
4919function CHFW_CLI_CheckNow(mytpy,callback) {
4920	if (mytpy == 'all'){
4921		var _cmd = composeCLI(['cloud-helper check firmware','service-register checkexpire']);
4922	}else{
4923		var _cmd = composeCLI(['cloud-helper check firmware']);
4924	}
4925	Ext.Ajax.request({
4926		url: zyCGI_P,
4927		method: 'POST',
4928		params: { filter:'js2', cmd:_cmd, write:0},
4929		failure:function(response,options){
4930			callback && callback("failure");
4931		},
4932		success:function(response){				
4933			callback && callback("success");
4934		}
4935	});
4936}
4937
4938function ZYSHD_CLI_Check(mytmp,callback) {
4939	if (mytmp == 'yes'){
4940		var _cmd = composeCLI(['diaginfo collect ac']);
4941	}else{
4942		var _cmd = composeCLI(['reboot']);
4943	}
4944	Ext.Ajax.request({
4945		url: zyCGI_P,
4946		method: 'POST',
4947		params: { filter:'js2', cmd:_cmd, write:0},
4948		failure:function(response,options){
4949			callback && callback("failure");
4950		},
4951		success:function(response){				
4952			callback && callback("success");
4953		}
4954	});
4955}
4956function Filter_Address_Store(pattern,stores) {
4957	for(var i=0; i<stores.length; i++){
4958		stores[i].clearFilter(true); 	
4959		stores[i].filterBy(function(rec, id) {
4960			if (rec.get('_Type').match(pattern))
4961				return false;
4962			else
4963				return true;
4964		});			
4965	
4966	}
4967}
4968
4969
4970/*
4971Examples :
4972[1,2,3,4,5,6].diff( [3,4,5] );  
4973// => [1, 2, 6]
4974
4975["test1", "test2","test3","test4","test5","test6"].diff(["test1","test2","test3","test4"]);  
4976// => ["test5", "test6"]
4977*/
4978Array.prototype.diff = function(a) {
4979    return this.filter(function(i) {return a.indexOf(i) < 0;});
4980};
4981
4982function LIC_Serv_Status(mystatus){
4983	switch (mystatus){
4984		case "Activated":
4985		case "Expired":
4986		case "Grace Period":
4987		case "Not Activated":
4988		case "Not Licensed":
4989			return mystatus;
4990		break;
4991		
4992	}
4993}
4994
4995function getAjaxJSONFile(url, callback){
4996	Ext.Ajax.request({
4997		url: url,
4998		method: 'POST',
4999		async:true,
5000		success: function(response){
5001			if (response.responseText != ""){
5002				var result = Ext.decode(response.responseText);
5003				callback && callback("success", result);
5004			}else{
5005				callback && callback("failure");
5006			}
5007		},
5008		failure: function(response) {
5009			callback && callback("failure");
5010		}
5011	});
5012}
5013
5014function showErrorMsg(msg){
5015  Ext.MessageBox.show({
5016			title: mlang['_Error_Message'],
5017			msg: msg,
5018			buttons: Ext.MessageBox.OK,
5019			icon: Ext.MessageBox.ERROR
5020	});          
5021}
5022
5023/*
5024function checkLicense(status){
5025  		switch(status){
5026  			case 'Expired':
5027  			case 'Not Licensed':
5028  				return false;
5029  			break;
5030  			case 'Grace Period':
5031  			case 'Not Activated':         
5032		    case "Activated":
5033  				return true;
5034  			break;
5035		  }
5036}*/
5037
5038function chkSecuReporteBanner(){
5039	var cmd = ['show service-register status secu-reporter'];
5040	Ext.Ajax.request({
5041		url: zyCGI_P,
5042		method: 'POST',
5043		params: { filter:'js2', cmd:composeCLI(cmd), write:0},
5044		callback: function(options, success, response){
5045			if (success){
5046				var res = Ext.decode(js2json(response.responseText));
5047				var rec = res.zyshdata0[0];
5048				secureporter_license_status = rec._Status;
5049				var isRegistered, failcount=0;/*Is the device registered on secuReporter?*/
5050				chkSecuReporterRegistered(function(status, isRegistered){
5051					if (status == "success"){ //success to start the connection      
5052						if(!isRegistered){  
5053							console.log("chkSecuReporterRegistered unclaim");
5054							var myCallback =  function(status){
5055							  if (status == "success"){ // success to start the connection            
5056								waitSecuReporterStatus(function(status, result){
5057									if (status == "success"){                            
5058									//Got the json1 and status = ready, the get json2
5059									getSecuReporteDevInfo(function(status, result){   
5060										if (status == "success"){
5061											isRegistered = result.status.code;
5062											if(isRegistered == 0 /* not registered */
5063											&& (secureporter_license_status=="Activated" || secureporter_license_status=="Grace Period" 
5064											|| secureporter_license_status=="Not Activated"
5065											)){
5066												SecuReporter_Device_Info = result;
5067												SecuReporter_Conn_Status = {status: 1}; /*file is ready*/
5068												SecuReporter_Orgs_Store = Ext.create('Ext.data.GroupingStore',{
5069													async : false,
5070													fields: ['id','name'],
5071													data: result.data.organizations
5072												}); 
5073												Open_SecuReporter_Banner(result, isRegistered);
5074												return;                
5075											}else if(isRegistered == 1){/* registered */      
5076												document.getElementById('secureporter-btn').setAttribute("style","");
5077												if(showSecuReporterEverEanble.getAt(0).get('_ever_enabled')=='no' && secureporter_license_status=="Activated" )
5078												  Open_SecuReporter_Banner(result, isRegistered);
5079												return;                               
5080											}else if(isRegistered == 0 && secureporter_license_status=="Expired"){ 
5081												return;/*Do nothing*/                                
5082											}else { /* timeout or error*/
5083												++failcount;                                  
5084												if(failcount<3){//Ext.defer(startToGetSecuReporterStatus(myCallback), 5000); //Mark by Eve 2019-12-24, console will show "Uncaught TypeError: Cannot read property 'apply' of undefined"
5085													Ext.defer(function(){
5086														startToGetSecuReporterStatus(function(MyStatus){
5087															myCallback(MyStatus);
5088														})
5089													}, 5000);
5090												}                                  
5091											}       
5092										}else{
5093											++failcount;
5094											if(failcount<3){
5095												//Ext.defer(startToGetSecuReporterStatus(myCallback), 5000); //Mark by Eve 2019-12-24, console will show "Uncaught TypeError: Cannot read property 'apply' of undefined"
5096												Ext.defer(function(){
5097													startToGetSecuReporterStatus(function(MyStatus){
5098														myCallback(MyStatus);
5099													})
5100												}, 5000);
5101											}                                
5102										}
5103									});                                     
5104								}else{
5105									++failcount;
5106									if(failcount<3){
5107										//Ext.defer(startToGetSecuReporterStatus(myCallback), 5000); //Mark by Eve 2019-12-24, console will show "Uncaught TypeError: Cannot read property 'apply' of undefined"
5108										Ext.defer(function(){
5109											startToGetSecuReporterStatus(function(MyStatus){
5110												myCallback(MyStatus);
5111											})
5112										}, 5000);                                
5113									}
5114								}
5115							});  
5116							}          
5117							};
5118							if (secureporter_license_status=="Activated" || secureporter_license_status=="Grace Period") 
5119							startToGetSecuReporterStatus(myCallback);        
5120						}else{//end of isRegistered
5121							//console.log("claimed device");
5122							document.getElementById('secureporter-btn').setAttribute("style","");
5123							if(showSecuReporterEverEanble.getAt(0).get('_ever_enabled')=='no' && secureporter_license_status=="Activated" ){             
5124							  Open_SecuReporter_Banner(null, 1);             
5125							}                 
5126						}
5127					}
5128				});
5129			}
5130		}
5131	});
5132	
5133}
5134
5135function waitSecuReporterConnStatus(){
5136	var task_loadJSON2Store = {
5137		run: function() {
5138			var url = '/securpt_api_status.json';
5139			me.getAjaxJSONFile(url, function(status, result) {
5140				if (status == "success"){  
5141					var code = result.status.code;     
5142					Open_SecuReporter_Banner(result);           
5143					if(code == 0){ /*Ready*/
5144						runTask.stop(task_loadJSON2Store);  
5145					}else if(code !=2){ /* wait or error: nothing happen*/
5146						runTask.stop(task_loadJSON2Store);        
5147					}
5148				}else{
5149					runTask.stop(task_loadJSON2Store);        
5150				}
5151			});
5152		},
5153		interval: 1000
5154	}
5155	runTask.start(task_loadJSON2Store);  
5156}
5157function Open_SecuReporter_Banner(result, registered){
5158    /*var msg = secureporter_license_status == 'Not Activated'? 
5159	'Do you want to activate the license and enable SecuReporter now?'
5160	:'Your SecuReporter is not enabled yet, do you want to enable and start analytics service?';*/
5161    var isEnabled = (showSecuReporter.getAt(0).get('_activate')=='yes')?true:false; 
5162    if(isEnabled)
5163      var msg = mlang['_SecuReporter_Enabled_Not_Claimed'];
5164    else
5165      var msg = mlang['_SecuReporter_Not_Enabled_Not_Claimed'];    
5166    /*var btn_msg = (secureporter_license_status == 'Not Activated')? 'Activate SecuReporter':'Enable SecuReporter';*/
5167    var btn_msg = isEnabled? mlang['_Easy_Continue']: mlang['_Enable_SecuReporter'];
5168
5169    var secu_close_msg = '<\/span><\/span><input type=\"checkbox\" id=\"secu_close_msg1\" >'+'<span style=font-size:12px;padding-top:0px;>'+mlang['_SecuReporter_Banner_Ask_User'];
5170    var floatPanel = new Ext.zyPanel({
5171      id: 'floatingpanel',          
5172      layout: {
5173          type: 'hbox'
5174      },
5175      openBanner:function(){
5176        if(registered){
5177			var btnClick = {caller:'secu-reporter-alert'};
5178			var win = callPage('zldapp.view.pagestore.gdpr', btnClick);
5179			var task = new Ext.util.DelayedTask(function(){
5180				win.putData2Store(win);
5181			});
5182			task.delay(Ext.isIE9 ? 2000 : 0);   
5183			Ext.getBody().unmask();            
5184        }else{
5185          callPage("zldapp.view.pagestore.secureporteredit", {});
5186        }
5187      },
5188      header:false,           
5189      floating: true,
5190      draggable: false,
5191      bodyCls:"x-secuReporter-banner",
5192      width: 464,
5193      height: 50,
5194      items: [      
5195      {
5196          xtype: 'zypanel',
5197          width:426,  
5198          style:"padding-left:14px;padding-top:2px;",
5199          bodyStyle:"background:#F7BE00;",       
5200          id:'banner_panel',            
5201          html: '<span style=\"width:100%;display:table-cell;font-size:12px;\">'+msg+ '<span onclick=\"Ext.getCmp(\'floatingpanel\').openBanner();\" style=\"cursor: pointer;margin-left:8px;padding-left:10px;padding-right:10px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-top-left-radius:5px;border-bottom-left-radius:5px;background-color:#FFF;width:124;color:#F18A00;font-weight:bold;font-size:12px;\">'+btn_msg+ secu_close_msg
5202      },
5203      { 
5204			xtype:'tool',
5205			type:'close',
5206			cls:'x-zybanner',
5207			qtip : 'Close',
5208			handler: function(e, target, header, tool){
5209				if ( document.getElementById("secu_close_msg1").checked === true )
5210				{
5211					Ext.Ajax.request({
5212					url: zyCGI_P,
5213					method: 'POST',
5214					params: { filter:'js2', cmd:composeCLI(['no secu-reporter banner']), write:1 },
5215					timeout: 3000,
5216					callback: function(options, success, response){
5217					}
5218					});
5219				}
5220				Ext.getCmp('floatingpanel').close();
5221				SecuReporter_Banner_Close = 1;
5222				eraseCookie('secuRtBannerClsCookie');           
5223			}          
5224      }],
5225      renderTo: Ext.getBody()
5226    });        
5227    floatPanel.el.alignTo(Ext.getBody(), 'tc-tc');    
5228    window.addEventListener('resize', function(event){
5229      floatPanel.el.alignTo(Ext.getBody(), 'tc-tc');
5230    });    
5231}
5232
5233
5234function chkSecuReporterRegistered(callback){
5235    var url = '/claim_status.json';
5236    var expiration_interval = 1;
5237    getAjaxJSONFile(url, function(status, result) {
5238      if (status == "success"){
5239        var today = new Date();
5240        var timestamp = new Date(result.timestamp* 1000 );
5241        var expirationDay = timestamp.setDate(timestamp.getDate()+ expiration_interval);
5242        var isExpired = today >= expirationDay;
5243        var isRegistered = result.status.code == 1? true:false;
5244        /*1:isRegistered, 0:isNotRegistered, timeout: 901 or -1 */       
5245 				callback && callback("success", (isRegistered && !isExpired)?true:false);
5246      }else{
5247 				callback && callback("success", false);        
5248      }  
5249    });
5250}
5251
5252function startToGetSecuReporterStatus(callback){
5253	Ext.Ajax.request({
5254		url: '/securpt.cgi',
5255		method : 'POST',  
5256		params: {action:'status'},
5257		async:true,
5258		scope : this,    
5259		success: function(response) {
5260			var ret = Ext.decode(response.responseText);
5261			if(ret.success)
5262				callback && callback("success");
5263			else
5264				callback && callback("failure");      
5265		},
5266		failure: function(response) {
5267			callback && callback("failure");
5268		}
5269	});
5270}
5271
5272function waitSecuReporterStatus(callback){
5273	var task_loadJSON2 = {
5274		run: function() {
5275			var url = '/securpt_api_status.json';      
5276			getAjaxJSONFile(url, function(status, result) {
5277				if (status == "success"){  
5278				  var code = result.code;              
5279				  if(code == 1){ //Ready
5280					secuReporterRunTask.stop(task_loadJSON2);  
5281					callback && callback("success");
5282				  }else{
5283					console.log("waiting for status")
5284				  }
5285				}else{
5286				  secuReporterRunTask.stop(task_loadJSON2);  
5287				  callback && callback("failure");      
5288				}
5289			});
5290		},
5291		interval: 1000
5292	}
5293	secuReporterRunTask.start(task_loadJSON2);  
5294}
5295
5296function getSecuReporteDevInfo(callback){
5297	var url = '/claim_status.json';
5298	getAjaxJSONFile(url, function(status, result) {
5299		if (status == "success"){
5300			callback && callback("success", result);
5301		}else{
5302			showErrorMsg(result.status.message);
5303		}
5304	});  
5305}
5306
5307function getSecuReporterSiteURL(type){
5308	if (type == "official"){
5309		return 'https://secureporter.cloudcnm.zyxel.com';
5310	}else if (type == "alpha"){
5311		return 'https://alpha.secureporter.cloudcnm.zyxel.com';
5312	}else{
5313		return 'https://beta.secureporter.cloudcnm.zyxel.com';
5314	} 
5315}
5316
5317function getSecuReporterLoginURL(type){
5318	if (type == "official"){
5319		return 'https://secureporter.cloudcnm.zyxel.com/device/login';
5320	}else if (type == "alpha"){
5321		return 'https://alpha.secureporter.cloudcnm.zyxel.com/device/login';
5322	}else{
5323		return 'https://beta.secureporter.cloudcnm.zyxel.com/device/login';
5324	} 
5325}
5326function deleteRuleInStore(store, field, str, flag){
5327	var rm=[];
5328	/* flag == true -> remove, flag == false -> keep*/  
5329	var reg = new RegExp("^" + str + ".*$");    
5330	store.each(function(rec) {
5331    result = flag? reg.test(rec.get(field)): !reg.test(rec.get(field));
5332    if(result)
5333		{
5334			rm.push(rec);
5335		}
5336	});
5337	store.remove(rm);
5338	return store;                    
5339}
5340var GtagID = "UA-169602851-3";
5341function gtag(){
5342	dataLayer.push(arguments);	
5343}
5344function GA_SetEnvir(){
5345		/*Include GA library: create new script tag*/
5346		var n = document.createElement("script");
5347		var head= document.getElementsByTagName("head").item(0);
5348		n.type = 'text/javascript';
5349		//n.id = id;
5350		n.src = "https://www.googletagmanager.com/gtag/js?id="+ GtagID;
5351		n.async = true;
5352		head.appendChild(n);
5353		head = n = null;
5354		
5355}
5356function GA_Set_Tag(myID){
5357	if (google_analytics == "yes"){
5358		
5359		window.dataLayer = window.dataLayer || [];
5360		gtag('js', new Date());
5361		
5362		gtag('config',  GtagID, {	
5363			'page_path': myID
5364		});
5365		
5366		if (Ext.isDefined(product_name) && Ext.isDefined(firmware_version) && Ext.isDefined(sn)){
5367			gtag('set', {
5368				'dimension1':product_name,
5369				'dimension2':firmware_version
5370			}); 
5371		}
5372	}
5373}
5374function GA_Set_Event(Category, Action, Label, Value){
5375    if (google_analytics == "yes"){
5376        gtag('event', Action, {
5377              'event_category': Category,
5378              'event_label': Label,
5379              'value': Value
5380        });
5381        var msg = Ext.String.format("[google analytics][Event] Category= {0}, Action= {1}, Label = {2}, Value={3}", Category, Action, Label, Value);
5382        console.log(msg);
5383    }
5384}
5385/* punycode */
5386var regexNonASCII = /[^\x20-\x7E]/;
5387var regexPunycode = /^xn--/;
5388
5389// remove @ handle from punycode.js source code
5390function mapDomain(string, fn) {
5391	var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g;
5392	function map(array, fn) {
5393		var length = array.length;
5394		var result = [];
5395		while (length--) {
5396			result[length] = fn(array[length]);
5397		}
5398		return result;
5399	}
5400	// Avoid `split(regex)` for IE8 compatibility. See #17.
5401	string = string.replace(regexSeparators, '\x2E');
5402	var labels = string.split('.');
5403	var encoded = map(labels, fn).join('.');
5404	return encoded;
5405}
5406
5407function punycodeToASCII(input){
5408	return mapDomain(input, function(string) {
5409		return regexNonASCII.test(string)
5410			? 'xn--' + punycode.encode(string)
5411			: string;
5412	});
5413}
5414
5415function punycodeToUnicode(input) {
5416	return mapDomain(input, function(string) {
5417		return regexPunycode.test(string)
5418			? punycode.decode(string.slice(4))
5419			: string;
5420	});
5421}
5422
5423/* Decode SSID name when it is encode with punycode */
5424function decodeSSIDName(ssidName) {	
5425	var decodeStr = '';
5426
5427	try {
5428		decodeStr = punycodeToUnicode(ssidName);
5429		
5430		var encodeStr = punycodeToASCII(decodeStr);
5431		if (encodeStr != ssidName) {
5432			decodeStr = ssidName;
5433		}
5434	}
5435	catch(e) {
5436		decodeStr = ssidName;
5437	}
5438	
5439	return decodeStr;
5440}
5441/* punycode */
5442
5443function renderSecurityMode(value, isPSK, isTransition){
5444	var show_value = '';
5445	var isLowerCase = /^[a-z]/.test(value);
5446	switch (value){
5447		case 'NONE':
5448			show_value = 'Open';
5449			break;
5450		case 'WPA2':
5451			show_value = 'WPA2-Enterprise';
5452			break;
5453		case 'WPA2-PSK':
5454			show_value = 'WPA2-Personal';
5455			break;	
5456		case 'WPA2Mix':
5457			show_value = 'WPA2Mix-Enterprise';
5458			break;			
5459		case 'WPA2Mix-PSK':
5460			show_value = 'WPA2Mix-Personal';
5461			break;	
5462		case '8021x-Only':
5463			show_value = 'Enterprise-Only';
5464			break;
5465		case '8021x+WEP':
5466			show_value = 'Enterprise+WEP';
5467			break;	
5468		case 'none':
5469			show_value = isPSK ? 'Open' : 'Enterprise-Only';
5470			break;
5471		case 'wep' :
5472			show_value = isPSK ? 'WEP' : 'Enterprise+WEP';
5473			break;
5474		case 'wpa2':
5475			show_value = isPSK ? 'WPA2-Personal' : 'WPA2-Enterprise';
5476			break;
5477		case 'wpa2-mix':
5478			show_value = isPSK ? 'WPA2Mix-Personal' : 'WPA2Mix-Enterprise';
5479			break;
5480		case 'enhanced-open':
5481			show_value = isTransition ? 'Open/Enhanced-Open' : 'Enhanced-Open';
5482			break;
5483		case 'wpa3':
5484			show_value = isPSK ? isTransition ? 'WPA2/WPA3-Personal' : 'WPA3-Personal' : 'WPA3-Enterprise';
5485			break;	
5486		default:
5487			show_value = isLowerCase ? value.toUpperCase(): value;
5488	}
5489	return show_value;
5490}
5491function chgIntoSubNet(netIP, netMask) {
5492		var i = 0, j = 0;
5493		var tempArray1 = new Array();
5494		var tempArray2 = new Array();
5495		var ret = "";
5496		tempArray1[0] = "";
5497		tempArray2[0] = "";
5498		while ((i < netIP.length) && (j<4)){
5499			if (netIP.charAt(i) != '.'){
5500				tempArray1[j] = tempArray1[j] + netIP.charAt(i);
5501			}else{
5502				j++;
5503				tempArray1[j] = "";
5504			}
5505			++i;
5506		}
5507		i = 0;
5508		j = 0;
5509		while ((i < netMask.length) && (j<4)){
5510			if (netMask.charAt(i) != '.'){
5511				tempArray2[j] = tempArray2[j] + netMask.charAt(i);
5512			}else{
5513				j++;
5514				tempArray2[j] = "";
5515			}
5516			++i;
5517		}
5518		for(i=0 ; i<=3 ; ++i){
5519			ret = ret + (tempArray2[i] & tempArray1[i]);
5520			if (i != 3) ret += ".";
5521		}
5522		return ret;
5523}  
5524function chgRangetoBits(addr) {
5525	var parts = addr.split('.')
5526	var result = (parts[0] ? parseInt(parts[0])<<24 : 0) + (parts[1] ? parseInt(parts[1])<<16 : 0) + (parts[2] ? parseInt(parts[2])<<8  : 0) + parseInt(parts[3])<<0;
5527    result = result >>> 0;
5528	return result;
5529}
5530function checkIpaddrInRange(ipaddr, start, end) {
5531  var num = chgRangetoBits(ipaddr);
5532  return (num >= chgRangetoBits(start)) && (num <= chgRangetoBits(end));
5533}
5534function renewSuffix(obj,objsuffix,objinote){
5535	var table = document.getElementById(obj.id+'-triggerWrap');
5536	var row = table.getElementsByTagName("tr")[0];
5537	if (objinote == null)
5538		row.cells[2].innerHTML = "<div style=\"margin-left:20px;\" >" + objsuffix + "</div>";
5539	else
5540		row.cells[2].innerHTML = "<div style=\"margin-left:20px;\" >" + objsuffix + "&nbsp;" + objinote + "</div>";
5541}
5542function renewInote(obj,objinote){
5543	var table = document.getElementById(obj.id+'-triggerWrap');
5544	var row = table.getElementsByTagName("tr")[0];
5545		row.cells[2].innerHTML = "<div style=\"margin-left:20px;\" >" + objinote + "</div>";
5546}
5547function addSuffix(ptype,pfrom,pvalue,zyid,zyidx){
5548	return '<a href="#" onclick="addProfile(\'' + ptype + '\', \'' + pfrom + '\',\'' + zyid + '\',\'' + zyidx + '\');"><img src="/ext-js/images/usg/icons/add.png" class="ez_img" align="absmiddle" data-qtip=\'' + mlang["_Add"] + '\'></a>&nbsp;&nbsp;';
5549}
5550function addEditSuffix(ptype,pfrom,pvalue,zyid,zyidx){
5551	return '<a href="#" onclick="addProfile(\'' + ptype + '\',\'' + pfrom + '\',\'' + zyid + '\',\'' + zyidx + '\');"><img src="/ext-js/images/usg/icons/add.png" class="ez_img" align="absmiddle" data-qtip=\'' + mlang["_Add"] + '\'></a>&nbsp;&nbsp;&nbsp;<a href="#" onclick="editProfile(\'' + ptype + '\', \'' + pvalue + '\',\'' + pfrom + '\',\'' + zyid + '\',\'' + zyidx + '\');"><img src="/ext-js/images/usg/icons/edit.png" class="ez_img" align="absmiddle" data-qtip=\'' + mlang["_Edit"] + '\'></a>&nbsp;&nbsp;';
5552}
5553function editSuffix(ptype,pfrom,pvalue,zyid,zyidx){
5554	return '<a href="#" onclick="editProfile(\'' + ptype + '\', \'' + pvalue + '\',\'' + pfrom + '\',\'' + zyid + '\',\'' + zyidx + '\');"><img src="/ext-js/images/usg/icons/edit.png" class="ez_img" align="absmiddle" data-qtip=\'' + mlang["_Edit"] + '\'></a>&nbsp;&nbsp;';
5555}
5556function addEditSuffixDisable(){
5557	return '<span style="text-decoration:underline;"><img src="/ext-js/images/usg/icons/add.png" class="ez_img_disable" align="absmiddle"></span>&nbsp;&nbsp;&nbsp;<span style="text-decoration:underline;"><img src="/ext-js/images/usg/icons/edit.png" class="ez_img_disable" align="absmiddle"></span>&nbsp;&nbsp;';
5558}
5559function aaaServerAddSuffix(ptype,pfrom,pvalue,zyid,zyidx){
5560	return '<a href="#" onclick="callPage(\'zldapp.view.object.authmeth.authmeth.addserverlist\',\'' + zyid + ' \' + \'' + zyidx + '\');"><img src="/ext-js/images/usg/icons/add.png" class="ez_img" align="absmiddle" data-qtip=\'' + mlang["_Add"] + '\'></a>&nbsp;&nbsp;';
5561}
5562function aaaServerAddEditSuffix(ptype,pfrom,pvalue,zyid,zyidx){
5563	return '<a href="#" onclick="callPage(\'zldapp.view.object.authmeth.authmeth.addserverlist\',\'' + zyid + ' \' + \'' + zyidx + '\');"><img src="/ext-js/images/usg/icons/add.png" class="ez_img" align="absmiddle" data-qtip=\'' + mlang["_Add"] + '\'></a>&nbsp;&nbsp;&nbsp;<a href="#" onclick="editProfile(\'' + ptype + '\', \'' + pvalue + '\',\'' + pfrom + '\',\'' + zyid + '\');"><img src="/ext-js/images/usg/icons/edit.png" class="ez_img" align="absmiddle" data-qtip=\'' + mlang["_Edit"] + '\'></a>&nbsp;&nbsp;';
5564}
5565function addProfile(pf_type, pf_from, zyid, zyidx){
5566	switch(pf_type) {
5567		case 'APGroup' :
5568		btnClick = {'type':'apgroupedit', 'winPath': 'zldapp.view.wireless.apmgnt.apgroupedit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5569		callInlineObj(btnClick);
5570		break;
5571		case 'Radio' :
5572		btnClick = {'type':'radioedit', 'winPath': 'zldapp.view.object.approfile.radioedit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5573		callInlineObj(btnClick);
5574		break;
5575		case 'Mon' :
5576		btnClick = {'type':'monprofedit', 'winPath': 'zldapp.view.object.monprofile.monprofedit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5577		callInlineObj(btnClick);
5578		break;
5579		case 'Zymesh' :
5580		btnClick = {'type':'zymeshprofedit', 'winPath': 'zldapp.view.object.zymeshprofile.zymeshprofedit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5581		callInlineObj(btnClick);
5582		break;
5583		case 'SSID' :
5584		btnClick = {'type':'ssidedit', 'winPath': 'zldapp.view.object.approfile.ssidedit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5585		callInlineObj(btnClick);
5586		break;
5587		case 'wlanSecurity' :
5588		btnClick = {'type':'securityedit', 'winPath': 'zldapp.view.object.approfile.securityedit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5589		callInlineObj(btnClick);
5590		break;
5591		case 'macFilter' :
5592		btnClick = {'type':'macfilteredit', 'winPath': 'zldapp.view.object.approfile.macfilteredit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5593		callInlineObj(btnClick);
5594		break;
5595		case 'l2Isolation' :
5596		btnClick = {'type':'l2isolationedit', 'winPath': 'zldapp.view.object.approfile.l2isolationedit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5597		callInlineObj(btnClick);
5598		break;
5599		case 'Authpolicygroup' :
5600		btnClick = {'type':'appolicygroupedit', 'winPath': 'zldapp.view.authpolicy.appolicygroupedit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5601		callInlineObj(btnClick);
5602		break;
5603		case 'ad' :
5604		btnClick = {'type':'aaaServerEdit', 'winPath': 'zldapp.view.object.aaserver.activediredit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5605		callInlineObj(btnClick);
5606		break;
5607		case 'radius' :
5608		btnClick = {'type':'aaaServerEdit', 'winPath': 'zldapp.view.object.aaserver.radiusedit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5609		callInlineObj(btnClick);
5610		break;
5611		case 'ldap' :
5612		btnClick = {'type':'aaaServerEdit', 'winPath': 'zldapp.view.object.aaserver.ldapedit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5613		callInlineObj(btnClick);
5614		break;
5615		case 'authMethod' :
5616		btnClick = {'type':'authmethedit', 'winPath': 'zldapp.view.object.authmeth.authmeth.authmethedit','caller':pf_from, action:'add', rowSel:null, quickedit:'no', select: 'yes', zyid: zyid, zyidx: zyidx};
5617		callInlineObj(btnClick);
5618		break;
5619	}
5620}
5621function editProfile(pf_type, pf_name, pf_from, zyid, zyidx){
5622	var aaa_type = '';
5623	var aaa_find = 0;
5624	var pf_name_filter = '';
5625	if (pf_type == 'Method3a')
5626		pf_name_filter = pf_name.split(' / ')[0];
5627	else
5628		pf_name_filter = pf_name;
5629	var pf_store = Ext.create('Ext.data.ArrayStore',{
5630		fields: ['__name'],
5631		data: [[pf_name_filter]]
5632	});
5633	switch(pf_type) {
5634		case 'APGroup' :
5635		btnClick = {'type':'apgroupedit', 'winPath': 'zldapp.view.wireless.apmgnt.apgroupedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5636		callInlineObj(btnClick);
5637		break;
5638		case 'Radio' :
5639		btnClick = {'type':'radioedit', 'winPath': 'zldapp.view.object.approfile.radioedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes',zyid: zyid};
5640		callInlineObj(btnClick);
5641		break;
5642		case 'SSID' :
5643		btnClick = {'type':'ssidedit', 'winPath': 'zldapp.view.object.approfile.ssidedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes', zyid: zyid, zyidx: zyidx};
5644		callInlineObj(btnClick);
5645		break;
5646		case 'Mon' :
5647		btnClick = {'type':'monprofedit', 'winPath': 'zldapp.view.object.monprofile.monprofedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes',zyid: zyid};
5648		callInlineObj(btnClick);
5649		break;
5650		case 'Zymesh' :
5651		btnClick = {'type':'zymeshprofedit', 'winPath': 'zldapp.view.object.zymeshprofile.zymeshprofedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5652		callInlineObj(btnClick);
5653		break;
5654		case 'Authpolicygroup' :
5655		btnClick = {'type':'appolicygroupedit', 'winPath': 'zldapp.view.authpolicy.appolicygroupedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5656		callInlineObj(btnClick);
5657		break;
5658		case 'APPolicyRule' :
5659		btnClick = {'type':'appolicyruleedit', 'winPath': 'zldapp.view.authpolicy.appolicyruleedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5660		callInlineObj(btnClick);
5661		break;
5662		case 'APPolicyRuledef' :
5663		btnClick = {'type':'appolicydefruleedit', 'winPath': 'zldapp.view.authpolicy.appolicydefruleedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5664		callInlineObj(btnClick);
5665		break;
5666		case 'wlanSecurity' :
5667		btnClick = {'type':'securityedit', 'winPath': 'zldapp.view.object.approfile.securityedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5668		callInlineObj(btnClick);
5669		break;
5670		case 'macFilter' :
5671		btnClick = {'type':'macfilteredit', 'winPath': 'zldapp.view.object.approfile.macfilteredit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5672		callInlineObj(btnClick);
5673		break;
5674		case 'l2Isolation' :
5675		btnClick = {'type':'l2isolationedit', 'winPath': 'zldapp.view.object.approfile.l2isolationedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5676		callInlineObj(btnClick);
5677		break;
5678		case 'authMethod' :
5679		btnClick = {'type':'authmethedit', 'winPath': 'zldapp.view.object.authmeth.authmeth.authmethedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5680		callInlineObj(btnClick);
5681		break;
5682		case 'Method3a' :
5683			switch(pf_name.split(' / ')[1]) {
5684				case 'AD' :
5685				btnClick = {'type':'aaaServerEdit', 'winPath': 'zldapp.view.object.aaserver.activediredit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5686				callInlineObj(btnClick);
5687				break;
5688				case 'RADIUS' :
5689				btnClick = {'type':'aaaServerEdit', 'winPath': 'zldapp.view.object.aaserver.radiusedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5690				callInlineObj(btnClick);
5691				break;
5692				case 'LDAP' :
5693				btnClick = {'type':'aaaServerEdit', 'winPath': 'zldapp.view.object.aaserver.ldapedit','caller':pf_from,action:'edit', rowSel:pf_store.getAt(0), quickedit:'yes'};
5694				callInlineObj(btnClick);
5695				break;
5696			}
5697		break;
5698	}
5699}
5700function setProfile2Top(name, store, field, prefix){
5701	if(prefix=='undefined'){
5702		if (name=='undefined'){
5703			store.sort(field, 'ASC');
5704			return mixStore(null, store, field);
5705		}else{
5706			var lastInx = store.data.length-1;
5707			var lastRecord = store.getAt(lastInx);
5708			store.remove(lastRecord);
5709			store.sort(field, 'ASC');
5710			store.insert(0,lastRecord);
5711			store.commitChanges();
5712			return mixStore(null, store, field);
5713		}
5714	}else{
5715		if (name=='undefined'){
5716			store.sort(field, 'ASC');
5717			return mixStore(prefix, store, field);
5718		}else{
5719			var lastInx = store.data.length-1;
5720			var lastRecord = store.getAt(lastInx);
5721			store.remove(lastRecord);
5722			store.sort(field, 'ASC');
5723			var createObj = {				
5724				'__name': prefix
5725			};
5726			var record = createRec(store,createObj);             
5727			store.insert(0, [record.rec]);
5728			store.commitChanges();
5729			store.insert(0,lastRecord);
5730			store.commitChanges();
5731			return mixStore(null, store, field);
5732		}
5733	}
5734}
5735function set_GA_Info_Event_For_Login(action,modelName){
5736	var GAInfo = {
5737		"status":  action,
5738		"modelName":  modelName
5739	};	
5740	GA_Set_Tag_RA_Event_For_Login(GAInfo);
5741}	
5742
5743function GA_Set_Tag_RA_Event_For_Login(GAInfo){
5744	var msg = "[google analytics] event id = " + GAInfo.status;
5745	window.dataLayer = window.dataLayer || [];
5746	gtag('js', new Date());	
5747	gtag('config',  GtagID, {	
5748		'page_path': 'Login>'+GAInfo.status,
5749	});
5750	gtag('set', {
5751			'dimension1': GAInfo.status,
5752			'dimension2': GAInfo.modelName
5753		}); 
5754	gtag('send','pageview');
5755
5756	var action = 'Login>'+GAInfo.status; 
5757
5758	gtag('event', action, {
5759		'event_category': 'Login',
5760	});
5761	msg += ", action = " + action+", modelName = "+ modelName;
5762	console.log(msg);
5763}
5764function update_availbable(mac) {
5765	console.log(mac);
5766	Ext.MessageBox.show({
5767		width: 450,
5768		title: mlang['_warning'],
5769		cls: 'x-zywindow',
5770		msg: mlang['_AP_FW_Download_Msg'],
5771		buttons: Ext.MessageBox.YESNO,
5772		fn: function(btn){
5773			if(btn == 'yes'){		
5774				Ext.Ajax.request({
5775					url: zyCGI_P,
5776					method: 'POST',
5777					async : true,            
5778					params: { filter:'js2', cmd:'capwap ap ' + mac + ' fw-updating', write:0},
5779					callback: function(options, success, response) {			
5780						if(success){
5781							console.log('success');
5782						}
5783					}
5784		    		});    
5785			};
5786		},
5787		icon: Ext.MessageBox.WARNING
5788	});
5789}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.