// File: readXML.js

// Start function when DOM has completely loaded 
$(document).ready(function(){ 

	// Open the students.xml file
	$.get("xml/schedule.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<table cellspacing="0" cellpadding="0" id="table-training01">';
	  	myHTMLOutput += '<tr id="toprow-training01"><td>VENDOR</td><td>COURSE DATES</td><td>COURSE TITLE</td><td>LOCATION</td><td>AVAILABILITY</td><td>BOOKING</td></tr>';
	  	
		// Run the function for each course tag in the XML file
		$('course',xml).each(function(i) {
			courseId = $(this).attr("courseid"); 
			courseVendor = $(this).find("vendor").text();
			courseDateStart = $(this).find("fromdate").text();
			courseDateEnd = $(this).find("todate").text();
			courseTitle = $(this).find("title").text();
			courseLocation = $(this).find("location").text();
			courseAvailability = $(this).find("status").text();
			//courseId = $(this).find("course").attr("courseid"); 
			
			// Build row HTML data and store in string
			mydata = BuildCourseHTML(courseVendor,courseDateStart,courseDateEnd,courseTitle,courseLocation,courseAvailability,courseId);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea").append(myHTMLOutput);
	});
});
 
 
 
 function BuildCourseHTML(courseVendor,courseDateStart,courseDateEnd,courseTitle,courseLocation,courseAvailability,courseId){
	
	// Build HTML string and return
	output = '';
	output += '<tr>';
	output += '<td class="tdfontsize02">'+ courseVendor + '</td>';
	output += '<td class="tdfontsize02">'+ courseDateStart +' to ' + courseDateEnd +'</td>';
	output += '<td class="tdfontsize02">'+ courseTitle +'</td>';
	output += '<td class="tdfontsize02">'+ courseLocation +'</td>';
	output += '<td class="tdfontsize02">'+ courseAvailability +'</td>';
	output += '<td class="tdfontsize01"><a href="book.php?cid='+ courseId +'&ct='+ courseTitle +'&cd1='+ courseDateStart +'&cd2='+ courseDateEnd +'" class="green02">BOOK HERE</td>';
	output += '</tr>';
	return output;
}
	 
