2 function cleanIEMemory() {
6 var a = [ "a", "div", "span", "select", "option", "img", "body", "iframe", "frame"];
7 for( var index in a ) {
8 var nodes = getDocument().getElementsByTagName(a[index]);
9 var nodes2 = document.getElementsByTagName(a[index]);
11 for( var n = 0; n!= nodes.length; n++ ) {
16 node.oncontextmenu = null;
19 for( var n = 0; n!= nodes2.length; n++ ) {
24 node.oncontextmenu = null;
31 globalMenuManager = null;
34 window.CollectGarbage();
35 getWindow().CollectGarbage();
44 function hideMe(obj) {
46 //remove_css_class( obj, "show_me");
47 //add_css_class( obj, "hide_me");
48 obj.style.visibility = "hidden";
49 obj.style.display = "none";
52 function showMe(obj) {
54 //remove_css_class( obj, "hide_me");
55 //add_css_class( obj, "show_me");
56 obj.style.visibility = "visible";
57 obj.style.display = "block";
62 function grabCharCode(evt) {
63 evt = (evt) ? evt : ((window.event) ? event : null); /* for mozilla and IE */
65 return (evt.charCode ? evt.charCode :
66 ((evt.which) ? evt.which : evt.keyCode ));
72 function getById(id) {
74 var obj = document.getElementById(id);
75 if(obj != null) return obj;
79 obj = globalAppFrame.document.getElementById(id);
82 debug(" + + + getById() for " + id + " failed and we have no app frame...: " + E);
88 function createAppElement(name) {
91 return globalAppFrame.document.createElement(name);
93 return document.createElement(name);
97 function createAppTextNode(text) {
100 return globalAppFrame.document.createTextNode(text);
102 return document.createTextNode(text);
106 function mktext(text) { return createAppTextNode(text); }
110 /* split on spaces. capitalize the first /\w/ character in
112 function normalize(val) {
117 try {val = val.split(' ');} catch(E) {return val;}
120 for( var c = 0; c < val.length; c++) {
124 for(var x = 0; x != string.length; x++) {
127 var ch = string.charAt(x);
128 if(reg.exec(ch + "")) {
129 newVal += string.charAt(x).toUpperCase();
135 newVal += string.charAt(x).toLowerCase();
137 if(c < (val.length-1)) newVal += " ";
140 newVal = newVal.replace(/\s*\.\s*$/,'');
141 newVal = newVal.replace(/\s*\/\s*\/\s*$/,' / ');
142 newVal = newVal.replace(/\s*\/\s*$/,'');
152 if(reg.exec(navigator.userAgent))
156 var WIN_DEBUG = false;
160 function debug(message) {
163 dump(" -|*|- Debug: " + message + "\n");
168 debugWindow = window.open(null,"Debug",
169 "location=0,menubar=0,status=0,resizeable,resize," +
170 "outerHeight=900,outerWidth=700,height=900," +
171 "width=700,scrollbars=1,screenX=100," +
172 "screenY=100,top=100,left=100,alwaysraised" )
174 debugWindow.document.write("<br/>" + message);
179 /* finds or builds the requested row id, adding any intermediate rows along the way */
180 function table_row_find_or_create( table, index ) {
182 if(table == null || index == null || index < 0 || index > 10000 ) {
183 throw "table_row_find_or_create with invalid " +
184 "params. table: " + table + " index: " + index + "\n";
187 var tbody = table.getElementsByTagName("tbody")[0];
190 tbody = table.appendChild(createAppElement("tbody"));
193 if(table.rows[index] != null)
194 return table.rows[index];
197 for( var x = 0; x <= index; x++ ) {
198 if(table.rows[x] == null) {
199 row = tbody.appendChild(createAppElement("tr"));
205 /* finds or builds the requested cell, adding any intermediate cells along the way */
206 function table_cell_find_or_create( row, index ) {
208 if(row == null || index == null || index < 0 || index > 10000 ) {
209 throw "table_cell_find_or_create with invalid " +
210 "params. row: " + row + " index: " + index + "\n";
213 if(row.cells[index] != null)
214 return row.cells[index];
216 for( var x = 0; x!= index; x++ ) {
217 if(row.cells[x] == null)
221 return row.insertCell(index);
226 // -----------------------------------------------------------------------
227 // Generic cookie libarary copied from
228 // http://webreference.com/js/column8/functions.html
229 // -----------------------------------------------------------------------
232 name - name of the cookie
233 value - value of the cookie
234 [expires] - expiration date of the cookie
235 (defaults to end of current session)
236 [path] - path for which the cookie is valid
237 (defaults to path of calling document)
238 [domain] - domain for which the cookie is valid
239 (defaults to domain of calling document)
240 [secure] - Boolean value indicating if the cookie transmission requires
241 a secure transmission
242 * an argument defaults when it is assigned null as a placeholder
243 * a null placeholder is not required for trailing omitted arguments
246 function setCookie(name, value, expires, path, domain, secure) {
247 var curCookie = name + "=" + escape(value) +
248 ((expires) ? "; expires=" + expires.toGMTString() : "") +
249 ((path) ? "; path=" + path : "") +
250 ((domain) ? "; domain=" + domain : "") +
251 ((secure) ? "; secure" : "");
252 document.cookie = curCookie;
257 name - name of the desired cookie
258 return string containing value of specified cookie or null
259 if cookie does not exist
262 function getCookie(name) {
263 var dc = document.cookie;
264 var prefix = name + "=";
265 var begin = dc.indexOf("; " + prefix);
267 begin = dc.indexOf(prefix);
268 if (begin != 0) return null;
273 var end = document.cookie.indexOf(";", begin);
274 if (end == -1) end = dc.length;
275 return unescape(dc.substring(begin + prefix.length, end));
280 name - name of the cookie
281 [path] - path of the cookie (must be same as path used to create cookie)
282 [domain] - domain of the cookie (must be same as domain used to
284 path and domain default if assigned null or omitted if no explicit
288 function deleteCookie(name, path, domain) {
289 if (getCookie(name)) {
290 var string = name + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
291 debug("Delete cookie string: "+ string );
292 document.cookie = string;
293 debug("Delete Cookie: " + document.cookie );
295 document.cookie = name + "=" +
296 ((path) ? "; path=" + path : "") +
297 ((domain) ? "; domain=" + domain : "") +
298 "; expires=Thu, 01-Jan-70 00:00:01 GMT";
303 // date - any instance of the Date object
304 // * hand all instances of the Date object to this function for "repairs"
306 function fixDate(date) {
307 var base = new Date(0);
308 var skew = base.getTime();
310 date.setTime(date.getTime() - skew);
313 // -----------------------------------------------------------------------
315 var globalProgressBar = null;
316 function ProgressBar( div, color, interval ) {
318 this.progressEnd = 9;
321 this.progressColor = color;
323 this.progressColor = 'blue';
326 this.progressInterval = interval;
328 this.progressInterval = 50;
330 this.progressAt = this.progressEnd;
333 for( var x = 0; x!= this.progressEnd; x++ ) {
334 var newdiv = createAppElement("span");
335 newdiv.id = "progress" + x;
336 newdiv.appendChild(document.createTextNode(" "));
337 div.appendChild(newdiv);
339 globalProgressBar = this;
342 ProgressBar.prototype.progressStart = function() {
343 this.progressUpdate();
346 ProgressBar.prototype.progressClear = function() {
347 for (var i = 0; i < this.progressEnd; i++) {
348 getById('progress' + i).style.backgroundColor = 'transparent';
353 ProgressBar.prototype.progressUpdate = function() {
354 debug(" -3-3-3-3- Updating Progress Bar");
356 if (this.progressAt > this.progressEnd)
357 this.progressClear();
359 getById('progress'+progressAt).style.backgroundColor = this.progressColor;
360 this.progressTimer = setTimeout('globalProgressBar.progressUpdate()', this.progressInterval);
361 debug("Timer is set at " + this.progressInterval);
364 ProgressBar.prototype.progressStop = function() {
365 clearTimeout(this.progressTimer);
366 this.progressClear();
369 function add_css_class(w,c) {
371 if (typeof(w) == 'object') {
378 var css_class_string = e.className;
382 css_class_array = css_class_string.split(/\s+/);
384 var string_ip = ""; /*strip out nulls*/
385 for (var css_class in css_class_array) {
386 if (css_class_array[css_class] == c) { return; }
387 if(css_class_array[css_class] !=null)
388 string_ip += css_class_array[css_class] + " ";
390 string_ip = string_ip + c;
391 e.className = string_ip;
394 function remove_css_class(w,c) {
399 if (typeof(w) == 'object') {
405 var css_class_string = '';
407 var css_class_array = e.className;
408 if( css_class_array )
409 css_class_array = css_class_array.split(/\s+/);
412 for (var css_class in css_class_array) {
413 if (css_class_array[css_class] != c) {
415 css_class_string = css_class_array[css_class];
418 css_class_string = css_class_string + ' ' +
419 css_class_array[css_class];
423 e.className = css_class_string;
429 /* takes an array of the form [ key, value, key, value, ..] and
430 redirects the page to the current host/path plus the key
433 function url_redirect(key_value_array) {
435 if( key_value_array == null ||
436 (key_value_array.length %2)) {
438 "AdvancedSearchPage.redirect has invalid args" );
441 var fullpath = globalRootPath;
444 debug("Redirecting...");
446 for( var x = 0; x!= key_value_array.length; x++ ) {
448 fullpath += "?" + encodeURIComponent(key_value_array[x]);
451 fullpath += "&" + encodeURIComponent(key_value_array[x]);
453 fullpath += "=" + encodeURIComponent(key_value_array[x]);
457 debug("Redirecting to " + fullpath );
458 globalAppFrame.location.href = fullpath;
465 the paramObj contains cgi params as object attributes
466 -> paramObj.__paramName
467 paramName is the name of the parameter. the '__' is there to
468 differentiate the paramName from other object attributes.
470 function build_param_array() {
471 var paramArray = new Array();
472 for( var p in paramObj ) {
473 if( p.substr(0,2) == "__" ) {
474 var name = p.substr(2,p.length - 1);
475 paramArray.push(name)
476 paramArray.push(paramObj[p])
483 var evtCache = new Object();
484 function EventListener(bool_callback, done_callback, name, usr_object) {
485 this.bool_callback = bool_callback;
486 this.done_callback = done_callback;
488 this.obj = usr_object;
489 this.complete = false;
490 evtCache["___" + name] = this;
494 //EventListener.prototype.poll = function() {
495 function eventPoll(name) {
496 var obj = evtCache["___" + name];
498 throw "No Listener by that name";
500 obj.complete = obj.bool_callback(obj.obj);
502 obj.done_callback(obj.obj);
504 debug("Setting timeout for next poll..");
505 setTimeout("eventPoll('" + name + "')", obj.interval );
512 function swapClass(obj, class1, class2 ) {
513 if(obj == null) return;
514 if( obj.className.indexOf(class1) != -1 ) {
515 remove_css_class(obj, class1);
516 add_css_class(obj,class2);
518 remove_css_class(obj, class2);
519 add_css_class(obj,class1);
528 function findPosX(obj)
531 if (obj.offsetParent)
533 while (obj.offsetParent)
535 curleft += obj.offsetLeft
536 obj = obj.offsetParent;
544 function findPosY(obj) {
547 if (obj.offsetParent) {
548 while (obj.offsetParent) {
549 curtop += obj.offsetTop
550 obj = obj.offsetParent;
562 function getObjectHeight(obj) {
565 if (elem.offsetHeight) {
566 result = elem.offsetHeight;
567 } else if (elem.clip && elem.clip.height) {
568 result = elem.clip.height;
569 } else if (elem.style && elem.style.pixelHeight) {
570 result = elem.style.pixelHeight;
572 return parseInt(result);
576 function getObjectWidth(obj) {
579 if (elem.offsetWidth) {
580 result = elem.offsetWidth;
581 } else if (elem.clip && elem.clip.width) {
582 result = elem.clip.width;
583 } else if (elem.style && elem.style.pixelWidth) {
584 result = elem.style.pixelWidth;
586 return parseInt(result);
591 function getAppWindow() {
593 return globalAppFrame.window;
597 function getDocument() {
599 return globalAppFrame.document;
603 function getWindow() {
605 return globalAppFrame;
609 /* returns [x, y] coords of the mouse */
610 function getMousePos(e) {
614 if (!e) e = getAppWindow().event;
615 if (e.pageX || e.pageY) {
619 else if (e.clientX || e.clientY) {
620 posx = e.clientX + getDocument().body.scrollLeft;
621 posy = e.clientY + getDocument().body.scrollTop;
624 return [ posx, posy ];
627 function buildFunction(string) {
628 return eval("new Function(" + string + ")");
632 function instanceOf(object, constructorFunction) {
635 while (object != null) {
636 if (object == constructorFunction.prototype)
638 object = object.__proto__;
641 while(object != null) {
642 if( object instanceof constructorFunction )
644 object = object.__proto__;
651 /* builds any element */
652 function elem(name, attrs, style, text) {
653 var e = createAppElement(name);
656 if (key == 'class') {
657 e.className = attrs[key];
658 } else if (key == 'id') {
661 e.setAttribute(key, attrs[key]);
667 e.style[key] = style[key];
671 e.appendChild(createAppTextNode(text));
676 function filter_list(list,f) {
678 for (var i in list) {
679 var t = f( list[i] );
680 if (t) new_list.push( list[i] );
685 function find_list(list,f) {
686 for (var i in list) {
687 var t = f( list[i] );
688 if (t) return list[i];
693 function removeChildren(node) {
694 if(typeof node == 'object' && node != null) {
695 while(node.childNodes[0])
696 node.removeChild(node.childNodes[0]);
703 function userMessage(msg) {
704 alert("An unknown error occured during the following process: " + msg);
709 /* returns [ xoffset, yoffset ] of the target node
710 object (if provided) is used as the box that will be displayed */
711 function getXYOffsets(target, object) {
713 var x = findPosX(target);
714 var y = findPosY(target);
715 var height = getObjectHeight(target);
719 xpos = x - getObjectWidth(object) + getObjectWidth(target);
722 var offsety = y + height;
725 if(IE) offsety += 15;
727 debug("getXYOffset y: " + offsety + " x: " + offsetx );
728 return [offsetx, offsety];
734 /* returns true if the user pressed enter */
735 function userPressedEnter(evt) {
736 var code = grabCharCode(evt);
737 if(code==13||code==3) return true;
742 /* return [ x, y ] for the window */
743 function getWindowSize() {
745 var doc = getDocument();
746 var win = getWindow();
751 if(doc.documentElement.offsetWidth != null) { /* IE 6 standards compliant */
752 x = doc.documentElement.offsetWidth;
753 y = doc.documentElement.offsetHeight;
756 x = doc.body.offsetWidth;
757 y = doc.body.offsetHeight;