1 /* - Request ------------------------------------------------------------- */
3 /* define it again here for pages that don't load RemoteRequest */
4 function isXUL() { try { if(IAMXUL) return true;}catch(e){return false;}; }
7 var cookieManager = new HTTP.Cookies();
9 var __ilsEvent; /* the last event the occurred */
12 function Request(type) {
14 var s = type.split(":");
15 if(s[2] == "1" && isXUL()) s[1] += ".staff";
16 this.request = new RemoteRequest(s[0], s[1]);
20 if(!location.href.match(/^https:/))
21 this.request.setSecure(false);
25 if( G.user && G.user.session ) {
26 /* if the user is logged in, all activity resets the timeout
27 This is not entirely accurate in the sense that not all
28 requests will reset the server timeout - this should
29 get close enough, however.
31 var at = getAuthtime();
32 if(at) new AuthTimer(at).run();
36 for( var x = 1; x!= arguments.length; x++ ) {
38 this.request.addParam(arguments[x]);
43 for( var i = 0; i != p.length; i++ ) {
44 if( i > 0 ) str += ", "
47 _debug('request ' + s[0] + ' ' + s[1] + ' ' + str );
49 } else if( DEBUGSLIM ) {
50 _debug('request ' + s[1]);
54 Request.prototype.callback = function(cal) {this.request.setCompleteCallback(cal);}
55 Request.prototype.send = function(block){this.request.send(block);}
56 Request.prototype.result = function(){return this.request.getResultObject();}
58 function showCanvas() {
59 for( var x in G.ui.altcanvas ) {
60 hideMe(G.ui.altcanvas[x]);
62 hideMe(G.ui.common.loading);
63 unHideMe(G.ui.common.canvas_main);
64 try{G.ui.searchbar.text.focus();}catch(e){}
67 function swapCanvas(newNode) {
68 for( var x in G.ui.altcanvas )
69 hideMe(G.ui.altcanvas[x]);
71 hideMe(G.ui.common.loading);
72 hideMe(G.ui.common.canvas_main);
76 /* finds the name of the current page */
77 var currentPage = null;
78 function findCurrentPage() {
79 if(currentPage) return currentPage;
82 for( var p in config.page ) pages.push(config.page[p]);
83 pages = pages.sort( function(a,b){ return - (a.length - b.length); } );
85 var path = location.pathname;
86 if(!path.match(/.*\.xml$/))
87 path += "index.xml"; /* in case they go to / */
90 for( var p in pages ) {
91 if( path.indexOf(pages[p]) != -1)
95 for( var p in config.page ) {
96 if(config.page[p] == page) {
105 /* sets all of the params values ----------------------------- */
106 function initParams() {
109 /* handle the location var */
111 var loc = cgi.param(PARAM_LOCATION);
113 org = findOrgUnit(loc);
114 if(!org) org = findOrgUnitSN(loc);
116 LOCATION = (org) ? org.id() : null;
119 loc = cgi.param(PARAM_ORIGLOC);
121 org = findOrgUnit(loc);
122 if(!org) org = findOrgUnitSN(loc);
124 ORIGLOC = (org) ? org.id() : null;
127 DEPTH = parseInt(cgi.param(PARAM_DEPTH));
128 if(isNaN(DEPTH)) DEPTH = null;
131 TERM = cgi.param(PARAM_TERM);
132 STYPE = cgi.param(PARAM_STYPE);
133 FORM = cgi.param(PARAM_FORM);
134 //DEPTH = parseInt(cgi.param(PARAM_DEPTH));
135 OFFSET = parseInt(cgi.param(PARAM_OFFSET));
136 COUNT = parseInt(cgi.param(PARAM_COUNT));
137 HITCOUNT = parseInt(cgi.param(PARAM_HITCOUNT));
138 MRID = parseInt(cgi.param(PARAM_MRID));
139 RID = parseInt(cgi.param(PARAM_RID));
140 AUTHTIME = parseInt(cgi.param(PARAM_AUTHTIME));
141 ADVTERM = cgi.param(PARAM_ADVTERM);
142 ADVTYPE = cgi.param(PARAM_ADVTYPE);
143 RTYPE = cgi.param(PARAM_RTYPE);
144 SORT = cgi.param(PARAM_SORT);
145 SORT_DIR = cgi.param(PARAM_SORT_DIR);
146 DEBUG = cgi.param(PARAM_DEBUG);
147 CALLNUM = cgi.param(PARAM_CN);
148 LITFORM = cgi.param(PARAM_LITFORM);
149 ITEMFORM = cgi.param(PARAM_ITEMFORM);
150 ITEMTYPE = cgi.param(PARAM_ITEMTYPE);
151 AUDIENCE = cgi.param(PARAM_AUDIENCE);
152 SEARCHES = cgi.param(PARAM_SEARCHES);
153 LANGUAGE = cgi.param(PARAM_LANGUAGE);
154 TFORM = cgi.param(PARAM_TFORM);
155 RDEPTH = cgi.param(PARAM_RDEPTH);
157 /* set up some sane defaults */
158 //if(isNaN(DEPTH)) DEPTH = 0;
159 if(isNaN(RDEPTH)) RDEPTH = 0;
160 if(isNaN(OFFSET)) OFFSET = 0;
161 if(isNaN(COUNT)) COUNT = 10;
162 if(isNaN(HITCOUNT)) HITCOUNT = 0;
163 if(isNaN(MRID)) MRID = 0;
164 if(isNaN(RID)) RID = 0;
165 if(isNaN(ORIGLOC)) ORIGLOC = 0; /* so we know it hasn't been set */
166 if(isNaN(AUTHTIME)) AUTHTIME = 0;
167 if(ADVTERM==null) ADVTERM = "";
170 function clearSearchParams() {
195 function initCookies() {
196 FONTSIZE = "regular";
197 var font = cookieManager.read(COOKIE_FONT);
199 if(font) FONTSIZE = font;
200 SKIN = cookieManager.read(COOKIE_SKIN);
203 /* URL param accessors */
204 function getTerm(){return TERM;}
205 function getStype(){return STYPE;}
206 function getLocation(){return LOCATION;}
207 function getDepth(){return DEPTH;}
208 function getForm(){return FORM;}
209 function getTform(){return TFORM;}
210 function getOffset(){return OFFSET;}
211 function getDisplayCount(){return COUNT;}
212 function getHitCount(){return HITCOUNT;}
213 function getMrid(){return MRID;};
214 function getRid(){return RID;};
215 function getOrigLocation(){return ORIGLOC;}
216 function getAuthtime() { return AUTHTIME; }
217 function getSearchBarExtras(){return SBEXTRAS;}
218 function getFontSize(){return FONTSIZE;};
219 function getSkin(){return SKIN;};
220 function getAdvTerm(){return ADVTERM;}
221 function getAdvType(){return ADVTYPE;}
222 function getRtype(){return RTYPE;}
223 function getSort(){return SORT;}
224 function getSortDir(){return SORT_DIR;}
225 function getDebug(){return DEBUG;}
226 function getCallnumber() { return CALLNUM; }
227 function getLitForm() { return LITFORM; }
228 function getItemForm() { return ITEMFORM; }
229 function getItemType() { return ITEMTYPE; }
230 function getAudience() { return AUDIENCE; }
231 function getSearches() { return SEARCHES; }
232 function getLanguage() { return LANGUAGE; }
233 function getRdepth() { return RDEPTH; }
236 function findBasePath() {
237 var path = location.pathname;
238 if(!path.match(/.*\.xml$/)) path += "index.xml";
239 var idx = path.indexOf(config.page[findCurrentPage()]);
240 return path.substring(0, idx);
243 function findBaseURL(ssl) {
244 var path = findBasePath();
245 var proto = (ssl) ? "https:" : "http:";
247 /* strip port numbers. This is necessary for browsers that
248 send an explicit <host>:80, 443 - explicit ports
249 break links that need to change ports (e.g. http -> https) */
250 var h = location.host.replace(/:.*/,'');
252 return proto + "//" + h + path;
256 function buildISBNSrc(isbn) {
257 return "http://" + location.host + "/jackets/" + isbn;
261 function buildImageLink(name, ssl) {
262 return findBaseURL(ssl) + "../../../../images/" + name;
265 function buildExtrasLink(name, ssl) {
266 return findBaseURL(ssl) + "../../../../extras/" + name;
270 function _debug(str) {
271 try { dump('dbg: ' + str + '\n'); } catch(e) {}
273 /* potentially useful, but usually just annoying */
276 if(!consoleService) {
278 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
279 this.consoleService = Components.classes['@mozilla.org/consoleservice;1']
280 .getService(Components.interfaces.nsIConsoleService);
286 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
287 consoleService.logStringMessage(str + '\n');
294 function buildOPACLink(args, slim, ssl) {
300 string = findBaseURL(ssl);
301 if(args.page) string += config.page[args.page];
302 else string += config.page[findCurrentPage()];
305 /* this may seem unnecessary.. safety precaution for now */
307 if( args[PARAM_DEPTH] == null )
308 args[PARAM_DEPTH] = getDepth();
313 for( var x in args ) {
315 if(x == "page" || v == null || v == undefined || v+'' == 'NaN' ) continue;
316 if(x == PARAM_OFFSET && v == 0) continue;
317 if(x == PARAM_COUNT && v == 10) continue;
318 if(x == PARAM_FORM && v == 'all' ) continue;
319 if( instanceOf(v, Array) && v.length ) {
320 for( var i = 0; i < v.length; i++ ) {
321 string += "&" + x + "=" + encodeURIComponent(v[i]);
324 string += "&" + x + "=" + encodeURIComponent(v);
329 string += _appendParam(DEBUG, PARAM_DEBUG, args, getDebug, string);
330 if(getOrigLocation() != 1)
331 string += _appendParam(ORIGLOC, PARAM_ORIGLOC, args, getOrigLocation, string);
333 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
335 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
336 if(getLocation() != 1)
337 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
338 if(getDepth() != null)
339 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
340 if(getForm() && (getForm() != 'all') )
341 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
342 if(getTform() && (getTform() != 'all') )
343 string += _appendParam(TFORM, PARAM_TFORM, args, getTform, string);
345 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
346 if(getDisplayCount() != 10)
347 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
349 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
351 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
353 string += _appendParam(RID, PARAM_RID, args, getRid, string);
355 string += _appendParam(AUTHTIME, PARAM_AUTHTIME, args, getAuthtime, string);
357 string += _appendParam(ADVTERM, PARAM_ADVTERM, args, getAdvTerm, string);
359 string += _appendParam(ADVTYPE, PARAM_ADVTYPE, args, getAdvType, string);
361 string += _appendParam(RTYPE, PARAM_RTYPE, args, getRtype, string);
363 string += _appendParam(ITEMFORM, PARAM_ITEMFORM, args, getItemForm, string);
365 string += _appendParam(ITEMTYPE, PARAM_ITEMTYPE, args, getItemType, string);
367 string += _appendParam(LITFORM, PARAM_LITFORM, args, getLitForm, string);
369 string += _appendParam(AUDIENCE, PARAM_AUDIENCE, args, getAudience, string);
371 string += _appendParam(SEARCHES, PARAM_SEARCHES, args, getSearches, string);
373 string += _appendParam(LANGUAGE, PARAM_LANGUAGE, args, getLanguage, string);
374 if(getRdepth() != null)
375 string += _appendParam(RDEPTH, PARAM_RDEPTH, args, getRdepth, string);
376 if(getSort() != null)
377 string += _appendParam(SORT, PARAM_SORT, args, getSort, string);
378 if(getSortDir() != null)
379 string += _appendParam(SORT_DIR, PARAM_SORT_DIR, args, getSortDir, string);
381 return string.replace(/\&$/,'').replace(/\?\&/,"?");
385 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
389 if( fieldVar != null &&
390 (fieldVar +'' != 'NaN') &&
391 overrideArgs[fieldName] == null &&
393 getFunc()+'' != '' ) {
395 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
401 /* ----------------------------------------------------------------------- */
402 function cleanISBN(isbn) {
404 isbn = isbn.toString().replace(/^\s+/,"");
405 var idx = isbn.indexOf(" ");
406 if(idx > -1) { isbn = isbn.substring(0, idx); }
412 /* builds a link that goes to the title listings for a metarecord */
413 function buildTitleLink(rec, link) {
415 link.appendChild(text(normalize(truncate(rec.title(), 65))));
418 args[PARAM_OFFSET] = 0;
419 args[PARAM_MRID] = rec.doc_id();
420 args[PARAM_RTYPE] = RTYPE_MRID;
421 link.setAttribute("href", buildOPACLink(args));
424 function buildTitleDetailLink(rec, link) {
426 link.appendChild(text(normalize(truncate(rec.title(), 65))));
429 //args[PARAM_OFFSET] = 0;
430 args[PARAM_RID] = rec.doc_id();
431 link.setAttribute("href", buildOPACLink(args));
434 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
435 'trunc' is the number of characters to show in the string, defaults to 65 */
436 function buildSearchLink(type, string, linknode, trunc) {
437 if(!trunc) trunc = 65;
439 if( SHOW_MR_DEFAULT) {
443 args[PARAM_RTYPE] = type;
445 args[PARAM_OFFSET] = 0;
446 args[PARAM_TERM] = string;
447 args[PARAM_STYPE] = type;
448 linknode.appendChild(text(normalize(truncate(string, trunc))));
449 linknode.setAttribute("href", buildOPACLink(args));
452 function setSessionCookie(ses) {
453 cookieManager.write(COOKIE_SES, ses, -1);
458 /* ----------------------------------------------------------------------- */
459 /* user session handling */
460 /* ----------------------------------------------------------------------- */
461 /* session is the login session. If no session is provided, we attempt
462 to find one in the cookies. If 'force' is true we retrieve the
463 user from the server even if there is already a global user present.
464 if ses != G.user.session, we also force a grab */
465 function grabUser(ses, force) {
467 if(!ses && isXUL()) {
468 stash = fetchXULStash();
469 ses = stash.session.key
470 _debug("stash auth token = " + ses);
474 ses = cookieManager.read(COOKIE_SES);
475 /* https cookies don't show up in http servers.. */
478 if(!ses) return false;
481 if(G.user && G.user.session == ses)
484 /* first make sure the session is valid */
485 var request = new Request(FETCH_SESSION, ses, 1 );
486 request.request.alertEvent = false;
488 var user = request.result();
492 return false; /* unable to grab the session */
495 if( !(typeof user == 'object' && user._isfieldmapper) ) {
501 G.user.fleshed = false;
502 G.user.session = ses;
503 setSessionCookie(ses);
506 if(G.user.prefs['opac.hits_per_page'])
507 COUNT = parseInt(G.user.prefs['opac.hits_per_page']);
509 if(G.user.prefs[PREF_DEF_FONT])
510 setFontSize(G.user.prefs[PREF_DEF_FONT]);
512 var at = getAuthtime();
513 //if(isXUL()) at = xulG['authtime'];
515 if(at && !isXUL()) new AuthTimer(at).run();
520 /* sets the 'prefs' field of the user object to their preferences
521 and returns the preferences */
522 function grabUserPrefs(user, force) {
523 if(user == null) user = G.user;
524 if(!force && user.prefs) return user.prefs;
525 var req = new Request(FETCH_USER_PREFS, user.session, user.id());
527 user.prefs = req.result();
531 function grabFleshedUser() {
533 if(!G.user || !G.user.session) {
535 if(!G.user || !G.user.session) return null;
538 if(G.user.fleshed) return G.user;
540 var req = new Request(FETCH_FLESHED_USER, G.user.session);
543 G.user = req.result();
545 if(!G.user || G.user.length == 0) {
546 G.user = null; return false;
547 cookieManager.write(COOKIE_SES,"");
550 G.user.session = ses;
551 G.user.fleshed = true;
553 setSessionCookie(ses);
557 function checkUserSkin(new_skin) {
559 return; /* XXX do some debugging with this... */
561 var user_skin = getSkin();
562 var cur_skin = grabSkinFromURL();
564 if(new_skin) user_skin = new_skin;
569 if(grabUserPrefs()) {
570 user_skin = G.user.prefs["opac.skin"];
571 cookieManager.write( COOKIE_SKIN, user_skin, '+1y' );
576 if(!user_skin) return;
578 if( cur_skin != user_skin ) {
579 var url = buildOPACLink();
580 goTo(url.replace(cur_skin, user_skin));
584 function updateUserSetting(setting, value, user) {
585 if(user == null) user = G.user;
588 var req = new Request( UPDATE_USER_PREFS, user.session, a );
593 function commitUserPrefs() {
594 var req = new Request(
595 UPDATE_USER_PREFS, G.user.session, null, G.user.prefs );
600 function grabSkinFromURL() {
601 var path = findBasePath();
602 path = path.replace("/xml/", "");
604 for( var i = path.length - 1; i >= 0; i-- ) {
605 var ch = path.charAt(i);
611 for( i = skin.length - 1; i >= 0; i--)
612 skin2 += skin.charAt(i);
618 /* returns a fleshed G.user on success, false on failure */
619 function doLogin(suppressEvents) {
623 var uname = G.ui.login.username.value;
624 var passwd = G.ui.login.password.value;
626 var init_request = new Request( LOGIN_INIT, uname );
627 init_request.send(true);
628 var seed = init_request.result();
630 if( ! seed || seed == '0') {
631 alert( "Error Communicating with Authentication Server" );
636 password : hex_md5(seed + hex_md5(passwd)),
638 org : getOrigLocation()
641 if( uname.match(REGEX_BARCODE) ) args.barcode = uname; /* make this better */
642 else args.username = uname;
644 var auth_request = new Request( LOGIN_COMPLETE, args );
646 auth_request.request.alertEvent = false;
647 auth_request.send(true);
648 var auth_result = auth_request.result();
651 alertId('patron_login_failed');
655 if( checkILSEvent(auth_result) ) {
657 if( auth_result.textcode == 'PATRON_INACTIVE' ) {
658 alertId('patron_inactive_alert');
662 if( auth_result.textcode == 'PATRON_CARD_INACTIVE' ) {
663 alertId('patron_card_inactive_alert');
667 if( auth_result.textcode == 'LOGIN_FAILED' ||
668 auth_result.textcode == 'PERM_FAILURE' ) {
669 alertId('patron_login_failed');
675 AUTHTIME = parseInt(auth_result.payload.authtime);
676 var u = grabUser(auth_result.payload.authtoken, true);
677 if(u && ! suppressEvents)
678 runEvt( "common", "locationChanged", u.ws_ou(), findOrgDepth(u.ws_ou()) );
685 function doLogout(noredirect) {
687 /* cancel everything else */
690 /* be nice and delete the session from the server */
691 if(G.user && G.user.session) {
692 var req = new Request(LOGIN_DELETE, G.user.session);
694 try { req.result(); } catch(E){}
699 /* remove any cached data */
700 //cookieManager.remove(COOKIE_IDS);
701 //cookieManager.remove(COOKIE_SRIDS);
702 cookieManager.remove(COOKIE_RIDS);
703 cookieManager.remove(COOKIE_SES);
704 cookieManager.remove(COOKIE_SKIN);
706 checkUserSkin("default");
711 args[PARAM_TERM] = "";
712 args[PARAM_LOCATION] = getOrigLocation();
713 args[PARAM_DEPTH] = findOrgDepth(getOrigLocation());
718 try{ if(isFrontPage) nored = true; } catch(e){nored = false;}
719 if(!nored) goTo(buildOPACLink(args));
723 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
724 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
727 /* ----------------------------------------------------------------------- */
728 /* build the org tree */
729 /* ----------------------------------------------------------------------- */
730 function drawOrgTree() {
731 //setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 10 );
732 setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 1 );
736 function buildOrgSelector(node) {
737 var tree = new SlimTree(node,'orgTreeSelector');
738 orgTreeSelector = tree;
739 for( var i in orgArraySearcher ) {
740 var node = orgArraySearcher[i];
741 if( node == null ) continue;
742 if(node.parent_ou() == null)
743 tree.addNode(node.id(), -1, node.name(),
744 "javascript:orgSelect(" + node.id() + ");", node.name());
746 tree.addNode(node.id(), node.parent_ou(), node.name(),
747 "javascript:orgSelect(" + node.id() + ");", node.name());
750 hideMe($('org_loading_div'));
751 unHideMe($('org_selector_tip'));
755 function orgSelect(id) {
757 runEvt("common", "locationChanged", id, findOrgDepth(id) );
759 removeChildren(G.ui.common.now_searching);
760 G.ui.common.now_searching.appendChild(text(findOrgUnit(id).name()));
763 function setFontSize(size) {
765 cookieManager.write(COOKIE_FONT, size, '+1y');
769 var resourceFormats = [
772 "sound recording", "software, multimedia",
777 "three dimensional object" ];
780 function modsFormatToMARC(format) {
786 case "sound recording":
788 case "sound recording-nonmusical":
790 case "sound recording-musical":
792 case "software, multimedia":
798 case "mixed material":
800 case "notated music":
802 case "three dimensional object":
809 function MARCFormatToMods(format) {
815 return "moving image";
817 return "sound recording-nonmusical";
819 return "sound recording-musical";
821 return "software, multimedia";
823 return "still images";
826 return "cartographic";
829 return "mixed material";
832 return "notated music";
834 return "three dimensional object";
839 function MARCTypeToFriendly(format) {
840 var words = $('format_words');
843 case 't' : return $n(words, 'at').innerHTML;
845 var node = $n(words,format);
846 if( node ) return node.innerHTML;
851 function setResourcePic( img, resource ) {
852 img.setAttribute( "src", "../../../../images/tor/" + resource + ".jpg");
853 img.title = resource;
858 function msg( text ) {
859 try { alert( text ); } catch(e) {}
862 function findRecord(id,type) {
864 for( var i = 0; i != recordsCache.length; i++ ) {
865 var rec = recordsCache[i];
866 if( rec && rec.doc_id() == id ) return rec;
869 var meth = FETCH_RMODS
870 if(type == 'M') meth = FETCH_MRMODS;
871 var req = new Request(meth, id);
872 req.request.alertEvent = false;
874 var res = req.result();
875 if( checkILSEvent(res) ) return null;
879 function Timer(name, node){
884 Timer.prototype.start =
885 function(){_timerRun(this.name);}
886 Timer.prototype.stop =
887 function(){this.done = true;}
888 function _timerRun(tname) {
892 if(_t.count > 100) return;
894 if( (_t.count % 5) == 0 )
896 _t.node.appendChild(text(str));
897 setTimeout("_timerRun('"+tname+"');", 200);
901 function checkILSEvent(obj) {
902 if( obj && obj.ilsevent != null && obj.ilsevent != 0 )
903 return parseInt(obj.ilsevent);
908 function alertILSEvent(evt, msg) {
911 alert(msg +'\n' + evt.textcode + '\n' + evt.desc );
913 alert(evt.textcode + '\n' + evt.desc );
918 function AuthTimer(time) {
919 this.time = (time - LOGOUT_WARNING_TIME) * 1000;
921 try {clearTimeout(__authTimer.id)} catch(e){}
925 AuthTimer.prototype.run = function() {
926 this.id = setTimeout('_authTimerAlert()', this.time);
929 function _authTimerAlert() {
930 alert( $('auth_session_expiring').innerHTML );
931 if(!grabUser(null, true)) doLogout();
935 function grabUserByBarcode( authtoken, barcode ) {
936 var req = new Request( FETCH_USER_BYBARCODE, authtoken, barcode );
943 goTo(buildOPACLink({page:HOME}));
947 function buildOrgSel(selector, org, offset) {
948 insertSelectorVal( selector, -1,
949 org.name(), org.id(), null, findOrgDepth(org) - offset );
950 for( var c in org.children() )
951 buildOrgSel( selector, org.children()[c], offset);
955 function parseForm(form) {
958 var it = form.replace(/-\w+$/,"");
963 if(form.match(/-/)) itf = form.replace(/^\w+-/,"");
967 for( var i = 0; i < it.length; i++ )
968 item_type.push( it.charAt(i) );
973 for( var i = 0; i < itf.length; i++ )
974 item_form.push( itf.charAt(i) );
977 return {item_type: item_type, item_form:item_form};
981 function isTrue(x) { return ( x && x != "0" && !(x+'').match(/^f$/i) ); }
983 function fetchPermOrgs() {
984 var a = []; /* why does arguments come accross as an object and not an array? */
985 for( var i = 0; i < arguments.length; i++ )
988 var preq = new Request(FETCH_HIGHEST_PERM_ORG,
989 G.user.session, G.user.id(), a );
991 return preq.result();
995 function print_tabs(t) {
997 for (var j = 0; j < t; j++ ) { r = r + " "; }
1000 function formatJSON(s) {
1001 var r = ''; var t = 0;
1003 if (s[i] == '{' || s[i] == '[' ) {
1004 r = r + s[i] + "\n" + print_tabs(++t);
1005 } else if (s[i] == '}' || s[i] == ']') {
1006 t--; r = r + "\n" + print_tabs(t) + s[i];
1007 } else if (s[i] == ',') {
1008 r = r + s[i] + "\n" + print_tabs(t);