function runajax(objID, serverPage) {

	// Create boolean variable to check for a valid Internet Explorer instance.
	var xmlhttp = false;

try {
	// if the javascript version is greater than 5
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
	// if not try older active x object
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(E) {
	xmlhttp = false
	}
}

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}

	var obj = document.getElementById(objID);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
		xmlhttp.send(null);
}

	// Delay in milliseconds before refreshing gallery
	var refreshrate = 1000;

	// Function to show a loading message
	function updateStatus() {

		document.getElementById("errordiv").innerHTML = "";
		document.getElementById("middiv").innerHTML = "<h3>Loading...</h3>";
	}

	function refreshView() {

		// Reload the full-size image
		setTimeout('runajax("middiv","midpic.php")' ,refreshrate);

		// Relaod the navigation
		setTimeout('runajax("picdiv","picnav.php")' ,refreshrate);

	}

	function uploadimg(theform) {

		// Update user status message
		updateStatus();

		// Submit the form
		theform.submit();

		// Update the display
		refreshView();
	}

	function removeimg(theimg) {

		runajax("errordiv", "delpic.php?pic=" + theimg);
		refreshView();
	}

	function imageClick(img,idx) {

		updateStatus();
		runajax("middiv", "midpic.php?curimage=" + img);
		runajax("picdiv", "picnav.php?curimage=" + img + "&firstidx=" + idx);
	}

