refact a function LoseFocus