function addEngine(name,ext,cat)
{
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) {
    window.sidebar.addSearchEngine("http://machaut.uchicago.edu/plugins/"+name+".src", "http://machaut.uchicago.edu/plugins/"+name+"."+ext, name, cat );
  } else {
  	alert("The Firefox browser or another Mozilla browser is needed to install a search plugin. Why not visit www.GetFirefox.com and install Firefox? It's an excellent browser, free and available for many platforms, and offers enhanced features and security especially compared to Internet Explorer.");
  }
}

var dictOn = true;

// I'm not calling this function anymore. I found it very annoying.

function dblDic() {
        var theSelection = getSelectedText() + "";
        if (theSelection.length > 0) {
                var theword = escape(theSelection);
		window.location = "http://machaut.uchicago.edu/?action=search&resource=Webster%27s&quicksearch=on&word=" + theword;
	}
}

function checkKeyPressed(keyEvent) {
	var theSelection = getSelectedText() + "";
	if (theSelection.length > 0) {
	  keyEvent = (keyEvent) ? keyEvent : (window.event) ? event : null;
	  if (keyEvent) {
		var charCode = (keyEvent.charCode) ? keyEvent.charCode :
					   ((keyEvent.keyCode) ? keyEvent.keyCode :
					   ((keyEvent.which) ? keyEvent.which : 0));
                var theword = escape(theSelection);
		//alert(charCode);
		if (charCode == 100) window.location = "http://machaut.uchicago.edu/?action=search&resource=Webster%27s&quicksearch=on&word=" + theword;
		if (charCode == 116) window.location = "http://machaut.uchicago.edu/?action=search&resource=Roget%27s&quicksearch=on&word=" + theword;
		if (charCode == 102) window.location = "http://machaut.uchicago.edu/?action=search&resource=English+-%3E+French&quicksearch=on&word=" + theword;
		if (charCode == 101) window.location = "http://machaut.uchicago.edu/?action=search&resource=French+-%3E+English&quicksearch=on&word=" + theword;
		if (charCode == 106) window.location = "http://machaut.uchicago.edu/?action=search&resource=conjugator&quicksearch=on&word=" + theword;
	
	  }
	}
}

function clearForms() {
        for (i=0; i < document.forms.length; i++) {
                for (j=0; j < document.forms[i].elements.length; j++) {
                        if (document.forms[i].elements[j].type == "text") {
                                document.forms[i].elements[j].value = "";
                        } else if (document.forms[i].elements[j].type == "checkbox") {
				document.forms[i].elements[j].checked = 0;
			} else if (document.forms[i].elements[j].type == "select-one") {
				document.forms[i].elements[j].selectedIndex = 0;
			}
                }
        }
}


function getSelectedText() {
	var selectText = (window.getSelection) ? window.getSelection() : 
					(document.getSelection) ? document.getSelection() :
					(document.selection) ? document.selection.createRange().text : null;
	return selectText;
}

