

var nav4 = window.Event ? true : false;

if (document.layers)
{ 
  document.captureEvents(Event.KEYPRESS); 
}
document.onkeypress = pulsacion; 

function pulsacion(evnt) 
{
  	var cadena=extraePalabra(textoSeleccionado());
  	if (cadena.length==0) return;
  	if (nav4) 
	{
	  	keycd = evnt.which; 
	}
  	else
  	{  
	  	evnt = window.event; 
      	keycd = evnt.keyCode; 
  	}

  	if (keycd==100 || keycd==68)
  	{ 
		window.open("/include/diccenlinea.formato?palabra="+escape(cadena), "", "height=480,width=640,status,resizable");
  	}
  	else 
	{
		if (keycd==119 || keycd==87)
  		{ 
			window.open("http://es.wikipedia.org/wiki/Especial:Search?search="+escape(cadena)+"&searchGoButton=Ir", "");
	  	}
	}
} 

function extraePalabra(x) 
{
	x = x.toLowerCase();
  	x = x.replace(/[^0-9a-záéíóúàèìòùäëïöüâêîôûçñ]+/g, " ");	// sustituyo caracteres que no sean numero o letra por espacios
  	x = x.replace(/^\s+/g, "");	// quito espacios al principio
  	x = x.replace(/\s+$/g, "");	// quito espacios al final
  	return x;
}


function textoSeleccionado()
{
	if (nav4)	return document.getSelection();
	else		return document.selection.createRange().text;
}

