home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2003 October / PCWELT_10_2003.ISO / pcwsoft / CUCKOO.z.exe / cuckoo.js < prev    next >
Encoding:
JavaScript  |  2002-06-09  |  15.3 KB  |  330 lines

  1. /*
  2.  * cuckoo.js
  3.  * - Helper function for scripts
  4.  * - Mouseover handling
  5.  *
  6.  * Version 0.1.1
  7.  * Copyright (c) 2000-2001 Alexis Grandemange
  8.  * Mail: alexis.grandemange@pagebox.net
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU Lesser General Public
  11.  * License as published by the Free Software Foundation; version
  12.  * 2.1 of the License.
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.  * GNU Lesser General Public License for more details.
  17.  * A copy of the GNU Lesser General Public License lesser.txt should be
  18.  * included in the distribution.
  19.  *
  20.  * Browser detection from Mozilla. See:
  21.  * http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
  22.  *
  23.  * Mouseover handling created by Jim Young (www.requestcode.com)
  24.  * Submitted to Website Abstraction (http://wsabstract.com)
  25.  * Visit http://wsabstract.com for this script
  26.  * Alexis Grandemange added:
  27.  * - fallback mode for Opera
  28.  * - the DOM scan to support mouse overs in tables on IE.
  29.  */
  30. //<!--
  31. // Ultimate client-side JavaScript client sniff. Version 3.03
  32. // (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
  33. // Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
  34. // Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
  35. //                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV
  36. // Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4, 
  37. //                      correct Opera 5 detection
  38. //                      add support for winME and win2k
  39. //                      synch with browser-type-oo.js
  40. // Revised 26 Mar 01 to correct Opera detection
  41. // Revised 02 Oct 01 to add IE6 detection
  42.  
  43. // Everything you always wanted to know about your JavaScript client
  44. // but were afraid to ask. Creates "is_" variables indicating:
  45. // (1) browser vendor:
  46. //     is_nav, is_ie, is_opera, is_hotjava, is_webtv, is_TVNavigator, is_AOLTV
  47. // (2) browser version number:
  48. //     is_major (integer indicating major version number: 2, 3, 4 ...)
  49. //     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
  50. // (3) browser vendor AND major version number
  51. //     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko, is_ie3,
  52. //     is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up, is_hotjava3, is_hotjava3up,
  53. //     is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up
  54. // (4) JavaScript version number:
  55. //     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
  56. // (5) OS platform and version:
  57. //     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98, is_winme, is_win2k
  58. //     is_os2
  59. //     is_mac, is_mac68k, is_macppc
  60. //     is_unix
  61. //     is_sun, is_sun4, is_sun5, is_suni86
  62. //     is_irix, is_irix5, is_irix6
  63. //     is_hpux, is_hpux9, is_hpux10
  64. //     is_aix, is_aix1, is_aix2, is_aix3, is_aix4
  65. //     is_linux, is_sco, is_unixware, is_mpras, is_reliant
  66. //     is_dec, is_sinix, is_freebsd, is_bsd
  67. //     is_vms
  68. //
  69. // See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
  70. // http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
  71. // for detailed lists of userAgent strings.
  72. //
  73. // Note: you don't want your Nav4 or IE4 code to "turn off" or
  74. // stop working when new versions of browsers are released, so
  75. // in conditional code forks, use is_ie5up ("IE 5.0 or greater") 
  76. // is_opera5up ("Opera 5.0 or greater") instead of is_ie5 or is_opera5
  77. // to check version in code which you want to work on future
  78. // versions.
  79.  
  80.     // convert all characters to lowercase to simplify testing
  81.     var agt=navigator.userAgent.toLowerCase();
  82.  
  83.     // *** BROWSER VERSION ***
  84.     // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
  85.     var is_major = parseInt(navigator.appVersion);
  86.     var is_minor = parseFloat(navigator.appVersion);
  87.  
  88.     // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
  89.     // If you want to allow spoofing, take out the tests for opera and webtv.
  90.     var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
  91.                 && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
  92.                 && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
  93.     var is_nav2 = (is_nav && (is_major == 2));
  94.     var is_nav3 = (is_nav && (is_major == 3));
  95.     var is_nav4 = (is_nav && (is_major == 4));
  96.     var is_nav4up = (is_nav && (is_major >= 4));
  97.     var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
  98.                           (agt.indexOf("; nav") != -1)) );
  99.     var is_nav6 = (is_nav && (is_major == 5));
  100.     var is_nav6up = (is_nav && (is_major >= 5));
  101.     var is_gecko = (agt.indexOf('gecko') != -1);
  102.  
  103.  
  104.     var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
  105.     var is_ie3    = (is_ie && (is_major < 4));
  106.     var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
  107.     var is_ie4up  = (is_ie && (is_major >= 4));
  108.     var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
  109.     var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
  110.     var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
  111.     var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
  112.     var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
  113.     var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
  114.  
  115.     // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
  116.     // or if this is the first browser window opened.  Thus the
  117.     // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
  118.     var is_aol   = (agt.indexOf("aol") != -1);
  119.     var is_aol3  = (is_aol && is_ie3);
  120.     var is_aol4  = (is_aol && is_ie4);
  121.     var is_aol5  = (agt.indexOf("aol 5") != -1);
  122.     var is_aol6  = (agt.indexOf("aol 6") != -1);
  123.  
  124.     var is_opera = (agt.indexOf("opera") != -1);
  125.     var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
  126.     var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
  127.     var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
  128.     var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
  129.     var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);
  130.  
  131.     var is_webtv = (agt.indexOf("webtv") != -1); 
  132.  
  133.     var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
  134.     var is_AOLTV = is_TVNavigator;
  135.  
  136.     var is_hotjava = (agt.indexOf("hotjava") != -1);
  137.     var is_hotjava3 = (is_hotjava && (is_major == 3));
  138.     var is_hotjava3up = (is_hotjava && (is_major >= 3));
  139.  
  140.     // *** JAVASCRIPT VERSION CHECK ***
  141.     var is_js;
  142.     if (is_nav2 || is_ie3) is_js = 1.0;
  143.     else if (is_nav3) is_js = 1.1;
  144.     else if (is_opera5up) is_js = 1.3;
  145.     else if (is_opera) is_js = 1.1;
  146.     else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
  147.     else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
  148.     else if (is_hotjava3up) is_js = 1.4;
  149.     else if (is_nav6 || is_gecko) is_js = 1.5;
  150.     // NOTE: In the future, update this code when newer versions of JS
  151.     // are released. For now, we try to provide some upward compatibility
  152.     // so that future versions of Nav and IE will show they are at
  153.     // *least* JS 1.x capable. Always check for JS version compatibility
  154.     // with > or >=.
  155.     else if (is_nav6up) is_js = 1.5;
  156.     // NOTE: ie5up on mac is 1.4
  157.     else if (is_ie5up) is_js = 1.3
  158.  
  159.     // HACK: no idea for other browsers; always check for JS version with > or >=
  160.     else is_js = 0.0;
  161.  
  162.     // *** PLATFORM ***
  163.     var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
  164.     // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
  165.     //        Win32, so you can't distinguish between Win95 and WinNT.
  166.     var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));
  167.  
  168.     // is this a 16 bit compiled version?
  169.     var is_win16 = ((agt.indexOf("win16")!=-1) || 
  170.                (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || 
  171.                (agt.indexOf("windows 16-bit")!=-1) );  
  172.  
  173.     var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
  174.                     (agt.indexOf("windows 16-bit")!=-1));
  175.  
  176.     var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
  177.     var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));
  178.  
  179.     // NOTE: Reliable detection of Win98 may not be possible. It appears that:
  180.     //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
  181.     //       - On Mercury client, the 32-bit version will return "Win98", but
  182.     //         the 16-bit version running on Win98 will still return "Win95".
  183.     var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
  184.     var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
  185.     var is_win32 = (is_win95 || is_winnt || is_win98 || 
  186.                     ((is_major >= 4) && (navigator.platform == "Win32")) ||
  187.                     (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));
  188.  
  189.     var is_os2   = ((agt.indexOf("os/2")!=-1) || 
  190.                     (navigator.appVersion.indexOf("OS/2")!=-1) ||   
  191.                     (agt.indexOf("ibm-webexplorer")!=-1));
  192.  
  193.     var is_mac    = (agt.indexOf("mac")!=-1);
  194.     // hack ie5 js version for mac
  195.     if (is_mac && is_ie5up) is_js = 1.4;
  196.     var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || 
  197.                                (agt.indexOf("68000")!=-1)));
  198.     var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || 
  199.                                 (agt.indexOf("powerpc")!=-1)));
  200.  
  201.     var is_sun   = (agt.indexOf("sunos")!=-1);
  202.     var is_sun4  = (agt.indexOf("sunos 4")!=-1);
  203.     var is_sun5  = (agt.indexOf("sunos 5")!=-1);
  204.     var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
  205.     var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
  206.     var is_irix5 = (agt.indexOf("irix 5") !=-1);
  207.     var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
  208.     var is_hpux  = (agt.indexOf("hp-ux")!=-1);
  209.     var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
  210.     var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
  211.     var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
  212.     var is_aix1  = (agt.indexOf("aix 1") !=-1);    
  213.     var is_aix2  = (agt.indexOf("aix 2") !=-1);    
  214.     var is_aix3  = (agt.indexOf("aix 3") !=-1);    
  215.     var is_aix4  = (agt.indexOf("aix 4") !=-1);    
  216.     var is_linux = (agt.indexOf("inux")!=-1);
  217.     var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
  218.     var is_unixware = (agt.indexOf("unix_system_v")!=-1); 
  219.     var is_mpras    = (agt.indexOf("ncr")!=-1); 
  220.     var is_reliant  = (agt.indexOf("reliantunix")!=-1);
  221.     var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || 
  222.            (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || 
  223.            (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)); 
  224.     var is_sinix = (agt.indexOf("sinix")!=-1);
  225.     var is_freebsd = (agt.indexOf("freebsd")!=-1);
  226.     var is_bsd = (agt.indexOf("bsd")!=-1);
  227.     var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux || 
  228.                  is_sco ||is_unixware || is_mpras || is_reliant || 
  229.                  is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);
  230.  
  231.     var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));
  232. /* End of http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html */
  233. /** Shows the tooltip. */
  234. function showtip(current, e, num) {
  235.     if (is_opera)
  236.         return;        // dynamic update not supported in Opera
  237.     current.title = ""  // Otherwise you see both the tooltip and the title
  238.     if (document.layers) { // Netscape 4.0+
  239.         theString = "<DIV CLASS='ttip'>" + format(tip[num]) + "</DIV>";
  240.         document.tooltip.document.write(theString);
  241.         document.tooltip.document.close();
  242.         document.tooltip.left = e.pageX + 14;
  243.         document.tooltip.top = e.pageY + 4;
  244.         document.tooltip.visibility = "show";
  245.     } else
  246.     if (document.getElementById) { // Netscape 6.0+, Internet Explorer 5.0+
  247.         var elm = document.getElementById("tooltip");
  248.         var elml = current;
  249.         elm.innerHTML = format(tip[num]);
  250.         if (is_gecko) {
  251.             elm.style.top = elml.offsetTop + elml.offsetHeight;
  252.             elm.style.left = elml.offsetLeft + elml.offsetWidth + 10;
  253.         } else {
  254.             var h = 0
  255.             var w = 0
  256.             var elm2 = elml.parentNode;
  257.             while (elm2 != null) {
  258.                 if (elm2.nodeType == 1) {
  259.                     if (elm2.tagName == "TD") {
  260.                         h += elm2.offsetTop;
  261.                         w += elm2.offsetLeft;
  262.                     }
  263.                     if (elm2.tagName == "TABLE") {
  264.                         h += elm2.offsetTop;
  265.                         w += elm2.offsetLeft;
  266.                     }
  267.                 }
  268.                 elm2 = elm2.parentNode;
  269.             }
  270.             elm.style.top = elml.offsetTop + elml.offsetHeight + h;
  271.             elm.style.left = elml.offsetLeft + elml.offsetWidth + w + 10;
  272.         }
  273.         elm.style.height = elml.style.height;
  274.         elm.style.visibility = "visible";
  275.     } else
  276.     if (document.all) {
  277.         var elm = document.all["tooltip"];
  278.         elm.innerHTML = format(tip[num]);
  279.         elm.style.top = elml.offsetTop + elml.offsetHeight;
  280.         elm.style.left = elml.offsetLeft + elml.offsetWidth + 10;
  281.         elm.style.height = elml.style.height;
  282.         elm.style.visibility = "visible";
  283.     }
  284. }
  285. /** Formats the tooltip for display. */
  286. function format(st) {
  287.     var str = new String(st);
  288.     str = str.replace("<", "<").replace(">", ">");
  289.     return str.replace("!@", "<").replace("@!", ">");
  290. }
  291. /** Hides the tooltip. */
  292. function hidetip() {
  293.     if (is_opera)
  294.         return;
  295.     if (document.layers) // Netscape 4.0+
  296.         document.tooltip.visibility = "hidden"
  297.     else
  298.     if (document.getElementById) { // Netscape 6.0+ and Internet Explorer 5.0+
  299.         var elm = document.getElementById("tooltip");
  300.         elm.style.visibility = "hidden";
  301.     } else
  302.     if (document.all) {
  303.         var elm = document.all["tooltip"];
  304.         elm.style.visibility = "hidden";
  305.     }
  306. }
  307. /** Helper function for document scripts. */
  308. function checkParms(form, func) {
  309.     var elts = form.getElementsByTagName('input');
  310.     for (var i = 0; i < elts.length; ++i) {
  311.         switch (elts[i].type) {
  312.             case "radio":
  313.                 if (elts[i].checked)
  314.                     eval(func + "_" + elts[i].name + "('" + elts[i].value + "')");
  315.                 break;
  316.             case "checkbox":
  317.                 if (elts[i].checked)
  318.                     eval(func + "_" + elts[i].name + "('" + elts[i].value + "')");
  319.                 break;
  320.             case "text":
  321.                 eval(func + "_" + elts[i].name + "('" + elts[i].value + "')");
  322.                 break;
  323.         }
  324.     }
  325.     elts = form.getElementsByTagName('select');
  326.     for (var i = 0; i < elts.length; ++i) {
  327.         var val = elts[i].options[elts[i].selectedIndex].value;
  328.         eval(func + "_" + elts[i].name + "('" + val + "')");
  329.     }
  330. }