/* autolabel.js
   $Id: autolabel.js,v 1.1 2007/03/22 19:03:25 dferruggia Exp $ */

/* Auto Label */

/*
if the auto-label feature does not work, change body tag to <body onload="labelFields()">
<script language="JavaScript" type="text/javascript" src="autolabel.js"></script>
If you have dynamically generated fields, convert them to labeled fields with "initField(FIELD_NAME)"
*/
function labelFields() {
	if (!document.getElementsByTagName){ return; }
	var allfields = document.getElementsByTagName("input");	
	for (var i=0; i<allfields.length; i++){ 	// loop through all input tags and add events
		initField(allfields[i]);
	}
	var allfields2 = document.getElementsByTagName("textarea");	
	for (var i=0; i<allfields2.length; i++){ 	// loop through all textarea tags and add events
		initField(allfields2[i]);
	}
}
function initField(field) {
	if (field) { //prevent misfire
		var graycolor = "#888";
		if ((field.type == "text" || field.type == "textarea") && (field.value != null)) {	// include text boxes, exclude empty ones
			field.style.color = graycolor;
			field.graytext = field.value;
			field.onfocus = function () {
				if (this.value==this.graytext){
					this.style.color="#000";
					this.value="";
				} else {
					this.select();
				}
			}
			field.onblur = function () {
				if (this.value=="") {
					this.style.color=graycolor;
					this.value=this.graytext;
				}
			}
		}
	}
}

//	window.onload = function() {
//		labelFields();
//	}

