jquery helps

I have below codes using jquery. It is working fine. However got some questions.

1. How to add onfocus inside of event ($("#btnPrincipal").click(function ())
2. How to add jquery validation. For example, just want to add if principalName is null or something close.
3. I want to add close button so I can close this pop up.
4. I want to use resource file as well inside of html codes like <label></label>

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

About the validation, it works, but after I put some thing in the textbox and tab next text box, the error message should be invisible. But it is not working. It is still shown error message even I have value inside of the text box.

In addition, it may be better if you can implement your example merge into my jquery codes. It is easier for me to read.

About your code, when the ok button is clicked, no matter what, the div is hidden. so the validation part does not shown visible. that is the problem. Your validation works but it is not visible.

And I want to validate with ok button. not submit button. I don't really care about the submit button because it is just a way pointing to the server IP. I need the validation check complete on ok button.

Thanks, I think yours works but I don't think it is ideal to me because If i don't use html table, it does not work.
As a result, I done on my own using some of your codes. The only issue is when it is tab, the error message does not go away. May be you can help me...:-). Thanks,

The repeated code you have is unnecessary. The dependence on the table was based on your markup. Here is code that does the same thing - on lost focus and Done button - without having to add the <span class="error"> elements to the markup and that is not dependent on tables