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));
453 /* ----------------------------------------------------------------------- */
454 /* user session handling */
455 /* ----------------------------------------------------------------------- */
456 /* session is the login session. If no session is provided, we attempt
457 to find one in the cookies. If 'force' is true we retrieve the
458 user from the server even if there is already a global user present.
459 if ses != G.user.session, we also force a grab */
460 function grabUser(ses, force) {
462 if(!ses && isXUL()) ses = xulG['authtoken'];
465 ses = cookieManager.read(COOKIE_SES);
466 /* https cookies don't show up in http servers.. */
469 if(!ses) return false;
472 if(G.user && G.user.session == ses)
475 /* first make sure the session is valid */
476 var request = new Request(FETCH_SESSION, ses, 1 );
477 request.request.alertEvent = false;
479 var user = request.result();
483 return false; /* unable to grab the session */
486 if( !(typeof user == 'object' && user._isfieldmapper) ) {
492 G.user.fleshed = false;
493 G.user.session = ses;
494 cookieManager.write(COOKIE_SES, ses, -1);
497 if(G.user.prefs['opac.hits_per_page'])
498 COUNT = parseInt(G.user.prefs['opac.hits_per_page']);
500 if(G.user.prefs[PREF_DEF_FONT])
501 setFontSize(G.user.prefs[PREF_DEF_FONT]);
503 var at = getAuthtime();
504 //if(isXUL()) at = xulG['authtime'];
506 if(at && !isXUL()) new AuthTimer(at).run();
511 /* sets the 'prefs' field of the user object to their preferences
512 and returns the preferences */
513 function grabUserPrefs(user, force) {
514 if(user == null) user = G.user;
515 if(!force && user.prefs) return user.prefs;
516 var req = new Request(FETCH_USER_PREFS, user.session, user.id());
518 user.prefs = req.result();
522 function grabFleshedUser() {
524 if(!G.user || !G.user.session) {
526 if(!G.user || !G.user.session) return null;
529 if(G.user.fleshed) return G.user;
531 var req = new Request(FETCH_FLESHED_USER, G.user.session);
534 G.user = req.result();
536 if(!G.user || G.user.length == 0) {
537 G.user = null; return false;
538 cookieManager.write(COOKIE_SES,"");
541 G.user.session = ses;
542 G.user.fleshed = true;
544 cookieManager.write(COOKIE_SES, ses, '+1y'); /* update the cookie */
548 function checkUserSkin(new_skin) {
550 return; /* XXX do some debugging with this... */
552 var user_skin = getSkin();
553 var cur_skin = grabSkinFromURL();
555 if(new_skin) user_skin = new_skin;
560 if(grabUserPrefs()) {
561 user_skin = G.user.prefs["opac.skin"];
562 cookieManager.write( COOKIE_SKIN, user_skin, '+1y' );
567 if(!user_skin) return;
569 if( cur_skin != user_skin ) {
570 var url = buildOPACLink();
571 goTo(url.replace(cur_skin, user_skin));
575 function updateUserSetting(setting, value, user) {
576 if(user == null) user = G.user;
579 var req = new Request( UPDATE_USER_PREFS, user.session, a );
584 function commitUserPrefs() {
585 var req = new Request(
586 UPDATE_USER_PREFS, G.user.session, null, G.user.prefs );
591 function grabSkinFromURL() {
592 var path = findBasePath();
593 path = path.replace("/xml/", "");
595 for( var i = path.length - 1; i >= 0; i-- ) {
596 var ch = path.charAt(i);
602 for( i = skin.length - 1; i >= 0; i--)
603 skin2 += skin.charAt(i);
609 /* returns a fleshed G.user on success, false on failure */
610 function doLogin(suppressEvents) {
614 var uname = G.ui.login.username.value;
615 var passwd = G.ui.login.password.value;
617 var init_request = new Request( LOGIN_INIT, uname );
618 init_request.send(true);
619 var seed = init_request.result();
621 if( ! seed || seed == '0') {
622 alert( "Error Communicating with Authentication Server" );
627 password : hex_md5(seed + hex_md5(passwd)),
629 org : getOrigLocation()
632 if( uname.match(REGEX_BARCODE) ) args.barcode = uname; /* make this better */
633 else args.username = uname;
635 var auth_request = new Request( LOGIN_COMPLETE, args );
637 auth_request.request.alertEvent = false;
638 auth_request.send(true);
639 var auth_result = auth_request.result();
642 alertId('patron_login_failed');
646 if( checkILSEvent(auth_result) ) {
648 if( auth_result.textcode == 'PATRON_INACTIVE' ) {
649 alertId('patron_inactive_alert');
653 if( auth_result.textcode == 'PATRON_CARD_INACTIVE' ) {
654 alertId('patron_card_inactive_alert');
658 if( auth_result.textcode == 'LOGIN_FAILED' ||
659 auth_result.textcode == 'PERM_FAILURE' ) {
660 alertId('patron_login_failed');
666 AUTHTIME = parseInt(auth_result.payload.authtime);
667 var u = grabUser(auth_result.payload.authtoken, true);
668 if(u && ! suppressEvents)
669 runEvt( "common", "locationChanged", u.ws_ou(), findOrgDepth(u.ws_ou()) );
676 function doLogout(noredirect) {
678 /* cancel everything else */
681 /* be nice and delete the session from the server */
682 if(G.user && G.user.session) {
683 var req = new Request(LOGIN_DELETE, G.user.session);
685 try { req.result(); } catch(E){}
690 /* remove any cached data */
691 //cookieManager.remove(COOKIE_IDS);
692 //cookieManager.remove(COOKIE_SRIDS);
693 cookieManager.remove(COOKIE_RIDS);
694 cookieManager.remove(COOKIE_SES);
695 cookieManager.remove(COOKIE_SKIN);
697 checkUserSkin("default");
702 args[PARAM_TERM] = "";
703 args[PARAM_LOCATION] = getOrigLocation();
704 args[PARAM_DEPTH] = findOrgDepth(getOrigLocation());
709 try{ if(isFrontPage) nored = true; } catch(e){nored = false;}
710 if(!nored) goTo(buildOPACLink(args));
714 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
715 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
718 /* ----------------------------------------------------------------------- */
719 /* build the org tree */
720 /* ----------------------------------------------------------------------- */
721 function drawOrgTree() {
722 //setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 10 );
723 setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 1 );
727 function buildOrgSelector(node) {
728 var tree = new SlimTree(node,'orgTreeSelector');
729 orgTreeSelector = tree;
730 for( var i in orgArraySearcher ) {
731 var node = orgArraySearcher[i];
732 if( node == null ) continue;
733 if(node.parent_ou() == null)
734 tree.addNode(node.id(), -1, node.name(),
735 "javascript:orgSelect(" + node.id() + ");", node.name());
737 tree.addNode(node.id(), node.parent_ou(), node.name(),
738 "javascript:orgSelect(" + node.id() + ");", node.name());
741 hideMe($('org_loading_div'));
742 unHideMe($('org_selector_tip'));
746 function orgSelect(id) {
748 runEvt("common", "locationChanged", id, findOrgDepth(id) );
750 removeChildren(G.ui.common.now_searching);
751 G.ui.common.now_searching.appendChild(text(findOrgUnit(id).name()));
754 function setFontSize(size) {
756 cookieManager.write(COOKIE_FONT, size, '+1y');
760 var resourceFormats = [
763 "sound recording", "software, multimedia",
768 "three dimensional object" ];
771 function modsFormatToMARC(format) {
777 case "sound recording":
779 case "sound recording-nonmusical":
781 case "sound recording-musical":
783 case "software, multimedia":
789 case "mixed material":
791 case "notated music":
793 case "three dimensional object":
800 function MARCFormatToMods(format) {
806 return "moving image";
808 return "sound recording-nonmusical";
810 return "sound recording-musical";
812 return "software, multimedia";
814 return "still images";
817 return "cartographic";
820 return "mixed material";
823 return "notated music";
825 return "three dimensional object";
830 function MARCTypeToFriendly(format) {
831 var words = $('format_words');
834 case 't' : return $n(words, 'at').innerHTML;
836 var node = $n(words,format);
837 if( node ) return node.innerHTML;
842 function setResourcePic( img, resource ) {
843 img.setAttribute( "src", "../../../../images/tor/" + resource + ".jpg");
844 img.title = resource;
849 function msg( text ) {
850 try { alert( text ); } catch(e) {}
853 function findRecord(id,type) {
855 for( var i = 0; i != recordsCache.length; i++ ) {
856 var rec = recordsCache[i];
857 if( rec && rec.doc_id() == id ) return rec;
860 var meth = FETCH_RMODS
861 if(type == 'M') meth = FETCH_MRMODS;
862 var req = new Request(meth, id);
863 req.request.alertEvent = false;
865 var res = req.result();
866 if( checkILSEvent(res) ) return null;
870 function Timer(name, node){
875 Timer.prototype.start =
876 function(){_timerRun(this.name);}
877 Timer.prototype.stop =
878 function(){this.done = true;}
879 function _timerRun(tname) {
883 if(_t.count > 100) return;
885 if( (_t.count % 5) == 0 )
887 _t.node.appendChild(text(str));
888 setTimeout("_timerRun('"+tname+"');", 200);
892 function checkILSEvent(obj) {
893 if( obj && obj.ilsevent != null && obj.ilsevent != 0 )
894 return parseInt(obj.ilsevent);
899 function alertILSEvent(evt, msg) {
902 alert(msg +'\n' + evt.textcode + '\n' + evt.desc );
904 alert(evt.textcode + '\n' + evt.desc );
909 function AuthTimer(time) {
910 this.time = (time - LOGOUT_WARNING_TIME) * 1000;
912 try {clearTimeout(__authTimer.id)} catch(e){}
916 AuthTimer.prototype.run = function() {
917 this.id = setTimeout('_authTimerAlert()', this.time);
920 function _authTimerAlert() {
921 alert( $('auth_session_expiring').innerHTML );
922 if(!grabUser(null, true)) doLogout();
926 function grabUserByBarcode( authtoken, barcode ) {
927 var req = new Request( FETCH_USER_BYBARCODE, authtoken, barcode );
934 goTo(buildOPACLink({page:HOME}));
938 function buildOrgSel(selector, org, offset) {
939 insertSelectorVal( selector, -1,
940 org.name(), org.id(), null, findOrgDepth(org) - offset );
941 for( var c in org.children() )
942 buildOrgSel( selector, org.children()[c], offset);
946 function parseForm(form) {
949 var it = form.replace(/-\w+$/,"");
954 if(form.match(/-/)) itf = form.replace(/^\w+-/,"");
958 for( var i = 0; i < it.length; i++ )
959 item_type.push( it.charAt(i) );
964 for( var i = 0; i < itf.length; i++ )
965 item_form.push( itf.charAt(i) );
968 return {item_type: item_type, item_form:item_form};
972 function isTrue(x) { return ( x && x != "0" && !(x+'').match(/^f$/i) ); }
974 function fetchPermOrgs() {
975 var a = []; /* why does arguments come accross as an object and not an array? */
976 for( var i = 0; i < arguments.length; i++ )
979 var preq = new Request(FETCH_HIGHEST_PERM_ORG,
980 G.user.session, G.user.id(), a );
982 return preq.result();
986 function print_tabs(t) {
988 for (var j = 0; j < t; j++ ) { r = r + " "; }
991 function formatJSON(s) {
992 var r = ''; var t = 0;
994 if (s[i] == '{' || s[i] == '[' ) {
995 r = r + s[i] + "\n" + print_tabs(++t);
996 } else if (s[i] == '}' || s[i] == ']') {
997 t--; r = r + "\n" + print_tabs(t) + s[i];
998 } else if (s[i] == ',') {
999 r = r + s[i] + "\n" + print_tabs(t);