var HIGHLIGHT_FLAG = true; // Flag to find whether the hit array initlized or not var g_blnInitializedHitArr = false; // a global array containing the html elements with class="VerityHit" var g_objHitArr = new Array(); var currentTerm; var currentTermIndex = -1; var objVerityHitIndex = 0; // it initializes the global array with the objects whose class name is "VerityHit". function initHitList() { if (!g_blnInitializedHitArr) { var objSpanList = document.getElementsByTagName("span"); for(var i=0; i < objSpanList.length; i++) { if (objSpanList[i].className == "VerityHit") { g_objHitArr[objVerityHitIndex] = objSpanList[i]; objVerityHitIndex++; } } g_blnInitializedHitArr = true; } } // It returns the index of the next highlighted term. function getNextHitIndex() { initHitList(); currentTermIndex++; if (currentTermIndex < g_objHitArr.length) { // we have found the current hit. return currentTermIndex; } else { currentTermIndex--; } return -1; } // It scrolls the window to the calculated y-coordinate of the next jump term. function scrollToNextHit() { var intCurrentHitIndex = getNextHitIndex(); if (intCurrentHitIndex != -1) { window.scroll(0, getYCoord(g_objHitArr[intCurrentHitIndex])); var currentObject = g_objHitArr[intCurrentHitIndex]; if (intCurrentHitIndex != 0) { var previousObject=g_objHitArr[intCurrentHitIndex - 1]; previousObject.className = "VerityHit"; } currentObject.className = "VerityHit highlight"; } else { if(objVerityHitIndex != 0) { alert("Reached the Last Term"); } } } // It returns the index of the previous highlighted term. function getPreviousHitIndex () { initHitList (); currentTermIndex--; if (currentTermIndex < 0) { currentTermIndex = 0; return -1; } else { return currentTermIndex; } } // It scrolls the window to the calculated y-coordinate of the previous jump term. function scrollToPreviousHit() { var intCurrentHitIndex = getPreviousHitIndex(); //alert ("current index = " + currentTermIndex + "|" + intCurrentHitIndex); if (intCurrentHitIndex != -1) { window.scroll(0, getYCoord(g_objHitArr[intCurrentHitIndex])); var previousObject=g_objHitArr[intCurrentHitIndex + 1]; var currentObject = g_objHitArr[intCurrentHitIndex]; currentObject.className = "VerityHit highlight"; previousObject.className = "VerityHit"; } else { alert("Reached the First Term"); } } // It returns current y coordinate of the window. function getYCoord(objElement) { var intYCoord = objElement.offsetTop; var objOffsetParent = objElement.offsetParent; while(objOffsetParent) { intYCoord += objOffsetParent.offsetTop; objOffsetParent = objOffsetParent.offsetParent; } return intYCoord; }