// xmlhttp.js

// Function to create an XMLHttp Object.
function getxmlhttp () {
	// Create a boolean variable to check for a valid MS ActiveX instance.
	var xmlhttp = false;
	
	// Check if we are using Internet Explorer.
	try {
		// If the JavaScript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		// If not then try the older ActiveX object.
		try {
			// If we using IE.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			// Else we are using a non-IE browser.
			xmlhttp = false;
		}
	}
	
	// If we are npt using IE, create a JavaScript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}

	return xmlhttp;
}

// Function to process an XMLHttpRequest.
function processajax (serverPage, obj, getOrPost, str) {
	// Get an XMLHttpRequest object for use.
	xmlhttp = getxmlhttp();
	if (getOrPost == "get") {
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200 || xmlhttp.status == 304)) {
				document.getElementById(obj).innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	} else {
		xmlhttp.open("POST", serverPage, true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function() {
			if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200 || xmlhttp.status == 304)) {
				document.getElementById(obj).innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(str);
	}
}

// Function to call the pages
function loadpage (newPage, container) {
	// Let the user know that the page is loading.
	document.getElementById(container).innerHTML = "<?php include('loading.php'); ?>";
	// Load the page into the container.
	processajax(newPage, container, 'get', '');	
}

