// ***** Utility functions for nicely handling forms
// requires laroueverte.js...

function prepareInputsForHints() {
    // search for all label tag
	var labels = document.getElementsByTagName("label");
	for (var i=0; i<labels.length; i++) {
		var title = labels[i].title;
		if (title) {
			// the label has a title
			var inputId = labels[i].attributes["for"].value;
			var input = document.getElementById(inputId);
			if (input && input.className.indexOf("_labelTitleHint") >= 0) { 
				var parent = input.parentNode;
				var hint = document.createElement('span');
				hint.className = "labelTitleHint";
				hint.innerHTML = title;
				hint.style.display = 'none';
				parent.appendChild(hint);
				input.onfocus = function () {
					var parent = this.parentNode;
					var children = parent.childNodes;
					for (var c = 0; c < children.length; c++) {
						var child = children[c];
						var childClass = child.className;
						if (childClass && childClass == "labelTitleHint") {
							child.style.display = "";
						}
					}
				}
				input.onblur = function () {
					var parent = this.parentNode;
					var children = parent.childNodes;
					for (var c = 0; c < children.length; c++) {
						var child = children[c];
						var childClass = child.className;
						if (childClass && childClass == "labelTitleHint") {
							child.style.display = 'none';
						}
					}
				}
			}
		}
	}
	// focus on first input
	var inputs = document.getElementsByTagName('input');
	if (inputs) {
		for (var count = 0; count < inputs.length; count++) {
			var input = inputs[count];
			if (input.type != "hidden") {
				input.focus();
				break;
			}
		}
	}
	
}

addLoadEvent(prepareInputsForHints);