16 function detect_browser() {
18 isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
19 NS = (navigator.appName == "Netscape") ? true : false;
20 NS4 = (document.layers) ? true : false;
21 IE = (navigator.appName == "Microsoft Internet Explorer") ? true : false;
22 IEmac = ((document.all)&&(isMac)) ? true : false;
23 IE4plus = (document.all) ? true : false;
24 IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
25 IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
26 IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
27 ver4 = (NS4 || IE4plus) ? true : false;
28 NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
34 var start = navigator.appVersion.indexOf("MSIE");
35 var end = navigator.appVersion.indexOf(".",start);
36 IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
37 IE5plus = (IEMajor>=5) ? true : false;
47 function hideMe(obj) {
49 add_css_class( obj, "hide_me");
50 remove_css_class( obj, "show_me");
53 function showMe(obj) {
55 add_css_class( obj, "show_me");
56 remove_css_class( obj, "hide_me");
59 function grabCharCode( evt ) {
60 evt = (evt) ? evt : ((window.event) ? event : null); /* for mozilla and IE */
62 return (evt.charCode ? evt.charCode :
63 ((evt.which) ? evt.which : evt.keyCode ));
69 function getById(id) {
71 var obj = document.getElementById(id);
72 if(obj != null) return obj;
76 obj = globalAppFrame.document.getElementById(id);
79 alert("We need a globalAppFrame to function");
85 function createAppElement(name) {
87 return globalAppFrame.document.createElement(name);
88 return document.createElement(name);
91 function createAppTextNode(text) {
93 return globalAppFrame.document.createTextNode(text);
94 return document.createTextNode(text);
99 function normalize(val) {
101 val = val.split(' ');
102 for(var c=0; c < val.length; c++) {
105 for(var x = 0; x != string.length; x++) {
107 newVal += string.charAt(x).toUpperCase();
109 newVal += string.charAt(x).toLowerCase();
111 if(c < (val.length-1)) newVal += " ";
121 if(reg.exec(navigator.userAgent))
126 function debug(message) {
129 dump(" -|*|- Debug: " + message + "\n");
134 /* finds or builds the requested row id, adding any intermediate rows along the way */
135 function table_row_find_or_create( table, index ) {
137 if(table == null || index == null || index < 0 || index > 10000 ) {
138 throw "table_row_find_or_create with invalid " +
139 "params. table: " + table + " index: " + index + "\n";
142 var tbody = table.getElementsByTagName("tbody")[0];
145 tbody = table.appendChild(createAppElement("tbody"));
148 if(table.rows[index] != null)
149 return table.rows[index];
152 for( var x = 0; x <= index; x++ ) {
153 if(table.rows[x] == null) {
154 row = tbody.appendChild(createAppElement("tr"));
155 //row = table.appendChild(document.createElement("tr"));
156 //row = document.createElement("tr");
157 //var tbody = table.getElementsByTagName("tbody")[0];
159 //tbody.appendChild(row);
160 //table.childNodes[x] = row;
161 //table.rows[x] = row;
162 //row = table.insertRow(x);
168 /* finds or builds the requested cell, adding any intermediate cells along the way */
169 function table_cell_find_or_create( row, index ) {
171 if(row == null || index == null || index < 0 || index > 10000 ) {
172 throw "table_cell_find_or_create with invalid " +
173 "params. row: " + row + " index: " + index + "\n";
176 if(row.cells[index] != null)
177 return row.cells[index];
179 for( var x = 0; x!= index; x++ ) {
180 if(row.cells[x] == null)
184 return row.insertCell(index);
189 // -----------------------------------------------------------------------
190 // Generic cookie libarary copied from
191 // http://webreference.com/js/column8/functions.html
192 // -----------------------------------------------------------------------
195 name - name of the cookie
196 value - value of the cookie
197 [expires] - expiration date of the cookie
198 (defaults to end of current session)
199 [path] - path for which the cookie is valid
200 (defaults to path of calling document)
201 [domain] - domain for which the cookie is valid
202 (defaults to domain of calling document)
203 [secure] - Boolean value indicating if the cookie transmission requires
204 a secure transmission
205 * an argument defaults when it is assigned null as a placeholder
206 * a null placeholder is not required for trailing omitted arguments
209 function setCookie(name, value, expires, path, domain, secure) {
210 var curCookie = name + "=" + escape(value) +
211 ((expires) ? "; expires=" + expires.toGMTString() : "") +
212 ((path) ? "; path=" + path : "") +
213 ((domain) ? "; domain=" + domain : "") +
214 ((secure) ? "; secure" : "");
215 document.cookie = curCookie;
220 name - name of the desired cookie
221 return string containing value of specified cookie or null
222 if cookie does not exist
225 function getCookie(name) {
226 var dc = document.cookie;
227 var prefix = name + "=";
228 var begin = dc.indexOf("; " + prefix);
230 begin = dc.indexOf(prefix);
231 if (begin != 0) return null;
236 var end = document.cookie.indexOf(";", begin);
237 if (end == -1) end = dc.length;
238 return unescape(dc.substring(begin + prefix.length, end));
243 name - name of the cookie
244 [path] - path of the cookie (must be same as path used to create cookie)
245 [domain] - domain of the cookie (must be same as domain used to
247 path and domain default if assigned null or omitted if no explicit
251 function deleteCookie(name, path, domain) {
252 if (getCookie(name)) {
253 var string = name + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
254 debug("Delete cookie string: "+ string );
255 document.cookie = string;
256 debug("Delete Cookie: " + document.cookie );
258 document.cookie = name + "=" +
259 ((path) ? "; path=" + path : "") +
260 ((domain) ? "; domain=" + domain : "") +
261 "; expires=Thu, 01-Jan-70 00:00:01 GMT";
266 // date - any instance of the Date object
267 // * hand all instances of the Date object to this function for "repairs"
269 function fixDate(date) {
270 var base = new Date(0);
271 var skew = base.getTime();
273 date.setTime(date.getTime() - skew);
276 // -----------------------------------------------------------------------
278 var globalProgressBar = null;
279 function ProgressBar( div, color, interval ) {
281 this.progressEnd = 9;
284 this.progressColor = color;
286 this.progressColor = 'blue';
289 this.progressInterval = interval;
291 this.progressInterval = 50;
293 this.progressAt = this.progressEnd;
296 for( var x = 0; x!= this.progressEnd; x++ ) {
297 var newdiv = createAppElement("span");
298 newdiv.id = "progress" + x;
299 newdiv.appendChild(document.createTextNode(" "));
300 div.appendChild(newdiv);
302 globalProgressBar = this;
305 ProgressBar.prototype.progressStart = function() {
306 this.progressUpdate();
309 ProgressBar.prototype.progressClear = function() {
310 for (var i = 0; i < this.progressEnd; i++) {
311 getById('progress' + i).style.backgroundColor = 'transparent';
316 ProgressBar.prototype.progressUpdate = function() {
317 debug(" -3-3-3-3- Updating Progress Bar");
319 if (this.progressAt > this.progressEnd)
320 this.progressClear();
322 getById('progress'+progressAt).style.backgroundColor = this.progressColor;
323 this.progressTimer = setTimeout('globalProgressBar.progressUpdate()', this.progressInterval);
324 debug("Timer is set at " + this.progressInterval);
327 ProgressBar.prototype.progressStop = function() {
328 clearTimeout(this.progressTimer);
329 this.progressClear();
332 function add_css_class(w,c) {
334 if (typeof(w) == 'object') {
339 var css_class_string = e.className;
343 css_class_array = css_class_string.split(/\s+/);
345 var string_ip = ""; /*strip out nulls*/
346 for (var css_class in css_class_array) {
347 if (css_class_array[css_class] == c) { return; }
348 if(css_class_array[css_class] !=null)
349 string_ip += css_class_array[css_class] + " ";
351 string_ip = string_ip + c;
352 e.className = string_ip;
355 function remove_css_class(w,c) {
360 if (typeof(w) == 'object') {
365 var css_class_string = '';
367 var css_class_array = e.className;
368 if( css_class_array )
369 css_class_array = css_class_array.split(/\s+/);
372 for (var css_class in css_class_array) {
373 if (css_class_array[css_class] != c) {
375 css_class_string = css_class_array[css_class];
378 css_class_string = css_class_string + ' ' +
379 css_class_array[css_class];
383 e.className = css_class_string;
389 /* takes an array of the form [ key, value, key, value, ..] and
390 redirects the page to the current host/path plus the key
393 function url_redirect(key_value_array) {
395 if( key_value_array == null ||
396 (key_value_array.length %2)) {
398 "AdvancedSearchPage.redirect has invalid args" );
401 var fullpath = globalRootPath;
404 debug("Redirecting...");
406 for( var x = 0; x!= key_value_array.length; x++ ) {
407 debug("Checking key_value_array " + x + " : " + key_value_array[x] );
409 fullpath += "?" + encodeURIComponent(key_value_array[x]);
412 fullpath += "&" + encodeURIComponent(key_value_array[x]);
414 fullpath += "=" + encodeURIComponent(key_value_array[x]);
418 debug("Redirecting to " + fullpath );
419 globalAppFrame.location.href = fullpath;
426 the paramObj contains cgi params as object attributes
427 -> paramObj.__paramName
428 paramName is the name of the parameter. the '__' is there to
429 differentiate the paramName from other object attributes.
431 function build_param_array() {
432 var paramArray = new Array();
433 for( var p in paramObj ) {
434 if( p.substr(0,2) == "__" ) {
435 var name = p.substr(2,p.length - 1);
436 paramArray.push(name)
437 paramArray.push(paramObj[p])
444 var evtCache = new Object();
445 function EventListener(bool_callback, done_callback, name, usr_object) {
446 this.bool_callback = bool_callback;
447 this.done_callback = done_callback;
449 this.obj = usr_object;
450 this.complete = false;
451 evtCache["___" + name] = this;
455 //EventListener.prototype.poll = function() {
456 function eventPoll(name) {
457 var obj = evtCache["___" + name];
459 throw "No Listener by that name";
461 obj.complete = obj.bool_callback(obj.obj);
463 obj.done_callback(obj.obj);
465 debug("Setting timeout for next poll..");
466 setTimeout("eventPoll('" + name + "')", obj.interval );
473 function swapClass(obj, class1, class2 ) {
474 if( obj.className.indexOf(class1) != -1 ) {
475 remove_css_class(obj, class1);
476 add_css_class(obj,class2);
478 remove_css_class(obj, class2);
479 add_css_class(obj,class1);
488 function findPosX(obj)
491 if (obj.offsetParent)
493 while (obj.offsetParent)
495 curleft += obj.offsetLeft
496 obj = obj.offsetParent;
504 function findPosY(obj)
507 if (obj.offsetParent)
509 while (obj.offsetParent)
511 curtop += obj.offsetTop
512 obj = obj.offsetParent;
522 function getObjectHeight(obj) {
525 if (elem.offsetHeight) {
526 result = elem.offsetHeight;
527 } else if (elem.clip && elem.clip.height) {
528 result = elem.clip.height;
529 } else if (elem.style && elem.style.pixelHeight) {
530 result = elem.style.pixelHeight;
532 return parseInt(result);
536 function getObjectWidth(obj) {
539 if (elem.offsetWidth) {
540 result = elem.offsetWidth;
541 } else if (elem.clip && elem.clip.width) {
542 result = elem.clip.width;
543 } else if (elem.style && elem.style.pixelWidth) {
544 result = elem.style.pixelWidth;
546 return parseInt(result);
551 function getAppWindow() {
553 return globalAppFrame.window;
557 function getDocument() {
559 return globalAppFrame.document;
563 /* returns [x, y] coords of the mouse */
564 function getMousePos(e) {
568 if (!e) e = getAppWindow().event;
569 if (e.pageX || e.pageY) {
573 else if (e.clientX || e.clientY) {
574 posx = e.clientX + getDocument().body.scrollLeft;
575 posy = e.clientY + getDocument().body.scrollTop;
578 return [ posx, posy ];
581 function buildFunction(string) {
582 return eval("new Function(" + string + ")");