var req;
loading = false;

function display_sub(id) {
	element = 'menu_'+id+'c';
	mode = document.getElementById(element).style.display;
	if (mode == 'none') {
		document.getElementById(element).style.display = 'block';
	} else {
		 document.getElementById(element).style.display = 'none';
	}
}
function display_menu() {
	mode = document.getElementById('menu_container').style.display;
	if (mode == 'none') {
		document.getElementById('menu_container').style.display = 'block';
		document.getElementById('content_container').style.marginLeft = '160px';
		document.getElementById('hide_menu').style.backgroundPosition = '0px 0px';
	} else {
		document.getElementById('menu_container').style.display = 'none';
		document.getElementById('content_container').style.marginLeft = '2px';
		document.getElementById('hide_menu').style.backgroundPosition = '-10px 0px';
	}
	return false;
}

function displayLoading(mode) {
	if (mode == "off") {
		loading = false;
		document.getElementById('loading_container').style.display = "none";
	} else {
		loading = true;
		document.getElementById('loading_container').style.display = "block";
	}
}

function hideMsgBox() {
	document.getElementById('loading_message').style.display = "none";
	document.getElementById('loading_message_close').style.display = "none";
}

function ErrorMsg(msg) {
	document.getElementById('loading_message').innerHTML = msg;
	document.getElementById('loading_message').style.display = "block";
	document.getElementById('loading_message_close').style.display = "block";
}

function timedOut() {
	if (loading) {
		ErrorMsg("A response from the server has not yet been received. You can wait for a response or refresh your page to abort the process.");
	}
}

function get_page(args) {
	try {
		// Firefox, Opera 8.0+, Safari
		req = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				ErrorMsg("AJAX is not supported by your browser, please try viewing this site with a different browser.");
				return false;
			}
		}
	}
	//Process instructions
	displayLoading('on');
	//window.setTimeout("timedOut()", 10000);
	req.onreadystatechange = function() {
		if(req.readyState == 4) {
			if (req.status == 200) {
				//HTTP request is fine
				displayLoading('off');
				document.getElementById('content_main').innerHTML=req.responseText;
				req = "";
			} else {
				//Something failed, reporting error
				ErrorMsg("An error has occured accessing the system. <br />HTTP "+xmlHttp.status);
			}
		}
	}
	url = "request.php?"+args;
	req.open("GET",url,true);
	req.send(null);
}

function popup(url, name, width, height) {
	//url = "www.tigerdragonrealm.com/innersanctum/kaotien/portfolio/"+url;
	settings=
	"toolbar=no,location=no,directories=no,"+
	"status=yes,menubar=no,scrollbars=yes,"+
	"resizable=yes,width="+width+",height="+height;
	
	MyNewWindow=window.open(url,name,settings);
}