var xmlHttp;

window.onload = function() {
	xmlHttp = getXmlHttpObject();
	if (xmlHttp == null)
		document.getElementById('prjMain').innerHTML = "Your browser does not support Ajax, so until I implement a Web 1.0 dev section, you should download the latest version of Firefox to use this section.";
	else {
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", '/dev/project', true);
		xmlHttp.send(null);
	}
}

function prjLoad(anchor) {
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET", '/dev/project/' + anchor.href.split("#").pop(), true);
	xmlHttp.send(null);
	return false;
}

function prjDir(anchor) {
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET", '/dev/dir/' + anchor.href.split("#").pop(), true);
	xmlHttp.send(null);
	return false;
}

function stateChanged() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		xmlDoc = xmlHttp.responseXML;
		
		//alert(xmlHttp.responseText);
		
		var target = xmlDoc.getElementsByTagName('target')[0].childNodes[0].nodeValue;
		var mode = xmlDoc.getElementsByTagName('mode')[0].childNodes[0].nodeValue;
		switch (mode) {
			case 'before':
				break;
			case 'after':
				break;
			default:
				document.getElementById(target).innerHTML = xmlDoc.getElementsByTagName('html')[0].childNodes[0].nodeValue;
		}
		document.getElementById('prjBreadcrumbs').innerHTML = xmlDoc.getElementsByTagName('breadcrumbs')[0].childNodes[0].nodeValue;
	}
}

function getXmlHttpObject() {
	var xmlHttp = null;
	
	try { // Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) { // Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
