/*Master.js is loaded by every single page that opens in the main 
  window of the library.  Multiple functions are launched depending
  on the type of page that is loaded -- pageTopper controls which
  functions are launched.  */
  
  
/* Set Global variables */

var prevScr   =   "";					// Current Screen's "Previous Screen"
var nextScr   =   "";					// Current Screen's "Next Screen"
var sub1      =   "";					// Current Screen's Subject Name
var ver1      =   "";					// Current Screen's Version Number
var menuFrame;							// DOM location of menu 
var libFrame;							// DOM location of library
var textString = "";					// Search Text String
var timesFound = 0;						// Number of Search Hits in a document
var currentHit = 0;						/* Current Hit for next and previous hit
										   buttons */
var tipChecker = 9;						/* Buffer for tips, so repeats don't
										   occur */	
var bodCounter = 0;						/* Counter that keeps text search from
 	 		                               hitting an endless loop	*/		
var maximized = false;					// Library iframe not initially maximized
	

// Variables that determine where page is located in the file structure
var whichPage  = document.location.href

var regexp     = new RegExp ("subjects","gi");
var regexp2    = new RegExp ("pnewdoc","gi");
var regexp3    = new RegExp ("OLLA%20Screens","gi");

var results    = regexp.exec (whichPage);
var results2   = regexp2.exec (whichPage);
var results3   = regexp3.exec (whichPage);

var twoDeep    = (results || results2 || results3 ); /* Used to determine depth. If this is true,
														the document is deeper in the structure.*/
														


//Browser Sniffer
var IE = false;
var N4 = false;
var N6 = false;
if (document.all) {
	IE = true;
} else if (document.layers) {
	N4 = true;
} else if (document.getElementById) {
	N6 = true;
} 


/**************************************************************************/
/************************  pageTopper script  *****************************/
/**************************************************************************/

/* pageTopper is launched by every page as it's loaded into the Library
   I-Frame.  It takes care of the following:
   		1.  Sets Global Variables for other functions
		2.  Builds Menu
	*/

function pageTopper(prevScreen,nextScreen,Subject,Version,Menu) {

	/* If maximized, change the title and scoot the right margin over to 25%; if minimized
	   put the title back to SRL and scoot the right margin over to 5% */		

	if (top.maximized == true) {
		top.document.title = top.frames[1].document.title;
		top.frames[1].document.body.style.marginRight = "25%";
		}
		else {	
		top.document.title = "Spectrum Reference Library";
		top.frames[1].document.body.style.marginRight = "5%";
	}
		
	/* If Netscape 4, get the heck out of dodge. This is a safety precaution,
	   since it would be impossible to get to this point with Netscape 4*/
	if (N4){
		return;
	}
	
	/* Leave the document alone if opened outside of the frames. */
	
	
	/*if  ( top.document.title != "Spectrum Reference Library" ){
		return;
	}*/
	
	//Set Global Variables
	if (prevScreen) {
		prevScr = prevScreen
	} else {
		prevScr = ""
	}
	if (nextScreen) {
		nextScr = nextScreen
	} else {
		nextScr = ""
	}
	if (Subject) {
		sub1 = Subject
	} else {
		sub1 = ""
	}
	if (Version) {
		ver1 = Version
	} else {
		ver1 = ""
	}
	
	
	menuFrame = top.frames[0].document;
	libFrame  = top.frames[1].document;
	
		
	//Check to see where this document lies in the directory tree
	pathdots = "../../"
	if ( twoDeep ) {
		pathdots = "../../../"
	}
	
	//Reset currentHit to 0 for searches
	top.currentHit = 0;
	
	//Set the document title in the section just about the Library I-Frame.
	top.document.getElementById("topich").innerHTML = sub1 + " " + ver1;
	
	//Clear Next Hit and Previous Hit buttons
	top.document.getElementById("highNext").style.visibility="hidden";
	top.document.getElementById("highPrev").style.visibility="hidden";
		
	// Check password protection for this page.
	if ( !checkEntry() ) {
		return;
	}
	
	// Set tip settings
	checkTipDisplay( false )
	
	//Build menu.
	netMenu();
	
	//Search the current page for what's in wordBuffer
	//(with the exception of a few non-search pages).
	if ( libFrame.title != "Search Results" &&
		 libFrame.title != "Command Display Select" &&
		 libFrame.title != "Subject Display Select" &&
		 libFrame.title != "Report Selection Display" &&
		 libFrame.title != "Base OLLA Screens" &&
		 libFrame.title != "Commands by Release" ) {
		findAllWords();
	}
	
	// Set flag variable for whether or not to scroll to the first hit
	// This must occur after the search of the page itself
	if ( libFrame.title == "Search Results" ) {
		top.firstSearchPage = true;
	} else {
		top.firstSearchPage = false;
	}
	
	//Check for Annotations (does not work in Netscape)
	var sTitle = document.title
	var endNum = sTitle.length
	//Grab title of document up to the first (
	//This allows us to change the release information
	//and still hold the annotations together.
	endNum = sTitle.indexOf(" (")
	if (endNum > -1) {
		sTitle = sTitle.substring (0,endNum)
	}
	endNum = sTitle.indexOf("(")
	if (endNum > -1) {
		sTitle = sTitle.substring (0,endNum)
	}
	parent.menu.siteFavorites.load("annotate")
	var oXMLDoc= parent.menu.siteFavorites.XMLDocument;
	var checkXML = oXMLDoc.selectNodes("//SITEINFO[TITLE='" + sTitle +"']")
	//Show annotation button if necessary
	if (checkXML.length > 0) {
		top.document.getElementById("annot").style.visibility = "visible";
		top.document.getElementById("maxAnnot").style.visibility = "visible"
	}
	else {
		top.document.getElementById("annot").style.visibility = "hidden";
		top.document.getElementById("maxAnnot").style.visibility = "hidden"
	}
			
	//Set "Print Subject" option if this page is in a subject
	top.document.getElementById("printItem").style.color = "gray";
	top.document.getElementById("printItem").onclick = "";
	if ( results ) {
		top.document.getElementById("printItem").style.color = "white";
		top.document.getElementById("printItem").onclick = printSubject;
	}
	
}


/***************************************************************************/
/************************** Table of Contents Scripts **********************/
/***************************************************************************/


/* Creates menu based on contents of page. */
function netMenu() {
	// Clears the old menu data
	clearIT();

	// Establishes menu frame and sets up root UL element
	var MenuBar = parent.menu
  	var el = parent.menu.document.createElement("UL")
  	el.id = "toc"

	// Gets document data
  	var cAll = parent.library.document.all
  	var iAll = cAll.length

	// Searches through lists of heading tags and sets up menu
  	var tagList = "H1;H2;H3;H4;H5;H6;"
  	for (var i=0;i<iAll;i++)
    	if (tagList.indexOf(cAll[i].tagName+";")>=0) {
	   		if (cAll[i].tagName == "H6" || cAll[i].tagName == "H1" || cAll[i].tagName == "H2") {
	   			var eLI = parent.menu.document.createElement("P")
			}
			else {
	  			var eLI = parent.menu.document.createElement("LI")
			}
      		eLI.className = "toc" + cAll[i].tagName
      		if (cAll[i].tagName == "H6") { 
				eLI.innerHTML=cAll[i].innerHTML
				eLI.onclick=""
				eLI.onmouseover = ""
				eLI.onmouseout = ""
				eLI.id = cAll[i].id
				if (eLI.id == "Logo") {
					eLI.align = "center"	
				}
				else {
					eLI.align = "left"
				}
			}
			else {
				if(cAll[i].tagName == "H1" || cAll[i].tagName == "H2") {
					eLI.align = "left"
				} 
				eLI.id = cAll[i].id
				eLI.target = cAll[i]
				eLI.onclick = goTarget
				eLI.innerText = cAll[i].innerText
    			eLI.onmouseover = goHighlight
				eLI.onmouseout = undoHighlight
			}
		el.insertBefore(eLI)
	}
	elInner = el.innerHTML	
	parent.menu.TOC.insertAdjacentElement("afterBegin",el)
	
	//Set previous and next button values
	nex = menuFrame.getElementById("next");
	pre = menuFrame.getElementById("previous");
	//Set previous and next values for restoreDiv
    hidNex = top.document.getElementById("hnext");
	hidPre = top.document.getElementById("hprevious");
	
	pre.onclick=""
    nex.onclick=""
	hidNex.onclick=""
	hidPre.onclick=""
	hidPre.style.color=""
	hidPre.style.cursor="default"
	hidPre.onmouseover=""
	hidPre.onmouseout=""
	hidNex.style.color=""
	hidNex.style.cursor="default"
	hidNex.onmouseover=""
	hidNex.onmouseover=""
	
	pre.style.display="none"  
	nex.style.display="none"
	hidPre.style.display="none"  
	hidNex.style.display="none"
	
	if (prevScr != "") { 
		pre.onclick=goPClear;
		pre.style.display="";
		pre.onmouseover=highlightPre;
		pre.onmouseout=unhighlightPre;
		hidPre.onclick=goPrev;
		hidPre.style.display="";
		hidNex.style.color="buttontext";
		hidPre.style.cursor="hand";
		hidPre.onmouseover=highlightPre;
		hidPre.onmouseout=unhighlightPre;
	}
	if (nextScr != "") { 
		nex.onclick=goNClear;
		nex.style.display="";
		nex.onmouseover=highlightNex;
		nex.onmouseout=unhighlightNex;
		hidNex.onclick=goNext;
		hidNex.style.display="";
		hidNex.style.color="buttontext";
		hidNex.style.cursor="hand";
		hidNex.onmouseover=highlightNex;
		hidNex.onmouseout=unhighlightNex;
	}
	status = "Done."
}

/* Sets up each of the menu items with the proper attributes. Called by netMenu().*/
function addAttributes( item, menuDoc, next, list ) {
	var theClass = "className";
	if (N6) {
		theClass = "class";
	}
	item = menuDoc.createElement("LI");
	item.setAttribute('id', next.id );
	item.setAttribute( theClass, 'toc' + next.nodeName );
    item.onmouseover = goHighlight;
	item.onmouseout = undoHighlight;
	item.onclick = goTarget;
	item.innerHTML = next.innerHTML;
	list.appendChild( item );
}

/* refreshScreen is used by Netscape 6 to properly load in a new document to the 
   library I-Frame. */
function refreshScreen () {
	var b= top.document.getElementById("library").URL;
	top.document.getElementById("library").src = "";
	top.document.getElementById("library").src = b;
}

/* Clears the information in the menu frame */
function clearIT () {
	menuFrame = top.frames[0].document;
	libFrame  = top.frames[1].document;
	menuTOC  = menuFrame.getElementById("TOC");
	menuDesc = menuFrame.getElementById("description");
	menuRel  = menuFrame.getElementById("release");
	menuNar  = menuFrame.getElementById("narrative");
	
	if(menuDesc != null) {
		menuDesc.innerHTML  = "";
	}
	if(menuRel != null) {
		menuRel.innerHTML   = "";
	}
	if(menuNar != null) {
		menuNar.innerHTML   = "";
	}
	if(menuTOC != null) {
		menuTOC.innerHTML   = ""; 
	}
}

// These next two functions change the contents and bring the nav buttons back to default color.

function goNClear() {
	unhighlightNex();
	goNext();
}

function goPClear() {
	unhighlightPre();
	goPrev();
}
/* Function called by the next button in the menu frame. */
function goNext() {
	changeScreen("../Subjects/" + sub1 + "/" + sub1 + " " + nextScr + ".html");
}

/* Function called by the previous button in the menu frame. */
function goPrev() {
	changeScreen("../Subjects/" + sub1 + "/" + sub1 + " " + prevScr + ".html")
}

/* Function called when an internal menu item is clicked. */
function goTarget() {
	if (N6) {
		changeScreen(libFrame.URL + "#" + this.id);
	}
	if (IE) {
		findIt = libFrame.getElementById( this.id );
		findIt.scrollIntoView();
	}
}

/* Highlights the left-menu items on mouseover. */
function goHighlight() {
    //This will be the color of the highlight in the menu
	this.style.color="cyan" 
	}	

/* Removes highlight on mouseout */
function undoHighlight() {
	var theClass = "className"
	if (N6) {
		theClass = "class"
	}
	var theLevel = this.getAttribute( theClass );
	if ( theLevel == "tocH3" || 			    
	     theLevel == "tocH1" ||
		 theLevel == "tocH2") {
		//This should be set to the same color as regular H1s in the menu
		this.style.color="gold" } 
	else {
	    //This should be set to the same color as other headings in the menu
		this.style.color="lightyellow"}
}

/* Changes the location of the target document. */
function changeScreen(Where) {
	top.document.getElementById("library").src = Where;
}
/* The four functions control the highlighting for the next and previous buttons. */
function highlightPre() {
	hidPre.style.color="buttonhighlight";
	pre.style.color="cyan";
}

function unhighlightPre() {
	hidPre.style.color="buttontext";
	pre.style.color="bisque";
}

function highlightNex() {
	hidNex.style.color="buttonhighlight";
	nex.style.color="cyan";
}

function unhighlightNex() {
	hidNex.style.color="buttontext";
	nex.style.color="bisque";
}

/*********************************************************************/
/********************  Page Search Scripts ***************************/
/*********************************************************************/

/* locateNow() assks the user for a word, then launches locateHere to find
   that word. */
function locateNow() {
	top.firstSearchPage = true;
	var text = prompt('Enter the text you wish to find in the current document:','');
	if ( text != null ){
		locateHere( text );
		if (!gotHits) {
			alert ("The text '" + text + "' was not found on this page.");
		}
	}
	text = null;
}


/* locateHere launches a quick search through the document, wrapping the found words
   with a highlightspan. Once it is done, it assigns numeric ids to all the spans
   that are on the page.  This allows next and previous even on pages with multiple
   searches.*/
   
function locateHere( text ){
	libFrame = parent.library.document;
	bodyTag = libFrame.getElementsByTagName("body");
	currentHit = 0;
	b = 0;
	timesFound = 0;
	gotHits = false;
	
	textString = text;
	processSiblings ( bodyTag.item(0) );
	
	// Give all the span elements numeric ids 
	allHits = libFrame.getElementsByTagName("span");
	for ( a=0; a< allHits.length; a++ ){
		if ( allHits.item(a).style.background == "#ffff33" ){
			// Make sure it's a tag, and not the innerHTML
			if ( allHits.item(a).innerHTML.indexOf ("<") < 0 ){
				gotHits = true;
				allHits.item(a).id = b;
				b++;
			}
		}
	}

	// Scroll to the first one if there is one, and if this is the first 
	// page after the Search Results screen
	if ( gotHits && top.firstSearchPage == true ) {
		if (N6) {
			changeScreen(libFrame.URL + "#" + currentHit);
		} else if (IE) {
			libFrame.getElementById( currentHit ).scrollIntoView();
			libFrame.body.scrollLeft = 0;
		}
	} else {
		top.currentHit = -1;
	}
	
}

/* The processSiblings function makes the Text Search more efficient by
   heading through the siblings of the first body child element, and then
   sending those elements through processChildren. 
   Called By: locateHere*/
function processSiblings( node ) {
	firstChild = node.firstChild;
	while (firstChild.nextSibling) {
		processChildren ( firstChild );
		firstChild = firstChild.nextSibling;
	}
}

/* The processChildren function runs through the entire tree of child elements, 
   and when it encounters a text node (nodeType = 3) it sends the contents of that
   node to the replaceText function. 
   Called By:  processSiblings */
function processChildren( node ) {
	if ( node.nodeName == "PRE" ) {
		return;
	}
	for ( var i=0; i < node.childNodes.length; i++ ) {
    	if ( node.childNodes[i].nodeType==1 ) {
        	//Element node - walk children
			//alert ("Parent Node: " + node.nodeName);
            processChildren( node.childNodes[i] )
        } else if ( node.childNodes[i].nodeType==3 ) {
            // Text Node - replace the text
			beanCounter = 0;
            replaceText ( node.childNodes[i] );
		}
	}
}

/* The replaceText function searches the text for the text equivalent to the
   value of textString and replaces it with the textString surrounded by a 
   highlighting span. */
function replaceText ( node ) {
         
        /* Initialize Variables */
            newString = textString               // buffer for string manipulation
	boundary = "[a-zA-Z0-9\\\-\\\.\\\ ]";    // reg expressions that says "match if any character"
	regholder = "";                // holds regular expression

        /* This while loop sets up a string with every word in search string
           broken up by a "match any character" wherever it encounters a space.
           This enables a match on "Member-file" when the search string is
           "member file" */
	while ( newString.indexOf( " " ) > -1 ) {
		oneWord = newString.substring( 0, newString.indexOf( " " ) )
		if (oneWord != "" && oneWord != " " ) {
			regholder += oneWord + boundary;
		}
		newString = newString.substring( ( newString.indexOf( " " ) ) + 1, newString.length );
	}
	regholder += newString;

        // Set up regular expression and test for hits
	searcher = new RegExp ( regholder, "gi" );
        getAHit = searcher.exec(node.nodeValue);

	// This next section checks for A href that were changed, and
	// changes them back
	if ( node.parentNode.nodeName == "A" ) {
		fixer = new RegExp ("<span%20style='background:#ffff33' >", "gi");
		fixer2 = new RegExp ("</span>","gi");
		node.parentNode.href = node.parentNode.href.replace ( fixer, "" );
		node.parentNode.href = node.parentNode.href.replace ( fixer2, "" );
	}

        // If there are hits, wrap them in a highlighting span.
	if ( getAHit) {
		timesFound++;
		if ( timesFound > 2 ) {
			top.document.getElementById("highNext").style.visibility="visible";
		}
 
                node.parentNode.innerHTML = node.parentNode.innerHTML.replace( searcher, "<span style='background:#ffff33' >" + getAHit[0] +"</span>");
	}

	
}


/* Used by the Next Hit button to scroll to the next hit. */
function nextHigh( ) {
	libFrame = top.frames[1].document
	// Increase the number of the current hit.
	// For some reason, you have to increase and decrease by 2 (not 1);
	currentHit += 1;
	// If the hit exists scroll to it. (Both browsers use different techniques.)
	if ( libFrame.getElementById( currentHit ) ){
		if (N6) {
			changeScreen(libFrame.URL + "#" + currentHit);
		} else if (IE) {
			libFrame.getElementById( currentHit ).scrollIntoView();
			libFrame.body.scrollLeft = 0;
		}
		// Determine if next and previous buttons should show.
		if (currentHit >= 1) {
			top.document.getElementById("highPrev").style.visibility="visible";
		}
		if ( !libFrame.getElementById( currentHit + 1 ) ){
			top.document.getElementById("highNext").style.visibility="hidden";
		}
	} 
}

/* Used by the Prev. Hit button to scroll to the previous hit. */
function prevHigh( ) {
	libFrame = top.frames[1].document
	// Decrease the number of the current hit.
	// For some reason, you have to increase and decrease by 2 (not 1);
	currentHit -= 1;
	// If the hit exists scroll to it. (Both browsers use different techniques.)
	if ( libFrame.getElementById( currentHit ) ){
		if (N6) {
			changeScreen(libFrame.URL + "#" + currentHit);
		} else if (IE) {
			libFrame.getElementById( currentHit ).scrollIntoView();
			libFrame.body.scrollLeft = 0;
		}
		// Determine if next and previous buttons should show.
		if ( !libFrame.getElementById( currentHit + 1 ) ) {
			top.document.getElementById("highNext").style.visibility="hidden";
		} else {
			top.document.getElementById("highNext").style.visibility="visible";
		}
		if ( !libFrame.getElementById( currentHit - 1 ) ) {
			top.document.getElementById("highPrev").style.visibility="hidden";
		}
	} 
}

/* findAllWords() breaks down the word that is in wordBuffer into seperate
   words and then sends those words to locateHere(). */ 
function findAllWords() {
	var theWords = top.document.getElementById("wordBuffer").innerHTML;
	var oneWord = "";
	// Check for actual words
	if ( theWords == "" ) {
		return;
	}
	// If a single word, search it!
	if ( theWords.indexOf( "\"" ) < 0 ){
		locateHere( theWords );
		// Clear Buffer
		return;
	}
	// Separate words with quotes
	if ( theWords.indexOf( "\"" ) > -1 ) {
		breakOutQuotes( theWords );
	} else {
		breakOutSpaces( theWords );
	}
}

/* breakOutQuotes separates out the words for a search so that string-search
   highlighting works. */
function breakOutQuotes( theWords ) {
	while ( theWords.indexOf ( "\"" ) > -1 ) {
		preWords = theWords.substring ( 0, theWords.indexOf( "\"" ) );
		// Search any words before the quotes
		if ( preWords != "" ) {
			breakOutSpaces( preWords );
		}
		theWords = theWords.substring ( ( theWords.indexOf( "\"" ) ) + 1, theWords.length );
		//alert ( "quotes: " + theWords );
		quoteWords = theWords.substring ( 0, theWords.indexOf ( "\"" ) );
		locateHere ( quoteWords );
		theWords = theWords.substring ( ( theWords.indexOf( "\"" ) ) + 1, theWords.length );
		//alert ( "quotes: " + theWords );
	}
	breakOutSpaces( theWords );
}

/* breakOutSpaces seperates out the words in a group by spaces, and then 
   searches for each individual word. */
function breakOutSpaces( theWords ) {
	// Break it up if words have spaces and search all of the words.
	while ( theWords.indexOf( " " ) > -1 ) {
		oneWord = theWords.substring( 0, theWords.indexOf( " " ) )
		if (oneWord != "" && oneWord != " " ) {
			locateHere ( oneWord );
		}
		theWords = theWords.substring( ( theWords.indexOf( " " ) ) + 1, theWords.length );
		//alert ( "spaces: " + theWords );
	}
	// Don't miss the last one.
	if ( theWords != "" && theWords != " " ) {
		locateHere ( theWords );
	}
}


/***************************************************************************/
/***************************  Cookie Scripts  ******************************/
/***************************************************************************/


/* Function setCookie sets a cookie.  The parameters are as follows:
		A. name = name of the cookie
		  	currently valid names:  
		  		1.  cuName = Credit Union Name
				2.  cuAddr = Credit Union Home Page URL
				3.  Q      = Current Password
				4.  fosSet = boolean - is front office protected?
				5.  bosSet = boolean - is back office protected?
				6.  opsSet = boolean - is operations protected?
				7.  dpset  = boolean - is data processing protected?
				8.  tip    = boolean - Are tips on?
				9.  tutor  = boolean - has tutorial software been downloaded?
		B. value = the value of the cookie
		C. fromWindow = are you setting this value from a new window?  True or
		   false
*/
function setCookie( name, value, fromWindow ) {
  	/* The expiration data is sometime in 2022, so it should be plenty of time.*/
	var expireD = new Date();
	expireD.setTime( expireD.getTime() + ( 999999 * 24 * 60 * 60 * 1000 ) );
  	if ( fromWindow ) {
  		// This may need to change for Netscape.  Keep an eye out for it.
    	opener.parent.document.cookie = name + "=" + escape( value ) + "; expires=" + ( expireD.toGMTString() );
  	} else { 
   		top.document.cookie = name + "=" + escape( value ) + "; expires=" +                 ( expireD.toGMTString() );
 	} 
}

/* function getCookie returns the value of a cookie.  As with setCookie, the 
   parameter fromWindow is a boolean that is true only if the cookie is being
   queried from a new window (not the main SRL window). If no cookie exists
   this function returns a null.*/
function getCookie(name, fromWindow){
 	var cookieName = name + "=";               
 	if ( fromWindow ) {
		// This may need to change for Netscape.
  		var dc = opener.document.cookie 
	} else {
  		var dc = top.document.cookie 
	}             
  	if ( dc.length > 0 ) {              
    	begin = dc.indexOf( cookieName );       
    		if ( begin != -1 ) {           
      			begin += cookieName.length;       
      			end = dc.indexOf(";", begin);
      			if ( end == -1 ) {
					end = dc.length;
				}
        		return unescape( dc.substring( begin, end ) );
    		} 
  	}
  	return null;
}

/***********************************************************************/
/*************** Customized Credit Union Link Scripts ******************/
/***********************************************************************/


/* Asks the user for the credit union name and the credit union home page internet
   address then sets those to cookie values cuName and cuAddr. */
function newCU() {
	// Set Credit Union Name	
	var cuName = prompt ( 'Please enter your Credit Union Name:', '' )
	if ( ( cuName != null) && ( cuName != "") ) {
		setCookie( 'cuName', cuName )
	}
	else {
		setCookie( 'cuName', null )
	}
	// Set Credit Union Home Page Address
	var cuAddr = prompt ( 'Please enter the internet address of your home page: (Example: http://www.summitsite.com)', '' )
	if ( ( cuAddr != null) && ( cuAddr != "") ) {
		setCookie( 'cuAddr', cuAddr )
	}
	else {
		setCookie( 'cuAddr', null )
	}
	// Change the display if there is a name set.
	if ( cuName != null && cuName != "" ) {
		top.document.getElementById("creditU").innerHTML = cuName;
	}
}

/* The goCreditUnion() function is launched when the customized credit union name
   is cliked.  It finds the address from the cookies, and goes there. */
function goCreditUnion() {
	if ( (getCookie( 'cuAddr' ) != null) || (getCookie( 'cuAddr' ) != 'null') ){
		top.document.getElementById("creditU").href = getCookie( 'cuAddr' )
	}
}


/********************************************************************/
/*******************  Password Protection Scripts  ******************/
/********************************************************************/

/* Encryption-related global variables */

bs="\\";
cs=' !"#$%&';
cs+="'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRS"
+"TUVWXYZ^[_]`abcdefghijklmnopqrstuvwxyz{|}~\t\r\n"+bs;
cm=0;
cm1=0;
cflg="";
sixteen="0000 0001 0010 0011 0100 0101 0110 0111 "
       +"1000 1001 1010 1011 1100 1101 1110 1111 ";
sixletter=";    .    *    ,    x    `    i    :    "
         +"_    -    ^    <    >    '    ~    =    ";
prevScr = ""
nextScr = ""
sub1 = ""
ver1 = ""

/* putIn encrypts a word, and returns the encrypted value.  Any password comparisons
   that must take place should be compared against encrypted values.  It is very
   tough to create the encrypted word itself. */ 
function putIn(wordSearch){
	ls="";
	ls1="";
	kwd="Summit";
	kwdpd=kwd;
	msg=wordSearch;
	if (!wordSearch) {
		return("")
	}
 	if (!msg.length) {
		return("")
	}
 	if (cflg==0){
  		sl=msg.length;
  	} else{
  		sl=msg.length/2;
  	}
	while (kwd.length<sl){
  		kwd+=kwdpd;
  	}
 	for (var i=0;i<msg.length;i++){
  		chk=kwd.charAt(i);
  		cmk=cs.indexOf(chk)+32;
  		chm=msg.charAt(i);
  		cmm=cs.indexOf(chm)+32;
  		for (var j=7;j>-1;j--){
   			c=Math.pow(2,j);
   			if (cmk>=c){
    			cmk=cmk-c;
    			ls+="1";
    		} else{
    			ls+="0"
    		}
   			if (cmm>=c){
    			cmm=cmm-c;
    			ls1+="1";
    		} else{
    			ls1+="0"
    		}
   		}
  	}
 	ls2="";
 	ls4="";
 	for (var i=0;i<ls1.length;i++){
  		ch=ls.charAt(i);
  		ch1=ls1.charAt(i);
  		if (ch=="0"){
   			if (ch1=="0"){
    			ch1="1";
    		} else{
    			ch1="0";
    		} 
   		}
  		ls2+=ch1;
  	}
	for (var i=0;i<ls2.length;i=i+4){
  		ls3=ls2.substring(i,i+4);
  		y=sixteen.indexOf(ls3);
  		ls4+=sixletter.charAt(y);
  	}
 	return(ls4); 
}

/* The checkEntry() function runs through the cookies and determines if the current
   document is protected by a password.  If it is protected, it asks the user for the
   password.  The user has two chances to get it right,  if not it does the
   following:
   				In Internet Explorer: Goes back one page
				In Netscape Navigator: Returns to the home page
   The browsers differ in how they interpret the history.back() or history.go(-1) 
   functions.  Internet Explorer changes the history of the current I-frame, while
   Netscape Navigator changes the history of the Top window. */
function checkEntry(){
		var docT = top.frames[1].document.title
		var goPa = 0
		// Do these words exist in the document's title?
		var BosCheck = docT.indexOf("Back Office")
		var DpCheck= docT.indexOf("Data Processing")
		var FosCheck = docT.indexOf("Front Office")
		var OpsCheck = docT.indexOf("Operations")
		
		// Are there any passwords that affect this document?
		if ( (BosCheck != -1 && getCookie('bosSet') == 'true') ||  
		     (DpCheck  != -1 && getCookie('dpSet')  == 'true') ||  
			 (FosCheck != -1 && getCookie('fosSet') == 'true') ||  
			 (OpsCheck != -1 && getCookie('opsSet') == 'true') ) {
			
			if (getCookie('Q') != null) {
				
				if (getCookie('Q') != "") {
					message = "Access Restricted.  Please enter Password:"
					checkPas = prompt(message,"")
					if (!checkPas) {
						backScreen();
						return false;
					} else {
					if ( putIn(checkPas) != getCookie('Q') ){
						alert ('The password you entered was incorrect. Please re-enter')
						checkPas=prompt(message,"")
						if (!checkPas) {
							backScreen();
							return false;
				   		} else {
					    	if (putIn(checkPas) != getCookie('Q')){
						   	alert ('Sorry, that password is incorrect.')
							backScreen();
							return false;
							}
						}
					}
					}
				}
			}
		}
	return true;
}

/* The function backScreen() does the following:		
				In Internet Explorer: Goes back one page
				In Netscape Navigator: Returns to the home page
   The browsers differ in how they interpret the history.back() or history.go(-1) 
   functions.  Internet Explorer changes the history of the current I-frame, while
   Netscape Navigator changes the history of the Top window. */
function backScreen () {
	history.go(-1);
}

/*********************************************************************/
/********************* New Window Scripts ****************************/
/*********************************************************************/

/* The addWindow functions do just that -- they add windows.  Each one adds
   a window with a slightly different look to it, either in size or position.
   I'm thinking that we should try and keep the number of the addWindow functions
   to a minimum, creating new functions only for completely different window
   types.  Each window that is created must then be closed when the main
   screen is unloaded.  (We don't want any rogue windows hanging around after
   the user has closed the library. */
   
/* addWindow1 adds the window for the Remote */   
function addWindow1( winLocation ) {
	var curURL = "";
	winStats='toolbar=no,location=no,directories=no,menubar=no,'
   	winStats+='scrollbars=no,'
   	if ( IE ) {
      	winStats+=',left=50,top=50,width=385,height=270'
    } else {
      	winStats+=',screenX=50,screenY=50,width=425,height=270'
    }
	if ( window.adWindow1 ) {
		if ( window.adWindow1.location ) {
			curURL = "" + window.adWindow1.location
		}
		if ( curURL == "" ) {
		   	adWindow1=window.open( winLocation, "", winStats)
			adWindow1.focus() 
		} else {
			window.adWindow1.location.href = winLocation
			adWindow1.focus()
		}
		
	} else {
   		adWindow1=window.open( winLocation, "", winStats) 
   		adWindow1.focus() 
	}
}

/* addWindow2 is used for generating the Tips window. */
function addWindow2( winLocation ) {
	var curURL = "";
	winStats='toolbar=no,location=no,directories=no,menubar=no,'
   	winStats+='scrollbars=no,'
   	if ( IE ) {
      	winStats+=',left=50,top=50,width=200,height=325'
    }else{
      	winStats+=',screenX=50,screenY=50,width=200,height=325'
    }
	if ( window.adWindow2 ) {
		if ( window.adWindow2.location ) {
			curURL = "" + window.adWindow2.location
		}
		if ( curURL == "" ) {
		   	adWindow2=window.open( winLocation, "", winStats)
			adWindow2.focus() 
		} else {
			window.adWindow2.location.href = winLocation
			adWindow2.focus()
		}
		
	} else {
   		adWindow2=window.open( winLocation, "", winStats) 
   		adWindow2.focus() 
	}
} 

/*******************************************************************/
/**********************  Tips Scripts ******************************/
/*******************************************************************/


/* Sets the tips that show up in the tip box.  If you need to add a tip,
   place it at the end of the list starting with ti[ti.length] =     */
function randTip () {
	ti = new Array()
	ti[ti.length] = "Add Favorites for individual sections of the Library by using Add to Favorites in the Navigation menu. If you set a favorite in Internet Explorer, the favorite will be for the library itself, not the individual section."
	ti[ti.length] = "Set annotations through the Annotation option in the Customize menu."
	ti[ti.length] = "View all annotations in the library by using the List Annotations option in the Customize menu.  You can also use this list as an annotated favorites list."
	ti[ti.length] = "An icon appears next to the title of that page if the page contains an annotation.  Click the icon to display the annotations."
	ti[ti.length] = "Turn tips off or back on by clicking Tips On/Off in the Customize menu."
	ti[ti.length] = "Search results can be selected to appear in either the main display area (where the documents appear) or in a separate pop-up window.  Use the Search menu to select either Main Display or New Window."
	ti[ti.length] = "Clicking any entry in the table of contents on the left side of the page will take you to that section immediately."
	ti[ti.length] = "Set Password protection for various sections of the library by using the Security option in the Customize menu."
	ti[ti.length] = "To set a link to your credit union's home page use the Set CU Home Page option in the Customize menu."
	ti[ti.length] = "Right-click within the document itself and choose Print to print an individual section. To print an entire subject, go to a document within that subject, and select the Print Subject option in the Navigation menu."
	ti[ti.length] = "The search engine is more powerful than in previous editions of the library.  To see examples of effective search queries, see <a target='library' href='SearchTips.html' >Search Engine Tips</a>."
	ti[ti.length] = "It is possible to insert an image, such as a logo, in the upper-right-hand corner of the display by using the Set CU Home Page option in the Customize menu. To do so, insert the HTML for an image (&lt;img src='<i>graphic.gif</i>'>) when prompted for the CU Name."
	ti[ti.length] = "View pages using the entire window by clicking the Maximize icon on the navigation bar, or by selecting Maximize from the Navigation menu ."
	
	rNum=Math.round(Math.random()*(ti.length - 1 ))
	while ( rNum == tipChecker ) {
		rNum=Math.round(Math.random()*(ti.length- 1))
	}
	tipChecker = rNum;
	document.getElementById("tipMessage").innerHTML = ti[rNum]
}

/* Determines current condition of tips, and toggles to opposite condition
   when called.  */
function turnTips () {
	var condition;
	var tipsOn = false;
	
	if ( getCookie ('tip') == 'true' ){
		tipsOn = true;
	}
	
	if ( tipsOn ) {
		setCookie('tip','false')
		tipsOn = false;
		condition= "off";
	} else {
		setCookie('tip','true')
		tipsOn = true;
		condition="on";
	}
	textmessage = "Pop-up tip messages are now " + condition + "."
	if ( tipsOn ) {
		if (confirm( textmessage + " Press OK to refresh the screen.")) {
			top.document.location.reload();
		}
		else {
		}
	}
	else {
		alert ( textmessage );
	}
	checkTipDisplay ( false );
}

/* Checks cookie for the current Tip setting and sets it accordingly. */
function checkTipDisplay ( fromNewWindow ) {

 	var place = parent.document
	if ( fromNewWindow ) { 
		place = opener.parent.document;
		checkCookie = getCookie( 'tip', true );
	}
	else
	{
		checkCookie = getCookie( 'tip' );
	}
	if (checkCookie == 'true') {
		place.getElementById("tipsItem").innerHTML = "Tips On*/Off"
		return true;
	}
	if ((checkCookie == 'false') || (checkCookie == null)) {
		place.getElementById("tipsItem").innerHTML = "Tips On/Off*"
		return false;
	}
	return true;
}

/* Checks cookie for the current Tip setting and sets it accordingly. */
function checkSearchDisplay () {

	checkCookie = getCookie( 'M' );
	if (checkCookie == '1') {
		document.getElementById("newItem").innerHTML = "New Window*";
		document.getElementById("mainItem").innerHTML = "Main Display";
	
	}
	if ((checkCookie == '0') || (checkCookie == null)) {
		document.getElementById("newItem").innerHTML = "New Window";
		document.getElementById("mainItem").innerHTML = "Main Display*";
		
	}
	
}



// Tutorial window pop-up that holds the tutorial objects and scripts.
// Delete after objects in place in container.

/*function newWindow(file,window) {
     tutWindow = open('',window,'resizable=yes, width=200, height=200, left=0, top=0, status=yes');
     tutWindow.location.href = file;
     if (tutWindow.opener == null) tutWindow.opener = self;
}*/

/* Places the A-Z links in the header for the glossary */
function alphaTop2() {
	top.document.getElementById("topich").innerHTML = alpha
	netMenu();
}

function printSubject() {
	/* Launched when the user selects the "print subject" option.  
	   Then, it just loads in the appropriate subject printer.html file
	   and the file itself does the rest of the work.  */
	var sTitle = parent.library.document.title
	var check = ":"
    var endNum = sTitle.length
	endNum = sTitle.indexOf(" :")
    if (endNum > -1) {
		sTitle = sTitle.substring (0,endNum)
	}
	endNum = sTitle.indexOf(":")
	if (endNum > -1) {
		sTitle = sTitle.substring (0,endNum)
	}
	changeScreen("../Subjects/"+ sTitle + "/" + sTitle +" printer.html")
}

function addWindow4(winName,winTitle) {
   winStats='toolbar=no,location=no,directories=no,menubar=no,status=no,'
   winStats+='scrollbars=no,'
   if(screen.availWidth <=800 || screen.availHeight <=600)   
	{
   winStats+=',left=100,top=50,width=520,height=420'}
   else{
      winStats+=',left=150,top=100,width=630,height=542'
	  }
		if ((results) || (results2) || (results3)) {
			winName = "../" + winName
			}
		if (window.adWindow4) {
			curURL = "" + window.adWindow4.location
		if (curURL == "") {
		    adWindow4=window.open(winName,"",winStats) 
   			adWindow4.focus() }
		else {
			adWindow4.focus()}
	}
	else {
   adWindow4=window.open(winName,"",winStats) 
   adWindow4.focus() 
	}
}

// These next two functions are for the Program Files from RDID

function doit(header){
	var head=header.style
	if (head.display=="none") 
			head.display=""
	else
			head.display="none"
}

function addWindow5 (winName, winWidth, winHeight){
	winStats = 'toolbar=no,location=no,directories=no,menubar=no,'
	winStats += 'scrollbars=yes,width=' + winWidth + ',height=' + winHeight
	if (navigator.appName.indexOf ("Microsoft") >= 0)
	{
		winStats += ',left=100,top=100'
	}
	else
	{
		winStats += ',screenX=100,screenY=100'
	}
	curURL = ""
	if (window.adWindow5)
	{
		curURL = "" + window.adWindow5.location
	}
	if (curURL == "")
	{
		tempName = ""
	}
	if (tempName == winName)
	{
		adWindow5.focus ()
	}
	else
	{
		adWindow5 = window.open (winName,"",winStats) 
		adWindow5.focus ()
		tempName = winName
	}
}