1 function convertToId(search)
4 for (i=0;i<search.length;i++)
6 var c = search.charAt(i);
7 var cn = c.charCodeAt(0);
8 if (c.match(/[a-z0-9\u0080-\uFFFF]/))
14 result+=
"_0"+cn.toString(16);
18 result+=
"_"+cn.toString(16);
24 function getXPos(item)
29 while (item && item!=document.body)
32 item = item.offsetParent;
38 function getYPos(item)
43 while (item && item!=document.body)
46 item = item.offsetParent;
59 function SearchBox(name, resultsPath, inFrame, label)
61 if (!name || !resultsPath) { alert(
"Missing parameters to SearchBox."); }
65 this.resultsPath = resultsPath;
67 this.keyTimeoutLength = 500;
68 this.closeSelectionTimeout = 300;
69 this.lastSearchValue =
"";
70 this.lastResultsPage =
"";
73 this.searchActive =
false;
74 this.insideFrame = inFrame;
75 this.searchLabel = label;
79 this.DOMSearchField =
function()
80 {
return document.getElementById(
"MSearchField"); }
82 this.DOMSearchSelect =
function()
83 {
return document.getElementById(
"MSearchSelect"); }
85 this.DOMSearchSelectWindow =
function()
86 {
return document.getElementById(
"MSearchSelectWindow"); }
88 this.DOMPopupSearchResults =
function()
89 {
return document.getElementById(
"MSearchResults"); }
91 this.DOMPopupSearchResultsWindow =
function()
92 {
return document.getElementById(
"MSearchResultsWindow"); }
94 this.DOMSearchClose =
function()
95 {
return document.getElementById(
"MSearchClose"); }
97 this.DOMSearchBox =
function()
98 {
return document.getElementById(
"MSearchBox"); }
103 this.OnSearchFieldFocus =
function(isActive)
105 this.Activate(isActive);
108 this.OnSearchSelectShow =
function()
110 var searchSelectWindow = this.DOMSearchSelectWindow();
111 var searchField = this.DOMSearchSelect();
113 if (this.insideFrame)
115 var left = getXPos(searchField);
116 var top = getYPos(searchField);
117 left += searchField.offsetWidth + 6;
118 top += searchField.offsetHeight;
121 searchSelectWindow.style.display=
'block';
122 left -= searchSelectWindow.offsetWidth;
123 searchSelectWindow.style.left = left +
'px';
124 searchSelectWindow.style.top = top +
'px';
128 var left = getXPos(searchField);
129 var top = getYPos(searchField);
130 top += searchField.offsetHeight;
133 searchSelectWindow.style.display=
'block';
134 searchSelectWindow.style.left = left +
'px';
135 searchSelectWindow.style.top = top +
'px';
139 if (this.hideTimeout)
141 clearTimeout(this.hideTimeout);
147 this.OnSearchSelectHide =
function()
149 this.hideTimeout = setTimeout(this.name +
".CloseSelectionWindow()",
150 this.closeSelectionTimeout);
154 this.OnSearchFieldChange =
function(evt)
158 clearTimeout(this.keyTimeout);
162 var e = (evt) ? evt : window.event;
163 if (e.keyCode==40 || e.keyCode==13)
167 this.OnSearchSelectShow();
168 var win=this.DOMSearchSelectWindow();
169 for (i=0;i<win.childNodes.length;i++)
171 var child = win.childNodes[i];
172 if (child.className==
'SelectItem')
180 else if (window.frames.MSearchResults.searchResults)
182 var elem = window.frames.MSearchResults.searchResults.NavNext(0);
183 if (elem) elem.focus();
186 else if (e.keyCode==27)
188 this.DOMSearchField().blur();
189 this.DOMPopupSearchResultsWindow().style.display =
'none';
190 this.DOMSearchClose().style.display =
'none';
191 this.lastSearchValue =
'';
192 this.Activate(
false);
197 var searchValue = this.DOMSearchField().value.replace(/ +/g,
"");
199 if (searchValue != this.lastSearchValue)
201 if (searchValue !=
"")
204 this.keyTimeout = setTimeout(this.name +
'.Search()',
205 this.keyTimeoutLength);
209 this.DOMPopupSearchResultsWindow().style.display =
'none';
210 this.DOMSearchClose().style.display =
'none';
211 this.lastSearchValue =
'';
216 this.SelectItemCount =
function(id)
219 var win=this.DOMSearchSelectWindow();
220 for (i=0;i<win.childNodes.length;i++)
222 var child = win.childNodes[i];
223 if (child.className==
'SelectItem')
231 this.SelectItemSet =
function(id)
234 var win=this.DOMSearchSelectWindow();
235 for (i=0;i<win.childNodes.length;i++)
237 var child = win.childNodes[i];
238 if (child.className==
'SelectItem')
240 var node = child.firstChild;
243 node.innerHTML=
'•';
247 node.innerHTML=
' ';
256 this.OnSelectItem =
function(id)
258 this.searchIndex = id;
259 this.SelectItemSet(
id);
260 var searchValue = this.DOMSearchField().value.replace(/ +/g,
"");
261 if (searchValue!=
"" && this.searchActive)
267 this.OnSearchSelectKey =
function(evt)
269 var e = (evt) ? evt : window.event;
270 if (e.keyCode==40 &&
this.searchIndex<
this.SelectItemCount())
273 this.OnSelectItem(this.searchIndex);
275 else if (e.keyCode==38 &&
this.searchIndex>0)
278 this.OnSelectItem(this.searchIndex);
280 else if (e.keyCode==13 || e.keyCode==27)
282 this.OnSelectItem(this.searchIndex);
283 this.CloseSelectionWindow();
284 this.DOMSearchField().focus();
292 this.CloseResultsWindow =
function()
294 this.DOMPopupSearchResultsWindow().style.display =
'none';
295 this.DOMSearchClose().style.display =
'none';
296 this.Activate(
false);
299 this.CloseSelectionWindow =
function()
301 this.DOMSearchSelectWindow().style.display =
'none';
305 this.Search =
function()
310 var searchValue = this.DOMSearchField().value.replace(/^ +/,
"");
312 var code = searchValue.toLowerCase().charCodeAt(0);
313 var idxChar = searchValue.substr(0, 1).toLowerCase();
314 if ( 0xD800 <= code && code <= 0xDBFF && searchValue > 1)
316 idxChar = searchValue.substr(0, 2);
320 var resultsPageWithSearch;
323 var idx = indexSectionsWithContent[this.searchIndex].indexOf(idxChar);
326 var hexCode=idx.toString(16);
327 resultsPage = this.resultsPath +
'/' + indexSectionNames[this.searchIndex] +
'_' + hexCode +
'.html';
328 resultsPageWithSearch = resultsPage+
'?'+escape(searchValue);
329 hasResultsPage =
true;
333 resultsPage = this.resultsPath +
'/nomatches.html';
334 resultsPageWithSearch = resultsPage;
335 hasResultsPage =
false;
338 window.frames.MSearchResults.location = resultsPageWithSearch;
339 var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
341 if (domPopupSearchResultsWindow.style.display!=
'block')
343 var domSearchBox = this.DOMSearchBox();
344 this.DOMSearchClose().style.display =
'inline';
345 if (this.insideFrame)
347 var domPopupSearchResults = this.DOMPopupSearchResults();
348 domPopupSearchResultsWindow.style.position =
'relative';
349 domPopupSearchResultsWindow.style.display =
'block';
350 var width = document.body.clientWidth - 8;
351 domPopupSearchResultsWindow.style.width = width +
'px';
352 domPopupSearchResults.style.width = width +
'px';
356 var domPopupSearchResults = this.DOMPopupSearchResults();
357 var left = getXPos(domSearchBox) + 150;
358 var top = getYPos(domSearchBox) + 20;
359 domPopupSearchResultsWindow.style.display =
'block';
360 left -= domPopupSearchResults.offsetWidth;
361 domPopupSearchResultsWindow.style.top = top +
'px';
362 domPopupSearchResultsWindow.style.left = left +
'px';
366 this.lastSearchValue = searchValue;
367 this.lastResultsPage = resultsPage;
374 this.Activate =
function(isActive)
377 this.DOMPopupSearchResultsWindow().style.display ==
'block' 380 this.DOMSearchBox().className =
'MSearchBoxActive';
382 var searchField = this.DOMSearchField();
384 if (searchField.value ==
this.searchLabel)
386 searchField.value =
'';
387 this.searchActive =
true;
392 this.DOMSearchBox().className =
'MSearchBoxInactive';
393 this.DOMSearchField().value = this.searchLabel;
394 this.searchActive =
false;
395 this.lastSearchValue =
'' 396 this.lastResultsPage =
'';
404 function SearchResults(name)
407 this.lastMatchCount = 0;
409 this.repeatOn =
false;
412 this.FindChildElement =
function(id)
414 var parentElement = document.getElementById(
id);
415 var element = parentElement.firstChild;
417 while (element && element!=parentElement)
419 if (element.nodeName ==
'DIV' && element.className ==
'SRChildren')
424 if (element.nodeName ==
'DIV' && element.hasChildNodes())
426 element = element.firstChild;
428 else if (element.nextSibling)
430 element = element.nextSibling;
436 element = element.parentNode;
438 while (element && element!=parentElement && !element.nextSibling);
440 if (element && element!=parentElement)
442 element = element.nextSibling;
448 this.Toggle =
function(id)
450 var element = this.FindChildElement(
id);
453 if (element.style.display ==
'block')
455 element.style.display =
'none';
459 element.style.display =
'block';
469 this.Search =
function(search)
473 search = window.location.search;
474 search = search.substring(1);
475 search = unescape(search);
478 search = search.replace(/^ +/,
"");
479 search = search.replace(/ +$/,
"");
480 search = search.toLowerCase();
481 search = convertToId(search);
483 var resultRows = document.getElementsByTagName(
"div");
487 while (i < resultRows.length)
489 var row = resultRows.item(i);
490 if (row.className ==
"SRResult")
492 var rowMatchName = row.id.toLowerCase();
493 rowMatchName = rowMatchName.replace(/^sr\d*_/,
'');
495 if (search.length<=rowMatchName.length &&
496 rowMatchName.substr(0, search.length)==search)
498 row.style.display =
'block';
503 row.style.display =
'none';
508 document.getElementById(
"Searching").style.display=
'none';
511 document.getElementById(
"NoMatches").style.display=
'block';
515 document.getElementById(
"NoMatches").style.display=
'none';
517 this.lastMatchCount = matches;
522 this.NavNext =
function(index)
527 var focusName =
'Item'+index;
528 focusItem = document.getElementById(focusName);
529 if (focusItem && focusItem.parentNode.parentNode.style.display==
'block')
543 this.NavPrev =
function(index)
548 var focusName =
'Item'+index;
549 focusItem = document.getElementById(focusName);
550 if (focusItem && focusItem.parentNode.parentNode.style.display==
'block')
564 this.ProcessKeys =
function(e)
566 if (e.type ==
"keydown")
568 this.repeatOn =
false;
569 this.lastKey = e.keyCode;
571 else if (e.type ==
"keypress")
575 if (this.lastKey) this.repeatOn =
true;
579 else if (e.type ==
"keyup")
582 this.repeatOn =
false;
584 return this.lastKey!=0;
587 this.Nav =
function(evt,itemIndex)
589 var e = (evt) ? evt : window.event;
590 if (e.keyCode==13)
return true;
591 if (!this.ProcessKeys(e))
return false;
593 if (this.lastKey==38)
595 var newIndex = itemIndex-1;
596 var focusItem = this.NavPrev(newIndex);
599 var child = this.FindChildElement(focusItem.parentNode.parentNode.id);
600 if (child && child.style.display ==
'block')
606 tmpElem = document.getElementById(
'Item'+newIndex+
'_c'+n);
625 parent.document.getElementById(
"MSearchField").focus();
628 else if (this.lastKey==40)
630 var newIndex = itemIndex+1;
632 var item = document.getElementById(
'Item'+itemIndex);
633 var elem = this.FindChildElement(item.parentNode.parentNode.id);
634 if (elem && elem.style.display ==
'block')
636 focusItem = document.getElementById(
'Item'+itemIndex+
'_c0');
638 if (!focusItem) focusItem = this.NavNext(newIndex);
639 if (focusItem) focusItem.focus();
641 else if (this.lastKey==39)
643 var item = document.getElementById(
'Item'+itemIndex);
644 var elem = this.FindChildElement(item.parentNode.parentNode.id);
645 if (elem) elem.style.display =
'block';
647 else if (this.lastKey==37)
649 var item = document.getElementById(
'Item'+itemIndex);
650 var elem = this.FindChildElement(item.parentNode.parentNode.id);
651 if (elem) elem.style.display =
'none';
653 else if (this.lastKey==27)
655 parent.searchBox.CloseResultsWindow();
656 parent.document.getElementById(
"MSearchField").focus();
658 else if (this.lastKey==13)
665 this.NavChild =
function(evt,itemIndex,childIndex)
667 var e = (evt) ? evt : window.event;
668 if (e.keyCode==13)
return true;
669 if (!this.ProcessKeys(e))
return false;
671 if (this.lastKey==38)
675 var newIndex = childIndex-1;
676 document.getElementById(
'Item'+itemIndex+
'_c'+newIndex).focus();
680 document.getElementById(
'Item'+itemIndex).focus();
683 else if (this.lastKey==40)
685 var newIndex = childIndex+1;
686 var elem = document.getElementById(
'Item'+itemIndex+
'_c'+newIndex);
689 elem = this.NavNext(itemIndex+1);
696 else if (this.lastKey==27)
698 parent.searchBox.CloseResultsWindow();
699 parent.document.getElementById(
"MSearchField").focus();
701 else if (this.lastKey==13)
709 function setKeyActions(elem,action)
711 elem.setAttribute(
'onkeydown',action);
712 elem.setAttribute(
'onkeypress',action);
713 elem.setAttribute(
'onkeyup',action);
716 function setClassAttr(elem,attr)
718 elem.setAttribute(
'class',attr);
719 elem.setAttribute(
'className',attr);
722 function createResults()
724 var results = document.getElementById(
"SRResults");
725 for (var e=0; e<searchData.length; e++)
727 var
id = searchData[e][0];
728 var srResult = document.createElement(
'div');
729 srResult.setAttribute(
'id',
'SR_'+
id);
730 setClassAttr(srResult,
'SRResult');
731 var srEntry = document.createElement(
'div');
732 setClassAttr(srEntry,
'SREntry');
733 var srLink = document.createElement(
'a');
734 srLink.setAttribute(
'id',
'Item'+e);
735 setKeyActions(srLink,
'return searchResults.Nav(event,'+e+
')');
736 setClassAttr(srLink,
'SRSymbol');
737 srLink.innerHTML = searchData[e][1][0];
738 srEntry.appendChild(srLink);
739 if (searchData[e][1].length==2)
741 srLink.setAttribute(
'href',searchData[e][1][1][0]);
742 if (searchData[e][1][1][1])
744 srLink.setAttribute(
'target',
'_parent');
746 var srScope = document.createElement(
'span');
747 setClassAttr(srScope,
'SRScope');
748 srScope.innerHTML = searchData[e][1][1][2];
749 srEntry.appendChild(srScope);
753 srLink.setAttribute(
'href',
'javascript:searchResults.Toggle("SR_'+
id+
'")');
754 var srChildren = document.createElement(
'div');
755 setClassAttr(srChildren,
'SRChildren');
756 for (var c=0; c<searchData[e][1].length-1; c++)
758 var srChild = document.createElement(
'a');
759 srChild.setAttribute(
'id',
'Item'+e+
'_c'+c);
760 setKeyActions(srChild,
'return searchResults.NavChild(event,'+e+
','+c+
')');
761 setClassAttr(srChild,
'SRScope');
762 srChild.setAttribute(
'href',searchData[e][1][c+1][0]);
763 if (searchData[e][1][c+1][1])
765 srChild.setAttribute(
'target',
'_parent');
767 srChild.innerHTML = searchData[e][1][c+1][2];
768 srChildren.appendChild(srChild);
770 srEntry.appendChild(srChildren);
772 srResult.appendChild(srEntry);
773 results.appendChild(srResult);
777 function init_search()
779 var results = document.getElementById(
"MSearchSelectWindow");
780 for (var key in indexSectionLabels)
782 var link = document.createElement(
'a');
783 link.setAttribute(
'class',
'SelectItem');
784 link.setAttribute(
'onclick',
'searchBox.OnSelectItem('+key+
')');
785 link.href=
'javascript:void(0)';
786 link.innerHTML=
'<span class="SelectionMark"> </span>'+indexSectionLabels[key];
787 results.appendChild(link);
789 searchBox.OnSelectItem(0);