/* -----------------------------------------------------------------------
   Programm: smartsearch.js
             SmartSearch-Funktion

             (c) Klaus Tucher Informatik
                 Klaus Tucher
                 Im Münzen 30
                 73230 Kirchheim unter Teck
   ------------------------------------------------------------------------ */

if (document.all) {
   if (document.selection) {
      document.attachEvent('onmouseup',enableSmartSearch);
      } 
   else {
      window.onmouseup=enableSmartSearch;
      } 
   } 
else {
   if (document.selection) {
      document.addEventListener('mouseup', enableSmartSearch, false);
      } 
   else {
      window.onmouseup=enableSmartSearch;
      } 
   } 

function enableSmartSearch (evnt) {
  if (!evnt)   {evnt=window.event;}

  var txt=localGetSelectedText();

  if (txt != '') {
     var div=document.getElementById('SmartSearch');
     var frm=document.getElementById('SmartSearchForm');
     if (frm) {
        frm.Suchbegriff.value=txt;
        if (div.style.display=='none') {
           var x,y;
           if (evnt.pageX) {
              x=evnt.pageX;
              y=evnt.pageY;
              }
           else {
              x = event.x + document.body.scrollLeft;
              y = event.y + document.body.scrollTop;
              }
           if (div.width) {
              x=x-div.width;
              if (x < 0) {x=0;} 
              }
           div.style.top =y;
           div.style.left=x;
           div.style.display='block';
           }
        }
     }
  }

function hideSmartSearch () {
  var f=document.getElementById('SmartSearch');
  if (f) {
     f.style.display='none';
     }
  }

function localGetSelectedText () {
   if (window.getSelection)        {return window.getSelection();} 
   else if (document.getSelection) {return document.getSelection();} 
   else if (document.selection)    {return document.selection.createRange().text;}
   else return '';    
   }
