//don't forget to add <body ondblclick="dictionary()">





function dictionary() 
{





		if (navigator.appName != 'Microsoft Internet Explorer') 
		{
//var txt = window.getSelection().getRangeAt(0).toString();
//alert(txt);
		//var t = document.getSelection();
		//od(t);

		//var t = window.document.getSelection().getRangeAt(0).toString();
		//od(t);

		var t = window.document.getSelection().toString();

//TRIM
t = t.replace(/^\s*|\s*$/g,"");
var palabras=t.indexOf(" ");


//SI PALABRAS == -1 ES UNA SOLA PALABRA 

                if (palabras == -1 && t != '' && t != '.' && t != ' ' && t != null  && t != '. ' && t != ',' && t != ', ' && t != '...' && t != '... ' && t != ')'  && t != ') ')
                 {
		od(t);
	         }

		}
		else 
		{
	if (document.selection.type == 'Text')
	{
		var t = document.selection.createRange();





//SOLO ACEPTAR UNA PALABRA

  // Obtenemos el texto del area.
  textoArea = t.text;


  // El numero de caracteres es su longitud
  numeroCaracteres = textoArea.length;

  // Eliminamos los caracteres en blanco del inicio y del final.
  // Como no tenemos funciones del tipo trim, rtrim y ltrim usamos
  // expresiones regulares
  // El ^ indica principio de cadena
  inicioBlanco = /^ /
  // El $ indica final de cadena
  finBlanco = / $/
  // El global (g) es para obtener todas las posibles combinaciones
  variosBlancos = /[ ]+/g 


  textoArea = textoArea.replace(inicioBlanco,"");
  textoArea = textoArea.replace(finBlanco,"");
  textoArea = textoArea.replace(variosBlancos," ");

  // Creamos un array con las diferentes palabras. Teniendo en 
  // cuenta que la separación entre palabras es el espacio en blanco.
  textoAreaDividido = textoArea.split(" ");
  numeroPalabras = textoAreaDividido.length;

  // Mostramos los datos.
  // Tendremos en cuenta si hay que escribir en plural o en singular.
  tC = (numeroCaracteres==1)?" carácter":" caracteres";
  tP = (numeroPalabras==1)?" palabra":" palabras";
     
  //alert (numeroCaracteres + tC +"\n" + numeroPalabras + tP);



                if (numeroPalabras == 1)
                 {

		if(document.selection.type == 'Text' && t.text>'') 
        {
		document.selection.empty();

		od(t.text);


	}//FIN SI ES TEXTO

                 }


		}


}













function od(t) {


dominio=window.location.hostname;

//dominio ='xunta.es';

//dominio=document.domain;



//alert(dominio);


if (navigator.appName!='Microsoft Internet Explorer') 
{
window.open('http://www.digalego.com/diccionario/Html/muestra_palabra.php?op=ver&dominio='+dominio+'&buscado='+encodeURIComponent(t), 'dict', 'width=700,height=500,resizable=1,menubar=0,scrollbars=1,status=1,titlebar=1,toolbar=0,location=0,personalbar=0');
}
else
{

t=t.replace(/[!.:?,;"]/, '');
while (t.substr(t.length-1,1)==' ') 
	t=t.substr(0,t.length-1);
while (t.substr(0,1)==' ') 
	t=t.substr(1);
if (t) window.open('http://www.digalego.com/diccionario/Html/muestra_palabra.php?op=ver&dominio='+dominio+'&buscado='+encodeURIComponent(t), 'dict', 'width=700,height=500,resizable=1,menubar=0,scrollbars=1,status=1,titlebar=1,toolbar=0,location=0,personalbar=0');
}   

}//FIN ELSE

};


status='Faga dobre click en calquer palabra para ver a súa definición.';
document.ondblclick=dictionary; //works for IE only. For other browsers add <body ondblclick="dictionary()">

