var wordInt = 0;



function chkIn(value)
{
    for (i = 0; i< glo.length; i++)
    {
        if (glo[i].charAt(0).toLowerCase() == value.charAt(0).toLowerCase()) // if we find a match
        {
            word=i; // initialize current word choice
            max = 1 // initialize best choice rating, (for each letter match add 1 to score)

            for (l=i; (glo[l].charAt(0).toLowerCase() == value.charAt(0).toLowerCase()); l++) // rate which word is closest to entry
            {
                test = chkDig(value, l); // algorithm to check number of correct letters
                if (test > max) 	// if check greater than max then update
                {
                 max = test;
                 word = l;
                }
            }

            wordInt=word;   // update navigation variable        
            return displayResult(word, ''); // write found word
        }
    }
    return displayResult(0, def[0]); // write no match found
}


function chkDig(value, i)
{
    num = 0; // count the number of matching letters
    for (j=0; j < value.length; j++)
    {
        if (glo[i].charAt(j).toLowerCase() == value.charAt(j).toLowerCase())
        num++;
    }
    return num;
}

function pageUp()
{
    if (wordInt == glo.length-2) wordInt = 1;
    else wordInt++;
    displayResult(wordInt, '');
}

function pageDown()
{
    if (wordInt > 1) wordInt--;
    else wordInt = glo.length-2;
    displayResult(wordInt, '');
}



function displayResult(word, msg)
{
	temp = glo[word];
	document.testForm.textIn.value = temp;
	document.testForm.textBox.value = temp + " " + def[word];
	document.testForm.textIn.select();
	document.testForm.textIn.focus();
}

function writeChoices(letter)
{
erase();// remove old entries
var temp = getSelLetter(letter);
temp = temp.split(",");
if (navigator.appName == "Netscape" && navigator.appVersion.indexOf("Mac") == -1) // netscape pc version ** to fix a bug in pc netscapes.
{
for (i=0; i < temp.length-1; i++)
	{
	opt = new Option(temp[i], temp[i],false,false);
	document.testForm.choices.options[i]=opt;	
	}
opt=new Option("Select a link","Select a link",true,true);
document.testForm.choices.options[temp.length]=opt;
}

else // normal browsers
{
opt=new Option("Select a link","Select a link",true,true);
document.testForm.choices.options[0]=opt;	
for (i=0; i < temp.length-1; i++)
	{
	opt = new Option(temp[i], temp[i],false,false);
	document.testForm.choices.options[i+1]=opt;		
	}
}
}



function erase()
{
var l = document.testForm.choices.length
for (i=0; i< l ; i++)
	{
	document.testForm.choices.options[l-i]=null;
	}
document.testForm.choices.options[0]=null;
return;
}

function go(place)
{
var tWord = "";
if (place != "")
	{
	place = place.split(" ");
	for (i = 0; i < place.length; i++)
		{
		tWord += place[i];
		if (place.length > i + 1)
		tWord += "_";
		}
	myLoc = "http://www.mythweb.com/encyc/entries/"+ tWord.toLowerCase() + ".html";
	window.location.href=myLoc;
	}
}

function getSelLetter(letter)
{
var temp ="";
for (i = 0; i< glo.length-1; i++)
    {
	if (glo[i].charAt(0).toLowerCase() == letter.toLowerCase())
	temp += glo[i] + ",";
	}
return temp; 
}	