window.onload = function() {
	
	var divs = document.getElementsByTagName("div");
	for (var i=0; i < divs.length; i++) {
		if (divs[i].className.indexOf("watermark") > -1) {

			// show the watermark span
			var theSpan = divs[i].getElementsByTagName("span")[0];
			if (theSpan) {
				theSpan.style.display = "block";
			}
			
			// set onfocus and onblur for the input contained in this div
			var theInput = divs[i].getElementsByTagName("input")[0];
			if (theInput) {
				
				theInput.onfocus = function() {
					var theSpan = this.parentNode.getElementsByTagName("span")[0];
					if (theSpan) {
						theSpan.style.display = "none";
					}
				}
				
				theInput.onblur = function() {
					// only reset watermark if field is empty
					if (this.value.length == 0) {
						var theSpan = this.parentNode.getElementsByTagName("span")[0];
						if (theSpan) {
							theSpan.style.display = "block";
						}
					}
				}								
			
			}
		}
	}	
}

