Hi Oberdan:
Without a link to your page and some context it is hard to understand what effect you are trying to implement. Basically either the button is a login button or it is a register button. The only way to automate registration is if the login attempt fails. So you would need to catch a login failure and register instead you would need to add a catch() that catches a login failure, tests the reason (you need a invalid user or password error). Then display a password element and change the name of the button to Register and use the button to register. If you do this then you can test for the button name in the loginButton_click() code and then perform the related login or register function followed by the redirecting to the pages you need to.
Steve