// Syphburner javascript functions
// COPYRIGHT 2008 Geert-Johan Riemer, The Netherlands
// It is not alowed to use or copy any of this functions without my strict permission.

/* Get the right movie pointed. */
function getMovieName(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	}
	else {
		return document[movieName]
	}
}

/* Change page>body>content div's innerHTML */
function changePlace(place, newData)
{
	document.getElementById(place).innerHTML = newData;
}

/* Change document title */
function changeTitle(newTitle, includeStart) {
	if(includeStart) {
		newTitle = "OpenLaserFrag: Open-Source Laser gaming system - "+newTitle+".";	
		}
	document.title = newTitle;
	}
	
function changeMenu(loc) {
		alert(loc);
}

/* open different pages and change content using one function: menu() */
function menu(loc) {
	//changePlace("menu", "<img src='images_system/ajax_loader_menu.gif' alt='content loading' border='0'><br />Menu loading");
	switch(loc) {
		case 0: //home
			//changePlace("content", "<img src='../images_system/ajax_loader_content.gif' alt='Home loading' border='0'><br />Home loading");
			changeTitle("Home", true);
		break;
		case 1: //about
			//changePlace("content", "<img src='../images_system/ajax_loader_content.gif' alt='About loading' border='0'><br />About loading");
			changeTitle("About", true);
		break;
		case 2: //guide
			//changePlace("content", "<img src='../images_system/ajax_loader_content.gif' alt='Guide loading' border='0'><br />Guide loading");
			changeTitle("Guide", true);
		break;
		case 3: //media
			//changePlace("content", "<img src='../images_system/ajax_loader_content.gif' alt='Media loading' border='0'><br />Media loading");
			changeTitle("Media", true);
		break;
		case 4: //download
			//changePlace("content", "<img src='../images_system/ajax_loader_content.gif' alt='Download loading' border='0'><br />Download loading");
			changeTitle("Download", true);
		break;
		default:
			alert("function menu(loc) received wrong parameter[0]: '"+loc+"'");
		break;
	}
	ajaxGet("menu", loc);
	ajaxGet("content", loc);
}

/* change flash menu location and global location value */
function changeLocation(loc) {
	getMovieName("MainFlashApplet").call_menu_change_js(loc); 
}

/* ajax receive content */
function ajaxGet(place, loc) {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange=function() { //word uitgevoerd als de status van object xmlHttp veranderd
		if(xmlHttp.readyState==4) { //Als laden klaar is
			changePlace(place, xmlHttp.responseText);//response schrijven
		}
	}
	xmlHttp.open("GET","load/"+place+".php?loc="+loc,true); //verbinding openen
	xmlHttp.send(null); //aanvraag versturen
}

// JavaScript file loaded successfully
var jsFiles=jsFiles+1;