home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / CHIP_CD_2005-06.iso / bonus / ds / files / dtSearchEval650.exe / dtSearchDesktop.msi / Data1.cab / F10323_docScript.js < prev    next >
Encoding:
Text File  |  2004-03-31  |  1.1 KB  |  44 lines

  1. var firstHitDone;
  2.  
  3. function firstHit()
  4. {
  5.     if (firstHitDone != 1)
  6.         firstHitDone = gotoHit("hit1");
  7. }
  8.  
  9. function gotoHit(where)
  10. {   var a = document.anchors.item(where);
  11.     if (a == null) {
  12.         return 0;
  13.         }
  14.     if (a.length > 1) {
  15.         return 0;
  16.         }
  17.     var s = document.body.createTextRange();
  18.     if (s == null) 
  19.         return 0;
  20.  
  21.     s.moveToElementText(a);
  22.     s.moveEnd("word");
  23.  
  24.  
  25.     // IE only
  26.     var height = 0;
  27.     if (document.body && document.body.clientHeight)
  28.         height = document.body.clientHeight;
  29.     else
  30.         height = window.innerHeight;
  31.  
  32.     // This puts items in the middle of the screen, but only forces movement when they are below
  33.     // the bottom 1/5, so that we don't scroll too much and make the display jumpy
  34.     var preferredMargin = height/2;
  35.     var minimumMargin = height/5;
  36.  
  37.     if (s.offsetTop < 0)
  38.         window.scrollBy(0, s.offsetTop - preferredMargin);
  39.     else if (s.offsetTop > height - minimumMargin)
  40.         window.scrollBy(0, s.offsetTop - preferredMargin);
  41.  
  42.     s.select();
  43.     return 1;
  44. }