function esObj(who){
	var Qui=(typeof(who)=='object') ? who :document.getElementById(who);
	return Qui
}

function noD(who){
	who.style.display='none'
}

function siD(who){
	who.style.display='block'
}

var nomLloc=/^(.+\/)(.+)\/$/;
var guio=/-/g;
var igual=new Array;
var urls=new Array;

window.onload=function(){
	document.getElementById('suggest').onsubmit=function(){
		return false
	};

	var inputS=document.getElementById('busc_link');
	inputS.focus();
	var noCri=document.getElementById('no-criteria');
	noD(noCri);

	inputS.onkeyup=function(e){
		var dinsInput=this.value.toLowerCase();
		var keycode=(window.event) ? window.event.keyCode : (e) ? e.which : null;

		var lis = document.getElementsByTagName("h3");
		
		for (cont = 0; cont < lis.length; cont++)
		{
			if(lis[cont].getAttribute("valido") == "true")
			{
				var llist=lis[cont];

				if(!llist)
					break;
				else
					pare=llist.parentNode.parentNode;

				var llarg=llist.innerHTML.substring(0,dinsInput.length).toLowerCase();
				nomLloc.test(llist.parentNode.href);
				if((dinsInput==llarg)||(dinsInput==RegExp.$2.replace(guio,' ').substring(0,dinsInput.length))){
					siD(pare);
					//urls.push(RegExp.$1+RegExp.$2);
					urls.push(lis[cont].getAttribute("enlace"));
					igual.push(RegExp.$2);
				}
				else
					noD(pare);
			}
		}

		if(keycode==13){
			// Modificat per Cesc. Sempre que premem enter saltarà al
			// link del primer element que tinguem.
			
			keycode='';
			window.location=urls[0]; //+'/';
			return
//			if(igual.length==1){
//				window.location=urls[0]; //+'/';
//				return
//			}
//			else
//			{
//				for(bb=0;bb<igual.length;bb++){
//					if(igual[bb].replace(guio,' ')==dinsInput){
//						window.location=urls[bb]+'/';
//						return
//					}
//				}
//			}
		}
		else
		{
			if(igual.length==0)
				siD(noCri);
			else
				noD(noCri);
		}

		igual.length=0;
		urls.length=0;
	};
};

