/*
 * http://www.anyexample.com/webdev/javascript/javascript_getelementsbyclass_function.xml
 * 
 * Described function getElementsByClass has three arguments.
 * Class name (first argument),
 * DOM node (by default it's a document) and
 * tag name (for selecting only <tag> elements with specific class).
 * Last two arguments are optional.
 * 
 * First, getElementsByClass function selects all tags
 * (every tag '*' or tags with name 'tagName' specified by user).
 * Afterwards, in for-loop our function checks if given class name
 * is in the className property string. If it is, it copies found
 * element to another array 'el' which is returned to user at the
 * end of function.
 * 
 * Here is getElementsByClass source code: 
 */

function getElementsByClass( searchClass, domNode, tagName) { 
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) { 
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1) 
			el[j++] = tags[i];
	} 
	return el;
} 

