function explain(element)
{
	var e = document.getElementById('explanation');
	e.style.display = 'block';
	var text = "<b>What it does:</b> ";
	switch(element.name)
	{
		case("inputlang") : { text += '"Automatically" will perform automatic input detection. This means it will detect '
							+ 'whether the input is western, romanised Japanese, hiragana, katakana or kanji. '
							+ 'You may wish to set this to "western" if you are searching for an English word '
							+ 'that can also be interpreted as a romanised Japanese word, according to '
							+ 'common IME romanisation rules.'; break; }
		case("stype") : { text += '"Starting with", "ending with" and "containing" should be intuitive. '
							+ 'For western input, "containing words" will find results if an entry '
							+ 'is a phrase containing the specified words ("happy" will find "happy new year", '
							+ 'for instance). "Written as" will only find results '
							+ 'consisting of, and only of, your search term. For Japanese, these do the same thing.'; break; }
		case("searchterm") : { text += 'Type your search term here. You can either use western or Japanese input, '
							+ 'but note that any text that looks like valid romaji will be considered romanised '
							+ 'Japanese.'; break; }
		case("size") : { text += 'This determines how many search results you will get on a page. The higher the number, '
						+ 'the longer the page will take to transfer from the server to your browser.'; break; }
		case("submit") : { text = 'Click here to start searching!'; break; }
	}
	e.innerHTML = text;
}

function clear_explanation()
{
	var e = document.getElementById('explanation');
	e.innerHTML = '';
	e.style.display = 'none';
}

function fit_quicknav()
{
	var d = document.getElementById('qnc');
	if (d.scrollHeight > d.clientHeight)
	{
		d.style.width = (d.offsetWidth + 25) + "px";
	}
}

// FIXME: turn this into a dialog form that can be filled out ('describe problem - report/cancel')
function question_morph(morph)
{
	alert(getContentFromURL('sendmail.php?morph='+morph));
}

// generic "get some JSON object from a URL" function (synchronised)
function getContentFromURL(url)
{
	// get information from database - is this character already defined?
	var xmlHttp;
	var error=false;
	try { xmlHttp = new XMLHttpRequest();  }
	catch (requesterror) {
		try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");  }
		catch (activexerror) {
			try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (browsererror) { error=true; alert('Your browser seems incompatible with the XMLHTTP object, this page will not work properly for you.'); }}}

	// fire off a request, if we can
	if(!error) {
		xmlHttp.open("GET", url, false);
		xmlHttp.send(null);
		// synchronous means we get the data back
		var response = xmlHttp.responseText;
		if(response!="") {
			if(response.substring(0,1)=='{') { 
				// JSON
				return eval('(' + response + ')'); }
			else { 
				// Plain text or HTML
				return response; }}}
	// failed query
	return false; 			
}
