File indexing completed on 2024-05-05 17:20:50

0001 function showAll() {
0002   // for now, assume only 1 table
0003   tbl = document.getElementsByTagName("table")[0];
0004   bdy = tbl.getElementsByTagName("tbody")[0];
0005   rows = bdy.getElementsByTagName("tr");
0006   for(i=0;i<rows.length;i++) {
0007 //    rows[i].style.display="table-row";
0008     if(i % 2) { rows[i].className='entry0'; }
0009     else { rows[i].className='entry1'; }
0010   }
0011 }
0012 
0013 function checkQuery() {
0014   s = queryVariable("searchText");
0015   if(s=="") {
0016     return;
0017   }
0018   doSearch(s);
0019 }
0020 
0021 function searchRows() {
0022   s = document.getElementById("searchText").value;
0023   if(s=="") {
0024     showAll();
0025     return;
0026   }
0027   doSearch(s);
0028 }
0029 
0030 function doSearch(s) {
0031   re = new RegExp(s,"i")
0032   tbl = document.getElementsByTagName("table")[0];
0033   bdy = tbl.getElementsByTagName("tbody")[0];
0034   rows = bdy.getElementsByTagName("tr");
0035   j = 0;
0036   for(i=0; i<rows.length; i++) {
0037     s = ts_getInnerText(rows[i]);
0038     if(re.test(s)) {
0039 //      rows[i].style.display="table-row";
0040       if(j % 2) { rows[i].className='entry1'; }
0041       else { rows[i].className='entry0'; }
0042       j++;
0043     } else {
0044 //      rows[i].style.display="none";
0045       // for msie
0046       rows[i].className='hidden';
0047     }
0048   }
0049 }
0050 
0051 function addEvent(elm, evType, fn, useCapture) {
0052 // addEvent and removeEvent
0053 // cross-browser event handling for IE5+,  NS6 and Mozilla
0054 // By Scott Andrew
0055   if (elm.addEventListener) {
0056     elm.addEventListener(evType, fn, useCapture);
0057     return true;
0058   } else if (elm.attachEvent) {
0059     var r = elm.attachEvent("on"+evType, fn);
0060     return r;
0061   }
0062 }
0063 
0064 addEvent(window, "load", checkQuery);
0065 
0066 function queryVariable(variable) {
0067   var query = window.location.search.substring(1);
0068   var vars = query.split("&");
0069   for (var i=0;i<vars.length;i++) {
0070     var pair = vars[i].split("=");
0071     if (pair[0] == variable) {
0072       return pair[1];
0073     }
0074   }
0075   return "";
0076 }
0077 
0078 function ts_getInnerText(el) {
0079         if (typeof el == "string") return el;
0080         if (typeof el == "undefined") { return el };
0081         if (el.innerText) return el.innerText; //Not needed but it is faster
0082         var str = "";
0083         
0084         var cs = el.childNodes;
0085         var l = cs.length;
0086         for (var i = 0; i < l; i++) {
0087                 switch (cs[i].nodeType) {
0088                         case 1: //ELEMENT_NODE
0089                                 str += ts_getInnerText(cs[i]);
0090                                 break;
0091                         case 3: //TEXT_NODE
0092                                 str += cs[i].nodeValue;
0093                                 break;
0094                 }
0095         }
0096         return str;
0097 }
0098 
0099 /*
0100   SortTable
0101   version 2
0102   7th April 2007
0103   Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/
0104   
0105   Instructions:
0106   Download this file
0107   Add <script src="sorttable.js"></script> to your HTML
0108   Add class="sortable" to any table you'd like to make sortable
0109   Click on the headers to sort
0110   
0111   Thanks to many, many people for contributions and suggestions.
0112   Licenced as X11: http://www.kryogenix.org/code/browser/licence.html
0113   This basically means: do what you want with it.
0114 */
0115 
0116  
0117 var stIsIE = /*@cc_on!@*/false;
0118 
0119 sorttable = {
0120   init: function() {
0121     // quit if this function has already been called
0122     if (arguments.callee.done) return;
0123     // flag this function so we don't do the same thing twice
0124     arguments.callee.done = true;
0125     // kill the timer
0126     if (_timer) clearInterval(_timer);
0127     
0128     if (!document.createElement || !document.getElementsByTagName) return;
0129     
0130     sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-](\d{4}|\d\d)$/;
0131     sorttable.YYMMDD_RE = /^(\d{4}|\d\d)[\/\.-](\d\d?)[\/\.-](\d\d?)$/;
0132     
0133     forEach(document.getElementsByTagName('table'), function(table) {
0134       if (table.className.search(/\bsortable\b/) != -1) {
0135         sorttable.makeSortable(table);
0136       }
0137     });
0138     
0139   },
0140   
0141   makeSortable: function(table) {
0142     if (table.getElementsByTagName('thead').length == 0) {
0143       // table doesn't have a tHead. Since it should have, create one and
0144       // put the first table row in it.
0145       the = document.createElement('thead');
0146       the.appendChild(table.rows[0]);
0147       table.insertBefore(the,table.firstChild);
0148     }
0149     // Safari doesn't support table.tHead, sigh
0150     if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0];
0151     
0152     if (table.tHead.rows.length != 1) return; // can't cope with two header rows
0153     
0154     // work through each column and calculate its type
0155     headrow = table.tHead.rows[0].cells;
0156     for (var i=0; i<headrow.length; i++) {
0157       // manually override the type with a sorttable_type attribute
0158       if (!headrow[i].className.match(/\bsorttable_nosort\b/)) { // skip this col
0159         mtch = headrow[i].className.match(/\bsorttable_([a-z0-9]+)\b/);
0160         if (mtch) { override = mtch[1]; }
0161             if (mtch && typeof sorttable["sort_"+override] == 'function') {
0162               headrow[i].sorttable_sortfunction = sorttable["sort_"+override];
0163             } else {
0164           var sortType = COL_SORT_ARRAY[i];
0165           if (sortType == 0) headrow[i].sorttable_sortfunction = sorttable["sort_alpha"];
0166           else if (sortType == 1) headrow[i].sorttable_sortfunction = sorttable["sort_numeric"];
0167           else if (sortType == 2) headrow[i].sorttable_sortfunction = sorttable["sort_yymmdd"];
0168           else headrow[i].sorttable_sortfunction = sorttable.guessType(table,i);
0169             }
0170               // make it clickable to sort
0171               headrow[i].sorttable_columnindex = i;
0172               headrow[i].sorttable_tbody = table.tBodies[0];
0173               dean_addEvent(headrow[i],"click", function(e) {
0174 
0175           if (this.className.search(/\bsorttable_sorted\b/) != -1) {
0176             // if we're already sorted by this column, just 
0177             // reverse the table, which is quicker
0178             sorttable.reverse(this.sorttable_tbody);
0179             this.className = this.className.replace('sorttable_sorted',
0180                                                     'sorttable_sorted_reverse');
0181             this.removeChild(document.getElementById('sorttable_sortfwdind'));
0182             sortrevind = document.createElement('span');
0183             sortrevind.id = "sorttable_sortrevind";
0184             sortrevind.innerHTML = stIsIE ? '&nbsp<font face="webdings">5</font>' : '&nbsp;&#x25B4;';
0185             this.appendChild(sortrevind);
0186             return;
0187           }
0188           if (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) {
0189             // if we're already sorted by this column in reverse, just 
0190             // re-reverse the table, which is quicker
0191             sorttable.reverse(this.sorttable_tbody);
0192             this.className = this.className.replace('sorttable_sorted_reverse',
0193                                                     'sorttable_sorted');
0194             this.removeChild(document.getElementById('sorttable_sortrevind'));
0195             sortfwdind = document.createElement('span');
0196             sortfwdind.id = "sorttable_sortfwdind";
0197             sortfwdind.innerHTML = stIsIE ? '&nbsp<font face="webdings">6</font>' : '&nbsp;&#x25BE;';
0198             this.appendChild(sortfwdind);
0199             return;
0200           }
0201           
0202           // remove sorttable_sorted classes
0203           theadrow = this.parentNode;
0204           forEach(theadrow.childNodes, function(cell) {
0205             if (cell.nodeType == 1) { // an element
0206               cell.className = cell.className.replace('sorttable_sorted_reverse','');
0207               cell.className = cell.className.replace('sorttable_sorted','');
0208             }
0209           });
0210           sortfwdind = document.getElementById('sorttable_sortfwdind');
0211           if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); }
0212           sortrevind = document.getElementById('sorttable_sortrevind');
0213           if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); }
0214           
0215           this.className += ' sorttable_sorted';
0216           sortfwdind = document.createElement('span');
0217           sortfwdind.id = "sorttable_sortfwdind";
0218           sortfwdind.innerHTML = stIsIE ? '&nbsp<font face="webdings">6</font>' : '&nbsp;&#x25BE;';
0219           this.appendChild(sortfwdind);
0220 
0221                 // build an array to sort. This is a Schwartzian transform thing,
0222                 // i.e., we "decorate" each row with the actual sort key,
0223                 // sort based on the sort keys, and then put the rows back in order
0224                 // which is a lot faster because you only do getInnerText once per row
0225                 row_array = [];
0226                 col = this.sorttable_columnindex;
0227                 rows = this.sorttable_tbody.rows;
0228                 for (var j=0; j<rows.length; j++) {
0229                   row_array[row_array.length] = [sorttable.getInnerText(rows[j].cells[col]), rows[j]];
0230                 }
0231                 /* If you want a stable sort, uncomment the following line */
0232                 //sorttable.shaker_sort(row_array, this.sorttable_sortfunction);
0233                 /* and comment out this one */
0234                 row_array.sort(this.sorttable_sortfunction);
0235                 
0236                 tb = this.sorttable_tbody;
0237                 for (var j=0; j<row_array.length; j++) {
0238               var row = row_array[j][1];
0239               if(j % 2) { row.className='entry0'; }
0240               else { row.className='entry1'; }
0241                   tb.appendChild(row);
0242                 }
0243                 
0244                 delete row_array;
0245               });
0246             }
0247     }
0248   },
0249   
0250   guessType: function(table, column) {
0251     // guess the type of a column based on its first non-blank row
0252     sortfn = sorttable.sort_alpha;
0253     for (var i=0; i<table.tBodies[0].rows.length; i++) {
0254       text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]);
0255       if (text != '') {
0256         if (text.match(/^-?[£$¤]?[\d,.]+%?$/)) {
0257           return sorttable.sort_numeric;
0258         }
0259         // check for a date: dd/mm/yyyy or dd/mm/yy 
0260         // can have / or . or - as separator
0261         // can be mm/dd as well
0262         possdate = text.match(sorttable.DATE_RE)
0263         if (possdate) {
0264           // looks like a date
0265           first = parseInt(possdate[1]);
0266           second = parseInt(possdate[2]);
0267           if (first > 12) {
0268             // definitely dd/mm
0269             return sorttable.sort_ddmm;
0270           } else if (second > 12) {
0271             return sorttable.sort_mmdd;
0272           } else {
0273             // looks like a date, but we can't tell which, so assume
0274             // that it's dd/mm (English imperialism!) and keep looking
0275             sortfn = sorttable.sort_ddmm;
0276           }
0277         }
0278       }
0279     }
0280     return sortfn;
0281   },
0282   
0283   getInnerText: function(node) {
0284     // gets the text we want to use for sorting for a cell.
0285     // strips leading and trailing whitespace.
0286     // this is *not* a generic getInnerText function; it's special to sorttable.
0287     // for example, you can override the cell text with a customkey attribute.
0288     // it also gets .value for <input> fields.
0289     
0290     hasInputs = (typeof node.getElementsByTagName == 'function') &&
0291                  node.getElementsByTagName('input').length;
0292     
0293     if (node.getAttribute("sorttable_customkey") != null) {
0294       return node.getAttribute("sorttable_customkey");
0295     }
0296     var innerText = '';
0297     if (typeof node.textContent != 'undefined' && !hasInputs) {
0298       innerText = node.textContent.replace(/^\s+|\s+$/g, '');
0299     }
0300     else if (typeof node.innerText != 'undefined' && !hasInputs) {
0301       innerText = node.innerText.replace(/^\s+|\s+$/g, '');
0302     }
0303     else if (typeof node.text != 'undefined' && !hasInputs) {
0304       innerText = node.text.replace(/^\s+|\s+$/g, '');
0305     }
0306     if(innerText != '') {
0307       return innerText;
0308     }
0309     else {
0310       switch (node.nodeType) {
0311         case 3:
0312           if (node.nodeName.toLowerCase() == 'input') {
0313             return node.value.replace(/^\s+|\s+$/g, '');
0314           }
0315         case 4:
0316           return node.nodeValue.replace(/^\s+|\s+$/g, '');
0317           break;
0318         case 1:
0319         case 11:
0320           if(node.nodeName.toLowerCase() == 'img') {
0321             var tokens = node.src.split('/');
0322             innerText += tokens[tokens.length-1];
0323           }
0324           for (var i = 0; i < node.childNodes.length; i++) {
0325             innerText += sorttable.getInnerText(node.childNodes[i]);
0326           }
0327           return innerText.replace(/^\s+|\s+$/g, '');
0328           break;
0329         default:
0330           return '';
0331       }
0332     }
0333   },
0334   
0335   reverse: function(tbody) {
0336     // reverse the rows in a tbody
0337     newrows = [];
0338     for (var i=0; i<tbody.rows.length; i++) {
0339       newrows[newrows.length] = tbody.rows[i];
0340     }
0341     for (var i=newrows.length-1; i>=0; i--) {
0342        tbody.appendChild(newrows[i]);
0343     }
0344     delete newrows;
0345   },
0346   
0347   /* sort functions
0348      each sort function takes two parameters, a and b
0349      you are comparing a[0] and b[0] */
0350   sort_numeric: function(a,b) {
0351     /* could be multiple values separated by semi-colon */
0352     aa = a[0].split(";")[0];
0353     bb = b[0].split(";")[0];
0354     aa = parseFloat(aa.replace(/[^0-9.-]/g,''));
0355     if (isNaN(aa)) aa = 0;
0356     bb = parseFloat(bb.replace(/[^0-9.-]/g,'')); 
0357     if (isNaN(bb)) bb = 0;
0358     return aa-bb;
0359   },
0360   sort_alpha: function(a,b) {
0361     /* case-insensitive */
0362     aa = a[0].toLowerCase();
0363     bb = b[0].toLowerCase();
0364     if(aa.localeCompare) return aa.localeCompare(bb); /* Robby Stephenson */
0365     if (aa==bb) return 0;
0366     if (aa<bb) return -1;
0367     return 1;
0368   },
0369   sort_yymmdd: function(a,b) {
0370     mtch = a[0].match(sorttable.YYMMDD_RE);
0371     if (mtch) {
0372       y = mtch[1]; m = mtch[2]; d = mtch[3];
0373       // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
0374       if (y.length == 2)
0375         if (parseInt(y) < 50) y = '20'+y; else y = '19'+y;
0376       if (m.length == 1) m = '0'+m;
0377       if (d.length == 1) d = '0'+d;
0378       dt1 = y+m+d;
0379     } else dt1 = a[0];
0380     mtch = b[0].match(sorttable.YYMMDD_RE);
0381     if (mtch) {
0382       y = mtch[1]; m = mtch[2]; d = mtch[3];
0383       if (y.length == 2)
0384         if (parseInt(y) < 50) y = '20'+y; else y = '19'+y;
0385       if (m.length == 1) m = '0'+m;
0386       if (d.length == 1) d = '0'+d;
0387       dt2 = y+m+d;
0388     } else dt2 = b[0];
0389     if (dt1==dt2) return 0;
0390     if (dt1<dt2) return -1;
0391     return 1;
0392   },
0393   sort_ddmm: function(a,b) {
0394     mtch = a[0].match(sorttable.DATE_RE);
0395     if (mtch) {
0396       y = mtch[3]; m = mtch[2]; d = mtch[1];
0397       if (m.length == 1) m = '0'+m;
0398       if (d.length == 1) d = '0'+d;
0399       dt1 = y+m+d;
0400     } else dt1 = a[0];
0401     mtch = b[0].match(sorttable.DATE_RE);
0402     if (mtch) {
0403       y = mtch[3]; m = mtch[2]; d = mtch[1];
0404       if (m.length == 1) m = '0'+m;
0405       if (d.length == 1) d = '0'+d;
0406       dt2 = y+m+d;
0407     } else dt2 = b[0];
0408     if (dt1==dt2) return 0;
0409     if (dt1<dt2) return -1;
0410     return 1;
0411   },
0412   sort_mmdd: function(a,b) {
0413     mtch = a[0].match(sorttable.DATE_RE);
0414     if (mtch) {
0415       y = mtch[3]; d = mtch[2]; m = mtch[1];
0416       if (m.length == 1) m = '0'+m;
0417       if (d.length == 1) d = '0'+d;
0418       dt1 = y+m+d;
0419     } else dt1 = a[0];
0420     mtch = b[0].match(sorttable.DATE_RE);
0421     if (mtch) {
0422       y = mtch[3]; d = mtch[2]; m = mtch[1];
0423       if (m.length == 1) m = '0'+m;
0424       if (d.length == 1) d = '0'+d;
0425       dt2 = y+m+d;
0426     } else dt2 = b[0];
0427     if (dt1==dt2) return 0;
0428     if (dt1<dt2) return -1;
0429     return 1;
0430   },
0431   
0432   shaker_sort: function(list, comp_func) {
0433     // A stable sort function to allow multi-level sorting of data
0434     // see: http://en.wikipedia.org/wiki/Cocktail_sort
0435     // thanks to Joseph Nahmias
0436     var b = 0;
0437     var t = list.length - 1;
0438     var swap = true;
0439 
0440     while(swap) {
0441         swap = false;
0442         for(var i = b; i < t; ++i) {
0443             if ( comp_func(list[i], list[i+1]) > 0 ) {
0444                 var q = list[i]; list[i] = list[i+1]; list[i+1] = q;
0445                 swap = true;
0446             }
0447         } // for
0448         t--;
0449 
0450         if (!swap) break;
0451 
0452         for(var i = t; i > b; --i) {
0453             if ( comp_func(list[i], list[i-1]) < 0 ) {
0454                 var q = list[i]; list[i] = list[i-1]; list[i-1] = q;
0455                 swap = true;
0456             }
0457         } // for
0458         b++;
0459 
0460     } // while(swap)
0461   }  
0462 }
0463 
0464 /* ******************************************************************
0465    Supporting functions: bundled here to avoid depending on a library
0466    ****************************************************************** */
0467 
0468 // Dean Edwards/Matthias Miller/John Resig
0469 
0470 /* for Mozilla/Opera9 */
0471 if (document.addEventListener) {
0472     document.addEventListener("DOMContentLoaded", sorttable.init, false);
0473 }
0474 
0475 /* for Internet Explorer */
0476 /*@cc_on @*/
0477 /*@if (@_win32)
0478     document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
0479     var script = document.getElementById("__ie_onload");
0480     script.onreadystatechange = function() {
0481         if (this.readyState == "complete") {
0482             sorttable.init(); // call the onload handler
0483         }
0484     };
0485 /*@end @*/
0486 
0487 /* for Safari */
0488 if (/WebKit/i.test(navigator.userAgent)) { // sniff
0489     var _timer = setInterval(function() {
0490         if (/loaded|complete/.test(document.readyState)) {
0491             sorttable.init(); // call the onload handler
0492         }
0493     }, 10);
0494 }
0495 
0496 /* for other browsers */
0497 window.onload = sorttable.init;
0498 
0499 // written by Dean Edwards, 2005
0500 // with input from Tino Zijdel, Matthias Miller, Diego Perini
0501 
0502 // http://dean.edwards.name/weblog/2005/10/add-event/
0503 
0504 function dean_addEvent(element, type, handler) {
0505         if (element.addEventListener) {
0506                 element.addEventListener(type, handler, false);
0507         } else {
0508                 // assign each event handler a unique ID
0509                 if (!handler.$$guid) handler.$$guid = dean_addEvent.guid++;
0510                 // create a hash table of event types for the element
0511                 if (!element.events) element.events = {};
0512                 // create a hash table of event handlers for each element/event pair
0513                 var handlers = element.events[type];
0514                 if (!handlers) {
0515                         handlers = element.events[type] = {};
0516                         // store the existing event handler (if there is one)
0517                         if (element["on" + type]) {
0518                                 handlers[0] = element["on" + type];
0519                         }
0520                 }
0521                 // store the event handler in the hash table
0522                 handlers[handler.$$guid] = handler;
0523                 // assign a global event handler to do all the work
0524                 element["on" + type] = handleEvent;
0525         }
0526 };
0527 // a counter used to create unique IDs
0528 dean_addEvent.guid = 1;
0529 
0530 function removeEvent(element, type, handler) {
0531         if (element.removeEventListener) {
0532                 element.removeEventListener(type, handler, false);
0533         } else {
0534                 // delete the event handler from the hash table
0535                 if (element.events && element.events[type]) {
0536                         delete element.events[type][handler.$$guid];
0537                 }
0538         }
0539 };
0540 
0541 function handleEvent(event) {
0542         var returnValue = true;
0543         // grab the event object (IE uses a global event object)
0544         event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
0545         // get a reference to the hash table of event handlers
0546         var handlers = this.events[event.type];
0547         // execute each event handler
0548         for (var i in handlers) {
0549                 this.$$handleEvent = handlers[i];
0550                 if (this.$$handleEvent(event) === false) {
0551                         returnValue = false;
0552                 }
0553         }
0554         return returnValue;
0555 };
0556 
0557 function fixEvent(event) {
0558         // add W3C standard event methods
0559         event.preventDefault = fixEvent.preventDefault;
0560         event.stopPropagation = fixEvent.stopPropagation;
0561         return event;
0562 };
0563 fixEvent.preventDefault = function() {
0564     this.returnValue = false;
0565 };
0566 fixEvent.stopPropagation = function() {
0567     this.cancelBubble = true;
0568 }
0569 
0570 // Dean's forEach: http://dean.edwards.name/base/forEach.js
0571 /*
0572         forEach, version 1.0
0573         Copyright 2006, Dean Edwards
0574         License: http://www.opensource.org/licenses/mit-license.php
0575 */
0576 
0577 // array-like enumeration
0578 if (!Array.forEach) { // mozilla already supports this
0579         Array.forEach = function(array, block, context) {
0580                 for (var i = 0; i < array.length; i++) {
0581                         block.call(context, array[i], i, array);
0582                 }
0583         };
0584 }
0585 
0586 // generic enumeration
0587 Function.prototype.forEach = function(object, block, context) {
0588         for (var key in object) {
0589                 if (typeof this.prototype[key] == "undefined") {
0590                         block.call(context, object[key], key, object);
0591                 }
0592         }
0593 };
0594 
0595 // character enumeration
0596 String.forEach = function(string, block, context) {
0597         Array.forEach(string.split(""), function(chr, index) {
0598                 block.call(context, chr, index, string);
0599         });
0600 };
0601 
0602 // globally resolve forEach enumeration
0603 var forEach = function(object, block, context) {
0604         if (object) {
0605                 var resolve = Object; // default
0606                 if (object instanceof Function) {
0607                         // functions have a "length" property
0608                         resolve = Function;
0609                 } else if (object.forEach instanceof Function) {
0610                         // the object implements a custom forEach method so use that
0611                         object.forEach(block, context);
0612                         return;
0613                 } else if (typeof object == "string") {
0614                         // the object is a string
0615                         resolve = String;
0616                 } else if (typeof object.length == "number") {
0617                         // the object is array-like
0618                         resolve = Array;
0619                 }
0620                 resolve.forEach(object, block, context);
0621         }
0622 };