
var nowFocusName = "";
var focusColor_active = "";
var focusColor_inactive = "";

function checkFocusColorEnable( item )
{
	return ( ( "text" == item.type ) || ( "textarea" == item.type ) || ( "password" == item.type ) );
}

function checkFocusSelectEnable( item )
{
	return ( ( "text" == item.type ) || ( "textarea" == item.type ) || ( "password" == item.type ) );
}

function setFocusColor( item )
{
	if ( ( "" != focusColor_active ) && checkFocusColorEnable( item ) ) item.style.backgroundColor = focusColor_active;
}

function clearFocusColor( item )
{
	if ( ( "" != focusColor_inactive ) && checkFocusColorEnable( item ) ) item.style.backgroundColor = focusColor_inactive;
}

function _nowFocus()
{
	if ( "" != nowFocusName ) this.form.elements[ nowFocusName ].nowBlur();
	nowFocusName = this.name;
	setFocusColor( this );
}

function _nowBlur()
{
	clearFocusColor( this );
	nowFocusName = "";
}

function initFocus( name, b1stSelectChansel, activeColor, inactiveColor )
{
	var fm = document.forms[ name ];
	var bFast = ( !!b1stSelectChansel ) ? false: true;
	
	if ( !!activeColor )   focusColor_active   = activeColor;
	if ( !!inactiveColor ) focusColor_inactive = inactiveColor;
	
	for ( var i = 0; i < fm.elements.length; i++ )
	{
		if ( checkFocusSelectEnable( fm.elements[ i ] ) )
		{
			fm.elements[ i ].onfocus = _nowFocus;
			fm.elements[ i ].onblur  = _nowBlur;
			if ( bFast )
			{
				fm.elements[ i ].focus();
				fm.elements[ i ].select();
				bFast = false;
			}
		}
	}
}

function nextFocus( fm )
{
	if ( "" != nowFocusName )
	{
		for ( var i = 0; i < fm.elements.length; i++ )
		{
			if ( checkFocusSelectEnable( fm.elements[ i ] )  )
			{
				if ( nowFocusName == fm.elements[ i ].name )
				{
					while ( i < (fm.elements.length - 1) )
					{
						i++;
						if ( checkFocusSelectEnable( fm.elements[ i ] )  )
						{
							if ( nowFocusName != fm.elements[ i ].name )
							{
								fm.elements[ i ].focus();
								return false;
							}
						}
					}
				}
			}
		}
	}
	return true;
}


