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