2 return document.getElementById(id);
6 function addCSSClass(e,c) {
9 var css_class_string = e.className;
13 css_class_array = css_class_string.split(/\s+/);
15 var string_ip = ""; /*strip out nulls*/
16 for (var css_class in css_class_array) {
17 if (css_class_array[css_class] == c) { return; }
18 if(css_class_array[css_class] !=null)
19 string_ip += css_class_array[css_class] + " ";
21 string_ip = string_ip + c;
22 e.className = string_ip;
25 function removeCSSClass(e, c) {
28 var css_class_string = '';
30 var css_class_array = e.className;
32 css_class_array = css_class_array.split(/\s+/);
35 for (var css_class in css_class_array) {
36 if (css_class_array[css_class] != c) {
38 css_class_string = css_class_array[css_class];
41 css_class_string = css_class_string + ' ' +
42 css_class_array[css_class];
46 e.className = css_class_string;
50 /*returns the character code pressed that caused the event */
51 function grabCharCode(evt) {
52 evt = (evt) ? evt : ((window.event) ? event : null);
54 return (evt.charCode ? evt.charCode :
55 ((evt.which) ? evt.which : evt.keyCode ));
60 /* returns true if the user pressed enter */
61 function userPressedEnter(evt) {
62 var code = grabCharCode(evt);
63 if(code==13||code==3) return true;
68 function goTo(url) {location.href = url;}
71 function removeChildren(dom) {
73 while(dom.childNodes[0])
74 dom.removeChild(dom.childNodes[0]);
78 function instanceOf(object, constructorFunction) {
81 while (object != null) {
82 if (object == constructorFunction.prototype)
84 object = object.__proto__;
87 while(object != null) {
88 if( object instanceof constructorFunction )
90 object = object.__proto__;
97 /* ------------------------------------------------------------------------------------------- */
98 /* detect my browser */
99 var isMac, NS, NS4, NS6, IE, IE4, IE4mac, IE4plus, IE5, IE5plus, IE6, IEMajor, ver4;
100 function detect_browser() {
102 isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
103 NS = (navigator.appName == "Netscape") ? true : false;
104 NS4 = (document.layers) ? true : false;
105 IE = (navigator.appName == "Microsoft Internet Explorer") ? true : false;
106 IEmac = ((document.all)&&(isMac)) ? true : false;
107 IE4plus = (document.all) ? true : false;
108 IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
109 IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
110 IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
111 ver4 = (NS4 || IE4plus) ? true : false;
112 NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
114 IE5plus = IE5 || IE6;
118 var start = navigator.appVersion.indexOf("MSIE");
119 var end = navigator.appVersion.indexOf(".",start);
120 IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
121 IE5plus = (IEMajor>=5) ? true : false;
125 /* ------------------------------------------------------------------------------------------- */
129 if(t == null) t = "";
130 return document.createTextNode(t);
133 function elem(name, attrs, text) {
134 var e = createAppElement(name);
137 if( key == 'id') e.id = attrs[key];
138 else e.setAttribute(key, attrs[key]);
141 if (text) e.appendChild(text(text));
146 /* sel is the selector object, sets selected on the
147 option with the given value. case does not matter...*/
148 function setSelector( sel, value ) {
149 if(sel && value != null) {
150 for( var i = 0; i!= sel.options.length; i++ ) {
151 if( sel.options[i] ) {
152 var val = sel.options[i].value;
153 value += ""; /* in case of number */
154 if( val && val.toLowerCase() == value.toLowerCase() ) {
155 sel.selectedIndex = i;
156 sel.options[i].selected = true;
164 /* split on spaces. capitalize the first /\w/ character in
166 function normalize(val) {
171 try {val = val.split(' ');} catch(E) {return val;}
174 for( var c = 0; c < val.length; c++) {
178 for(var x = 0; x != string.length; x++) {
181 var ch = string.charAt(x);
182 if(reg.exec(ch + "")) {
183 newVal += string.charAt(x).toUpperCase();
189 newVal += string.charAt(x).toLowerCase();
191 if(c < (val.length-1)) newVal += " ";
194 newVal = newVal.replace(/\s*\.\s*$/,'');
195 newVal = newVal.replace(/\s*\/\s*\/\s*$/,' / ');
196 newVal = newVal.replace(/\s*\/\s*$/,'');
202 /* returns true if n is null or stringifies to 'undefined' */
204 if( n == null || n == undefined || n.toString().toLowerCase() == "undefined"
205 || n.toString().toLowerCase() == "null" )
211 /* find nodes with an attribute of 'name' that equals nodeName */
213 function findNodeByName(root, nodeName) {
214 if( !root || !nodeName) return null;
216 if(root.nodeType != 1) return null;
218 if(root.getAttribute("name") == nodeName ||
219 root.name == nodeName ) {
223 var children = root.childNodes;
225 for( var i = 0; i != children.length; i++ ) {
226 var n = findNodeByName(children[i], nodeName);
235 /* truncates the string at 'size' characters and appends a '...' to the end */
236 function truncate(string, size) {
237 if(string && size != null &&
238 size > -1 && string.length > size)
239 return string.substr(0, size) + "... ";
244 /* style sheets must have a 'name' attribute for these functions to work */
245 function setActivateStyleSheet(name) {
247 for (i = 0; (a = document.getElementsByTagName ("link")[i]); i++) {
248 if (a.getAttribute ("rel").indexOf ("style") != -1 && a.getAttribute ("name")) {
250 if (a.getAttribute ("name").indexOf(name) != -1)
257 /* ----------------------------------------------------- */
258 function scaleFonts(type) {
262 case "large": size = "113%"; break;
263 case "small": size = "87%"; break;
266 document.body.style.fontSize = size;
267 for (i = 0; (a = document.getElementsByTagName ("table")[i]); i++) a.style.fontSize = size;
271 function sortWordsIgnoreCase(a, b) {