034232cddca3c0550947591fd7642781a59316e2
[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
14         this.w = window;
15     var x = document.getElementById('network_progress');
16     x.setAttribute('count','0');
17     x.addEventListener(
18         'click',
19         function() {
20             if ( window.confirm(offlineStrings.getString('menu.reset_network_stats')) ) {
21                 var y = document.getElementById('network_progress_rows');
22                 while(y.firstChild) { y.removeChild( y.lastChild ); }
23                 x.setAttribute('mode','determined');
24                 x.setAttribute('count','0');
25             }
26         },
27         false
28     );
29
30         if (xulG.pref.getBoolPref('open-ils.disable_accesskeys_on_tabs')) {
31                 var tabs = document.getElementById('main_tabs');
32                 for (var i = 0; i < tabs.childNodes.length; i++) {
33                         tabs.childNodes[i].setAttribute('accesskey','');
34                 }
35         }
36 }
37
38 main.menu.prototype = {
39
40         'id_incr' : 0,
41
42         'url_prefix' : function(url) {
43                 if (url.match(/^\//)) url = urls.remote + url;
44                 if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
45                 dump('url_prefix = ' + url + '\n');
46                 return url;
47         },
48
49         'init' : function( params ) {
50
51                 urls.remote = params['server'];
52
53                 var obj = this;
54
55                 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
56
57         var button_bar = String( obj.data.hash.aous['ui.general.button_bar'] ) == 'true';
58         if (button_bar) {
59             var x = document.getElementById('main_toolbar');
60             if (x) x.setAttribute('hidden','false');
61         }
62
63                 var cmd_map = {
64                         'cmd_broken' : [
65                                 ['oncommand'],
66                                 function() { alert(offlineStrings.getString('common.unimplemented')); }
67                         ],
68
69                         /* File Menu */
70                         'cmd_close_window' : [ 
71                                 ['oncommand'], 
72                                 function() { window.close(); } 
73                         ],
74                         'cmd_new_window' : [
75                                 ['oncommand'],
76                                 function() {
77                                         obj.data.stash_retrieve();
78                                         var mframe = obj.window.open(
79                                                 obj.url_prefix(urls.XUL_MENU_FRAME)
80                                                 + '?server='+window.escape(urls.remote),
81                                                 'main' + obj.window.window_name_increment(),
82                                                 'chrome,resizable'); 
83                     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
84                     mframe.xulG = xulG;
85                                 }
86                         ],
87                         'cmd_new_tab' : [
88                                 ['oncommand'],
89                                 function() { obj.new_tab(null,{'focus':true},null); }
90                         ],
91                         'cmd_close_tab' : [
92                                 ['oncommand'],
93                                 function() { obj.close_tab(); }
94                         ],
95                         'cmd_close_all_tabs' : [
96                                 ['oncommand'],
97                                 function() { obj.close_all_tabs(); }
98                         ],
99
100                         /* Edit Menu */
101                         'cmd_edit_copy_buckets' : [
102                                 ['oncommand'],
103                                 function() {
104                                         obj.data.stash_retrieve();
105                                         obj.set_tab(obj.url_prefix(urls.XUL_COPY_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_copy_buckets.tab')},{});
106                                 }
107                         ],
108                         'cmd_edit_volume_buckets' : [
109                                 ['oncommand'],
110                                 function() {
111                                         obj.data.stash_retrieve();
112                                         obj.set_tab(obj.url_prefix(urls.XUL_VOLUME_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_volume_buckets.tab')},{});
113                                 }
114                         ],
115                         'cmd_edit_record_buckets' : [
116                                 ['oncommand'],
117                                 function() {
118                                         obj.data.stash_retrieve();
119                                         obj.set_tab(obj.url_prefix(urls.XUL_RECORD_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_record_buckets.tab')},{});
120                                 }
121                         ],
122                         'cmd_edit_user_buckets' : [
123                                 ['oncommand'],
124                                 function() {
125                                         obj.data.stash_retrieve();
126                                         obj.set_tab(obj.url_prefix(urls.XUL_USER_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_user_buckets.tab')},{});
127                                 }
128                         ],
129
130
131                         'cmd_replace_barcode' : [
132                                 ['oncommand'],
133                                 function() {
134                                         try {
135                                                 JSAN.use('util.network');
136                                                 var network = new util.network();
137
138                                                 var old_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.label'));
139                                                 if (!old_bc) return;
140         
141                                                 var copy;
142                         try {
143                             copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
144                                                 if (typeof copy.ilsevent != 'undefined') throw(copy); 
145                                                 if (!copy) throw(copy);
146                         } catch(E) {
147                             alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.retrieval.error', [old_bc]) + '\n');
148                             return;
149                         }
150         
151                                                 // Why did I want to do this twice?  Because this copy is more fleshed?
152                         try {
153                                                 copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
154                                                 if (typeof copy.ilsevent != 'undefined') throw(copy);
155                                                 if (!copy) throw(copy);
156                         } catch(E) {
157                             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); }
158                             return;
159                         }
160         
161                                                 var new_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.replacement.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.replacement.label'));
162                                                 new_bc = String( new_bc ).replace(/\s/g,'');
163                                                 /* Casting a possibly null input value to a String turns it into "null" */
164                                                 if (!new_bc || new_bc == 'null') {
165                                                         alert(offlineStrings.getString('menu.cmd_replace_barcode.blank.error'));
166                                                         return;
167                                                 }
168         
169                                                 var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ new_bc ]);
170                                                 if (typeof test.ilsevent == 'undefined') {
171                                                 alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.duplicate.error', [new_bc]));
172                                                         return;
173                                                 } else {
174                                                         if (test.ilsevent != 1502 /* ASSET_COPY_NOT_FOUND */) {
175                                                         obj.error.standard_unexpected_error_alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.testing.error', [new_bc]),test);
176                                                                 return;
177                                                         }       
178                                                 }
179
180                                                 copy.barcode(new_bc); copy.ischanged('1');
181                                                 var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
182                                                 if (typeof r.ilsevent != 'undefined') { 
183                             if (r.ilsevent != 0) {
184                                 if (r.ilsevent == 5000 /* PERM_FAILURE */) {
185                                     alert(offlineStrings.getString('menu.cmd_replace_barcode.permission.error'));
186                                 } else {
187                                     obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.error'),r);
188                                 }
189                             }
190                         }
191                                         } catch(E) {
192                                                 obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.failure'),copy);
193                                         }
194                                 }
195                         ],
196
197                         /* Search Menu */
198                         'cmd_patron_search' : [
199                                 ['oncommand'],
200                                 function() {
201                     obj.set_patron_tab();
202                                 }
203                         ],
204                         'cmd_search_opac' : [
205                                 ['oncommand'],
206                                 function() {
207                                         obj.data.stash_retrieve();
208                                         var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
209                                         obj.set_tab(obj.url_prefix(urls.XUL_OPAC_WRAPPER), {'tab_name':offlineStrings.getString('menu.cmd_search_opac.tab')}, content_params);
210                                 }
211                         ],
212                         'cmd_search_tcn' : [
213                                 ['oncommand'],
214                                 function() {
215                                         var tcn = prompt(offlineStrings.getString('menu.cmd_search_tcn.tab'),'',offlineStrings.getString('menu.cmd_search_tcn.prompt'));
216
217                                         function spawn_tcn(r) {
218                                                 for (var i = 0; i < r.count; i++) {
219                                                         var id = r.ids[i];
220                                                         var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + id;
221                                                         obj.data.stash_retrieve();
222                                                         var content_params = { 
223                                                                 'session' : ses(), 
224                                                                 'authtime' : ses('authtime'),
225                                                                 'opac_url' : opac_url,
226                                                         };
227                                                         if (i == 0) {
228                                                                 obj.set_tab(
229                                                                         obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
230                                                                         {'tab_name':tcn}, 
231                                                                         content_params
232                                                                 );
233                                                         } else {
234                                                                 obj.new_tab(
235                                                                         obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
236                                                                         {'tab_name':tcn}, 
237                                                                         content_params
238                                                                 );
239                                                         }
240                                                 }
241                                         }
242
243                                         if (tcn) {
244                                                 JSAN.use('util.network');
245                                                 var network = new util.network();
246                                                 var robj = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn]);
247                                                 if (robj.count != robj.ids.length) throw('FIXME -- FM_BRE_ID_SEARCH_VIA_TCN = ' + js2JSON(robj));
248                                                 if (robj.count == 0) {
249                                                         var robj2 = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn,1]);
250                                                         if (robj2.count == 0) {
251                                                                 alert(offlineStrings.getFormattedString('menu.cmd_search_tcn.not_found.error', [tcn]));
252                                                         } else {
253                                                                 if ( window.confirm(offlineStrings.getFormattedString('menu.cmd_search_tcn.deleted.error', [tcn])) ) {
254                                                                         spawn_tcn(robj2);
255                                                                 }
256                                                         }
257                                                 } else {
258                                                         spawn_tcn(robj);
259                                                 }
260                                         }
261                                 }
262                         ],
263                         'cmd_search_bib_id' : [
264                                 ['oncommand'],
265                                 function() {
266                                         var bib_id = prompt(offlineStrings.getString('menu.cmd_search_bib_id.tab'),'',offlineStrings.getString('menu.cmd_search_bib_id.prompt'));
267                     if (!bib_id) return;
268
269                                         var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + bib_id;
270                                         var content_params = { 
271                                                 'session' : ses(), 
272                                                 'authtime' : ses('authtime'),
273                                                 'opac_url' : opac_url,
274                                         };
275                                         obj.set_tab(
276                                                 obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
277                                                 {'tab_name':'#' + bib_id}, 
278                                                 content_params
279                                         );
280                                 }
281                         ],
282                         'cmd_copy_status' : [
283                                 ['oncommand'],
284                                 function() {
285                                         obj.data.stash_retrieve();
286                                         obj.set_tab(obj.url_prefix(urls.XUL_COPY_STATUS),{},{});
287                                 }
288                         ],
289
290                         /* Circulation Menu */
291                         'cmd_patron_register' : [
292                                 ['oncommand'],
293                                 function() {
294                                                                 function spawn_editor(p) {
295                                                                         var url = urls.XUL_PATRON_EDIT;
296                                                                         var param_count = 0;
297                                                                         for (var i in p) {
298                                                                                 if (param_count++ == 0) url += '?'; else url += '&';
299                                                                                 url += i + '=' + window.escape(p[i]);
300                                                                         }
301                                                                         var loc = obj.url_prefix( urls.XUL_REMOTE_BROWSER ) + '?url=' + window.escape( url );
302                                                                         obj.new_tab(
303                                                                                 loc, 
304                                                                                 {}, 
305                                                                                 { 
306                                                                                         'show_print_button' : true , 
307                                                                                         'tab_name' : offline.getString('menu.cmd_patron_register.related.tab'),
308                                                                                         'passthru_content_params' : {
309                                                                                                 'spawn_search' : function(s) { obj.spawn_search(s); },
310                                                                                                 'spawn_editor' : spawn_editor,
311                                                                                         }
312                                                                                 }
313                                                                         );
314                                                                 }
315
316                                         obj.data.stash_retrieve();
317                                         var loc = obj.url_prefix( urls.XUL_REMOTE_BROWSER ) 
318                                                 + '?url=' + window.escape( urls.XUL_PATRON_EDIT + '?ses=' + window.escape( ses() ) );
319                                         obj.set_tab(
320                                                 loc, 
321                                                 {}, 
322                                                 { 
323                                                         'show_print_button' : true , 
324                                                         'tab_name' : offlineStrings.getString('menu.cmd_patron_register.tab'),
325                                                         'passthru_content_params' : {
326                                                                 'spawn_search' : function(s) { obj.spawn_search(s); },
327                                                                 'spawn_editor' : spawn_editor,
328                                                         }
329                                                 }
330                                         );
331                                 }
332                         ],
333                         'cmd_circ_checkin' : [
334                                 ['oncommand'],
335                                 function() { 
336                                         obj.data.stash_retrieve();
337                                         obj.set_tab(obj.url_prefix(urls.XUL_CHECKIN),{},{});
338                                 }
339                         ],
340                         'cmd_circ_checkout' : [
341                                 ['oncommand'],
342                                 function() { 
343                                         obj.data.stash_retrieve();
344                                         obj.set_tab(obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY),{},{});
345                                 }
346                         ],
347                         'cmd_circ_hold_capture' : [
348                                 ['oncommand'],
349                                 function() { 
350                                         obj.data.stash_retrieve();
351                                         obj.set_tab(obj.url_prefix(urls.XUL_CHECKIN)+'?hold_capture=1',{},{});
352                                 }
353                         ],
354                         'cmd_browse_holds' : [
355                                 ['oncommand'],
356                                 function() { 
357                                         obj.data.stash_retrieve();
358                                         obj.set_tab(obj.url_prefix(urls.XUL_HOLDS_BROWSER),{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds.tab') },{});
359                                 }
360                         ],
361                         'cmd_browse_holds_shelf' : [
362                                 ['oncommand'],
363                                 function() { 
364                                         obj.data.stash_retrieve();
365                                         obj.set_tab(obj.url_prefix(urls.XUL_HOLDS_BROWSER)+'?shelf=1',{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds_shelf.tab') },{});
366                                 }
367                         ],
368                         'cmd_circ_hold_pull_list' : [
369                                 ['oncommand'],
370                                 function() { 
371                                         obj.data.stash_retrieve();
372                                         var loc = urls.XUL_REMOTE_BROWSER + '?url=' + window.escape(
373                                                 obj.url_prefix(urls.XUL_HOLD_PULL_LIST) + '?ses='+window.escape(ses())
374                                         );
375                                         obj.set_tab( loc, {'tab_name' : offlineStrings.getString('menu.cmd_browse_hold_pull_list.tab')}, { 'show_print_button' : true } );
376                                 }
377                         ],
378
379                         'cmd_in_house_use' : [
380                                 ['oncommand'],
381                                 function() { 
382                                         obj.data.stash_retrieve();
383                                         obj.set_tab(obj.url_prefix(urls.XUL_IN_HOUSE_USE),{},{});
384                                 }
385                         ],
386
387                         'cmd_standalone' : [
388                                 ['oncommand'],
389                                 function() { 
390                                         obj.set_tab(obj.url_prefix(urls.XUL_STANDALONE),{},{});
391                                 }
392                         ],
393
394                         'cmd_local_admin' : [
395                                 ['oncommand'],
396                                 function() { 
397                                         //obj.set_tab(obj.url_prefix(urls.XUL_LOCAL_ADMIN)+'?ses='+window.escape(ses())+'&session='+window.escape(ses()),{},{});
398                                         var loc = urls.XUL_REMOTE_BROWSER + '?url=' + window.escape(
399                                                 urls.XUL_LOCAL_ADMIN+'?ses='+window.escape(ses())+'&session='+window.escape(ses())
400                                         );
401                                         obj.set_tab( 
402                                                 loc, 
403                                                 {'tab_name' : offlineStrings.getString('menu.cmd_local_admin.tab'), 'browser' : false }, 
404                                                 { 'no_xulG' : false, 'show_nav_buttons' : true, 'show_print_button' : true } 
405                                         );
406
407                                 }
408                         ],
409
410             'cmd_toggle_buttonbar' : [
411                 ['oncommand'],
412                 function() {
413                     var x = document.getElementById('main_toolbar');
414                     if (x) x.hidden = ! x.hidden;
415                 }
416             ],
417
418                         'cmd_open_vandelay' : [
419                                 ['oncommand'],
420                                 function() { 
421                                         var loc = urls.XUL_REMOTE_BROWSER + '?url=' + 
422                         window.escape(urls.VANDELAY+'?ses='+window.escape(ses()));
423                                         obj.set_tab( 
424                                                 loc, 
425                                                 {'tab_name' : offlineStrings.getString('menu.cmd_open_vandelay.tab'), 'browser' : false }, 
426                                                 {'no_xulG' : false, 'show_print_button' : false } 
427                                         );
428
429                                 }
430                         ],
431
432             'cmd_local_admin_fonts_and_sounds' : [
433                 ['oncommand'],
434                 function() { 
435                     alert(123);
436                 }
437             ],
438             'cmd_local_admin_printer' : [
439                 ['oncommand'],
440                 function() { 
441                     alert(123);
442                 }
443             ],
444             'cmd_local_admin_closed_dates' : [
445                 ['oncommand'],
446                 function() { 
447                     alert(123);
448                 }
449             ],
450             'cmd_local_admin_copy_locations' : [
451                 ['oncommand'],
452                 function() { 
453                     alert(123);
454                 }
455             ],
456             'cmd_local_admin_lib_settings' : [
457                 ['oncommand'],
458                 function() { 
459                     alert(123);
460                 }
461             ],
462             'cmd_local_admin_non_cat_types' : [
463                 ['oncommand'],
464                 function() { 
465                     alert(123);
466                 }
467             ],
468             'cmd_local_admin_stat_cats' : [
469                 ['oncommand'],
470                 function() { 
471                     alert(123);
472                 }
473             ],
474             'cmd_local_admin_standing_penalty' : [
475                 ['oncommand'],
476                 function() { 
477                     alert(123);
478                 }
479             ],
480             'cmd_local_admin_grp_penalty_threshold' : [
481                 ['oncommand'],
482                 function() { 
483                     alert(123);
484                 }
485             ],
486             'cmd_local_admin_idl_field_doc' : [
487                 ['oncommand'],
488                 function() { 
489                     alert(123);
490                 }
491             ],
492             'cmd_local_admin_action_trigger' : [
493                 ['oncommand'],
494                 function() { 
495                     alert(123);
496                 }
497             ],
498             'cmd_local_admin_survey' : [
499                 ['oncommand'],
500                 function() { 
501                     alert(123);
502                 }
503             ],
504
505             'cmd_server_admin_org_type' : [
506                 ['oncommand'],
507                 function() { 
508                     alert(123);
509                 }
510             ],
511             'cmd_server_admin_org_unit' : [
512                 ['oncommand'],
513                 function() { 
514                     alert(123);
515                 }
516             ],
517             'cmd_server_admin_grp_tree' : [
518                 ['oncommand'],
519                 function() { 
520                     alert(123);
521                 }
522             ],
523             'cmd_server_admin_perm_list' : [
524                 ['oncommand'],
525                 function() { 
526                     alert(123);
527                 }
528             ],
529             'cmd_server_admin_copy_status' : [
530                 ['oncommand'],
531                 function() { 
532                     alert(123);
533                 }
534             ],
535             'cmd_server_admin_marc_code' : [
536                 ['oncommand'],
537                 function() { 
538                     alert(123);
539                 }
540             ],
541             'cmd_server_admin_billing_type' : [
542                 ['oncommand'],
543                 function() { 
544                     alert(123);
545                 }
546             ],
547             'cmd_server_admin_z39_source' : [
548                 ['oncommand'],
549                 function() { 
550                     alert(123);
551                 }
552             ],
553             'cmd_server_admin_circ_mod' : [
554                 ['oncommand'],
555                 function() { 
556                     alert(123);
557                 }
558             ],
559
560
561                         'cmd_open_conify' : [
562                                 ['oncommand'],
563                                 function() { 
564                                         var loc = urls.XUL_REMOTE_BROWSER + '?url=' + 
565                         window.escape(urls.CONIFY+'?ses='+window.escape(ses()));
566                                         obj.set_tab( 
567                                                 loc, 
568                                                 {'tab_name' : offlineStrings.getString('menu.cmd_open_conify.tab'), 'browser' : false }, 
569                                                 {'no_xulG' : false, 'show_print_button' : false } 
570                                         );
571
572                                 }
573                         ],
574
575                         'cmd_reprint' : [
576                                 ['oncommand'],
577                                 function() {
578                                         try {
579                                                 JSAN.use('util.print'); var print = new util.print();
580                                                 print.reprint_last();
581                                         } catch(E) {
582                                                 alert(E);
583                                         }
584                                 }
585                         ],
586
587                         'cmd_retrieve_last_patron' : [
588                                 ['oncommand'],
589                                 function() {
590                                         obj.data.stash_retrieve();
591                                         if (!obj.data.last_patron) {
592                                                 alert(offlineStrings.getString('menu.cmd_retrieve_last_patron.session.error'));
593                                                 return;
594                                         }
595                                         var url = obj.url_prefix( urls.XUL_PATRON_DISPLAY ); // + '?id=' + window.escape( obj.data.last_patron ) );
596                                         obj.set_tab( url, {}, { 'id' : obj.data.last_patron } );
597                                 }
598                         ],
599                         
600                         'cmd_retrieve_last_record' : [
601                                 ['oncommand'],
602                                 function() {
603                                         obj.data.stash_retrieve();
604                                         if (!obj.data.last_record) {
605                                                 alert(offlineStrings.getString('menu.cmd_retrieve_last_record.session.error'));
606                                                 return;
607                                         }
608                                         var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + obj.data.last_record;
609                                         var content_params = {
610                                                 'session' : ses(),
611                                                 'authtime' : ses('authtime'),
612                                                 'opac_url' : opac_url,
613                                         };
614                                         obj.set_tab(
615                                                 obj.url_prefix(urls.XUL_OPAC_WRAPPER),
616                                                 {'tab_name' : offlineStrings.getString('menu.cmd_retrieve_last_record.status')},
617                                                 content_params
618                                         );
619                                 }
620                         ],
621
622             'cmd_verify_credentials' : [
623                 ['oncommand'],
624                 function() {
625                                         obj.set_tab(
626                                                 obj.url_prefix(urls.XUL_VERIFY_CREDENTIALS),
627                                                 { 'tab_name' : offlineStrings.getString('menu.cmd_verify_credentials.tabname') },
628                                                 {}
629                                         );
630                 }
631             ],
632
633                         /* Cataloging Menu */
634                         'cmd_z39_50_import' : [
635                                 ['oncommand'],
636                                 function() {
637                                         obj.data.stash_retrieve();
638                                         obj.set_tab(obj.url_prefix(urls.XUL_Z3950_IMPORT),{},{});
639                                 }
640                         ],
641                         'cmd_create_marc' : [
642                                 ['oncommand'],
643                                 function() {
644                                         obj.data.stash_retrieve();
645                                         obj.set_tab(obj.url_prefix(urls.XUL_MARC_NEW),{},{});
646                                 }
647                         ],
648
649                         /* Admin menu */
650                         'cmd_change_session' : [
651                                 ['oncommand'],
652                                 function() {
653                                         try {
654                                                 obj.data.stash_retrieve();
655                                                 JSAN.use('util.network'); var network = new util.network();
656                                                 var x = document.getElementById('oc_menuitem');
657                                                 var x_label = x.getAttribute('label_orig');
658                                                 var temp_au = js2JSON( obj.data.list.au[0] );
659                                                 var temp_ses = js2JSON( obj.data.session );
660                                                 if (obj.data.list.au.length > 1) {
661                                                         obj.data.list.au = [ obj.data.list.au[1] ];
662                                                         obj.data.stash('list');
663                                                         network.reset_titlebars( obj.data );
664                                                         x.setAttribute('label', x_label );
665                                                         network.simple_request('AUTH_DELETE', [ obj.data.session.key ] );
666                                                         obj.data.session = obj.data.previous_session;
667                                                         obj.data.stash('session');
668                                             try {
669                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
670                                                                 var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
671                                                                 var cookieUri = ios.newURI("http://" + obj.data.server_unadorned, null, null);
672                                                                 var cookieUriSSL = ios.newURI("https://" + obj.data.server_unadorned, null, null);
673                                                                 var cookieSvc = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);
674
675                                                                 cookieSvc.setCookieString(cookieUri, null, "ses="+obj.data.session.key, null);
676                                                                 cookieSvc.setCookieString(cookieUriSSL, null, "ses="+obj.data.session.key, null);
677
678                                             } catch(E) {
679                                                     alert(offlineStrings.getFormattedString(main.session_cookie.error, [E]));
680                                             }
681
682                                                         removeCSSClass(document.getElementById('main_tabbox'),'operator_change');
683                                                 } else {
684                                                         if (network.get_new_session(offlineStrings.getString('menu.cmd_chg_session.label'),{'url_prefix':obj.url_prefix})) {
685                                                                 obj.data.stash_retrieve();
686                                                                 obj.data.list.au[1] = JSON2js( temp_au );
687                                                                 obj.data.stash('list');
688                                                                 obj.data.previous_session = JSON2js( temp_ses );
689                                                                 obj.data.stash('previous_session');
690                                                                 x.setAttribute('label', offlineStrings.getFormattedString('menu.cmd_chg_session.operator.label', [obj.data.list.au[1].usrname()]) );
691                                                                 addCSSClass(document.getElementById('main_tabbox'),'operator_change');
692                                                         }
693                                                 }
694                                         } catch(E) {
695                                                 obj.error.standard_unexpected_error_alert('cmd_change_session',E);
696                                         }
697                                 }
698                         ],
699                         'cmd_manage_offline_xacts' : [
700                                 ['oncommand'],
701                                 function() {
702                                         obj.set_tab(obj.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS), {'tab_name' : offlineStrings.getString('menu.cmd_manage_offline_xacts.tab')}, {});
703                                 }
704                         ],
705                         'cmd_download_patrons' : [
706                                 ['oncommand'],
707                                 function() {
708                                         try {
709                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
710                                                 var x = new XMLHttpRequest();
711                                                 var url = 'http://' + XML_HTTP_SERVER + '/standalone/list.txt';
712                                                 x.open("GET",url,false);
713                                                 x.send(null);
714                                                 if (x.status == 200) {
715                                                         JSAN.use('util.file'); var file = new util.file('offline_patron_list');
716                                                         file.write_content('truncate',x.responseText);
717                                                         file.close();
718                                                         file = new util.file('offline_patron_list.date');
719                                                         file.write_content('truncate',new Date());
720                                                         file.close();
721                                                         alert(offlineStrings.getString('menu.cmd_download_patrons.complete.status'));
722                                                 } else {
723                                                         alert(offlineStrings.getFormattedString('menu.cmd_download_patrons.error', [x.status, x.statusText]));
724                                                 }
725                                         } catch(E) {
726                                                 obj.error.standard_unexpected_error_alert('cmd_download_patrons',E);
727                                         }
728                                 }
729                         ],
730                         'cmd_adv_user_edit' : [
731                                 ['oncommand'],
732                                 function() {
733                                         obj.data.stash_retrieve();
734                                         obj.set_tab(obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY), {}, { 'perm_editor' : true });
735                                 }
736                         ],
737                         'cmd_print_list_template_edit' : [
738                                 ['oncommand'],
739                                 function() {
740                                         obj.data.stash_retrieve();
741                                         obj.set_tab(obj.url_prefix(urls.XUL_PRINT_LIST_TEMPLATE_EDITOR), {}, {});
742                                 }
743                         ],
744                         'cmd_stat_cat_edit' : [
745                                 ['oncommand'],
746                                 function() {
747                                         obj.data.stash_retrieve();
748                                         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')},{});
749                                 }
750                         ],
751                         'cmd_non_cat_type_edit' : [
752                                 ['oncommand'],
753                                 function() {
754                                         obj.data.stash_retrieve();
755                                         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')},{});
756                                 }
757                         ],
758                         'cmd_copy_location_edit' : [
759                                 ['oncommand'],
760                                 function() {
761                                         obj.data.stash_retrieve();
762                                         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')},{});
763                                 }
764                         ],
765                         'cmd_test' : [
766                                 ['oncommand'],
767                                 function() {
768                                         obj.data.stash_retrieve();
769                                         var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
770                                         obj.set_tab(obj.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
771                                 }
772                         ],
773                         'cmd_test_html' : [
774                                 ['oncommand'],
775                                 function() {
776                                         obj.data.stash_retrieve();
777                                         obj.set_tab(obj.url_prefix(urls.TEST_HTML) + '?ses='+window.escape(ses()),{ 'browser' : true },{});
778                                 }
779                         ],
780                         'cmd_test_xul' : [
781                                 ['oncommand'],
782                                 function() {
783                                         obj.data.stash_retrieve();
784                                         obj.set_tab(obj.url_prefix(urls.TEST_XUL) + '?ses='+window.escape(ses()),{ 'browser' : false },{});
785                                 }
786                         ],
787                         'cmd_console' : [
788                                 ['oncommand'],
789                                 function() {
790                                         obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_CONSOLE),{'tab_name' : offlineStrings.getString('menu.cmd_console.tab')},{});
791                                 }
792                         ],
793                         'cmd_shell' : [
794                                 ['oncommand'],
795                                 function() {
796                                         obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_SHELL),{'tab_name' : offlineStrings.getString('menu.cmd_shell.tab')},{});
797                                 }
798                         ],
799                         'cmd_xuleditor' : [
800                                 ['oncommand'],
801                                 function() {
802                                         obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_XULEDITOR),{'tab_name' : offlineStrings.getString('menu.cmd_xuleditor.tab')},{});
803                                 }
804                         ],
805                         'cmd_fieldmapper' : [
806                                 ['oncommand'],
807                                 function() {
808                                         obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_FIELDMAPPER),{'tab_name' : offlineStrings.getString('menu.cmd_fieldmapper.tab')},{});
809                                 }
810                         ],
811                         'cmd_survey_wizard' : [
812                                 ['oncommand'],
813                                 function() {
814                                         obj.data.stash_retrieve();
815                                         xulG.window.open(obj.url_prefix(urls.XUL_SURVEY_WIZARD),'survey_wizard','chrome'); 
816                                 }
817                         ],
818                         'cmd_public_opac' : [
819                                 ['oncommand'],
820                                 function() {
821                                         var loc = urls.XUL_REMOTE_BROWSER + '?url=' + window.escape(
822                                                 urls.remote
823                                         );
824                                         obj.set_tab( 
825                                                 loc, 
826                                                 {'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
827                                                 { 'no_xulG' : true, 'show_nav_buttons' : true, 'show_print_button' : true } 
828                                         );
829                                 }
830                         ],
831                         'cmd_clear_cache' : [
832                                 ['oncommand'],
833                                 function clear_the_cache() {
834                                         try {
835                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
836                                                 var cacheClass          = Components.classes["@mozilla.org/network/cache-service;1"];
837                                                 var cacheService        = cacheClass.getService(Components.interfaces.nsICacheService);
838                                                 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
839                                                 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
840                                         } catch(E) {
841                                                 dump(E+'\n');alert(E);
842                                         }
843                                 }
844                         ],
845                         'cmd_restore_all_tabs' : [
846                                 ['oncommand'],
847                                 function() {
848                                         var tabs = obj.controller.view.tabs;
849                                         for (var i = 0; i < tabs.childNodes.length; i++) {
850                                                 tabs.childNodes[i].hidden = false;
851                                         }
852                                 }
853                         ],
854                         'cmd_extension_manager' : [
855                                 ['oncommand'],
856                                 function() {
857                                         obj.set_tab('chrome://mozapps/content/extensions/extensions.xul?type=extensions',{'tab_name' : offlineStrings.getString('menu.cmd_extension_manager.tab')},{});
858                                 }
859                         ],
860                         'cmd_theme_manager' : [
861                                 ['oncommand'],
862                                 function() {
863                                         obj.set_tab('chrome://mozapps/content/extensions/extensions.xul?type=themes',{'tab_name' : offlineStrings.getString('menu.cmd_theme_manager.tab')},{});
864                                 }
865                         ],
866                         'cmd_about_config' : [
867                                 ['oncommand'],
868                                 function() {
869                                         obj.set_tab('chrome://global/content/config.xul',{'tab_name' : 'about:config'},{});
870                                 }
871                         ],
872                         'cmd_shutdown' : [
873                                 ['oncommand'],
874                                 function() {
875                                         if (window.confirm(offlineStrings.getString('menu.cmd_shutdown.prompt'))) {
876                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
877                                                 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
878                                                 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
879                                                 var enumerator = windowManagerInterface.getEnumerator(null);
880                                                 var w; // close all other windows
881                                                 while ( w = enumerator.getNext() ) {
882                                                         if (w != window) w.close();
883                                                 }
884                                                 window.close();
885                                         }
886                                 }
887                         ],
888
889                         'cmd_acq_view_picklist' : [
890                                 ['oncommand'],
891                                 function() {
892                                         obj.set_tab( 
893                                                 obj.url_prefix(urls.XUL_ACQ_PICKLIST),
894                                                 //{'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
895                                                 {'tab_name' : 'Selection Lists', 'browser' : false}, 
896                                                 {'show_nav_buttons' : true, 'show_print_button' : true} 
897                                         );
898                                 }
899                         ],
900                         'cmd_acq_view_po' : [
901                                 ['oncommand'],
902                                 function() {
903                                         obj.set_tab( 
904                                                 obj.url_prefix(urls.XUL_ACQ_PO),
905                                                 //{'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
906                                                 {'tab_name' : 'Purchase Orders', 'browser' : false}, 
907                                                 {'show_nav_buttons' : true, 'show_print_button' : true} 
908                                         );
909                                 }
910                         ],
911                         'cmd_acq_upload' : [
912                                 ['oncommand'],
913                                 function() {
914                                         obj.set_tab( 
915                                                 obj.url_prefix(urls.XUL_ACQ_UPLOAD),
916                                                 //{'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
917                                                 {'tab_name' : 'Load Order Record', 'browser' : false}, 
918                                                 {'show_nav_buttons' : true, 'show_print_button' : true} 
919                                         );
920                                 }
921                         ],
922
923                 };
924
925                 JSAN.use('util.controller');
926                 var cmd;
927                 obj.controller = new util.controller();
928                 obj.controller.init( { 'window_knows_me_by' : 'g.menu.controller', 'control_map' : cmd_map } );
929
930                 obj.controller.view.tabbox = window.document.getElementById('main_tabbox');
931                 obj.controller.view.tabs = obj.controller.view.tabbox.firstChild;
932                 obj.controller.view.panels = obj.controller.view.tabbox.lastChild;
933
934                 obj.new_tab(null,{'focus':true},null);
935
936                 obj.init_tab_focus_handlers();
937         },
938
939         'spawn_search' : function(s) {
940                 var obj = this;
941                 obj.error.sdump('D_TRACE', offlineStrings.getFormattedString('menu.spawn_search.msg', [js2JSON(s)]) ); 
942                 obj.data.stash_retrieve();
943                 var loc = obj.url_prefix(urls.XUL_PATRON_DISPLAY);
944                 loc += '?doit=1&query=' + window.escape(js2JSON(s));
945                 obj.new_tab( loc, {}, {} );
946         },
947
948         'init_tab_focus_handlers' : function() {
949                 var obj = this;
950                 for (var i = 0; i < obj.controller.view.tabs.childNodes.length; i++) {
951                         var tab = obj.controller.view.tabs.childNodes[i];
952                         var panel = obj.controller.view.panels.childNodes[i];
953                         tab.addEventListener(
954                                 'command',
955                                 function(p) {
956                                         return function() {
957                                                 try {
958                                                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
959                                                                 if (p
960                                                                         && p.firstChild 
961                                                                         && ( p.firstChild.nodeName == 'iframe' || p.firstChild.nodeName == 'browser' )
962                                                                         && p.firstChild.contentWindow 
963                                                                 ) {
964                                                                         if (typeof p.firstChild.contentWindow.default_focus == 'function') {
965                                                                                 p.firstChild.contentWindow.default_focus();
966                                                                         } else {
967                                                                                 //p.firstChild.contentWindow.firstChild.focus();
968                                                                         }
969                                                                 }
970                                                 } catch(E) {
971                                                         obj.error.sdump('D_ERROR','init_tab_focus_handler: ' + js2JSON(E));
972                                                 }
973                                         }
974                                 }(panel),
975                                 false
976                         );
977                 }
978         },
979
980         'close_all_tabs' : function() {
981                 var obj = this;
982                 try {
983                         var count = obj.controller.view.tabs.childNodes.length;
984                         for (var i = 0; i < count; i++) obj.close_tab();
985                         setTimeout( function(){ obj.controller.view.tabs.firstChild.focus(); }, 0);
986                 } catch(E) {
987                         obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.close_all_tabs.error'),E);
988                 }
989         },
990
991         'close_tab' : function () {
992                 var idx = this.controller.view.tabs.selectedIndex;
993                 var tab = this.controller.view.tabs.childNodes[idx];
994                 var panel = this.controller.view.panels.childNodes[ idx ];
995                 while ( panel.lastChild ) panel.removeChild( panel.lastChild );
996                 if (idx == 0) {
997                         try {
998                                 this.controller.view.tabs.advanceSelectedTab(+1);
999                         } catch(E) {
1000                                 this.error.sdump('D_TAB','failed tabs.advanceSelectedTab(+1):'+js2JSON(E) + '\n');
1001                                 try {
1002                                         this.controller.view.tabs.advanceSelectedTab(-1);
1003                                 } catch(E) {
1004                                         this.error.sdump('D_TAB','failed again tabs.advanceSelectedTab(-1):'+
1005                                                 js2JSON(E) + '\n');
1006                                 }
1007                         }
1008                 } else {
1009                         try {
1010                                 this.controller.view.tabs.advanceSelectedTab(-1);
1011                         } catch(E) {
1012                                 this.error.sdump('D_TAB','failed tabs.advanceSelectedTab(-1):'+js2JSON(E) + '\n');
1013                                 try {
1014                                         this.controller.view.tabs.advanceSelectedTab(+1);
1015                                 } catch(E) {
1016                                         this.error.sdump('D_TAB','failed again tabs.advanceSelectedTab(+1):'+
1017                                                 js2JSON(E) + '\n');
1018                                 }
1019                         }
1020
1021                 }
1022                 
1023                 this.error.sdump('D_TAB','\tnew tabbox.selectedIndex = ' + this.controller.view.tabbox.selectedIndex + '\n');
1024
1025                 this.controller.view.tabs.childNodes[ idx ].hidden = true;
1026                 this.error.sdump('D_TAB','tabs.childNodes[ ' + idx + ' ].hidden = true;\n');
1027
1028                 // Make sure we keep at least one tab open.
1029                 var tab_flag = true;
1030                 for (var i = 0; i < this.controller.view.tabs.childNodes.length; i++) {
1031                         var tab = this.controller.view.tabs.childNodes[i];
1032                         if (!tab.hidden)
1033                                 tab_flag = false;
1034                 }
1035                 if (tab_flag) {
1036                         this.controller.view.tabs.selectedIndex = 0;
1037                         this.new_tab(); 
1038                 }
1039         },
1040
1041         'find_free_tab' : function() {
1042                 var last_not_hidden = -1;
1043                 for (var i = 0; i<this.controller.view.tabs.childNodes.length; i++) {
1044                         var tab = this.controller.view.tabs.childNodes[i];
1045                         if (!tab.hidden)
1046                                 last_not_hidden = i;
1047                 }
1048                 if (last_not_hidden == this.controller.view.tabs.childNodes.length - 1)
1049                         last_not_hidden = -1;
1050                 // If the one next to last_not_hidden is hidden, we want it.
1051                 // Basically, we fill in tabs after existing tabs for as 
1052                 // long as possible.
1053                 var idx = last_not_hidden + 1;
1054                 var candidate = this.controller.view.tabs.childNodes[ idx ];
1055                 if (candidate.hidden)
1056                         return idx;
1057                 // Alright, find the first hidden then
1058                 for (var i = 0; i<this.controller.view.tabs.childNodes.length; i++) {
1059                         var tab = this.controller.view.tabs.childNodes[i];
1060                         if (tab.hidden)
1061                                 return i;
1062                 }
1063                 return -1;
1064         },
1065
1066         'new_tab' : function(url,params,content_params) {
1067                 var tc = this.find_free_tab();
1068                 if (tc == -1) { return null; } // 9 tabs max
1069                 var tab = this.controller.view.tabs.childNodes[ tc ];
1070                 tab.hidden = false;
1071                 if (!content_params) content_params = {};
1072                 if (!params) params = {};
1073                 if (!params.tab_name) params.tab_name = offlineStrings.getString('menu.new_tab.tab');
1074                 if (!params.nofocus) params.focus = true; /* make focus the default */
1075                 try {
1076                         if (params.focus) this.controller.view.tabs.selectedIndex = tc;
1077                         params.index = tc;
1078                         this.set_tab(url,params,content_params);
1079                 } catch(E) {
1080                         this.error.sdump('D_ERROR',E);
1081                 }
1082         },
1083
1084     'network_meter' : {
1085         'inc' : function(app,method) {
1086             try {
1087                 var m = document.getElementById('network_progress');
1088                 var count = 1 + Number( m.getAttribute('count') );
1089                 m.setAttribute('mode','undetermined');
1090                 m.setAttribute('count', count);
1091                 var rows = document.getElementById('network_progress_rows');
1092                 var row = document.getElementById('network_progress_tip_'+app+'_'+method);
1093                 if (!row) {
1094                     row = document.createElement('row'); row.setAttribute('id','network_progress_tip_'+app+'_'+method);
1095                     var a = document.createElement('label'); a.setAttribute('value','App:');
1096                     var b = document.createElement('label'); b.setAttribute('value',app);
1097                     var c = document.createElement('label'); c.setAttribute('value','Method:');
1098                     var d = document.createElement('label'); d.setAttribute('value',method);
1099                     var e = document.createElement('label'); e.setAttribute('value','Total:');
1100                     var f = document.createElement('label'); f.setAttribute('value','0'); 
1101                     f.setAttribute('id','network_progress_tip_total_'+app+'_'+method);
1102                     var g = document.createElement('label'); g.setAttribute('value','Outstanding:');
1103                     var h = document.createElement('label'); h.setAttribute('value','0');
1104                     h.setAttribute('id','network_progress_tip_out_'+app+'_'+method);
1105                     row.appendChild(a); row.appendChild(b); row.appendChild(c);
1106                     row.appendChild(d); row.appendChild(e); row.appendChild(f);
1107                     row.appendChild(g); row.appendChild(h); rows.appendChild(row);
1108                 }
1109                 var total = document.getElementById('network_progress_tip_total_'+app+'_'+method);
1110                 if (total) {
1111                     total.setAttribute('value', 1 + Number( total.getAttribute('value') ));
1112                 }
1113                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
1114                 if (out) {
1115                     out.setAttribute('value', 1 + Number( out.getAttribute('value') ));
1116                 }
1117             } catch(E) {
1118                 dump('network_meter.inc(): ' + E + '\n');
1119             }
1120         },
1121         'dec' : function(app,method) {
1122             try {
1123                 var m = document.getElementById('network_progress');
1124                 var count = -1 + Number( m.getAttribute('count') );
1125                 if (count < 0) count = 0;
1126                 if (count == 0) m.setAttribute('mode','determined');
1127                 m.setAttribute('count', count);
1128                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
1129                 if (out) {
1130                     out.setAttribute('value', -1 + Number( out.getAttribute('value') ));
1131                 }
1132             } catch(E) {
1133                 dump('network_meter.dec(): ' + E + '\n');
1134             }
1135         }
1136     },
1137     'set_patron_tab' : function(params,content_params) {
1138         var obj = this;
1139         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1140         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1141         obj.set_tab(url,params ? params : {},content_params ? content_params : {});
1142     },
1143     'new_patron_tab' : function(params,content_params) {
1144         var obj = this;
1145         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1146         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1147         obj.new_tab(url,params ? params : {},content_params ? content_params : {});
1148     },
1149         'set_tab' : function(url,params,content_params) {
1150                 var obj = this;
1151                 if (!url) url = '/xul/server/';
1152                 if (!url.match(/:\/\//) && !url.match(/^data:/)) url = urls.remote + url;
1153                 if (!params) params = {};
1154                 if (!content_params) content_params = {};
1155                 var idx = this.controller.view.tabs.selectedIndex;
1156                 if (params && typeof params.index != 'undefined') idx = params.index;
1157                 var tab = this.controller.view.tabs.childNodes[ idx ];
1158                 if (params.focus) tab.focus();
1159                 var panel = this.controller.view.panels.childNodes[ idx ];
1160                 while ( panel.lastChild ) panel.removeChild( panel.lastChild );
1161
1162                 content_params.new_tab = function(a,b,c) { return obj.new_tab(a,b,c); };
1163                 content_params.set_tab = function(a,b,c) { return obj.set_tab(a,b,c); };
1164                 content_params.new_patron_tab = function(a,b) { return obj.new_patron_tab(a,b); };
1165                 content_params.set_patron_tab = function(a,b) { return obj.set_patron_tab(a,b); };
1166                 content_params.set_tab_name = function(name) { tab.setAttribute('label',(idx + 1) + ' ' + name); };
1167                 content_params.open_chrome_window = function(a,b,c) { return xulG.window.open(a,b,c); };
1168                 content_params.url_prefix = function(url) { return obj.url_prefix(url); };
1169         content_params.network_meter = obj.network_meter;
1170         content_params.chrome_xulG = xulG;
1171                 if (params && params.tab_name) content_params.set_tab_name( params.tab_name );
1172                 
1173                 var frame;
1174                 try {
1175             if (typeof params.browser == 'undefined') params.browser = false;
1176                         if (params.browser) {
1177                                 obj.id_incr++;
1178                                 frame = this.w.document.createElement('browser');
1179                                 frame.setAttribute('flex','1');
1180                                 frame.setAttribute('type','content');
1181                                 frame.setAttribute('id','frame_'+obj.id_incr);
1182                                 panel.appendChild(frame);
1183                                 try {
1184                                         dump('creating browser with src = ' + url + '\n');
1185                                         JSAN.use('util.browser');
1186                                         var b = new util.browser();
1187                                         b.init(
1188                                                 {
1189                                                         'url' : url,
1190                                                         'push_xulG' : true,
1191                                                         'alt_print' : false,
1192                                                         'browser_id' : 'frame_'+obj.id_incr,
1193                                                         'passthru_content_params' : content_params,
1194                                                 }
1195                                         );
1196                                 } catch(E) {
1197                                         alert(E);
1198                                 }
1199                         } else {
1200                                 frame = this.w.document.createElement('iframe');
1201                                 frame.setAttribute('flex','1');
1202                                 panel.appendChild(frame);
1203                                 dump('creating iframe with src = ' + url + '\n');
1204                                 frame.setAttribute('src',url);
1205                                 try {
1206                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1207                                         var cw = frame.contentWindow;
1208                                         if (typeof cw.wrappedJSObject != 'undefined') cw = cw.wrappedJSObject;
1209                                         cw.IAMXUL = true;
1210                                         cw.xulG = content_params;
1211                                 } catch(E) {
1212                                         this.error.sdump('D_ERROR', 'main.menu: ' + E);
1213                                 }
1214                         }
1215                 } catch(E) {
1216                         this.error.sdump('D_ERROR', 'main.menu:2: ' + E);
1217                         alert(offlineStrings.getString('menu.set_tab.error'));
1218                 }
1219
1220                 return frame;
1221         }
1222
1223 }
1224
1225 dump('exiting main/menu.js\n');