var words = new Array(0);
var doc;
function loaddict(dict)
{
	var dicttext=getFileText(dict+'.txt');
	var dictswords=dicttext.split('\n');
	words = words.concat(dictswords);
}

function definecurrentword()
{
	var defanition = doc.getElementById('Defanition_of_current_word');
	var currentword = doc.getElementById('current_word');
	var worddefanition="unknown word.";
	var i = 0;
	for(var i = 0; i < words.length && words[i].indexOf(currentword.innerHTML.toString() + " ") !== 0; ++i){}
	if(i<words.length)worddefanition=words[i];
	defanition.innerHTML="<A href=\"http://www.lojban.org/cgi-bin/dict.pl?Form=dict.pl1&Query="+currentword.innerHTML+"&Strategy=*&Database=en%3C-%3Ejbo&submit=Submit+query\">"+worddefanition+"</A>";
}

function setcontext(context){doc=context;}

function getFileText(filename) {
 oxmlhttp = null;
  if (typeof XMLHttpRequest!=='undefined'&&typeof XMLHttpRequest!=='unknown'){
    oxmlhttp = new XMLHttpRequest();
    if (oxmlhttp.overrideMimeType)
    oxmlhttp.overrideMimeType("text/xml");
    }
  else if (typeof ActiveXObject!=='undefined'&&typeof ActiveXObject!=='unknown') {
      oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
      else { return null; }
  if (typeof doc.documentElement=='object'&&(typeof oxmlhttp.open=='function'||typeof oxmlhttp.open=='unknown')){
    oxmlhttp.open("GET",filename,false);
    oxmlhttp.send(null);
    if(oxmlhttp.status == 404) {
      window.alert("URL doesn't exist!  Please contact the webmaster.");
      return false;
    } else if(oxmlhttp.status != 0&&(oxmlhttp.status != 200 /*Request OK*/) && (oxmlhttp.status != 304 /*Not modified, don't know if this will be needed, but better safe than sorry*/)) {
      window.alert("An error " + oxmlhttp.status + " has occurred!  Please alert the webmaster.");
      return false;
    }
  }else { return null; }
  return oxmlhttp.responseText;
}
