To test whether an user has already logged in, you'd be safer using server-side code to hold a session variable. All js code can be circumvented, so using it to handle this sort of thing may not be appropriate. Ajax is being used more and more to deal with login.
As Jorge states, you need to pass data that will change the image. Using the src attribute of an image is probably the easiest:
Is this form meant to accept registration data and login data depending on the content of the div? E.g.