var Hogarth = {
	init : function() {
		var c = Hogarth;
		var u = c.utility;

		u.addLoadEvent(function() {
			if (u.isCompatible()) {
				c.labelScrub("subscribe");
				c.clickToRemoveText();
			}
		});
	}

	/*
		SVA functions
	*/
	,labelScrub : function(sId) {
		var oForm = document.getElementById(sId);
		if (oForm) {
			var cLabels = oForm.getElementsByTagName("label");
			for (var i = 0; i < cLabels.length; i++) {
				var oTarget = document.getElementById(cLabels[i].htmlFor);
				if (oTarget) {
					oTarget.value = cLabels[i].innerHTML.replace(/<\/?[^>]+>/gi,'');
					cLabels[i].parentNode.removeChild(cLabels[i]);
				}
			}
		}
	}

	,clickToRemoveText : function() {
		if (document.getElementsByTagName) {
			var inputs = document.getElementsByTagName("input");
			for (var i = 0; i < inputs.length; i++) {
				var this_input = inputs[i];
				if (this_input.getAttribute("type") == "text") {
					this_input.setAttribute("previous", this_input.value);

					this_input.onclick = function() {
						this.value = "";
					}

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

	/*
		UTILITY FUNCTIONS
	*/
	,utility : {
		addLoadEvent : function(func) {
			var oldonload = window.onload;
			if (typeof window.onload != 'function') {
				window.onload = func;
			} else {
				window.onload = function() {
					oldonload();
					func();
				}
			}
		}

		,isCompatible : function() {
			if (document.getElementById && document.getElementsByTagName && document.createElement) {
				return true;
			} else {
				return false;
			}
		}
	}
};

Hogarth.init();

