function getElementsByClass(node,searchClass,tag) {
    var classElements = new Array();
    var els = node.getElementsByTagName(tag); // use "*" for all elements
    var elsLen = els.length;
    var pattern = new RegExp("\\b"+searchClass+"\\b");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function showNumberOfClasses(className) {
    var el = getElementsByClass(document,className,'*');
    alert(el.length);
}

      function indexInLiteral(str, index) {
        var inStrLiteral = 0;
        var inObjLiteral = 0;
        var inArrayLiteral = 0;

        for (var i = 0; i < str.length; i++) {
          if (inStrLiteral) {
            if (str.charAt(i) == "'" || str.charAt(i) == '"') {
              inObjLiteral--;
            }
          } else {
            if (str.charAt(i) == "'" || str.charAt(i) == '"') {
              inObjLiteral++;
            }
          }
          if (!inStrLiteral) {
            if (inObjLiteral) {
              if (i == index) {
                return (true);
              }
              if (str.charAt(i) == "}") {
                inObjLiteral--;
              }
            } else {
              if (str.charAt(i) == "{") {
                inObjLiteral++;
              }
            }
            if (inArrayLiteral) {
              if (i == index) {
                return (true);
              }
              if (str.charAt(i) == "]") {
                inArrayLiteral--;
              }
            } else {
              if (str.charAt(i) == "[") {
                inArrayLiteral++;
              }
            }
          }
        }

        return (false);
      }

      function getLocals(args) {
        var ret = [];
        var reArg = /\(?\s*(\w+)\s*(,|\))/g;
        var reEndArg = /\{/;
        var reHasVar = /(\W|^)var\W/;
        var reGetVar = /(var|,)\s*(\w+)/g;
        var lookForArgs = true;
        var reResult;
        var a;

        if (typeof args == 'function' ) {
          a = args.toString().split("\n");
        } else {
          a = (args) ? args.callee.toString().split("\n") : [];
        }

        ret.push(a[0]); // save the function name for later use
        
        for (var i = 0; i < a.length; i++) {
          if (lookForArgs) {
            reArg.lastIndex = 0;
            while ((reResult = reArg.exec(a[i])) != null) {
              ret.push(reResult[1]);
            }
            reEndArg.lastIndex = 0;
            if (reEndArg.test(a[i])) {
              lookForArgs = false;
            }
          }
          if (!lookForArgs) {
            reHasVar.lastIndex = 0;
            if (reHasVar.test(a[i])) {
              reGetVar.lastIndex = 0;
              while ((reResult = reGetVar.exec(a[i])) != null) {
                if (!indexInLiteral(a[i], reResult.index)) { 
                  ret.push(reResult[2]);
                }
              }
            }
          }
        }
        return (ret);
      }

      function getLocalsOfType(args,type) {
        var ret = [];
        var reArg = /\(?\s*(\w+)\s*(,|\))/g;
        var reEndArg = /\{/;
        var reHasVar = /(\W|^)var\W/;
        var reGetType = /(?:Fx.Slide)/g;
        var reGetVar = /(var|,)\s*(\w+)/g;
        var lookForArgs = true;
        var reResult;
        var reResultType;
        var a;

        if (typeof args == 'function' ) {
          a = args.toString().split("\n");
        } else {
          a = (args) ? args.callee.toString().split("\n") : [];
        }

        ret.push(a[0]); // save the function name for later use
        
        for (var i = 0; i < a.length; i++) {
          //alert(reGetType.exec(a[i]));
          if (lookForArgs) {
            reArg.lastIndex = 0;
            while ((reResult = reArg.exec(a[i])) != null) {
              ret.push(reResult[1]);
            }
            reEndArg.lastIndex = 0;
            if (reEndArg.test(a[i])) {
              lookForArgs = false;
            }
          }
          if (!lookForArgs) {
              if (reGetType.exec(a[i]) == type) {
                reHasVar.lastIndex = 0;
                if (reHasVar.test(a[i])) {
                  reGetVar.lastIndex = 0;
                  while ((reResult = reGetVar.exec(a[i])) != null) {
                    if (!indexInLiteral(a[i], reResult.index)) { 
                      ret.push(reResult[2]);
                    }
                  }
                }
              }
          }
        }
        return (ret);
      }

      function showLocals(func, args) {
        var str = "Variables for ";
        var arrayOfLocals = getLocals(args);
        var v;

        for (var i = 0; i < arrayOfLocals.length; i++) {
          if (i == 0) {
            str += arrayOfLocals[i] + "\n";
          } else {
            if (typeof func == 'function') {
              v = func(arrayOfLocals[i]);
              if (typeof v == 'string') {
                v = '"' + v + '"';
              }
              str += "    " + arrayOfLocals[i] + " = " + v + "\n";
            } else {
              str += "    " + arrayOfLocals[i] + "\n";
            }
          }
        }
        alert(str);
      }

      function doItInside(s) { 
        var x = 5, y = 9;
        var re = /^test$/;

        for (var i = 0; i < 5; i++) {
          var arr = [ 2, 4, 6, 8 ];

          if (arr[i] == i) {
            break;
          }
        }

        var ob = { x: 7, y: 5 };

        showLocals(function($$$$){return(eval($$$$))}, arguments);
      }

      var outsideCheckerFunc;
      function doItOutside(str_param, num_param) {
        var timer = 100;
        outsideCheckerFunc = function($$$$){return(eval($$$$))};

        var f = function(){alert("hi")};
        var a = 55, b = 66, c = 77;
        var regE = new RegExp("^s*tart?");
      }

      function doItOutsideCaller(withEvalFunc) {
        if (withEvalFunc) {
          doItOutside('test param string', 9);
          showLocals(outsideCheckerFunc, doItOutside);
        } else {
          showLocals(null, doItOutside);
        }
      }


/* Returns the class name of the argument or undefined if
   it's not a valid JavaScript object.
*/
function getObjectClass(obj) {
    if (obj && obj.constructor && obj.constructor.toString) {
        var arr = obj.constructor.toString().match(
            /function\s*(\w+)/);

        if (arr && arr.length == 2) {
            return arr[1];
        }
    }

    return undefined;
}

// changes color of an element
function changecolor(id, color) { 
    element = document.getElementById(id); 
    event.cancelBubble = true; 
    oldcolor = element.currentStyle.background; 
    element.style.background = color; 
} 

