	function createRequest() {
		var v;
	
		try {
			v = new XMLHttpRequest(); //Mozilla and IE7
		} catch (e) {
			v = createActivexXMLHttp(); //IE6 and back
		}
	
		if (v == null)
			throw new Error("XMLHttpRequest not supported");
	
		return v;
	}

	function createActivexXMLHttp() {
		var aVersions = [ "MSXML2.XMLHttp.5.0",
			"MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
			"MSXML2.XMLHttp","Microsoft.XMLHttp"];
	
		for (var i = 0; i < aVersions.length; i++) {
			try {
				var oXmlHttp = new ActiveXObject(aVersions[i]);
				
				return oXmlHttp;
			} catch (oError) {
				//Do nothing
			}
		}
	
		throw new Error("MSXML is not installed.");
	}

	/*
	 * Utility method to allow concurrent GET requests
	 */
	function ajaxGet(url, onLoad, async, data) {
		var xhr = createRequest();
		
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if(xhr.status == 200) {
					onLoad(xhr, data);
				} else {
					alert("Failed to get Ajax reply: " + xhr.status);
				}
				xhr = null; //Avoid IE memory leak
				data = null;
			}
		}
		xhr.open("GET", url, async);
		xhr.send("");
	
	}


function showLVCDates(courseCode) {
	ajaxGet('/training/register/public/lvc/class_dates.xml', showDates, true, courseCode);
}

function showPrice(xhr, courseCode) {
	var doc = xhr.responseXML;
	var courses = doc.getElementsByTagName("course");

	for (var i = 0; i < courses.length; ++i) {
		var code = courses[i].getAttribute("code");
		
		//alert(code);
		if (code != null && code == courseCode) {
			var childList = courses[i].childNodes;
			for (var j = 0; j < childList.length; ++j) {
				//alert(childList[j].nodeName);
				if (childList[j].nodeType == 1 && childList[j].nodeName == "price") {
					var priceSpan = document.getElementById("lvc_price");
					var price = childList[j].text ? childList[j].text : childList[j].textContent;
					
					priceSpan.innerHTML = price;
				}
			}
		}
	}
}

function showDates(xhr, courseCode) {
	//alert("Showing dates: " + courseCode);
	var doc = xhr.responseXML;
	var courses = doc.getElementsByTagName("course");

	for (var i = 0; i < courses.length; ++i) {
		var code = courses[i].getAttribute("code");
		
		//alert(code);
		if (code != null && code == courseCode) {
			//alert("Found date for: " + code);
			//We have found a LVC date for this course
			//Fetch pricing
			ajaxGet('/training/register/public/lvc_prices.xml', showPrice, true, courseCode);
			//Show dates
			var list = document.getElementById("lvc_dates");
			if (list == null) {alert("List not found");}
			var childList = courses[i].childNodes;
			//alert("Number of dates found: " + childList.length);
			for (var j = 0; j < childList.length; ++j) {
				//alert(childList[j].nodeName);
				if (childList[j].nodeType == 1 && childList[j].nodeName == "date") {
					var li = document.createElement("li");
					li.innerHTML = childList[j].text ? childList[j].text : childList[j].textContent;
					//alert(li.innerHTML);
					list.appendChild(li);
				}
			}
			try {
				document.getElementById("lvc_schedule_table").style.display = "table"; //Show the table
			} catch(e) {
				document.getElementById("lvc_schedule_table").style.display = "block"; //Show the table
			}
			
			break;
		}
	}
}



