addLoadEvent(function() {
	//initRemoveText();
});


/*-  When a user clicks on a text field, any default text should
	be removed.
----------------------------------------------------------------------*/
function initRemoveText() {
	if (document.getElementsByTagName) {
		var inputs = new Array();
		var texts = document.getElementsByTagName("input");
		var textareas = document.getElementsByTagName("textarea");

		for (var i = 0; i < texts.length; i++) {
			inputs.push(texts[i]);
		}

		for (var i = 0; i < textareas.length; i++) {
			inputs.push(textareas[i]);
		}

		for (var i = 0; i < inputs.length; i++) {
			var this_input = inputs[i];
			if (this_input.getAttribute("type") == "text" || this_input.tagName.toLowerCase() == "textarea") {
				this_input.setAttribute("previous", this_input.value);
				this_input.className = safeAppend(this_input.className, "not-clicked");

				this_input.onclick = function() {
					this.value = "";
					this.className = replaceWord("not-clicked", "", this.className);
				}

				this_input.onblur = function() {
					if (this.value.length == 0) {
						this.value = this.getAttribute("previous");
					}
					this.setAttribute("previous", this.value);
				}
			}
		}
	}
}


/*-  Utility functions
----------------------------------------------------------------------*/
/*
	Add Load Event
*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/*
	Smart string concatenation
*/
function safeAppend(target, str) {
	target += (target.length > 0 ? " ": "") + str;
	return target;
}

/*
	Find full word (needle) in a string (haystack)
*/
function findWord(needle, haystack) {
	return haystack.match(needle + "\\b");
}

/*
	Used to replace a word (oldNeedle) with a new word (newNeedle), as found in a string (haystack)
*/
function replaceWord(oldNeedle, newNeedle, haystack) {
	return haystack.replace(new RegExp(oldNeedle + "\\b", "g"), newNeedle);
}

