// setup AJAX
var ajaxRequest;  // AJAX variable
try{
	// Opera 8.0+, Firefox, Safari
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	// Internet Explorer Browsers
	try{
		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){
			alert("nothing happened\n");
		}
	}
}


// request data from the server
function SignUpEmail()
{
	// create the callback function
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			document.getElementById('signupMessage').innerHTML = ajaxRequest.responseText;
		}
	}
	
	// process the query
	var emailAddr = document.getElementById('email').value;
	var query = "newsletter.php" + "?email=" + emailAddr;
	ajaxRequest.open("GET", query, true);
	ajaxRequest.send(null);
}


function DisplayMenu()
{
	document.write("<font class='menu'>");
	document.write("	<a class='menu' href='#' onclick='DisplayArticle(1, 0)'>MAIN</a>  |  ");
	document.write("	<a class='menu' href='#' onclick='DisplayGames()'>GAMES</a>  |  ");
	document.write("	<a class='menu' href='#' onclick='DisplayArticle(3, 0)'>NEWS</a>  |  ");
	document.write("	<a class='menu' href='#' onclick='DisplayCompany()'>COMPANY</a>  |  ");
	document.write("	<a class='menu' href='#' onclick='DisplayContact()'>CONTACT</a>");
	document.write("</font>");
}


function DisplayArticle(numArticles, offset)
{
	// create the callback function
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			document.getElementById('content').innerHTML = ajaxRequest.responseText;
		}
	}
	
	// process the query
	var query = "articles.php?numRows=" + numArticles + "&offset=" + offset;
	ajaxRequest.open("GET", query, true);
	ajaxRequest.send(null);
}


function DisplayGames()
{
	// create the callback function
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			document.getElementById('content').innerHTML = ajaxRequest.responseText;
		}
	}
	
	// process the query
	ajaxRequest.open("GET", "games.php", true);
	ajaxRequest.send(null);
}


function DisplayCompany()
{
	// create the callback function
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			document.getElementById('content').innerHTML = ajaxRequest.responseText;
		}
	}
	
	// process the query;
	ajaxRequest.open("GET", "companyInfo.php", true);
	ajaxRequest.send(null);
}


function DisplayContact()
{
	// create the callback function
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			document.getElementById('content').innerHTML = ajaxRequest.responseText;
		}
	}
	
	// process the query;
	ajaxRequest.open("GET", "contactInfo.php", true);
	ajaxRequest.send(null);
}


function DisplayFooter()
{
	document.write("<a href='#' onclick='DisplayArticle(1, 0)'>MAIN</a> | ");
	document.write("<a href='#' onclick='DisplayGames()'>GAMES</a> | ");
	document.write("<a href='#' onclick='DisplayArticle(3, 0)'>NEWS</a> | ");
	document.write("<a href='#' onclick='DisplayCompany()'>COMPANY</a> | ");
	document.write("<a href='#' onclick='DisplayContact()'>CONTACT</a>");
}


function PlayVideo(filename, autoplay, showControls)
{
	var attributes = "src='data/" + filename + "'";
	if(autoplay) attributes += " autoplay";
	document.write("<video " + attributes + " controls>");
	document.write("<font class='error'>If you cannot view this video, your browser does not support HTML5.</font>");
	document.write("</video>");
}

