if (window.Event)
{
	document.captureEvents(Event.KEYPRESS);
	document.captureEvents(Event.KEYUP);
}

function findwikipedia(e)
{
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
  	switch(KeyID)
   	{
    	case 119:
      	window.setTimeout("wiki_search()", 0);
      	break;
   	}
}

if (navigator.appName=="Microsoft Internet Explorer")
{
	document.onkeyup = findwikipedia;
}
else
{
	document.onkeypress = findwikipedia;
}

function wiki_search()
{
	var target='http://it.wikipedia.org/wiki/'+get_selection();
	self.name = "body";
	openWin(target, "", 750, 500, "1", "1", "1", "1", "1");
}

function get_selection()
{
	var str = new String("");
	if (window.getSelection)
	{
		str = window.getSelection().toString();
	} 
	else if (document.selection && document.selection.createRange)
	{
		var range = document.selection.createRange();
		str = range.text.toString();
	}
	str = str.replace(/[^a-zA-Z 0-9]+/g,'');
	return str;
}

function openWin(_url, _name, _w, _h, _toolb, _status, _scrollb, _resize, _loc)
{
	var _leftPos = (screen.availWidth-_w)/2, _topPos = (screen.availHeight-_h)/2;
	var _args = new Array();
	_args[0] = "alwaysRaised=1";
	_args[1] = "dependent=1";
	_args[2] = "height=" + _h;
	_args[3] = "width=" + _w;
	_args[4] = "top=" + _topPos;
	_args[5] = "left=" + _leftPos;
	_args[6] = "screenY=" + _topPos;
	_args[7] = "screenX=" + _leftPos;
	_args[8] = "menubar=1";
	_args[9] = "resizable="+ _resize;
	_args[10] = "status=" + _status;
	_args[11] = "titlebar=1";
	_args[12] = "toolbar=" + _toolb;
	_args[13] = "scrollbars=" + _scrollb;
	_args[14] = "location=" + _loc;
	var _win;
	_win = window.open(_url, _name, _args);
}