//
// Hit navigation JavaScript for the dtSearch 6 ASP sample
//
// 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 = 1;
nLinksPerItem = 1;
nDoc = -1;
var nTotHits = 0;
var nWasLast = 0;

var nHit = 0;

var simpleNav = 1;
var browser = navigator.appName;
var version = parseInt(navigator.appVersion);

if ((browser.indexOf("Microsoft") != -1) && (version >= 4))
    simpleNav = 0;

function setCurrentDoc(n) {
    nDoc = n;
    }

//function gotoDoc(n) {
//    nLink = nFirstLink + (n * nLinksPerItem);
//    if (n < 0)
//       return;
//    if (nLink >= document.links.length)
//        return;
//    setCurrentDoc(n);
//    link = parent.document.links[nLink];
//    // document.write("You came from " + document.referrer);
//    // Can also set parent.doc.window.location.href but that sometimes crashes IE
//    parent.document.location=link.href;
//
//    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(1);
//            s.select();
//        }
//   }

//function nextDoc() {
//    gotoDoc(nDoc+1);
//    }
//function prevDoc() {
//    gotoDoc(nDoc-1);
//    }


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(1);
    s.select();
}

function gotoNthHit(n) {
    gotoHit('hit' + n);
    nHit = n;
}

function nextHit() {
	var j = nHit+1
	if (document.anchors.item('hit'+j) != null) 
	{
	    gotoNthHit(nHit+1);
	    nWasLast = 0;
	}
	else
	{
		if (nWasLast == 0) nHit = nHit + 1;
		gotoHit("hit_last");
		nWasLast = 1;
	}
}
    
function prevHit() {
    if (nHit > 0)
        gotoNthHit(nHit-1);
    }

