// Hit navigation JavaScript for dtSearch 6
//
// Copyright 2000 dtSearch Corp.
//
// This JavaScript is included in both retrieved documents and in
// the search results list, to enable hit navigation using the
// button bar in the sample search form.  The button bar
// uses JavaScript to call these functions in the search results frame
// or in the retrieved document frame.

// The first two variables in this file may need to be changed
// if you modify dtsearch.asp to change the layout of search results.
//
// nFirstLink is the offset in search results of the first
//            link to a retrieved item.
// nLinksPerItem is the number of links for each search results item.
//            nextDoc() and prevDoc() use these values to navigate through the
//            list of links on a search results page.
//

nFirstLink = 0;
nLinksPerItem = 1;
nDoc = -1;

nHit = 0;

var simpleNav = 1;
var browser = navigator.appName;
var version = parseInt(navigator.appVersion);
var bAgt = navigator.userAgent.toLowerCase();

if ((browser.indexOf("Microsoft") != -1) && (version >= 4) && (bAgt.indexOf("mac") == -1))
    simpleNav = 0;

function setCurrentDoc(n) {
    nDoc = n;
    }

function gotoDoc(n) {
    nLink = nFirstLink + (n * nLinksPerItem);
    if (n < 0)
        return;
    if (nLink >= document.links.length) {
        alert("There are no additional documents.");
        return;
    }
    setCurrentDoc(n);
    link = document.links[nLink];
    // Can also set parent.doc.window.location.href but that sometimes crashes IE
    parent.window.open(link.href, "doc");

    if (link.y)
        // Netscape
        window.scrollTo(0, link.y);
    else
        // IE
        window.scrollTo(0, link.offsetTop + link.offsetHeight + link.offsetParent.offsetTop);

    if (!simpleNav) {
        var s = document.body.createTextRange();
        if (s == null) return;
            s.moveToElementText(link);
            s.moveEnd("word");
            s.scrollIntoView(true);
            s.select();
        }
    }

function nextDoc() {
    gotoDoc(nDoc+1);
}

function prevDoc() {
  if (nDoc > 0) {
    gotoDoc(nDoc-1);
  } else {
    alert("There are no previous documents.");
  }
}

function old_gotoHit(where) {
    window.location.hash = where;
    }

function gotoHit(where)
{   if (simpleNav) {
        old_gotoHit(where);
        return;
        }

    var a = document.anchors.item(where);
    if (a == null) return;
    if (a.length > 1) return;

    var s = document.body.createTextRange();
    if (s == null) return;

    s.moveToElementText(a);
    s.moveEnd("word");
    s.scrollIntoView(true);
    if ( where != "hit0" ) s.select();
}

function gotoNthHit(n) {
    if(n > 1 && n == maxHits) {
        gotoHit('hit_last');
    } else {
        gotoHit('hit' + n);
    }
    nHit = n;
}

function nextHit() {
    if (nHit == maxHits) {
      alert("There are no additional hits.");
    }
    else if (nHit < maxHits) {
      gotoNthHit(nHit+1);
    } else {
      gotoNthHit(maxHits);
    }
}

function prevHit() {
    if (nHit > 1) {
      gotoNthHit(nHit-1);
    } else {
      alert("There are no previous hits.");
    }
}

function highlightLink(n) {
    if (n < 0)
        return;
    if (n >= document.links.length) {
        return;
    }
    link = document.links[n];
    if (!simpleNav) {
        var s = document.body.createTextRange();
        if (s == null) return;
            s.moveToElementText(link);
            s.moveEnd("word");
						s.scrollIntoView(true);
            s.select();
        }
    }

