function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


/**
 * This function will return the parent object of the
 * given element using a classname to locate it. It will
 * iterate through all parent nodes until one with the
 * given class name if found.
 *
 * @param obj object to locate parent element of
 * @param className class name to use as search term
 * @return parent element with given class name or null
 */
function findParentByClassName(obj, className) {
	var found = false;
	while (!found && obj != null) {
		if(typeof obj.parentNode != 'undefined') {
			obj = obj.parentNode;
		}

		found = containsClassName(obj, className);
	}
	return found ? obj : null;
}

function findChildrenByClassName(obj, className) {
	var children = new Array();
	for(var i = 0; i < obj.childNodes.length; i++) {
		if(typeof obj.childNodes[i] != 'undefined' &&
			containsClassName(obj.childNodes[i], className)) {

			children[children.length] = obj.childNodes[i];
		}
	}
	return children;
}

function findChildrenByTagName(obj, tagName) {
	var children = new Array();
	for(var i = 0; i < obj.childNodes.length; i++) {
		if(typeof obj.childNodes[i] != 'undefined' && obj.childNodes[i].nodeName &&
			obj.childNodes[i].nodeName.toUpperCase() == tagName.toUpperCase()) {

			children[children.length] = obj.childNodes[i];
		}
	}
	return children;
}


/**
 * Function to add a class name to an element. This
 * function will also check to see if any existing
 * class names exist and simply append the new class
 * name to it. There are a few conditions though. If
 * the class name already exists, it will not be appended.
 * If the optional override parameter is given, then
 * any previous class names on the element are replaced
 * by the new one.
 *
 * @param objOrId element or ID of element to add 
 *            class name to
 * @param className class name to add to element
 * @param override flag to replace or append class name
 */
function addClassName(objOrId, className, override) {
	var obj = getObject(objOrId);
	if(obj == null) return;

	if(override) {
		obj.className = className;
	} else {
		var classNames = className.split(' ');

		for(var i = 0; i < classNames.length; i++) {
			if(obj.className.indexOf(classNames[i]) == -1) {
				obj.className = obj.className.trim() + ' ' + classNames[i];
			}
		}
	}
}

/**
 * This function will remove a class name from the
 * specified element. This function will work with
 * elements that have multiple class names as well.
 *
 * @param objOrId element or ID of element to remove
 *            class name from
 * @param className class name to remove from element
 */
function removeClassName(objOrId, className) {
	var obj = getObject(objOrId);
	if(obj == null) return;

	var classNames = className.split(' ');

	for(var i = 0; i < classNames.length; i++) {
		if(obj.className.indexOf(classNames[i]) != -1) {
			obj.className = (obj.className.replace(classNames[i], '')).trim();
		}
	}
}

/**
 * Simple utility function used to return an
 * object using an ID or the object itself. This
 * is a simple replacement for the getElementById()
 * method that only accepts an ID.
 *
 * @param objOrId element or ID of element to return
 *            as object
 * @return either the object or null
 */
function getObject(objOrId) {
	if(typeof objOrId == 'object') {
		return objOrId;
	} else if(typeof objOrId == 'string') {
		return document.getElementById(objOrId);
	} else {
		return null;
	}
}

/**
 * A function to iterate through all elements on a page and
 * return an array of those elements that contain the specified
 * class name
 *
 * @param obj the parent object to use as the base element
 * @param c class name to search for
 * @return array of elements or empty array
 */
function getElementsByClassName(obj, c) {
	var ret = new Array();
	var j = 0;
	var objs = obj.getElementsByTagName('*');

	// if no elemets are returned, then get all DIV's instead. This is
	// a hack to get some older browsers to work, like IE 5.x
	objs = objs.length == 0 ? obj.getElementsByTagName('DIV') : objs;

	for(i = 0; i < objs.length; i++){
		if(containsClassName(objs[i], c)) {
			ret[j] = objs[i];
			j++;
		} // if
	} // for
	return ret;
} // getElementsByClassName

/**
 * This function will check for the existance of a class name
 * within an object. This method will work with multiple
 * class name definitions.
 *
 * @param obj object to search for class name on
 * @param s class name to search for
 * @return true if class name found, false otherwise
 */
function containsClassName(obj, s) {
	if (obj == null || typeof obj == 'undefined' || typeof obj.className == 'undefined') {
		return false;
	}

	var classNames = obj.className.split(' ');

	for(var i = 0; i < classNames.length; i++) {
		if (classNames[i] == s) {
			return true;
		}
	}

	return false;
}


function strltrim() {
	return this.replace(/^\s+/,'');
}

function strrtrim() {
	return this.replace(/\s+$/,'');
}
function strtrim() {
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

