]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/result_common.js
copy counts come back, but must be interpreted differently
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / result_common.js
1
2 var recordsHandled = 0;
3 var recordsCache = [];
4 var lowHitCount = 4;
5 var isbnList = '';
6 var googleBooks = true;
7
8 var resultFetchAllRecords = false;
9 var resultCompiledSearch = null;
10
11 /* set up the event handlers */
12 if( findCurrentPage() == MRESULT || findCurrentPage() == RRESULT ) {
13         G.evt.result.hitCountReceived.push(resultSetHitInfo);
14         G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
15         G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
16         G.evt.result.allRecordsReceived.push(resultBuildCaches, resultDrawSubjects, 
17       resultDrawAuthors, resultDrawSeries, function(){unHideMe($('result_info_2'))},
18           fetchGoogleBooks);
19
20         attachEvt('result','lowHits',resultLowHits);
21         attachEvt('result','zeroHits',resultZeroHits);
22         attachEvt( "common", "locationUpdated", resultSBSubmit );
23         /* do this after we have ID's so the rank for mr pages will be correct */
24         attachEvt("result", "preCollectRecords", resultPaginate);
25 }
26
27 function resultSBSubmit(){searchBarSubmit();}
28
29 /* returns the last 'index' postion ocurring in this page */
30 function resultFinalPageIndex() {
31         if(getHitCount() < (getOffset() + getDisplayCount())) 
32                 return getHitCount() - 1;
33         return getOffset() + getDisplayCount() - 1;
34 }
35
36
37
38
39 /* generic search method */
40 function resultCollectSearchIds( type, method, handler ) {
41
42         var sort                = (getSort() == SORT_TYPE_REL) ? null : getSort(); 
43         var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
44
45         var item_type;
46         var item_form;
47         var args = {};
48
49         if( type ) {
50                 var form = parseForm(getForm());
51                 item_type = form.item_type;
52                 item_form = form.item_form;
53
54         } else {
55                 item_type = (getItemType()) ? getItemType().split(/,/) : null;
56                 item_form = (getItemForm()) ? getItemForm().split(/,/) : null;
57         }
58
59         var limit = (resultFetchAllRecords) ? 1000 : getDisplayCount();
60
61         if( getOffset() > 0 ) {
62                 if( getHitCount() > 0 && (getOffset() + getDisplayCount()) > getHitCount() ) 
63                         limit = getHitCount() - getOffset();
64         }
65
66         var lasso = getLasso();
67
68         if (lasso) args.org_unit = -lasso;
69         else args.org_unit = getLocation();
70
71         args.depth    = getDepth();
72         args.limit    = limit;
73         args.offset   = getOffset();
74         args.visibility_limit = 3000;
75     args.default_class = getStype();
76
77         if(sort) args.sort = sort;
78         if(sortdir) args.sort_dir = sortdir;
79         if(item_type) args.item_type    = item_type;
80         if(item_form) args.item_form    = item_form;
81     if(getAvail()) args.available = 1;
82
83
84         if(getAudience()) args.audience  = getAudience().split(/,/);
85         if(getLitForm()) args.lit_form  = getLitForm().split(/,/);
86         if(getLanguage()) args.language = getLanguage().split(/,/);
87         if(getBibLevel()) args.bib_level        = getBibLevel().split(/,/);
88
89         _debug('Search args: ' + js2JSON(args));
90         _debug('Raw query: ' + getTerm());
91
92         var req = new Request(method, args, getTerm(), 1);
93         req.callback(handler);
94         req.send();
95 }
96
97
98
99
100
101 /* set the search result info, number of hits, which results we're 
102         displaying, links to the next/prev pages, etc. */
103 function resultSetHitInfo() { 
104
105
106         /* tell the user where the results are coming from */
107         var baseorg = findOrgUnit(getLocation());
108         var depth = getDepth();
109         var mydepth = findOrgDepth(baseorg);
110         if( findOrgDepth(baseorg) != depth ) {
111                 var tmporg = baseorg;
112                 while( mydepth > depth ) {
113                         mydepth--;
114                         tmporg = findOrgUnit(tmporg.parent_ou());
115                 }
116                 unHideMe($('including_results_for'));
117                 $('including_results_location').appendChild(text(tmporg.name()));
118         }
119
120
121         try{searchTimer.stop()}catch(e){}
122
123         //if( findCurrentPage() == MRESULT ) {
124         if( findCurrentPage() == MRESULT || 
125
126                 (findCurrentPage() == RRESULT &&
127                         (
128                                 getRtype() == RTYPE_TITLE ||
129                                 getRtype() == RTYPE_AUTHOR ||
130                                 getRtype() == RTYPE_SUBJECT ||
131                                 getRtype() == RTYPE_SERIES ||
132                                 getRtype() == RTYPE_KEYWORD 
133                         )
134
135                 ) ) {
136
137                 if(getHitCount() <= lowHitCount && getTerm())
138                         runEvt('result', 'lowHits');
139         }
140
141         if(getHitCount() == 0) {
142                 runEvt('result', 'zeroHits');
143                 return;
144         }
145
146
147         var pages = getHitCount() / getDisplayCount();
148         if(pages % 1) pages = parseInt(pages) + 1;
149
150         
151
152         var cpage = (getOffset()/getDisplayCount()) + 1;
153
154         G.ui.result.current_page.appendChild(text(cpage));
155         G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
156
157         $('current_page2').appendChild(text(cpage));
158         $('num_pages2').appendChild(text(pages + ")")); /* the ) is dumb */
159
160         /* set the offsets */
161         var offsetEnd = getDisplayCount() + getOffset();  
162         if( getDisplayCount() > (getHitCount() - getOffset()))  
163                 offsetEnd = getHitCount();
164
165         G.ui.result.offset_end.appendChild(text(offsetEnd));
166         G.ui.result.offset_start.appendChild(text(getOffset() + 1));
167
168         $('offset_end2').appendChild(text(offsetEnd));
169         $('offset_start2').appendChild(text(getOffset() + 1));
170
171         G.ui.result.result_count.appendChild(text(getHitCount()));
172         unHideMe(G.ui.result.info);
173
174         $('result_count2').appendChild(text(getHitCount()));
175         unHideMe($('result_info_div2'));
176 }
177
178 function resultLowHits() {
179         showCanvas();
180         unHideMe($('result_low_hits'));
181         if(getHitCount() > 0)
182                 unHideMe($('result_low_hits_msg'));
183
184     var words = [];
185     for(var key in resultCompiledSearch.searches) 
186         words.push(resultCompiledSearch.searches[key].term);
187
188         var sreq = new Request(CHECK_SPELL, words.join(' '));
189         sreq.callback(resultSuggestSpelling);
190         sreq.send();
191
192     for(var key in resultCompiledSearch.searches) {
193                 var areq = new Request(FETCH_CROSSREF, key, resultCompiledSearch.searches[key].term);
194                 areq.callback(resultLowHitXRef);
195                 areq.send();
196         }
197
198         if( !(getForm() == null || getForm() == 'all' || getForm() == "") ) {
199                 var a = {};
200                 a[PARAM_FORM] = "all";
201                 $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
202                 unHideMe($('low_hits_remove_format'));
203         }
204
205         resultSuggestSearchClass();
206
207         if(getTerm()) resultExpandSearch(); /* advanced search */
208 }
209
210 var lowHitsXRefLink;
211 var lowHitsXRefLinkParent;
212 function resultLowHitXRef(r) {
213         if(!lowHitsXRefLink){
214                 lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
215                 lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
216         }
217         var res = r.getResultObject();
218         var arr = res.from;
219         arr.concat(res.also);
220         if(arr && arr.length > 0) {
221                 unHideMe($('low_hits_cross_ref'));
222                 var word;
223                 var c = 0;
224                 while( word = arr.shift() ) {
225                         if(c++ > 20) break;
226                         var a = {};
227                         a[PARAM_TERM] = word;
228                         var template = lowHitsXRefLink.cloneNode(true);
229                         template.setAttribute('href',buildOPACLink(a));
230                         template.appendChild(text(word));
231                         lowHitsXRefLinkParent.appendChild(template);
232                         lowHitsXRefLinkParent.appendChild(text(' '));
233                 }
234         }
235 }
236
237 function resultZeroHits() {
238         showCanvas();
239         unHideMe($('result_low_hits'));
240         unHideMe($('result_zero_hits_msg'));
241         //if(getTerm()) resultExpandSearch(); /* advanced search */
242 }
243
244 function resultExpandSearch() {
245         var top = findOrgDepth(globalOrgTree);
246         if(getDepth() == top) return;
247         unHideMe($('low_hits_expand_range'));
248         var par = $('low_hits_expand_link').parentNode;
249         var template = par.removeChild($('low_hits_expand_link'));
250
251         var bottom = getDepth();
252         while( top < bottom ) {
253                 var a = {};
254                 a[PARAM_DEPTH] = top;
255                 var temp = template.cloneNode(true);
256                 temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
257                 temp.setAttribute('href',buildOPACLink(a));
258                 par.appendChild(temp);
259                 top++;
260         }
261 }
262
263 function resultSuggestSearchClass() {
264         var stype = getStype();
265         if(stype == STYPE_KEYWORD) return;
266         var a = {}; var ref;
267         unHideMe($('low_hits_search_type'));
268         if(stype != STYPE_TITLE) {
269                 ref = $('low_hits_title_search');
270                 unHideMe(ref);
271                 a[PARAM_STYPE] = STYPE_TITLE;
272                 ref.setAttribute('href',buildOPACLink(a));
273         }
274         if(stype != STYPE_AUTHOR) {
275                 ref = $('low_hits_author_search');
276                 unHideMe(ref);
277                 a[PARAM_STYPE] = STYPE_AUTHOR;
278                 ref.setAttribute('href',buildOPACLink(a));
279         }
280         if(stype != STYPE_SUBJECT) {
281                 ref = $('low_hits_subject_search');
282                 unHideMe(ref);
283                 a[PARAM_STYPE] = STYPE_SUBJECT;
284                 ref.setAttribute('href',buildOPACLink(a));
285         }
286         if(stype != STYPE_KEYWORD) {
287                 ref = $('low_hits_keyword_search');
288                 unHideMe(ref);
289                 a[PARAM_STYPE] = STYPE_KEYWORD;
290                 ref.setAttribute('href',buildOPACLink(a));
291         }
292         if(stype != STYPE_SERIES) {
293                 ref = $('low_hits_series_search');
294                 unHideMe(ref);
295                 a[PARAM_STYPE] = STYPE_SERIES;
296                 ref.setAttribute('href',buildOPACLink(a));
297         }
298 }
299
300 function resultSuggestSpelling(r) {
301         var res = r.getResultObject();
302         var phrase = getTerm();
303         var words = phrase.split(/ /);
304
305         var newterm = "";
306
307         for( var w = 0; w < words.length; w++ ) {
308                 var word = words[w];
309                 var blob = grep(res, function(i){return (i.word == word);});
310                 if( blob ) blob = blob[0];
311                 else continue;
312                 if( blob.word == word ) {
313                         if( blob.suggestions && blob.suggestions[0] ) {
314                                 newterm += " " + blob.suggestions[0];
315                                 unHideMe($('did_you_mean'));
316                         } else {
317                                 newterm += " " + word;
318                         }
319                 }
320         }
321
322         var arg = {};
323         arg[PARAM_TERM] = newterm;
324         $('spell_check_link').setAttribute('href', buildOPACLink(arg));
325         $('spell_check_link').appendChild(text(newterm));
326 }
327
328
329 function resultPaginate() {
330         var o = getOffset();
331
332         if( !(  ((o) + getDisplayCount()) >= getHitCount()) ) {
333
334                 var args = {};
335                 args[PARAM_OFFSET]      = o + getDisplayCount();
336                 args[PARAM_SORT]                = SORT;
337                 args[PARAM_SORT_DIR] = SORT_DIR;
338                 args[PARAM_RLIST]               = new CGI().param(PARAM_RLIST);
339
340                 G.ui.result.next_link.setAttribute("href", buildOPACLink(args)); 
341                 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
342
343                 $('next_link2').setAttribute("href", buildOPACLink(args)); 
344                 addCSSClass($('next_link2'), config.css.result.nav_active);
345
346                 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
347
348                 /* when hit count is divisible by display count, we have to adjust */
349                 if( getHitCount() % getDisplayCount() == 0 ) 
350                         args[PARAM_OFFSET] -= getDisplayCount();
351
352         /*
353                 G.ui.result.end_link.setAttribute("href", buildOPACLink(args)); 
354                 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
355
356                 $('end_link2').setAttribute("href", buildOPACLink(args)); 
357                 addCSSClass($('end_link2'), config.css.result.nav_active);
358         */
359         }
360
361         if( o > 0 ) {
362
363                 var args = {};
364                 args[PARAM_SORT]                = SORT;
365                 args[PARAM_SORT_DIR] = SORT_DIR;
366                 args[PARAM_RLIST]               = new CGI().param(PARAM_RLIST);
367
368                 args[PARAM_OFFSET] = o - getDisplayCount();
369                 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args)); 
370                 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
371
372                 $('prev_link2').setAttribute( "href", buildOPACLink(args)); 
373                 addCSSClass($('prev_link2'), config.css.result.nav_active);
374
375                 args[PARAM_OFFSET] = 0;
376                 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args)); 
377                 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
378
379                 $('search_home_link2').setAttribute( "href", buildOPACLink(args)); 
380                 addCSSClass($('search_home_link2'), config.css.result.nav_active);
381         }
382
383         if(getDisplayCount() < getHitCount()) {
384                 unHideMe($('start_end_links_span'));
385                 unHideMe($('start_end_links_span2'));
386    }
387
388         showCanvas();
389         try{searchTimer.stop()}catch(e){}
390 }
391
392 function buildunAPISpan (span, type, id) {
393         var cgi = new CGI();
394         var d = new Date();
395
396         addCSSClass(span,'unapi-id');
397
398         span.setAttribute(
399                 'title',
400                 'tag:' + cgi.server_name + ',' +
401                         d.getFullYear() +
402                         ':' + type + '/' + id
403         );
404 }
405
406 function unhideGoogleBooks (data) {
407     for ( var i in data ) {
408         //if (data[i].preview == 'noview') continue;
409
410         var gbspan = $n(document.documentElement, 'googleBooks-' + i);
411         var gba = $n(gbspan, "googleBooks-link");
412
413         gba.setAttribute(
414             'href',
415             data[i].info_url
416         );
417         removeCSSClass( gbspan, 'hide_me' );
418     }
419 }
420
421 /* display the record info in the record display table 'pos' is the 
422                 zero based position the record should have in the display table */
423 function resultDisplayRecord(rec, pos, is_mr) {
424
425         if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
426         recordsHandled++;
427         recordsCache.push(rec);
428
429         var r = table.rows[pos + 1];
430     var currentISBN = cleanISBN(rec.isbn());
431
432     if (googleBooks) {
433             var gbspan = $n(r, "googleBooks");
434         if (currentISBN) {
435             gbspan.setAttribute(
436                 'name',
437                 gbspan.getAttribute('name') + '-' + currentISBN
438             );
439
440             if (isbnList) isbnList += ', ';
441             isbnList += currentISBN;
442         }
443     }
444
445 /*
446         try {
447                 var rank = parseFloat(ranks[pos + getOffset()]);
448                 rank            = parseInt( rank * 100 );
449                 var relspan = $n(r, "relevancy_span");
450                 relspan.appendChild(text(rank));
451                 unHideMe(relspan.parentNode);
452         } catch(e){ }
453 */
454
455         var pic = $n(r, config.names.result.item_jacket);
456         pic.setAttribute("src", buildISBNSrc(currentISBN));
457
458         var title_link = $n(r, config.names.result.item_title);
459         var author_link = $n(r, config.names.result.item_author);
460
461         if( is_mr )  {
462                 var onlyrec = onlyrecord[ getOffset() + pos ];
463                 if(onlyrec) {
464                         buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', onlyrec);
465
466                         var args = {};
467                         args.page = RDETAIL;
468                         args[PARAM_OFFSET] = 0;
469                         args[PARAM_RID] = onlyrec;
470                         args[PARAM_MRID] = rec.doc_id();
471                         pic.parentNode.setAttribute("href", buildOPACLink(args));
472                         title_link.setAttribute("href", buildOPACLink(args));
473                         title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
474                         
475                 } else {
476                         buildunAPISpan($n(r,'unapi'), 'metabib-metarecord', rec.doc_id());
477
478                         buildTitleLink(rec, title_link); 
479                         var args = {};
480                         args.page = RRESULT;
481                         args[PARAM_OFFSET] = 0;
482                         args[PARAM_MRID] = rec.doc_id();
483                         pic.parentNode.setAttribute("href", buildOPACLink(args));
484                 }
485
486         } else {
487                 buildunAPISpan($n(r,'unapi'), 'biblio-record_entry', rec.doc_id());
488
489                 buildTitleDetailLink(rec, title_link); 
490                 var args = {};
491                 args.page = RDETAIL;
492                 args[PARAM_OFFSET] = 0;
493                 args[PARAM_RID] = rec.doc_id();
494                 pic.parentNode.setAttribute("href", buildOPACLink(args));
495
496                 unHideMe($n(r,'place_hold_span'));
497                 $n(r,'place_hold_link').setAttribute(
498                         'href','javascript:holdsDrawEditor({record:"'+rec.doc_id()+'",type:"T"});');
499         }
500
501         buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
502
503         if(! is_mr ) {
504         
505                 if(!isNull(rec.edition()))      {
506                         unHideMe( $n(r, "result_table_extra_span"));
507                         $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
508                 }
509                 if(!isNull(rec.pubdate())) {
510                         unHideMe( $n(r, "result_table_extra_span"));
511                         unHideMe($n(r, "result_table_pub_span"));
512                         $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
513                 }
514                 if(!isNull(rec.publisher()) ) {
515                         unHideMe( $n(r, "result_table_extra_span"));
516                         unHideMe($n(r, "result_table_pub_span"));
517                         $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
518                 }
519
520                 if(!isNull(rec.physical_description()) ) {
521                         unHideMe( $n(r, "result_table_extra_span"));
522                         var t = " " + rec.physical_description();
523                         //$n(r, "result_table_phys_span").appendChild( text(t.replace(/:.*/g,'')));
524                         $n(r, "result_table_phys_span").appendChild( text(t));
525                 }
526
527         }
528
529         resultBuildFormatIcons( r, rec, is_mr );
530
531         unHideMe(r);
532         
533         runEvt("result", "recordDrawn", rec.doc_id(), title_link);
534
535         /*
536         if(resultPageIsDone())  {
537                 runEvt('result', 'allRecordsReceived', recordsCache);
538         }
539         */
540 }
541
542 function _resultFindRec(id) {
543         for( var i = 0; i != recordsCache.length; i++ ) {
544                 var rec = recordsCache[i];
545                 if( rec && rec.doc_id() == id )
546                         return rec;
547         }
548         return null;
549 }
550
551
552 function resultBuildFormatIcons( row, rec, is_mr ) {
553
554         var ress = rec.types_of_resource();
555
556         for( var i in ress ) {
557
558                 var res = ress[i];
559                 if(!res) continue;
560
561                 var link = $n(row, res + "_link");
562                 link.title = res;
563                 var img = link.getElementsByTagName("img")[0];
564                 removeCSSClass( img, config.css.dim );
565
566                 var f = getForm();
567                 if( f != "all" ) {
568                         if( f == modsFormatToMARC(res) ) 
569                                 addCSSClass( img, "dim2_border");
570                 }
571
572                 var args = {};
573                 args[PARAM_OFFSET] = 0;
574
575                 if(is_mr) {
576                         args.page = RRESULT;
577                         args[PARAM_TFORM] = modsFormatToMARC(res);
578                         args[PARAM_MRID] = rec.doc_id();
579
580                 } else {
581                         args.page = RDETAIL
582                         args[PARAM_RID] = rec.doc_id();
583                 }
584
585                 link.setAttribute("href", buildOPACLink(args));
586
587         }
588 }
589
590 function fetchGoogleBooks () {
591     if (isbnList && googleBooks) {
592         var scriptElement = document.createElement("script");
593         scriptElement.setAttribute("id", "jsonScript");
594         scriptElement.setAttribute("src",
595             "http://books.google.com/books?bibkeys=" + 
596             escape(isbnList) + "&jscmd=viewapi&callback=unhideGoogleBooks");
597         scriptElement.setAttribute("type", "text/javascript");
598         // make the request to Google Book Search
599         document.documentElement.firstChild.appendChild(scriptElement);
600     }
601 }
602
603 function resultPageIsDone(pos) {
604
605         return (recordsHandled == getDisplayCount() 
606                 || recordsHandled + getOffset() == getHitCount());
607 }
608
609 var resultCCHeaderApplied = false;
610
611 /* -------------------------------------------------------------------- */
612 /* dynamically add the copy count rows based on the org type 'countsrow' 
613         is the row into which we will add TD's to hold the copy counts 
614         This code generates copy count cells with an id of
615         'copy_count_cell_<depth>_<pagePosition>'  */
616 function resultAddCopyCounts(rec, pagePosition) {
617
618         var r = table.rows[pagePosition + 1];
619         var countsrow = $n(r, config.names.result.counts_row );
620         var ccell = $n(countsrow, config.names.result.count_cell);
621
622         var nodes = orgNodeTrail(findOrgUnit(getLocation()));
623         var node = nodes[0];
624         var type = findOrgType(node.ou_type());
625         ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
626         ccell.title = type.opac_label();
627         //addCSSClass(ccell, config.css.result.cc_cell_even);
628
629         var lastcell = ccell;
630         var lastheadcell = null;
631
632         var cchead = null;
633         var ccheadcell = null;
634         if(!resultCCHeaderApplied) {
635                 ccrow = $('result_thead_row');
636                 ccheadcell =  ccrow.removeChild($n(ccrow, "result_thead_ccell"));
637                 var t = ccheadcell.cloneNode(true);
638                 lastheadcell = t;
639                 t.appendChild(text(type.opac_label()));
640                 ccrow.appendChild(t);
641                 resultCCHeaderApplied = true;
642         }
643
644         if(nodes[1]) {
645
646                 var x = 1;
647                 var d = findOrgDepth(nodes[1]);
648                 var d2 = findOrgDepth(nodes[nodes.length -1]);
649
650                 for( var i = d; i <= d2 ; i++ ) {
651         
652                         ccell = ccell.cloneNode(true);
653
654                         //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
655                         //else addCSSClass(ccell, "copy_count_cell_even");
656
657                         var node = nodes[x++];
658                         var type = findOrgType(node.ou_type());
659         
660                         ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
661                         ccell.title = type.opac_label();
662                         countsrow.insertBefore(ccell, lastcell);
663                         lastcell = ccell;
664
665                         if(ccheadcell) {
666                                 var t = ccheadcell.cloneNode(true);
667                                 t.appendChild(text(type.opac_label()));
668                                 ccrow.insertBefore(t, lastheadcell);
669                                 lastheadcell = t;
670                         }
671                 }
672         }
673
674         unHideMe($("search_info_table"));
675 }
676
677 /* collect copy counts for a record using method 'methodName' */
678 function resultCollectCopyCounts(rec, pagePosition, methodName) {
679         if(rec == null || rec.doc_id() == null) return;
680
681         var loc = getLasso();
682         if (loc) loc = -loc;
683         else loc= getLocation();
684
685         var req = new Request(methodName, loc, rec.doc_id(), getForm() );
686         req.request.userdata = [ rec, pagePosition ];
687         req.callback(resultHandleCopyCounts);
688         req.send();
689 }
690
691 function resultHandleCopyCounts(r) {
692         runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject()); 
693 }
694
695
696 /* display the collected copy counts */
697 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
698         if(copy_counts == null || rec == null) return;
699         var i = 0;
700         while(copy_counts[i] != null) {
701                 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
702                 var cts = copy_counts[i];
703                 cell.appendChild(text(cts.available + " / " + cts.count));
704
705                 if(isXUL()) {
706                         /* here we style opac-invisible records for xul */
707
708                         if( cts.depth == 0 ) {
709                                 if(!cts.transcendant && !cts.unshadow) {
710                                         _debug("found an opac-shadowed record: " + rec.doc_id());
711                                         var row = cell.parentNode.parentNode.parentNode.parentNode.parentNode; 
712                                         if( cts.count == 0 ) 
713                                                 addCSSClass( row, 'no_copies' );
714                                         else 
715                                                 addCSSClass( row, 'shadowed' );
716                                 }
717                         }
718                 }
719                 i++;
720         }
721 }
722
723