// var searchURLString = "../search/searchform.html";

// -----------------
function searchURL() 
// -----------------
{
    if (typeof(searchURLString) !== "undefined") {
	var cwin = window.open(searchURLString,'_cis_search',['toolbar=yes,width=580,height=550,directories=no,status=yes,scrollbars=yes,resizable=yes,menubar=no']);   
	
	cwin.focus();  
    }
    else {
	alert("This publication has no index to search");
    }
}

// ---------------------
function getCookie(Name) 
// ---------------------
{
    var search = Name + "=";
    
    if (document.cookie.length > 0) { // if there are any cookies
	offset = document.cookie.indexOf(search);
	if (offset != -1) { // if cookie exists
	    offset += search.length;
	    // set index of beginning of value
	    end = document.cookie.indexOf(";", offset);
	    // set index of end of cookie value
	    if (end == -1) end = document.cookie.length;
	    
	    return unescape(document.cookie.substring(offset, end));                   
	}           
    }
    else return "";
}

function highlightSearchTerm() 
// --------------------------
{
    var word = getCookie("highlight");

    if (word) {
	var sc = document.getElementById('sectioncontent');  // may be null
	if (sc != null) {
	    var reg = eval("/" + word + "/gi");
	    
	    var s = sc.innerHTML;
	    sc.innerHTML = s.replace(reg, "<span class=\"index-anchor\">"+word+"</span>");
	}
    }
    
    document.cookie = "highlight=";  // Turn it off.
}

function BMLP(word) 
// ---------------
{
    document.cookie = "mybookmarkurl=" + window.location;
    document.cookie = "mybookmark=" + word;
    document.cookie = "mybookmarktitle=" + document.title;
    // alert("Set Bookmark: " + word);
    // alert("Reaffirm: " + getCookie("mybookmark"));
    // alert("Reaffirm URL: " + getCookie("mybookmarkurl"));
    
    location.reload();  // Make sure the page updates. How to update the search page?
    var sw= window.open("", _SEARCHWIN);
    if (sw) sw.location.reload();
}

function highlightBookmark(bm) 
// --------------------------
{
    if (getCookie("bookmark") == "on") {
	if (getCookie("mybookmark") == bm) {
	    document.write("<a href=\"javascript:BMLP('" + bm + "')\"><img src=\"../../images/bookmark.gif\" border=\"0\" alt=\"" + bm + "\"></a>");
	}
	else {
	    document.write("<a class=\"xxplink\" href=\"javascript:BMLP('" + bm + "')\">&para; </a>");
	}
	// did have: <span class=\"index-anchor\">" + bm + "</span></a>");  
    }
    
}

function LocalLoad() 
// -----------------
{
	highlightSearchTerm();
}
