1 function $(id) { return getId(id); }
3 return document.getElementById(id);
6 function swapCSSClass(obj, old, newc ) {
7 removeCSSClass(obj, old );
8 addCSSClass(obj, newc );
12 function addCSSClass(e,c) {
15 var css_class_string = e.className;
19 css_class_array = css_class_string.split(/\s+/);
21 var string_ip = ""; /*strip out nulls*/
22 for (var css_class in css_class_array) {
23 if (css_class_array[css_class] == c) { return; }
24 if(css_class_array[css_class] !=null)
25 string_ip += css_class_array[css_class] + " ";
28 e.className = string_ip;
31 function removeCSSClass(e, c) {
34 var css_class_string = '';
36 var css_class_array = e.className;
38 css_class_array = css_class_array.split(/\s+/);
41 for (var css_class in css_class_array) {
42 if (css_class_array[css_class] != c) {
44 css_class_string = css_class_array[css_class];
47 css_class_string = css_class_string + ' ' +
48 css_class_array[css_class];
52 e.className = css_class_string;
56 /*returns the character code pressed that caused the event */
57 function grabCharCode(evt) {
58 evt = (evt) ? evt : ((window.event) ? event : null);
60 return (evt.charCode ? evt.charCode :
61 ((evt.which) ? evt.which : evt.keyCode ));
66 /* returns true if the user pressed enter */
67 function userPressedEnter(evt) {
68 var code = grabCharCode(evt);
69 if(code==13||code==3) return true;
75 /* setTimeout because ie sux */
76 setTimeout( function(){ location.href = url; }, 0 );
80 function removeChildren(dom) {
82 while(dom.childNodes[0])
83 dom.removeChild(dom.childNodes[0]);
86 function appendClear(node, child) {
88 node.appendChild(child);
92 function instanceOf(object, constructorFunction) {
95 while (object != null) {
96 if (object == constructorFunction.prototype)
98 object = object.__proto__;
101 while(object != null) {
102 if( object instanceof constructorFunction )
104 object = object.__proto__;
111 /* ------------------------------------------------------------------------------------------- */
112 /* detect my browser */
113 var isMac, NS, NS4, NS6, IE, IE4, IE4mac, IE4plus, IE5, IE5plus, IE6, IEMajor, ver4;
114 function detect_browser() {
116 isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
117 NS = (navigator.appName == "Netscape") ? true : false;
118 NS4 = (document.layers) ? true : false;
119 IE = (navigator.appName == "Microsoft Internet Explorer") ? true : false;
120 IEmac = ((document.all)&&(isMac)) ? true : false;
121 IE4plus = (document.all) ? true : false;
122 IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
123 IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
124 IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
125 ver4 = (NS4 || IE4plus) ? true : false;
126 NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
128 IE5plus = IE5 || IE6;
132 var start = navigator.appVersion.indexOf("MSIE");
133 var end = navigator.appVersion.indexOf(".",start);
134 IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
135 IE5plus = (IEMajor>=5) ? true : false;
139 /* ------------------------------------------------------------------------------------------- */
143 if(t == null) t = "";
144 return document.createTextNode(t);
147 function elem(name, attrs, txt) {
148 var e = document.createElement(name);
151 if( key == 'id') e.id = attrs[key];
152 else e.setAttribute(key, attrs[key]);
155 if (txt) e.appendChild(text(txt));
160 /* sel is the selector object, sets selected on the
161 option with the given value. case does not matter...*/
162 function setSelector( sel, value ) {
163 if(sel && value != null) {
164 for( var i = 0; i!= sel.options.length; i++ ) {
165 if( sel.options[i] ) {
166 var val = sel.options[i].value;
167 value += ""; /* in case of number */
168 if( val && val.toLowerCase() == value.toLowerCase() ) {
169 sel.selectedIndex = i;
170 sel.options[i].selected = true;
177 function getSelectorVal( sel ) {
178 if(!sel) return null;
179 return sel.options[sel.selectedIndex].value;
182 function insertSelectorVal( selector, index, name, value, action, indent ) {
183 for( var i = selector.options.length; i != index; i-- ) {
184 selector.options[i] = selector.options[i-1].cloneNode(true);
186 setSelectorVal( selector, index, name, value, action, indent );
189 function setSelectorVal( selector, index, name, value, action, indent ) {
190 if(!indent) indent = 0;
191 indent = parseInt(indent);
195 var pre = elem("pre");
196 for( var i = 0; i != indent; i++ )
197 pre.appendChild(text(" "));
199 pre.appendChild(text(name));
200 option = new Option("", value);
201 selector.options[index] = option;
202 select.appendChild(pre);
205 indent = indent * 14;
206 option= new Option(name, value);
207 option.setAttribute("style", "padding-left: "+indent+'px;');
208 selector.options[index] = option;
210 if(action) option.onclick = action;
214 /* split on spaces. capitalize the first /\w/ character in
216 function normalize(val) {
221 try {val = val.split(' ');} catch(E) {return val;}
224 for( var c = 0; c < val.length; c++) {
228 for(var x = 0; x != string.length; x++) {
231 var ch = string.charAt(x);
232 if(reg.exec(ch + "")) {
233 newVal += string.charAt(x).toUpperCase();
239 newVal += string.charAt(x).toLowerCase();
241 if(c < (val.length-1)) newVal += " ";
244 newVal = newVal.replace(/\s*\.\s*$/,'');
245 newVal = newVal.replace(/\s*\/\s*\/\s*$/,' / ');
246 newVal = newVal.replace(/\s*\/\s*$/,'');
252 /* returns true if n is null or stringifies to 'undefined' */
254 if( n == null || n == undefined || n.toString().toLowerCase() == "undefined"
255 || n.toString().toLowerCase() == "null" )
261 /* find nodes with an attribute of 'name' that equals nodeName */
263 function $n( root, nodeName ) { return findNodeByName(root,nodeName); }
265 function findNodeByName(root, nodeName) {
266 if( !root || !nodeName) return null;
268 if(root.nodeType != 1) return null;
270 if(root.getAttribute("name") == nodeName || root.name == nodeName )
273 var children = root.childNodes;
275 for( var i = 0; i != children.length; i++ ) {
276 var n = findNodeByName(children[i], nodeName);
284 /* truncates the string at 'size' characters and appends a '...' to the end */
285 function truncate(string, size) {
286 if(string && size != null &&
287 size > -1 && string.length > size)
288 return string.substr(0, size) + "... ";
293 /* style sheets must have a 'name' attribute for these functions to work */
294 function setActivateStyleSheet(name) {
296 for (i = 0; (a = document.getElementsByTagName ("link")[i]); i++) {
297 if (a.getAttribute ("rel").indexOf ("style") != -1 && a.getAttribute ("name")) {
299 if (a.getAttribute ("name").indexOf(name) != -1)
306 /* ----------------------------------------------------- */
307 function scaleFonts(type) {
320 document.getElementsByTagName('body')[0].style.fontSize = size;
321 for (i = 0; (a = document.getElementsByTagName ("td")[i]); i++) a.style.fontSize = size;;
322 for (i = 0; (a = document.getElementsByTagName ("div")[i]); i++) a.style.fontSize = ssize;
323 for (i = 0; (a = document.getElementsByTagName ("option")[i]); i++) a.style.fontSize = ssize;
324 for (i = 0; (a = document.getElementsByTagName ("li")[i]); i++) a.style.fontSize = ssize;
325 for (i = 0; (a = document.getElementsByTagName ("span")[i]); i++) a.style.fontSize = ssize;
329 function sortWordsIgnoreCase(a, b) {