function addEvent(objElement, strEventType, ptrEventFunc, bCapture) {
	if (bCapture == null) bCapture = false;
	if (objElement.addEventListener) objElement.addEventListener(strEventType, ptrEventFunc, bCapture);
		else if (objElement.attachEvent) objElement.attachEvent('on' + strEventType, ptrEventFunc);
}


var reSymbolsBefore = new RegExp('[\\s\\-\\(\\;\\' + String.fromCharCode(160) + ']');
var reSymbolsAfter = /[\s\-\.\,\;\)]/;

function findGlossaryItemsOnPage() {
//	var dStart = new Date();
	var sFound = '|';
	if (aGItems) {
		var oContent = document.getElementById('content');
		if (oContent) {
			for (var i in aGItems) {
				var re = new RegExp('(^|[\\s\\-\\>\\;])(' + i + ')($|[\\s\\-\\.\\,\\;\\<\\&])');
				if (re.test(oContent.innerHTML)) {
					highlightText(i, oContent);
					sFound += i + '|';
				}
			}
		}
	}
//	var dEnd = new Date();
//	alert((dEnd.getTime() - dStart.getTime()) + ': ' + sFound)
}


function highlightText(sText, oParent) {
	var oNode = oParent.firstChild;
	while(oNode) {
		switch (oNode.nodeType) {
			case 1:
				if (oNode.tagName != 'A' && oNode.tagName != 'ACRONYM') iNextParentNo = highlightText(sText, oNode);
				break;
			case 3:
				if (oNode.nodeValue.length > 0) {
					var aNodeOccurrences = getNodeOccurrences(oNode.nodeValue, sText);
					for (var i = 0; i < aNodeOccurrences.length; i++) {
						var oSelectionText = oNode.splitText(aNodeOccurrences[i][0]);
						var oLeftText = oSelectionText.splitText(aNodeOccurrences[i][1]);
						var oSelectionElem = document.createElement('acronym');
						oSelectionElem.setAttribute('title', aGItems[sText])
						oNode.parentNode.insertBefore(oSelectionElem, oNode.nextSibling);
						oSelectionElem.appendChild(oSelectionText);
//						var oDescription = document.createElement('i');
//						oDescription.className = 'description';
//						oDescription.innerHTML = '<i> (</i>' + aGItems[sText] + '<i>)</i>';
//						oSelectionElem.appendChild(oDescription);
						oNode = oLeftText;
					}
				}
				break;
		}
		oNode = oNode.nextSibling;
	}
}

function getNodeOccurrences(sNodeValue, sText) {
	var aNodeOccurrences = new Array();
//	var sNodeValue = sNodeValue.toLowerCase();

	while (sNodeValue.indexOf(sText) >= 0) {
		var iStart = sNodeValue.indexOf(sText);
		if (iStart == 0 || reSymbolsBefore.test(sNodeValue.substr(iStart - 1, 1))) {
			aNodeOccurrences[aNodeOccurrences.length] = [iStart, sText.length];
		}
		sNodeValue = sNodeValue.substr(iStart + sText.length);
	}

	return aNodeOccurrences;
}

addEvent(window, 'load', findGlossaryItemsOnPage);


// <acronym>����<i class="description"><i> (</i>���������������������&nbsp;��������� ��������� ��������� ���������<i>)</i></i></acronym>