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);
108 /* split on spaces. capitalize the first /\w/ character in
110 function normalize(val) {
115 try {val = val.split(' ');} catch(E) {return val;}
118 for( var c = 0; c < val.length; c++) {
122 for(var x = 0; x != string.length; x++) {
125 var ch = string.charAt(x);
126 if(reg.exec(ch + "")) {
127 newVal += string.charAt(x).toUpperCase();
133 newVal += string.charAt(x).toLowerCase();
135 if(c < (val.length-1)) newVal += " ";
138 newVal = newVal.replace(/\s*\.\s*$/,'');
139 newVal = newVal.replace(/\s*\/\s*\/\s*$/,' / ');
140 newVal = newVal.replace(/\s*\/\s*$/,'');
150 if(reg.exec(navigator.userAgent))
154 var WIN_DEBUG = false;
158 function debug(message) {
161 dump(" -|*|- Debug: " + message + "\n");
166 debugWindow = window.open(null,"Debug",
167 "location=0,menubar=0,status=0,resizeable,resize," +
168 "outerHeight=900,outerWidth=700,height=900," +
169 "width=700,scrollbars=1,screenX=100," +
170 "screenY=100,top=100,left=100,alwaysraised" )
172 debugWindow.document.write("<br/>" + message);
177 /* finds or builds the requested row id, adding any intermediate rows along the way */
178 function table_row_find_or_create( table, index ) {
180 if(table == null || index == null || index < 0 || index > 10000 ) {
181 throw "table_row_find_or_create with invalid " +
182 "params. table: " + table + " index: " + index + "\n";
185 var tbody = table.getElementsByTagName("tbody")[0];
188 tbody = table.appendChild(createAppElement("tbody"));
191 if(table.rows[index] != null)
192 return table.rows[index];
195 for( var x = 0; x <= index; x++ ) {
196 if(table.rows[x] == null) {
197 row = tbody.appendChild(createAppElement("tr"));
203 /* finds or builds the requested cell, adding any intermediate cells along the way */
204 function table_cell_find_or_create( row, index ) {
206 if(row == null || index == null || index < 0 || index > 10000 ) {
207 throw "table_cell_find_or_create with invalid " +
208 "params. row: " + row + " index: " + index + "\n";
211 if(row.cells[index] != null)
212 return row.cells[index];
214 for( var x = 0; x!= index; x++ ) {
215 if(row.cells[x] == null)
219 return row.insertCell(index);
224 // -----------------------------------------------------------------------
225 // Generic cookie libarary copied from
226 // http://webreference.com/js/column8/functions.html
227 // -----------------------------------------------------------------------
230 name - name of the cookie
231 value - value of the cookie
232 [expires] - expiration date of the cookie
233 (defaults to end of current session)
234 [path] - path for which the cookie is valid
235 (defaults to path of calling document)
236 [domain] - domain for which the cookie is valid
237 (defaults to domain of calling document)
238 [secure] - Boolean value indicating if the cookie transmission requires
239 a secure transmission
240 * an argument defaults when it is assigned null as a placeholder
241 * a null placeholder is not required for trailing omitted arguments
244 function setCookie(name, value, expires, path, domain, secure) {
245 var curCookie = name + "=" + escape(value) +
246 ((expires) ? "; expires=" + expires.toGMTString() : "") +
247 ((path) ? "; path=" + path : "") +
248 ((domain) ? "; domain=" + domain : "") +
249 ((secure) ? "; secure" : "");
250 document.cookie = curCookie;
255 name - name of the desired cookie
256 return string containing value of specified cookie or null
257 if cookie does not exist
260 function getCookie(name) {
261 var dc = document.cookie;
262 var prefix = name + "=";
263 var begin = dc.indexOf("; " + prefix);
265 begin = dc.indexOf(prefix);
266 if (begin != 0) return null;
271 var end = document.cookie.indexOf(";", begin);
272 if (end == -1) end = dc.length;
273 return unescape(dc.substring(begin + prefix.length, end));
278 name - name of the cookie
279 [path] - path of the cookie (must be same as path used to create cookie)
280 [domain] - domain of the cookie (must be same as domain used to
282 path and domain default if assigned null or omitted if no explicit
286 function deleteCookie(name, path, domain) {
287 if (getCookie(name)) {
288 var string = name + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
289 debug("Delete cookie string: "+ string );
290 document.cookie = string;
291 debug("Delete Cookie: " + document.cookie );
293 document.cookie = name + "=" +
294 ((path) ? "; path=" + path : "") +
295 ((domain) ? "; domain=" + domain : "") +
296 "; expires=Thu, 01-Jan-70 00:00:01 GMT";
301 // date - any instance of the Date object
302 // * hand all instances of the Date object to this function for "repairs"
304 function fixDate(date) {
305 var base = new Date(0);
306 var skew = base.getTime();
308 date.setTime(date.getTime() - skew);
311 // -----------------------------------------------------------------------
313 var globalProgressBar = null;
314 function ProgressBar( div, color, interval ) {
316 this.progressEnd = 9;
319 this.progressColor = color;
321 this.progressColor = 'blue';
324 this.progressInterval = interval;
326 this.progressInterval = 50;
328 this.progressAt = this.progressEnd;
331 for( var x = 0; x!= this.progressEnd; x++ ) {
332 var newdiv = createAppElement("span");
333 newdiv.id = "progress" + x;
334 newdiv.appendChild(document.createTextNode(" "));
335 div.appendChild(newdiv);
337 globalProgressBar = this;
340 ProgressBar.prototype.progressStart = function() {
341 this.progressUpdate();
344 ProgressBar.prototype.progressClear = function() {
345 for (var i = 0; i < this.progressEnd; i++) {
346 getById('progress' + i).style.backgroundColor = 'transparent';
351 ProgressBar.prototype.progressUpdate = function() {
352 debug(" -3-3-3-3- Updating Progress Bar");
354 if (this.progressAt > this.progressEnd)
355 this.progressClear();
357 getById('progress'+progressAt).style.backgroundColor = this.progressColor;
358 this.progressTimer = setTimeout('globalProgressBar.progressUpdate()', this.progressInterval);
359 debug("Timer is set at " + this.progressInterval);
362 ProgressBar.prototype.progressStop = function() {
363 clearTimeout(this.progressTimer);
364 this.progressClear();
367 function add_css_class(w,c) {
369 if (typeof(w) == 'object') {
376 var css_class_string = e.className;
380 css_class_array = css_class_string.split(/\s+/);
382 var string_ip = ""; /*strip out nulls*/
383 for (var css_class in css_class_array) {
384 if (css_class_array[css_class] == c) { return; }
385 if(css_class_array[css_class] !=null)
386 string_ip += css_class_array[css_class] + " ";
388 string_ip = string_ip + c;
389 e.className = string_ip;
392 function remove_css_class(w,c) {
397 if (typeof(w) == 'object') {
403 var css_class_string = '';
405 var css_class_array = e.className;
406 if( css_class_array )
407 css_class_array = css_class_array.split(/\s+/);
410 for (var css_class in css_class_array) {
411 if (css_class_array[css_class] != c) {
413 css_class_string = css_class_array[css_class];
416 css_class_string = css_class_string + ' ' +
417 css_class_array[css_class];
421 e.className = css_class_string;
427 /* takes an array of the form [ key, value, key, value, ..] and
428 redirects the page to the current host/path plus the key
431 function url_redirect(key_value_array) {
433 if( key_value_array == null ||
434 (key_value_array.length %2)) {
436 "AdvancedSearchPage.redirect has invalid args" );
439 var fullpath = globalRootPath;
442 debug("Redirecting...");
444 for( var x = 0; x!= key_value_array.length; x++ ) {
446 fullpath += "?" + encodeURIComponent(key_value_array[x]);
449 fullpath += "&" + encodeURIComponent(key_value_array[x]);
451 fullpath += "=" + encodeURIComponent(key_value_array[x]);
455 debug("Redirecting to " + fullpath );
456 globalAppFrame.location.href = fullpath;
463 the paramObj contains cgi params as object attributes
464 -> paramObj.__paramName
465 paramName is the name of the parameter. the '__' is there to
466 differentiate the paramName from other object attributes.
468 function build_param_array() {
469 var paramArray = new Array();
470 for( var p in paramObj ) {
471 if( p.substr(0,2) == "__" ) {
472 var name = p.substr(2,p.length - 1);
473 paramArray.push(name)
474 paramArray.push(paramObj[p])
481 var evtCache = new Object();
482 function EventListener(bool_callback, done_callback, name, usr_object) {
483 this.bool_callback = bool_callback;
484 this.done_callback = done_callback;
486 this.obj = usr_object;
487 this.complete = false;
488 evtCache["___" + name] = this;
492 //EventListener.prototype.poll = function() {
493 function eventPoll(name) {
494 var obj = evtCache["___" + name];
496 throw "No Listener by that name";
498 obj.complete = obj.bool_callback(obj.obj);
500 obj.done_callback(obj.obj);
502 debug("Setting timeout for next poll..");
503 setTimeout("eventPoll('" + name + "')", obj.interval );
510 function swapClass(obj, class1, class2 ) {
511 if(obj == null) return;
512 if( obj.className.indexOf(class1) != -1 ) {
513 remove_css_class(obj, class1);
514 add_css_class(obj,class2);
516 remove_css_class(obj, class2);
517 add_css_class(obj,class1);
526 function findPosX(obj)
529 if (obj.offsetParent)
531 while (obj.offsetParent)
533 curleft += obj.offsetLeft
534 obj = obj.offsetParent;
542 function findPosY(obj) {
545 if (obj.offsetParent) {
546 while (obj.offsetParent) {
547 curtop += obj.offsetTop
548 obj = obj.offsetParent;
560 function getObjectHeight(obj) {
563 if (elem.offsetHeight) {
564 result = elem.offsetHeight;
565 } else if (elem.clip && elem.clip.height) {
566 result = elem.clip.height;
567 } else if (elem.style && elem.style.pixelHeight) {
568 result = elem.style.pixelHeight;
570 return parseInt(result);
574 function getObjectWidth(obj) {
577 if (elem.offsetWidth) {
578 result = elem.offsetWidth;
579 } else if (elem.clip && elem.clip.width) {
580 result = elem.clip.width;
581 } else if (elem.style && elem.style.pixelWidth) {
582 result = elem.style.pixelWidth;
584 return parseInt(result);
589 function getAppWindow() {
591 return globalAppFrame.window;
595 function getDocument() {
597 return globalAppFrame.document;
601 function getWindow() {
603 return globalAppFrame;
607 /* returns [x, y] coords of the mouse */
608 function getMousePos(e) {
612 if (!e) e = getAppWindow().event;
613 if (e.pageX || e.pageY) {
617 else if (e.clientX || e.clientY) {
618 posx = e.clientX + getDocument().body.scrollLeft;
619 posy = e.clientY + getDocument().body.scrollTop;
622 return [ posx, posy ];
625 function buildFunction(string) {
626 return eval("new Function(" + string + ")");
630 function instanceOf(object, constructorFunction) {
633 while (object != null) {
634 if (object == constructorFunction.prototype)
636 object = object.__proto__;
639 while(object != null) {
640 if( object instanceof constructorFunction )
642 object = object.__proto__;
649 /* builds any element */
650 function elem(name, attrs, style, text) {
651 var e = createAppElement(name);
654 if (key == 'class') {
655 e.className = attrs[key];
656 } else if (key == 'id') {
659 e.setAttribute(key, attrs[key]);
665 e.style[key] = style[key];
669 e.appendChild(createAppTextNode(text));
674 function filter_list(list,f) {
676 for (var i in list) {
677 var t = f( list[i] );
678 if (t) new_list.push( list[i] );
683 function find_list(list,f) {
684 for (var i in list) {
685 var t = f( list[i] );
686 if (t) return list[i];
691 function removeChildren(node) {
692 if(typeof node == 'object' && node != null) {
693 while(node.childNodes[0])
694 node.removeChild(node.childNodes[0]);