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;
69 /* setTimeout because ie sux */
70 setTimeout( function(){ location.href = url; }, 0 );
74 function removeChildren(dom) {
76 while(dom.childNodes[0])
77 dom.removeChild(dom.childNodes[0]);
81 function instanceOf(object, constructorFunction) {
84 while (object != null) {
85 if (object == constructorFunction.prototype)
87 object = object.__proto__;
90 while(object != null) {
91 if( object instanceof constructorFunction )
93 object = object.__proto__;
100 /* ------------------------------------------------------------------------------------------- */
101 /* detect my browser */
102 var isMac, NS, NS4, NS6, IE, IE4, IE4mac, IE4plus, IE5, IE5plus, IE6, IEMajor, ver4;
103 function detect_browser() {
105 isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
106 NS = (navigator.appName == "Netscape") ? true : false;
107 NS4 = (document.layers) ? true : false;
108 IE = (navigator.appName == "Microsoft Internet Explorer") ? true : false;
109 IEmac = ((document.all)&&(isMac)) ? true : false;
110 IE4plus = (document.all) ? true : false;
111 IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
112 IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
113 IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
114 ver4 = (NS4 || IE4plus) ? true : false;
115 NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
117 IE5plus = IE5 || IE6;
121 var start = navigator.appVersion.indexOf("MSIE");
122 var end = navigator.appVersion.indexOf(".",start);
123 IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
124 IE5plus = (IEMajor>=5) ? true : false;
128 /* ------------------------------------------------------------------------------------------- */
132 if(t == null) t = "";
133 return document.createTextNode(t);
136 function elem(name, attrs, text) {
137 var e = createAppElement(name);
140 if( key == 'id') e.id = attrs[key];
141 else e.setAttribute(key, attrs[key]);
144 if (text) e.appendChild(text(text));
149 /* sel is the selector object, sets selected on the
150 option with the given value. case does not matter...*/
151 function setSelector( sel, value ) {
152 if(sel && value != null) {
153 for( var i = 0; i!= sel.options.length; i++ ) {
154 if( sel.options[i] ) {
155 var val = sel.options[i].value;
156 value += ""; /* in case of number */
157 if( val && val.toLowerCase() == value.toLowerCase() ) {
158 sel.selectedIndex = i;
159 sel.options[i].selected = true;
167 /* split on spaces. capitalize the first /\w/ character in
169 function normalize(val) {
174 try {val = val.split(' ');} catch(E) {return val;}
177 for( var c = 0; c < val.length; c++) {
181 for(var x = 0; x != string.length; x++) {
184 var ch = string.charAt(x);
185 if(reg.exec(ch + "")) {
186 newVal += string.charAt(x).toUpperCase();
192 newVal += string.charAt(x).toLowerCase();
194 if(c < (val.length-1)) newVal += " ";
197 newVal = newVal.replace(/\s*\.\s*$/,'');
198 newVal = newVal.replace(/\s*\/\s*\/\s*$/,' / ');
199 newVal = newVal.replace(/\s*\/\s*$/,'');
205 /* returns true if n is null or stringifies to 'undefined' */
207 if( n == null || n == undefined || n.toString().toLowerCase() == "undefined"
208 || n.toString().toLowerCase() == "null" )
214 /* find nodes with an attribute of 'name' that equals nodeName */
216 function findNodeByName(root, nodeName) {
217 if( !root || !nodeName) return null;
219 if(root.nodeType != 1) return null;
221 if(root.getAttribute("name") == nodeName ||
222 root.name == nodeName ) {
226 var children = root.childNodes;
228 for( var i = 0; i != children.length; i++ ) {
229 var n = findNodeByName(children[i], nodeName);
238 /* truncates the string at 'size' characters and appends a '...' to the end */
239 function truncate(string, size) {
240 if(string && size != null &&
241 size > -1 && string.length > size)
242 return string.substr(0, size) + "... ";
247 /* style sheets must have a 'name' attribute for these functions to work */
248 function setActivateStyleSheet(name) {
250 for (i = 0; (a = document.getElementsByTagName ("link")[i]); i++) {
251 if (a.getAttribute ("rel").indexOf ("style") != -1 && a.getAttribute ("name")) {
253 if (a.getAttribute ("name").indexOf(name) != -1)
260 /* ----------------------------------------------------- */
261 function scaleFonts(type) {
274 document.body.style.fontSize = size;
275 for (i = 0; (a = document.getElementsByTagName ("td")[i]); i++) a.style.fontSize = size;;
276 for (i = 0; (a = document.getElementsByTagName ("div")[i]); i++) a.style.fontSize = ssize;
277 for (i = 0; (a = document.getElementsByTagName ("option")[i]); i++) a.style.fontSize = ssize;
278 for (i = 0; (a = document.getElementsByTagName ("li")[i]); i++) a.style.fontSize = ssize;
279 for (i = 0; (a = document.getElementsByTagName ("span")[i]); i++) a.style.fontSize = ssize;
283 function sortWordsIgnoreCase(a, b) {