Although this doesn’t answer the question (requiring a common script), I though it might be useful for others to know that HTML5 introduces the ‘autofocus’ attribute:
<form>
<input type="text" name="username" autofocus>
<input type="password" name="password">
<input type="submit" value="Login">
</form>
Dive in to HTML5 has more information.