//
// Only load once.
// 
if (typeof require_external_js == 'undefined') {
	var require_external_js = {};
}
if (!require_external_js['/ixa/scripts/general.js']) {
	require_external_js['/ixa/scripts/general.js'] = 1;

// Browser Detection
isOpera = (navigator.userAgent.toLowerCase().indexOf('opera') > -1);
safari = (navigator.userAgent.toLowerCase().indexOf('safari') > -1);
isGecko = (!isOpera && !safari && navigator.userAgent.toLowerCase().indexOf('gecko') > -1);
msie = (!isOpera && navigator.userAgent.toLowerCase().indexOf('msie') > -1);

/*
 * Return an array of objects that contain a given class name. Keep in mind
 * that a single tag can have multiple classes, delimited by a space
 * character. The optional 2nd param tagType is there to speed up the
 * search on larger documents, the default is to search all tags. By
 * default the top document is searched, but an optional 3rd param can be
 * given to narrow the search.
 */
function getElementsByClassName(clsName)
{
	var argv = getElementsByClassName.arguments;
	var argc = getElementsByClassName.arguments.length;
	var tag = (argc > 1 && argv[1] != null) ? argv[1].toUpperCase() : "*";
	var top = (argc > 2 && argv[2] != null) ? argv[2] : document;

	var arr = new Array(); 

	//
	// recursively iterate through all nodes
	//
	// Note: In IE6, this is a bit better than an order of
	// magnitude(!!) faster than using getElementsByTagName():
	// 0.203 vs 2.266 seconds on the large SCoTT edit form in ERS
	//
	function iterate(e) {
		while (e) {
			if (tag == '*' || e.tagName == tag) {
				if (e.className) {
					if (clsName == "") {
						arr[arr.length] = e;
					} else {
						var classes = e.className.split(' ');
						for (var j = 0; j < classes.length; j++) {
							if (classes[j] == clsName) {
								arr[arr.length] = e;
								continue;
							}
						}
					}
				}
			}
			if (e.firstChild) {
				iterate(e.firstChild);
			}
			e = e.nextSibling;
		}
	}

	iterate(top);

	return arr;
}


/*
 * Change the className within an object, keeping in mind that classes are
 * delimited by spaces, and we only want to replace one of them. However if
 * there is currently no class, or the from doesn't exist, then there is no
 * issue with just setting it.
 */
function changeClassName(obj, from, to)
{
	if (obj.className) {
		var reg = new RegExp("\\b" + to + "\\b");
		if (obj.className.match(reg)) {
			to = '';
		}
		var reg = new RegExp("\\b" + from + "\\b");
		if (obj.className.match(reg)) {
			obj.className = obj.className.replace(reg, to);
		} else if (to) {
			obj.className += " " + to;
		}
	} else {
		obj.className = to;
	}
	return true;
}

/*
 * Unselect all the options for a given select box
 */
function unselectAll(box) {
	for (var i = 0; i < box.options.length; i++) {
		box.options[i].selected = false;
	}
	return true;
}

/*
 * Select all the options for a given select box
 */
function selectAll(box) {
	for (var i = 0; i < box.options.length; i++) {
		if (box.options[i].value != "") {
			box.options[i].selected = true;
		} else {
			box.options[i].selected = false;
		}
	}
	return true;
}

}
