
	// creates an XMLHttpRequest instance
	function createXMLHttpRequestObject() {
		var xmlHttp; // xmlHttp will store the reference to the XMLHttpRequest object
		try { // try to instantiate the native XMLHttpRequest object
		  xmlHttp = new XMLHttpRequest(); // create an XMLHttpRequest object
		} catch(e) {
		  try { // assume IE6 or older
		    xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
		  } catch(e) { }
		}
		if (!xmlHttp) { // return the created object or display an error message
		  alert("Error creating the XMLHttpRequest object.");
		} else {
		  return xmlHttp;
		}
	}
	
	// Common generic AJAX function
	function ajaxc(url, vars, pos) {

		var request =  new createXMLHttpRequestObject();
		request.open("POST", url, true);
		request.setRequestHeader("Content-Type",
				                     "application/x-www-form-urlencoded");
	 
		request.onreadystatechange = function() {
			var done = 4, ok = 200;
			if (request.readyState == done && request.status == ok) {
				if (request.responseText && pos != "") {
				  document.getElementById(pos).innerHTML = request.responseText;
				}
			}
		};
		request.send(vars);
	}
	
	// Encodes values for URLs
	function urlencode(string) {
		string = encodeURIComponent(string);
		return string.replace(/~/g,'%7E').replace(/%20/g,'+');
	}

	// Open centered popup window
	function OpenCentered(psUrl, psName, piWidth, piHeight, psFlags) {
		var iX=(screen.width-piWidth-20)/2;
		var iY=(screen.height-piHeight-30)/2;
		open(psUrl, psName, 'width=' + piWidth + ',height=' + piHeight + ',scrollbars=1,left=' + iX + ',top=' + iY +  ',screenX=' + iX + ',screenY=' + iY + psFlags);
	}
	
		// Page Visit Statistics
	window.onbeforeunload = statistics;
	function statistics() {
		var statsFile = document.getElementById("statsFile").value;
		var statsTime = document.getElementById("statsTime").value;
		ajaxc("http://www.sostaqua.com/_srv/altMind/ajax/save_statistics.php", "statsFile=" + statsFile + "&statsTime=" + statsTime, "");
	}
		
	function SOSTAQUA_fotogal(gal, foto) {
		document.getElementById("fotogal_cover").style.display = "block";
		document.getElementById("fotogal").style.display = "block";
		ajaxc("http://www.sostaqua.com/_srv/fotos.php", "gal=" + gal + "&foto=" + foto, "fotogal");
	}
	
	function SOSTAQUA_fotogal_close() {
		document.getElementById("fotogal_cover").style.display = "none";
		document.getElementById("fotogal").style.display = "none";
		document.getElementById("fotogal").innerHTML = "";
	}

