/*
	Fetch HTML data from a URL. If non-null, object_name specifies an object id
	that will have its innerHTML replaces with the URL response. If func is
	non-null it specifies a function that will be run. The XMLHttpRequest will
	be passed to this function.
*/
function fetch_data(url, func, async) {
	if (async != false) {
		async = true;
	}

	var req;

	try {
		/* Firefox, Opera 8.0+, Safari */
		req = new XMLHttpRequest();
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
		} catch (e) { }
	}
	catch (e) {
		/* Internet Explorer */
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert ("Your browser does not support this webpage!");
				return false;
			}
		}
	}

	try {
		req.open("GET",url,async);
		if (async == true) {
			req.onreadystatechange = function(event) {
				if (req.readyState == 4) {
					if (req.status == 200) {
						if ( func != null ) {
							func(req);
						}
					} else {
						func(null);
					}
				}
			}
		}
		req.send(null);
		if (async == false) {
			func(req);
		}
	}
	catch (e) {
		alert("Error processing AJAX script. "+e.description);
		return false;
	}
	return true;
}

function post_data(url, data, func, async) {
	if (async != false) {
		async = true;
	}

	var req;

	try {
		/* Firefox, Opera 8.0+, Safari */
		req = new XMLHttpRequest();
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
		} catch (e) { }
	}
	catch (e) {
		/* Internet Explorer */
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert ("Your browser does not support this webpage!");
				return false;
			}
		}
	}

	try {
		req.open("POST", url, async);
		if (async == true) {
			req.onreadystatechange = function(event) {
				if (req.readyState == 4) {
					if (req.status == 200) {
						if ( func != null ) {
							func(req);
						}
					} else {
						func(null);
					}
				}
			}
		}
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", data.length);
		req.send(data);
		if (async == false) {
			func(req);
		}
	}
	catch (e) {
		alert("Error processing AJAX script.");
		return false;
	}
	return true;
}
