
// initialize the request XMLHttpRequest variable
var request = false;

function CreateRequest() {
	try {
		request = new XMLHttpRequest();
	} catch(e) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(failed) {
				request = false;
			}
		}
	}

	if (!request) {
		alert("Error initializing XMLHttpRequest");
	}
}

function GetDefinition(str) {

	// trying to enable cross-site xmlhttprequests
	// borrowed from:
	// http://www.captain.at/howto-ajax-permission-denied-xmlhttprequest.php

	// there's a strange bug with this script, firefox, and firebug...
	// disabling firebug seems to get this thing working
	try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
	} catch (e) {
		// commented the following line out since it goes through IE just fine
		// alert("Permission UniversalBrowserRead denied.");
	}

	// stupid IE caching workaraound
	// since IE caches same requests, we must create a random thing here
	CreateRequest();
	var url="dictionary.php?sid=" + Math.random() + "&q=" + str;
	request.open("GET", url, true);
	request.onreadystatechange = UpdateConsequence;
	request.send(null);
}

function UpdateConsequence() {
	if (request.readyState == 4) {
		if (request.status == 200) {
			var response = request.responseText;
			document.getElementById("consequence").innerHTML += response;
		} else {
			alert(request.status);
		}
	}
}

