/* JavaScript Document

Laura Rusnak: lr310807@ohio.edu
Updated: May 21, 2009

Note: This document controls the dynamic loading of the lefthand navigation
that contains the issues anmes and numbers as well as the datefor the
footer copyright.

*/

var xmlDoc=null;
function parseNav(){	
	if(navigator.vendor == "Apple Computer, Inc."){ //Safari Only
		xmlDoc = new XMLHttpRequest();
		xmlDoc.onreadystatechange = readXMLsaf;
		xmlDoc.open("GET", "http://satjournal.tcom.ohiou.edu/a_nav.xml", true);	//change to http://satjournal.tcom.ohiou.edu/
		xmlDoc.send("");
		return(null);
	}else if (window.ActiveXObject){ //IE only
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); 
	}
	else if (document.implementation.createDocument){ //Mozilla, Firefox, Opera, etc.
		xmlDoc=document.implementation.createDocument("","",null);
	}
	else{ 
		alert('Browser cannot display left-hand journal issues navigation.'); 
	}
	
	if (xmlDoc!=null) {
		xmlDoc.async=false;
		xmlDoc.load("http://satjournal.tcom.ohiou.edu/a_nav.xml"); //change to http://satjournal.tcom.ohiou.edu/
		
		var x=xmlDoc.getElementsByTagName("journal");
		var swt = 0; //switch used in for loop
		
		//Unordered list begins here
		document.write("<ul><li class='header'>Upcoming Issue(s)</li>");
		for (i=0;i<x.length;i++){ 
			//Is the issue: future, current, or past
			str = x[i].getElementsByTagName("issueType")[0].childNodes[0].nodeValue.toLowerCase();
			//Issue number used for creating link
			iNum = x[i].getElementsByTagName("issueNum")[0].childNodes[0].nodeValue;
			//Issue name used for creating list
			iName = x[i].getElementsByTagName("issueName")[0].childNodes[0].nodeValue;
			
			//Inserts the header above the CURRENT issue and the first PAST issue.
			if (str == "current" && swt == 0){
				document.write("<li class='header'>Current Issue</li>");
				swt = 1;
			}else if(str == "past" && swt == 1){
				document.write("<li class='header'>Past Issues</li>");
				swt = 0;
			}
			
			//Writes the actual list item with link and name
			if (str == "future"){
				//no link for future issues
				document.write("<li class='item'><span style='font-weight:bold;color:#ffffff;'>Issue No. "+ iNum +":</span><br />"+ iName +"</li>");
			}else{
				document.write("<li class='item'><a href='http://satjournal.tcom.ohiou.edu/issue"+ iNum +"/main.html'>Issue No. "+ iNum +":</a><br />"+ iName +"</li>");  //change to http://satjournal.tcom.ohiou.edu/
			}
		}
		//Unordered list ends here
		document.write("</ul>");
	}
}

//XML parsing for SAFARI only.
function readXMLsaf(){
    if (xmlDoc.readyState == 4){
		if (xmlDoc.status == 200){
			var x=xmlDoc.responseXML.getElementsByTagName("journal");
			var swt = 0; //switch used in for loop
		
			//Unordered list begins here
			var jStr = "<ul><li class='header'>Upcoming Issue(s)</li>";
			for (i=0;i<x.length;i++){
				//Is the issue: future, current, or past
				str = x[i].getElementsByTagName("issueType")[0].childNodes[0].nodeValue.toLowerCase();
				//Issue number used for creating link
				iNum = x[i].getElementsByTagName("issueNum")[0].childNodes[0].nodeValue;
				//Issue name used for creating list
				iName = x[i].getElementsByTagName("issueName")[0].childNodes[0].nodeValue;
				
				//Inserts the header above the CURRENT issue and the first PAST issue.
				if (str == "current" && swt == 0){
					jStr += "<li class='header'>Current Issue</li>";
					swt = 1;
				}else if(str == "past" && swt == 1){
					jStr += "<li class='header'>Past Issue</li>";
					swt = 0;
				}
				
				//Writes the actual list item with link and name
				if (str == "future"){
					//no link for future issues
					jStr += "<li class='item'><span style='font-weight:bold;color:#ffffff;'>Issue No. "+ iNum +":</span><br />"+ iName +"</li>"; 
				}else{
					jStr += "<li class='item'><a href='http://satjournal.tcom.ohiou.edu/issue"+ iNum +"/main.html'>Issue No. "+ iNum +":</a><br />"+ iName +"</li>";
				}  //change to http://satjournal.tcom.ohiou.edu/
			}
			//Unordered list ends here
			jStr +="</ul>";
			//Writes list to the DIV: colLeft
			colLeft.innerHTML = jStr;
		}
	}
}

//year used in the copyright/footer
function dYear(){
 	var Xdate = new Date();
	var Xyear = Xdate.getFullYear();
	document.write(Xyear);	
}