function cstmGetElementsByClassName(class_name) {
	/*This method must be bound to and object or used with call or apply*/

	/* Get array of all tags */
	var docList = this.all || this.getElementsByTagName('*');

	/*Create a regular expression object for class*/
	var re = new RegExp("(?:^|\\s)"+class_name+"(?:\\s|$)");

	/* Create output array*/
	var matchArray = new Array();

	/* Populate output array from tag array */
	for (var i = 0; i < docList.length; i++) {
		if (re.test(docList[i].className)) {
			//Didn't use array.push since older browsers don't support it
			matchArray[matchArray.length] = docList[i];
		}
	}
	return matchArray;
}//eof

//This line binds the function to the document object change it to fit your needs
document.getElementsByClassName = cstmGetElementsByClassName;

function cstmGetElementsByClassNameExt(parentElement, class_name, tag) {
	/* Extendeds function with performance improvements.
	 * by using a parentElement and the tag the class is on
	 * the list of elements to check is reduced.
	 *
	 * This function doesn't get bound to an object.
	 */
	var docList;
	var matchArray;
	var re;
	var len;
	
	parentElement = parentElement || document;
	if (typeof parentElement == "string") //object could be passed instead of Id
		parentElement = document.getElementById(parentElement);
		
	/* Get array of all tags */
	tag = tag || "*";
	if (tag == "*")
		/* The test is to accommodate IE 5, but you can leave it out if IE 5 support is not required */
		docList = parentElement.all || parentElement.getElementsByTagName('*');
	else
		docList = parentElement.getElementsByTagName(tag);
		
	/*Create a regular expression object for class*/
	re = new RegExp("(?:^|\\s)" + class_name + "(?:\\s|$)");

	/* Create output array*/
	matchArray = new Array();
	len = docList.length;
	
	/* Populate output array from tag array 
	 * do loop is faster than for loop 
	 * albeit out is in reverse order
	 */
	while (len--) {
		if (re.test(docList[len].className)) {			
			matchArray[matchArray.length] = docList[len];
		}
	}
	//return matchArray.reverse(); //if the order needs to forward
	return matchArray;
}//eof

function cstmGetElementsByClassNameExt2(class_name, tag) {
	/* Bonus function with performance improvements
	 * by using this for the parent element along with tag
	 * to reduce the list of elements to check.
	 *
	 * This method GETS bound to an object
	 *
	 * Call either
	 *      elementRef = document.getElementById(id);
	 *      elementRef.getElementsByClassName = cstGetElementsByClassNameExt2;
	 *      array = elementRef.getElementByClassName("class-name", "p");
	 * or
	 *      elementRef = document.getElementById(id);
	 *      array = cstGetElementsByClassNameExt2.call(elementRef, "class-name", "p");
	 */
	var re = new RegExp("(?:^|\\s)" + class_name + "(?:\\s|$)");
	var matchArray = [];
	var docList;
	var len;
	
	/* Get array of all tags */
	tag = tag || "*";
	if (tag == "*")
		/* The test is to accommodate IE 5, but you can leave it out if IE 5 support is not required */
		docList = this.all || this.getElementsByTagName('*');
	else
		docList = this.getElementsByTagName(tag);
		
	/* Populate output array from tag array 
	 * do loop is faster than for loop 
	 * albeit out is in reverse order
	 */
	len = docList.length;
	while (len--) {
		if (re.test(docList[len].className)) {			
			matchArray[matchArray.length] = docList[len];
		}
	}
	//return matchArray.reverse(); //if the order needs to forward
	return matchArray;
}//eof

