]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/main/menu.js
Merge remote-tracking branch 'eg-working/user/senator/tpac-bookbag-viewer'
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / main / menu.js
1 dump('entering main/menu.js\n');
2 // vim:noet:sw=4:ts=4:
3
4 var offlineStrings;
5
6 if (typeof main == 'undefined') main = {};
7 main.menu = function () {
8
9     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
10     offlineStrings = document.getElementById('offlineStrings');
11     JSAN.use('util.error'); this.error = new util.error();
12     JSAN.use('util.window'); this.window = new util.window();
13     JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
14
15     this.w = window;
16     var x = document.getElementById('network_progress');
17     x.setAttribute('count','0');
18     x.addEventListener(
19         'click',
20         function() {
21             if ( window.confirm(offlineStrings.getString('menu.reset_network_stats')) ) {
22                 var y = document.getElementById('network_progress_rows');
23                 while(y.firstChild) { y.removeChild( y.lastChild ); }
24                 x.setAttribute('mode','determined');
25                 x.setAttribute('count','0');
26             }
27         },
28         false
29     );
30 }
31
32 main.menu.prototype = {
33
34     'id_incr' : 0,
35
36     'toolbar' : 'none',
37     'toolbar_size' : 'large',
38     'toolbar_mode' : 'both',
39     'toolbar_labelpos' : 'side',
40
41     'url_prefix' : function(url,secure) {
42         // if host unspecified URL with leading /, prefix the remote hostname
43         if (url.match(/^\//)) url = urls.remote + url;
44         // if it starts with http:// and we want secure, convert to https://
45         if (secure && url.match(/^http:\/\//)) {
46             url = url.replace(/^http:\/\//, 'https://');
47         }
48         // if it doesn't start with a known protocol, add http(s)://
49         if (! url.match(/^(http|https|chrome):\/\//) && ! url.match(/^data:/) ) {
50             url = secure
51                 ? 'https://' + url
52                 : 'http://' + url;
53         }
54         dump('url_prefix = ' + url + '\n');
55         return url;
56     },
57
58     'init' : function( params ) {
59
60         var obj = this;
61
62         urls.remote = params['server'];
63
64         xulG.get_barcode = this.get_barcode;
65
66         // Pull in local customizations
67         var r = new XMLHttpRequest();
68         r.open("GET", obj.url_prefix('/xul/server/skin/custom.js'), false);
69         r.send(null);
70         if (r.status == 200) {
71             dump('Evaluating /xul/server/skin/custom.js\n');
72             eval( r.responseText );
73         }
74
75         // Try workstation pref for button bar
76         var button_bar = xulG.pref.getCharPref('open-ils.menu.toolbar');
77
78         if (!button_bar) // No workstation pref? Try org unit pref.
79             button_bar = String( obj.data.hash.aous['ui.general.button_bar'] );
80
81         if (button_bar) {
82             var x = document.getElementById('toolbar_' + button_bar);
83             if (x) x.setAttribute('hidden','false');
84             this.toolbar = button_bar;
85         }
86
87         // Check for alternate Size pref
88         var toolbar_size = xulG.pref.getCharPref('open-ils.menu.toolbar.iconsize');
89         if(toolbar_size) this.toolbar_size = toolbar_size;
90         // Check for alternate Mode pref
91         var toolbar_mode = xulG.pref.getCharPref('open-ils.menu.toolbar.mode');
92         if(toolbar_mode) this.toolbar_mode = toolbar_mode;
93         // Check for alternate Label Position pref
94         var toolbar_labelpos = xulG.pref.getBoolPref('open-ils.menu.toolbar.labelbelow');
95         if(toolbar_labelpos) this.toolbar_labelpos = toolbar_labelpos;
96
97         if(button_bar || toolbar_size || toolbar_mode || toolbar_labelpos) {
98             var toolbox = document.getElementById('main_toolbox');
99             var toolbars = toolbox.getElementsByTagName('toolbar');
100             for(var i = 0; i < toolbars.length; i++) {
101                 if(toolbars[i].id == 'toolbar_' + button_bar)
102                     toolbars[i].setAttribute('hidden', 'false');
103                 else
104                     toolbars[i].setAttribute('hidden', 'true');
105                 if(toolbar_mode) toolbars[i].setAttribute('mode', toolbar_mode);
106                 if(toolbar_size) toolbars[i].setAttribute('iconsize', toolbar_size);
107                 if(toolbar_labelpos) addCSSClass(toolbars[i], 'labelbelow');
108             }
109         }
110
111         if(button_bar) {
112             var x = document.getElementById('main.menu.admin.client.toolbars.current.popup');
113             if (x) {
114                 var selectitems = x.getElementsByAttribute('value',button_bar);
115                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
116             }
117         }
118
119         if(toolbar_size) {
120             var x = document.getElementById('main.menu.admin.client.toolbars.size.popup');
121             if (x) {
122                 var selectitems = x.getElementsByAttribute('value',toolbar_size);
123                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
124             }
125         }
126
127         if(toolbar_mode) {
128             var x = document.getElementById('main.menu.admin.client.toolbars.mode.popup');
129             if (x) {
130                 var selectitems = x.getElementsByAttribute('value',toolbar_mode);
131                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
132             }
133         }
134
135         if(toolbar_labelpos) {
136             var x = document.getElementById('main.menu.admin.client.toolbars.label_position.popup');
137             if (x) {
138                 var selectitems = x.getElementsByAttribute('value',"under");
139                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
140             }
141         }
142
143         var cl_first = xulG.pref.getBoolPref('oils.copy_editor.copy_location_name_first');
144         var menuitems = document.getElementsByAttribute('command','cmd_copy_editor_copy_location_first_toggle');
145         for(var i = 0; i < menuitems.length; i++)
146             menuitems[i].setAttribute('checked', cl_first ? 'true' : 'false');
147
148         xulG.pref.addObserver('', this, false);
149         window.addEventListener("unload", function(e) { this.stop_observing(); }, false);
150
151         var network_meter = String( obj.data.hash.aous['ui.network.progress_meter'] ) == 'true';
152         if (! network_meter) {
153             var x = document.getElementById('network_progress');
154             if (x) x.setAttribute('hidden','true');
155             var y = document.getElementById('page_progress');
156             if (y) y.setAttribute('hidden','true');
157         }
158
159         var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
160                     getService(Components.interfaces.nsIWindowMediator);
161         var mainwin = wm.getMostRecentWindow('eg_main');
162         mainwin.get_menu_perms(document);
163         var hotkeysets = mainwin.load_hotkey_sets();
164
165         var popupmenu = document.getElementById('main.menu.admin.client.hotkeys.current.popup');
166         
167         for(var i = 0; i < hotkeysets.length; i++) {
168             var keysetname = hotkeysets[i];
169             var menuitem = document.createElement('menuitem');
170             if(offlineStrings.testString('hotkey.' + keysetname))
171                 menuitem.setAttribute('label',offlineStrings.getString('hotkey.' + keysetname));
172             else
173                 menuitem.setAttribute('label',keysetname);
174             menuitem.setAttribute('value',keysetname);
175             menuitem.setAttribute('type','radio');
176             menuitem.setAttribute('name','menu_hotkey_current');
177             menuitem.setAttribute('command','cmd_hotkeys_set');
178             popupmenu.appendChild(menuitem);
179         }
180
181         JSAN.use('util.network');
182         var network = new util.network();
183         network.set_user_status();
184
185         this.set_menu_hotkeys();
186
187         function open_conify_page(path, labelKey, event) {
188
189             // tab label
190             labelKey = labelKey || 'menu.cmd_open_conify.tab';
191             label = offlineStrings.getString(labelKey);
192
193             // URL
194             var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.CONIFY) + '/' + path + '.html');
195
196             obj.command_tab(
197                 event,
198                 loc, 
199                 {'tab_name' : label, 'browser' : false }, 
200                 {'no_xulG' : false, 'show_print_button' : false, show_nav_buttons:true} 
201             );
202         }
203
204         function open_admin_page(path, labelKey, addSes, event) {
205
206             // tab label
207             labelKey = labelKey || 'menu.cmd_open_conify.tab';
208             label = offlineStrings.getString(labelKey);
209
210             // URL
211             var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.XUL_LOCAL_ADMIN_BASE) + '/' + path);
212             if(addSes) loc += window.escape('?ses=' + ses());
213
214             obj.command_tab( 
215                 event,
216                 loc, 
217                 {'tab_name' : label, 'browser' : false }, 
218                 {'no_xulG' : false, 'show_print_button' : true, 'show_nav_buttons' : true } 
219             );
220         }
221
222
223         function open_eg_web_page(path, labelKey, event) {
224             
225             // tab label
226             labelKey = labelKey || 'menu.cmd_open_conify.tab';
227             var label = offlineStrings.getString(labelKey);
228
229             // URL
230             var loc = urls.XUL_BROWSER + '?url=' + window.escape(obj.url_prefix(urls.EG_WEB_BASE) + '/' + path);
231
232             obj.command_tab(
233                 event,
234                 loc, 
235                 {tab_name : label, browser : false }, 
236                 {no_xulG : false, show_print_button : true, show_nav_buttons : true }
237             );
238         }
239
240         var cmd_map = {
241             'cmd_broken' : [
242                 ['oncommand'],
243                 function() { alert(offlineStrings.getString('common.unimplemented')); }
244             ],
245
246             /* File Menu */
247             'cmd_close_window' : [ 
248                 ['oncommand'], 
249                 function() {
250                     JSAN.use('util.widgets');
251                     util.widgets.dispatch('close',window);
252                 }
253             ],
254             'cmd_new_window' : [
255                 ['oncommand'],
256                 function() {
257                     var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
258                         getService(Components.interfaces.nsIWindowMediator);
259                     wm.getMostRecentWindow('eg_main').new_tabs(Array('new'));
260                 }
261             ],
262             'cmd_new_tab' : [
263                 ['oncommand'],
264                 function() {
265                     if (obj.new_tab(null,{'focus':true},null) == false)
266                     {
267                         if(window.confirm(offlineStrings.getString('menu.new_tab.max_tab_dialog')))
268                         {
269                             var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
270                                 getService(Components.interfaces.nsIWindowMediator);
271                             wm.getMostRecentWindow('eg_main').new_tabs(Array('tab'));
272                         }
273                     }
274                 }
275             ],
276             'cmd_portal' : [
277                 ['oncommand'],
278                 function() {
279                     obj.set_tab();
280                 }
281             ],
282             'cmd_close_tab' : [
283                 ['oncommand'],
284                 function(event) {
285                     var myEvent = event;
286                     var closeAll = false;
287                     if(event && event.sourceEvent) myEvent = event.sourceEvent;
288                     // Note: The last event is not supposed to be myEvent in this if.
289                     if(myEvent && myEvent.explicitOriginalTarget.nodeName.match(/toolbarbutton/) && myEvent.explicitOriginalTarget.command == event.originalTarget.id) {
290                         var value = xulG.pref.getIntPref('ui.key.accelKey');
291                         switch(value) {
292                             case 17:
293                                 closeAll = myEvent.ctrlKey;
294                                 break;
295                             case 18:
296                                 closeAll = myEvent.altKey;
297                                 break;
298                             case 224:
299                                 closeAll = myEvent.metaKey;
300                                 break;
301                         }
302                     }
303                     if(closeAll) {
304                         obj.close_all_tabs();
305                     } else {
306                         obj.close_tab();
307                     }
308                 }
309             ],
310             'cmd_close_all_tabs' : [
311                 ['oncommand'],
312                 function() { obj.close_all_tabs(); }
313             ],
314
315             /* Edit Menu */
316             'cmd_edit_copy_buckets' : [
317                 ['oncommand'],
318                 function(event) {
319                     obj.data.stash_retrieve();
320                     obj.command_tab(event,obj.url_prefix(urls.XUL_COPY_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_copy_buckets.tab')},{});
321                 }
322             ],
323             'cmd_edit_volume_buckets' : [
324                 ['oncommand'],
325                 function(event) {
326                     obj.data.stash_retrieve();
327                     obj.command_tab(event,obj.url_prefix(urls.XUL_VOLUME_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_volume_buckets.tab')},{});
328                 }
329             ],
330             'cmd_edit_record_buckets' : [
331                 ['oncommand'],
332                 function(event) {
333                     obj.data.stash_retrieve();
334                     obj.command_tab(event,obj.url_prefix(urls.XUL_RECORD_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_record_buckets.tab')},{});
335                 }
336             ],
337             'cmd_edit_user_buckets' : [
338                 ['oncommand'],
339                 function(event) {
340                     obj.data.stash_retrieve();
341                     obj.command_tab(event,obj.url_prefix(urls.XUL_USER_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_user_buckets.tab')},{});
342                 }
343             ],
344
345
346             'cmd_replace_barcode' : [
347                 ['oncommand'],
348                 function() {
349                     try {
350                         JSAN.use('util.network');
351                         var network = new util.network();
352
353                         var old_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.label'));
354                         if (!old_bc) return;
355     
356                         var copy;
357                         try {
358                             copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
359                             if (typeof copy.ilsevent != 'undefined') throw(copy); 
360                             if (!copy) throw(copy);
361                         } catch(E) {
362                             alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.retrieval.error', [old_bc]) + '\n');
363                             return;
364                         }
365     
366                         // Why did I want to do this twice?  Because this copy is more fleshed?
367                         try {
368                             copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
369                             if (typeof copy.ilsevent != 'undefined') throw(copy);
370                             if (!copy) throw(copy);
371                         } catch(E) {
372                             try { alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.retrieval.error', [old_bc]) + '\n' + (typeof E.ilsevent == 'undefined' ? '' : E.textcode + ' : ' + E.desc)); } catch(F) { alert(E + '\n' + F); }
373                             return;
374                         }
375     
376                         var new_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.replacement.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.replacement.label'));
377                         new_bc = String( new_bc ).replace(/\s/g,'');
378                         /* Casting a possibly null input value to a String turns it into "null" */
379                         if (!new_bc || new_bc == 'null') {
380                             alert(offlineStrings.getString('menu.cmd_replace_barcode.blank.error'));
381                             return;
382                         }
383     
384                         var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ new_bc ]);
385                         if (typeof test.ilsevent == 'undefined') {
386                             alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.duplicate.error', [new_bc]));
387                             return;
388                         } else {
389                             if (test.ilsevent != 1502 /* ASSET_COPY_NOT_FOUND */) {
390                                 obj.error.standard_unexpected_error_alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.testing.error', [new_bc]),test);
391                                 return;
392                             }    
393                         }
394
395                         copy.barcode(new_bc); copy.ischanged('1');
396                         var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
397                         if (typeof r.ilsevent != 'undefined') { 
398                             if (r.ilsevent != 0) {
399                                 if (r.ilsevent == 5000 /* PERM_FAILURE */) {
400                                     alert(offlineStrings.getString('menu.cmd_replace_barcode.permission.error'));
401                                 } else {
402                                     obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.error'),r);
403                                 }
404                             }
405                         }
406                     } catch(E) {
407                         obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.failure'),copy);
408                     }
409                 }
410             ],
411
412             /* Search Menu */
413             'cmd_patron_search' : [
414                 ['oncommand'],
415                 function(event) {
416                     obj.set_patron_tab({},{},event);
417                 }
418             ],
419             'cmd_search_usr_id' : [
420                 ['oncommand'],
421                 function(event) {
422                     var usr_id = prompt(
423                         offlineStrings.getString('menu.cmd_search_usr_id.tab'),
424                         '',
425                         offlineStrings.getString('menu.cmd_search_usr_id.prompt')
426                     );
427                     if (usr_id != '' && ! isNaN(usr_id)) {
428                         obj.set_patron_tab(
429                             {},
430                             { 'id' : usr_id },
431                             event
432                         );
433                     }
434                 }
435             ],
436             'cmd_search_opac' : [
437                 ['oncommand'],
438                 function(event) {
439                     obj.data.stash_retrieve();
440                     var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
441                     obj.command_tab(event,obj.url_prefix(urls.XUL_OPAC_WRAPPER), {'tab_name':offlineStrings.getString('menu.cmd_search_opac.tab')}, content_params);
442                 }
443             ],
444             'cmd_search_tcn' : [
445                 ['oncommand'],
446                 function(event) {
447                     var tcn = prompt(offlineStrings.getString('menu.cmd_search_tcn.tab'),'',offlineStrings.getString('menu.cmd_search_tcn.prompt'));
448
449                     function spawn_tcn(r,event) {
450                         for (var i = 0; i < r.count; i++) {
451                             var id = r.ids[i];
452                             var opac_url = obj.url_prefix( urls.opac_rdetail ) + id;
453                             obj.data.stash_retrieve();
454                             var content_params = { 
455                                 'session' : ses(), 
456                                 'authtime' : ses('authtime'),
457                                 'opac_url' : opac_url,
458                             };
459                             if (i == 0) {
460                                 obj.command_tab(
461                                     event,
462                                     obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
463                                     {'tab_name':tcn}, 
464                                     content_params
465                                 );
466                             } else {
467                                 obj.new_tab(
468                                     obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
469                                     {'tab_name':tcn}, 
470                                     content_params
471                                 );
472                             }
473                         }
474                     }
475
476                     if (tcn) {
477                         JSAN.use('util.network');
478                         var network = new util.network();
479                         var robj = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn]);
480                         if (robj.count != robj.ids.length) throw('FIXME -- FM_BRE_ID_SEARCH_VIA_TCN = ' + js2JSON(robj));
481                         if (robj.count == 0) {
482                             var robj2 = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn,1]);
483                             if (robj2.count == 0) {
484                                 alert(offlineStrings.getFormattedString('menu.cmd_search_tcn.not_found.error', [tcn]));
485                             } else {
486                                 if ( window.confirm(offlineStrings.getFormattedString('menu.cmd_search_tcn.deleted.error', [tcn])) ) {
487                                     spawn_tcn(robj2,event);
488                                 }
489                             }
490                         } else {
491                             spawn_tcn(robj,event);
492                         }
493                     }
494                 }
495             ],
496             'cmd_search_bib_id' : [
497                 ['oncommand'],
498                 function(event) {
499                     var bib_id = prompt(offlineStrings.getString('menu.cmd_search_bib_id.tab'),'',offlineStrings.getString('menu.cmd_search_bib_id.prompt'));
500                     if (!bib_id) return;
501
502                     var opac_url = obj.url_prefix( urls.opac_rdetail ) + bib_id;
503                     var content_params = { 
504                         'session' : ses(), 
505                         'authtime' : ses('authtime'),
506                         'opac_url' : opac_url,
507                     };
508                     obj.command_tab(
509                         event,
510                         obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
511                         {'tab_name':'#' + bib_id}, 
512                         content_params
513                     );
514                 }
515             ],
516             'cmd_copy_status' : [
517                 ['oncommand'],
518                 function(event) {
519                     obj.data.stash_retrieve();
520                     obj.command_tab(event,obj.url_prefix(urls.XUL_COPY_STATUS),{},{});
521                 }
522             ],
523
524             /* Circulation Menu */
525             'cmd_patron_register' : [
526                 ['oncommand'],
527                 function(event) {
528
529                     function log_registration(p) {
530                         try {
531                             obj.error.work_log(
532                                 document.getElementById('offlineStrings').getFormattedString(
533                                     'staff.circ.work_log_patron_registration.message',
534                                     [
535                                         ses('staff_usrname'),
536                                         p.family_name(),
537                                         p.card().barcode()
538                                     ]
539                                 ), {
540                                     'au_id' : p.id(),
541                                     'au_family_name' : p.family_name(),
542                                     'au_barcode' : p.card().barcode()
543                                 }
544                             );
545                         } catch(E) {
546                             obj.error.sdump('D_ERROR','Error with work_logging in menu.js, cmd_patron_register:' + E);
547                         }
548                     }
549
550                     function spawn_editor(p) {
551                         var url = urls.XUL_PATRON_EDIT;
552                         var param_count = 0;
553                         for (var i in p) {
554                             if (param_count++ == 0) url += '?'; else url += '&';
555                             url += i + '=' + window.escape(p[i]);
556                         }
557                         var loc = obj.url_prefix( urls.XUL_BROWSER ) + '?url=' + window.escape( obj.url_prefix(url) );
558                         obj.new_tab(
559                             loc, 
560                             {}, 
561                             { 
562                                 'show_print_button' : true , 
563                                 'tab_name' : offline.getString('menu.cmd_patron_register.related.tab'),
564                                 'passthru_content_params' : {
565                                     'spawn_search' : function(s) { obj.spawn_search(s); },
566                                     'spawn_editor' : spawn_editor,
567                                     'on_save' : function(p) { log_registration(p); }
568                                 }
569                             }
570                         );
571                     }
572
573                     obj.data.stash_retrieve();
574                     var loc = obj.url_prefix( urls.XUL_BROWSER ) 
575                         + '?url=' + window.escape( obj.url_prefix(urls.XUL_PATRON_EDIT) );
576                     obj.command_tab(
577                         event,
578                         loc, 
579                         {}, 
580                         { 
581                             'show_print_button' : true , 
582                             'tab_name' : offlineStrings.getString('menu.cmd_patron_register.tab'),
583                             'passthru_content_params' : {
584                                 'ses' : ses(),
585                                 'spawn_search' : function(s) { obj.spawn_search(s); },
586                                 'spawn_editor' : spawn_editor,
587                                 'on_save' : function(p) { log_registration(p); }
588                             }
589                         }
590                     );
591                 }
592             ],
593             'cmd_staged_patrons' : [
594                 ['oncommand'],
595                 function(event) {
596                     obj.data.stash_retrieve();
597                     obj.command_tab(event,obj.url_prefix(urls.XUL_STAGED_PATRONS),{'tab_name':offlineStrings.getString('menu.circulation.staged_patrons.tab')},{});
598                 }
599             ],
600             'cmd_circ_checkin' : [
601                 ['oncommand'],
602                 function(event) { 
603                     obj.data.stash_retrieve();
604                     obj.command_tab(event,obj.url_prefix(urls.XUL_CHECKIN),{},{});
605                 }
606             ],
607             'cmd_circ_renew' : [
608                 ['oncommand'],
609                 function(event) { 
610                     obj.data.stash_retrieve();
611                     obj.command_tab(event,obj.url_prefix(urls.XUL_RENEW),{},{});
612                 }
613             ],
614             'cmd_circ_checkout' : [
615                 ['oncommand'],
616                 function(event) { 
617                     obj.data.stash_retrieve();
618                     obj.command_tab(event,obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY),{},{});
619                 }
620             ],
621             'cmd_circ_hold_capture' : [
622                 ['oncommand'],
623                 function(event) { 
624                     obj.data.stash_retrieve();
625                     obj.command_tab(event,obj.url_prefix(urls.XUL_CHECKIN)+'?hold_capture=1',{},{});
626                 }
627             ],
628             'cmd_browse_holds' : [
629                 ['oncommand'],
630                 function(event) { 
631                     obj.data.stash_retrieve();
632                     obj.command_tab(event,obj.url_prefix(urls.XUL_HOLDS_BROWSER),{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds.tab') },{});
633                 }
634             ],
635             'cmd_browse_holds_shelf' : [
636                 ['oncommand'],
637                 function(event) { 
638                     obj.data.stash_retrieve();
639                     obj.command_tab(event,obj.url_prefix(urls.XUL_HOLDS_BROWSER)+'?shelf=1',{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds_shelf.tab') },{});
640                 }
641             ],
642             'cmd_circ_hold_pull_list' : [
643                 ['oncommand'],
644                 function(event) { 
645                     obj.data.stash_retrieve();
646                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
647                         obj.url_prefix(urls.XUL_HOLD_PULL_LIST)
648                     );
649                     obj.command_tab(event, loc, {'tab_name' : offlineStrings.getString('menu.cmd_browse_hold_pull_list.tab')} );
650                 }
651             ],
652
653             'cmd_in_house_use' : [
654                 ['oncommand'],
655                 function(event) { 
656                     obj.data.stash_retrieve();
657                     obj.command_tab(event,obj.url_prefix(urls.XUL_IN_HOUSE_USE),{},{});
658                 }
659             ],
660
661             'cmd_scan_item_as_missing_pieces' : [
662                 ['oncommand'],
663                 function() { 
664                     xulG.window.open(obj.url_prefix(urls.XUL_SCAN_ITEM_AS_MISSING_PIECES),'scan_missing_pieces','chrome'); 
665                 }
666             ],
667
668             'cmd_standalone' : [
669                 ['oncommand'],
670                 function() { 
671                     //obj.set_tab(obj.url_prefix(urls.XUL_STANDALONE),{},{});
672                     window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
673                 }
674             ],
675
676             'cmd_local_admin' : [
677                 ['oncommand'],
678                 function(event) { 
679                     //obj.set_tab(obj.url_prefix(urls.XUL_LOCAL_ADMIN)+'?ses='+window.escape(ses())+'&session='+window.escape(ses()),{},{});
680                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
681                         obj.url_prefix( urls.XUL_LOCAL_ADMIN+'?ses='+window.escape(ses())+'&session='+window.escape(ses()) )
682                     );
683                     obj.command_tab(
684                         event,
685                         loc, 
686                         {'tab_name' : offlineStrings.getString('menu.cmd_local_admin.tab'), 'browser' : false }, 
687                         { 'no_xulG' : false, 'show_nav_buttons' : true, 'show_print_button' : true } 
688                     );
689
690                 }
691             ],
692
693             'cmd_toggle_meters' : [
694                 ['oncommand'],
695                 function() {
696                     var x = document.getElementById('network_progress');
697                     if (x) x.hidden = ! x.hidden;
698                     var y = document.getElementById('page_progress');
699                     if (y) y.hidden = ! y.hidden;
700                 }
701             ],
702
703             'cmd_local_admin_reports' : [
704                 ['oncommand'],
705                 function(event) { 
706                     var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.XUL_REPORTS) + '?ses=' + ses());
707                     obj.command_tab(
708                         event,
709                         loc, 
710                         {'tab_name' : offlineStrings.getString('menu.cmd_local_admin_reports.tab'), 'browser' : false }, 
711                         {'no_xulG' : false, 'show_print_button' : false, show_nav_buttons : true } 
712                     );
713                 }
714             ],
715             'cmd_open_vandelay' : [
716                 ['oncommand'],
717                 function(event) { open_eg_web_page('vandelay/vandelay', null, event); }
718             ],
719             'cmd_local_admin_transit_list' : [
720                 ['oncommand'],
721                 function(event) { open_admin_page('transit_list.xul', 'menu.cmd_local_admin_transit_list.tab', false, event); }
722             ],
723             'cmd_local_admin_age_overdue_circulations_to_lost' : [
724                 ['oncommand'],
725                 function(event) { open_admin_page('circ_age_to_lost.xul', 'menu.cmd_local_admin_age_overdue_circulations_to_lost.tab', true, event); }
726             ],
727             'cmd_local_admin_cash_reports' : [
728                 ['oncommand'],
729                 function(event) { open_admin_page('cash_reports.xhtml', 'menu.cmd_local_admin_cash_reports.tab', true, event); }
730             ],
731             'cmd_local_admin_fonts_and_sounds' : [
732                 ['oncommand'],
733                 function(event) { open_admin_page('font_settings.xul', 'menu.cmd_local_admin_fonts_and_sounds.tab', false, event); }
734             ],
735             'cmd_local_admin_printer' : [
736                 ['oncommand'],
737                 function(event) { open_admin_page('printer_settings.html', 'menu.cmd_local_admin_printer.tab', true, event); }
738             ],
739             'cmd_local_admin_do_not_auto_attempt_print_setting' : [
740                 ['oncommand'],
741                 function(event) { 
742                     obj.command_tab(event,obj.url_prefix(urls.XUL_DO_NOT_AUTO_ATTEMPT_PRINT_SETTING),{'tab_name':offlineStrings.getString('menu.cmd_local_admin_do_not_auto_attempt_print_setting.tab')},{});
743                 }
744             ],
745             'cmd_local_admin_closed_dates' : [
746                 ['oncommand'],
747                 function(event) { open_admin_page('closed_dates.xhtml', 'menu.cmd_local_admin_closed_dates.tab', true, event); }
748             ],
749             'cmd_local_admin_copy_locations' : [
750                 ['oncommand'],
751                 function(event) { open_admin_page('copy_locations.xhtml', 'menu.cmd_local_admin_copy_locations.tab', true, event); }
752             ],
753             'cmd_local_admin_lib_settings' : [
754                 ['oncommand'],
755                 function(event) { open_admin_page('org_unit_settings.xhtml', 'menu.cmd_local_admin_lib_settings.tab', true, event); }
756             ],
757             'cmd_local_admin_non_cat_types' : [
758                 ['oncommand'],
759                 function(event) { open_admin_page('non_cat_types.xhtml', 'menu.cmd_local_admin_non_cat_types.tab', true, event); }
760             ],
761             'cmd_local_admin_stat_cats' : [
762                 ['oncommand'],
763                 function(event) { open_admin_page('stat_cat_editor.xhtml', 'menu.cmd_local_admin_stat_cats.tab', true, event); }
764             ],
765             'cmd_local_admin_standing_penalty' : [
766                 ['oncommand'],
767                 function(event) { open_eg_web_page('conify/global/config/standing_penalty', null, event); }
768             ],
769             'cmd_local_admin_grp_penalty_threshold' : [
770                 ['oncommand'],
771                 function(event) { open_eg_web_page('conify/global/permission/grp_penalty_threshold', null, event); }
772             ],
773             'cmd_server_admin_config_rule_circ_duration' : [
774                 ['oncommand'],
775                 function(event) { open_eg_web_page('conify/global/config/rule_circ_duration', null, event); }
776             ],
777             'cmd_server_admin_config_hard_due_date' : [
778                 ['oncommand'],
779                 function(event) { open_eg_web_page('conify/global/config/hard_due_date', null, event); }
780             ],
781             'cmd_server_admin_config_rule_recurring_fine' : [
782                 ['oncommand'],
783                 function(event) { open_eg_web_page('conify/global/config/rule_recurring_fine', null, event); }
784             ],
785             'cmd_server_admin_config_rule_max_fine' : [
786                 ['oncommand'],
787                 function(event) { open_eg_web_page('conify/global/config/rule_max_fine', null, event); }
788             ],
789             'cmd_server_admin_config_rule_age_hold_protect' : [
790                 ['oncommand'],
791                 function(event) { open_eg_web_page('conify/global/config/rule_age_hold_protect', null, event); }
792             ],
793             'cmd_server_admin_config_circ_weights' : [
794                 ['oncommand'],
795                 function(event) { open_eg_web_page('conify/global/config/circ_matrix_weights', null, event); }
796             ],
797             'cmd_server_admin_config_hold_weights' : [
798                 ['oncommand'],
799                 function(event) { open_eg_web_page('conify/global/config/hold_matrix_weights', null, event); }
800             ],
801             'cmd_server_admin_config_weight_assoc' : [
802                 ['oncommand'],
803                 function(event) { open_eg_web_page('conify/global/config/weight_assoc', null, event); }
804             ],
805             'cmd_server_admin_config_actor_sip_fields' : [
806                 ['oncommand'],
807                 function(event) { open_eg_web_page('conify/global/config/actor_sip_fields', null, event); }
808             ],
809             'cmd_server_admin_config_asset_sip_fields' : [
810                 ['oncommand'],
811                 function(event) { open_eg_web_page('conify/global/config/asset_sip_fields', null, event); }
812             ],
813             'cmd_local_admin_external_text_editor' : [
814                 ['oncommand'],
815                 function() {
816                     var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
817                     var key = 'oils.text_editor.external.cmd';
818                     var has_key = prefs.prefHasUserValue(key);
819                     var value = has_key ? prefs.getCharPref(key) : 'C:\\Windows\\notepad.exe %letter.txt%';
820                     var cmd = window.prompt(
821                         document.getElementById('offlineStrings').getString('text_editor.prompt_for_external_cmd'),
822                         value
823                     );
824                     if (!cmd) { return; }
825                     prefs.setCharPref(key,cmd);
826                 }
827             ],
828             'cmd_local_admin_idl_field_doc' : [
829                 ['oncommand'],
830                 function(event) { open_eg_web_page('conify/global/config/idl_field_doc', null, event); }
831             ],
832             'cmd_local_admin_action_trigger' : [
833                 ['oncommand'],
834                 function(event) { open_eg_web_page('conify/global/action_trigger/event_definition', null, event); }
835             ],
836             'cmd_local_admin_survey' : [
837                 ['oncommand'],
838                 function(event) { open_eg_web_page('conify/global/action/survey', null, event); }
839             ],
840             'cmd_local_admin_barcode_completion' : [
841                 ['oncommand'],
842                 function() { open_eg_web_page('conify/global/config/barcode_completion', 
843                     'menu.local_admin.barcode_completion.tab'); }
844             ],
845             'cmd_local_admin_circ_matrix_matchpoint' : [
846                 ['oncommand'],
847                 function() { open_eg_web_page('conify/global/config/circ_matrix_matchpoint', 
848                     'menu.local_admin.circ_matrix_matchpoint.tab'); }
849             ],
850             'cmd_local_admin_hold_matrix_matchpoint' : [
851                 ['oncommand'],
852                 function() { open_eg_web_page('conify/global/config/hold_matrix_matchpoint', 
853                     'menu.local_admin.hold_matrix_matchpoint.tab'); }
854             ],
855             'cmd_local_admin_copy_location_order' : [
856                 ['oncommand'],
857                 function(event) { open_eg_web_page('conify/global/asset/copy_location_order', null, event); }
858             ],
859             'cmd_local_admin_work_log' : [
860                 ['oncommand'],
861                 function(event) { 
862                     obj.command_tab(
863                         event,
864                         urls.XUL_WORK_LOG,
865                         { 'tab_name' : offlineStrings.getString('menu.local_admin.work_log.tab') },
866                         {}
867                     );
868                 }
869             ],
870             "cmd_local_admin_copy_template": [
871                 ["oncommand"],
872                 function() {
873                     open_eg_web_page("conify/global/asset/copy_template");
874                 }
875             ],
876             'cmd_local_admin_patrons_due_refunds' : [
877                 ['oncommand'],
878                 function(event) {
879                     obj.command_tab(
880                         event,
881                         obj.url_prefix(urls.XUL_PATRONS_DUE_REFUNDS),
882                         { 'tab_name' : offlineStrings.getString('menu.local_admin.patrons_due_refunds.tab') },
883                         {}
884                     );
885                 }
886             ],
887             'cmd_server_admin_org_type' : [
888                 ['oncommand'],
889                 function(event) { open_conify_page('actor/org_unit_type', null, event); }
890             ],
891             'cmd_server_admin_org_unit' : [
892                 ['oncommand'],
893                 function(event) { open_conify_page('actor/org_unit', null, event); }
894             ],
895             'cmd_server_admin_grp_tree' : [
896                 ['oncommand'],
897                 function(event) { open_conify_page('permission/grp_tree', null, event); }
898             ],
899             'cmd_server_admin_perm_list' : [
900                 ['oncommand'],
901                 function(event) { open_conify_page('permission/perm_list', null, event); }
902             ],
903             'cmd_server_admin_copy_status' : [
904                 ['oncommand'],
905                 function(event) { open_conify_page('config/copy_status', null, event); }
906             ],
907             'cmd_server_admin_marc_code' : [
908                 ['oncommand'],
909                 function(event) { open_eg_web_page('conify/global/config/record_attr_definition', null, event); }
910             ],
911             'cmd_server_admin_coded_value_map' : [
912                 ['oncommand'],
913                 function(event) { open_eg_web_page('conify/global/config/coded_value_map', null, event); }
914             ],
915             'cmd_server_admin_metabib_field' : [
916                 ['oncommand'],
917                 function(event) { open_eg_web_page('conify/global/config/metabib_field', null, event); }
918             ],
919             'cmd_server_admin_acn_prefix' : [
920                 ['oncommand'],
921                 function(event) { open_eg_web_page('conify/global/config/acn_prefix', null, event); }
922             ],
923             'cmd_server_admin_acn_suffix' : [
924                 ['oncommand'],
925                 function(event) { open_eg_web_page('conify/global/config/acn_suffix', null, event); }
926             ],
927             'cmd_server_admin_billing_type' : [
928                 ['oncommand'],
929                 function(event) { open_eg_web_page('conify/global/config/billing_type', null, event); }
930             ],
931             'cmd_server_admin_acq_invoice_item_type' : [
932                 ['oncommand'],
933                 function(event) { open_eg_web_page('conify/global/acq/invoice_item_type', null, event); }
934             ],
935             'cmd_server_admin_acq_invoice_payment_method' : [
936                 ['oncommand'],
937                 function(event) { open_eg_web_page('conify/global/acq/invoice_payment_method', null, event); }
938             ],
939             'cmd_server_admin_acq_lineitem_alert' : [
940                 ['oncommand'],
941                 function(event) { open_eg_web_page('conify/global/acq/lineitem_alert', null, event); }
942             ],
943             'cmd_server_admin_acq_lineitem_marc_attr_def' : [
944                 ['oncommand'],
945                 function(event) { open_eg_web_page('conify/global/acq/lineitem_marc_attr_def', null, event); }
946             ],
947             'cmd_server_admin_acq_fund_tag' : [
948                 ['oncommand'],
949                 function(event) { open_eg_web_page('conify/global/acq/fund_tag', null, event); }
950             ],
951             'cmd_server_admin_acq_cancel_reason' : [
952                 ['oncommand'],
953                 function(event) { open_eg_web_page('conify/global/acq/cancel_reason', null, event); }
954             ],
955             'cmd_server_admin_acq_claim_type' : [
956                 ['oncommand'],
957                 function(event) { open_eg_web_page('conify/global/acq/claim_type', null, event); }
958             ],
959             'cmd_server_admin_acq_claim_event_type' : [
960                 ['oncommand'],
961                 function(event) { open_eg_web_page('conify/global/acq/claim_event_type', null, event); }
962             ],
963             'cmd_server_admin_acq_claim_policy' : [
964                 ['oncommand'],
965                 function(event) { open_eg_web_page('conify/global/acq/claim_policy', null, event); }
966             ],
967             'cmd_server_admin_acq_claim_policy_action' : [
968                 ['oncommand'],
969                 function(event) { open_eg_web_page('conify/global/acq/claim_policy_action', null, event); }
970             ],
971             'cmd_server_admin_acq_fund' : [
972                 ['oncommand'],
973                 function(event) { open_eg_web_page('acq/fund/list', null, event); }
974             ],
975             'cmd_server_admin_acq_funding_source' : [
976                 ['oncommand'],
977                 function(event) { open_eg_web_page('acq/funding_source/list', null, event); }
978             ],
979             'cmd_server_admin_acq_provider' : [
980                 ['oncommand'],
981                 function(event) { open_eg_web_page('conify/global/acq/provider', null, event); }
982             ],
983             'cmd_server_admin_acq_edi_account' : [
984                 ['oncommand'],
985                 function(event) { open_eg_web_page('conify/global/acq/edi_account', null, event); }
986             ],
987             'cmd_server_admin_acq_edi_message' : [
988                 ['oncommand'],
989                 function(event) { open_eg_web_page('acq/po/edi_messages', null, event); }
990             ],
991             'cmd_server_admin_acq_currency_type' : [
992                 ['oncommand'],
993                 function(event) { open_eg_web_page('acq/currency_type/list', null, event); }
994             ],
995             'cmd_server_admin_acq_exchange_rate' : [
996                 ['oncommand'],
997                 function(event) { open_eg_web_page('conify/global/acq/exchange_rate', null, event); }
998             ],
999             'cmd_server_admin_acq_distrib_formula' : [
1000                 ['oncommand'],
1001                 function(event) { open_eg_web_page('conify/global/acq/distribution_formula', null, event); }
1002             ],
1003             'cmd_server_admin_sms_carrier' : [
1004                 ['oncommand'],
1005                 function(event) { open_eg_web_page('conify/global/config/sms_carrier', null, event); }
1006             ],
1007             'cmd_server_admin_z39_source' : [
1008                 ['oncommand'],
1009                 function(event) { open_eg_web_page('conify/global/config/z3950_source', null, event); }
1010             ],
1011             'cmd_server_admin_circ_mod' : [
1012                 ['oncommand'],
1013                 function(event) { open_eg_web_page('conify/global/config/circ_modifier', null, event); }
1014             ],
1015             'cmd_server_admin_global_flag' : [
1016                 ['oncommand'],
1017                 function(event) { open_eg_web_page('conify/global/config/global_flag', null, event); }
1018             ],
1019             'cmd_server_admin_org_unit_setting_type' : [
1020                 ['oncommand'],
1021                 function(event) { open_eg_web_page('conify/global/config/org_unit_setting_type', null, event); }
1022             ],
1023             'cmd_server_admin_import_match_set' : [
1024                 ['oncommand'],
1025                 function(event) { open_eg_web_page('conify/global/vandelay/match_set', null, event); }
1026             ],
1027             'cmd_server_admin_usr_setting_type' : [
1028                 ['oncommand'],
1029                 function(event) { open_eg_web_page('conify/global/config/usr_setting_type', null, event); }
1030             ],
1031             'cmd_server_admin_authority_control_set': [
1032                 ['oncommand'],
1033                 function(event) { open_eg_web_page('conify/global/cat/authority/control_set', null, event); }
1034             ],
1035             'cmd_server_admin_authority_browse_axis': [
1036                 ['oncommand'],
1037                 function(event) { open_eg_web_page('conify/global/cat/authority/browse_axis', null, event); }
1038             ],
1039             'cmd_server_admin_authority_thesaurus': [
1040                 ['oncommand'],
1041                 function(event) { open_eg_web_page('conify/global/cat/authority/thesaurus', null, event); }
1042             ],
1043             'cmd_server_admin_booking_resource': [
1044                 ['oncommand'],
1045                 function(event) { open_eg_web_page('conify/global/booking/resource', null, event); }
1046             ],
1047             'cmd_server_admin_booking_resource_type': [
1048                 ['oncommand'],
1049                 function(event) { open_eg_web_page('conify/global/booking/resource_type', null, event); }
1050             ],
1051             'cmd_server_admin_booking_resource_attr': [
1052                 ['oncommand'],
1053                 function(event) { open_eg_web_page('conify/global/booking/resource_attr', null, event); }
1054             ],
1055             'cmd_server_admin_booking_resource_attr_value': [
1056                 ['oncommand'],
1057                 function(event) { open_eg_web_page('conify/global/booking/resource_attr_value', null, event); }
1058             ],
1059             'cmd_server_admin_booking_resource_attr_map': [
1060                 ['oncommand'],
1061                 function(event) { open_eg_web_page('conify/global/booking/resource_attr_map', null, event); }
1062             ],
1063             'cmd_local_admin_address_alert' : [
1064                 ['oncommand'],
1065                 function(event) { open_eg_web_page('conify/global/actor/address_alert', null, event); }
1066             ],
1067             'cmd_acq_create_invoice' : [
1068                 ['oncommand'],
1069                 function(event) { open_eg_web_page('acq/invoice/view?create=1', 'menu.cmd_acq_create_invoice.tab', event); }
1070             ],
1071             'cmd_acq_view_my_pl' : [
1072                 ['oncommand'],
1073                 function(event) { open_eg_web_page('acq/search/unified?ca=pl', 'menu.cmd_acq_unified_search.tab', event); }
1074             ],
1075             'cmd_acq_view_local_po' : [
1076                 ['oncommand'],
1077                 function(event) { open_eg_web_page('acq/search/unified?ca=po', 'menu.cmd_acq_unified_search.tab', event); }
1078             ],
1079             'cmd_acq_create_po' : [
1080                 ['oncommand'],
1081                 function(event) { open_eg_web_page('acq/po/create', 'menu.cmd_acq_po.tab', event); }
1082             ],
1083             'cmd_acq_view_local_inv' : [
1084                 ['oncommand'],
1085                 function(event) { open_eg_web_page('acq/search/unified?ca=inv', 'menu.cmd_acq_unified_search.tab', event); }
1086             ],
1087             'cmd_acq_user_requests' : [
1088                 ['oncommand'],
1089                 function(event) { open_eg_web_page('acq/picklist/user_request', 'menu.cmd_acq_user_requests.tab', event); }
1090             ],
1091             'cmd_acq_upload' : [
1092                 ['oncommand'],
1093                 function(event) { open_eg_web_page('acq/picklist/upload', 'menu.cmd_acq_upload.tab', event); }
1094             ],
1095             'cmd_acq_bib_search' : [
1096                 ['oncommand'],
1097                 function(event) { open_eg_web_page('acq/picklist/bib_search', 'menu.cmd_acq_bib_search.tab', event); }
1098             ],
1099             'cmd_acq_unified_search' : [
1100                 ['oncommand'],
1101                 function(event) { open_eg_web_page('acq/search/unified', 'menu.cmd_acq_unified_search.tab', event); }
1102             ],
1103             'cmd_acq_from_bib' : [
1104                 ['oncommand'],
1105                 function(event) { open_eg_web_page('acq/picklist/from_bib', 'menu.cmd_acq_from_bib.tab', event); }
1106             ],
1107             'cmd_acq_new_brief_record' : [
1108                 ['oncommand'],
1109                 function(event) { open_eg_web_page('acq/picklist/brief_record', 'menu.cmd_acq_new_brief_record.tab', event); }
1110             ],
1111             'cmd_acq_claim_eligible' : [
1112                 ['oncommand'],
1113                 function(event) { open_eg_web_page('acq/financial/claim_eligible', 'menu.cmd_acq_claim_eligible.tab', event); }
1114             ],
1115             'cmd_booking_reservation' : [
1116                 ['oncommand'],
1117                 function(event) {
1118                     open_eg_web_page(
1119                         "/eg/booking/reservation",
1120                         "menu.cmd_booking_reservation.tab",
1121                         event
1122                     );
1123                 }
1124             ],
1125             'cmd_booking_pull_list' : [
1126                 ['oncommand'],
1127                 function(event) {
1128                     open_eg_web_page(
1129                         "/eg/booking/pull_list",
1130                         "menu.cmd_booking_pull_list.tab",
1131                         event
1132                     );
1133                 }
1134             ],
1135             'cmd_booking_capture' : [
1136                 ['oncommand'],
1137                 function(event) {
1138                     open_eg_web_page(
1139                         "/eg/booking/capture",
1140                         "menu.cmd_booking_capture.tab",
1141                         event
1142                     );
1143                 }
1144             ],
1145             'cmd_booking_reservation_pickup' : [
1146                 ['oncommand'],
1147                 function(event) {
1148                     open_eg_web_page(
1149                         "/eg/booking/pickup",
1150                         "menu.cmd_booking_reservation_pickup.tab",
1151                         event
1152                     );
1153                 }
1154             ],
1155             'cmd_booking_reservation_return' : [
1156                 ['oncommand'],
1157                 function(event) {
1158                     open_eg_web_page(
1159                         "/eg/booking/return",
1160                         "menu.cmd_booking_reservation_return.tab",
1161                         event
1162                     );
1163                 }
1164             ],
1165             'cmd_reprint' : [
1166                 ['oncommand'],
1167                 function() {
1168                     try {
1169                         JSAN.use('util.print'); var print = new util.print();
1170                         print.reprint_last();
1171                     } catch(E) {
1172                         alert(E);
1173                     }
1174                 }
1175             ],
1176
1177             'cmd_retrieve_last_patron' : [
1178                 ['oncommand'],
1179                 function(event) {
1180                     obj.data.stash_retrieve();
1181                     if (!obj.data.last_patron) {
1182                         alert(offlineStrings.getString('menu.cmd_retrieve_last_patron.session.error'));
1183                         return;
1184                     }
1185                     var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1186                     var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1187                     obj.command_tab( event, url, {}, { 'id' : obj.data.last_patron } );
1188                 }
1189             ],
1190             
1191             'cmd_retrieve_last_record' : [
1192                 ['oncommand'],
1193                 function(event) {
1194                     obj.data.stash_retrieve();
1195                     if (!obj.data.last_record) {
1196                         alert(offlineStrings.getString('menu.cmd_retrieve_last_record.session.error'));
1197                         return;
1198                     }
1199                     var opac_url = obj.url_prefix( urls.opac_rdetail ) + obj.data.last_record;
1200                     var content_params = {
1201                         'session' : ses(),
1202                         'authtime' : ses('authtime'),
1203                         'opac_url' : opac_url,
1204                     };
1205                     obj.command_tab(
1206                         event,
1207                         obj.url_prefix(urls.XUL_OPAC_WRAPPER),
1208                         {'tab_name' : offlineStrings.getString('menu.cmd_retrieve_last_record.status')},
1209                         content_params
1210                     );
1211                 }
1212             ],
1213
1214             'cmd_verify_credentials' : [
1215                 ['oncommand'],
1216                 function(event) {
1217                     obj.command_tab(
1218                         event,
1219                         obj.url_prefix(urls.XUL_VERIFY_CREDENTIALS),
1220                         { 'tab_name' : offlineStrings.getString('menu.cmd_verify_credentials.tabname') },
1221                         {}
1222                     );
1223                 }
1224             ],
1225
1226             /* Cataloging Menu */
1227             'cmd_z39_50_import' : [
1228                 ['oncommand'],
1229                 function(event) {
1230                     obj.data.stash_retrieve();
1231                     obj.command_tab(event,obj.url_prefix(urls.XUL_Z3950_IMPORT),{},{});
1232                 }
1233             ],
1234             'cmd_create_marc' : [
1235                 ['oncommand'],
1236                 function(event) {
1237                     obj.data.stash_retrieve();
1238                     obj.command_tab(event,obj.url_prefix(urls.XUL_MARC_NEW),{},{});
1239                 }
1240             ],
1241
1242             'cmd_authority_manage' : [
1243                 ['oncommand'],
1244                 function(event) {
1245                     open_eg_web_page(
1246                         urls.AUTHORITY_MANAGE,
1247                         "menu.cmd_authority_manage.tab",
1248                         event
1249                     );
1250                 }
1251             ],
1252
1253             'cmd_marc_batch_edit' : [
1254                 ['oncommand'],
1255                 function(event) {
1256                     obj.command_tab(
1257                         event,
1258                         obj.url_prefix(urls.MARC_BATCH_EDIT),{
1259                             'tab_name' : offlineStrings.getString('menu.cmd_marc_batch_edit.tab')
1260                         },
1261                         {}
1262                     );
1263                 }
1264             ],
1265
1266             /* Admin menu */
1267             'cmd_change_session' : [
1268                 ['oncommand'],
1269                 function() {
1270                     try {
1271                         obj.data.stash_retrieve();
1272                         JSAN.use('util.network'); var network = new util.network();
1273                         var temp_au = js2JSON( obj.data.list.au[0] );
1274                         var temp_ses = js2JSON( obj.data.session );
1275                         if (obj.data.list.au.length > 1) {
1276                             obj.data.list.au = [ obj.data.list.au[1] ];
1277                             obj.data.stash('list');
1278                             network.reset_titlebars( obj.data );
1279                             network.simple_request('AUTH_DELETE', [ obj.data.session.key ] );
1280                             obj.data.session = obj.data.previous_session;
1281                             obj.data.menu_perms = obj.data.previous_menu_perms;
1282                             obj.data.stash('session');
1283                             obj.data.stash('menu_perms');
1284                             try {
1285                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1286                                 var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
1287                                 var cookieUri = ios.newURI("http://" + obj.data.server_unadorned, null, null);
1288                                 var cookieUriSSL = ios.newURI("https://" + obj.data.server_unadorned, null, null);
1289                                 var cookieSvc = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);
1290
1291                                 cookieSvc.setCookieString(cookieUri, null, "ses="+obj.data.session.key, null);
1292                                 cookieSvc.setCookieString(cookieUriSSL, null, "ses="+obj.data.session.key, null);
1293
1294                         } catch(E) {
1295                             alert(offlineStrings.getFormattedString(main.session_cookie.error, [E]));
1296                         }
1297
1298                         } else {
1299                             if (network.get_new_session(offlineStrings.getString('menu.cmd_chg_session.label'),{'url_prefix':obj.url_prefix})) {
1300                                 obj.data.stash_retrieve();
1301                                 obj.data.list.au[1] = JSON2js( temp_au );
1302                                 obj.data.stash('list');
1303                                 obj.data.previous_session = JSON2js( temp_ses );
1304                                 obj.data.previous_menu_perms = obj.data.menu_perms;
1305                                 obj.data.menu_perms = false;
1306                                 obj.data.stash('previous_session');
1307                                 obj.data.stash('previous_menu_perms');
1308                                 obj.data.stash('menu_perms');
1309                             }
1310                         }
1311                         network.set_user_status();
1312                     } catch(E) {
1313                         obj.error.standard_unexpected_error_alert('cmd_change_session',E);
1314                     }
1315                 }
1316             ],
1317             'cmd_manage_offline_xacts' : [
1318                 ['oncommand'],
1319                 function(event) {
1320                     obj.command_tab(event,obj.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS), {'tab_name' : offlineStrings.getString('menu.cmd_manage_offline_xacts.tab')}, {});
1321                 }
1322             ],
1323             'cmd_download_patrons' : [
1324                 ['oncommand'],
1325                 function() {
1326                     try {
1327                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1328                         var x = new XMLHttpRequest();
1329                         var url = 'http://' + XML_HTTP_SERVER + '/standalone/list.txt';
1330                         x.open("GET",url,false);
1331                         x.send(null);
1332                         if (x.status == 200) {
1333                             JSAN.use('util.file'); var file = new util.file('offline_patron_list');
1334                             file.write_content('truncate',x.responseText);
1335                             file.close();
1336                             file = new util.file('offline_patron_list.date');
1337                             file.write_content('truncate',new Date());
1338                             file.close();
1339                             alert(offlineStrings.getString('menu.cmd_download_patrons.complete.status'));
1340                         } else {
1341                             alert(offlineStrings.getFormattedString('menu.cmd_download_patrons.error', [x.status, x.statusText]));
1342                         }
1343                     } catch(E) {
1344                         obj.error.standard_unexpected_error_alert('cmd_download_patrons',E);
1345                     }
1346                 }
1347             ],
1348             'cmd_adv_user_edit' : [
1349                 ['oncommand'],
1350                 function(event) {
1351                     obj.data.stash_retrieve();
1352                     obj.command_tab(event,obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY), {}, { 'perm_editor' : true });
1353                 }
1354             ],
1355             'cmd_print_list_template_edit' : [
1356                 ['oncommand'],
1357                 function(event) {
1358                     obj.data.stash_retrieve();
1359                     obj.command_tab(event,obj.url_prefix(urls.XUL_PRINT_LIST_TEMPLATE_EDITOR), {}, {});
1360                 }
1361             ],
1362             'cmd_stat_cat_edit' : [
1363                 ['oncommand'],
1364                 function(event) {
1365                     obj.data.stash_retrieve();
1366                     obj.command_tab(event,obj.url_prefix(urls.XUL_STAT_CAT_EDIT) + '?ses='+window.escape(ses()), {'tab_name' : offlineStrings.getString('menu.cmd_stat_cat_edit.tab')},{});
1367                 }
1368             ],
1369             'cmd_non_cat_type_edit' : [
1370                 ['oncommand'],
1371                 function(event) {
1372                     obj.data.stash_retrieve();
1373                     obj.command_tab(event,obj.url_prefix(urls.XUL_NON_CAT_LABEL_EDIT) + '?ses='+window.escape(ses()), {'tab_name' : offlineStrings.getString('menu.cmd_non_cat_type_edit.tab')},{});
1374                 }
1375             ],
1376             'cmd_copy_location_edit' : [
1377                 ['oncommand'],
1378                 function(event) {
1379                     obj.data.stash_retrieve();
1380                     obj.command_tab(event,obj.url_prefix(urls.XUL_COPY_LOCATION_EDIT) + '?ses='+window.escape(ses()),{'tab_name' : offlineStrings.getString('menu.cmd_copy_location_edit.tab')},{});
1381                 }
1382             ],
1383             'cmd_test' : [
1384                 ['oncommand'],
1385                 function(event) {
1386                     obj.data.stash_retrieve();
1387                     var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
1388                     obj.command_tab(event,obj.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
1389                 }
1390             ],
1391             'cmd_test_html' : [
1392                 ['oncommand'],
1393                 function(event) {
1394                     obj.data.stash_retrieve();
1395                     obj.command_tab(event,obj.url_prefix(urls.TEST_HTML) + '?ses='+window.escape(ses()),{ 'browser' : true },{});
1396                 }
1397             ],
1398             'cmd_test_xul' : [
1399                 ['oncommand'],
1400                 function(event) {
1401                     obj.data.stash_retrieve();
1402                     obj.command_tab(event,obj.url_prefix(urls.TEST_XUL) + '?ses='+window.escape(ses()),{ 'browser' : false },{});
1403                 }
1404             ],
1405             'cmd_console' : [
1406                 ['oncommand'],
1407                 function(event) {
1408                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_CONSOLE),{'tab_name' : offlineStrings.getString('menu.cmd_console.tab')},{});
1409                 }
1410             ],
1411             'cmd_shell' : [
1412                 ['oncommand'],
1413                 function(event) {
1414                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_SHELL),{'tab_name' : offlineStrings.getString('menu.cmd_shell.tab')},{});
1415                 }
1416             ],
1417             'cmd_xuleditor' : [
1418                 ['oncommand'],
1419                 function(event) {
1420                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_XULEDITOR),{'tab_name' : offlineStrings.getString('menu.cmd_xuleditor.tab')},{});
1421                 }
1422             ],
1423             'cmd_fieldmapper' : [
1424                 ['oncommand'],
1425                 function(event) {
1426                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_FIELDMAPPER),{'tab_name' : offlineStrings.getString('menu.cmd_fieldmapper.tab')},{});
1427                 }
1428             ],
1429             'cmd_survey_wizard' : [
1430                 ['oncommand'],
1431                 function() {
1432                     obj.data.stash_retrieve();
1433                     xulG.window.open(obj.url_prefix(urls.XUL_SURVEY_WIZARD),'survey_wizard','chrome'); 
1434                 }
1435             ],
1436             'cmd_public_opac' : [
1437                 ['oncommand'],
1438                 function(event) {
1439                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
1440                         obj.url_prefix(urls.remote)
1441                     );
1442                     obj.command_tab(
1443                         event,
1444                         loc, 
1445                         {'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
1446                         { 'no_xulG' : true, 'show_nav_buttons' : true, 'show_print_button' : true } 
1447                     );
1448                 }
1449             ],
1450             'cmd_clear_cache' : [
1451                 ['oncommand'],
1452                 function clear_the_cache() {
1453                     try {
1454                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1455                         var cacheClass         = Components.classes["@mozilla.org/network/cache-service;1"];
1456                         var cacheService    = cacheClass.getService(Components.interfaces.nsICacheService);
1457                         cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
1458                         cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
1459                     } catch(E) {
1460                         dump(E+'\n');alert(E);
1461                     }
1462                 }
1463             ],
1464             'cmd_restore_all_tabs' : [
1465                 ['oncommand'],
1466                 function() {
1467                     var tabs = obj.controller.view.tabs;
1468                     for (var i = 0; i < tabs.childNodes.length; i++) {
1469                         tabs.childNodes[i].hidden = false;
1470                     }
1471                 }
1472             ],
1473             'cmd_extension_manager' : [
1474                 ['oncommand'],
1475                 function(event) {
1476                     obj.command_tab(event,'chrome://mozapps/content/extensions/extensions.xul?type=extensions',{'tab_name' : offlineStrings.getString('menu.cmd_extension_manager.tab')},{});
1477                 }
1478             ],
1479             'cmd_theme_manager' : [
1480                 ['oncommand'],
1481                 function(event) {
1482                     obj.command_tab(event,'chrome://mozapps/content/extensions/extensions.xul?type=themes',{'tab_name' : offlineStrings.getString('menu.cmd_theme_manager.tab')},{});
1483                 }
1484             ],
1485             'cmd_about_config' : [
1486                 ['oncommand'],
1487                 function(event) {
1488                     obj.command_tab(event,'chrome://global/content/config.xul',{'tab_name' : 'about:config'},{});
1489                 }
1490             ],
1491             'cmd_shutdown' : [
1492                 ['oncommand'],
1493                 function() {
1494                     var confirm_string = offlineStrings.getString('menu.cmd_shutdown.prompt');
1495                     obj.data.stash_retrieve();
1496                     if (typeof obj.data.unsaved_data != 'undefined') {
1497                         if (obj.data.unsaved_data > 0) {
1498                             confirm_string = offlineStrings.getString('menu.shutdown.unsaved_data_warning');
1499                         }
1500                     }
1501                     if (window.confirm(confirm_string)) {
1502                         obj.data.unsaved_data = 0; // just in case the program doesn't close somehow
1503                         obj.data.stash('unsaved_data');
1504                         dump('forcing data.unsaved_data == ' + obj.data.unsaved_data + '\n');
1505                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1506                         var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
1507                         var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
1508                         var enumerator = windowManagerInterface.getEnumerator(null);
1509                         var w; // close all other windows
1510                         while ( w = enumerator.getNext() ) {
1511                             if (w != window) {
1512                                 if (w.xulG) { w.close(); } // FIXME: kludge so we don't close Firefox windows as an extension.  We should define a @windowtype for all the staff client windows and have the enumerator just pull those
1513                             }
1514                         }
1515                         window.close();
1516                     }
1517                 }
1518             ],
1519             'cmd_hotkeys_toggle' : [
1520                 ['oncommand'],
1521                 function() {
1522                     // Easy enough, toggle disabled on the keyset
1523                     var keyset = document.getElementById("menu_frame_keys");
1524                     var disabled = (keyset.getAttribute("disabled") == "true") ? "false" : "true";
1525                     if(disabled == "true")
1526                         keyset.setAttribute("disabled", "true");
1527                     else
1528                         keyset.removeAttribute("disabled");
1529                     // Then find every menuitem/toolbarbutton for this command for a graphical hint
1530                     var controls = document.getElementsByAttribute("command","cmd_hotkeys_toggle");
1531                     for(var i = 0; i < controls.length; i++)
1532                         controls[i].setAttribute("checked",disabled);
1533                 }
1534             ],
1535             'cmd_hotkeys_set' : [
1536                 ['oncommand'],
1537                 function(event) {
1538                     obj.set_menu_hotkeys(event.explicitOriginalTarget.getAttribute('value'));
1539                 }
1540             ],
1541             'cmd_hotkeys_setworkstation' : [
1542                 ['oncommand'],
1543                 function() {
1544                     xulG.pref.setCharPref('open-ils.menu.hotkeyset', obj.data.current_hotkeyset);
1545                 }
1546             ],
1547             'cmd_hotkeys_clearworkstation' : [
1548                 ['oncommand'],
1549                 function() {
1550                     if(xulG.pref.prefHasUserValue('open-ils.menu.hotkeyset'))
1551                         xulG.pref.clearUserPref('open-ils.menu.hotkeyset');
1552                 }
1553             ],
1554             'cmd_toolbar_set' : [
1555                 ['oncommand'],
1556                 function(event) {
1557                     var newToolbar = event.explicitOriginalTarget.getAttribute('value');
1558                     var toolbox = document.getElementById('main_toolbox');
1559                     var toolbars = toolbox.getElementsByTagName('toolbar');
1560                     for(var i = 0; i < toolbars.length; i++) {
1561                         if(toolbars[i].id == 'toolbar_' + newToolbar)
1562                             toolbars[i].setAttribute('hidden', 'false');
1563                         else
1564                             toolbars[i].setAttribute('hidden', 'true');
1565                     }
1566                     obj.toolbar = newToolbar;
1567                 }
1568             ],
1569             'cmd_toolbar_mode_set' : [
1570                 ['oncommand'],
1571                 function(event) {
1572                     var newMode = event.explicitOriginalTarget.getAttribute('value');
1573                     var toolbox = document.getElementById('main_toolbox');
1574                     var toolbars = toolbox.getElementsByTagName('toolbar');
1575                     for(var i = 0; i < toolbars.length; i++)
1576                         toolbars[i].setAttribute("mode",newMode);
1577                     obj.toolbar_mode = newMode;
1578                 }
1579             ],
1580             'cmd_toolbar_size_set' : [
1581                 ['oncommand'],
1582                 function(event) {
1583                     var newSize = event.explicitOriginalTarget.getAttribute('value');
1584                     var toolbox = document.getElementById('main_toolbox');
1585                     var toolbars = toolbox.getElementsByTagName('toolbar');
1586                     for(var i = 0; i < toolbars.length; i++)
1587                         toolbars[i].setAttribute("iconsize",newSize);
1588                     obj.toolbar_size = newSize;
1589                 }
1590             ],
1591             'cmd_toolbar_label_position_set' : [
1592                 ['oncommand'],
1593                 function(event) {
1594                     var altPosition = (event.explicitOriginalTarget.getAttribute('value') == "under");
1595                     var toolbox = document.getElementById('main_toolbox');
1596                     var toolbars = toolbox.getElementsByTagName('toolbar');
1597                     for(var i = 0; i < toolbars.length; i++) {
1598                         if(altPosition)
1599                             addCSSClass(toolbars[i], 'labelbelow');
1600                         else
1601                             removeCSSClass(toolbars[i], 'labelbelow');
1602                     }
1603                     obj.toolbar_labelpos = (altPosition ? "under" : "side");
1604                 }
1605             ],
1606             'cmd_toolbar_setworkstation' : [
1607                 ['oncommand'],
1608                 function() {
1609                 xulG.pref.setCharPref('open-ils.menu.toolbar', obj.toolbar);
1610                 xulG.pref.setCharPref('open-ils.menu.toolbar.iconsize', obj.toolbar_size);
1611                 xulG.pref.setCharPref('open-ils.menu.toolbar.mode', obj.toolbar_mode);
1612                 xulG.pref.setBoolPref('open-ils.menu.toolbar.labelbelow', (obj.toolbar_labelpos == "under"));
1613                 }
1614             ],
1615             'cmd_toolbar_clearworkstation' : [
1616                 ['oncommand'],
1617                 function() {
1618                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar'))
1619                         xulG.pref.clearUserPref('open-ils.menu.toolbar');
1620                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar.iconsize'))
1621                         xulG.pref.clearUserPref('open-ils.menu.toolbar.iconsize');
1622                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar.mode'))
1623                         xulG.pref.clearUserPref('open-ils.menu.toolbar.mode');
1624                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar.labelbelow'))
1625                         xulG.pref.clearUserPref('open-ils.menu.toolbar.labelbelow');
1626                 }
1627             ],
1628             'cmd_debug_venkman' : [
1629                 ['oncommand'],
1630                 function() {
1631                     try{
1632                         xulG.window.win.start_debugger();
1633                     } catch(E) {
1634                         alert(E);
1635                     }
1636                 }
1637             ],
1638             'cmd_debug_inspector' : [
1639                 ['oncommand'],
1640                 function() {
1641                     try{
1642                         xulG.window.win.start_inspector();
1643                     } catch(E) {
1644                         alert(E);
1645                     }
1646                 }
1647             ],
1648             'cmd_debug_chrome_list' : [
1649                 ['oncommand'],
1650                 function() {
1651                     try{
1652                         xulG.window.win.start_chrome_list();
1653                     } catch(E) {
1654                         alert(E);
1655                     }
1656                 }
1657             ],
1658             'cmd_debug_chrome_shell' : [
1659                 ['oncommand'],
1660                 function() {
1661                     try{
1662                         xulG.window.win.start_js_shell();
1663                     } catch(E) {
1664                         alert(E)
1665                     }
1666                 }
1667             ],
1668             'cmd_copy_editor_copy_location_first_toggle' : [
1669                 ['oncommand'],
1670                 function() {
1671                     var curvalue = xulG.pref.getBoolPref('oils.copy_editor.copy_location_name_first');
1672                     xulG.pref.setBoolPref('oils.copy_editor.copy_location_name_first', !curvalue);
1673                 }
1674             ],
1675         };
1676
1677         JSAN.use('util.controller');
1678         var cmd;
1679         obj.controller = new util.controller();
1680         obj.controller.init( { 'window_knows_me_by' : 'g.menu.controller', 'control_map' : cmd_map } );
1681
1682         obj.controller.view.tabbox = window.document.getElementById('main_tabbox');
1683         // Despite what the docs say:
1684         // The "tabs" element need not be the first child
1685         // The "panels" element need not be the second/last
1686         // Nor need they be the only ones there.
1687         // Thus, use the IDs for robustness.
1688         obj.controller.view.tabs = window.document.getElementById('main_tabs');
1689         obj.controller.view.panels = window.document.getElementById('main_panels');
1690         obj.controller.view.tabscroller = window.document.getElementById('main_tabs_scrollbox');
1691         if(params['firstURL']) {
1692             obj.new_tab(params['firstURL'],{'focus':true},null);
1693         }
1694         else {
1695             obj.new_tab(null,{'focus':true},null);
1696         }
1697     },
1698
1699     'spawn_search' : function(s) {
1700         var obj = this;
1701         obj.error.sdump('D_TRACE', offlineStrings.getFormattedString('menu.spawn_search.msg', [js2JSON(s)]) ); 
1702         obj.new_patron_tab( {}, { 'doit' : 1, 'query' : js2JSON(s) } );
1703     },
1704
1705     'close_all_tabs' : function() {
1706         var obj = this;
1707         try {
1708             var count = obj.controller.view.tabs.childNodes.length;
1709             for (var i = 1; i < count; i++) obj.close_tab();
1710             setTimeout( function(){ obj.controller.view.tabs.firstChild.focus(); }, 0);
1711         } catch(E) {
1712             obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.close_all_tabs.error'),E);
1713         }
1714     },
1715
1716     'close_tab' : function (specific_idx) {
1717         var idx = specific_idx || this.controller.view.tabs.selectedIndex;
1718         var panel = this.controller.view.panels.childNodes[ idx ];
1719
1720         var tab = this.controller.view.tabs.getItemAtIndex( idx );
1721         var id = tab.getAttribute('id');
1722         if (typeof this.tab_semaphores[id] != 'undefined') {
1723             if (this.tab_semaphores[id] > 0) {
1724                 var confirmation = window.confirm(offlineStrings.getString('menu.close_tab.unsaved_data_warning'));
1725                 if (!confirmation) { return; }
1726                 oils_unsaved_data_P( this.tab_semaphores[id] );
1727             }
1728             delete this.tab_semaphores[id];
1729         }
1730
1731         this.controller.view.tabs.removeItemAt(idx);
1732         this.controller.view.panels.removeChild(panel);
1733         if(this.controller.view.tabs.childNodes.length > idx) {
1734             this.controller.view.tabbox.selectedIndex = idx;
1735         }
1736         else {
1737             this.controller.view.tabbox.selectedIndex = idx - 1;
1738         }
1739         this.controller.view.tabscroller.ensureElementIsVisible(this.controller.view.tabs.selectedItem);
1740         this.update_all_tab_names();
1741         // Make sure we keep at least one tab open.
1742         if(this.controller.view.tabs.childNodes.length == 1) {
1743             this.new_tab(); 
1744         }
1745     },
1746     
1747     'update_all_tab_names' : function() {
1748         var doAccessKeys = !xulG.pref.getBoolPref('open-ils.disable_accesskeys_on_tabs');
1749         for(var i = 1; i < this.controller.view.tabs.childNodes.length; ++i) {
1750             var tab = this.controller.view.tabs.childNodes[i];
1751             tab.curindex = i;
1752             tab.label = i + ' ' + tab.origlabel;
1753             if(doAccessKeys && offlineStrings.testString('menu.tab' + i + '.accesskey')) {
1754                 tab.accessKey = offlineStrings.getString('menu.tab' + i + '.accesskey');
1755             }
1756         }
1757     },
1758
1759     'command_tab' : function(event,url,params,content_params) {
1760         var newTab = false;
1761         var myEvent = event;
1762         if(event && event.sourceEvent) myEvent = event.sourceEvent;
1763         // Note: The last event is not supposed to be myEvent in this if.
1764         if(myEvent && myEvent.explicitOriginalTarget.nodeName.match(/toolbarbutton/) && myEvent.explicitOriginalTarget.command == event.originalTarget.id) {
1765             var value = xulG.pref.getIntPref('ui.key.accelKey');
1766             switch(value) {
1767                 case 17:
1768                     newTab = myEvent.ctrlKey;
1769                     break;
1770                 case 18:
1771                     newTab = myEvent.altKey;
1772                     break;
1773                 case 224:
1774                     newTab = myEvent.metaKey;
1775                     break;
1776             }
1777             try {
1778                 if(xulG.pref.getBoolPref('open-ils.toolbar.defaultnewtab')) {
1779                     newTab = !newTab;
1780                 }
1781             }
1782             catch (e) {
1783             }
1784         }
1785         if(newTab) {
1786             this.new_tab(url,params,content_params);
1787         }
1788         else {
1789             this.set_tab(url,params,content_params);
1790         }
1791     },
1792
1793     'new_tab' : function(url,params,content_params) {
1794         var obj = this;
1795         var max_tabs = 0;
1796         try {
1797             var max_tabs = xulG.pref.getIntPref('open-ils.window_max_tabs') || max_tabs;
1798         }
1799         catch (e) {}
1800         if(max_tabs > 0 && this.controller.view.tabs.childNodes.length > max_tabs) return false;
1801         var tab = this.w.document.createElement('tab');
1802         var panel = this.w.document.createElement('tabpanel');
1803         var tabscroller = this.controller.view.tabscroller;
1804         this.controller.view.tabs.appendChild(tab);
1805         this.controller.view.panels.appendChild(panel);
1806         tab.curindex = this.controller.view.tabs.childNodes.length - 1;
1807         if(!xulG.pref.getBoolPref('open-ils.disable_accesskeys_on_tabs')) {
1808             if(offlineStrings.testString('menu.tab' + tab.curindex + '.accesskey')) {
1809                 tab.accessKey = offlineStrings.getString('menu.tab' + tab.curindex + '.accesskey');
1810             }
1811         }
1812         var tabs = this.controller.view.tabs;
1813         tab.addEventListener(
1814             'command',
1815             function() {
1816                 try {
1817                     tabscroller.ensureElementIsVisible(tab);
1818                     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1819                     if (panel
1820                         && panel.firstChild 
1821                         && ( panel.firstChild.nodeName == 'iframe' || panel.firstChild.nodeName == 'browser' )
1822                         && panel.firstChild.contentWindow 
1823                     ) {
1824                         var cw = panel.firstChild.contentWindow;
1825                         var help_params = {
1826                             'protocol' : cw.location.protocol,
1827                             'hostname' : cw.location.hostname,
1828                             'port' : cw.location.port,
1829                             'pathname' : cw.location.pathname,
1830                             'src' : ''
1831                         };
1832                         obj.set_help_context(help_params);
1833                         if (typeof cw.default_focus == 'function') {
1834                             cw.default_focus();
1835                         }
1836                     }
1837                 } catch(E) {
1838                     obj.error.sdump('D_ERROR','init_tab_focus_handler: ' + js2JSON(E));
1839                 }
1840             }
1841             ,
1842             false
1843         );
1844         if (!content_params) content_params = {};
1845         if (!params) params = {};
1846         if (!params.tab_name) params.tab_name = offlineStrings.getString('menu.new_tab.tab');
1847         if (!params.nofocus) params.focus = true; /* make focus the default */
1848         try {
1849             if (params.focus) {
1850                 this.controller.view.tabs.selectedItem = tab;
1851                 tabscroller.ensureElementIsVisible(tab);
1852             }
1853             params.index = tab.curindex;
1854             this.set_tab(url,params,content_params);
1855             return true;
1856         } catch(E) {
1857             this.error.sdump('D_ERROR',E);
1858             return false;
1859         }
1860     },
1861
1862     'set_menu_access' : function(perms) {
1863         if(perms === false) return;
1864         var commands = document.getElementById('universal_cmds').getElementsByTagName('command');
1865         var commandperms;
1866 commands:
1867         for (var i = 0; i < commands.length; i++) { 
1868             if (commands[i].hasAttribute('perm')) {
1869                 commandperms = commands[i].getAttribute('perm').split(' ');
1870                 for (var j = 0; j < commandperms.length; j++) {
1871                     if (perms[commandperms[j]]) {
1872                         commands[i].setAttribute('disabled','false');
1873                         continue commands;
1874                     }
1875                 }
1876                 commands[i].setAttribute('disabled','true');
1877             }           
1878         }
1879
1880     },
1881
1882     'set_menu_hotkeys' : function(hotkeyset) {
1883         this.data.stash_retrieve();
1884
1885         var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
1886                     getService(Components.interfaces.nsIWindowMediator);
1887         var mainwin = wm.getMostRecentWindow('eg_main');
1888         JSAN.use('util.network');
1889         var network = new util.network();
1890
1891         if(hotkeyset) { // Explicit request
1892             // Store
1893             this.data.current_hotkeyset = hotkeyset;
1894             this.data.stash('current_hotkeyset');
1895             // Then iterate over windows
1896             var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
1897             var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
1898             var enumerator = windowManagerInterface.getEnumerator('eg_menu');
1899
1900             var w;
1901             while ( w = enumerator.getNext() ) {
1902                 if ( w != window )
1903                     w.g.menu.set_menu_hotkeys();
1904             }
1905         }
1906         else { // Non-explicit request?
1907             if(this.data.current_hotkeyset) // Previous hotkeyset?
1908                 hotkeyset = this.data.current_hotkeyset; // Use it
1909             else { // No previous? We need to decide on one!
1910                 // Load the list so we know if what we are being asked to load is valid.
1911                 var hotkeysets = mainwin.load_hotkey_sets();
1912                 if(!hotkeysets) return; // No sets = nothing to load. Which is probably an error, but meh.
1913                 hotkeysets.has = function(test) {
1914                     for(i = 0; i < this.length; i++) {
1915                         if(this[i] == test) return true;
1916                     }
1917                     return false;
1918                 }; 
1919                 // Try workstation (pref)
1920                 hotkeyset = xulG.pref.getCharPref('open-ils.menu.hotkeyset');
1921
1922                 // Nothing or nothing valid?
1923                 if(!hotkeyset || !hotkeysets.has(hotkeyset)) {
1924                     hotkeyset = this.data.hash.aous['ui.general.hotkeyset'];
1925                 }
1926                 // STILL nothing? Try Default.
1927                 if(!hotkeyset || !hotkeysets.has(hotkeyset)) {
1928                     if(hotkeysets.has('Default'))
1929                         hotkeyset = 'Default';
1930                     else
1931                         return false;
1932                 }
1933                 // And save whatever we are using.
1934                 this.data.current_hotkeyset = hotkeyset;
1935                 this.data.stash('current_hotkeyset');
1936             }
1937         }
1938         // Clear out all the old hotkeys
1939         var keyset = document.getElementById('menu_frame_keys');
1940         var main_menu = document.getElementById('main_menubar');
1941         if(keyset.hasChildNodes()) {
1942             var menuitems = main_menu.getElementsByAttribute('key','*');
1943             while(menuitems.length > 0) {
1944                 var menuitem = menuitems[0];
1945                 menuitem.removeAttribute('key');
1946                 // Trick/force mozilla to re-evaluate the menuitem
1947                 // If you want to take this trick for use *anywhere* in *any* project, regardless of licensing, please do
1948                 // Because it was a PITA to figure out
1949                 menuitem.style.display = 'none'; // Hide the item to force menu to clear spot
1950                 menuitem.setAttribute('acceltext', ''); // Set acceltext to blank string outright
1951                 menuitem.removeAttribute('acceltext'); // Remove acceltext to clear out hotkey hint text
1952                 menuitem.parentNode.openPopupAtScreen(0,0,false); // Tell menupopup to redraw itself
1953                 menuitem.parentNode.hidePopup(); // And then make it go away right away.
1954                 menuitem.style.removeProperty('display'); // Restore normal css display
1955             }
1956             while(keyset.hasChildNodes()) keyset.removeChild(keyset.childNodes[0]);
1957         }
1958         keyset_lines = mainwin.get_hotkey_array(hotkeyset);
1959         // Next, fill the keyset
1960         for(var line = 0; line < keyset_lines.length; line++) {
1961             // Create and populate our <key>
1962             var key_node = document.createElement('key');
1963             key_node.setAttribute('id',keyset_lines[line][0] + "_key");
1964             key_node.setAttribute('command',keyset_lines[line][0]);
1965             key_node.setAttribute('modifiers',keyset_lines[line][1]);
1966             // If keycode starts with VK_ we assume it is a key code.
1967             // Key codes go in the keycode attribute
1968             // Regular keys (like "i") go in the key attribute
1969             if(keyset_lines[line][2].match(/^VK_/))
1970                 key_node.setAttribute('keycode',keyset_lines[line][2]);
1971             else
1972                 key_node.setAttribute('key',keyset_lines[line][2]);
1973             // If a fourth option was specified, set keytext to it.
1974             if(keyset_lines[line][3])
1975                 key_node.setAttribute('keytext',keyset_lines[line][3]);
1976             // Add the new node to the DOM
1977             keyset.appendChild(key_node);
1978             // And populate all the menu items that should now display it
1979             var menuitems = main_menu.getElementsByAttribute('command',keyset_lines[line][0]);
1980             for(var i = 0; i < menuitems.length; i++) {
1981                 menuitems[i].setAttribute('key', keyset_lines[line][0] + "_key");
1982                 // Trick/force mozilla to re-evaluate the menuitem
1983                 menuitems[i].style.display = 'none'; // Hide the item to force menu to clear spot
1984                 menuitems[i].parentNode.openPopupAtScreen(0,0,false); // Tell menupopup to redraw itself
1985                 menuitems[i].parentNode.hidePopup(); // And then make it go away right away
1986                 menuitems[i].style.removeProperty('display'); // Restore normal css display
1987             }
1988         }
1989         // Force reload of keyset cache?
1990         keyset.parentNode.insertBefore(keyset, keyset.nextSibling);
1991         // If no keys, disable ability to toggle hotkeys (because why bother?)
1992         var x = document.getElementById('cmd_hotkeys_toggle');
1993         if(x) {
1994             if(keyset.hasChildNodes())
1995                 x.removeAttribute('disabled');
1996             else
1997                 x.setAttribute('disabled', 'true');
1998         }
1999         // Select the hotkey set in the menu
2000         // This ensures that first window load OR remote window update shows properly
2001         var hotkeylist = document.getElementById('main.menu.admin.client.hotkeys.current.popup');
2002         var selectitems = hotkeylist.getElementsByAttribute('value',hotkeyset);
2003         if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
2004     },
2005
2006     'page_meter' : {
2007         'node' : document.getElementById('page_progress'),
2008         'on' : function() {
2009             document.getElementById('page_progress').setAttribute('mode','undetermined');
2010         },
2011         'off' : function() {
2012             document.getElementById('page_progress').setAttribute('mode','determined');
2013         },
2014         'tooltip' : function(text) {
2015             if (text || text == '') {
2016                 document.getElementById('page_progress').setAttribute('tooltiptext',text);
2017             }
2018             return document.getElementById('page_progress').getAttribute('tooltiptext');
2019         }
2020     },
2021
2022     'network_meter' : {
2023         'inc' : function(app,method) {
2024             try {
2025                 var m = document.getElementById('network_progress');
2026                 var count = 1 + Number( m.getAttribute('count') );
2027                 m.setAttribute('mode','undetermined');
2028                 m.setAttribute('count', count);
2029                 var rows = document.getElementById('network_progress_rows');
2030                 var row = document.getElementById('network_progress_tip_'+app+'_'+method);
2031                 if (!row) {
2032                     row = document.createElement('row'); row.setAttribute('id','network_progress_tip_'+app+'_'+method);
2033                     var a = document.createElement('label'); a.setAttribute('value','App:');
2034                     var b = document.createElement('label'); b.setAttribute('value',app);
2035                     var c = document.createElement('label'); c.setAttribute('value','Method:');
2036                     var d = document.createElement('label'); d.setAttribute('value',method);
2037                     var e = document.createElement('label'); e.setAttribute('value','Total:');
2038                     var f = document.createElement('label'); f.setAttribute('value','0'); 
2039                     f.setAttribute('id','network_progress_tip_total_'+app+'_'+method);
2040                     var g = document.createElement('label'); g.setAttribute('value','Outstanding:');
2041                     var h = document.createElement('label'); h.setAttribute('value','0');
2042                     h.setAttribute('id','network_progress_tip_out_'+app+'_'+method);
2043                     row.appendChild(a); row.appendChild(b); row.appendChild(c);
2044                     row.appendChild(d); row.appendChild(e); row.appendChild(f);
2045                     row.appendChild(g); row.appendChild(h); rows.appendChild(row);
2046                 }
2047                 var total = document.getElementById('network_progress_tip_total_'+app+'_'+method);
2048                 if (total) {
2049                     total.setAttribute('value', 1 + Number( total.getAttribute('value') ));
2050                 }
2051                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
2052                 if (out) {
2053                     out.setAttribute('value', 1 + Number( out.getAttribute('value') ));
2054                 }
2055             } catch(E) {
2056                 dump('network_meter.inc(): ' + E + '\n');
2057             }
2058         },
2059         'dec' : function(app,method) {
2060             try {
2061                 var m = document.getElementById('network_progress');
2062                 var count = -1 + Number( m.getAttribute('count') );
2063                 if (count < 0) count = 0;
2064                 if (count == 0) m.setAttribute('mode','determined');
2065                 m.setAttribute('count', count);
2066                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
2067                 if (out) {
2068                     out.setAttribute('value', -1 + Number( out.getAttribute('value') ));
2069                 }
2070             } catch(E) {
2071                 dump('network_meter.dec(): ' + E + '\n');
2072             }
2073         }
2074     },
2075     'set_patron_tab' : function(params,content_params,event) {
2076         var obj = this;
2077         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
2078         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
2079         obj.command_tab(event,url,params ? params : {},content_params ? content_params : {});
2080     },
2081     'new_patron_tab' : function(params,content_params) {
2082         var obj = this;
2083         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
2084         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
2085         obj.new_tab(url,params ? params : {},content_params ? content_params : {});
2086     },
2087     'volume_item_creator' : function(params) {
2088         var obj = this;
2089         var url;
2090         var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true';
2091         if (unified_interface) {
2092             var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true';
2093             url = obj.url_prefix( horizontal_interface ? urls.XUL_VOLUME_COPY_CREATOR_HORIZONTAL : urls.XUL_VOLUME_COPY_CREATOR );
2094         } else {
2095             url = obj.url_prefix( urls.XUL_VOLUME_COPY_CREATOR_ORIGINAL );
2096         }
2097         var w = obj.new_tab(
2098             url,
2099             { 'tab_name' : document.getElementById('offlineStrings').getString('staff.cat.create_or_rebarcode_items') },
2100             params
2101         );
2102     },
2103     'holdings_maintenance_tab' : function(docid,params,content_params) {
2104         var obj = this;
2105         if (!content_params) {
2106             content_params = {};
2107         }
2108         if (docid) {
2109             content_params['docid'] = docid;
2110         }
2111         var url = obj.url_prefix( urls.XUL_COPY_VOLUME_BROWSE );
2112         obj.new_tab(url,params || {}, content_params);
2113     },
2114     'get_new_session' : function(params) {
2115         var obj = this;
2116         if (!params) { params = {}; }
2117         JSAN.use('util.network'); var net = new util.network();
2118         var result = net.get_new_session(null,{'url_prefix':obj.url_prefix},!params.operator_change);
2119         if (typeof params.callback == 'function') {
2120             return params.callback( result, ses(), ses('authtime') );
2121         }
2122         return result;
2123     },
2124     'set_help_context' : function(params) {
2125         var obj = this;
2126         if (!params) { params = {}; }
2127         if (params.protocol == 'chrome:') { return; } /* not supported */
2128         var help_btn = document.getElementById('help_btn');
2129         if (help_btn) {
2130             dump('set_help_context: ' + js2JSON(params) + '\n');
2131             if (params.protocol) { help_btn.setAttribute('protocol', params.protocol); }
2132             if (params.hostname) { help_btn.setAttribute('hostname', params.hostname);  }
2133             if (params.port) { help_btn.setAttribute('port', params.port);  }
2134             if (params.pathname) { help_btn.setAttribute('pathname', params.pathname); }
2135             if (params.src) { help_btn.setAttribute('src', params.src); }
2136         }
2137     },
2138
2139     'tab_semaphores' : {},
2140
2141     'set_tab' : function(url,params,content_params) {
2142         var obj = this;
2143         if (!url) url = '/xul/server/';
2144         if (!url.match(/:\/\//) && !url.match(/^data:/)) url = urls.remote + url;
2145         if (!params) params = {};
2146         if (!content_params) content_params = {};
2147         var idx = this.controller.view.tabs.selectedIndex;
2148         if (params && typeof params.index != 'undefined') idx = params.index;
2149         var tab = this.controller.view.tabs.childNodes[ idx ];
2150
2151         var id = tab.getAttribute('id');
2152         if (id) {
2153             if (typeof obj.tab_semaphores[id] != 'undefined') {
2154                 if (obj.tab_semaphores[id] > 0) {
2155                     var confirmation = window.confirm(offlineStrings.getString('menu.replace_tab.unsaved_data_warning'));
2156                     if (!confirmation) { return; }
2157                     oils_unsaved_data_P( obj.tab_semaphores[id] );
2158                 }
2159                 delete obj.tab_semaphores[id];
2160             }
2161         }
2162         var unique_id = idx + ':' + new Date();
2163         tab.setAttribute('id',unique_id);
2164         if (params.focus) tab.focus();
2165         var panel = this.controller.view.panels.childNodes[ idx ];
2166         while ( panel.lastChild ) panel.removeChild( panel.lastChild );
2167
2168         content_params.lock_tab = function() { 
2169             dump('lock_tab\n');
2170             var id = tab.getAttribute('id');
2171             if (typeof obj.tab_semaphores[id] == 'undefined') {
2172                 obj.tab_semaphores[id] = 0;
2173             }
2174             obj.tab_semaphores[id]++; 
2175             oils_unsaved_data_V();
2176             return obj.tab_semaphores[id]; 
2177         };
2178         content_params.unlock_tab = function() { 
2179             dump('unlock_tab\n');
2180             var id = tab.getAttribute('id');
2181             if (typeof obj.tab_semaphores[id] == 'undefined') {
2182                 obj.tab_semaphores[id] = 0;
2183             }
2184             obj.tab_semaphores[id]--;
2185             if (obj.tab_semaphores[id] < 0) { obj.tab_semaphores[id] = 0; } 
2186             oils_unsaved_data_P();
2187             return obj.tab_semaphores[id]; 
2188         };
2189         content_params.inspect_tab = function() {
2190             var id = tab.getAttribute('id');
2191             return 'id = ' + id + ' semaphore = ' + obj.tab_semaphores[id];
2192         }
2193         content_params.new_tab = function(a,b,c) { return obj.new_tab(a,b,c); };
2194         content_params.set_tab = function(a,b,c) { return obj.set_tab(a,b,c); };
2195         content_params.close_tab = function() { return obj.close_tab(); };
2196         content_params.new_patron_tab = function(a,b) { return obj.new_patron_tab(a,b); };
2197         content_params.set_patron_tab = function(a,b) { return obj.set_patron_tab(a,b); };
2198         content_params.volume_item_creator = function(a) { return obj.volume_item_creator(a); };
2199         content_params.get_new_session = function(a) { return obj.get_new_session(a); };
2200         content_params.holdings_maintenance_tab = function(a,b,c) { return obj.holdings_maintenance_tab(a,b,c); };
2201         content_params.set_tab_name = function(name) { tab.label = tab.curindex + ' ' + name; tab.origlabel = name; };
2202         content_params.set_help_context = function(params) { return obj.set_help_context(params); };
2203         content_params.open_chrome_window = function(a,b,c) { return xulG.window.open(a,b,c); };
2204         content_params.url_prefix = function(url,secure) { return obj.url_prefix(url,secure); };
2205         content_params.network_meter = obj.network_meter;
2206         content_params.page_meter = obj.page_meter;
2207         content_params.get_barcode = obj.get_barcode;
2208         content_params.set_statusbar = function(slot,text,tooltiptext,click_handler) {
2209             var e = document.getElementById('statusbarpanel'+slot);
2210             if (e) {
2211                 var p = e.parentNode;
2212                 var sbp = document.createElement('statusbarpanel');
2213                 sbp.setAttribute('id','statusbarpanel'+slot);
2214                 p.replaceChild(sbp,e); // destroy and replace the statusbarpanel as a poor man's way of clearing event handlers
2215
2216                 sbp.setAttribute('label',text);
2217                 if (tooltiptext) {
2218                     sbp.setAttribute('tooltiptext',tooltiptext);
2219                 }
2220                 if (click_handler) {
2221                     sbp.addEventListener(
2222                         'click',
2223                         click_handler,
2224                         false
2225                     );
2226                 }
2227             }
2228         };
2229         content_params.chrome_xulG = xulG;
2230         content_params._data = xulG._data;
2231         if (params && params.tab_name) content_params.set_tab_name( params.tab_name );
2232         
2233         var frame;
2234         try {
2235             if (typeof params.browser == 'undefined') params.browser = false;
2236             if (params.browser) {
2237                 obj.id_incr++;
2238                 frame = this.w.document.createElement('browser');
2239                 frame.setAttribute('flex','1');
2240                 frame.setAttribute('type','content');
2241                 frame.setAttribute('autoscroll','false');
2242                 frame.setAttribute('id','frame_'+obj.id_incr);
2243                 panel.appendChild(frame);
2244                 try {
2245                     dump('creating browser with src = ' + url + '\n');
2246                     JSAN.use('util.browser');
2247                     var b = new util.browser();
2248                     b.init(
2249                         {
2250                             'url' : url,
2251                             'push_xulG' : true,
2252                             'alt_print' : false,
2253                             'browser_id' : 'frame_'+obj.id_incr,
2254                             'passthru_content_params' : content_params,
2255                         }
2256                     );
2257                 } catch(E) {
2258                     alert(E);
2259                 }
2260             } else {
2261                 frame = this.w.document.createElement('iframe');
2262                 frame.setAttribute('flex','1');
2263                 panel.appendChild(frame);
2264                 dump('creating iframe with src = ' + url + '\n');
2265                 frame.setAttribute('src',url);
2266                 try {
2267                     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
2268                     var cw = frame.contentWindow;
2269                     if (typeof cw.wrappedJSObject != 'undefined') cw = cw.wrappedJSObject;
2270                     cw.IAMXUL = true;
2271                     cw.xulG = content_params;
2272                     cw.addEventListener(
2273                         'load',
2274                         function() {
2275                             try {
2276                                 if (typeof cw.help_context_set_locally == 'undefined') {
2277                                     var help_params = {
2278                                         'protocol' : cw.location.protocol,
2279                                         'hostname' : cw.location.hostname,
2280                                         'port' : cw.location.port,
2281                                         'pathname' : cw.location.pathname,
2282                                         'src' : ''
2283                                     };
2284                                     obj.set_help_context(help_params);
2285                                 } else if (typeof cw.default_focus == 'function') {
2286                                     cw.default_focus();
2287                                 }
2288                             } catch(E) {
2289                                 obj.error.sdump('D_ERROR', 'main.menu, set_tab, onload: ' + E);
2290                             }
2291                             try {
2292                                 if (typeof params.on_tab_load == 'function') {
2293                                     params.on_tab_load(cw);
2294                                 }
2295                             } catch(E) {
2296                                 obj.error.sdump('D_ERROR', 'main.menu, set_tab, onload #2: ' + E);
2297                             }
2298                         },
2299                         false
2300                     );
2301                 } catch(E) {
2302                     this.error.sdump('D_ERROR', 'main.menu: ' + E);
2303                 }
2304             }
2305         } catch(E) {
2306             this.error.sdump('D_ERROR', 'main.menu:2: ' + E);
2307             alert(offlineStrings.getString('menu.set_tab.error'));
2308         }
2309
2310         return frame;
2311     },
2312
2313     'get_barcode' : function(window, context, barcode) {
2314         JSAN.use('util.network');
2315         JSAN.use('util.sound');
2316
2317         // Depending on where we were called from data can be found in multiple ways
2318         var data;
2319         if(this.data) data = this.data;
2320         else if(xulG.data) data = xulG.data;        
2321         else {
2322             JSAN.use('util.data');
2323             data = new util.data();
2324         }
2325         data.stash_retrieve();
2326
2327         var network = new util.network();
2328         var sound = new util.sound();
2329
2330         // Should return an array. Or an error.
2331         var r = network.simple_request('GET_BARCODES', [ ses(), data.list.au[0].ws_ou(), context, barcode ]);
2332
2333         if(!r) // Nothing?
2334             return false;
2335
2336         // Top-level error, likely means bad session or no STAFF_LOGIN permission.
2337         if(typeof r.ilsevent != 'undefined') {
2338             // Hand it off to the caller.
2339             return r;
2340         }
2341
2342         // No results? Return false
2343         if(r.length == 0) return false;
2344
2345         // One result?
2346         if(r.length == 1) {
2347             // Return it. If it is an error the caller should deal with it.
2348             return r[0];
2349         }
2350
2351         // At this point we have more than one result.
2352         // Check to see what we got.
2353         var result_filter = {};
2354         var valid_r = [];
2355         var unique_count = 0;
2356         var found_errors = false;
2357         var errors = '';
2358         var len = r.length;
2359
2360         // Check each result.
2361         for(var i = 0; i < len; ++i) {
2362             // If it is an error
2363             if(typeof r[i].ilsevent != 'undefined') {
2364                 // Make note that we found errors
2365                 found_errors = true;
2366                 // Grab the error into a string
2367                 errors += js2JSON(r[i]);
2368             }
2369             else {
2370                 // Otherwise, record the type/id combo for later
2371                 var type = r[i].type;
2372                 var id = r[i].id;
2373                 var barcode = r[i].barcode;
2374                 if(!result_filter[type]) result_filter[type] = {};
2375                 if(!result_filter[type][id]) {
2376                     unique_count++;
2377                     result_filter[type][id] = [];
2378                 }
2379                 result_filter[type][id].push(barcode);
2380                 valid_r.push(r[i]);
2381             }
2382         }
2383
2384         // Only errors? Return the first one.
2385         if(unique_count == 0 && found_errors == true) {
2386             return r[0];
2387         }
2388
2389         // No errors, one (unique) result? Return it.
2390         if(unique_count == 1 && found_errors == false) return valid_r[0];
2391
2392         // For possible debugging, dump the errors.
2393         if(found_errors) dump(errors);
2394
2395         // Still here? Must need to have the user pick.
2396         if(!xulG.url_prefix) xulG.url_prefix = url_prefix; // Make util.window happy
2397         JSAN.use('util.window');
2398         var win = new util.window();
2399         var url = url_prefix(urls.XUL_FANCY_PROMPT);
2400         var title = offlineStrings.getString('barcode_choice.title');
2401         var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml" flex="1">';
2402         xml += '<groupbox flex="1" style="overflow: auto; border: solid thin;"><caption label="' + title + '"/>';
2403         xml += '<description style="-moz-user-select: text; -moz-user-focus: normal; font-size: large">' + offlineStrings.getString('barcode_choice.prompt') + '</description>';
2404         if(found_errors) // Let the user know that one or more possible answers errored out.
2405             xml += '<description style="-moz-user=select: text; -moz-user-focus: normal; font-size: large">' + offlineStrings.getString('barcode_choice.errors_found') + '</description>';
2406         xml += '</groupbox><groupbox><caption label="' + offlineStrings.getString('barcode_choice.choice_label') + '"/><vbox>';
2407
2408         len = valid_r.length;
2409         // Look at all the non-error answers we got
2410         for(var i = 0; i < len; ++i) {
2411             // If we still have a filtered answer, display a button.
2412             if(result_filter[valid_r[i].type][valid_r[i].id]) {
2413                 var result_data = false;
2414                 var barcodes = result_filter[valid_r[i].type][valid_r[i].id];
2415                 var barcodes_assembled = barcodes.shift();
2416                 var button_label = '';
2417                 while(barcodes.length > 0) // Join any secondary barcodes found together
2418                     barcodes_assembled = offlineStrings.getFormattedString('barcode_choice.join_barcodes', [barcodes_assembled, barcodes.shift()]);
2419                 switch(r[i].type) {
2420                     case 'actor':
2421                         result_data = network.simple_request('BLOB_AU_PARTS_RETRIEVE',
2422                             [ ses() , valid_r[i].id, ['family_name', 'first_given_name', 'second_given_name', 'home_ou' ] ]);
2423                         button_label = offlineStrings.getFormattedString('barcode_choice.actor',
2424                             [barcodes_assembled, result_data[0], result_data[1] + (result_data[2] ? ' ' + result_data[2] : ''), data.hash.aou[ result_data[3] ].name(), data.hash.aou[ result_data[3] ].shortname()]);
2425                         break;
2426                     case 'booking':
2427                         result_data = network.simple_request('FM_ACP_DETAILS_VIA_BARCODE', [ ses(), valid_r[i].barcode ]);
2428                         // Note: This falls through intentionally.
2429                     case 'asset':
2430                     case 'serial':
2431                         if(!result_data) // If we fell through this should be set already.
2432                             result_data = network.simple_request('FM_ACP_DETAILS', [ ses(), valid_r[i].id ]);
2433                         button_label = offlineStrings.getFormattedString('barcode_choice.asset',
2434                             [barcodes_assembled, result_data.mvr.title(), data.hash.aou[ result_data.copy.circ_lib() ].name(), data.hash.aou[ result_data.copy.circ_lib() ].shortname()]);
2435                         break;
2436                 }
2437                 r[i].data = result_data;
2438
2439                 // This ensures we only show each unique id once
2440                 delete result_filter[valid_r[i].type][valid_r[i].id];
2441
2442                 // If we have more than one context this should label each entry with where it came from
2443                 // Likely most useful for distinguishing assets from bookings
2444                 if(context != valid_r[i].type && offlineStrings.testString('barcode_choice.' + valid_r[i].type + '_label'))
2445                     button_label = offlineStrings.getFormattedString('barcode_choice.' + valid_r[i].type + '_label', [button_label]);
2446
2447                 xml += '<button label="' + button_label + '" name="fancy_submit" value="' + i + '"/>';
2448             }
2449         }
2450         xml += '<button label="' + offlineStrings.getString('barcode_choice.none') + '" name="fancy_cancel"/>';
2451         xml += '</vbox></groupbox></vbox>';
2452         var fancy_prompt_data = win.open( url, 'fancy_prompt', 'chrome,resizable,modal,width=500,height=500', { 'xml' : xml, 'title' : title, 'sound' : 'bad' } );
2453         if(fancy_prompt_data.fancy_status == 'complete')
2454             return valid_r[fancy_prompt_data.fancy_submit];
2455         else
2456             // user_false is used to indicate the user said "None of the above" to avoid fall-through erroring later.
2457             return "user_false";
2458     },
2459
2460     'observe' : function(subject, topic, data) {
2461         if (topic != "nsPref:changed") {
2462             return;
2463         }
2464
2465         switch(data) {
2466             case 'oils.copy_editor.copy_location_name_first':
2467                 var cl_first = xulG.pref.getBoolPref('oils.copy_editor.copy_location_name_first');
2468                 var menuitems = document.getElementsByAttribute('command','cmd_copy_editor_copy_location_first_toggle');
2469                 for(var i = 0; i < menuitems.length; i++)
2470                     menuitems[i].setAttribute('checked', cl_first ? 'true' : 'false');
2471             break;
2472         }
2473     },
2474
2475     'stop_observing' : function() {
2476         xulG.pref.removeObserver('oils.copy_editor.*', this);
2477     }
2478 }
2479
2480 dump('exiting main/menu.js\n');