//Write info to page
function createMediaDiv(xmlDoc) {
var newDiv = document.createElement('newDiv');
var pressReleases = xmlDoc.getElementsByTagName('pressReleases'); 
var releaseYear = pressReleases[0].getElementsByTagName("releaseYear");	

//Get the number of years for releases
for (j=0; j<releaseYear.length; j++) {	
	if(selectedYear == releaseYear[j].getAttribute("year") || selectedYear == 'all') {
		var br = document.createElement('br');
		var prTable = document.createElement('table');
		prTable.setAttribute('id','prTable');
		prTable.setAttribute('cellpadding','0');
		prTable.setAttribute('cellspacing','0');
		prTable.setAttribute('width','100%');

		var prTbody = document.createElement('tbody');
		var prRow = document.createElement('tr');
		var prCell = document.createElement('td');

		var releaseYearText = document.createTextNode(releaseYear[j].getAttribute("year")); //create text for the year header
		var yearHeader = document.createElement('h2'); //create container for year header
		yearHeader.appendChild(releaseYearText); //append year text to year header

		var newsItem = releaseYear[j].getElementsByTagName("newsItem");		
		var newsUL = document.createElement('ul');
		newsUL.setAttribute('class','firstLevelUL');
		newsUL.setAttribute('className','firstLevelUL'); //for IE

		document.getElementById('pressReleases').appendChild(newDiv);//append table to div
		newDiv.appendChild(prTable);
		prTable.appendChild(prTbody); //append tbody to table
		prTbody.appendChild(prRow); //append row to tbody
		prRow.appendChild(prCell); //append cell to row
		prCell.appendChild(yearHeader);//append year to cell				

		prTbody.appendChild(prRow); //append row to tbody
		prRow.appendChild(prCell); //append cell to row
		prCell.appendChild(newsUL); //append news ul to cell 

		var backToTopP = document.createElement('p');
		backToTopP.setAttribute('align','center');
		var backToTopHR = document.createElement('img');
		backToTopHR.setAttribute('src','/assets/images/content_hr.gif');
		backToTopHR.setAttribute('height','1');
		backToTopHR.setAttribute('width','435');
		var backToTopA = document.createElement('a');
		backToTopA.setAttribute('href','#top');
		backToTopA.setAttribute('class','backToTopLink');
		backToTopA.setAttribute('className','backToTopLink');
		var backToTopText = document.createTextNode('back to top');
		var backToTopAr = document.createElement('img');
		backToTopAr.setAttribute('src','/assets/images/content_linkArrow_up.gif');
		backToTopAr.setAttribute('class','linkArrow');
		backToTopAr.setAttribute('className','linkArrow');

		newDiv.appendChild(backToTopP);//append back to top to div
		backToTopP.appendChild(backToTopHR);
		backToTopP.appendChild(backToTopA);
		backToTopA.appendChild(backToTopText);
		backToTopP.appendChild(backToTopAr);

		for (i=0; i<newsItem.length; i++) {			

			var newsLi = document.createElement('li');
			newsLi.setAttribute('class','newsFirstLevel');
			newsLi.setAttribute('className','newsFirstLevel'); //for IE
	
			//All the elements from XML to write to the page
			var htmlPath= newsItem[i].getAttribute("html"); //Path to html page
			var pdfPath = newsItem[i].getAttribute("pdf"); //Path to pdf page
			var headline = document.createTextNode(newsItem[i].getAttribute("headline")); //Headlinetext
			var date = document.createTextNode(newsItem[i].getAttribute("date")); //Date
			var htmlText = document.createTextNode('HTML'); //HTML text
			var spacer = document.createTextNode(' | '); //Seperator
			var pdfText = document.createTextNode('PDF'); //PDF text
	
			var newsIco = document.createElement('img'); //Bullet image
			newsIco.setAttribute('src','/assets/images/news_ico.gif');
			newsIco.setAttribute('id','arrow_02');
			newsIco.setAttribute('class','newsIco');
			newsIco.setAttribute('className','newsIco'); //for IE
			newsIco.setAttribute('name','arrow_02');
			newsIco.setAttribute('width','12');
			newsIco.setAttribute('height','13');
			newsIco.setAttribute('border','0');

			//Link for headline	
			var headlineLink = document.createElement('a'); 
			headlineLink.setAttribute('href',htmlPath);
			headlineLink.setAttribute('class','newsFirstLevel_ablock');
			headlineLink.setAttribute('className','newsFirstLevel_ablock'); //for IE
			
			//Span for date info
			var newsDate = document.createElement('span'); 
			newsDate.setAttribute('class','newsDate');
			newsDate.setAttribute('className','newsDate'); //for IE
	
			//Span for HTML | PDF
			var secondLinks = document.createElement('span'); 
			secondLinks.setAttribute('class','newsFirstLevel_aformat');
			secondLinks.setAttribute('className','newsFirstLevel_aformat'); //for IE
		
			//Link for HTML
			var htmlLink = document.createElement('a'); 
			htmlLink.setAttribute('href',htmlPath);
			
			//Link for PDF
			var pdfLink = document.createElement('a'); 
			pdfLink.setAttribute('href',pdfPath);
			pdfLink.setAttribute('target','_blank');
			
			newsUL.appendChild(newsLi);
			newsLi.appendChild(headlineLink);
			headlineLink.appendChild(newsIco);
			headlineLink.appendChild(headline);
						
			newsLi.appendChild(newsDate);
			newsDate.appendChild(date);
			
			newsLi.appendChild(secondLinks);
			secondLinks.appendChild(htmlLink);
			htmlLink.appendChild(htmlText);
			
			secondLinks.appendChild(spacer);
			secondLinks.appendChild(pdfLink);
			pdfLink.appendChild(pdfText);
		}
	}
		
}
}