// ------------------------------------------------------------
//
//  Script : rsc_formhighlight.js
//
//  Enhanced form-field highlighting preserving CSS-backgrounds.
//	Logic encapsulated for better portabiity.
//	Focus on arbitrary form-field on document loading
//
//	Author	: Rolf Scherzinger	15.9.2007 
//
//	Original idea : © Dynamic Drive (www.dynamicdrive.com)
//
//  -----------------------------------------------------------
//
//	Instructions :
//
//  1. Load script into desired page 
//
//   <script language="JavaScript" src="js/rsc_formhighlight.js"></script>
//
//  2. Activate Focus-Highlighting for a FORM 
//
//   <form onKeyUp="formhighlight(event)" onClick="formhighlight(event)">
//
//	3. (Optional) Focus on desired first INPUT-Field xyz
//
//   <input id=xyz onFocus="formhighlight(event)">
//   <script>document.onLoad=document.getElementById("xyz").focus();</script>
//
//	-------------------------------------------------------------------------


var focus_old='';										// FORM-field last focus
var focus_old_bg='';								// FORM-field last focus original Background
var focus_new_bg="#ffffff";					// FORM-field highlight-color on Focus

function formhighlight(e){
  var tags=/INPUT|TEXTAREA|SELECT|OPTION|SUBMIT/;
	var ns6=document.getElementById&&!document.all;
	var focus_new=ns6? e.target : event.srcElement;
	if (ns6&&focus_new.nodeType==3) {focus_new=focus_new.parentNode.parentNode;}	

	function fldchk(el){return el.style&&tags.test(el.tagName);}

	if ((focus_old!='')&&(fldchk(focus_old))) {
			focus_old.style.backgroundColor=focus_old_bg;
	} 
	if (fldchk(focus_new)) {
    focus_old_bg=focus_new.style.backgroundColor;
		focus_new.style.backgroundColor=focus_new_bg;
		focus_old=focus_new;
	}
}
