function testNum (SentNumber){
	NumCheck = /\d{1}/
	if (NumCheck.test(SentNumber)){
		return true;
	}
	else {
		return false;
	}
}


function AddFavorite() {
	
	var sURL = parent.library.document.location.href
	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)
	}
	if (sTitle=="Search Results") {
		alert ("This document is a generated list of search results, and cannot be saved as a favorite.")
	return;
	}
	parent.menu.siteFavorites.load("favorites")
	var oXMLDoc=parent.menu.siteFavorites.XMLDocument;
	var checkXML = oXMLDoc.selectNodes("//SITEINFO[TITLE='" + sTitle +"']")
	if (checkXML.length > 0) {
		alert("This document is already in your favorites list.")
		return;
	}
	var oNode=oXMLDoc.createNode(1,"SITEINFO", "");
   	var oURLNode=oXMLDoc.createNode(1,"URL", "");
   	var oTitleNode=oXMLDoc.createNode(1,"TITLE", "");
	oURLNode.text=sURL;
	oTitleNode.text = sTitle
	oNode.insertBefore(oURLNode,null)
	oNode.insertBefore(oTitleNode,null)
	oXMLDoc.documentElement.insertBefore(oNode, null);
	parent.menu.siteFavorites.save("favorites")	
}

function ListFavorites(){
	var check=0
	parent.menu.siteFavorites.load("favorites")
	var oXMLDoc = parent.menu.siteFavorites.XMLDocument.documentElement
	var cXMLDoc = oXMLDoc.selectNodes("//SITEINFO")
	if (cXMLDoc.length < 1) {
		check = 1
	}
	var wList = window.open("","fav","width=300,height=450,top=25,left=25,scrollbars=yes,resizable=yes")
	wList.document.open()
	wList.document.write("<TITLE>Favorite List</TITLE>")	
	wList.document.write("<link rel='stylesheet' href='css/summit.css' type='text/css'>")
	wList.document.write("<script src='js/favorites.js' language='JavaScript'></script>")
	wList.document.write("<BASE TARGET=\"library\">")	
	if (check == 1){
		wList.document.write ("<p>You currently have no defined favorites. </p><p><b>Use the Add To Favorites option in the Navigation menu to add the displayed page as a favorite.</b></p>")
		return;
	}
	wList.document.write("<p>Click on any of the following links:<ol>")
	for (var i=0;i<oXMLDoc.childNodes.length;i++) {
 		with (wList.document) {
			write("<li>")
			write("<A HREF=\"" + oXMLDoc.childNodes[i].childNodes[0].text + "\">")
			write(oXMLDoc.childNodes[i].childNodes[1].text)
			write("</A><BR></li>")
		}
	}
	wList.document.write("</ol>")
	wList.document.write("<br/><p><b>Or enter the number of the favorite you wish to delete:</b></p><input id='deleter' type='text' size='3'/><input type='button' value='Delete' onclick='deleteit(deleter.value,\"favorites\")'/>")
wList.focus()
}

function annotate() {
	var wList = window.open("html/Annotation.html","fav","width=600,height=300,top=200,left=150,scrollbars=yes,resizable=yes")
}


function addAnnotation() {
	if (!document.annotate.BoxOText.value) {
		alert ("Please enter annotation text. (Or close the window to not enter an Annotation.)")
		return;
	}
	if (!document.annotate.initials.value) {
		alert ("Please enter your initials.")
		return;
	}
	parent.opener.parent.menu.siteFavorites.load("annotate")
	var sURL = parent.opener.library.document.location.href
	var sTitle = parent.opener.library.document.title
    var endNum = sTitle.length
	endNum = sTitle.indexOf("(")
	if (endNum > -1) {
		sTitle = sTitle.substring (0,endNum)
	}
	var oXMLDoc=parent.opener.parent.menu.siteFavorites.XMLDocument;
	var oNode=oXMLDoc.createNode(1,"SITEINFO", "");
   	var oURLNode=oXMLDoc.createNode(1,"URL", "");
   	var oTitleNode=oXMLDoc.createNode(1,"TITLE", "");
	var oNarNode=oXMLDoc.createNode(1,"NARRATION", "");
	var oInitNode = oXMLDoc.createNode(1,"INITIALS","");
	var oDateNode = oXMLDoc.createNode(1,"DATE","");
	oURLNode.text=sURL;
	oTitleNode.text = sTitle;
	oNarNode.text = document.annotate.BoxOText.value
	oInitNode.text = document.annotate.initials.value
	oDateNode.text = checkDate()
	oNode.insertBefore(oURLNode,null)
	oNode.insertBefore(oTitleNode,null)
	oNode.insertBefore(oNarNode,null)
	oNode.insertBefore(oInitNode,null)
	oNode.insertBefore(oDateNode,null)
	oXMLDoc.documentElement.insertBefore(oNode, null);
	parent.opener.parent.menu.siteFavorites.save("annotate")
	parent.opener.annot.style.visibility = "visible"
	window.close()
}


function ListAnnotate(){
	parent.menu.siteFavorites.load("annotate")
	var check = 0 
	var sTitle = library.document.title
	var oDoc = parent.menu.siteFavorites.XMLDocument
	endNum = sTitle.indexOf(" (")
	if (endNum > -1) {
		sTitle = sTitle.substring (0,endNum)
	}
	endNum = sTitle.indexOf("(")
	if (endNum > -1) {
		sTitle = sTitle.substring (0,endNum)
	}
	var oXMLDoc = oDoc.selectNodes("//SITEINFO[TITLE='" + sTitle +"']")
		if (oXMLDoc.length < 1) {
		check = 1
	}
	if (oXMLDoc.length != 0){
	var holderNode = oDoc.createNode(1,"TOPICLIST","");
	holderNode.insertBefore(oXMLDoc.item(0).cloneNode(true), null);
	for (var j=1;j< oXMLDoc.length;j++){
     counter = 0;
     for (var k=0; k< holderNode.childNodes.length;k++){
       if (oXMLDoc.item(j).text == holderNode.childNodes.item(k).text || oXMLDoc.item(j).text == ""){
         counter=1;
         break;
         }
       else counter = 0;
       }
     if (counter == 0){
       holderNode.insertBefore(oXMLDoc.item(j).cloneNode(true), null);
       }
	  }
	}
	var wList = window.open("","fav","width=500,height=350,top=25,left=25,scrollbars=yes,resizable=yes")
	wList.document.open()
	wList.document.write("<TITLE>Annotation List</TITLE>")	
	wList.document.write("<link rel='stylesheet' href='css/summit.css' type='text/css'>")
	wList.document.write("<script src='js/favorites.js' language='JavaScript'></script>")
	wList.document.write("<BASE TARGET=\"library\">")
	if (check == 1) {
		wList.document.write ("<p>There are currently no annotations on this page.</p><p><b>To add an annotation, go to the page you wish to annotate and choose the Annotate option from the Customize menu.</b></p>")
		return;
	}
	for (var i=0;i<holderNode.childNodes.length;i++) {
 		with (wList.document) {
			write("<li>")
			write("<p>" + holderNode.childNodes[i].childNodes[2].text + " (" + holderNode.childNodes[i].childNodes[3].text + ", " + holderNode.childNodes[i].childNodes[4].text+")</p>")
			
		}
		}
wList.document.write("</A><BR></li><p><b>To delete annotations, use the List Annotations option in the Customize menu.</b></p>")	
wList.focus()
parent.menu.siteFavorites.save("annotate")
}

function ListAllAnnotate(){
	var check = 0
	parent.menu.siteFavorites.load("annotate")
	var sTitle = library.document.title
	var oDoc = parent.menu.siteFavorites.XMLDocument
	var oXMLDoc = oDoc.selectNodes("//SITEINFO")
	if (oXMLDoc.length < 1) {
		check = 1
	}
	if (oXMLDoc.length != 0){
	var holderNode = oDoc.createNode(1,"TOPICLIST","");
	holderNode.insertBefore(oXMLDoc.item(0).cloneNode(true), null);
	for (var j=1;j< oXMLDoc.length;j++){
     counter = 0;
     for (var k=0; k< holderNode.childNodes.length;k++){
       if (oXMLDoc.item(j).text == holderNode.childNodes.item(k).text || oXMLDoc.item(j).text == ""){
         counter=1;
         break;
         }
       else counter = 0;
       }
     if (counter == 0){
       holderNode.insertBefore(oXMLDoc.item(j).cloneNode(true), null);
       }
	  }
	}
	var wList = window.open("","fav","width=500,height=350,top=25,left=25,scrollbars=yes,resizable=yes")
	wList.document.open()
	wList.document.write("<TITLE>Annotation List</TITLE>")	
	wList.document.write("<link rel='stylesheet' href='css/summit.css' type='text/css'>")
	wList.document.write("<script src='js/favorites.js' language='JavaScript'></script>")
	wList.document.write("<BASE TARGET=\"library\">")
	if (check==1) {
		wList.document.write ("<p>There are currently no annotations.</p><p><b>To add an annotation, go to the page you wish to annotate and choose the Annotate option from the Customize menu.</b></p>")
		return;
	}
	else {    
	wList.document.write("<p><b>Click on any link to go to that page:</b></p><ol>")
	for (var i=0;i<holderNode.childNodes.length;i++) {
 		with (wList.document) {
			write("<li>")
			write("<a href='" + holderNode.childNodes[i].childNodes[0].text + "'>")
			write(holderNode.childNodes[i].childNodes[1].text + "</a>")
			write("<p>" + holderNode.childNodes[i].childNodes[2].text + " (" + holderNode.childNodes[i].childNodes[3].text + ", " + holderNode.childNodes[i].childNodes[4].text+")</p>")
			write("</A><BR></li>")
		}
	 }
	}
wList.document.write("</ol><br/><p><b>Or enter the number of the annotation you wish to delete:</b></p><input id='deleter' type='text' size='3'/><input type='button' value='Delete' onclick='deleteit(deleter.value,\"annotate\")'/>")	
wList.focus()
}

function deleteit(sNumber,file) {

parent.opener.parent.menu.siteFavorites.load(file)
var oXMLDoc = parent.opener.parent.menu.siteFavorites.XMLDocument.documentElement
var ourNumber = sNumber - 1
if (!testNum(sNumber)) {
	alert ("Your entry must be the number of the entry you wish to delete.")
	deleter.value=""
	return;
} 
if (oXMLDoc.childNodes(ourNumber)) {
	oXMLDoc.removeChild(oXMLDoc.childNodes[ourNumber])
	parent.opener.parent.menu.siteFavorites.save(file)
	window.close()
}
else {
	alert ("There is no entry number "+(sNumber)+". Please enter a valid number.")
}
}

function checkDate(){
   d = new Date();                           //Create Date object.
   var s = (d.getMonth() + 1) + "-";            //Get month
   s += d.getDate() + "-";                   //Get day
   s += d.getYear();                         //Get year.
   return(s);                                //Return date.
}

	