function getNavList(filename)
{
xmlDoc = loadXMLfile(filename);
var x = xmlDoc.documentElement.childNodes;
var mystring='<br><div id="dirheader"><p align="center" style="margin-bottom:0">';
var nodetotal=0;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType != 1) {continue;}
nodetotal++;
}
var nodecount=0;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType != 1) {continue;}
 nodecount++;


mystring += ' <a href="#' + x[i].nodeName + '">' + x[i].getAttribute('displayname') +'<\/a> ';
if (nodecount < nodetotal && nodecount%3!=0) mystring += '|';
if (nodecount%3==0)
mystring +='<br/>';
}

mystring += '<\/p></div>';
mystring +="<br/>";
return mystring;

}

function parseXML(filename,group)
{
xmlDoc = loadXMLfile(filename);
var group = xmlDoc.getElementsByTagName(group)[0];
var mystring='<br\/>';

mystring += '<table class="dirtitle" width="100%" border="0" >' +
  '<tr valign="top">'+
   '<td width="80%" height="24" valign="top"><h2 style="margin-top: 0; margin-bottom: 0"><span style="margin-top: 0; margin-bottom: 0"><strong>' + group.getAttribute('displayname')+ '<\/strong><\/span><a name="'+group.nodeName + '"><\/a>&nbsp;<\/h2><\/td>' +
   '<td width="20%" valign="top"><div align="right"><a href="#top">(top)<\/a><\/div><\/td>' +
 '<\/tr>' +
'<\/table>'
mystring += '<table class="dirlisting" width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#666666">';



    if(group.hasChildNodes()) 
	{
	//mystring +="Total Nodes: " + group.childNodes.length;
	
		i =0;
		
		while (i<group.childNodes.length)
		{
		person = group.getElementsByTagName('person')[i];
		
		//mystring +=" Nodes:" +i ;
		i++;
		
	
		if (person == null)
		{
		//mystring +=" is null/";
	//	i++;		
		continue;
		}
		if (person.nodeType != 1)
		{	
		//mystring += " is not type 1/";
	//	i++;   	
		continue;
		}
		//var j=0;
		k=0;
		
		var attrib;
		if (person!=null && person.nodeType ==1)
		mystring += '<tr><td class="col1">';
	
		while (k<person.childNodes.length)
		{
		attrib = person.getElementsByTagName("attrib")[k];
		k++;
		if (attrib == null){   continue;}
		if (attrib.nodeType!=1){   continue;}
			if(attrib.hasChildNodes() && attrib.getAttribute("type")=="name" ) 
					{
					if (attrib.getAttribute("link")!=null)
					{
					mystring += '<b><a href="'+ attrib.getAttribute("link") +'">' + attrib.firstChild.nodeValue  + '<\/a><\/b>';
					}
					else
					mystring += '<b><a">' + attrib.firstChild.nodeValue  + '<\/a><\/b>';
			
	
					}
					
				else if(attrib.hasChildNodes() && attrib.getAttribute("type")=="title") 
					{
					
					mystring += '<br\/>' + attrib.firstChild.nodeValue  + '';

					}
		
				else if(attrib.hasChildNodes() && attrib.getAttribute("type") == 'note1') 
					{
					if (attrib.getAttribute("link")!=null)
					{
					mystring += '<br\/><a href="'+ attrib.getAttribute("link") +'">' + attrib.firstChild.nodeValue  + '<\/a>';
					}
					else

					mystring += '<br\/>' + attrib.firstChild.nodeValue  + '';

					}
					else if(attrib.hasChildNodes() && attrib.getAttribute("type") == 'note2') 
					{
					if (attrib.getAttribute("link")!=null)
					{
					mystring += '<br\/><a href="'+ attrib.getAttribute("link") +'">' + attrib.firstChild.nodeValue  + '<\/a>';
					}
					else

					mystring += '<br\/>' + attrib.firstChild.nodeValue  + '';

					}
		
				else if(attrib.getAttribute("type") == 'phone1') 
					{
					mystring += '<\/td><td class="col2">';
					if(attrib.hasChildNodes()) 
					mystring += 'Phone: ' + attrib.firstChild.nodeValue  + '';

					}
				
				else if(attrib.hasChildNodes() && attrib.getAttribute("type") == 'phone2') 
					{
					
					mystring += '/ ' + attrib.firstChild.nodeValue  + '';

					}
		
				else if(attrib.hasChildNodes() && attrib.getAttribute("type") == 'phone3') 
					{
					
					mystring += '/ ' + attrib.firstChild.nodeValue  + '';

					}
				else if(attrib.hasChildNodes() && attrib.getAttribute("type") == 'address1') 
					{
					
					mystring += '<br\/>Address: ' + attrib.firstChild.nodeValue  + '';

					}
				else if(attrib.hasChildNodes() && attrib.getAttribute("type") == 'address2') 
					{
					
					mystring += '/ ' + attrib.firstChild.nodeValue  + '';

					}
				else if(attrib.hasChildNodes() && attrib.getAttribute("type") == 'email') 
					{
					
					mystring += '<br\/>Email: <a href="mailto:' + attrib.firstChild.nodeValue  +'" >'+attrib.firstChild.nodeValue+ '<\/a>';

					}
	
		}
			mystring += '<\/td><\/tr>';
		}
	
		
    }

mystring += '<\/table>';

return mystring;

}
function parseAllXML()
{
var nav = getNavList('directory.xml');
var faculty = parseXML('directory.xml','faculty');
var secfaculty = parseXML('directory.xml','secfaculty');
var researchsci = parseXML('directory.xml','researchsci');
var postdoc = parseXML('directory.xml','postdoc');
var staff = parseXML('directory.xml','staff');
var gradudate = parseXML('directory.xml','graduate');
var inter = parseXML('directory.xml','intergrad');
document.getElementById('xmlout').innerHTML = nav + faculty + secfaculty +researchsci+  postdoc+staff+ gradudate + inter;
}
