Set the focus on page load but only if the page is loaded by clicking on a certain link

Set the focus on page load but only if the page is loaded by clicking on a certain link

Hi,

In the header of my page there is a link which loads the Login page.
On the login page I have two links: Login link and Register link.

Inside the login page if I click on "Login" link it reloads the page.
If I click on "Register" link it loads the register page.

What I'm trying to achieve is this:

If I click on the "login" link in the header and the login page is loaded, the focus should be on the login link inside the page.This is easy, I just need to set the focus on document.ready.

But now the tricky part:
Inside the login page if I click on login link (which reloads the same page again) I need to put the focus on the first input field.

In short:
1) If I click on the login link inside the header: Load the login page and set the focus on login-link on the login page.
2) Inside the login-page, if I click on login-link, reload the page and set the focus on the first input field.

Is it possible?

Thanks