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]);
87 function instanceOf(object, constructorFunction) {
90 while (object != null) {
91 if (object == constructorFunction.prototype)
93 object = object.__proto__;
96 while(object != null) {
97 if( object instanceof constructorFunction )
99 object = object.__proto__;
106 /* ------------------------------------------------------------------------------------------- */
107 /* detect my browser */
108 var isMac, NS, NS4, NS6, IE, IE4, IE4mac, IE4plus, IE5, IE5plus, IE6, IEMajor, ver4;
109 function detect_browser() {
111 isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
112 NS = (navigator.appName == "Netscape") ? true : false;
113 NS4 = (document.layers) ? true : false;
114 IE = (navigator.appName == "Microsoft Internet Explorer") ? true : false;
115 IEmac = ((document.all)&&(isMac)) ? true : false;
116 IE4plus = (document.all) ? true : false;
117 IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
118 IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
119 IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
120 ver4 = (NS4 || IE4plus) ? true : false;
121 NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
123 IE5plus = IE5 || IE6;
127 var start = navigator.appVersion.indexOf("MSIE");
128 var end = navigator.appVersion.indexOf(".",start);
129 IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
130 IE5plus = (IEMajor>=5) ? true : false;
134 /* ------------------------------------------------------------------------------------------- */
138 if(t == null) t = "";
139 return document.createTextNode(t);
142 function elem(name, attrs, txt) {
143 var e = document.createElement(name);
146 if( key == 'id') e.id = attrs[key];
147 else e.setAttribute(key, attrs[key]);
150 if (txt) e.appendChild(text(txt));
155 /* sel is the selector object, sets selected on the
156 option with the given value. case does not matter...*/
157 function setSelector( sel, value ) {
158 if(sel && value != null) {
159 for( var i = 0; i!= sel.options.length; i++ ) {
160 if( sel.options[i] ) {
161 var val = sel.options[i].value;
162 value += ""; /* in case of number */
163 if( val && val.toLowerCase() == value.toLowerCase() ) {
164 sel.selectedIndex = i;
165 sel.options[i].selected = true;
173 /* split on spaces. capitalize the first /\w/ character in
175 function normalize(val) {
180 try {val = val.split(' ');} catch(E) {return val;}
183 for( var c = 0; c < val.length; c++) {
187 for(var x = 0; x != string.length; x++) {
190 var ch = string.charAt(x);
191 if(reg.exec(ch + "")) {
192 newVal += string.charAt(x).toUpperCase();
198 newVal += string.charAt(x).toLowerCase();
200 if(c < (val.length-1)) newVal += " ";
203 newVal = newVal.replace(/\s*\.\s*$/,'');
204 newVal = newVal.replace(/\s*\/\s*\/\s*$/,' / ');
205 newVal = newVal.replace(/\s*\/\s*$/,'');
211 /* returns true if n is null or stringifies to 'undefined' */
213 if( n == null || n == undefined || n.toString().toLowerCase() == "undefined"
214 || n.toString().toLowerCase() == "null" )
220 /* find nodes with an attribute of 'name' that equals nodeName */
222 function findNodeByName(root, nodeName) {
223 if( !root || !nodeName) return null;
225 if(root.nodeType != 1) return null;
227 if(root.getAttribute("name") == nodeName ||
228 root.name == nodeName ) {
232 var children = root.childNodes;
234 for( var i = 0; i != children.length; i++ ) {
235 var n = findNodeByName(children[i], nodeName);
244 /* truncates the string at 'size' characters and appends a '...' to the end */
245 function truncate(string, size) {
246 if(string && size != null &&
247 size > -1 && string.length > size)
248 return string.substr(0, size) + "... ";
253 /* style sheets must have a 'name' attribute for these functions to work */
254 function setActivateStyleSheet(name) {
256 for (i = 0; (a = document.getElementsByTagName ("link")[i]); i++) {
257 if (a.getAttribute ("rel").indexOf ("style") != -1 && a.getAttribute ("name")) {
259 if (a.getAttribute ("name").indexOf(name) != -1)
266 /* ----------------------------------------------------- */
267 function scaleFonts(type) {
280 document.body.style.fontSize = size;
281 for (i = 0; (a = document.getElementsByTagName ("td")[i]); i++) a.style.fontSize = size;;
282 for (i = 0; (a = document.getElementsByTagName ("div")[i]); i++) a.style.fontSize = ssize;
283 for (i = 0; (a = document.getElementsByTagName ("option")[i]); i++) a.style.fontSize = ssize;
284 for (i = 0; (a = document.getElementsByTagName ("li")[i]); i++) a.style.fontSize = ssize;
285 for (i = 0; (a = document.getElementsByTagName ("span")[i]); i++) a.style.fontSize = ssize;
289 function sortWordsIgnoreCase(a, b) {