function go(f){
	window.location.href = "#" + f.cartouche[f.cartouche.selectedIndex].value;
	//alert(window.location.protocol+"//"+window.location.hostname+window.location.pathname + "#" + f.cartouche[f.cartouche.selectedIndex].value);
}

function esp() {
	window.location.href= "microthesaurus_detail.html";
}

function esp_lp() {
	window.location.href= "esp.html";
}

function esp_la() {
	window.location.href= "esp_la.html";
}

function historique(f) {
	if (f.histo[f.histo.selectedIndex].value == "LP"){
		window.location.href= "liste_permut.html";
	} else if (f.histo[f.histo.selectedIndex].value == "ESD")
	{
		window.location.href= "esp.html";
	} else if (f.histo[f.histo.selectedIndex].value == "MT")
	{
		window.location.href= "microthesaurus_lp.html";
	} else if (f.histo[f.histo.selectedIndex].value == "LMT")
	{
		window.location.href= "microthesaurus.html";
	}
}

/* AJAX functions */
var xhr_object = null;
var timerReq = null;

function requeteAjax() {
	if (timerReq) clearTimeout(timerReq);

	xhr_object = null;
	if (window.XMLHttpRequest) {
		/* création d'une instance de l'objet XMLHTTPRequest sous Firefox */
		xhr_object = new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
		/* création d'une instance de l'objet XMLHTTPRequest sous MSIE */
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else	{
		/* XMLHttpRequest non supporté par le navigateur */
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return false;
	}

	var data = "debut=" + document.recherche.m.value;
	xhr_object.open("POST", "http://"+window.location.hostname+"/thesaurus-motbis/site/ajax/propmot.php", true);
	xhr_object.onreadystatechange = function() {
			reponseAjax()
		};

	/* spécification de l'en-tête adéquat ; nécessaire avec POST pour préciser l'encodage */
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	/* exécution de la requête avec envoi des données à transmettre */
	xhr_object.send(data);

	return true;
}

function reponseAjax() {
	if (xhr_object.readyState == 4) {
		if (xhr_object.status == 200) {
			var obj = document.getElementById("divResult");
			if (obj) {
				var buffer = "";
				var tabMot = (xhr_object.responseText).split("\n");
				for (var i = 0; i < tabMot.length; i++) {
					var valeur = tabMot[i].replace("'", "\\'");
					if (valeur != '') {
						buffer += "<a href=\"javacript:void(0);\" onClick=\"javascript:setInput(document.recherche.m, '" + valeur + "'); document.recherche.m.focus(); return false;\">" + tabMot[i] + "</a>";
					}
				}
				obj.innerHTML = buffer;
				obj.style.display = 'block';
				adjustLayout();				
			}
		}
	}
}

function setInput(input, valeur) {
	input.value = valeur;
	document.getElementById("divResult").style.display = "none";
	return false;
}

function keypress(evt) {
	evt = (evt) ? evt : (window.event) ? event : null;
	if (evt)
	{
		var charCode = (evt.charCode) ? evt.charCode :
		((evt.keyCode) ? evt.keyCode :
			((evt.which) ? evt.which : 0));

		switch (charCode) {
			case 27:
				var obj = document.getElementById("divResult");
				if (obj) obj.style.display = 'none';
				break;
			default:
				if (timerReq) clearTimeout(timerReq);
				timerReq = setTimeout('requeteAjax();', 1000);
				break;
		}
	}
}
/******************/
