]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
Merge branch 'opac-tt-poc' of git+ssh://yeti.esilibrary.com/home/evergreen/evergreen...
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / rdetail.js
1
2 /* */
3
4 detachAllEvt('common', 'run');
5 attachEvt("common", "run", rdetailDraw);
6 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
7 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
8 attachEvt("rdetail", "recordDrawn", rdetailGetPageIds);
9
10 /* Per-skin configuration settings */
11 var rdetailLocalOnly = true;
12 var rdetailShowLocal = true;
13 var rdetailShowCopyLocation = true;
14 var rdetailGoogleBookPreview = true;
15 var rdetailDisplaySerialHoldings = true;
16 var rdetailEnableRefWorks = false;
17 var rdetailRefWorksHost = 'http://www.refworks.com';
18
19 /* vars vars vars */
20 var record = null;
21 var cp_statuses = null;
22 var recordsCache = [];
23
24 var copyRowParent = null;
25 var copyRow = null;
26 var statusRow = null;
27 var numStatuses = null;
28 var defaultCN;
29 var callnumberCache = {};
30 var globalCNCache = {};
31 var localTOC;
32 var cachedRecords;
33 var _statusPositions = {};
34 var opac_strings;
35
36 var nextContainerIndex;
37
38 var nextRecord;
39 var prevRecord;
40
41 var rdetailPrev = null;
42 var rdetailNext = null;
43 var rdetailStart = null;
44 var rdetailEnd = null;
45
46 var mfhdDetails = [];
47 var orgHiding = false;
48
49 if(location.href.match(/&place_hold=1/)) {
50     // prevent load flicker between canvases
51     hideMe(dojo.byId('canvas_main'));
52 }
53
54 /* serials are currently the only use of Dojo strings in the OPAC */
55 if (rdetailDisplaySerialHoldings) {
56         dojo.require("dijit.Menu");
57         dojo.require("dijit.form.Button");
58         dojo.requireLocalization("openils.opac", "opac");
59         opac_strings = dojo.i18n.getLocalization("openils.opac", "opac");
60 }
61
62 function rdetailReload() {
63         var args = {};
64         args[PARAM_LOCATION] = getNewSearchLocation();
65         args[PARAM_DEPTH] = depthSelGetDepth();
66         goTo(buildOPACLink(args));
67 }
68
69 /* looks to see if we have a next and/or previous record in the
70    record cache, if so, set up the nav links */
71 function rdetailSetPaging(ids) {
72
73         cachedRecords = {};
74         cachedRecords.ids = ids;
75
76         for( var i = 0; i < cachedRecords.ids.length; i++ ) {
77                 var rec = cachedRecords.ids[i];
78                 if( rec == getRid() ) {
79                         if( i > 0 ) prevRecord = cachedRecords.ids[i-1];
80                         if( i < cachedRecords.ids.length - 1 )
81                                 nextRecord = cachedRecords.ids[i+1];
82                         break;
83                 }
84         }
85
86         $('np_offset').appendChild(text(i + 1));
87         $('np_count').appendChild(text(getHitCount()));
88
89         if(prevRecord) {
90                 unHideMe($('np_table'));
91                 unHideMe($('np_prev'));
92                 unHideMe($('np_start'));
93                 rdetailPrev = function() { _rdetailNav(prevRecord); };
94                 rdetailStart = function() { _rdetailNav(cachedRecords.ids[0]); };
95         }
96
97         if(nextRecord) {
98                 unHideMe($('np_table'));
99                 unHideMe($('np_next'));
100                 unHideMe($('np_end'));
101                 rdetailNext = function() { _rdetailNav(nextRecord); };
102                 rdetailEnd = function() { _rdetailNav(cachedRecords.ids[cachedRecords.ids.length-1]); };
103         }
104
105         runEvt('rdetail', 'nextPrevDrawn', i, cachedRecords.ids.length);
106 }
107
108
109 function _rdetailNav(id, offset) {
110         var args = {};
111         args[PARAM_RID] = id;
112         goTo(buildOPACLink(args));
113 }
114
115 function rdetailHandlePlaceHold() {
116     function reload() {
117         location.href = location.href.replace(/&place_hold=1/, '');
118     }
119     attachEvt("common", "holdUpdated", reload);
120     attachEvt("common", "holdUpdateCanceled", reload);
121     attachEvt("common", "loginCanceled", reload);
122     holdsDrawEditor({record:getRid(), type: 'T'});
123 }
124
125 function rdetailDraw() {
126
127     if(new CGI().param('place_hold')) {
128         rdetailHandlePlaceHold();
129         return;
130     }
131
132         detachAllEvt('common','depthChanged');
133         detachAllEvt('common','locationUpdated');
134         attachEvt('common','depthChanged', rdetailReload);
135         attachEvt('common','locationUpdated', rdetailReload);
136         attachEvt('common','holdUpdated', rdetailReload);
137         attachEvt('common','holdUpdateCanceled', rdetailReload);
138
139         copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
140         copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
141         statusRow = G.ui.rdetail.cp_status.parentNode;
142         statusRow.id = '__rdsrow';
143
144         G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
145         G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
146
147         if(getLocation() == globalOrgTree.id())
148                 hideMe(G.ui.rdetail.cp_info_all);
149
150     if(getRid()) {
151
152             var req = new Request(FETCH_RMODS, getRid());
153             req.callback(_rdetailDraw);
154             req.send();
155
156     } else { // No record ID was specified
157
158        // If we have an ISBN in the URL, let's try to find that record
159        // This allows direct linking by ISBN.
160        // Note, this uses the first record it finds
161        if(getRtype() == RTYPE_ISBN) { 
162             var req = new Request(FETCH_ADV_ISBN_RIDS, getAdvTerm() );
163             req.callback(
164                 function(r) {
165                     var blob = r.getResultObject();
166                     if(blob && blob.count > 0) 
167                         RID = blob.ids[0]; 
168                     var req2 = new Request(FETCH_RMODS, getRid());
169                     req2.callback(_rdetailDraw);
170                     req2.send();
171                 }
172             );
173             req.send();
174         }
175     }
176
177
178         if (rdetailDisplaySerialHoldings && (
179         isXUL() || !fetchOrgSettingDefault(
180             getLocation(), "opac.fully_compressed_serial_holdings")
181         )
182     ) {
183                 var req = new Request(FETCH_MFHD_SUMMARY, getRid());
184                 req.callback(_holdingsDraw);
185                 req.send();
186                 if (isXUL()) {
187                         var here = findOrgUnit(getLocation());
188                         dojo.place("<div id='mfhd_ad_menu'></div>", "rdetail_details_table", "after");
189                         var mfhd_add = new dijit.Menu({style:"float: right;"});
190                         new dijit.MenuItem({onClick:function(){
191                                 var req = new Request(CREATE_MFHD_RECORD, G.user.session, 1, here.id(), getRid());
192                                 var res = req.send();
193                                 alert(dojo.string.substitute(opac_strings.CREATED_MFHD_RECORD, [here.name()]));
194                         }, label:opac_strings.CREATE_MFHD}).placeAt(mfhd_add);
195                         mfhd_add.placeAt(mfhd_ad_menu);
196                 }
197         }
198
199         detachAllEvt("result", "idsReceived");
200         G.evt.result.hitCountReceived = [];
201         G.evt.result.recordReceived = [];
202         G.evt.result.copyCountsReceived = [];
203         G.evt.result.allRecordsReceived = [];
204
205     if(isXUL()) 
206         unHideMe($('rdetail_show_orders'));
207 }
208
209 function rdetailGetPageIds() {
210         attachEvt("result", "idsReceived", rdetailSetPaging );
211         resultFetchAllRecords = true;
212         rresultCollectIds(true);
213 }
214
215
216 function buildunAPISpan (span, type, id) {
217         var cgi = new CGI();
218         var d = new Date();
219
220         addCSSClass(span,'unapi-id');
221
222         span.setAttribute(
223                         'title', 'tag:' + cgi.server_name + ',' +
224                         d.getFullYear() + ':' + type + '/' + id
225                         );
226 }
227
228 function rdetailViewMarc(r,id) {
229         hideMe($('rdetail_extras_loading'));
230         $('rdetail_view_marc_box').innerHTML = r.getResultObject();
231
232         var div = elem('div', { "class" : 'hide_me' });
233         var span = div.appendChild( elem('abbr') );
234
235         buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
236
237         $('rdetail_view_marc_box').insertBefore(span, $('rdetail_view_marc_box').firstChild);
238 }
239
240 function rdetailForeignItems(r,id) {
241         hideMe($('rdetail_extras_loading'));
242     var tbody = $('rdetail_foreign_items_tbody');
243
244     var robj = r.getResultObject(); /* mvr list with foreign_copy_maps fleshed */
245
246     for (var i = 0; i < robj.length; i++) {
247         var args = {};
248         args.page = RDETAIL;
249         args[PARAM_OFFSET] = 0;
250         args[PARAM_RID] = robj[i].doc_id();
251         var row = elem('tr'); tbody.appendChild(row);
252         var td1 = elem('td'); row.appendChild(td1);
253         var title = elem(
254             'a',
255             {
256                 'href' : buildOPACLink(args),
257                 'class' : 'classic_link'
258             },
259             robj[i].title()
260         );
261         td1.appendChild(title);
262         var td2 = elem('td',{},robj[i].author()); row.appendChild(td2);
263         var td3 = elem('td'); row.appendChild(td3);
264         var details = elem(
265             'a',
266             {
267                 'href' : 'javascript:void(0)',
268                 'class' : 'classic_link'
269             },
270             'Copy Details'
271         );
272         details.onclick = function(idx,context_row){
273             return function() {
274                 cpdBuild(
275                     tbody,
276                     context_row,
277                     robj[idx],
278                     null,
279                     1,
280                     0,
281                     1,
282                     dojo.map(
283                         robj[idx].foreign_copy_maps(),
284                         function(x){ return x.target_copy(); }
285                     ),
286                     dojo.map(
287                         robj[idx].foreign_copy_maps(),
288                         function(x){ return x.peer_type().name(); }
289                     )
290                 );
291             };
292         }(i,row);
293         td3.appendChild(details);
294     }
295 }
296
297
298
299 function rdetailShowLocalCopies() {
300         rdetailShowLocal = true;
301         rdetailBuildInfoRows();
302         hideMe(G.ui.rdetail.cp_info_local);
303         unHideMe(G.ui.rdetail.cp_info_all);
304         hideMe(G.ui.rdetail.cp_info_none); 
305 }
306
307 function rdetailShowAllCopies() {
308
309         rdetailShowLocal = false;
310         rdetailBuildInfoRows();
311         hideMe(G.ui.rdetail.cp_info_all);
312         unHideMe(G.ui.rdetail.cp_info_local);
313         hideMe(G.ui.rdetail.cp_info_none); 
314 }
315
316 function OpenMarcEditWindow(pcrud, rec) {
317         /*
318            To run in Firefox directly, must set signed.applets.codebase_principal_support
319            to true in about:config
320          */
321         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
322         win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
323         dojo.require('openils.PermaCrud');
324
325         win.xulG = {
326                 "record": {"marc": rec.marc(), "rtype": "sre"},
327                 "save": {
328                         "label": opac_strings.SAVE_MFHD_LABEL,
329                         "func": function(xmlString) {
330                                 rec.marc(xmlString);
331                                 rec.edit_date('now');
332                                 rec.ischanged(true);
333                                 pcrud.update(rec);
334                         }
335                 },
336         'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
337         'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
338         };
339 }
340
341 function loadMarcEditor(recId) {
342         var pcrud = new openils.PermaCrud({"authtoken": G.user.session});
343         var rec = pcrud.retrieve("sre", recId);
344         if (rec) {
345                 OpenMarcEditWindow(pcrud, rec);
346         }
347 }
348
349 /*
350  * This function could be written much more intelligently
351  * Limited brain power means that I'm brute-forcing it for now
352  */
353 function _holdingsDraw(h) {
354         holdings = h.getResultObject();
355         if (!holdings) { return null; }
356
357         dojo.forEach(holdings, _holdingsDrawMFHD);
358
359         // Populate XUL menus
360         if (isXUL()) {
361                 runEvt('rdetail','MFHDDrawn');
362         }
363 }
364
365 function _holdingsDrawMFHD(holdings, entryNum) {
366
367         var here = findOrgUnit(getLocation());
368         if (getDepth() > 0 || getDepth === 0 ) {
369                 while (getDepth() < findOrgDepth(here))
370                 here = findOrgUnit( here.parent_ou() );
371                 if (!orgIsMine(findOrgUnit(here), findOrgUnit(holdings.owning_lib()))) {
372                         return null;
373                 }
374         }
375
376         var hb = holdings.basic_holdings();
377         var hba = holdings.basic_holdings_add();
378         var hs = holdings.supplement_holdings();
379         var hsa = holdings.supplement_holdings_add();
380         var hi = holdings.index_holdings();
381         var hia = holdings.index_holdings_add();
382         var ho = holdings.online();
383         var hm = holdings.missing();
384         var hinc = holdings.incomplete();
385         var hloc = holdings.location() || 'MFHD';
386
387         if (    hb.length == 0 && hba.length == 0 && hs.length == 0 &&
388                 hsa.length == 0 && hi.length == 0 && hia.length == 0 &&
389                 ho.length == 0 && hm.length == 0 && hinc.length == 0
390         ) {
391
392                 if (isXUL()) {
393                         /* 
394                          * If we have a record, but nothing to show for it, then the
395                          * record is likely empty or corrupt. This gives cataloguers a
396                          * chance to add holdings or correct the record
397                          */
398                         hb = ['PLACEHOLDER'];
399                 } else {
400                         return null;
401                 }
402         }
403
404         // Show entryNum + 1 in staff client for better menu correlation
405         // Maybe this should be holdings.sre_id() instead? (which could get long after time)
406         var entryNumString = '';
407         if (isXUL()) {
408                 var entryNumInc = entryNum + 1;
409                 entryNumString = ' [Entry #'+entryNumInc+'] ';
410         }
411
412         var refNode;
413         if (entryNum > 0) {
414                 refNode = 'rdetail_holdings_table_' + (entryNum - 1);
415         } else {
416                 refNode = 'rdetail_details_table';
417         }
418
419         dojo.place("<table style='width: 100%;' id='rdetail_holdings_table_"+entryNum+"'><caption id='mfhdHoldingsCaption" + entryNum + "' class='rdetail_header color_1'>" +
420                 dojo.string.substitute(opac_strings.HOLDINGS_TABLE_CAPTION, [hloc]) + entryNumString +
421                 "</caption><tbody id='rdetail_holdings_tbody_" + entryNum +
422                 "'></tbody></table>", refNode, "after"
423         );
424         if (hb.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.BASIC_HOLDINGS, hb); }
425         if (hba.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.BASIC_HOLDINGS_ADD, hba); }
426         if (hs.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.SUPPLEMENT_HOLDINGS, hs); }
427         if (hsa.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.SUPPLEMENT_HOLDINGS_ADD, hsa); }
428         if (hi.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.INDEX_HOLDINGS, hi); }
429         if (hia.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.INDEX_HOLDINGS_ADD, hia); }
430         if (ho.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.ONLINE_VOLUMES, ho); }
431         if (hm.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.MISSING_VOLUMES, hm); }
432         if (hinc.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.INCOMPLETE_VOLUMES, hinc); }
433
434         if (isXUL()) {
435                 mfhdDetails.push({ 'id' : holdings.sre_id(), 'label' : hloc, 'entryNum' : entryNum, 'owning_lib' : holdings.owning_lib() });
436                 dojo.require('openils.Event');
437                 dojo.require('openils.PermaCrud');
438                 var mfhd_edit = new dijit.Menu({});
439                 new dijit.MenuItem({onClick: function(){loadMarcEditor(holdings.sre_id())}, label:opac_strings.EDIT_MFHD_RECORD}).placeAt(mfhd_edit, "first");
440                 new dijit.MenuItem({onClick:function(){
441                         // Avoid accidental deletion of MFHD records
442                         if (!confirm(opac_strings.DELETE_MFHD_CONFIRM)) {
443                                 return;
444                         }
445                         var pcrud = new openils.PermaCrud({"authtoken": G.user.session});
446                         var mfhd_rec = pcrud.retrieve("sre", holdings.sre_id());
447                         if (mfhd_rec) {
448                                 pcrud.eliminate(mfhd_rec);
449                                 alert(dojo.string.substitute(opac_strings.DELETED_MFHD_RECORD, [holdings.sre_id()]));
450                         }
451                 }, label:opac_strings.DELETE_MFHD}).placeAt(mfhd_edit, "last");
452                 // new dijit.MenuItem({onClick:function(){alert("Edit properties " + holdings.sre_id());}, label:opac_strings.EDIT_PROPERTIES}).placeAt(mfhd_edit, "last");
453                 var mfhd_mb = new dijit.form.DropDownButton({dropDown: mfhd_edit, label:opac_strings.EDIT_MFHD_MENU, style:"float:right"});
454                 mfhd_mb.placeAt("mfhdHoldingsCaption" + entryNum, "last");
455                 mfhd_edit.startup();
456         }
457 }
458
459 function _holdingsDrawMFHDEntry(entryNum, entryName, entry) {
460         var flatEntry = entry.toString().replace(/,/g, ', ');
461         dojo.place("<tr><td> </td><td nowrap='nowrap' class='rdetail_desc'>" + entryName + "</td><td class='rdetail_item'>" + flatEntry + "</td></tr>", "rdetail_holdings_tbody_" + entryNum, "last");
462 }
463
464 function _rdetailDraw(r) {
465         record = r.getResultObject();
466
467         runEvt('rdetail', 'recordRetrieved', record.doc_id());
468
469         G.ui.rdetail.title.appendChild(text(record.title()));
470         buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
471         G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
472         G.ui.rdetail.edition.appendChild(text(record.edition()));
473         G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
474         G.ui.rdetail.publisher.appendChild(text(record.publisher()));
475         $('rdetail_physical_desc').appendChild(text(record.physical_description()));
476         r = record.types_of_resource();
477         if(r) {
478                 G.ui.rdetail.tor.appendChild(text(r[0]));
479                 setResourcePic( G.ui.rdetail.tor_pic, r[0]);
480         }
481         G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
482
483         try{
484                 if(record.isbn()) {
485                         if(ENABLE_ADDED_CONTENT_ATTRIB_LINKS) {
486                                 unHideMe($('rdetail.jacket_attrib_div'));
487                                 var href = $('rdetail.jacket_attrib_link').getAttribute('href') +cleanISBN(record.isbn());
488                                 $('rdetail.jacket_attrib_link').setAttribute('href', href);
489                         }
490                         rdetailCheckForGBPreview();
491
492                 } else {
493                         hideMe($("rdetail.jacket_attrib_div"));
494                         hideMe($("rdetail_img_link"));
495                 }
496         } catch(E) {}
497
498
499         // see if the record has any external links 
500         var links = record.online_loc();
501         for( var i = 0; links && links.length > 0 && i < links.length; i = i + 3 ) {
502                 var href = links[i];
503                 // avoid matching "HTTP: The Complete Reference"
504                 if( href.match(/https?:\/|ftps?:\/|mailto:/i) ) {
505                         unHideMe($('rdetail_online_row'));
506                         // MODS can contain a display label (used for the text of the link)
507                         // as well as a note about the URL; many legacy systems conflate the
508                         // two and generate MARC records that expect the note to be used as
509                         // the text of the link, with no display label; here's the canonical
510                         // format:
511                         //
512                         // 856 40 $uhttp://localhost$yDisplay label$zPublic note
513                         //
514                         // Note that the MARC21slim2MODS XSL concatenates $3 and $y together
515                         // (as $y was defined later in MARC21's life as the display label)
516                         var displayLabel = '' + links[i+1];
517                         var note = '' + links[i+2];
518                         if(!displayLabel || displayLabel.match(/https?:\/|ftps?:\/|mailto:/i)) {
519                                 if(!note || note.match(/https?:\/|ftps?:\/|mailto:/i)) {
520                                         displayLabel = href;
521                                 } else {
522                                         displayLabel = note;
523                                 }
524                         }
525                         $('rdetail_online').appendChild(elem('a', {href:href,'class':'classic_link'}, displayLabel));
526                         if (note && note != displayLabel) {
527                                 $('rdetail_online').appendChild(elem('span', {'class':'url_note'}, ' - ' + note));
528                         }
529                         $('rdetail_online').appendChild(elem('br'));
530                 }
531         }
532
533         // Fill in our unAPI ID, if anyone cares
534         var abbrs = document.getElementsByTagName('abbr');
535         var span;
536         for (var i = 0; i < abbrs.length; i++) {
537                 if (abbrs[i].getAttribute('name') == 'unapi') {
538                         span = abbrs[i];
539                         break;
540                 }
541         }
542         buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
543
544         $('rdetail_place_hold').onclick = function() {
545         var src = location.href;
546
547         if(forceLoginSSL && src.match(/^http:/)) {
548
549             src = src.replace(/^http:/, 'https:');
550
551             if(!src.match(/&place_hold=1/)) {
552                 src += '&place_hold=1';
553             }
554
555             location.href = src;
556
557         } else {
558             holdsDrawEditor({record:record.doc_id(), type:'T'});
559         }
560     }
561
562
563         var RW = $('rdetail_exp_refworks');
564         if (RW && rdetailEnableRefWorks) {
565
566                 var here = (findOrgUnit(getLocation())).name();
567                 var org_name = here.replace(" ", "+");
568                 var cgi = new CGI();
569
570                 RW.setAttribute(
571                         'href',
572                         rdetailRefWorksHost + '/express/expressimport.asp?vendor='
573                         + org_name
574                         + '&filter=MARC+Format&database=All+MARC+Formats&encoding=65001&url=http%3A%2F%2F'
575                         + cgi.server_name + '/opac/extras/supercat/marctxt/record/'
576                         + record.doc_id()
577                );
578
579                 RW.setAttribute('target', 'RefWorksMain');
580
581                 unHideMe($('rdetail_exp_refworks_span'));
582         }
583
584         $('rdetail_img_link').setAttribute('href', buildISBNSrc(cleanISBN(record.isbn()), 'large'));
585         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
586         runEvt("rdetail", "recordDrawn");
587         recordsCache.push(record);
588
589         rdetailSetExtrasSelector();
590
591         var breq = new Request(FETCH_BRE, [getRid()]);
592         breq.callback( rdetailCheckDeleted );
593         breq.send();
594
595         //resultBuildCaches( [ record ] );
596         //resultDrawSubjects();
597         //resultDrawSeries();
598
599         // grab added content 
600
601     // Proxied through Evergreen AddedContent module
602         acCollectData(cleanISBN(record.isbn()), rdetailhandleAC);
603
604     var currentISBN = cleanISBN(record.isbn());
605
606     // Not proxied, cross-site javascript
607
608     // ChiliFresh
609     if (chilifresh && chilifresh != '(none)' && currentISBN) {
610         $('chilifreshReviewLink').setAttribute('id','isbn_'+currentISBN);
611         $('chilifreshReviewResult').setAttribute('id','chili_review_'+currentISBN);
612         unHideMe($('rdetail_reviews_link'));
613         unHideMe($('rdetail_chilifresh_reviews'));
614         try {
615             chili_init();
616         } catch(E) {
617             console.log(E + '\n');
618             hideMe($('rdetail_reviews_link'));
619             hideMe($('rdetail_chilifresh_reviews'));
620         }
621     }
622
623     // Novelist
624     if (novelist && currentISBN) {
625         unHideMe($('rdetail_novelist_link'));
626     }
627
628     // Multi-Home / Foreign Items / Peer Bibs
629     var req = new Request( TEST_PEER_BIBS, record.doc_id() );
630     req.callback(function(r){
631         var test = r.getResultObject();
632         if (test == "1") {
633             unHideMe($('rdetail_foreign_items_link'));
634         }
635     }); 
636     req.send();
637 }
638
639
640
641 function rdetailCheckDeleted(r) {
642         var br = r.getResultObject()[0];
643         if( isTrue(br.deleted()) ) {
644                 hideMe($('rdetail_place_hold'));
645                 $('rdetail_more_actions_selector').disabled = true;
646                 unHideMe($('rdetail_deleted_exp'));
647         }
648 }
649
650 function rdetailSetExtrasSelector() {
651         if(!grabUser()) return;
652         unHideMe($('rdetail_more_actions'));
653
654         var req = new Request( 
655                         FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
656         req.callback(rdetailAddBookbags);
657         req.send();
658 }
659
660 function rdetailAddBookbags(r) {
661
662         var containers = r.getResultObject();
663         var selector = $('rdetail_more_actions_selector');
664         var found = false;
665         var index = 3;
666         doSelectorActions(selector);
667
668         for( var i = 0; i < containers.length; i++ ) {
669                 found = true;
670                 var container = containers[i];
671                 insertSelectorVal( selector, index++, container.name(), 
672                                 "container_" + container.id(), rdetailAddToBookbag,  1 );
673         }
674
675         nextContainerIndex = index;
676 }
677
678 var _actions = {};
679 function rdetailNewBookbag() {
680         var name = prompt($('rdetail_bb_new').innerHTML,"");
681         if(!name) return;
682
683         var id;
684         if( id = containerCreate( name ) ) {
685                 alert($('rdetail_bb_success').innerHTML);
686                 var selector = $('rdetail_more_actions_selector');
687                 insertSelectorVal( selector, nextContainerIndex++, name, 
688                                 "container_" + id, rdetailAddToBookbag, 1 );
689                 setSelector( selector, 'start' );
690         }
691 }
692
693
694 function rdetailAddToBookbag() {
695         var selector = $('rdetail_more_actions_selector');
696         var id = selector.options[selector.selectedIndex].value;
697         setSelector( selector, 'start' );
698
699         if( containerCreateItem( id.substring(10), record.doc_id() )) {
700                 alert($('rdetail_bb_item_success').innerHTML);
701         }
702 }
703
704
705 var rdetailMarcFetched = false;
706 var rdetailForeignItemsFetched = false;
707 function rdetailShowExtra(type, args) {
708
709         hideMe($('rdetail_copy_info_div'));
710         hideMe($('rdetail_summary_div'));
711         hideMe($('rdetail_reviews_div'));
712         hideMe($('rdetail_toc_div'));
713         hideMe($('rdetail_anotes_div'));
714         hideMe($('rdetail_excerpt_div'));
715         hideMe($('rdetail_preview_div'));
716         hideMe($('rdetail_marc_div'));
717         hideMe($('cn_browse'));
718         hideMe($('rdetail_cn_browse_div'));
719         hideMe($('rdetail_novelist_div'));
720         hideMe($('rdetail_foreign_items_div'));
721         hideMe($('rdetail_notes_div'));
722
723         removeCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
724         removeCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
725         removeCSSClass($('rdetail_summary_link'), 'rdetail_extras_selected');
726         removeCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
727         removeCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
728         removeCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
729         removeCSSClass($('rdetail_preview_link'), 'rdetail_extras_selected');
730         removeCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
731         removeCSSClass($('rdetail_annotation_link'), 'rdetail_extras_selected');
732         removeCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
733         removeCSSClass($('rdetail_novelist_link'), 'rdetail_extras_selected');
734         removeCSSClass($('rdetail_foreign_items_link'), 'rdetail_extras_selected');
735
736         switch(type) {
737
738                 case "copyinfo": 
739                         unHideMe($('rdetail_copy_info_div')); 
740                         addCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
741                         break;
742
743         case "summary":
744             addCSSClass($('rdetail_summary_link'), 'rdetail_extras_selected');
745             unHideMe($('rdetail_summary_div'));
746             break;
747
748                 case "reviews": 
749                         addCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
750                         unHideMe($('rdetail_reviews_div')); 
751                         break;
752
753                 case "excerpt": 
754                         addCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
755                         unHideMe($('rdetail_excerpt_div'));
756                         break;
757
758                 case "preview": 
759                         addCSSClass($('rdetail_preview_link'), 'rdetail_extras_selected');
760                         unHideMe($('rdetail_preview_div'));
761                         rdetailDisplayGBPreview();
762                         break;
763
764                 case "anotes": 
765                         addCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
766                         unHideMe($('rdetail_anotes_div'));
767                         break;
768
769                 case "toc": 
770                         addCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
771                         unHideMe($('rdetail_toc_div'));
772                         break;
773
774                 case "marc": 
775                         addCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
776                         unHideMe($('rdetail_marc_div')); 
777                         if(rdetailMarcFetched) return;
778                         unHideMe($('rdetail_extras_loading'));
779                         rdetailMarcFetched = true;
780                         var req = new Request( FETCH_MARC_HTML, record.doc_id() );
781                         req.callback(rdetailViewMarc); 
782                         req.send();
783                         break;
784
785                 case "novelist": 
786                         addCSSClass($('rdetail_novelist_link'), 'rdetail_extras_selected');
787                         unHideMe($('rdetail_novelist_div')); 
788                         break;
789
790                 case "foreign_items": 
791                         addCSSClass($('rdetail_foreign_items_link'), 'rdetail_extras_selected');
792                         unHideMe($('rdetail_foreign_items_div')); 
793             if(rdetailForeignItemsFetched) return;
794                         unHideMe($('rdetail_extras_loading'));
795             rdetailForeignItemsFetched = true;
796                         var req = new Request( FETCH_PEER_BIBS, record.doc_id() );
797                         req.callback(rdetailForeignItems); 
798                         req.send();
799                         break;
800
801                 case 'cn':
802                         addCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
803                         unHideMe($('rdetail_cn_browse_div'));
804                         rdetailShowCNBrowse(defaultCN, getLocation(), null, true);
805                         break;
806
807         }
808 }
809
810 function rdetailVolumeDetails(args) {
811         var row = $(args.rowid);
812         var tbody = row.parentNode;
813         cpdBuild( tbody, row, record, args.cn, args.org, args.depth, args.copy_location );
814         return;
815 }
816
817 function rdetailBuildCNList() {
818
819         var select = $('cn_browse_selector');
820         var index = 0;
821         var arr = [];
822         for( var cn in callnumberCache ) arr.push( cn );
823         arr.sort();
824
825         if( arr.length == 0 ) {
826                 hideMe($('rdetail_cn_browse_select_div'));
827                 return;
828         }
829
830         for( var i = 0; i < arr.length; i++ ) {
831                 var cn = arr[i];
832                 var opt = new Option(cn);
833                 select.options[index++] = opt;
834         }
835         select.onchange = rdetailGatherCN;
836 }
837
838 function rdetailGatherCN() {
839         var cn = getSelectorVal($('cn_browse_selector'));
840         rdetailShowCNBrowse( cn, getLocation(), getDepth(), true );
841         setSelector( $('cn_browse_selector'), cn );
842 }
843
844
845 function rdetailShowCNBrowse( cn, loc, depth, fromOnclick ) {
846
847         if(!cn) {
848                 unHideMe($('cn_browse_none'));
849                 hideMe($('rdetail_cn_browse_select_div'));
850                 return;
851         }
852
853         unHideMe($('rdetail_cn_browse_select_div'));
854         rdetailBuildCNList();
855         setSelector( $('cn_browse_selector'), cn );
856         hideMe($('rdetail_copy_info_div'));
857         hideMe($('rdetail_reviews_div'));
858         hideMe($('rdetail_summary_div'));
859         hideMe($('rdetail_toc_div'));
860         hideMe($('rdetail_marc_div'));
861         unHideMe($('rdetail_cn_browse_div'));
862         unHideMe($('cn_browse'));
863         if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
864         cnBrowseGo(cn, loc, depth);
865 }
866
867 function rdetailhandleAC(data) {
868
869         if( data.summary.html ) {
870                 $('rdetail_summary_div').innerHTML = data.summary.html;
871                 unHideMe($('rdetail_summary_link'));
872         }
873
874         if( data.reviews.html ) {
875                 $('rdetail_review_container').innerHTML = data.reviews.html;
876                 unHideMe($('rdetail_reviews_link'));
877         }
878
879         if( data.toc.html ) {
880                 $('rdetail_toc_div').innerHTML = data.toc.html;
881                 unHideMe($('rdetail_toc_link'));
882         }
883
884         if( data.excerpt.html ) {
885                 $('rdetail_excerpt_div').innerHTML = data.excerpt.html;
886                 unHideMe($('rdetail_excerpt_link'));
887         }
888
889         if( data.anotes.html ) {
890                 $('rdetail_anotes_div').innerHTML = data.anotes.html;
891                 unHideMe($('rdetail_anotes_link'));
892         }
893 }
894
895 function rdetailShowReviews(r) {
896         hideMe($('rdetail_extras_loading'));
897         var res = r.getResultObject();
898         var par = $('rdetail_reviews_div');
899         var template = par.removeChild($('rdetail_review_template'));
900         if( res && res.length > 0 ) {
901                 unHideMe($('rdetail_reviews_link'));
902                 for( var i = 0; i < res.length; i++ ) {
903                         var rev = res[i];       
904                         if( rev.text && rev.info ) {
905                                 var node = template.cloneNode(true);
906                                 $n(node, 'review_header').appendChild(text(rev.info));
907                                 $n(node, 'review_text').appendChild(text(rev.text));
908                                 par.appendChild(node);
909                         }
910                 }
911         }
912 }
913
914
915 function rdetailShowTOC(r) {
916         hideMe($('rdetail_extras_loading'));
917         var resp = r.getResultObject();
918         if(resp) {
919                 unHideMe($('rdetail_toc_link'));
920                 $('rdetail_toc_div').innerHTML = resp;
921         }
922 }
923
924 function rdetailBuildInfoRows() {
925         var req;
926         var method = FETCH_COPY_COUNTS_SUMMARY;
927         if (rdetailShowCopyLocation)
928                 method = FETCH_COPY_LOCATION_COUNTS_SUMMARY;
929
930         if( rdetailShowLocal ) 
931                 req = new Request(method, record.doc_id(), getLocation(), getDepth())
932         else
933                 req = new Request(method, record.doc_id());
934         req.callback(_rdetailBuildInfoRows);
935         req.send();
936 }
937
938 function _rdetailRows(node) {
939
940         if( rdetailShowLocal && getLocation() != globalOrgTree.id() ) {
941                 var loc = findOrgUnit(getLocation());
942                 if( node ) {
943                         if( !orgIsMine(node, loc) && !orgIsMine(loc,node) ) return;
944                 } else {
945             var kids = globalOrgTree.children();
946             if (kids) {
947                         for( var i = 0; i < kids.length; i++ ) {
948                                 var org = findOrgUnit(kids[i]);
949                                 if( orgIsMine(org, loc) ) {
950                                         node = org;
951                                         break;
952                                 }
953                 }
954                         }
955                 } 
956         }
957
958         if(!node && findOrgType(globalOrgTree.ou_type()).can_have_vols())
959                 node = globalOrgTree;
960
961
962         /* don't show hidden orgs */
963
964         if(node) {
965
966                 if(!isXUL() && !isTrue(node.opac_visible())) return;
967
968                 if (orgHiding) {
969                         if (isTrue( findOrgType(node.ou_type()).can_have_vols() )) {
970                                 if ( ! orgIsMine( orgHiding.org, node, orgHiding.depth ) ) {
971                                         return;
972                                 }
973                         }
974                 }
975
976                 var row = copyRow.cloneNode(true);
977                 row.id = "cp_info_" + node.id();
978
979                 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
980                 var cntd  = findNodeByName( row, config.names.rdetail.cn_cell );
981                 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
982                 var actions = $n(row, 'rdetail_actions_cell');
983
984                 var p = libtd.getElementsByTagName('a')[0];
985                 libtd.insertBefore(text(node.name()), p);
986                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
987
988                 if(!findOrgType(node.ou_type()).can_have_vols()) {
989
990                         row.removeChild(cntd);
991                         row.removeChild(cpctd);
992                         row.removeChild(actions);
993                         row.setAttribute('novols', '1');
994
995                         libtd.setAttribute("colspan", numStatuses + 3 );
996                         libtd.colSpan = numStatuses + 3;
997                         addCSSClass(row, 'copy_info_region_row');
998                 } 
999
1000                 copyRowParent.appendChild(row);
1001
1002         } else { node = globalOrgTree; }
1003
1004     var kids = node.children();
1005     if (kids) {
1006         for( var c = 0; c < kids.length; c++ ) 
1007                 _rdetailRows(kids[c]);
1008     }
1009 }
1010
1011 function rdetailCNPrint(orgid, cn) {
1012         var div = cpdBuildPrintWindow( record, orgid);
1013         var template = div.removeChild($n(div, 'cnrow'));
1014         var rowNode = $("cp_info_" + orgid);
1015         cpdStylePopupWindow(div);
1016         openWindow(div.innerHTML);
1017 }
1018
1019 var localCNFound = false;
1020 var ctr = 0;
1021 function _rdetailBuildInfoRows(r) {
1022
1023         if (rdetailShowCopyLocation)
1024                 unHideMe( $n( $('rdetail_copy_info_table'), 'rdetail_copylocation_header' ) );
1025
1026         removeChildren(copyRowParent);
1027
1028         orgHiding = checkOrgHiding();
1029
1030         _rdetailRows();
1031
1032         var summary = r.getResultObject();
1033         if(!summary) return;
1034
1035         var found = false;
1036         for( var i = 0; i < summary.length; i++ ) {
1037
1038                 var arr = summary[i];
1039                 globalCNCache[arr[1]] = 1;
1040                 var thisOrg = findOrgUnit(arr[0]);
1041                 var rowNode = $("cp_info_" + thisOrg.id());
1042                 if(!rowNode) continue;
1043
1044                 if(rowNode.getAttribute("used")) {
1045
1046                         if( rowNode.nextSibling ) {
1047                                 sib = rowNode.nextSibling;
1048                                 o ='cp_info_'+thisOrg.id()+'_';
1049                                 /* push the new row on as the last row for this org unit */
1050                                 while( sib && sib.id.match(o) ) {
1051                                         sib = sib.nextSibling;
1052                                 }
1053                                 if(sib)
1054                                         rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), sib);
1055                                 else
1056                                         rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
1057                         } else {
1058                                 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
1059                         }
1060
1061                         var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
1062                         n.appendChild(text(thisOrg.name()));
1063                         n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1)  * 9) + "px;");
1064                         rowNode.id = "cp_info_" + thisOrg.id() + '_' + (++ctr); 
1065
1066                 } else {
1067                         rowNode.setAttribute("used", "1");
1068                 }
1069
1070                 var cpc_temp = rowNode.removeChild(
1071                                 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
1072
1073                 var statuses = arr[2];
1074                 var cl = '';
1075                 if (rdetailShowCopyLocation) {
1076                         cl = arr[2];
1077                         statuses = arr[3];
1078                 }
1079
1080
1081                 rdetailApplyStatuses(rowNode, cpc_temp, statuses);
1082
1083                 var isLocal = false;
1084                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { 
1085                         found = true; 
1086                         isLocal = true; 
1087                         if(!localCNFound) {
1088                                 localCNFound = true;
1089                                 defaultCN = arr[1];
1090                         }
1091                 }
1092
1093                 //if(isLocal) unHideMe(rowNode);
1094                 unHideMe(rowNode);
1095
1096                 rdetailSetPath( thisOrg, isLocal );
1097                 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal, thisOrg, cl );
1098
1099                 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
1100         }
1101
1102         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
1103 }
1104
1105 function rdetailBuildBrowseInfo(row, cn, local, orgNode, cl) {
1106
1107         if(local) {
1108                 var cache = callnumberCache[cn];
1109                 if( cache ) cache.count++;
1110                 else callnumberCache[cn] = { count : 1 };
1111         }
1112
1113         var depth = getDepth();
1114         if( !local ) depth = findOrgDepth(globalOrgTree);
1115
1116         $n(row, 'rdetail_callnumber_cell').appendChild(text(cn));
1117
1118         if (rdetailShowCopyLocation) {
1119                 var cl_cell = $n(row, 'rdetail_copylocation_cell');
1120                 cl_cell.appendChild(text(cl));
1121                 unHideMe(cl_cell);
1122         }
1123
1124         _debug('setting action clicks for cn ' + cn);
1125
1126         var dHref = 'javascript:rdetailVolumeDetails('+
1127                         '{copy_location : "'+cl.replace(/\"/g, '\\"')+'", rowid : "'+row.id+'", cn :"'+cn.replace(/\"/g, '\\"')+'", depth:"'+depth+'", org:"'+orgNode.id()+'", local: '+local+'});';
1128
1129         var bHref = 'javascript:rdetailShowCNBrowse("' + cn.replace(/\"/g, '\\"') + '", '+orgNode.id()+', "'+depth+'");'; 
1130
1131         unHideMe( $n(row, 'details') )
1132                 $n(row, 'details').setAttribute('href', dHref);
1133         unHideMe( $n(row, 'browse') )
1134                 $n(row, 'browse').setAttribute('href', bHref);
1135
1136         if(isXUL()) {
1137                 unHideMe($n(row, 'hold_div'));
1138                 $n(row, 'hold').onclick = function() {
1139                         var req = new Request(FETCH_VOLUME_BY_INFO, cn, record.doc_id(), orgNode.id());
1140                         req.callback(
1141                                         function(r) {
1142                                         var vol = r.getResultObject();
1143                                         holdsDrawEditor({type: 'V', volumeObject : vol});
1144                                         }
1145                                     );
1146                         req.send();
1147                 };
1148         }
1149 }
1150
1151 // sets the path to org as 'active' and displays the path if it's local 
1152 function rdetailSetPath(org, local) {
1153         if( findOrgDepth(org) == 0 ) return;
1154         var row = $("cp_info_" + org.id());
1155         row.setAttribute("hasinfo", "1");
1156         unHideMe(row);
1157         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
1158 }
1159
1160 //Append all the statuses for a given summary to the 
1161 //copy summary table 
1162 function rdetailApplyStatuses( row, template, statuses ) {
1163         for( var j in _statusPositions ) {
1164                 var stat = _statusPositions[j];
1165                 var val = statuses[stat.id()];
1166                 var nn = template.cloneNode(true);
1167                 if(val) nn.appendChild(text(val));
1168                 else nn.appendChild(text(0));
1169                 row.appendChild(nn);
1170         }
1171 }
1172
1173 //Add one td (creating a new column) to the copy summary
1174 //table for each opac_visible copy status
1175 function rdetailBuildStatusColumns() {
1176
1177         rdetailGrabCopyStatuses();
1178         var parent = statusRow;
1179         var template = parent.removeChild(G.ui.rdetail.cp_status);
1180
1181         var i = 0;
1182         for( i = 0; i < cp_statuses.length; i++ ) {
1183
1184                 var c = cp_statuses[i];
1185                 if( c && isTrue(c.opac_visible()) ) {
1186                         var name = c.name();
1187                         _statusPositions[i] = c;
1188                         var node = template.cloneNode(true);
1189                         var data = findNodeByName( node, config.names.rdetail.cp_status);
1190
1191                         data.appendChild(text(name));
1192                         parent.appendChild(node);
1193                 }
1194         }       
1195
1196         numStatuses = 0;
1197         for(x in _statusPositions) numStatuses++; 
1198 }
1199
1200 function rdetailGrabCopyStatuses() {
1201         if(cp_statuses) return cp_statuses;
1202         var req = new Request(FETCH_COPY_STATUSES);
1203         req.send(true);
1204         cp_statuses = req.result();
1205         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
1206 }
1207
1208 function _rdetailSortStatuses(a, b) {
1209         return parseInt(a.id()) - parseInt(b.id());
1210 }
1211
1212 /**
1213  * Check for a Google Book preview after the main page loads
1214  */
1215 function rdetailCheckForGBPreview() {
1216         if (!rdetailGoogleBookPreview) return;
1217         dojo.addOnLoad(function() {
1218                 searchForGBPreview( cleanISBN(record.isbn()) );
1219         });
1220 }
1221
1222 /**
1223  *
1224  * @param {DOM object} isbn The form element containing the input parameters "isbns"
1225  */
1226 function searchForGBPreview( isbn ) {
1227         dojo.require("dojo.io.script");
1228         dojo.io.script.get({"url": "https://www.google.com/jsapi"});
1229         dojo.io.script.get({"url": "http://books.google.com/books", "content": { "bibkeys": isbn, "jscmd": "viewapi", "callback": "GBPreviewCallback"}});
1230 }
1231
1232 /**
1233  * This function is the call-back function for the JSON scripts which 
1234  * executes a Google book search response.
1235  *
1236  * XXX I18N of text needed
1237  *
1238  * @param {JSON} GBPBookInfo is the JSON object pulled from the Google books service.
1239  */
1240 function GBPreviewCallback(GBPBookInfo) {
1241         var GBPreviewDiv = document.getElementById("rdetail_preview_div");
1242         var GBPBook;
1243
1244         for ( i in GBPBookInfo ) {
1245                 GBPBook = GBPBookInfo[i];
1246         }
1247
1248         if ( !GBPBook ) {
1249                 return;
1250         }
1251
1252         if ( GBPBook.preview != "noview" ) {
1253                 // Add a button below the book cover image to load the preview.
1254                 GBPBadge = document.createElement( 'img' );
1255                 GBPBadge.src = 'http://books.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif';
1256                 GBPBadge.title = $('rdetail_preview_badge').innerHTML;
1257                 GBPBadge.style.border = 0;
1258                 GBPBadgelink = document.createElement( 'a' );
1259                 GBPBadgelink.href = 'javascript:rdetailShowExtra("preview");';
1260                 GBPBadgelink.appendChild( GBPBadge );
1261                 $('rdetail_image_cell').appendChild( GBPBadgelink );
1262                 $('rdetail_preview_div').style.height = 600;
1263
1264                 /* Display the "Preview" tab in the Extras section */
1265                 unHideMe( $('rdetail_preview_link' ) );
1266         }
1267 }
1268
1269 /**
1270  *  This is called when the user clicks on the 'Preview' link.  We assume
1271  *  a preview is available from Google if this link was made visible.
1272  *
1273  * XXX I18N of Google Book Preview language attribute needed
1274  */
1275 function rdetailDisplayGBPreview() {
1276         unHideMe($('rdetail_extras_loading'));
1277         GBPreviewPane = $('rdetail_preview_div');
1278         if ( GBPreviewPane.getAttribute('loaded') == null ||
1279                 GBPreviewPane.getAttribute('loaded') == "false" ) {
1280                 google.load("books", "0", {"callback" : rdetailGBPViewerLoadCallback, "language": "en"} );
1281                 GBPreviewPane.setAttribute('loaded', 'true');
1282         }
1283 }
1284
1285 function rdetailGBPViewerLoadCallback() {
1286         hideMe($('rdetail_extras_loading'));
1287         var GBPViewer = new google.books.DefaultViewer(document.getElementById('rdetail_preview_div'));
1288         GBPViewer.load('ISBN:' + cleanISBN(record.isbn()) );
1289
1290 }
1291
1292 function rdetailDrawExpandedHoldings(anchor, bibid, type) {
1293     var offsets = {"basic": 0, "index": 0, "supplement": 0};
1294     var limit = 10; /* XXX give user control over this? */
1295     var target_id = "holding_type_" + type;
1296     var target = dojo.byId(target_id);
1297
1298     anchor.innerHTML = "[-]";
1299     anchor.oldonclick = anchor.onclick;
1300     anchor.onclick = function() {
1301         anchor.onclick = anchor.oldonclick;
1302         anchor.innerHTML = "[+]";
1303         dojo.empty(target);
1304     };
1305
1306     function _load() {
1307         dojo.empty(target);
1308         fieldmapper.standardRequest(
1309             ["open-ils.serial",
1310                 "open-ils.serial.received_siss.retrieve.by_bib.atomic"], {
1311                 "params": [bibid, {"offset": offsets[type], "limit": limit}],
1312                 "async": true,
1313                 "oncomplete": function(r) {
1314                     try {
1315                         if (msg = r.recv().content()) { /* sic, assignment */
1316                             if (!msg.length) return;
1317                             offsets[type] += msg.length;
1318                             var table = dojo.create("table", null, target);
1319                             dojo.forEach(
1320                                 msg, function(o) {
1321                                     var tr = dojo.create("tr", null, table);
1322                                     dojo.create(
1323                                         "td", {
1324                                             "innerHTML": o.issuance.label(),
1325                                             "style": {"paddingLeft": "3em"}
1326                                         }, tr
1327                                     );
1328
1329                                     if (!o.has_units) return;
1330                                     /* can't place holds if no units */
1331                                     var td = dojo.create("td", null, tr);
1332                                     dojo.create(
1333                                         "a", {
1334                                             "href":"javascript:void(0);",
1335                                             "style": {"marginLeft": "1.5em"},
1336                                             "onclick": function() {
1337                                                 holdsDrawEditor({
1338                                                     "type": "I",
1339                                                     "issuance": o.issuance.id()
1340                                                 });
1341                                             },
1342                                             "innerHTML": "[" +
1343                                                 opac_strings.PLACE_HOLD + "]"
1344                                         }, td
1345                                     );
1346                                 }
1347                             );
1348                             if (msg.length == limit) {
1349                                 dojo.create("br", null, target);
1350                                 dojo.create(
1351                                     "a", {
1352                                         "href": "javascript:void(0);",
1353                                         "innerHTML":
1354                                             "[" + opac_strings.MORE + "]",
1355                                         "onclick": _load
1356                                     }, target
1357                                 );
1358                             }
1359                         }
1360                     } catch (E) {
1361                         void(0);
1362                     }
1363                 }
1364             }
1365         );
1366     }
1367     _load();
1368 }