home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 August / Chip_2004-08_cd1.bin / zkuste / fototools / download / looky / LookyLooky-Ver1_0-Beta.exe / _SETUP.1 / SuchScr.js < prev    next >
Text File  |  2001-11-09  |  11KB  |  418 lines

  1. <!--
  2. /*
  3. Kommentar
  4. */
  5.  
  6. var op = (navigator.userAgent.indexOf('Opera') != -1);
  7.  
  8. var Optionen = true;
  9.  
  10.  
  11.  
  12. function suche(eingabe)
  13. {
  14.   var Beschreibung    = new Object();
  15.   Beschreibung.Bilder = 'Bilder';
  16.   Beschreibung.desc   = 'Beschreibung';
  17.   Beschreibung.kw     = 'Text';
  18.   Beschreibung.title  = 'Titel';
  19.   Beschreibung.url    = 'Name';
  20.  
  21.   var options = '  <b>Suche bei: </b>';
  22.   var SuchIn = new Array();
  23.  
  24.  
  25.  
  26.  
  27.   var ok = (document.mf && document.mf.Bilder);
  28.   var einsok = ok;
  29.   if ((!op && ok && document.mf.Bilder.checked) || (op && ok && document.mf.Bilder.value)) {
  30.     SuchIn[SuchIn.length] = 'Bilder';
  31.     options += Beschreibung.Bilder + ', ';
  32.   }
  33.  
  34.  
  35.  
  36.   ok = (document.mf && document.mf.kw);
  37.   einsok = (ok || einsok);
  38.   if ((!op && ok && document.mf.kw.checked) || (op && ok && document.mf.kw.value)) {
  39.     SuchIn[SuchIn.length] = 'desc';
  40.     options += Beschreibung.desc + ', ';
  41.   }
  42.  
  43.  
  44.   ok = (document.mf && document.mf.kw);
  45.   einsok = (ok || einsok);
  46.   if ((!op && ok && document.mf.kw.checked) || (op && ok && document.mf.kw.value)) {
  47.     SuchIn[SuchIn.length] = 'kw';
  48.     options += Beschreibung.kw + ', ';
  49.   }
  50.  
  51.   ok = (document.mf && document.mf.kw);
  52.   einsok = (ok || einsok);    
  53.   if ((!op && ok && document.mf.kw.checked) || (op && ok && document.mf.kw.value)) {
  54.     SuchIn[SuchIn.length] = 'title';
  55.     options += Beschreibung.title + ', ';
  56.   }
  57.  
  58.   ok = (document.mf && document.mf.url);
  59.   einsok = (ok || einsok);
  60.   if ((!op && ok && document.mf.url.checked) || (op && ok && document.mf.url.value)) {
  61.     SuchIn[SuchIn.length] = 'url';
  62.     options += Beschreibung.url + ', ';
  63.   }
  64.  
  65.   if (!einsok) {
  66.     SuchIn[SuchIn.length] = 'kw';
  67.     options += Beschreibung.kw + ', ';
  68.   }
  69.  
  70.   options = options.substring(0, options.length-2) + '<br>\n  <b>Berücksichtigt wird:</b> ';
  71.   var wortwahl = -1;
  72.  
  73.   ok = (document.mf && document.mf.lc);
  74.   if ((!op && ok && document.mf.lc.checked) || (op && ok && document.mf.lc.value))
  75.     options += 'Groß-/Kleinschreibung, ';
  76.  
  77.   ok = (document.mf && document.mf.wa);
  78.   var ok2 = (document.mf && document.mf.we);
  79.   if ((!op && ok && ok2 && document.mf.wa.checked && document.mf.we.checked) || (op && ok && ok2 && document.mf.wa.value && document.mf.we.value)) {
  80.     wortwahl = 3;
  81.     options += 'Wortanfang, Wortende<br>\n';
  82.   }
  83.   else if ((!op && ok && document.mf.wa.checked) || (op && ok && document.mf.wa.value)) {
  84.     wortwahl = 1;
  85.     options += 'Wortanfang<br>\n';
  86.   }
  87.   else if ((!op && ok2 && document.mf.we.checked) || (op && ok2 && document.mf.we.value)) {
  88.     wortwahl = 2;
  89.     options += 'Wortende<br>\n';
  90.   }
  91.   else if (ok || ok2) {
  92.     wortwahl = 0;
  93.     options += 'Alles<br>\n';
  94.   }
  95.   else {
  96.     wortwahl = 1;
  97.     options += 'Wortanfang<br>\n';
  98.   }
  99.  
  100.   var auswahl = 0;
  101.   options += '  <b>Verknüpfung: </b>';
  102.  
  103.   ok = (document.mf && document.mf.r);
  104.   if ((!op && ok && document.mf.r[0] && document.mf.r[0].checked) || (op && ok && document.mf.r[0] && document.mf.r[0].value)) {
  105.     auswahl = 1;
  106.     options += 'UND';
  107.   }
  108.   else if ((!op && ok && document.mf.r[1] && document.mf.r[1].checked) || (op && ok && document.mf.r[1] && document.mf.r[1].value)) {
  109.     auswahl = 2;
  110.     options += 'ODER';
  111.   }
  112.   else if ((!op && ok && document.mf.r[2] && document.mf.r[2].checked) || (op && ok && document.mf.r[2] && document.mf.r[2].value)) {
  113.     auswahl = 3;
  114.     options += 'NICHT UND';
  115.   }
  116.   else if (ok && document.mf.r[3]) {
  117.     auswahl = 4;
  118.     options += 'NICHT ODER';
  119.   }
  120.   else {
  121.     auswahl = 1;
  122.     options += 'UND';
  123.   }
  124.  
  125.   var HTMLDok = Kopf(eingabe, auswahl, options);
  126.  
  127.   var eoa = p.length + 1;
  128.   var zaehler = 0;
  129.  
  130.   var liste      = new Array();
  131.   var liste2     = new Array();
  132.   var tquot      = new Array();
  133.   var ausgWort   = new Array();
  134.   var Anker      = new Array();
  135.  
  136.   for (var i=0; i < p.length; i++) {
  137.     liste[i] = i;
  138.     ausgWort[i] = '';
  139.     Anker[i] = '';
  140.   }
  141.   liste[i] = eoa;
  142.  
  143.   var keyw = splitter(eingabe);
  144.  
  145.   if (!keyw[0]) {
  146.     alert ('Bitte mindestens einen gⁿltigen Suchbegriff eingeben!');
  147.     return;
  148.   }
  149.   else if (!SuchIn.length) {
  150.     alert ('Wo soll gesucht werden? ;)');
  151.     return;
  152.   }
  153.  
  154.   var tmptquot = 0;
  155.   var tmpWort = '';
  156.   var tmpAnker = '';
  157.   var gefunden = false;
  158.  
  159.   for (var i=0; i < keyw.length; i++) {
  160.  
  161.     for (var j=0; liste[j] != eoa; j++) {
  162.  
  163.       for (var k=0; k < SuchIn.length; k++) {
  164.  
  165.         var suchObj = new Array();
  166.  
  167.         if (SuchIn[k] != 'kw' && p[liste[j]][SuchIn[k]])
  168.           suchObj = splitter(p[liste[j]][SuchIn[k]]);
  169.         else if (p[liste[j]][SuchIn[k]])
  170.           suchObj = p[liste[j]][SuchIn[k]];
  171.  
  172.         for (var l=0; l < suchObj.length; l++) {
  173.  
  174.           var suchKw = '';
  175.           var suchStr = '';
  176.  
  177.           ok = (document.mf && document.mf.lc);
  178.           if ((!op && ok && document.mf.lc.checked) || (op && ok && document.mf.lc.value)) {
  179.             suchKw = suchObj[l];
  180.             suchStr = keyw[i];
  181.           }
  182.           else {
  183.             suchKw = suchObj[l].toLowerCase();
  184.             suchStr = keyw[i].toLowerCase();
  185.           }
  186.  
  187.           if (suchKw.indexOf(suchStr) != -1 && ((wortwahl == 1 && suchKw.indexOf(suchStr) == 0) || (wortwahl == 2 && suchKw.substring(suchKw.length - suchStr.length) == suchStr) || (wortwahl == 3 && (suchKw.indexOf(suchStr) == 0 || suchKw.substring(suchKw.length - suchStr.length) == suchStr)) || wortwahl == 0)) {
  188.  
  189.             if (keyw[i].length / suchKw.length * 100 > tmptquot) {
  190.  
  191.               tmptquot = keyw[i].length / suchKw.length * 100;
  192.  
  193.               if (auswahl == 1 || auswahl == 2) {
  194.  
  195.                 if (wortwahl == 1 || (wortwahl == 3 && suchKw.indexOf(suchStr) == 0) || wortwahl == 0)
  196.                   tmpWort = suchObj[l].substring(0, suchKw.indexOf(suchStr)) + '<i><u>' + suchObj[l].substring(suchKw.indexOf(suchStr), suchKw.indexOf(suchStr)+suchStr.length) + '</u></i>' + suchObj[l].substring(suchKw.indexOf(suchStr)+suchStr.length) + ' (' + Beschreibung[SuchIn[k]] + ')' + ', ';
  197.                 else
  198.                   tmpWort = suchObj[l].substring(0, suchKw.length - suchStr.length) + '<i><u>' + suchObj[l].substring(suchKw.length - suchStr.length) + '</u></i>' + ' (' + Beschreibung[SuchIn[k]] + ')' + ', ';
  199.  
  200.                 tmpAnker = suchObj[l].toLowerCase();
  201.  
  202.               }
  203.  
  204.               gefunden = true;
  205.  
  206.             }
  207.  
  208.           }
  209.  
  210.         }
  211.  
  212.       }
  213.  
  214.       if (gefunden) {
  215.  
  216.         if (auswahl == 1 || auswahl == 2) {
  217.  
  218.           ausgWort[liste[j]] += tmpWort;
  219.           Anker[liste[j]] = tmpAnker;
  220.  
  221.         }
  222.  
  223.         if (auswahl == 1 || auswahl == 3) {
  224.  
  225.           liste[zaehler] = liste[j];
  226.  
  227.           if (!tquot[j])
  228.             tquot[j] = 0;
  229.           tquot[zaehler] = (i * tquot[j] + tmptquot) / (i + 1);
  230.  
  231.           zaehler++;
  232.  
  233.         }
  234.         else {
  235.  
  236.           liste2[j] = 1;
  237.  
  238.           if (!tquot[j] || tquot[j] < tmptquot)
  239.             tquot[j] = tmptquot;
  240.  
  241.         }
  242.         gefunden = false;
  243.         tmptquot = 0;
  244.  
  245.       }
  246.  
  247.     }
  248.     if (auswahl == 1 || auswahl == 3) {
  249.       liste[zaehler] = eoa;
  250.       tquot[zaehler] = 0;
  251.       if (i+1 < keyw.length)
  252.         zaehler=0;
  253.     }
  254.   }
  255.   if (auswahl == 2 || auswahl == 4) {
  256.  
  257.     for (var i=0; i < p.length; i++) {
  258.  
  259.       if (liste2[i]) {
  260.  
  261.         liste[zaehler] = i;
  262.         tquot[zaehler] = tquot[i];
  263.         zaehler++;
  264.  
  265.       }
  266.     }
  267.     liste[zaehler] = eoa;
  268.     tquot[zaehler] = 0;
  269.  
  270.   }
  271.   if (auswahl == 3 || auswahl == 4)
  272.   {
  273.  
  274.     for (var i=0; i < p.length; i++)
  275.       liste2[i] = i;
  276.  
  277.     for (i=0; liste[i] != eoa; i++)
  278.       liste2[liste[i]] = eoa;
  279.  
  280.     zaehler = 0;
  281.     for (var i=0; i < liste2.length; i++) {
  282.  
  283.       if (liste2[i] != eoa) {
  284.  
  285.         liste[zaehler] = liste2[i];
  286.         tquot[zaehler] = 100;
  287.         zaehler++;
  288.  
  289.       }
  290.  
  291.     }
  292.     tquot[zaehler] = 0;
  293.  
  294.   }
  295.  
  296.   HTMLDok += Zwischen(zaehler);
  297.  
  298.   if (zaehler) {
  299.  
  300.     var k = 0;
  301.     for (var i=0; tquot[i]; i++) {
  302.  
  303.       for (var j=i+1; tquot[j]; j++) {
  304.  
  305.         if (tquot[i] < tquot[j]) {
  306.  
  307.           k = liste[j];
  308.           liste[j] = liste[i];
  309.           liste[i] = k;
  310.           k = tquot[j];
  311.           tquot[j] = tquot[i];
  312.           tquot[i] = k;
  313.  
  314.         }
  315.  
  316.       }
  317.  
  318.     }
  319.     for (var i=0; tquot[i]; i++) {
  320.  
  321.       HTMLDok += '     <li><font face="Arial,Helvetica, sans-serif;" size=+1>['+Math.round(tquot[i])+'%]<strong>' + p[liste[i]].title +'</strong>  <A HREF="'+p[liste[i]].url;
  322.  
  323.       if (Anker[liste[i]])
  324.         HTMLDok += '#'+Anker[liste[i]];
  325.  
  326.       HTMLDok += '">'+p[liste[i]].url+'</a><br><font size="-1">\n';
  327.  
  328.       if (p[liste[i]].Bilder && 1==2)
  329.         HTMLDok += '     <b>Bilder: </b><i>' +p[liste[i]].Bilder+ '</i><br>\n';
  330.  
  331.       HTMLDok += '     <b>Beschreibung:  </b>' +p[liste[i]].desc + '\n';
  332.  
  333.       if (ausgWort[liste[i]])
  334.         HTMLDok += '     <br><b>Treffer: </b><font face="Courier New,Courier">' + ausgWort[liste[i]].substring(0, ausgWort[liste[i]].length-2);
  335.  
  336.       HTMLDok += '\n     </font></font></font></li><br><br>\n'
  337.  
  338.     }
  339.     HTMLDok += ' </ol>\n';
  340.  
  341.   }
  342.   else
  343.     HTMLDok += ' </ol>\n' +
  344.                ' <p>Leider wurde kein Ergebnis gefunden.</p>\n';
  345.  
  346.   HTMLDok += Fuss();
  347.  
  348.   document.open ('text/html');
  349.   document.write(HTMLDok);
  350.   document.close();
  351.  
  352.   return;
  353.  
  354. }
  355.  
  356.  
  357.  
  358. function splitter(Wert)
  359. {
  360.   var tmpWert = Wert.split(' ').join(',').split(',').join('+').split('+').join('&').split('&');
  361.  
  362.   var retVal = new Array();
  363.   for (var i=0; i < tmpWert.length; i++)
  364.     if (tmpWert[i])
  365.       retVal[retVal.length] = tmpWert[i];
  366.  
  367.   return (retVal);
  368. }
  369.  
  370.  
  371. function Kopf(eingabe, auswahl, options)
  372. {
  373.   var retVal = '<html>\n' +
  374.                '<head>\n' +
  375.                '<title>Suchergebnis</title>\n' +
  376.                '</head>\n' +
  377.                '<body>\n' +
  378.                '<center><h1><table border=3 cellspacing=1 cellpadding=0><tr><td bgcolor="#C0C0C0"><font face="Arial,Helvetica,Sans-Serif" size=+2><b> LookyLooky Album Suchergebnis </b></font></td></tr></table></h1></center><br>\n';
  379.  
  380.   if (auswahl == 1 || auswahl == 2)
  381.     retVal += '<center><td bgcolor="#C0C0C0"><font face="Arial,Helvetica,Sans-Serif" size=+1><b>Sie haben nach "<b>'+eingabe+'</b>" gesucht.</b></font></center><br>\n';
  382.     //retVal += ' <p>Sie haben nach "<b>'+eingabe+'</b>" gesucht.<br><br>\n';
  383.   else
  384.     retVal += ' <p>Sie haben nach Dokumenten gesucht, in denen "<b>'+eingabe+'</b>" nicht vorkommt.<br><br>\n';
  385.  
  386.   if (Optionen)
  387.     //retVal += '  <font face="Arial,Helvetica,Sans-Serif" size="1"><b><i>Optionen:</i></b><br>\n' + options + '</font><br><br>\n';
  388.  
  389.   return (retVal);
  390. }
  391.  
  392.  
  393. function Zwischen(zaehler)
  394. {
  395.  
  396.   return ('  <hr color="#004080" noshade>\n' +
  397.           '  <center><p><font face="Arial,Helvetica,Sans-Serif" size=+1><b>Es wurden '+zaehler+' von ' + p.length + ' Seiten gefunden: </b></font></p></center>\n' +
  398.         //  '  <P><b>Folgende Seiten/Stellen wurden gefunden:</b></P>\n' +
  399.           '  <OL>\n');
  400.  
  401. }
  402.  
  403. function Fuss()
  404. {
  405.  
  406.   return ('<a href="javascript:history.back();">Zurück zur Suche</a>\n' +
  407.           '</body>\n' +
  408.           '</html>');
  409.  
  410. }
  411.  
  412. function loesche()
  413. {
  414.   document.mf.reset();
  415.   document.mf.eingabe.focus();
  416. }
  417. //-->
  418.