// function to write last modified date of file
function modDate() {
	var ma=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var dMod=new Date (document.lastModified);
	var d=dMod.getDate();var m=dMod.getMonth();var y=dMod.getFullYear();
	var dd=d+" "+ma[m]+" "+y; 
	document.write(dd);document.write();
}

// function for common code for obtaining XML using Firefox and IE5.5 - both menu and content
function getXmlCommonCode(targ) {
	var root = xmlhttp.responseXML.documentElement; //getElementsByTagName('bcsMenu')[0];
	var sections = root.getElementsByTagName("section");
	//alert("common code in redy="+xmlhttp.readyState+" stat="+xmlhttp.status+" targ="+targ+" len="+sections.length)
	menuStr = menuStr + "<ul>";
	for (i=0; i<sections.length; i++) {
		sTitle = sections[i].getElementsByTagName("sectionTitle")[0].firstChild.nodeValue;
		sUrl = sections[i].getElementsByTagName("sectionUrl")[0].firstChild.nodeValue;
		var trigger = sections[i].getAttribute('idref');	// eg theol
		// make selected section not a hyperlink
		if (trigger == targ) {
			menuStr = menuStr + "<li class='thisone'>"+sTitle+"</li>";
		} else {
			menuStr = menuStr + "<li><a href="+sUrl+">"+sTitle+"</a></li>";
		} 							
		//alert("title="+sTitle+" sUrl="+sUrl+" trigger="+trigger); // Design etc
		if (trigger == targ) {
			//get the first subsection element
			ss = sections[i].getElementsByTagName("subSection");
			//alert("subsections="+ss.length); // subsection
			for (j=0; j<ss.length; j++) {
				ssTitle = ss[j].getElementsByTagName("subSectionTitle")[0].firstChild.nodeValue;
				htmlStr = htmlStr + "<h3>"+ssTitle+"</h3><ul>";			
				//alert("ssTitle="+ssTitle); // May 2005 etc	
				
				//get the first article element
				a = ss[j].getElementsByTagName("article");
				//alert("a="+a.length); // subsection	
				for (k=0; k<a.length; k++) {
					aTitle = a[k].getElementsByTagName("articleTitle")[0].firstChild.nodeValue;
					asTitle = a[k].getElementsByTagName("articleSubTitle")[0].firstChild.nodeValue; 
					if (asTitle == "a") {
						asTitle = '';
					}
					aUrl = a[k].getElementsByTagName("articleUrl")[0].firstChild.nodeValue;
					htmlStr = htmlStr+"<li><a class='menuc2' href="+aUrl+">"+aTitle+asTitle+"</a></li>";
					//htmlStr = htmlStr+"<li><a class='menuc2' href="+aUrl+">"+aTitle+"</a></li>";
					//alert("s="+asTitle);
					//alert("aTitle="+aTitle+" aurl="+aUrl); // May 2005 etc				
				}  // for k
				htmlStr = htmlStr +"</ul>";
			}  // for j
			if (document.getElementById)  {
				x = document.getElementById("writeroot");
				x.innerHTML = '';
				x.innerHTML = htmlStr;
			}
			//writeStrXml(document.getElementById("writeroot"),htmlStr);
		}  // if st 
	}  // for i     
	menuStr = menuStr + "<ul>";
	if (document.getElementById)  {
		x = document.getElementById("urlContent");
		x.innerHTML = '';
		x.innerHTML = menuStr;
	}
	//writeStrXml(document.getElementById("urlContent"),menuStr);
}
		

// function to provide menu for index.html
function getXmlCommonCodeIndex(targ) {
	var root = xmlhttp.responseXML.documentElement; //getElementsByTagName('bcsMenu')[0];
	var sections = root.getElementsByTagName("section");
	menuStr = menuStr + "<ul>";
	for (i=0; i<sections.length; i++) {
		sTitle = sections[i].getElementsByTagName("sectionTitle")[0].firstChild.nodeValue;
		sUrl = sections[i].getElementsByTagName("sectionUrl")[0].firstChild.nodeValue;
		var trigger = sections[i].getAttribute('idref');	// eg theol
		// make selected section not a hyperlink
		if (trigger == targ) {
			menuStr = menuStr + "<li class='thisone'>"+sTitle+"</li>";
		} else {
			menuStr = menuStr + "<li><a href="+sUrl+">"+sTitle+"</a></li>";
		} 
	}  // for i     
	menuStr = menuStr + "<ul>";
	if (document.getElementById)  {
		x = document.getElementById("urlContent");
		x.innerHTML = '';
		x.innerHTML = menuStr;
	}
	//writeStrXml(document.getElementById("urlContent"),menuStr);
}

  // this works in both Firefox and in IE
  // produces both the menu and the contents for default.html and index.html pages - find in <body onload=)
 var xmlhttp;
var htmlStr = '';
var menuStr = '';
var sTitle;
var sUrl;
var ssTitle;
var ssUrl;
var aTitle;
var asTitle;
var aUrl;
var i,j,k,a;
function getSectionAndMenuXml(url,target,idx) {
	// target is home, environ, etc
	// Set up the request
	if (window.XMLHttpRequest) { // Non-IE browsers
	 	xmlhttp = new XMLHttpRequest();
		// The callback function
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if (idx == true) {
						getXmlCommonCodeIndex(target);
					} else {
						getXmlCommonCode(target);
					}
				}  // status
			}  // ready
		}  // function
		xmlhttp.open('GET', url, true);
		xmlhttp.send(null);
	} else if (window.ActiveXObject) { // IE
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) {
		  // The callback function
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if (idx == true) {
						getXmlCommonCodeIndex(target)
					} else {
						getXmlCommonCode(target);
					}
				}  // status
			}  // ready
		}  // function
		xmlhttp.open('GET', url, true);
		xmlhttp.send(); 
		} // if xmlhttp
    }  // else if
}  // function 	

// function to import XML and display it as a text file
var req;
var which;
var ns4 = (document.layers) ? 1 : 0;
function retrieveURL(url,target) {
	if (window.XMLHttpRequest) { // Non-IE browsers
	  req = new XMLHttpRequest();
	  req.onreadystatechange = processStateChange;
	  try {
		req.open("GET", url, true);
	  } catch (e) {
		alert(e);
	  }
	  req.send(null);
	} else if (window.ActiveXObject) { // IE
	  req = new ActiveXObject("Microsoft.XMLHTTP");
	  if (req) {
		req.onreadystatechange = processStateChange;
		req.open("GET", url, true);
		req.send();
	  }
	}
}

function processStateChange() {
	//alert("rSS="+req.readyState+" rState="+req.status)
	if (req.readyState == 4) { // Complete
	  if (req.status == 200) { // OK response
		document.getElementById("urlContent").innerHTML = req.responseText;
	  } else {
		alert("Problem: " + req.statusText);
	  }
	}
}
  
// function to display xml - I think this is unused
function displaySection(s,subSection) {
	//var objDom = new XMLDoc(strXML, xmlError)
	var objDom = new XMLDoc(s, xmlError)
	//get the root node
	var objDomTree = objDom.docNode;
	//get all of the elements named section
	var secElements = objDomTree.getElements("section");
	//now get the text
	var sTitle;
	var sUrl;
	var ssTitle;
	var ssUrl;
	var aTitle;
	var asTitle;
	var aUrl;
	var st;
	var i,j,k,a;
	var str = "";
	for (i=0; i<secElements.length; i++) {
		sTitle = secElements[i].getElements("sectiontitle")[0];
		sUrl = secElements[i].getElements("sectionurl")[0];
		//alert("title="+sTitle.getText()+" sUrl="+sUrl.getText()); // Design etc
		st = sTitle.getText();
		//if (st == "Biblical Studies") {
		if (st == subSection) {
			//get the first subsection element
			ss = secElements[i].getElements("subsection");
			//alert("secele="+ss.length); // subsection
			for (j=0; j<ss.length; j++) {
				ssTitle = ss[j].getElements("subsectiontitle")[0];
				str = str + "<h3>"+ssTitle.getText()+"</h3><ul>";			
				//alert("ssTitle="+ssTitle.getText()); // May 2005 etc	
				
				//get the first article element
				a = ss[j].getElements("article");
				//alert("a="+a.length); // subsection	
				for (k=0; k<a.length; k++) {
					aTitle = a[k].getElements("articletitle")[0];  // check these two 
					asTitle = a[k].getElements("articlesubtitle")[0]; 
					aUrl = a[k].getElements("articleurl")[0];
                	str = str+"<li><a class='menuc2' href="+aUrl.getText()+">"+aTitle.getText()+asTitle.getText()+"</a></li>"; 	
					//alert("s="+asTitle);				
					//alert("ssTitle="+ssTitle.getText()+" aTitle="+aTitle.getText()+" aurl="+aUrl.getText()); // May 2005 etc				
				}
				str = str +"</ul>";
			}
			writeStrXml(document.getElementById("writeroot"),str);
		}
	}
}

// function to write to an ID
// example writeStrXml(document.getElementById("span1"),"The <b>NEW</b> text for <i>SPAN1</i><b>!</b>");
// into <span1>old text</span>
function writeStrXml(node,txtHTML){
		var newRange = document.createRange();
		newRange.selectNodeContents(node);
		newRange.deleteContents();
		var newHTML = newRange.createContextualFragment(txtHTML);
		node.appendChild(newHTML);
}
			
// function to display lefthand menu			
function displayMenu(s,section) {
	//var objDom = new XMLDoc(strXML, xmlError)
	var objDom = new XMLDoc(s, xmlError)
	//get the root node
	var objDomTree = objDom.docNode;
	//get all of the elements named section
	var secElements = objDomTree.getElements("section");
	//now get the text
	var sTitle;
	var str = "";
	for (var i=0; i<secElements.length; i++) {
		sTitle = secElements[i].getElements("sectiontitle")[0];
		sUrl = secElements[i].getElements("sectionurl")[0];		
		sTitleTxt = sTitle.getText();
		if (sTitle.getText() == section) {
			str = str + "<strong>"+sTitle.getText()+"</strong><br>";
		} else {
			str = str+"<a class='menuc2' href="+sUrl.getText()+">"+sTitle.getText()+"</a><br>";
		}
	}
	writeStrXml(document.getElementById("writemenu"),str);
}

function xmlError(e) {
	//there was an error, show the user
	alert(e);
} //end function xmlError

// ======================= for flyout menu
// for all-in one flying out menu
// function for common code for obtaining XML using Firefox and IE5.5 - both menu and content
function getXmlCommonCodeFlyOut(targ) {
	var root = xmlhttp.responseXML.documentElement; //getElementsByTagName('bcsMenu')[0];
	var sections = root.getElementsByTagName("section");
	//alert("common code in redy="+xmlhttp.readyState+" stat="+xmlhttp.status+" targ="+targ+" len="+sections.length)

	menuStr = menuStr + "<ul>";
	for (i=0; i<sections.length; i++) {
		sTitle = sections[i].getElementsByTagName("sectionTitle")[0].firstChild.nodeValue;
		sUrl = sections[i].getElementsByTagName("sectionUrl")[0].firstChild.nodeValue;

		//get the first subsection element
		ss = sections[i].getElementsByTagName("subSection");
		//alert("subsections="+ss.length); // subsection
		if (ss.length > 0) {
			menuStr = menuStr + "<ul><li class='sub'><a href="+sUrl+">"+sTitle+"</a></li>";
			for (j=0; j<ss.length; j++) {
				ssTitle = ss[j].getElementsByTagName("subSectionTitle")[0].firstChild.nodeValue;
				menuStr = menuStr + "<li class='sub'>"+ssTitle+"</li>";			
				//alert("ssTitle="+ssTitle); // May 2005 etc	
				
				//get the first article element
				a = ss[j].getElementsByTagName("article");
				//alert("a="+a.length); // subsection	
				if (a.length > 0) {
					menuStr = menuStr + "<ul>";
					for (k=0; k<a.length; k++) {
						aTitle = a[k].getElementsByTagName("articleTitle")[0].firstChild.nodeValue;  // check these two
						aUrl = a[k].getElementsByTagName("articleUrl")[0].firstChild.nodeValue;
						menuStr = menuStr+"<li><a class='menuc2' href="+aUrl+">"+aTitle+"</a></li>";
						//alert("s="+str);
						//alert("aTitle="+aTitle+" aurl="+aUrl); // May 2005 etc				
					}  // for k
					menuStr = menuStr + "</ul>";
				}  // if a.length
			}  // for j
			menuStr = menuStr +"</ul>";
		}  // if ss.length
			
			//writeStrXml(document.getElementById("writeroot"),htmlStr);
	}  // for i     
	menuStr = menuStr + "</ul>";
	if (document.getElementById)  {
		//x = document.getElementById("urlContent");
		x = document.getElementById("menu");
		x.innerHTML = '';
		x.innerHTML = menuStr;
	}
	//writeStrXml(document.getElementById("urlContent"),menuStr);
}

  // New version for flyout menu
 // this works in both Firefox and in IE
  // produces both the menu and the contents for default.html and index.html pages - find in <body onload=)
 var xmlhttp;
var htmlStr = '';
var menuStr = '';
var sTitle;
var sUrl;
var ssTitle;
var ssUrl;
var aTitle;
var aUrl;
var i,j,k,a;
function getSectionAndMenuXmlFlyOut(url,target,idx) {
	// target is home, environ, etc
	// Set up the request
	if (window.XMLHttpRequest) { // Non-IE browsers
	 	xmlhttp = new XMLHttpRequest();
		// The callback function
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if (idx == true) {
						//getXmlCommonCodeIndex(target);
						getXmlCommonCodeFlyOut(target);
					} else {
						getXmlCommonCode(target);
					}
				}  // status
			}  // ready
		}  // function
		xmlhttp.open('GET', url, true);
		xmlhttp.send(null);
	} else if (window.ActiveXObject) { // IE
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) {
		  // The callback function
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if (idx == true) {
						//getXmlCommonCodeIndex(target)
						getXmlCommonCodeFlyOut(target);
					} else {
						getXmlCommonCode(target);
					}
				}  // status
			}  // ready
		}  // function
		xmlhttp.open('GET', url, true);
		xmlhttp.send(); 
		} // if xmlhttp
    }  // else if
}  // function 	
	
// ======================= for flyout menu
// for all-in one flying out menu
// function for common code for obtaining XML using Firefox and IE5.5 - both menu and content
function getXmlCommonCodeFlyOut(targ) {
	var root = xmlhttp.responseXML.documentElement; //getElementsByTagName('bcsMenu')[0];
	var sections = root.getElementsByTagName("section");
	//alert("common code in redy="+xmlhttp.readyState+" stat="+xmlhttp.status+" targ="+targ+" len="+sections.length)

	menuStr = menuStr + "<ul>";
	for (i=0; i<sections.length; i++) {
		sTitle = sections[i].getElementsByTagName("sectionTitle")[0].firstChild.nodeValue;
		sUrl = sections[i].getElementsByTagName("sectionUrl")[0].firstChild.nodeValue;

		//get the first subsection element     
		ss = sections[i].getElementsByTagName("subSection");
		//alert("subsections="+ss.length); // subsection
		if (ss.length < 1) {
			// only a single file; no children (sub-sectioins or articles)
			menuStr = menuStr + "<li><a href='"+sUrl+"'>"+sTitle+"</a>";
		} else if (ss.length == 1) {
			// in xml sub-section called 'Contents' ie only one sub-section with articles
			menuStr = menuStr + "<li class='sub'><a href='"+sUrl+"'>"+sTitle+"<!--[if IE 7]><!--></a><!--<![endif]-->";
			menuStr = menuStr + "<!--[if lte IE 6]><table><tr><td><![endif]-->";
			//get the first article element
			a = ss[0].getElementsByTagName("article");
			if (a.length > 0) {
				menuStr = menuStr + "<ul>";
				for (k=0; k<a.length; k++) {
					aTitle = a[k].getElementsByTagName("articleTitle")[0].firstChild.nodeValue;  // check these two
					aUrl = a[k].getElementsByTagName("articleUrl")[0].firstChild.nodeValue;
					menuStr = menuStr+"<li><a href='"+aUrl+"'>"+aTitle+"</a></li>";
				}  // for k
				menuStr = menuStr + "</ul>"; 
			}  // if a.length    
			menuStr = menuStr + "</li>";
		} else {
			// has more than one sub-section with its own title and children (articles)
			menuStr = menuStr + "<li class='sub'><a href='"+sUrl+"'>"+sTitle+"</a>";
			menuStr = menuStr + "<ul>";
			for (j=0; j<ss.length; j++) {
				ssTitle = ss[j].getElementsByTagName("subSectionTitle")[0].firstChild.nodeValue;
				ssUrl = ss[j].getElementsByTagName("subSectionUrl")[0].firstChild.nodeValue;
				menuStr = menuStr + "<li class='second sub'><a href='"+ssUrl+"'>"+ssTitle+"</a>";
							
				//get the first article element
				a = ss[j].getElementsByTagName("article");
				if (a.length > 0) {
					menuStr = menuStr + "<ul>";
					for (k=0; k<a.length; k++) {
						aTitle = a[k].getElementsByTagName("articleTitle")[0].firstChild.nodeValue;  
						aUrl = a[k].getElementsByTagName("articleUrl")[0].firstChild.nodeValue;
						menuStr = menuStr+"<li><a href='"+aUrl+"'>"+aTitle+"</a></li>";
					}  // for k
					menuStr = menuStr + "</ul>"; 
				}  // if a.length    
			menuStr = menuStr + "</li>";
			}  // for j      
			menuStr = menuStr +"</ul>"; 
		}  // if ss.length
	}  // for i     
	menuStr = menuStr + "</ul>";
	//alert(menuStr);
	if (document.getElementById)  {
		//x = document.getElementById("urlContent");
		//x = document.getElementById("urlFlyout");
		x = document.getElementById("menu");
		x.innerHTML = '';
		x.innerHTML = menuStr;
	}
}

  // New version for flyout menu
 // this works in both Firefox and in IE
  // produces both the menu and the contents for default.html and index.html pages - find in <body onload=)
 var xmlhttp;
var htmlStr = '';
var menuStr = '';
var sTitle;
var sUrl;
var ssTitle;
var ssUrl;
var aTitle;
var aUrl;
var i,j,k,a;
function getSectionAndMenuXmlFlyOut(url,target,idx) {
	// target is home, environ, etc
	// Set up the request
	if (window.XMLHttpRequest) { // Non-IE browsers
	 	xmlhttp = new XMLHttpRequest();
		// The callback function
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if (idx == true) {
						//getXmlCommonCodeIndex(target);
						getXmlCommonCodeFlyOut(target);
					} else {
						getXmlCommonCode(target);
					}
				}  // status
			}  // ready
		}  // function
		xmlhttp.open('GET', url, true);
		xmlhttp.send(null);
	} else if (window.ActiveXObject) { // IE
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) {
		  // The callback function
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if (idx == true) {
						//getXmlCommonCodeIndex(target)
						getXmlCommonCodeFlyOut(target);
					} else {
						getXmlCommonCode(target);
					}
				}  // status
			}  // ready
		}  // function
		xmlhttp.open('GET', url, true);
		xmlhttp.send(); 
		} // if xmlhttp
    }  // else if
}  // function 	
		