
function glFocus(e) {

	// This ends up being the actual event handler for the controls

	if(!e)
		var e = window.event;
	
	// IE uses srcElement, while all other browsers use target. Thanks Microsoft
	var target = (e.target) ? e.target : e.srcElement;
	
	//Defeats a Safari bug	
	if(target.nodeType == 3)
		target = target.parentNode;
		
	// If the control has been brought into focus, give it a distinctive
	// background color, otherwise just make it standard white.
	var color = (e.type == 'focus') ? 'rgb(255,255,240)' : 'rgb(255,255,255)';
	var ftype = target.type;
	
	if(ftype == 'text' ||
		ftype == 'textarea' ||
		ftype == 'select-one' ||
		ftype == 'select-multiple') {
		target.style.background = color;
	}

}

function initHighlightControls(tagName) {

	// Call this function once the form has loaded

	var fields = document.getElementsByTagName(tagName);//form.elements;
			
	// For text type fields, we'll be setting and onfocus and onblur
	// event handler. This saves time as it spares us from declaring
	// the event handlers in each and every control.
	
	for(var i=0;i<fields.length;i++) {
		var ftype = fields[i].type;
		
		// Set the blur and focus events
		fields[i].onfocus = glFocus;
		fields[i].onblur = glFocus;
		
		// Since IE is garbage and doesn't support input[type='text']
		// type elements in CSS, we have to set the class type for text
		// fields. If it weren't this easy I'd be quite angry
		
		if(ftype == 'text' || ftype == 'textarea')
			fields[i].className = 'textelement';
	}
}
