Booking: This should a) make booking interfaces behave better when a staff
[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     'url_prefix' : function(url) {
37         if (url.match(/^\//)) url = urls.remote + url;
38         if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
39         dump('url_prefix = ' + url + '\n');
40         return url;
41     },
42
43     'init' : function( params ) {
44
45         var obj = this;
46
47         urls.remote = params['server'];
48
49         // Pull in local customizations
50         var r = new XMLHttpRequest();
51         r.open("GET", obj.url_prefix('/xul/server/skin/custom.js'), false);
52         r.send(null);
53         if (r.status == 200) {
54             dump('Evaluating /xul/server/skin/custom.js\n');
55             eval( r.responseText );
56         }
57
58         var button_bar = String( obj.data.hash.aous['ui.general.button_bar'] ) == 'true';
59         if (button_bar) {
60             var x = document.getElementById('main_toolbar');
61             if (x) x.setAttribute('hidden','false');
62         }
63
64         var network_meter = String( obj.data.hash.aous['ui.network.progress_meter'] ) == 'true';
65         if (! network_meter) {
66             var x = document.getElementById('network_progress');
67             if (x) x.setAttribute('hidden','true');
68             var y = document.getElementById('page_progress');
69             if (y) y.setAttribute('hidden','true');
70         }
71
72         function open_conify_page(path, labelKey) {
73
74             // tab label
75             labelKey = labelKey || 'menu.cmd_open_conify.tab';
76             label = offlineStrings.getString(labelKey);
77
78             // URL
79             var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.CONIFY) + '/' + path + '.html');
80
81             obj.set_tab( 
82                 loc, 
83                 {'tab_name' : label, 'browser' : false }, 
84                 {'no_xulG' : false, 'show_print_button' : false, show_nav_buttons:true} 
85             );
86         }
87
88         function open_admin_page(path, labelKey, addSes) {
89
90             // tab label
91             labelKey = labelKey || 'menu.cmd_open_conify.tab';
92             label = offlineStrings.getString(labelKey);
93
94             // URL
95             var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.XUL_LOCAL_ADMIN_BASE) + '/' + path);
96             if(addSes) loc += window.escape('?ses=' + ses());
97
98             obj.set_tab( 
99                 loc, 
100                 {'tab_name' : label, 'browser' : false }, 
101                 {'no_xulG' : false, 'show_print_button' : true, 'show_nav_buttons' : true } 
102             );
103         }
104
105
106         function open_eg_web_page(path, labelKey) {
107             
108             // tab label
109             labelKey = labelKey || 'menu.cmd_open_conify.tab';
110             var label = offlineStrings.getString(labelKey);
111
112             // URL
113             var loc = urls.XUL_BROWSER + '?url=' + window.escape(obj.url_prefix(urls.EG_WEB_BASE) + '/' + path);
114
115             obj.set_tab( 
116                 loc, 
117                 {tab_name : label, browser : false }, 
118                 {no_xulG : false, show_print_button : true, show_nav_buttons : true }
119             );
120         }
121
122         var cmd_map = {
123             'cmd_broken' : [
124                 ['oncommand'],
125                 function() { alert(offlineStrings.getString('common.unimplemented')); }
126             ],
127
128             /* File Menu */
129             'cmd_close_window' : [ 
130                 ['oncommand'], 
131                 function() {
132                     JSAN.use('util.widgets');
133                     util.widgets.dispatch('close',window);
134                 }
135             ],
136             'cmd_new_window' : [
137                 ['oncommand'],
138                 function() {
139                     var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
140                         getService(Components.interfaces.nsIWindowMediator);
141                     wm.getMostRecentWindow('eg_main').new_tabs(Array('new'));
142                 }
143             ],
144             'cmd_new_tab' : [
145                 ['oncommand'],
146                 function() {
147                     if (obj.new_tab(null,{'focus':true},null) == false)
148                     {
149                         if(window.confirm(offlineStrings.getString('menu.new_tab.max_tab_dialog')))
150                         {
151                             var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
152                                 getService(Components.interfaces.nsIWindowMediator);
153                             wm.getMostRecentWindow('eg_main').new_tabs(Array('tab'));
154                         }
155                     }
156                 }
157             ],
158             'cmd_close_tab' : [
159                 ['oncommand'],
160                 function() { obj.close_tab(); }
161             ],
162             'cmd_close_all_tabs' : [
163                 ['oncommand'],
164                 function() { obj.close_all_tabs(); }
165             ],
166
167             /* Edit Menu */
168             'cmd_edit_copy_buckets' : [
169                 ['oncommand'],
170                 function() {
171                     obj.data.stash_retrieve();
172                     obj.set_tab(obj.url_prefix(urls.XUL_COPY_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_copy_buckets.tab')},{});
173                 }
174             ],
175             'cmd_edit_volume_buckets' : [
176                 ['oncommand'],
177                 function() {
178                     obj.data.stash_retrieve();
179                     obj.set_tab(obj.url_prefix(urls.XUL_VOLUME_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_volume_buckets.tab')},{});
180                 }
181             ],
182             'cmd_edit_record_buckets' : [
183                 ['oncommand'],
184                 function() {
185                     obj.data.stash_retrieve();
186                     obj.set_tab(obj.url_prefix(urls.XUL_RECORD_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_record_buckets.tab')},{});
187                 }
188             ],
189             'cmd_edit_user_buckets' : [
190                 ['oncommand'],
191                 function() {
192                     obj.data.stash_retrieve();
193                     obj.set_tab(obj.url_prefix(urls.XUL_USER_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_user_buckets.tab')},{});
194                 }
195             ],
196
197
198             'cmd_replace_barcode' : [
199                 ['oncommand'],
200                 function() {
201                     try {
202                         JSAN.use('util.network');
203                         var network = new util.network();
204
205                         var old_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.label'));
206                         if (!old_bc) return;
207     
208                         var copy;
209                         try {
210                             copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
211                             if (typeof copy.ilsevent != 'undefined') throw(copy); 
212                             if (!copy) throw(copy);
213                         } catch(E) {
214                             alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.retrieval.error', [old_bc]) + '\n');
215                             return;
216                         }
217     
218                         // Why did I want to do this twice?  Because this copy is more fleshed?
219                         try {
220                             copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
221                             if (typeof copy.ilsevent != 'undefined') throw(copy);
222                             if (!copy) throw(copy);
223                         } catch(E) {
224                             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); }
225                             return;
226                         }
227     
228                         var new_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.replacement.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.replacement.label'));
229                         new_bc = String( new_bc ).replace(/\s/g,'');
230                         /* Casting a possibly null input value to a String turns it into "null" */
231                         if (!new_bc || new_bc == 'null') {
232                             alert(offlineStrings.getString('menu.cmd_replace_barcode.blank.error'));
233                             return;
234                         }
235     
236                         var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ new_bc ]);
237                         if (typeof test.ilsevent == 'undefined') {
238                             alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.duplicate.error', [new_bc]));
239                             return;
240                         } else {
241                             if (test.ilsevent != 1502 /* ASSET_COPY_NOT_FOUND */) {
242                                 obj.error.standard_unexpected_error_alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.testing.error', [new_bc]),test);
243                                 return;
244                             }    
245                         }
246
247                         copy.barcode(new_bc); copy.ischanged('1');
248                         var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
249                         if (typeof r.ilsevent != 'undefined') { 
250                             if (r.ilsevent != 0) {
251                                 if (r.ilsevent == 5000 /* PERM_FAILURE */) {
252                                     alert(offlineStrings.getString('menu.cmd_replace_barcode.permission.error'));
253                                 } else {
254                                     obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.error'),r);
255                                 }
256                             }
257                         }
258                     } catch(E) {
259                         obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.failure'),copy);
260                     }
261                 }
262             ],
263
264             /* Search Menu */
265             'cmd_patron_search' : [
266                 ['oncommand'],
267                 function(event) {
268                     obj.set_patron_tab({},{},event);
269                 }
270             ],
271             'cmd_search_opac' : [
272                 ['oncommand'],
273                 function(event) {
274                     obj.data.stash_retrieve();
275                     var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
276                     obj.command_tab(event,obj.url_prefix(urls.XUL_OPAC_WRAPPER), {'tab_name':offlineStrings.getString('menu.cmd_search_opac.tab')}, content_params);
277                 }
278             ],
279             'cmd_search_tcn' : [
280                 ['oncommand'],
281                 function() {
282                     var tcn = prompt(offlineStrings.getString('menu.cmd_search_tcn.tab'),'',offlineStrings.getString('menu.cmd_search_tcn.prompt'));
283
284                     function spawn_tcn(r) {
285                         for (var i = 0; i < r.count; i++) {
286                             var id = r.ids[i];
287                             var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + id;
288                             obj.data.stash_retrieve();
289                             var content_params = { 
290                                 'session' : ses(), 
291                                 'authtime' : ses('authtime'),
292                                 'opac_url' : opac_url,
293                             };
294                             if (i == 0) {
295                                 obj.set_tab(
296                                     obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
297                                     {'tab_name':tcn}, 
298                                     content_params
299                                 );
300                             } else {
301                                 obj.new_tab(
302                                     obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
303                                     {'tab_name':tcn}, 
304                                     content_params
305                                 );
306                             }
307                         }
308                     }
309
310                     if (tcn) {
311                         JSAN.use('util.network');
312                         var network = new util.network();
313                         var robj = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn]);
314                         if (robj.count != robj.ids.length) throw('FIXME -- FM_BRE_ID_SEARCH_VIA_TCN = ' + js2JSON(robj));
315                         if (robj.count == 0) {
316                             var robj2 = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn,1]);
317                             if (robj2.count == 0) {
318                                 alert(offlineStrings.getFormattedString('menu.cmd_search_tcn.not_found.error', [tcn]));
319                             } else {
320                                 if ( window.confirm(offlineStrings.getFormattedString('menu.cmd_search_tcn.deleted.error', [tcn])) ) {
321                                     spawn_tcn(robj2);
322                                 }
323                             }
324                         } else {
325                             spawn_tcn(robj);
326                         }
327                     }
328                 }
329             ],
330             'cmd_search_bib_id' : [
331                 ['oncommand'],
332                 function() {
333                     var bib_id = prompt(offlineStrings.getString('menu.cmd_search_bib_id.tab'),'',offlineStrings.getString('menu.cmd_search_bib_id.prompt'));
334                     if (!bib_id) return;
335
336                     var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + bib_id;
337                     var content_params = { 
338                         'session' : ses(), 
339                         'authtime' : ses('authtime'),
340                         'opac_url' : opac_url,
341                     };
342                     obj.set_tab(
343                         obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
344                         {'tab_name':'#' + bib_id}, 
345                         content_params
346                     );
347                 }
348             ],
349             'cmd_copy_status' : [
350                 ['oncommand'],
351                 function(event) {
352                     obj.data.stash_retrieve();
353                     obj.command_tab(event,obj.url_prefix(urls.XUL_COPY_STATUS),{},{});
354                 }
355             ],
356
357             /* Circulation Menu */
358             'cmd_patron_register' : [
359                 ['oncommand'],
360                 function(event) {
361
362                     function log_registration(p) {
363                         try {
364                             obj.error.work_log(
365                                 document.getElementById('offlineStrings').getFormattedString(
366                                     'staff.circ.work_log_patron_registration.message',
367                                     [
368                                         ses('staff_usrname'),
369                                         p.family_name(),
370                                         p.card().barcode()
371                                     ]
372                                 ), {
373                                     'au_id' : p.id(),
374                                     'au_family_name' : p.family_name(),
375                                     'au_barcode' : p.card().barcode()
376                                 }
377                             );
378                         } catch(E) {
379                             obj.error.sdump('D_ERROR','Error with work_logging in menu.js, cmd_patron_register:' + E);
380                         }
381                     }
382
383                     function spawn_editor(p) {
384                         var url = urls.XUL_PATRON_EDIT;
385                         var param_count = 0;
386                         for (var i in p) {
387                             if (param_count++ == 0) url += '?'; else url += '&';
388                             url += i + '=' + window.escape(p[i]);
389                         }
390                         var loc = obj.url_prefix( urls.XUL_BROWSER ) + '?url=' + window.escape( obj.url_prefix(url) );
391                         obj.new_tab(
392                             loc, 
393                             {}, 
394                             { 
395                                 'show_print_button' : true , 
396                                 'tab_name' : offline.getString('menu.cmd_patron_register.related.tab'),
397                                 'passthru_content_params' : {
398                                     'spawn_search' : function(s) { obj.spawn_search(s); },
399                                     'spawn_editor' : spawn_editor,
400                                     'on_save' : function(p) { log_registration(p); }
401                                 }
402                             }
403                         );
404                     }
405
406                     obj.data.stash_retrieve();
407                     var loc = obj.url_prefix( urls.XUL_BROWSER ) 
408                         + '?url=' + window.escape( obj.url_prefix(urls.XUL_PATRON_EDIT) );
409                     obj.command_tab(
410                         event,
411                         loc, 
412                         {}, 
413                         { 
414                             'show_print_button' : true , 
415                             'tab_name' : offlineStrings.getString('menu.cmd_patron_register.tab'),
416                             'passthru_content_params' : {
417                                 'ses' : ses(),
418                                 'spawn_search' : function(s) { obj.spawn_search(s); },
419                                 'spawn_editor' : spawn_editor,
420                                 'on_save' : function(p) { log_registration(p); }
421                             }
422                         }
423                     );
424                 }
425             ],
426             'cmd_staged_patrons' : [
427                 ['oncommand'],
428                 function() {
429                     obj.data.stash_retrieve();
430                     obj.set_tab(obj.url_prefix(urls.XUL_STAGED_PATRONS),{'tab_name':offlineStrings.getString('menu.circulation.staged_patrons.tab')},{});
431                 }
432             ],
433             'cmd_circ_checkin' : [
434                 ['oncommand'],
435                 function(event) { 
436                     obj.data.stash_retrieve();
437                     obj.command_tab(event,obj.url_prefix(urls.XUL_CHECKIN),{},{});
438                 }
439             ],
440             'cmd_circ_renew' : [
441                 ['oncommand'],
442                 function() { 
443                     obj.data.stash_retrieve();
444                     obj.set_tab(obj.url_prefix(urls.XUL_RENEW),{},{});
445                 }
446             ],
447             'cmd_circ_checkout' : [
448                 ['oncommand'],
449                 function(event) { 
450                     obj.data.stash_retrieve();
451                     obj.command_tab(event,obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY),{},{});
452                 }
453             ],
454             'cmd_circ_hold_capture' : [
455                 ['oncommand'],
456                 function() { 
457                     obj.data.stash_retrieve();
458                     obj.set_tab(obj.url_prefix(urls.XUL_CHECKIN)+'?hold_capture=1',{},{});
459                 }
460             ],
461             'cmd_browse_holds' : [
462                 ['oncommand'],
463                 function() { 
464                     obj.data.stash_retrieve();
465                     obj.set_tab(obj.url_prefix(urls.XUL_HOLDS_BROWSER),{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds.tab') },{});
466                 }
467             ],
468             'cmd_browse_holds_shelf' : [
469                 ['oncommand'],
470                 function() { 
471                     obj.data.stash_retrieve();
472                     obj.set_tab(obj.url_prefix(urls.XUL_HOLDS_BROWSER)+'?shelf=1',{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds_shelf.tab') },{});
473                 }
474             ],
475             'cmd_circ_hold_pull_list' : [
476                 ['oncommand'],
477                 function() { 
478                     obj.data.stash_retrieve();
479                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
480                         obj.url_prefix(urls.XUL_HOLD_PULL_LIST)
481                     );
482                     obj.set_tab( loc, {'tab_name' : offlineStrings.getString('menu.cmd_browse_hold_pull_list.tab')}, { 'show_print_button' : true } );
483                 }
484             ],
485
486             'cmd_in_house_use' : [
487                 ['oncommand'],
488                 function() { 
489                     obj.data.stash_retrieve();
490                     obj.set_tab(obj.url_prefix(urls.XUL_IN_HOUSE_USE),{},{});
491                 }
492             ],
493
494             'cmd_scan_item_as_missing_pieces' : [
495                 ['oncommand'],
496                 function() { 
497                     xulG.window.open(obj.url_prefix(urls.XUL_SCAN_ITEM_AS_MISSING_PIECES),'scan_missing_pieces','chrome'); 
498                 }
499             ],
500
501             'cmd_standalone' : [
502                 ['oncommand'],
503                 function() { 
504                     //obj.set_tab(obj.url_prefix(urls.XUL_STANDALONE),{},{});
505                     window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
506                 }
507             ],
508
509             'cmd_local_admin' : [
510                 ['oncommand'],
511                 function() { 
512                     //obj.set_tab(obj.url_prefix(urls.XUL_LOCAL_ADMIN)+'?ses='+window.escape(ses())+'&session='+window.escape(ses()),{},{});
513                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
514                         obj.url_prefix( urls.XUL_LOCAL_ADMIN+'?ses='+window.escape(ses())+'&session='+window.escape(ses()) )
515                     );
516                     obj.set_tab( 
517                         loc, 
518                         {'tab_name' : offlineStrings.getString('menu.cmd_local_admin.tab'), 'browser' : false }, 
519                         { 'no_xulG' : false, 'show_nav_buttons' : true, 'show_print_button' : true } 
520                     );
521
522                 }
523             ],
524
525             'cmd_toggle_buttonbar' : [
526                 ['oncommand'],
527                 function() {
528                     var x = document.getElementById('main_toolbar');
529                     if (x) x.hidden = ! x.hidden;
530                 }
531             ],
532
533             'cmd_toggle_meters' : [
534                 ['oncommand'],
535                 function() {
536                     var x = document.getElementById('network_progress');
537                     if (x) x.hidden = ! x.hidden;
538                     var y = document.getElementById('page_progress');
539                     if (y) y.hidden = ! y.hidden;
540                 }
541             ],
542
543             'cmd_local_admin_reports' : [
544                 ['oncommand'],
545                 function() { 
546                     var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.XUL_REPORTS) + '?ses=' + ses());
547                     obj.set_tab( 
548                         loc, 
549                         {'tab_name' : offlineStrings.getString('menu.cmd_local_admin_reports.tab'), 'browser' : false }, 
550                         {'no_xulG' : false, 'show_print_button' : false, show_nav_buttons : true } 
551                     );
552                 }
553             ],
554             'cmd_open_vandelay' : [
555                 ['oncommand'],
556                 function() { open_eg_web_page('vandelay/vandelay'); }
557             ],
558             'cmd_local_admin_transit_list' : [
559                 ['oncommand'],
560                 function() { open_admin_page('transit_list.xul', 'menu.cmd_local_admin_transit_list.tab'); }
561             ],
562             'cmd_local_admin_age_overdue_circulations_to_lost' : [
563                 ['oncommand'],
564                 function() { open_admin_page('circ_age_to_lost.xul', 'menu.cmd_local_admin_age_overdue_circulations_to_lost.tab', true); }
565             ],
566             'cmd_local_admin_cash_reports' : [
567                 ['oncommand'],
568                 function() { open_admin_page('cash_reports.xhtml', 'menu.cmd_local_admin_cash_reports.tab', true); }
569             ],
570             'cmd_local_admin_fonts_and_sounds' : [
571                 ['oncommand'],
572                 function() { open_admin_page('font_settings.xul', 'menu.cmd_local_admin_fonts_and_sounds.tab'); }
573             ],
574             'cmd_local_admin_printer' : [
575                 ['oncommand'],
576                 function() { open_admin_page('printer_settings.html', 'menu.cmd_local_admin_printer.tab', true); }
577             ],
578             'cmd_local_admin_do_not_auto_attempt_print_setting' : [
579                 ['oncommand'],
580                 function() { 
581                     obj.set_tab(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')},{});
582                 }
583             ],
584             'cmd_local_admin_closed_dates' : [
585                 ['oncommand'],
586                 function() { open_admin_page('closed_dates.xhtml', 'menu.cmd_local_admin_closed_dates.tab', true); }
587             ],
588             'cmd_local_admin_copy_locations' : [
589                 ['oncommand'],
590                 function() { open_admin_page('copy_locations.xhtml', 'menu.cmd_local_admin_copy_locations.tab', true); }
591             ],
592             'cmd_local_admin_lib_settings' : [
593                 ['oncommand'],
594                 function() { open_admin_page('org_unit_settings.xhtml', 'menu.cmd_local_admin_lib_settings.tab', true); }
595             ],
596             'cmd_local_admin_non_cat_types' : [
597                 ['oncommand'],
598                 function() { open_admin_page('non_cat_types.xhtml', 'menu.cmd_local_admin_non_cat_types.tab', true); }
599             ],
600             'cmd_local_admin_stat_cats' : [
601                 ['oncommand'],
602                 function() { open_admin_page('stat_cat_editor.xhtml', 'menu.cmd_local_admin_stat_cats.tab', true); }
603             ],
604             'cmd_local_admin_standing_penalty' : [
605                 ['oncommand'],
606                 function() { open_eg_web_page('conify/global/config/standing_penalty'); }
607             ],
608             'cmd_local_admin_grp_penalty_threshold' : [
609                 ['oncommand'],
610                 function() { open_eg_web_page('conify/global/permission/grp_penalty_threshold'); }
611             ],
612             'cmd_server_admin_config_rule_circ_duration' : [
613                 ['oncommand'],
614                 function() { open_eg_web_page('conify/global/config/rule_circ_duration'); }
615             ],
616             'cmd_server_admin_config_hard_due_date' : [
617                 ['oncommand'],
618                 function() { open_eg_web_page('conify/global/config/hard_due_date'); }
619             ],
620             'cmd_server_admin_config_rule_recurring_fine' : [
621                 ['oncommand'],
622                 function() { open_eg_web_page('conify/global/config/rule_recurring_fine'); }
623             ],
624             'cmd_server_admin_config_rule_max_fine' : [
625                 ['oncommand'],
626                 function() { open_eg_web_page('conify/global/config/rule_max_fine'); }
627             ],
628             'cmd_server_admin_config_rule_age_hold_protect' : [
629                 ['oncommand'],
630                 function() { open_eg_web_page('conify/global/config/rule_age_hold_protect'); }
631             ],
632             'cmd_server_admin_config_circ_weights' : [
633                 ['oncommand'],
634                 function() { open_eg_web_page('conify/global/config/circ_matrix_weights'); }
635             ],
636             'cmd_server_admin_config_hold_weights' : [
637                 ['oncommand'],
638                 function() { open_eg_web_page('conify/global/config/hold_matrix_weights'); }
639             ],
640             'cmd_server_admin_config_weight_assoc' : [
641                 ['oncommand'],
642                 function() { open_eg_web_page('conify/global/config/weight_assoc'); }
643             ],
644             'cmd_local_admin_external_text_editor' : [
645                 ['oncommand'],
646                 function() {
647                     var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
648                     var key = 'oils.text_editor.external.cmd';
649                     var has_key = prefs.prefHasUserValue(key);
650                     var value = has_key ? prefs.getCharPref(key) : 'C:\\Windows\\notepad.exe %letter.txt%';
651                     var cmd = window.prompt(
652                         document.getElementById('offlineStrings').getString('text_editor.prompt_for_external_cmd'),
653                         value
654                     );
655                     if (!cmd) { return; }
656                     prefs.setCharPref(key,cmd);
657                 }
658             ],
659             'cmd_local_admin_idl_field_doc' : [
660                 ['oncommand'],
661                 function() { open_eg_web_page('conify/global/config/idl_field_doc'); }
662             ],
663             'cmd_local_admin_action_trigger' : [
664                 ['oncommand'],
665                 function() { open_eg_web_page('conify/global/action_trigger/event_definition'); }
666             ],
667             'cmd_local_admin_survey' : [
668                 ['oncommand'],
669                 function() { open_eg_web_page('conify/global/action/survey'); }
670             ],
671             'cmd_local_admin_circ_matrix_matchpoint' : [
672                 ['oncommand'],
673                 function() { open_eg_web_page('conify/global/config/circ_matrix_matchpoint', 
674                     'menu.local_admin.circ_matrix_matchpoint.tab'); }
675             ],
676             'cmd_local_admin_hold_matrix_matchpoint' : [
677                 ['oncommand'],
678                 function() { open_eg_web_page('conify/global/config/hold_matrix_matchpoint', 
679                     'menu.local_admin.hold_matrix_matchpoint.tab'); }
680             ],
681             'cmd_local_admin_copy_location_order' : [
682                 ['oncommand'],
683                 function() { open_eg_web_page('conify/global/asset/copy_location_order'); }
684             ],
685             'cmd_local_admin_work_log' : [
686                 ['oncommand'],
687                 function() { 
688                     obj.set_tab(
689                         urls.XUL_WORK_LOG,
690                         { 'tab_name' : offlineStrings.getString('menu.local_admin.work_log.tab') },
691                         {}
692                     );
693                 }
694             ],
695             "cmd_local_admin_copy_template": [
696                 ["oncommand"],
697                 function() {
698                     open_eg_web_page("conify/global/asset/copy_template");
699                 }
700             ],
701             'cmd_local_admin_patrons_due_refunds' : [
702                 ['oncommand'],
703                 function() {
704                     obj.set_tab(
705                         obj.url_prefix(urls.XUL_PATRONS_DUE_REFUNDS),
706                         { 'tab_name' : offlineStrings.getString('menu.local_admin.patrons_due_refunds.tab') },
707                         {}
708                     );
709                 }
710             ],
711             'cmd_server_admin_org_type' : [
712                 ['oncommand'],
713                 function() { open_conify_page('actor/org_unit_type', null); }
714             ],
715             'cmd_server_admin_org_unit' : [
716                 ['oncommand'],
717                 function() { open_conify_page('actor/org_unit', null); }
718             ],
719             'cmd_server_admin_grp_tree' : [
720                 ['oncommand'],
721                 function() { open_conify_page('permission/grp_tree', null); }
722             ],
723             'cmd_server_admin_perm_list' : [
724                 ['oncommand'],
725                 function() { open_conify_page('permission/perm_list', null); }
726             ],
727             'cmd_server_admin_copy_status' : [
728                 ['oncommand'],
729                 function() { open_conify_page('config/copy_status', null); }
730             ],
731             'cmd_server_admin_marc_code' : [
732                 ['oncommand'],
733                 function() { open_eg_web_page('conify/global/config/record_attr_definition'); }
734             ],
735             'cmd_server_admin_coded_value_map' : [
736                 ['oncommand'],
737                 function() { open_eg_web_page('conify/global/config/coded_value_map'); }
738             ],
739             'cmd_server_admin_acn_prefix' : [
740                 ['oncommand'],
741                 function() { open_eg_web_page('conify/global/config/acn_prefix'); }
742             ],
743             'cmd_server_admin_acn_suffix' : [
744                 ['oncommand'],
745                 function() { open_eg_web_page('conify/global/config/acn_suffix'); }
746             ],
747             'cmd_server_admin_billing_type' : [
748                 ['oncommand'],
749                 function() { open_eg_web_page('conify/global/config/billing_type'); }
750             ],
751             'cmd_server_admin_acq_invoice_item_type' : [
752                 ['oncommand'],
753                 function() { open_eg_web_page('conify/global/acq/invoice_item_type'); }
754             ],
755             'cmd_server_admin_acq_invoice_payment_method' : [
756                 ['oncommand'],
757                 function() { open_eg_web_page('conify/global/acq/invoice_payment_method'); }
758             ],
759             'cmd_server_admin_acq_lineitem_alert' : [
760                 ['oncommand'],
761                 function() { open_eg_web_page('conify/global/acq/lineitem_alert'); }
762             ],
763             'cmd_server_admin_acq_lineitem_marc_attr_def' : [
764                 ['oncommand'],
765                 function() { open_eg_web_page('conify/global/acq/lineitem_marc_attr_def'); }
766             ],
767             'cmd_server_admin_acq_fund_tag' : [
768                 ['oncommand'],
769                 function() { open_eg_web_page('conify/global/acq/fund_tag'); }
770             ],
771             'cmd_server_admin_acq_cancel_reason' : [
772                 ['oncommand'],
773                 function() { open_eg_web_page('conify/global/acq/cancel_reason'); }
774             ],
775             'cmd_server_admin_acq_claim_type' : [
776                 ['oncommand'],
777                 function() { open_eg_web_page('conify/global/acq/claim_type'); }
778             ],
779             'cmd_server_admin_acq_claim_event_type' : [
780                 ['oncommand'],
781                 function() { open_eg_web_page('conify/global/acq/claim_event_type'); }
782             ],
783             'cmd_server_admin_acq_claim_policy' : [
784                 ['oncommand'],
785                 function() { open_eg_web_page('conify/global/acq/claim_policy'); }
786             ],
787             'cmd_server_admin_acq_claim_policy_action' : [
788                 ['oncommand'],
789                 function() { open_eg_web_page('conify/global/acq/claim_policy_action'); }
790             ],
791             'cmd_server_admin_acq_fund' : [
792                 ['oncommand'],
793                 function() { open_eg_web_page('acq/fund/list'); }
794             ],
795             'cmd_server_admin_acq_funding_source' : [
796                 ['oncommand'],
797                 function() { open_eg_web_page('acq/funding_source/list'); }
798             ],
799             'cmd_server_admin_acq_provider' : [
800                 ['oncommand'],
801                 function() { open_eg_web_page('conify/global/acq/provider'); }
802             ],
803             'cmd_server_admin_acq_edi_account' : [
804                 ['oncommand'],
805                 function() { open_eg_web_page('conify/global/acq/edi_account'); }
806             ],
807             'cmd_server_admin_acq_edi_message' : [
808                 ['oncommand'],
809                 function() { open_eg_web_page('acq/po/edi_messages'); }
810             ],
811             'cmd_server_admin_acq_currency_type' : [
812                 ['oncommand'],
813                 function() { open_eg_web_page('acq/currency_type/list'); }
814             ],
815             'cmd_server_admin_acq_exchange_rate' : [
816                 ['oncommand'],
817                 function() { open_eg_web_page('conify/global/acq/exchange_rate'); }
818             ],
819             'cmd_server_admin_acq_distrib_formula' : [
820                 ['oncommand'],
821                 function() { open_eg_web_page('conify/global/acq/distribution_formula'); }
822             ],
823             'cmd_server_admin_z39_source' : [
824                 ['oncommand'],
825                 function() { open_eg_web_page('conify/global/config/z3950_source'); }
826             ],
827             'cmd_server_admin_circ_mod' : [
828                 ['oncommand'],
829                 function() { open_eg_web_page('conify/global/config/circ_modifier'); }
830             ],
831             'cmd_server_admin_global_flag' : [
832                 ['oncommand'],
833                 function() { open_eg_web_page('conify/global/config/global_flag'); }
834             ],
835             'cmd_server_admin_org_unit_setting_type' : [
836                 ['oncommand'],
837                 function() { open_eg_web_page('conify/global/config/org_unit_setting_type'); }
838             ],
839             'cmd_server_admin_usr_setting_type' : [
840                 ['oncommand'],
841                 function() { open_eg_web_page('conify/global/config/usr_setting_type'); }
842             ],
843             'cmd_server_admin_booking_resource': [
844                 ['oncommand'],
845                 function() { open_eg_web_page('conify/global/booking/resource'); }
846             ],
847             'cmd_server_admin_booking_resource_type': [
848                 ['oncommand'],
849                 function() { open_eg_web_page('conify/global/booking/resource_type'); }
850             ],
851             'cmd_server_admin_booking_resource_attr': [
852                 ['oncommand'],
853                 function() { open_eg_web_page('conify/global/booking/resource_attr'); }
854             ],
855             'cmd_server_admin_booking_resource_attr_value': [
856                 ['oncommand'],
857                 function() { open_eg_web_page('conify/global/booking/resource_attr_value'); }
858             ],
859             'cmd_server_admin_booking_resource_attr_map': [
860                 ['oncommand'],
861                 function() { open_eg_web_page('conify/global/booking/resource_attr_map'); }
862             ],
863             'cmd_acq_create_invoice' : [
864                 ['oncommand'],
865                 function() { open_eg_web_page('acq/invoice/view?create=1', 'menu.cmd_acq_create_invoice.tab'); }
866             ],
867             'cmd_acq_view_my_pl' : [
868                 ['oncommand'],
869                 function() { open_eg_web_page('acq/search/unified?ca=pl', 'menu.cmd_acq_unified_search.tab'); }
870             ],
871             'cmd_acq_view_local_po' : [
872                 ['oncommand'],
873                 function() { open_eg_web_page('acq/search/unified?ca=po', 'menu.cmd_acq_unified_search.tab'); }
874             ],
875             'cmd_acq_create_po' : [
876                 ['oncommand'],
877                 function() { open_eg_web_page('acq/po/create', 'menu.cmd_acq_po.tab'); }
878             ],
879             'cmd_acq_view_local_inv' : [
880                 ['oncommand'],
881                 function() { open_eg_web_page('acq/search/unified?ca=inv', 'menu.cmd_acq_unified_search.tab'); }
882             ],
883             'cmd_acq_user_requests' : [
884                 ['oncommand'],
885                 function() { open_eg_web_page('acq/picklist/user_request', 'menu.cmd_acq_user_requests.tab'); }
886             ],
887             'cmd_acq_upload' : [
888                 ['oncommand'],
889                 function() { open_eg_web_page('acq/picklist/upload', 'menu.cmd_acq_upload.tab'); }
890             ],
891             'cmd_acq_bib_search' : [
892                 ['oncommand'],
893                 function() { open_eg_web_page('acq/picklist/bib_search', 'menu.cmd_acq_bib_search.tab'); }
894             ],
895             'cmd_acq_unified_search' : [
896                 ['oncommand'],
897                 function() { open_eg_web_page('acq/search/unified', 'menu.cmd_acq_unified_search.tab'); }
898             ],
899             'cmd_acq_from_bib' : [
900                 ['oncommand'],
901                 function() { open_eg_web_page('acq/picklist/from_bib', 'menu.cmd_acq_from_bib.tab'); }
902             ],
903             'cmd_acq_new_brief_record' : [
904                 ['oncommand'],
905                 function() { open_eg_web_page('acq/picklist/brief_record', 'menu.cmd_acq_new_brief_record.tab'); }
906             ],
907             'cmd_acq_claim_eligible' : [
908                 ['oncommand'],
909                 function() { open_eg_web_page('acq/financial/claim_eligible', 'menu.cmd_acq_claim_eligible.tab'); }
910             ],
911             'cmd_booking_reservation' : [
912                 ['oncommand'],
913                 function() {
914                     open_eg_web_page(
915                         "/eg/booking/reservation",
916                         "menu.cmd_booking_reservation.tab"
917                     );
918                 }
919             ],
920             'cmd_booking_pull_list' : [
921                 ['oncommand'],
922                 function() {
923                     open_eg_web_page(
924                         "/eg/booking/pull_list",
925                         "menu.cmd_booking_pull_list.tab"
926                     );
927                 }
928             ],
929             'cmd_booking_capture' : [
930                 ['oncommand'],
931                 function() {
932                     open_eg_web_page(
933                         "/eg/booking/capture",
934                         "menu.cmd_booking_capture.tab"
935                     );
936                 }
937             ],
938             'cmd_booking_reservation_pickup' : [
939                 ['oncommand'],
940                 function() {
941                     open_eg_web_page(
942                         "/eg/booking/pickup",
943                         "menu.cmd_booking_reservation_pickup.tab"
944                     );
945                 }
946             ],
947             'cmd_booking_reservation_return' : [
948                 ['oncommand'],
949                 function() {
950                     open_eg_web_page(
951                         "/eg/booking/return",
952                         "menu.cmd_booking_reservation_return.tab"
953                     );
954                 }
955             ],
956             'cmd_reprint' : [
957                 ['oncommand'],
958                 function() {
959                     try {
960                         JSAN.use('util.print'); var print = new util.print();
961                         print.reprint_last();
962                     } catch(E) {
963                         alert(E);
964                     }
965                 }
966             ],
967
968             'cmd_retrieve_last_patron' : [
969                 ['oncommand'],
970                 function() {
971                     obj.data.stash_retrieve();
972                     if (!obj.data.last_patron) {
973                         alert(offlineStrings.getString('menu.cmd_retrieve_last_patron.session.error'));
974                         return;
975                     }
976                     var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
977                     var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
978                     obj.set_tab( url, {}, { 'id' : obj.data.last_patron } );
979                 }
980             ],
981             
982             'cmd_retrieve_last_record' : [
983                 ['oncommand'],
984                 function() {
985                     obj.data.stash_retrieve();
986                     if (!obj.data.last_record) {
987                         alert(offlineStrings.getString('menu.cmd_retrieve_last_record.session.error'));
988                         return;
989                     }
990                     var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + obj.data.last_record;
991                     var content_params = {
992                         'session' : ses(),
993                         'authtime' : ses('authtime'),
994                         'opac_url' : opac_url,
995                     };
996                     obj.set_tab(
997                         obj.url_prefix(urls.XUL_OPAC_WRAPPER),
998                         {'tab_name' : offlineStrings.getString('menu.cmd_retrieve_last_record.status')},
999                         content_params
1000                     );
1001                 }
1002             ],
1003
1004             'cmd_verify_credentials' : [
1005                 ['oncommand'],
1006                 function() {
1007                     obj.set_tab(
1008                         obj.url_prefix(urls.XUL_VERIFY_CREDENTIALS),
1009                         { 'tab_name' : offlineStrings.getString('menu.cmd_verify_credentials.tabname') },
1010                         {}
1011                     );
1012                 }
1013             ],
1014
1015             /* Cataloging Menu */
1016             'cmd_z39_50_import' : [
1017                 ['oncommand'],
1018                 function() {
1019                     obj.data.stash_retrieve();
1020                     obj.set_tab(obj.url_prefix(urls.XUL_Z3950_IMPORT),{},{});
1021                 }
1022             ],
1023             'cmd_create_marc' : [
1024                 ['oncommand'],
1025                 function() {
1026                     obj.data.stash_retrieve();
1027                     obj.set_tab(obj.url_prefix(urls.XUL_MARC_NEW),{},{});
1028                 }
1029             ],
1030
1031             'cmd_authority_manage' : [
1032                 ['oncommand'],
1033                 function() {
1034                     obj.data.stash_retrieve();
1035                     obj.set_tab(obj.url_prefix(urls.AUTHORITY_MANAGE),{},{});
1036                 }
1037             ],
1038
1039             'cmd_marc_batch_edit' : [
1040                 ['oncommand'],
1041                 function() {
1042                     obj.set_tab(
1043                         obj.url_prefix(urls.MARC_BATCH_EDIT),{
1044                             'tab_name' : offlineStrings.getString('menu.cmd_marc_batch_edit.tab')
1045                         },
1046                         {}
1047                     );
1048                 }
1049             ],
1050
1051             /* Admin menu */
1052             'cmd_change_session' : [
1053                 ['oncommand'],
1054                 function() {
1055                     try {
1056                         obj.data.stash_retrieve();
1057                         JSAN.use('util.network'); var network = new util.network();
1058                         var x = document.getElementById('oc_menuitem');
1059                         var x_label = x.getAttribute('label_orig');
1060                         var temp_au = js2JSON( obj.data.list.au[0] );
1061                         var temp_ses = js2JSON( obj.data.session );
1062                         if (obj.data.list.au.length > 1) {
1063                             obj.data.list.au = [ obj.data.list.au[1] ];
1064                             obj.data.stash('list');
1065                             network.reset_titlebars( obj.data );
1066                             x.setAttribute('label', x_label );
1067                             network.simple_request('AUTH_DELETE', [ obj.data.session.key ] );
1068                             obj.data.session = obj.data.previous_session;
1069                             obj.data.stash('session');
1070                             try {
1071                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1072                                 var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
1073                                 var cookieUri = ios.newURI("http://" + obj.data.server_unadorned, null, null);
1074                                 var cookieUriSSL = ios.newURI("https://" + obj.data.server_unadorned, null, null);
1075                                 var cookieSvc = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);
1076
1077                                 cookieSvc.setCookieString(cookieUri, null, "ses="+obj.data.session.key, null);
1078                                 cookieSvc.setCookieString(cookieUriSSL, null, "ses="+obj.data.session.key, null);
1079
1080                         } catch(E) {
1081                             alert(offlineStrings.getFormattedString(main.session_cookie.error, [E]));
1082                         }
1083
1084                             removeCSSClass(document.getElementById('main_tabbox'),'operator_change');
1085                         } else {
1086                             if (network.get_new_session(offlineStrings.getString('menu.cmd_chg_session.label'),{'url_prefix':obj.url_prefix})) {
1087                                 obj.data.stash_retrieve();
1088                                 obj.data.list.au[1] = JSON2js( temp_au );
1089                                 obj.data.stash('list');
1090                                 obj.data.previous_session = JSON2js( temp_ses );
1091                                 obj.data.stash('previous_session');
1092                                 x.setAttribute('label', offlineStrings.getFormattedString('menu.cmd_chg_session.operator.label', [obj.data.list.au[1].usrname()]) );
1093                                 addCSSClass(document.getElementById('main_tabbox'),'operator_change');
1094                             }
1095                         }
1096                     } catch(E) {
1097                         obj.error.standard_unexpected_error_alert('cmd_change_session',E);
1098                     }
1099                 }
1100             ],
1101             'cmd_manage_offline_xacts' : [
1102                 ['oncommand'],
1103                 function() {
1104                     obj.set_tab(obj.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS), {'tab_name' : offlineStrings.getString('menu.cmd_manage_offline_xacts.tab')}, {});
1105                 }
1106             ],
1107             'cmd_download_patrons' : [
1108                 ['oncommand'],
1109                 function() {
1110                     try {
1111                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1112                         var x = new XMLHttpRequest();
1113                         var url = 'http://' + XML_HTTP_SERVER + '/standalone/list.txt';
1114                         x.open("GET",url,false);
1115                         x.send(null);
1116                         if (x.status == 200) {
1117                             JSAN.use('util.file'); var file = new util.file('offline_patron_list');
1118                             file.write_content('truncate',x.responseText);
1119                             file.close();
1120                             file = new util.file('offline_patron_list.date');
1121                             file.write_content('truncate',new Date());
1122                             file.close();
1123                             alert(offlineStrings.getString('menu.cmd_download_patrons.complete.status'));
1124                         } else {
1125                             alert(offlineStrings.getFormattedString('menu.cmd_download_patrons.error', [x.status, x.statusText]));
1126                         }
1127                     } catch(E) {
1128                         obj.error.standard_unexpected_error_alert('cmd_download_patrons',E);
1129                     }
1130                 }
1131             ],
1132             'cmd_adv_user_edit' : [
1133                 ['oncommand'],
1134                 function() {
1135                     obj.data.stash_retrieve();
1136                     obj.set_tab(obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY), {}, { 'perm_editor' : true });
1137                 }
1138             ],
1139             'cmd_print_list_template_edit' : [
1140                 ['oncommand'],
1141                 function() {
1142                     obj.data.stash_retrieve();
1143                     obj.set_tab(obj.url_prefix(urls.XUL_PRINT_LIST_TEMPLATE_EDITOR), {}, {});
1144                 }
1145             ],
1146             'cmd_stat_cat_edit' : [
1147                 ['oncommand'],
1148                 function() {
1149                     obj.data.stash_retrieve();
1150                     obj.set_tab(obj.url_prefix(urls.XUL_STAT_CAT_EDIT) + '?ses='+window.escape(ses()), {'tab_name' : offlineStrings.getString('menu.cmd_stat_cat_edit.tab')},{});
1151                 }
1152             ],
1153             'cmd_non_cat_type_edit' : [
1154                 ['oncommand'],
1155                 function() {
1156                     obj.data.stash_retrieve();
1157                     obj.set_tab(obj.url_prefix(urls.XUL_NON_CAT_LABEL_EDIT) + '?ses='+window.escape(ses()), {'tab_name' : offlineStrings.getString('menu.cmd_non_cat_type_edit.tab')},{});
1158                 }
1159             ],
1160             'cmd_copy_location_edit' : [
1161                 ['oncommand'],
1162                 function() {
1163                     obj.data.stash_retrieve();
1164                     obj.set_tab(obj.url_prefix(urls.XUL_COPY_LOCATION_EDIT) + '?ses='+window.escape(ses()),{'tab_name' : offlineStrings.getString('menu.cmd_copy_location_edit.tab')},{});
1165                 }
1166             ],
1167             'cmd_test' : [
1168                 ['oncommand'],
1169                 function() {
1170                     obj.data.stash_retrieve();
1171                     var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
1172                     obj.set_tab(obj.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
1173                 }
1174             ],
1175             'cmd_test_html' : [
1176                 ['oncommand'],
1177                 function() {
1178                     obj.data.stash_retrieve();
1179                     obj.set_tab(obj.url_prefix(urls.TEST_HTML) + '?ses='+window.escape(ses()),{ 'browser' : true },{});
1180                 }
1181             ],
1182             'cmd_test_xul' : [
1183                 ['oncommand'],
1184                 function() {
1185                     obj.data.stash_retrieve();
1186                     obj.set_tab(obj.url_prefix(urls.TEST_XUL) + '?ses='+window.escape(ses()),{ 'browser' : false },{});
1187                 }
1188             ],
1189             'cmd_console' : [
1190                 ['oncommand'],
1191                 function() {
1192                     obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_CONSOLE),{'tab_name' : offlineStrings.getString('menu.cmd_console.tab')},{});
1193                 }
1194             ],
1195             'cmd_shell' : [
1196                 ['oncommand'],
1197                 function() {
1198                     obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_SHELL),{'tab_name' : offlineStrings.getString('menu.cmd_shell.tab')},{});
1199                 }
1200             ],
1201             'cmd_xuleditor' : [
1202                 ['oncommand'],
1203                 function() {
1204                     obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_XULEDITOR),{'tab_name' : offlineStrings.getString('menu.cmd_xuleditor.tab')},{});
1205                 }
1206             ],
1207             'cmd_fieldmapper' : [
1208                 ['oncommand'],
1209                 function() {
1210                     obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_FIELDMAPPER),{'tab_name' : offlineStrings.getString('menu.cmd_fieldmapper.tab')},{});
1211                 }
1212             ],
1213             'cmd_survey_wizard' : [
1214                 ['oncommand'],
1215                 function() {
1216                     obj.data.stash_retrieve();
1217                     xulG.window.open(obj.url_prefix(urls.XUL_SURVEY_WIZARD),'survey_wizard','chrome'); 
1218                 }
1219             ],
1220             'cmd_public_opac' : [
1221                 ['oncommand'],
1222                 function() {
1223                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
1224                         obj.url_prefix(urls.remote)
1225                     );
1226                     obj.set_tab( 
1227                         loc, 
1228                         {'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
1229                         { 'no_xulG' : true, 'show_nav_buttons' : true, 'show_print_button' : true } 
1230                     );
1231                 }
1232             ],
1233             'cmd_clear_cache' : [
1234                 ['oncommand'],
1235                 function clear_the_cache() {
1236                     try {
1237                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1238                         var cacheClass         = Components.classes["@mozilla.org/network/cache-service;1"];
1239                         var cacheService    = cacheClass.getService(Components.interfaces.nsICacheService);
1240                         cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
1241                         cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
1242                     } catch(E) {
1243                         dump(E+'\n');alert(E);
1244                     }
1245                 }
1246             ],
1247             'cmd_restore_all_tabs' : [
1248                 ['oncommand'],
1249                 function() {
1250                     var tabs = obj.controller.view.tabs;
1251                     for (var i = 0; i < tabs.childNodes.length; i++) {
1252                         tabs.childNodes[i].hidden = false;
1253                     }
1254                 }
1255             ],
1256             'cmd_extension_manager' : [
1257                 ['oncommand'],
1258                 function() {
1259                     obj.set_tab('chrome://mozapps/content/extensions/extensions.xul?type=extensions',{'tab_name' : offlineStrings.getString('menu.cmd_extension_manager.tab')},{});
1260                 }
1261             ],
1262             'cmd_theme_manager' : [
1263                 ['oncommand'],
1264                 function() {
1265                     obj.set_tab('chrome://mozapps/content/extensions/extensions.xul?type=themes',{'tab_name' : offlineStrings.getString('menu.cmd_theme_manager.tab')},{});
1266                 }
1267             ],
1268             'cmd_about_config' : [
1269                 ['oncommand'],
1270                 function() {
1271                     obj.set_tab('chrome://global/content/config.xul',{'tab_name' : 'about:config'},{});
1272                 }
1273             ],
1274             'cmd_shutdown' : [
1275                 ['oncommand'],
1276                 function() {
1277                     var confirm_string = offlineStrings.getString('menu.cmd_shutdown.prompt');
1278                     obj.data.stash_retrieve();
1279                     if (typeof obj.data.unsaved_data != 'undefined') {
1280                         if (obj.data.unsaved_data > 0) {
1281                             confirm_string = offlineStrings.getString('menu.shutdown.unsaved_data_warning');
1282                         }
1283                     }
1284                     if (window.confirm(confirm_string)) {
1285                         obj.data.unsaved_data = 0; // just in case the program doesn't close somehow
1286                         obj.data.stash('unsaved_data');
1287                         dump('forcing data.unsaved_data == ' + obj.data.unsaved_data + '\n');
1288                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1289                         var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
1290                         var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
1291                         var enumerator = windowManagerInterface.getEnumerator(null);
1292                         var w; // close all other windows
1293                         while ( w = enumerator.getNext() ) {
1294                             if (w != window) {
1295                                 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
1296                             }
1297                         }
1298                         window.close();
1299                     }
1300                 }
1301             ],
1302         };
1303
1304         JSAN.use('util.controller');
1305         var cmd;
1306         obj.controller = new util.controller();
1307         obj.controller.init( { 'window_knows_me_by' : 'g.menu.controller', 'control_map' : cmd_map } );
1308
1309         obj.controller.view.tabbox = window.document.getElementById('main_tabbox');
1310         // Despite what the docs say:
1311         // The "tabs" element need not be the first child
1312         // The "panels" element need not be the second/last
1313         // Nor need they be the only ones there.
1314         // Thus, use the IDs for robustness.
1315         obj.controller.view.tabs = window.document.getElementById('main_tabs');
1316         obj.controller.view.panels = window.document.getElementById('main_panels');
1317         obj.controller.view.tabscroller = window.document.getElementById('main_tabs_scrollbox');
1318         if(params['firstURL']) {
1319             obj.new_tab(params['firstURL'],{'focus':true},null);
1320         }
1321         else {
1322             obj.new_tab(null,{'focus':true},null);
1323         }
1324     },
1325
1326     'spawn_search' : function(s) {
1327         var obj = this;
1328         obj.error.sdump('D_TRACE', offlineStrings.getFormattedString('menu.spawn_search.msg', [js2JSON(s)]) ); 
1329         obj.new_patron_tab( {}, { 'doit' : 1, 'query' : js2JSON(s) } );
1330     },
1331
1332     'close_all_tabs' : function() {
1333         var obj = this;
1334         try {
1335             var count = obj.controller.view.tabs.childNodes.length;
1336             for (var i = 1; i < count; i++) obj.close_tab();
1337             setTimeout( function(){ obj.controller.view.tabs.firstChild.focus(); }, 0);
1338         } catch(E) {
1339             obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.close_all_tabs.error'),E);
1340         }
1341     },
1342
1343     'close_tab' : function (specific_idx) {
1344         var idx = specific_idx || this.controller.view.tabs.selectedIndex;
1345         var panel = this.controller.view.panels.childNodes[ idx ];
1346
1347         var tab = this.controller.view.tabs.getItemAtIndex( idx );
1348         var id = tab.getAttribute('id');
1349         if (typeof this.tab_semaphores[id] != 'undefined') {
1350             if (this.tab_semaphores[id] > 0) {
1351                 var confirmation = window.confirm(offlineStrings.getString('menu.close_tab.unsaved_data_warning'));
1352                 if (!confirmation) { return; }
1353                 oils_unsaved_data_P( this.tab_semaphores[id] );
1354             }
1355             delete this.tab_semaphores[id];
1356         }
1357
1358         this.controller.view.tabs.removeItemAt(idx);
1359         this.controller.view.panels.removeChild(panel);
1360         if(this.controller.view.tabs.childNodes.length > idx) {
1361             this.controller.view.tabbox.selectedIndex = idx;
1362         }
1363         else {
1364             this.controller.view.tabbox.selectedIndex = idx - 1;
1365         }
1366         this.controller.view.tabscroller.ensureElementIsVisible(this.controller.view.tabs.selectedItem);
1367         this.update_all_tab_names();
1368         // Make sure we keep at least one tab open.
1369         if(this.controller.view.tabs.childNodes.length == 1) {
1370             this.new_tab(); 
1371         }
1372     },
1373     
1374     'update_all_tab_names' : function() {
1375         var doAccessKeys = !xulG.pref.getBoolPref('open-ils.disable_accesskeys_on_tabs');
1376         for(var i = 1; i < this.controller.view.tabs.childNodes.length; ++i) {
1377             var tab = this.controller.view.tabs.childNodes[i];
1378             tab.curindex = i;
1379             tab.label = i + ' ' + tab.origlabel;
1380             if(doAccessKeys && offlineStrings.testString('menu.tab' + i + '.accesskey')) {
1381                 tab.accessKey = offlineStrings.getString('menu.tab' + i + '.accesskey');
1382             }
1383         }
1384     },
1385
1386     'command_tab' : function(event,url,params,content_params) {
1387         var newTab = false;
1388         if(event && event.explicitOriginalTarget.nodeName == 'toolbarbutton' && event.explicitOriginalTarget.command == event.originalTarget.id) {
1389             var value = xulG.pref.getIntPref('ui.key.accelKey');
1390             switch(value) {
1391                 case 17:
1392                     newTab = event.ctrlKey;
1393                     break;
1394                 case 18:
1395                     newTab = event.altKey;
1396                     break;
1397                 case 224:
1398                     newTab = event.metaKey;
1399                     break;
1400             }
1401             try {
1402                 if(xulG.pref.getBoolPref('open-ils.toolbar.defaultnewtab')) {
1403                     newTab = !newTab;
1404                 }
1405             }
1406             catch (e) {
1407             }
1408         }
1409         if(newTab) {
1410             this.new_tab(url,params,content_params);
1411         }
1412         else {
1413             this.set_tab(url,params,content_params);
1414         }
1415     },
1416
1417     'new_tab' : function(url,params,content_params) {
1418         var obj = this;
1419         var max_tabs = 0;
1420         try {
1421             var max_tabs = xulG.pref.getIntPref('open-ils.window_max_tabs') || max_tabs;
1422         }
1423         catch (e) {}
1424         if(max_tabs > 0 && this.controller.view.tabs.childNodes.length > max_tabs) return false;
1425         var tab = this.w.document.createElement('tab');
1426         var panel = this.w.document.createElement('tabpanel');
1427         var tabscroller = this.controller.view.tabscroller;
1428         this.controller.view.tabs.appendChild(tab);
1429         this.controller.view.panels.appendChild(panel);
1430         tab.curindex = this.controller.view.tabs.childNodes.length - 1;
1431         if(!xulG.pref.getBoolPref('open-ils.disable_accesskeys_on_tabs')) {
1432             if(offlineStrings.testString('menu.tab' + tab.curindex + '.accesskey')) {
1433                 tab.accessKey = offlineStrings.getString('menu.tab' + tab.curindex + '.accesskey');
1434             }
1435         }
1436         var tabs = this.controller.view.tabs;
1437         tab.addEventListener(
1438             'command',
1439             function() {
1440                 try {
1441                     tabscroller.ensureElementIsVisible(tab);
1442                     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1443                     if (panel
1444                         && panel.firstChild 
1445                         && ( panel.firstChild.nodeName == 'iframe' || panel.firstChild.nodeName == 'browser' )
1446                         && panel.firstChild.contentWindow 
1447                     ) {
1448                         var cw = panel.firstChild.contentWindow;
1449                         var help_params = {
1450                             'protocol' : cw.location.protocol,
1451                             'hostname' : cw.location.hostname,
1452                             'port' : cw.location.port,
1453                             'pathname' : cw.location.pathname,
1454                             'src' : ''
1455                         };
1456                         obj.set_help_context(help_params);
1457                         if (typeof cw.default_focus == 'function') {
1458                             cw.default_focus();
1459                         }
1460                     }
1461                 } catch(E) {
1462                     obj.error.sdump('D_ERROR','init_tab_focus_handler: ' + js2JSON(E));
1463                 }
1464             }
1465             ,
1466             false
1467         );
1468         if (!content_params) content_params = {};
1469         if (!params) params = {};
1470         if (!params.tab_name) params.tab_name = offlineStrings.getString('menu.new_tab.tab');
1471         if (!params.nofocus) params.focus = true; /* make focus the default */
1472         try {
1473             if (params.focus) {
1474                 this.controller.view.tabs.selectedItem = tab;
1475                 tabscroller.ensureElementIsVisible(tab);
1476             }
1477             params.index = tab.curindex;
1478             this.set_tab(url,params,content_params);
1479             return true;
1480         } catch(E) {
1481             this.error.sdump('D_ERROR',E);
1482             return false;
1483         }
1484     },
1485
1486     'page_meter' : {
1487         'node' : document.getElementById('page_progress'),
1488         'on' : function() {
1489             document.getElementById('page_progress').setAttribute('mode','undetermined');
1490         },
1491         'off' : function() {
1492             document.getElementById('page_progress').setAttribute('mode','determined');
1493         },
1494         'tooltip' : function(text) {
1495             if (text || text == '') {
1496                 document.getElementById('page_progress').setAttribute('tooltiptext',text);
1497             }
1498             return document.getElementById('page_progress').getAttribute('tooltiptext');
1499         }
1500     },
1501
1502     'network_meter' : {
1503         'inc' : function(app,method) {
1504             try {
1505                 var m = document.getElementById('network_progress');
1506                 var count = 1 + Number( m.getAttribute('count') );
1507                 m.setAttribute('mode','undetermined');
1508                 m.setAttribute('count', count);
1509                 var rows = document.getElementById('network_progress_rows');
1510                 var row = document.getElementById('network_progress_tip_'+app+'_'+method);
1511                 if (!row) {
1512                     row = document.createElement('row'); row.setAttribute('id','network_progress_tip_'+app+'_'+method);
1513                     var a = document.createElement('label'); a.setAttribute('value','App:');
1514                     var b = document.createElement('label'); b.setAttribute('value',app);
1515                     var c = document.createElement('label'); c.setAttribute('value','Method:');
1516                     var d = document.createElement('label'); d.setAttribute('value',method);
1517                     var e = document.createElement('label'); e.setAttribute('value','Total:');
1518                     var f = document.createElement('label'); f.setAttribute('value','0'); 
1519                     f.setAttribute('id','network_progress_tip_total_'+app+'_'+method);
1520                     var g = document.createElement('label'); g.setAttribute('value','Outstanding:');
1521                     var h = document.createElement('label'); h.setAttribute('value','0');
1522                     h.setAttribute('id','network_progress_tip_out_'+app+'_'+method);
1523                     row.appendChild(a); row.appendChild(b); row.appendChild(c);
1524                     row.appendChild(d); row.appendChild(e); row.appendChild(f);
1525                     row.appendChild(g); row.appendChild(h); rows.appendChild(row);
1526                 }
1527                 var total = document.getElementById('network_progress_tip_total_'+app+'_'+method);
1528                 if (total) {
1529                     total.setAttribute('value', 1 + Number( total.getAttribute('value') ));
1530                 }
1531                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
1532                 if (out) {
1533                     out.setAttribute('value', 1 + Number( out.getAttribute('value') ));
1534                 }
1535             } catch(E) {
1536                 dump('network_meter.inc(): ' + E + '\n');
1537             }
1538         },
1539         'dec' : function(app,method) {
1540             try {
1541                 var m = document.getElementById('network_progress');
1542                 var count = -1 + Number( m.getAttribute('count') );
1543                 if (count < 0) count = 0;
1544                 if (count == 0) m.setAttribute('mode','determined');
1545                 m.setAttribute('count', count);
1546                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
1547                 if (out) {
1548                     out.setAttribute('value', -1 + Number( out.getAttribute('value') ));
1549                 }
1550             } catch(E) {
1551                 dump('network_meter.dec(): ' + E + '\n');
1552             }
1553         }
1554     },
1555     'set_patron_tab' : function(params,content_params,event) {
1556         var obj = this;
1557         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1558         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1559         obj.command_tab(event,url,params ? params : {},content_params ? content_params : {});
1560     },
1561     'new_patron_tab' : function(params,content_params) {
1562         var obj = this;
1563         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1564         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1565         obj.new_tab(url,params ? params : {},content_params ? content_params : {});
1566     },
1567     'volume_item_creator' : function(params) {
1568         var obj = this;
1569         var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true';
1570         var url = obj.url_prefix( horizontal_interface ? urls.XUL_VOLUME_COPY_CREATOR_HORIZONTAL : urls.XUL_VOLUME_COPY_CREATOR );
1571         var w = obj.new_tab(
1572             url,
1573             { 'tab_name' : document.getElementById('offlineStrings').getString('staff.cat.create_or_rebarcode_items') },
1574             params
1575         );
1576     },
1577     'holdings_maintenance_tab' : function(docid,params,content_params) {
1578         var obj = this;
1579         if (!content_params) {
1580             content_params = {};
1581         }
1582         if (docid) {
1583             content_params['docid'] = docid;
1584         }
1585         var url = obj.url_prefix( urls.XUL_COPY_VOLUME_BROWSE );
1586         obj.new_tab(url,params || {}, content_params);
1587     },
1588     'get_new_session' : function(params) {
1589         var obj = this;
1590         if (!params) { params = {}; }
1591         JSAN.use('util.network'); var net = new util.network();
1592         var result = net.get_new_session(null,{'url_prefix':obj.url_prefix},!params.operator_change);
1593         if (typeof params.callback == 'function') {
1594             return params.callback( result, ses(), ses('authtime') );
1595         }
1596         return result;
1597     },
1598     'set_help_context' : function(params) {
1599         var obj = this;
1600         if (!params) { params = {}; }
1601         if (params.protocol == 'chrome:') { return; } /* not supported */
1602         var help_btn = document.getElementById('help_btn');
1603         if (help_btn) {
1604             dump('set_help_context: ' + js2JSON(params) + '\n');
1605             if (params.protocol) { help_btn.setAttribute('protocol', params.protocol); }
1606             if (params.hostname) { help_btn.setAttribute('hostname', params.hostname);  }
1607             if (params.port) { help_btn.setAttribute('port', params.port);  }
1608             if (params.pathname) { help_btn.setAttribute('pathname', params.pathname); }
1609             if (params.src) { help_btn.setAttribute('src', params.src); }
1610         }
1611     },
1612
1613     'tab_semaphores' : {},
1614
1615     'set_tab' : function(url,params,content_params) {
1616         var obj = this;
1617         if (!url) url = '/xul/server/';
1618         if (!url.match(/:\/\//) && !url.match(/^data:/)) url = urls.remote + url;
1619         if (!params) params = {};
1620         if (!content_params) content_params = {};
1621         var idx = this.controller.view.tabs.selectedIndex;
1622         if (params && typeof params.index != 'undefined') idx = params.index;
1623         var tab = this.controller.view.tabs.childNodes[ idx ];
1624
1625         var id = tab.getAttribute('id');
1626         if (id) {
1627             if (typeof obj.tab_semaphores[id] != 'undefined') {
1628                 if (obj.tab_semaphores[id] > 0) {
1629                     var confirmation = window.confirm(offlineStrings.getString('menu.replace_tab.unsaved_data_warning'));
1630                     if (!confirmation) { return; }
1631                     oils_unsaved_data_P( obj.tab_semaphores[id] );
1632                 }
1633                 delete obj.tab_semaphores[id];
1634             }
1635         }
1636         var unique_id = idx + ':' + new Date();
1637         tab.setAttribute('id',unique_id);
1638         if (params.focus) tab.focus();
1639         var panel = this.controller.view.panels.childNodes[ idx ];
1640         while ( panel.lastChild ) panel.removeChild( panel.lastChild );
1641
1642         content_params.lock_tab = function() { 
1643             dump('lock_tab\n');
1644             var id = tab.getAttribute('id');
1645             if (typeof obj.tab_semaphores[id] == 'undefined') {
1646                 obj.tab_semaphores[id] = 0;
1647             }
1648             obj.tab_semaphores[id]++; 
1649             oils_unsaved_data_V();
1650             return obj.tab_semaphores[id]; 
1651         };
1652         content_params.unlock_tab = function() { 
1653             dump('unlock_tab\n');
1654             var id = tab.getAttribute('id');
1655             if (typeof obj.tab_semaphores[id] == 'undefined') {
1656                 obj.tab_semaphores[id] = 0;
1657             }
1658             obj.tab_semaphores[id]--;
1659             if (obj.tab_semaphores[id] < 0) { obj.tab_semaphores[id] = 0; } 
1660             oils_unsaved_data_P();
1661             return obj.tab_semaphores[id]; 
1662         };
1663         content_params.inspect_tab = function() {
1664             var id = tab.getAttribute('id');
1665             return 'id = ' + id + ' semaphore = ' + obj.tab_semaphores[id];
1666         }
1667         content_params.new_tab = function(a,b,c) { return obj.new_tab(a,b,c); };
1668         content_params.set_tab = function(a,b,c) { return obj.set_tab(a,b,c); };
1669         content_params.close_tab = function() { return obj.close_tab(); };
1670         content_params.new_patron_tab = function(a,b) { return obj.new_patron_tab(a,b); };
1671         content_params.set_patron_tab = function(a,b) { return obj.set_patron_tab(a,b); };
1672         content_params.volume_item_creator = function(a) { return obj.volume_item_creator(a); };
1673         content_params.get_new_session = function(a) { return obj.get_new_session(a); };
1674         content_params.holdings_maintenance_tab = function(a,b,c) { return obj.holdings_maintenance_tab(a,b,c); };
1675         content_params.set_tab_name = function(name) { tab.label = tab.curindex + ' ' + name; tab.origlabel = name; };
1676         content_params.set_help_context = function(params) { return obj.set_help_context(params); };
1677         content_params.open_chrome_window = function(a,b,c) { return xulG.window.open(a,b,c); };
1678         content_params.url_prefix = function(url) { return obj.url_prefix(url); };
1679         content_params.network_meter = obj.network_meter;
1680         content_params.page_meter = obj.page_meter;
1681         content_params.set_statusbar = function(slot,text) {
1682             var e = document.getElementById('statusbarpanel'+slot);
1683             if (e) { e.setAttribute('label',text); }
1684         };
1685         content_params.chrome_xulG = xulG;
1686         content_params._data = xulG._data;
1687         if (params && params.tab_name) content_params.set_tab_name( params.tab_name );
1688         
1689         var frame;
1690         try {
1691             if (typeof params.browser == 'undefined') params.browser = false;
1692             if (params.browser) {
1693                 obj.id_incr++;
1694                 frame = this.w.document.createElement('browser');
1695                 frame.setAttribute('flex','1');
1696                 frame.setAttribute('type','content');
1697                 frame.setAttribute('autoscroll','false');
1698                 frame.setAttribute('id','frame_'+obj.id_incr);
1699                 panel.appendChild(frame);
1700                 try {
1701                     dump('creating browser with src = ' + url + '\n');
1702                     JSAN.use('util.browser');
1703                     var b = new util.browser();
1704                     b.init(
1705                         {
1706                             'url' : url,
1707                             'push_xulG' : true,
1708                             'alt_print' : false,
1709                             'browser_id' : 'frame_'+obj.id_incr,
1710                             'passthru_content_params' : content_params,
1711                         }
1712                     );
1713                 } catch(E) {
1714                     alert(E);
1715                 }
1716             } else {
1717                 frame = this.w.document.createElement('iframe');
1718                 frame.setAttribute('flex','1');
1719                 panel.appendChild(frame);
1720                 dump('creating iframe with src = ' + url + '\n');
1721                 frame.setAttribute('src',url);
1722                 try {
1723                     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1724                     var cw = frame.contentWindow;
1725                     if (typeof cw.wrappedJSObject != 'undefined') cw = cw.wrappedJSObject;
1726                     cw.IAMXUL = true;
1727                     cw.xulG = content_params;
1728                     cw.addEventListener(
1729                         'load',
1730                         function() {
1731                             try {
1732                                 if (typeof cw.help_context_set_locally == 'undefined') {
1733                                     var help_params = {
1734                                         'protocol' : cw.location.protocol,
1735                                         'hostname' : cw.location.hostname,
1736                                         'port' : cw.location.port,
1737                                         'pathname' : cw.location.pathname,
1738                                         'src' : ''
1739                                     };
1740                                     obj.set_help_context(help_params);
1741                                 } else if (typeof cw.default_focus == 'function') {
1742                                     cw.default_focus();
1743                                 }
1744                             } catch(E) {
1745                                 obj.error.sdump('D_ERROR', 'main.menu, set_tab, onload: ' + E);
1746                             }
1747                         },
1748                         false
1749                     );
1750                 } catch(E) {
1751                     this.error.sdump('D_ERROR', 'main.menu: ' + E);
1752                 }
1753             }
1754         } catch(E) {
1755             this.error.sdump('D_ERROR', 'main.menu:2: ' + E);
1756             alert(offlineStrings.getString('menu.set_tab.error'));
1757         }
1758
1759         return frame;
1760     }
1761
1762 }
1763
1764 dump('exiting main/menu.js\n');