1 /* - Request ------------------------------------------------------------- */
4 /* define it again here for pages that don't load RemoteRequest */
5 function isXUL() { try { if(IAMXUL) return true;}catch(e){return false;}; }
8 var cookieManager = new HTTP.Cookies();
10 var __ilsEvent; /* the last event the occurred */
13 function Request(type) {
15 var s = type.split(":");
16 if(s[2] == "1" && isXUL()) s[1] += ".staff";
17 this.request = new RemoteRequest(s[0], s[1]);
21 if(!location.href.match(/^https:/))
22 this.request.setSecure(false);
26 if( G.user && G.user.session ) {
27 /* if the user is logged in, all activity resets the timeout
28 This is not entirely accurate in the sense that not all
29 requests will reset the server timeout - this should
30 get close enough, however.
32 var at = getAuthtime();
33 if(at) new AuthTimer(at).run();
37 for( var x = 1; x!= arguments.length; x++ ) {
39 this.request.addParam(arguments[x]);
44 for( var i = 0; i != p.length; i++ ) {
45 if( i > 0 ) str += ", "
48 _debug('request ' + s[0] + ' ' + s[1] + ' ' + str );
50 } else if( DEBUGSLIM ) {
51 _debug('request ' + s[1]);
55 Request.prototype.callback = function(cal) {this.request.setCompleteCallback(cal);}
56 Request.prototype.send = function(block){this.request.send(block);}
57 Request.prototype.result = function(){return this.request.getResultObject();}
59 function showCanvas() {
60 for( var x in G.ui.altcanvas ) {
61 hideMe(G.ui.altcanvas[x]);
63 hideMe(G.ui.common.loading);
64 unHideMe(G.ui.common.canvas_main);
65 try{G.ui.searchbar.text.focus();}catch(e){}
68 function swapCanvas(newNode) {
69 for( var x in G.ui.altcanvas )
70 hideMe(G.ui.altcanvas[x]);
72 hideMe(G.ui.common.loading);
73 hideMe(G.ui.common.canvas_main);
77 /* finds the name of the current page */
78 var currentPage = null;
79 function findCurrentPage() {
80 if(currentPage) return currentPage;
83 for( var p in config.page ) pages.push(config.page[p]);
84 pages = pages.sort( function(a,b){ return - (a.length - b.length); } );
86 var path = location.pathname;
87 if(!path.match(/.*\.xml$/))
88 path += "index.xml"; /* in case they go to / */
91 for( var p in pages ) {
92 if( path.indexOf(pages[p]) != -1)
96 for( var p in config.page ) {
97 if(config.page[p] == page) {
106 /* sets all of the params values ----------------------------- */
107 function initParams() {
110 /* handle the location var */
112 var loc = cgi.param(PARAM_LOCATION);
113 var lasso = cgi.param(PARAM_LASSO);
116 lasso = findOrgLasso( lasso );
117 LASSO = lasso ? lasso.id() : null;
121 org = findOrgUnit(loc);
122 LOCATION = org ? org.id() : null;
125 org = findOrgUnit(loc);
126 LOCATION = org ? org.id() : null;
131 loc = cgi.param(PARAM_ORIGLOC);
133 org = findOrgUnit(loc);
134 if(!org) org = findOrgUnitSN(loc);
136 ORIGLOC = (org) ? org.id() : null;
139 DEPTH = parseInt(cgi.param(PARAM_DEPTH));
140 if(isNaN(DEPTH)) DEPTH = null;
143 TERM = cgi.param(PARAM_TERM);
144 STYPE = cgi.param(PARAM_STYPE);
145 FORM = cgi.param(PARAM_FORM);
146 //DEPTH = parseInt(cgi.param(PARAM_DEPTH));
147 OFFSET = parseInt(cgi.param(PARAM_OFFSET));
148 COUNT = parseInt(cgi.param(PARAM_COUNT));
149 HITCOUNT = parseInt(cgi.param(PARAM_HITCOUNT));
150 MRID = parseInt(cgi.param(PARAM_MRID));
151 RID = parseInt(cgi.param(PARAM_RID));
152 AUTHTIME = parseInt(cgi.param(PARAM_AUTHTIME));
153 ADVTERM = cgi.param(PARAM_ADVTERM);
154 ADVTYPE = cgi.param(PARAM_ADVTYPE);
155 RTYPE = cgi.param(PARAM_RTYPE);
156 SORT = cgi.param(PARAM_SORT);
157 SORT_DIR = cgi.param(PARAM_SORT_DIR);
158 DEBUG = cgi.param(PARAM_DEBUG);
159 CALLNUM = cgi.param(PARAM_CN);
160 LITFORM = cgi.param(PARAM_LITFORM);
161 ITEMFORM = cgi.param(PARAM_ITEMFORM);
162 ITEMTYPE = cgi.param(PARAM_ITEMTYPE);
163 BIBLEVEL = cgi.param(PARAM_BIBLEVEL);
164 AUDIENCE = cgi.param(PARAM_AUDIENCE);
165 SEARCHES = cgi.param(PARAM_SEARCHES);
166 LANGUAGE = cgi.param(PARAM_LANGUAGE);
167 TFORM = cgi.param(PARAM_TFORM);
168 RDEPTH = cgi.param(PARAM_RDEPTH);
169 AVAIL = cgi.param(PARAM_AVAIL);
170 COPYLOCS = cgi.param(PARAM_COPYLOCS);
171 PUBD_BEFORE = cgi.param(PARAM_PUBD_BEFORE);
172 PUBD_AFTER = cgi.param(PARAM_PUBD_AFTER);
173 PUBD_BETWEEN = cgi.param(PARAM_PUBD_BETWEEN);
174 PUBD_DURING = cgi.param(PARAM_PUBD_DURING);
177 /* set up some sane defaults */
178 //if(isNaN(DEPTH)) DEPTH = 0;
179 if(isNaN(RDEPTH)) RDEPTH = 0;
180 if(isNaN(OFFSET)) OFFSET = 0;
181 if(isNaN(COUNT)) COUNT = 10;
182 if(isNaN(HITCOUNT)) HITCOUNT = 0;
183 if(isNaN(MRID)) MRID = 0;
184 if(isNaN(RID)) RID = 0;
185 if(isNaN(ORIGLOC)) ORIGLOC = 0; /* so we know it hasn't been set */
186 if(isNaN(AUTHTIME)) AUTHTIME = 0;
187 if(ADVTERM==null) ADVTERM = "";
188 if(isNaN(AVAIL)) AVAIL = 0;
191 function clearSearchParams() {
223 function initCookies() {
224 FONTSIZE = "regular";
225 var font = cookieManager.read(COOKIE_FONT);
227 if(font) FONTSIZE = font;
228 SKIN = cookieManager.read(COOKIE_SKIN);
229 if(findCurrentPage() == HOME)
230 cookieManager.remove(COOKIE_SEARCH);
233 /* URL param accessors */
234 function getTerm(){return TERM;}
235 function getStype(){return STYPE;}
236 function getLocation(){return LOCATION;}
237 function getLasso(){return LASSO;}
238 function getDepth(){return DEPTH;}
239 function getForm(){return FORM;}
240 function getTform(){return TFORM;}
241 function getOffset(){return OFFSET;}
242 function getDisplayCount(){return COUNT;}
243 function getHitCount(){return HITCOUNT;}
244 function getMrid(){return MRID;};
245 function getRid(){return RID;};
246 function getOrigLocation(){return ORIGLOC;}
247 function getAuthtime() { return AUTHTIME; }
248 function getSearchBarExtras(){return SBEXTRAS;}
249 function getFontSize(){return FONTSIZE;};
250 function getSkin(){return SKIN;};
251 function getAdvTerm(){return ADVTERM;}
252 function getAdvType(){return ADVTYPE;}
253 function getRtype(){return RTYPE;}
254 function getSort(){return SORT;}
255 function getSortDir(){return SORT_DIR;}
256 function getDebug(){return DEBUG;}
257 function getCallnumber() { return CALLNUM; }
258 function getLitForm() { return LITFORM; }
259 function getItemForm() { return ITEMFORM; }
260 function getItemType() { return ITEMTYPE; }
261 function getBibLevel() { return BIBLEVEL; }
262 function getAudience() { return AUDIENCE; }
263 function getSearches() { return SEARCHES; }
264 function getLanguage() { return LANGUAGE; }
265 function getRdepth() { return RDEPTH; }
266 function getAvail() { return AVAIL; }
267 function getCopyLocs() { return COPYLOCS; }
268 function getPubdBefore() { return PUBD_BEFORE; }
269 function getPubdAfter() { return PUBD_AFTER; }
270 function getPubdBetween() { return PUBD_BETWEEN; }
271 function getPubdDuring() { return PUBD_DURING; }
274 function findBasePath() {
275 var path = location.pathname;
276 if(!path.match(/.*\.xml$/)) path += "index.xml";
277 var idx = path.indexOf(config.page[findCurrentPage()]);
278 return path.substring(0, idx);
281 function findBaseURL(ssl) {
282 var path = findBasePath();
283 var proto = (ssl) ? "https:" : "http:";
285 /* strip port numbers. This is necessary for browsers that
286 send an explicit <host>:80, 443 - explicit ports
287 break links that need to change ports (e.g. http -> https) */
288 var h = location.host.replace(/:.*/,'');
290 return proto + "//" + h + path;
294 function buildISBNSrc(isbn) {
295 return "http://" + location.host + "/jackets/" + isbn;
299 function buildImageLink(name, ssl) {
300 return findBaseURL(ssl) + "../../../../images/" + name;
303 function buildExtrasLink(name, ssl) {
304 return findBaseURL(ssl) + "../../../../extras/" + name;
308 function _debug(str) {
309 try { dump('dbg: ' + str + '\n'); } catch(e) {}
311 /* potentially useful, but usually just annoying */
314 if(!consoleService) {
316 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
317 this.consoleService = Components.classes['@mozilla.org/consoleservice;1']
318 .getService(Components.interfaces.nsIConsoleService);
324 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
325 consoleService.logStringMessage(str + '\n');
332 function buildOPACLink(args, slim, ssl) {
338 string = findBaseURL(ssl);
339 if(args.page) string += config.page[args.page];
340 else string += config.page[findCurrentPage()];
343 /* this may seem unnecessary.. safety precaution for now */
345 if( args[PARAM_DEPTH] == null )
346 args[PARAM_DEPTH] = getDepth();
351 for( var x in args ) {
353 if(x == "page" || v == null || v == undefined || v+'' == 'NaN' ) continue;
354 if(x == PARAM_OFFSET && v == 0) continue;
355 if(x == PARAM_COUNT && v == 10) continue;
356 if(x == PARAM_FORM && v == 'all' ) continue;
357 if( instanceOf(v, Array) && v.length ) {
358 for( var i = 0; i < v.length; i++ ) {
359 string += "&" + x + "=" + encodeURIComponent(v[i]);
362 string += "&" + x + "=" + encodeURIComponent(v);
367 string += _appendParam(DEBUG, PARAM_DEBUG, args, getDebug, string);
368 if(getOrigLocation() != 1)
369 string += _appendParam(ORIGLOC, PARAM_ORIGLOC, args, getOrigLocation, string);
371 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
373 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
374 if(getLocation() != 1)
375 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
376 if(getLasso() != null)
377 string += _appendParam(LASSO, PARAM_LASSO, args, getLasso, string);
378 if(getDepth() != null)
379 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
380 if(getForm() && (getForm() != 'all') )
381 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
382 if(getTform() && (getTform() != 'all') )
383 string += _appendParam(TFORM, PARAM_TFORM, args, getTform, string);
385 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
386 if(getDisplayCount() != 10)
387 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
389 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
391 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
393 string += _appendParam(RID, PARAM_RID, args, getRid, string);
395 string += _appendParam(AUTHTIME, PARAM_AUTHTIME, args, getAuthtime, string);
397 string += _appendParam(ADVTERM, PARAM_ADVTERM, args, getAdvTerm, string);
399 string += _appendParam(ADVTYPE, PARAM_ADVTYPE, args, getAdvType, string);
401 string += _appendParam(RTYPE, PARAM_RTYPE, args, getRtype, string);
403 string += _appendParam(ITEMFORM, PARAM_ITEMFORM, args, getItemForm, string);
405 string += _appendParam(ITEMTYPE, PARAM_ITEMTYPE, args, getItemType, string);
407 string += _appendParam(BIBLEVEL, PARAM_BIBLEVEL, args, getBibLevel, string);
409 string += _appendParam(LITFORM, PARAM_LITFORM, args, getLitForm, string);
411 string += _appendParam(AUDIENCE, PARAM_AUDIENCE, args, getAudience, string);
413 string += _appendParam(SEARCHES, PARAM_SEARCHES, args, getSearches, string);
415 string += _appendParam(LANGUAGE, PARAM_LANGUAGE, args, getLanguage, string);
416 if(getRdepth() != null)
417 string += _appendParam(RDEPTH, PARAM_RDEPTH, args, getRdepth, string);
418 if(getSort() != null)
419 string += _appendParam(SORT, PARAM_SORT, args, getSort, string);
420 if(getSortDir() != null)
421 string += _appendParam(SORT_DIR, PARAM_SORT_DIR, args, getSortDir, string);
423 string += _appendParam(AVAIL, PARAM_AVAIL, args, getAvail, string);
425 string += _appendParam(COPYLOCS, PARAM_COPYLOCS, args, getCopyLocs, string);
427 string += _appendParam(PUBD_BEFORE, PARAM_PUBD_BEFORE, args, getPubdBefore, string);
429 string += _appendParam(PUBD_AFTER, PARAM_PUBD_AFTER, args, getPubdAfter, string);
431 string += _appendParam(PUBD_BETWEEN, PARAM_PUBD_BETWEEN, args, getPubdBetween, string);
433 string += _appendParam(PUBD_DURING, PARAM_PUBD_DURING, args, getPubdDuring, string);
436 return string.replace(/\&$/,'').replace(/\?\&/,"?");
440 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
444 if( fieldVar != null &&
445 (fieldVar +'' != 'NaN') &&
446 overrideArgs[fieldName] == null &&
448 getFunc()+'' != '' ) {
450 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
456 /* ----------------------------------------------------------------------- */
457 function cleanISBN(isbn) {
459 isbn = isbn.toString().replace(/^\s+/,"");
460 var idx = isbn.indexOf(" ");
461 if(idx > -1) { isbn = isbn.substring(0, idx); }
467 /* builds a link that goes to the title listings for a metarecord */
468 function buildTitleLink(rec, link) {
470 link.appendChild(text(normalize(truncate(rec.title(), 65))));
473 args[PARAM_OFFSET] = 0;
474 args[PARAM_MRID] = rec.doc_id();
475 args[PARAM_RTYPE] = RTYPE_MRID;
476 var linkText = link.innerHTML; // IE
477 link.setAttribute("href", buildOPACLink(args));
478 link.innerHTML = linkText; // IE
481 function buildTitleDetailLink(rec, link) {
483 link.appendChild(text(normalize(truncate(rec.title(), 65))));
486 args[PARAM_RID] = rec.doc_id();
487 // in IE, if the link text contains a '@', it replaces the innerHTML text
488 // with the value of the href attribute. Wait, what? Yes. Capture the
489 // innerHTML and put it back into place after the href is set
490 var linkText = link.innerHTML; // IE
491 link.setAttribute("href", buildOPACLink(args));
492 link.innerHTML = linkText; // IE
495 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
496 'trunc' is the number of characters to show in the string, defaults to 65 */
497 function buildSearchLink(type, string, linknode, trunc) {
498 if(!trunc) trunc = 65;
500 if( SHOW_MR_DEFAULT) {
504 args[PARAM_RTYPE] = type;
506 args[PARAM_OFFSET] = 0;
507 args[PARAM_TERM] = string;
508 args[PARAM_STYPE] = type;
509 linknode.appendChild(text(normalize(truncate(string, trunc))));
510 linknode.setAttribute("href", buildOPACLink(args));
513 function setSessionCookie(ses) {
514 cookieManager.write(COOKIE_SES, ses, -1);
519 /* ----------------------------------------------------------------------- */
520 /* user session handling */
521 /* ----------------------------------------------------------------------- */
522 /* session is the login session. If no session is provided, we attempt
523 to find one in the cookies. If 'force' is true we retrieve the
524 user from the server even if there is already a global user present.
525 if ses != G.user.session, we also force a grab */
526 function grabUser(ses, force) {
528 if(!ses && isXUL()) {
529 stash = fetchXULStash();
530 ses = stash.session.key
531 _debug("stash auth token = " + ses);
535 ses = cookieManager.read(COOKIE_SES);
536 /* https cookies don't show up in http servers.. */
539 if(!ses) return false;
542 if(G.user && G.user.session == ses)
545 /* first make sure the session is valid */
546 var request = new Request(FETCH_SESSION, ses, 1 );
547 request.request.alertEvent = false;
549 var user = request.result();
553 return false; /* unable to grab the session */
556 if( !(typeof user == 'object' && user._isfieldmapper) ) {
562 G.user.fleshed = false;
563 G.user.session = ses;
564 setSessionCookie(ses);
567 if(G.user.prefs['opac.hits_per_page'])
568 COUNT = parseInt(G.user.prefs['opac.hits_per_page']);
570 if(G.user.prefs[PREF_DEF_FONT])
571 setFontSize(G.user.prefs[PREF_DEF_FONT]);
573 var at = getAuthtime();
574 //if(isXUL()) at = xulG['authtime'];
576 if(at && !isXUL()) new AuthTimer(at).run();
581 /* sets the 'prefs' field of the user object to their preferences
582 and returns the preferences */
583 function grabUserPrefs(user, force) {
584 if(user == null) user = G.user;
585 if(!force && user.prefs) return user.prefs;
586 var req = new Request(FETCH_USER_PREFS, G.user.session, user.id());
588 user.prefs = req.result();
592 function grabFleshedUser() {
594 if(!G.user || !G.user.session) {
596 if(!G.user || !G.user.session) return null;
599 if(G.user.fleshed) return G.user;
601 var req = new Request(FETCH_FLESHED_USER, G.user.session);
604 G.user = req.result();
606 if(!G.user || G.user.length == 0) {
607 G.user = null; return false;
608 cookieManager.write(COOKIE_SES,"");
611 G.user.session = ses;
612 G.user.fleshed = true;
614 setSessionCookie(ses);
618 function checkUserSkin(new_skin) {
620 return; /* XXX do some debugging with this... */
622 var user_skin = getSkin();
623 var cur_skin = grabSkinFromURL();
625 if(new_skin) user_skin = new_skin;
630 if(grabUserPrefs()) {
631 user_skin = G.user.prefs["opac.skin"];
632 cookieManager.write( COOKIE_SKIN, user_skin, '+1y' );
637 if(!user_skin) return;
639 if( cur_skin != user_skin ) {
640 var url = buildOPACLink();
641 goTo(url.replace(cur_skin, user_skin));
645 function updateUserSetting(setting, value, user) {
646 if(user == null) user = G.user;
649 var req = new Request( UPDATE_USER_PREFS, user.session, a );
654 function commitUserPrefs() {
655 var req = new Request(
656 UPDATE_USER_PREFS, G.user.session, null, G.user.prefs );
661 function grabSkinFromURL() {
662 var path = findBasePath();
663 path = path.replace("/xml/", "");
665 for( var i = path.length - 1; i >= 0; i-- ) {
666 var ch = path.charAt(i);
672 for( i = skin.length - 1; i >= 0; i--)
673 skin2 += skin.charAt(i);
679 /* returns a fleshed G.user on success, false on failure */
680 function doLogin(suppressEvents) {
684 var uname = G.ui.login.username.value;
685 var passwd = G.ui.login.password.value;
687 var init_request = new Request( LOGIN_INIT, uname );
688 init_request.send(true);
689 var seed = init_request.result();
691 if( ! seed || seed == '0') {
692 alert( "Error Communicating with Authentication Server" );
697 password : hex_md5(seed + hex_md5(passwd)),
699 org : getOrigLocation()
702 r = fetchOrgSettingDefault(globalOrgTree.id(), 'opac.barcode_regex');
703 if(r) REGEX_BARCODE = new RegExp(r);
705 if( uname.match(REGEX_BARCODE) ) args.barcode = uname;
706 else args.username = uname;
708 var auth_request = new Request( LOGIN_COMPLETE, args );
710 auth_request.request.alertEvent = false;
711 auth_request.send(true);
712 var auth_result = auth_request.result();
715 alertId('patron_login_failed');
719 if( checkILSEvent(auth_result) ) {
721 if( auth_result.textcode == 'PATRON_INACTIVE' ) {
722 alertId('patron_inactive_alert');
726 if( auth_result.textcode == 'PATRON_CARD_INACTIVE' ) {
727 alertId('patron_card_inactive_alert');
731 if( auth_result.textcode == 'LOGIN_FAILED' ||
732 auth_result.textcode == 'PERM_FAILURE' ) {
733 alertId('patron_login_failed');
739 AUTHTIME = parseInt(auth_result.payload.authtime);
740 var u = grabUser(auth_result.payload.authtoken, true);
741 if(u && ! suppressEvents)
742 runEvt( "common", "locationChanged", u.ws_ou(), findOrgDepth(u.ws_ou()) );
749 function doLogout() {
751 /* cancel everything else */
754 /* be nice and delete the session from the server */
755 if(G.user && G.user.session) {
756 var req = new Request(LOGIN_DELETE, G.user.session);
758 try { req.result(); } catch(E){}
763 /* remove any cached data */
764 dojo.require('dojo.cookie');
765 dojo.cookie(COOKIE_SES, '', {expires:-1});
766 dojo.cookie(COOKIE_RIDS, '', {expires:-1});
767 dojo.cookie(COOKIE_SKIN, '', {expires:-1});
768 dojo.cookie(COOKIE_SEARCH, '', {expires:-1});
771 checkUserSkin("default");
776 args[PARAM_TERM] = "";
777 args[PARAM_LOCATION] = getOrigLocation();
778 args[PARAM_DEPTH] = findOrgDepth(getOrigLocation());
783 try{ if(isFrontPage) nored = true; } catch(e){nored = false;}
784 if(!nored) goTo(buildOPACLink(args));
788 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
789 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
792 /* ----------------------------------------------------------------------- */
793 /* build the org tree */
794 /* ----------------------------------------------------------------------- */
795 function drawOrgTree() {
796 //setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 10 );
797 setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 1 );
801 function buildOrgSelector(node) {
802 var tree = new SlimTree(node,'orgTreeSelector');
803 orgTreeSelector = tree;
804 for( var i in orgArraySearcher ) {
805 var node = orgArraySearcher[i];
806 if( node == null ) continue;
807 if(!isXUL() && !isTrue(node.opac_visible())) continue;
808 if(node.parent_ou() == null)
809 tree.addNode(node.id(), -1, node.name(),
810 "javascript:orgSelect(" + node.id() + ");", node.name());
812 tree.addNode(node.id(), node.parent_ou(), node.name(),
813 "javascript:orgSelect(" + node.id() + ");", node.name());
816 hideMe($('org_loading_div'));
817 unHideMe($('org_selector_tip'));
821 function orgSelect(id) {
823 runEvt("common", "locationChanged", id, findOrgDepth(id) );
826 var loc = findOrgLasso(getLasso());
827 if (!loc) loc = findOrgUnit(id);
829 removeChildren(G.ui.common.now_searching);
830 G.ui.common.now_searching.appendChild(text(loc.name()));
833 function setFontSize(size) {
835 cookieManager.write(COOKIE_FONT, size, '+1y');
838 var resourceFormats = [
841 "sound recording", "software, multimedia",
846 "three dimensional object" ];
849 function modsFormatToMARC(format) {
855 case "sound recording":
857 case "sound recording-nonmusical":
859 case "sound recording-musical":
861 case "software, multimedia":
867 case "mixed material":
869 case "notated music":
871 case "three dimensional object":
878 function MARCFormatToMods(format) {
884 return "moving image";
886 return "sound recording-nonmusical";
888 return "sound recording-musical";
890 return "software, multimedia";
892 return "still image";
895 return "cartographic";
898 return "mixed material";
901 return "notated music";
903 return "three dimensional object";
908 function MARCTypeToFriendly(format) {
909 var words = $('format_words');
912 case 't' : return $n(words, 'at').innerHTML;
914 var node = $n(words,format);
915 if( node ) return node.innerHTML;
920 function setResourcePic( img, resource ) {
921 img.setAttribute( "src", "../../../../images/tor/" + resource + ".jpg");
922 img.title = resource;
927 function msg( text ) {
928 try { alert( text ); } catch(e) {}
931 function findRecord(id,type) {
933 for( var i = 0; i != recordsCache.length; i++ ) {
934 var rec = recordsCache[i];
935 if( rec && rec.doc_id() == id ) return rec;
938 var meth = FETCH_RMODS
939 if(type == 'M') meth = FETCH_MRMODS;
940 var req = new Request(meth, id);
941 req.request.alertEvent = false;
943 var res = req.result();
944 if( checkILSEvent(res) ) return null;
948 function Timer(name, node){
953 Timer.prototype.start =
954 function(){_timerRun(this.name);}
955 Timer.prototype.stop =
956 function(){this.done = true;}
957 function _timerRun(tname) {
961 if(_t.count > 100) return;
963 if( (_t.count % 5) == 0 )
965 _t.node.appendChild(text(str));
966 setTimeout("_timerRun('"+tname+"');", 200);
970 function checkILSEvent(obj) {
971 if( obj && obj.ilsevent != null && obj.ilsevent != 0 )
972 return parseInt(obj.ilsevent);
977 function alertILSEvent(evt, msg) {
980 alert(msg +'\n' + evt.textcode + '\n' + evt.desc );
982 alert(evt.textcode + '\n' + evt.desc );
987 function AuthTimer(time) {
988 this.time = (time - LOGOUT_WARNING_TIME) * 1000;
990 try {clearTimeout(__authTimer.id)} catch(e){}
994 AuthTimer.prototype.run = function() {
995 this.id = setTimeout('_authTimerAlert()', this.time);
998 function _authTimerAlert() {
999 alert( $('auth_session_expiring').innerHTML );
1000 if(!grabUser(null, true)) doLogout();
1004 function grabUserByBarcode( authtoken, barcode ) {
1005 var req = new Request( FETCH_USER_BYBARCODE, authtoken, barcode );
1007 return req.result();
1012 goTo(buildOPACLink({page:HOME}));
1016 function buildOrgSel(selector, org, offset, namecol) {
1017 if(!namecol) namecol = 'name';
1018 if(!isXUL() && !isTrue(org.opac_visible())) return;
1019 insertSelectorVal( selector, -1,
1020 org[namecol](), org.id(), null, findOrgDepth(org) - offset );
1021 for( var c in org.children() )
1022 buildOrgSel( selector, org.children()[c], offset, namecol);
1025 function buildMergedOrgSel(selector, org_list, offset, namecol) {
1026 if(!namecol) namecol = 'name';
1027 for(var i = 0; i < org_list.length; i++) {
1028 var org = findOrgUnit(org_list[i]);
1029 insertSelectorVal( selector, -1,
1030 org[namecol](), org.id(), null, findOrgDepth(org) - offset );
1031 for( var c in org.children() )
1032 buildOrgSel( selector, org.children()[c], offset, namecol);
1037 function parseForm(form) {
1038 if(!form) return {};
1040 var it = form.replace(/-\w+$/,"");
1045 if(form.match(/-/)) itf = form.replace(/^\w+-/,"");
1049 for( var i = 0; i < it.length; i++ )
1050 item_type.push( it.charAt(i) );
1055 for( var i = 0; i < itf.length; i++ )
1056 item_form.push( itf.charAt(i) );
1059 return {item_type: item_type, item_form:item_form};
1063 function isTrue(x) { return ( x && x != "0" && !(x+'').match(/^f$/i) ); }
1065 function fetchPermOrgs() {
1066 var a = []; /* why does arguments come accross as an object and not an array? */
1067 for( var i = 0; i < arguments.length; i++ )
1068 a.push(arguments[i])
1070 var preq = new Request(FETCH_HIGHEST_PERM_ORG,
1071 G.user.session, G.user.id(), a );
1073 return preq.result();
1077 function print_tabs(t) {
1079 for (var j = 0; j < t; j++ ) { r = r + " "; }
1082 function formatJSON(s) {
1083 var r = ''; var t = 0;
1085 if (s[i] == '{' || s[i] == '[' ) {
1086 r = r + s[i] + "\n" + print_tabs(++t);
1087 } else if (s[i] == '}' || s[i] == ']') {
1088 t--; r = r + "\n" + print_tabs(t) + s[i];
1089 } else if (s[i] == ',') {
1090 r = r + s[i] + "\n" + print_tabs(t);