/*
lib.js
by Caio Chassot (http://v2studio.com/k/code/)
parts by other authors, see commented version for details
version 0.5.75
File generated on Fri Sep 24 00:35:55 E. South America Standard Time 2004
for documentation, see commented version.
get commented version at http://v2studio.com/k/code/lib/lib_c.js
Use freely. Credit is appreciated but not required.
Abridged Version : Just for Jocasi Site.
*/
function getElementsByClass(className, tagName, parentNode) {
	var noClassTags = list('#comment,BASE,BASEFONT,HEAD,HTML,META,PARAM,SCRIPT,STYLE,TITLE');
	return filter(getAll(tagName,parentNode),
		function(elem) {
				return !noClassTags.include(elem.nodeName) && hasClass(elem, className)
		});
}

getElementsByClassName = getElementsByClass;

function list(s, sep) {
	if (!isString(sep) && !isRegexp(sep))
		sep = sep? ',' : /\s*,\s*/;
	return s.split(sep);
}

function isString(a)    { return typeof a == 'string' }
function isRegexp(a)    { return a && a.constructor == RegExp }
function isdef(v) { return !isUndefined(v) }
function isUndefined(a) { return typeof a == 'undefined' }
function undef(v) { return  isUndefined(v) }
function isFunction(a)  { return typeof a == 'function' }
function isElement(o, strict) {
	return o && isObject(o) && ((!strict && (o==window || o==document)) || o.nodeType == 1)
}
function isObject(a)    { return (a && typeof a == 'object') || isFunction(a) }

function filter(list, fn) {
	if (typeof(fn)=='string') return filter(list, __strfn('item,idx,list', fn));
	var result = [];
	fn = fn || function(v) {return v};
	map(list, function(item,idx,list) { if (fn(item,idx,list)) result.push(item) } );
	return result;
}

function getAll(tagName, parent) {
	parent = isdef(parent)? getElem(parent) : document;
	if (undef(tagName)) tagName = '*';
	var r = parent.getElementsByTagName(tagName);
	return r.length || tagName != '*'?  map(r) :
		reduce(filterElementNodes(parent.childNodes), [], function(l,c){
			return l.merge([c], getAll(tagName, c))
		})
}

function map(list, fn) {
	if (typeof(fn)=='string') return map(list, __strfn('item,idx,list', fn));
	var result = [];
	fn = fn || function(v) {return v};
	for (var i=0; i < list.length; i++) result.push(fn(list[i], i, list));
	return result;
}

function hasClass(elem, className) {
	return getElem(elem).className.split(' ').count(className);
}

function getElem(el) {
	var ge = (document.getElementById && function(id){return document.getElementById(id)} ) ||
		(document.all && function(id){return document.all[id]} ) ||
		function(){return null};
		return isElement(el)? el : isString(el) ? ge(el) : null;
}

Array.prototype.contains = function(value,strict) {
	return this.indexOf(value,0,strict) !== -1;
}
Array.prototype.include = Array.prototype.contains;
Array.prototype.count = function(value, strict) {
	var pos, start = 0, count = 0;
	while ((pos = this.indexOf(value, start, strict)) !== -1) {
		start = pos + 1;
		count++;
	}
	return count;
}
Array.prototype.indexOf = function(value, start, strict) {
	start = start || 0;
	for (var i=start; i<this.length; i++) {
		var item = this[i];
		if (strict            ? item === value   :
			isRegexp(value)   ? value.test(item) :
			isFunction(value) ? value(item)      :
			item == value)
			return i;
	}
	return -1;
}
