JSSwitch

This file is the JavaScript file that shows the JavaScript based Reset button and hides the PHP based Reset button when JavaScript is active in the browser.

      1| function jsShow(classname,toggle)
      2| {
      3|     if("show" == toggle)
      4|     {
      5|         dVar = "inline";
      6|         vVar = "visible";
      7|     }
      8|     else if ("hide" == toggle)
      9|     {
    10|         dVar = "none";
    11|         vVar = "hidden";
    12|     }
    13|     else
    14|     {
    15|         window.alert("Toggle not selected!");
    16|     }
    17| 
    18|     var rawElements = getElementsByClass(classname);
    19|     var arrLen = rawElements.length;
    20| 
    21|     for(var n = 0; n < arrLen; n++)
    22|     {
    23|         var element = rawElements[n];
    24| 
    25|         element.style.display = dVar;
    26|         element.style.visibility = vVar;
    27| 
    28|     }
    29| }
    30| 
    31| function getElementsByClass(classname)
    32| {
    33|     if(document.getElementsByClassName)
    34|     {
    35|         /*use native implementation if browser is new enough like CMS over at (http://stackoverflow.com/questions/1933602/how-to-getelementbyclass-instead-of-getelementbyid-with-javscript)recommends in his answer.*/
    36| 
    37|         return document.getElementsByClassName(classname);
    38|     }
    39|     else
    40|     {
    41|         /*
    42|         Rolled my own similar to what is recommended in JavaScript & DHTML Cookbook (2nd edition) 14.14 pp.180-181 (http://www.amazon.com/gp/product/0596514085?ie=UTF8&tag=keithgallcom-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=0596514085).
    43|         */
    44|         var allElements = (document.all) ? document.all : document.getElementsByTagName("*");
    45|         var ELen = allElements.length;
    46| 
    47|         var results = new Array();
    48|         var regEx = new RegExp("\\b" + classname + "\\b");
    49| 
    50|         for(var i = 0; i < ELen; i++)
    51|         {
    52|             //The '.className' is not the same as element 'classname'. NEVER CONFUSE!
    53|             if(regEx.test(allElements[i].className))
    54|             {
    55|                 results.push(allElements[i]);
    56|             }
    57|         }
    58| 
    59|         return results;
    60|     }
    61| }
    62|