if (typeof vnajax == 'undefined') var vnajax = function() {
	document.write(unescape('%3Clink href="/css/ajax.css" rel="stylesheet" type="text/css" /%3E'));
	document.write(unescape('%3Cdiv id="ajaxLoaderDiv"%3E%26nbsp%3B%3C/div%3E'));
	document.write(unescape('%3Cimg id="ajaxLoaderImg" src="/images/loader.gif" onclick="vnajax.kill()" /%3E'));
	document.write(unescape('%3Cscript type="text/javascript" src="/scripts/json.js"%3E%3C/script%3E'));

	var loaders = 0, ald, ali, h, w;

	function displayAjaxLoader() {
		if (loaders == 0) {
			if (h == null) h = vnglobals.getInnerHeight();
			if (w == null) w = vnglobals.getInnerWidth();
			if (ald == null) ald = $get('ajaxLoaderDiv');
			if (ali == null) ali = $get('ajaxLoaderImg');

			ald.style.height = '100%';
			ald.style.width = '100%';
			ald.style.display = 'block';
			ald.style.zIndex = 100;
			ali.style.height = '16px';
			ali.style.width = '16px';
			ali.style.display = 'block';
			ali.style.top = (((h - 16) / 2) + vnglobals.getScrollY()) + 'px';
			ali.style.left = ((w - 16) / 2) + 'px';
			ali.style.zIndex = 101;
			document.body.style.cursor = 'wait';
		}
		loaders++;
	}
	function hideAjaxLoader() {
		loaders--;
		if (loaders < 0) loaders = 0;
		if (loaders == 0) {
			ald.style.height = '0px';
			ald.style.width = '0px';
			ald.style.display = 'none';
			ald.style.zIndex = -1;
			ali.style.height = '0px';
			ali.style.width = '0px';
			ali.style.display = 'none';
			ali.style.top = '0px';
			ali.style.left = '0px';
			ali.style.zIndex = -1;
			document.body.style.cursor = 'default';
		}
	}
	function processAjaxRequest(method, type, url, body, prepare, process, terminate, loader) {
		var xmlhttp = null;
		try { xmlhttp = new XMLHttpRequest(); }	// Firefox, Opera 8.0+, Safari
		catch (e) {
			try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } // Internet Explorer
			catch (e) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
		}
		if (xmlhttp == null) {
			alert ("Your browser must support AJAX to use this software");
			return null;
		}

		if (loader) displayAjaxLoader();
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp == null) return;
			if (xmlhttp.readyState == 4) {
				var headers = xmlhttp.getAllResponseHeaders();
				if (headers.indexOf("logged-out: true") > 0) {
					xmlhttp.abort();
					if (loader) hideAjaxLoader();
					if ($get('ajaxLoginFrame')) vnframe.open(175, 300, 60, 5, 'ajaxLoginFrame');
					if (terminate != null) terminate();
					return;
				}
				if (xmlhttp.status >= 500) {}			 // Display server error message
				else if (xmlhttp.status >= 400) {}		// Display not found error message
				else if (xmlhttp.status == 200) try {
					var response = ((type == 'xml') ? xmlhttp.responseXML :
								   (type == 'text') ? xmlhttp.responseText.trim() :
								   (type == 'json') ? xmlhttp.responseText.parseJSON() : null);
				} catch(e) { /*alert(e.message + "\n" + response); */ }

				if (process != null && response != null) process(response);
				if (terminate != null) terminate();
				if (loader) hideAjaxLoader();
			}
		}
		if (prepare != null) prepare();
		xmlhttp.open(method, url, true);
		if (method == "POST") {
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader("Content-length", body.length);
			xmlhttp.setRequestHeader("Connection", "close");
		}
		xmlhttp.send(body);
	}

	return {
		jsonget : function(url, body, prepare, process, terminate, loader) {
			processAjaxRequest('GET', 'json', url, body, prepare, process, terminate, ((loader == null) ? true : loader));
		},
		textget : function(url, body, prepare, process, terminate, loader) {
			processAjaxRequest('GET', 'text', url, body, prepare, process, terminate, ((loader == null) ? true : loader));
		},
		xmlget : function(url, body, prepare, process, terminate, loader) {
			processAjaxRequest('GET', 'xml', url, body, prepare, process, terminate, ((loader == null) ? true : loader));
		},
		jsonset : function(url, body, prepare, process, terminate, loader) {
			processAjaxRequest('POST', 'json', url, body, prepare, process, terminate, ((loader == null) ? true : loader));
		},
		textset : function(url, body, prepare, process, terminate, loader) {
			processAjaxRequest('POST', 'text', url, body, prepare, process, terminate, ((loader == null) ? true : loader));
		},
		xmlset : function(url, body, prepare, process, terminate, loader) {
			processAjaxRequest('POST', 'xml', url, body, prepare, process, terminate, ((loader == null) ? true : loader));
		},
		kill : function() {
			loaders = 0;
			hideAjaxLoader();
		}
	};
}();
