// JavaScript Document

var objContainer;
var request = false;

/**
 * Try to create a request object based on the type of browser.
 * All compliant browsers request an XMLHttpRequest object while
 * Microsoft needs a different one based on the version of IE.
 */
try {
	request = new XMLHttpRequest();
} catch (trymicrosoft) {
	try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (othermicrosoft) {
		try {
			request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (failed) {
			request = false;
		}
	}
}

/**
 * Send the request to get a new virtual tour and on state change
 * update the page.
 * @param filename A string representing the filename of the movie.
 */
function getVT(filename, container) {
	var query = "getVT.php?fn=" + escape(filename);
	objContainer = container;
	request.open("GET", query, true);
	request.onreadystatechange = updatePage;
	request.send(null);
}

/**
 * Updates the page depending on the status and state of the request object.
 */
function updatePage() {
	if (request.readyState == 4) {
		if (request.status == 200) {
			document.getElementById(objContainer).innerHTML = request.responseText;
		} else {
			document.getElementById(objContainer).innerHTML = "<p>Could not load VT</p>";
		}
	} else {
		document.getElementById(objContainer).innerHTML = "<p>Loading Virtual Tour</p>";
	}
}
