	
	// Common generic AJAX function
	function ajax(url, vars, pos) {

		/* if backend operating in "_srv/" dir */
		var thisUrl = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;
		var thisMind = thisUrl.search(/_srv/);
		if(thisMind > 0) {
			var backend = true;
		} else {
			var backend = false;
		}

		url = "http://www.realzacapital.com/_srv/altMind/ajax/" + url;
		if(pos != "" && backend == true) {
			document.getElementById("wait").style.display = "block";
		}
		var request =  new XMLHttpRequest();
		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;
				  if(pos != "" && backend == true) {
						document.getElementById("wait").style.display = "none";
					}
				}
			}
		};
		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);
	}

