/**
 * 
 */

Event.observe(window, "load", init);

function init(e)
{
	Event.observe($("recherche"), "keyup", completion);
	$('recherche').setAttribute("autocomplete", "off");
}

function completion(e)
{
	var text = $("recherche").value;
	if ((text.length >= 2))
	{
		var CustomParam = {"word":text};
		new Ajax.Request("recherche/keyword/", {
			parameters:CustomParam,
			onSuccess:function(response)
			{
				var d = response.responseJSON;
				if (d != null)
				{
					var listWord = "<ul>"
					for(var i = 0, max = d.length; i<max;i++)
					{
						listWord += '<li><a href="javascript:completeValue(\'' + d[i].mot_keyword + '\');">' + d[i].mot_keyword + '</a></li>';
					}
					listWord += "</ul>" + "<a href=\"javascript:hideCompletion();\" >Fermer</a>";
					$("completion").innerHTML = listWord;
					$("completion").style.display = "block";
				}
			}});
	}
}

function hideCompletion()
{
	$("completion").hide();
}

function completeValue(sValue)
{
	$("recherche").value = sValue;
	hideCompletion();
}
