// trim(), ltrim(), and rtrim(): Credit: http://www.somacon.com/p355.php
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

// Shows an element, element ID or series of comma separated element IDs
function show(id) {
	var element;
	
	// Validate Input
	if (!id) {
		alert("The element has not been specified in show() or does not exist");
		return false;
	}
	
	// String
	if ((typeof id) == "string") {
		id = id.split(",");
		for(i=0; i < id.length; i++) {
			
			// Check for the element
			if (!(element = document.getElementById(id[i].trim()))) {
				alert("The element ID \""+id[i].trim()+"\"specified in show() does not exist");
			} else {
			
				// Show Block Level Tags
				if (element.tagName.toLowerCase() in {"p":"","div":"","hr":"","h1":"","h2":"","h3":"","h4":"","h5":"","h6":"","address":"","blockquote":"","center":"","del":"","ins":"","noscript":"","pre":""}) {
					element.style.display = "block";
				
				// Show Inline Tags
				} else {
					element.style.display = "inline";
				}
			}
		}

	// Object
	} else {
		element = id;
		
		// Show Block Level Tags
		if (element.tagName.toLowerCase() in {"p":"","div":"","hr":"","h1":"","h2":"","h3":"","h4":"","h5":"","h6":"","address":"","blockquote":"","center":"","del":"","ins":"","noscript":"","pre":""}) {
			element.style.display = "block";
		
		// Show Inline Tags
		} else {
			element.style.display = "inline";
		}
	}
	return true;
}

// Hides an element, element ID or series of comma separated element IDs
function hide(id) {
	var element;
	
	// Validate Input
	if (!id) {
		alert("The element has not been specified in hide() or does not exist");
		return false;
	}
	
	// String
	if ((typeof id) == "string") {
		id = id.split(",");
		for(i=0; i < id.length; i++) {
			
			// Check for the element
			if (!(element = document.getElementById(id[i].trim()))) {
				alert("The element ID \""+id[i].trim()+"\" specified in hide() does not exist");

			// Hide
			} else {
				element.style.display = "none";
			}
		}
		
	// Object
	} else {
		element = id;
		element.style.display = "none";
	}
	return true;
}

// Hides a tag by a class
function hideByClass(tag,c) {
	var elements;
	
	// Validate Input
	if (!tag) {
		alert("A tag has not been specified in hideByClass()");
		return false;
	}
	if (!c) {
		alert("A class has not been specified in hideByClass()");
		return false;
	}
	
	// Find elements
	elements = document.getElementsByTagName(tag.toLowerCase());

	// Hide matching elements
	for(i=0; i < elements.length; i++) {
		if (elements[i].className == c) {
			elements[i].style.display = "none";
		}
	}
	return true;
}

// Changes the class of an element, element ID or series of comma separated element IDs
function changeClassByElement(id,c) {
	var element;
	
	// Validate Input
	if (!id) {
		alert("The element has not been specified in changeClassByElement() or does not exist");
		return false;
	}
	if (!c) c = "";
	
	// String
	if ((typeof id) == "string") {
		id = id.split(",");
		for(i=0; i < id.length; i++) {
			
			// Check for the element
			if (!(element = document.getElementById(id[i].trim()))) {
				alert("The element ID \""+id[i].trim()+"\"specified in changeClassByElement() does not exist");
			} else {
				element.className = c;
			}
		}

	// Object
	} else {
		element = id;
		element.className = c;
	}
	return true;
}

// Changes the class of a tag by a class
function changeClassByClass(tag,find,replace) {
	var elements;
	
	// Validate Input
	if (!tag) {
		alert("A tag has not been specified in changeClassByClass()");
		return false;
	}
	if (!find) {
		alert("A class to find has not been specified in changeClassByClass()");
		return false;
	}
	if (!replace) replace = "";
	
	// Find Elements
	elements = document.getElementsByTagName(tag.toLowerCase());

	// Hide matching elements
	for(i=0; i < elements.length; i++) {
		if (elements[i].className == find) {
			elements[i].className = replace;
		}
	}
	return true;
}