// hints.js

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}else{
		window.onload = function() {
			oldonload();
			func;
		}
	}
}

/*The function prepareInputsForHints() looks for all <input>tags and cycles through them. When there is a focus on that input field,
we grab the first span tag in the <li> in which the <input> resides, and we change it's display to inline so that it'll show up.*/
function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++) {
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span") [0]) {
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = function() {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function() {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	//duplicating above logic of <input> so that it works with <select>.
	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++) {
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function() {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function() {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	//duplicating above logic of <input> so that it works with <select>.
	var textarea = document.getElementsByTagName("textarea");
	for (var j=0; j<textarea.length; j++) {
		if (textarea[j].parentNode.getElementsByTagName("span")[0]) {
			textarea[j].onfocus = function() {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			textarea[j].onblur = function() {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}
addLoadEvent(prepareInputsForHints);
